Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "gridcols.hxx"
30 : : #include <tools/debug.hxx>
31 : : #include <comphelper/types.hxx>
32 : : #include "fmservs.hxx"
33 : : #include "svx/fmtools.hxx"
34 : : using namespace ::com::sun::star::uno;
35 : :
36 : : //------------------------------------------------------------------------------
37 : 62 : const ::comphelper::StringSequence& getColumnTypes()
38 : : {
39 [ + + ][ + - ]: 62 : static ::comphelper::StringSequence aColumnTypes(10);
[ + - ][ # # ]
40 [ + + ]: 62 : if (aColumnTypes.getConstArray()[0].isEmpty())
41 : : {
42 : 2 : ::rtl::OUString* pNames = aColumnTypes.getArray();
43 : 2 : pNames[TYPE_CHECKBOX] = FM_COL_CHECKBOX;
44 : 2 : pNames[TYPE_COMBOBOX] = FM_COL_COMBOBOX;
45 : 2 : pNames[TYPE_CURRENCYFIELD] = FM_COL_CURRENCYFIELD;
46 : 2 : pNames[TYPE_DATEFIELD] = FM_COL_DATEFIELD;
47 : 2 : pNames[TYPE_FORMATTEDFIELD] = FM_COL_FORMATTEDFIELD;
48 : 2 : pNames[TYPE_LISTBOX] = FM_COL_LISTBOX;
49 : 2 : pNames[TYPE_NUMERICFIELD] = FM_COL_NUMERICFIELD;
50 : 2 : pNames[TYPE_PATTERNFIELD] = FM_COL_PATTERNFIELD;
51 : 2 : pNames[TYPE_TEXTFIELD] = FM_COL_TEXTFIELD;
52 : 2 : pNames[TYPE_TIMEFIELD] = FM_COL_TIMEFIELD;
53 : : }
54 : 62 : return aColumnTypes;
55 : : }
56 : :
57 : : //------------------------------------------------------------------
58 : : // Vergleichen von PropertyInfo
59 : 152 : extern "C" int SAL_CALL NameCompare(const void* pFirst, const void* pSecond)
60 : : {
61 : 152 : return ((::rtl::OUString*)pFirst)->compareTo(*(::rtl::OUString*)pSecond);
62 : : }
63 : :
64 : : namespace
65 : : {
66 : : //------------------------------------------------------------------------------
67 : 62 : sal_Int32 lcl_findPos(const ::rtl::OUString& aStr, const Sequence< ::rtl::OUString>& rList)
68 : : {
69 : 62 : const ::rtl::OUString* pStrList = rList.getConstArray();
70 : 62 : ::rtl::OUString* pResult = (::rtl::OUString*) bsearch(&aStr, (void*)pStrList, rList.getLength(), sizeof(::rtl::OUString),
71 : 62 : &NameCompare);
72 : :
73 [ + - ]: 62 : if (pResult)
74 : 62 : return (pResult - pStrList);
75 : : else
76 : 62 : return -1;
77 : : }
78 : : }
79 : :
80 : : //------------------------------------------------------------------------------
81 : 62 : sal_Int32 getColumnTypeByModelName(const ::rtl::OUString& aModelName)
82 : : {
83 [ + - ]: 62 : const ::rtl::OUString aModelPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component."));
84 [ + - ]: 62 : const ::rtl::OUString aCompatibleModelPrefix(RTL_CONSTASCII_USTRINGPARAM("stardiv.one.form.component."));
85 : :
86 : 62 : sal_Int32 nTypeId = -1;
87 [ + - ][ - + ]: 62 : if (aModelName == FM_COMPONENT_EDIT)
88 : 0 : nTypeId = TYPE_TEXTFIELD;
89 : : else
90 : : {
91 : 62 : sal_Int32 nPrefixPos = aModelName.indexOf(aModelPrefix);
92 : : #ifdef DBG_UTIL
93 : : sal_Int32 nCompatiblePrefixPos = aModelName.indexOf(aCompatibleModelPrefix);
94 : : DBG_ASSERT( (nPrefixPos != -1) || (nCompatiblePrefixPos != -1), "::getColumnTypeByModelName() : wrong servivce !");
95 : : #endif
96 : :
97 : : ::rtl::OUString aColumnType = (nPrefixPos != -1)
98 : : ? aModelName.copy(aModelPrefix.getLength())
99 [ + - ]: 62 : : aModelName.copy(aCompatibleModelPrefix.getLength());
100 : :
101 [ + - ]: 62 : const ::comphelper::StringSequence& rColumnTypes = getColumnTypes();
102 [ + - ]: 62 : nTypeId = lcl_findPos(aColumnType, rColumnTypes);
103 : : }
104 : 62 : return nTypeId;
105 : : }
106 : :
107 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|