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