Line data Source code
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 <comphelper/types.hxx>
23 : #include "fmservs.hxx"
24 : #include "svx/fmtools.hxx"
25 : using namespace ::com::sun::star::uno;
26 :
27 : //------------------------------------------------------------------------------
28 0 : const ::comphelper::StringSequence& getColumnTypes()
29 : {
30 0 : static ::comphelper::StringSequence aColumnTypes(10);
31 0 : if (aColumnTypes.getConstArray()[0].isEmpty())
32 : {
33 0 : ::rtl::OUString* pNames = aColumnTypes.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 : }
45 0 : return aColumnTypes;
46 : }
47 :
48 : //------------------------------------------------------------------
49 : // Vergleichen von PropertyInfo
50 0 : extern "C" int SAL_CALL NameCompare(const void* pFirst, const void* pSecond)
51 : {
52 0 : return ((::rtl::OUString*)pFirst)->compareTo(*(::rtl::OUString*)pSecond);
53 : }
54 :
55 : namespace
56 : {
57 : //------------------------------------------------------------------------------
58 0 : sal_Int32 lcl_findPos(const ::rtl::OUString& aStr, const Sequence< ::rtl::OUString>& rList)
59 : {
60 0 : const ::rtl::OUString* pStrList = rList.getConstArray();
61 0 : ::rtl::OUString* pResult = (::rtl::OUString*) bsearch(&aStr, (void*)pStrList, rList.getLength(), sizeof(::rtl::OUString),
62 0 : &NameCompare);
63 :
64 0 : if (pResult)
65 0 : return (pResult - pStrList);
66 : else
67 0 : return -1;
68 : }
69 : }
70 :
71 : //------------------------------------------------------------------------------
72 0 : sal_Int32 getColumnTypeByModelName(const ::rtl::OUString& aModelName)
73 : {
74 0 : const ::rtl::OUString aModelPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component."));
75 0 : const ::rtl::OUString aCompatibleModelPrefix(RTL_CONSTASCII_USTRINGPARAM("stardiv.one.form.component."));
76 :
77 0 : sal_Int32 nTypeId = -1;
78 0 : if (aModelName == FM_COMPONENT_EDIT)
79 0 : nTypeId = TYPE_TEXTFIELD;
80 : else
81 : {
82 0 : sal_Int32 nPrefixPos = aModelName.indexOf(aModelPrefix);
83 : #ifdef DBG_UTIL
84 : sal_Int32 nCompatiblePrefixPos = aModelName.indexOf(aCompatibleModelPrefix);
85 : DBG_ASSERT( (nPrefixPos != -1) || (nCompatiblePrefixPos != -1), "::getColumnTypeByModelName() : wrong servivce !");
86 : #endif
87 :
88 : ::rtl::OUString aColumnType = (nPrefixPos != -1)
89 : ? aModelName.copy(aModelPrefix.getLength())
90 0 : : aModelName.copy(aCompatibleModelPrefix.getLength());
91 :
92 0 : const ::comphelper::StringSequence& rColumnTypes = getColumnTypes();
93 0 : nTypeId = lcl_findPos(aColumnType, rColumnTypes);
94 : }
95 0 : return nTypeId;
96 : }
97 :
98 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|