1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include "gridcols.hxx" 27 #include <tools/debug.hxx> 28 #include <comphelper/types.hxx> 29 #include "fmservs.hxx" 30 #include "svx/fmtools.hxx" 31 using namespace ::com::sun::star::uno; 32 33 //------------------------------------------------------------------------------ 34 const ::comphelper::StringSequence& getColumnTypes() 35 { 36 static ::comphelper::StringSequence aColumnTypes(10); 37 if (!aColumnTypes.getConstArray()[0].getLength()) 38 { 39 ::rtl::OUString* pNames = aColumnTypes.getArray(); 40 pNames[TYPE_CHECKBOX] = FM_COL_CHECKBOX; 41 pNames[TYPE_COMBOBOX] = FM_COL_COMBOBOX; 42 pNames[TYPE_CURRENCYFIELD] = FM_COL_CURRENCYFIELD; 43 pNames[TYPE_DATEFIELD] = FM_COL_DATEFIELD; 44 pNames[TYPE_FORMATTEDFIELD] = FM_COL_FORMATTEDFIELD; 45 pNames[TYPE_LISTBOX] = FM_COL_LISTBOX; 46 pNames[TYPE_NUMERICFIELD] = FM_COL_NUMERICFIELD; 47 pNames[TYPE_PATTERNFIELD] = FM_COL_PATTERNFIELD; 48 pNames[TYPE_TEXTFIELD] = FM_COL_TEXTFIELD; 49 pNames[TYPE_TIMEFIELD] = FM_COL_TIMEFIELD; 50 } 51 return aColumnTypes; 52 } 53 54 //------------------------------------------------------------------ 55 // Vergleichen von PropertyInfo 56 extern "C" int 57 #if defined( WNT ) 58 __cdecl 59 #endif 60 #if defined( ICC ) && defined( OS2 ) 61 _Optlink 62 #endif 63 NameCompare(const void* pFirst, const void* pSecond) 64 { 65 return ((::rtl::OUString*)pFirst)->compareTo(*(::rtl::OUString*)pSecond); 66 } 67 68 namespace 69 { 70 //------------------------------------------------------------------------------ 71 sal_Int32 lcl_findPos(const ::rtl::OUString& aStr, const Sequence< ::rtl::OUString>& rList) 72 { 73 const ::rtl::OUString* pStrList = rList.getConstArray(); 74 ::rtl::OUString* pResult = (::rtl::OUString*) bsearch(&aStr, (void*)pStrList, rList.getLength(), sizeof(::rtl::OUString), 75 &NameCompare); 76 77 if (pResult) 78 return (pResult - pStrList); 79 else 80 return -1; 81 } 82 } 83 84 //------------------------------------------------------------------------------ 85 sal_Int32 getColumnTypeByModelName(const ::rtl::OUString& aModelName) 86 { 87 const ::rtl::OUString aModelPrefix = ::rtl::OUString::createFromAscii("com.sun.star.form.component."); 88 const ::rtl::OUString aCompatibleModelPrefix = ::rtl::OUString::createFromAscii("stardiv.one.form.component."); 89 90 sal_Int32 nTypeId = -1; 91 if (aModelName == FM_COMPONENT_EDIT) 92 nTypeId = TYPE_TEXTFIELD; 93 else 94 { 95 sal_Int32 nPrefixPos = aModelName.indexOf(aModelPrefix); 96 #ifdef DBG_UTIL 97 sal_Int32 nCompatiblePrefixPos = aModelName.indexOf(aCompatibleModelPrefix); 98 DBG_ASSERT( (nPrefixPos != -1) || (nCompatiblePrefixPos != -1), "::getColumnTypeByModelName() : wrong servivce !"); 99 #endif 100 101 ::rtl::OUString aColumnType = (nPrefixPos != -1) 102 ? aModelName.copy(aModelPrefix.getLength()) 103 : aModelName.copy(aCompatibleModelPrefix.getLength()); 104 105 const ::comphelper::StringSequence& rColumnTypes = getColumnTypes(); 106 nTypeId = lcl_findPos(aColumnType, rColumnTypes); 107 } 108 return nTypeId; 109 } 110 111