LibreOffice Module svx (master) 1
gridcols.cxx
Go to the documentation of this file.
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
25using namespace ::com::sun::star::uno;
26
27
28static const css::uno::Sequence<OUString>& getColumnTypes()
29{
30 static css::uno::Sequence<OUString> aColumnTypes = []()
31 {
32 css::uno::Sequence<OUString> tmp(10);
33 OUString* pNames = tmp.getArray();
44 return tmp;
45 }();
46 return aColumnTypes;
47}
48
49
50extern "C" {
51
52// comparison of PropertyInfo
53static int NameCompare(const void* pFirst, const void* pSecond)
54{
55 return static_cast<OUString const *>(pFirst)->compareTo(*static_cast<OUString const *>(pSecond));
56}
57
58}
59
60namespace
61{
62
63 sal_Int32 lcl_findPos(const OUString& aStr, const Sequence< OUString>& rList)
64 {
65 const OUString* pStrList = rList.getConstArray();
66 OUString* pResult = static_cast<OUString*>(bsearch(&aStr, static_cast<void const *>(pStrList), rList.getLength(), sizeof(OUString),
67 &NameCompare));
68
69 if (pResult)
70 return (pResult - pStrList);
71 else
72 return -1;
73 }
74}
75
76
77sal_Int32 getColumnTypeByModelName(const OUString& aModelName)
78{
79 static constexpr OUStringLiteral aModelPrefix(u"com.sun.star.form.component.");
80 static constexpr OUStringLiteral aCompatibleModelPrefix(u"stardiv.one.form.component.");
81
82 sal_Int32 nTypeId = -1;
83 if (aModelName == FM_COMPONENT_EDIT)
84 nTypeId = TYPE_TEXTFIELD;
85 else
86 {
87 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 OUString aColumnType = (nPrefixPos != -1)
94 ? aModelName.copy(aModelPrefix.getLength())
95 : aModelName.copy(aCompatibleModelPrefix.getLength());
96
97 const css::uno::Sequence<OUString>& rColumnTypes = getColumnTypes();
98 nTypeId = lcl_findPos(aColumnType, rColumnTypes);
99 }
100 return nTypeId;
101}
102
103/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DBG_ASSERT(sCon, aError)
float u
constexpr OUStringLiteral FM_COMPONENT_EDIT
Definition: fmservs.hxx:29
sal_Int32 getColumnTypeByModelName(const OUString &aModelName)
Definition: gridcols.cxx:77
static int NameCompare(const void *pFirst, const void *pSecond)
Definition: gridcols.cxx:53
static const css::uno::Sequence< OUString > & getColumnTypes()
Definition: gridcols.cxx:28
#define FM_COL_FORMATTEDFIELD
Definition: gridcols.hxx:34
#define FM_COL_DATEFIELD
Definition: gridcols.hxx:29
#define TYPE_FORMATTEDFIELD
Definition: gridcols.hxx:41
#define TYPE_TIMEFIELD
Definition: gridcols.hxx:46
#define TYPE_COMBOBOX
Definition: gridcols.hxx:38
#define TYPE_TEXTFIELD
Definition: gridcols.hxx:45
#define TYPE_CHECKBOX
Definition: gridcols.hxx:37
#define FM_COL_LISTBOX
Definition: gridcols.hxx:33
#define TYPE_DATEFIELD
Definition: gridcols.hxx:40
#define FM_COL_CHECKBOX
Definition: gridcols.hxx:27
#define FM_COL_TIMEFIELD
Definition: gridcols.hxx:28
#define FM_COL_TEXTFIELD
Definition: gridcols.hxx:25
#define TYPE_NUMERICFIELD
Definition: gridcols.hxx:43
#define TYPE_PATTERNFIELD
Definition: gridcols.hxx:44
#define FM_COL_PATTERNFIELD
Definition: gridcols.hxx:32
#define TYPE_CURRENCYFIELD
Definition: gridcols.hxx:39
#define FM_COL_NUMERICFIELD
Definition: gridcols.hxx:30
#define FM_COL_COMBOBOX
Definition: gridcols.hxx:26
#define TYPE_LISTBOX
Definition: gridcols.hxx:42
#define FM_COL_CURRENCYFIELD
Definition: gridcols.hxx:31