Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/fmcomp/gridcols.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <gridcols.hxx>
21
#include <tools/debug.hxx>
22
#include <fmservs.hxx>
23
#include <com/sun/star/uno/Sequence.hxx>
24
25
using namespace ::com::sun::star::uno;
26
27
28
static const css::uno::Sequence<OUString>& getColumnTypes()
29
0
{
30
0
    static css::uno::Sequence<OUString> aColumnTypes = []()
31
0
    {
32
0
        css::uno::Sequence<OUString> tmp(10);
33
0
        OUString* pNames = tmp.getArray();
34
0
        pNames[TYPE_CHECKBOX] = FM_COL_CHECKBOX;
35
0
        pNames[TYPE_COMBOBOX] = FM_COL_COMBOBOX;
36
0
        pNames[TYPE_CURRENCYFIELD] = FM_COL_CURRENCYFIELD;
37
0
        pNames[TYPE_DATEFIELD] = FM_COL_DATEFIELD;
38
0
        pNames[TYPE_FORMATTEDFIELD] = FM_COL_FORMATTEDFIELD;
39
0
        pNames[TYPE_LISTBOX] = FM_COL_LISTBOX;
40
0
        pNames[TYPE_NUMERICFIELD] = FM_COL_NUMERICFIELD;
41
0
        pNames[TYPE_PATTERNFIELD] = FM_COL_PATTERNFIELD;
42
0
        pNames[TYPE_TEXTFIELD] = FM_COL_TEXTFIELD;
43
0
        pNames[TYPE_TIMEFIELD] = FM_COL_TIMEFIELD;
44
0
        return tmp;
45
0
    }();
46
0
    return aColumnTypes;
47
0
}
48
49
50
extern "C" {
51
52
// comparison of PropertyInfo
53
static int NameCompare(const void* pFirst, const void* pSecond)
54
0
{
55
0
    return static_cast<OUString const *>(pFirst)->compareTo(*static_cast<OUString const *>(pSecond));
56
0
}
57
58
}
59
60
namespace
61
{
62
63
    sal_Int32 lcl_findPos(const OUString& aStr, const Sequence< OUString>& rList)
64
0
    {
65
0
        const OUString* pStrList = rList.getConstArray();
66
0
        OUString* pResult = static_cast<OUString*>(bsearch(&aStr, static_cast<void const *>(pStrList), rList.getLength(), sizeof(OUString),
67
0
            &NameCompare));
68
69
0
        if (pResult)
70
0
            return (pResult - pStrList);
71
0
        else
72
0
            return -1;
73
0
    }
74
}
75
76
77
sal_Int32 getColumnTypeByModelName(const OUString& aModelName)
78
0
{
79
0
    static constexpr OUString aModelPrefix(u"com.sun.star.form.component."_ustr);
80
0
    static constexpr OUString aCompatibleModelPrefix(u"stardiv.one.form.component."_ustr);
81
82
0
    sal_Int32 nTypeId = -1;
83
0
    if (aModelName == FM_COMPONENT_EDIT)
84
0
        nTypeId = TYPE_TEXTFIELD;
85
0
    else
86
0
    {
87
0
        sal_Int32 nPrefixPos = aModelName.indexOf(aModelPrefix);
88
#ifdef DBG_UTIL
89
        sal_Int32 nCompatiblePrefixPos = aModelName.indexOf(aCompatibleModelPrefix);
90
        DBG_ASSERT( (nPrefixPos != -1) ||   (nCompatiblePrefixPos != -1), "::getColumnTypeByModelName() : wrong service!");
91
#endif
92
93
0
        OUString aColumnType = (nPrefixPos != -1)
94
0
            ? aModelName.copy(aModelPrefix.getLength())
95
0
            : aModelName.copy(aCompatibleModelPrefix.getLength());
96
97
0
        const css::uno::Sequence<OUString>& rColumnTypes = getColumnTypes();
98
0
        nTypeId = lcl_findPos(aColumnType, rColumnTypes);
99
0
    }
100
0
    return nTypeId;
101
0
}
102
103
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */