merge the formfield patch from ooo-build
[ooovba.git] / svx / source / form / fmsrccfg.cxx
blob58ad4d641ee03255d4441a1b677c680c96c375c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmsrccfg.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "fmsrccfg.hxx"
34 #include <svtools/filerec.hxx>
35 #include <com/sun/star/i18n/TransliterationModules.hpp>
36 #include <comphelper/processfactory.hxx>
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::i18n;
42 //........................................................................
43 namespace svxform
45 //........................................................................
47 // ====================================================================
48 // = struct FmSearchParams - Parameter einer Suche
49 // ====================================================================
51 //---------------------------------------------------------------------
52 //--- 20.08.01 18:17:34 -----------------------------------------------
54 FmSearchParams::FmSearchParams()
55 :nTransliterationFlags( 0 )
56 ,nSearchForType ( 0 )
57 ,nPosition ( MATCHING_ANYWHERE )
58 ,nLevOther ( 2 )
59 ,nLevShorter ( 2 )
60 ,nLevLonger ( 2 )
61 ,bLevRelaxed ( sal_True )
62 ,bAllFields ( sal_False )
63 ,bUseFormatter ( sal_True )
64 ,bBackwards ( sal_False )
65 ,bWildcard ( sal_False )
66 ,bRegular ( sal_False )
67 ,bApproxSearch ( sal_False )
68 ,bSoundsLikeCJK ( sal_False )
70 nTransliterationFlags =
71 TransliterationModules_ignoreSpace_ja_JP
72 | TransliterationModules_ignoreMiddleDot_ja_JP
73 | TransliterationModules_ignoreProlongedSoundMark_ja_JP
74 | TransliterationModules_ignoreSeparator_ja_JP
75 | TransliterationModules_IGNORE_CASE;
78 //---------------------------------------------------------------------
79 //--- 21.08.01 13:31:48 -----------------------------------------------
81 sal_Bool FmSearchParams::isIgnoreWidthCJK( ) const
83 return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
86 //---------------------------------------------------------------------
87 //--- 21.08.01 13:32:03 -----------------------------------------------
89 void FmSearchParams::setIgnoreWidthCJK( sal_Bool _bIgnore )
91 if ( _bIgnore )
92 nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
93 else
94 nTransliterationFlags &= ~TransliterationModules_IGNORE_WIDTH;
97 //---------------------------------------------------------------------
98 //--- 21.08.01 13:47:52 -----------------------------------------------
100 sal_Bool FmSearchParams::isCaseSensitive( ) const
102 return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
105 //---------------------------------------------------------------------
106 //--- 21.08.01 13:48:00 -----------------------------------------------
108 void FmSearchParams::setCaseSensitive( sal_Bool _bCase )
110 if ( _bCase )
111 nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
112 else
113 nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
116 // ====================================================================
117 // = maps from ascii values to int values
118 // ====================================================================
120 struct Ascii2Int16
122 const sal_Char* pAscii;
123 sal_Int16 nValue;
126 //---------------------------------------------------------------------
127 //--- 20.08.01 18:28:38 -----------------------------------------------
129 static const Ascii2Int16* lcl_getSearchForTypeValueMap()
131 static const Ascii2Int16 s_aSearchForTypeMap[] =
133 { "text", 0 },
134 { "null", 1 },
135 { "non-null", 2 },
136 { NULL, -1 }
138 return s_aSearchForTypeMap;
141 //---------------------------------------------------------------------
142 //--- 20.08.01 18:28:38 -----------------------------------------------
144 static const Ascii2Int16* lcl_getSearchPositionValueMap()
146 static const Ascii2Int16 s_aSearchPositionMap[] =
148 { "anywhere-in-field", MATCHING_ANYWHERE },
149 { "beginning-of-field", MATCHING_BEGINNING },
150 { "end-of-field", MATCHING_END },
151 { "complete-field", MATCHING_WHOLETEXT },
152 { NULL, -1 }
154 return s_aSearchPositionMap;
157 //---------------------------------------------------------------------
158 //--- 20.08.01 18:30:15 -----------------------------------------------
160 static sal_Int16 lcl_implMapAsciiValue( const ::rtl::OUString& _rAsciiValue, const Ascii2Int16* _pMap )
162 // search the map for the given ascii value
163 const Ascii2Int16* pSearch = _pMap;
164 while ( pSearch && pSearch->pAscii )
166 if ( 0 == _rAsciiValue.compareToAscii( pSearch->pAscii ) )
167 // found
168 return pSearch->nValue;
169 ++pSearch;
172 DBG_ERROR(
173 ( ::rtl::OString( "lcl_implMapAsciiValue: could not convert the ascii value " )
174 += ::rtl::OString( _rAsciiValue.getStr(), _rAsciiValue.getLength(), RTL_TEXTENCODING_ASCII_US )
175 += ::rtl::OString( " !" )
176 ).getStr()
178 return -1;
181 //---------------------------------------------------------------------
182 //--- 20.08.01 18:33:06 -----------------------------------------------
184 static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
186 // search the map for the given integer value
187 const Ascii2Int16* pSearch = _pMap;
188 while ( pSearch && pSearch->pAscii )
190 if ( _nValue == pSearch->nValue )
191 // found
192 return pSearch->pAscii;
193 ++pSearch;
196 DBG_ERROR(
197 ( ::rtl::OString( "lcl_implMapIntValue: could not convert the integer value " )
198 += ::rtl::OString::valueOf( (sal_Int32)_nValue )
199 += ::rtl::OString( " !" )
200 ).getStr()
202 static const sal_Char* s_pDummy = "";
203 // just as a fallback ....
204 return s_pDummy;
207 // ====================================================================
208 // = class FmSearchConfigItem - ein ConfigItem, dass sich Suchparameter merkt
209 // ====================================================================
211 #define TA( c ) &c, getCppuType( &c )
213 //---------------------------------------------------------------------
214 //--- 20.08.01 18:19:59 -----------------------------------------------
216 FmSearchConfigItem::FmSearchConfigItem()
217 :OConfigurationValueContainer( ::comphelper::getProcessServiceFactory(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
219 // register our members so the data exchange with the node values is done automatically
221 registerExchangeLocation( "SearchHistory", TA( aHistory ) );
222 registerExchangeLocation( "LevenshteinOther", TA( nLevOther ) );
223 registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter ) );
224 registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger ) );
225 registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed ) );
226 registerExchangeLocation( "IsSearchAllFields", TA( bAllFields ) );
227 registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter ) );
228 registerExchangeLocation( "IsBackwards", TA( bBackwards ) );
229 registerExchangeLocation( "IsWildcardSearch", TA( bWildcard ) );
230 registerExchangeLocation( "IsUseRegularExpression", TA( bRegular ) );
231 registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch ) );
232 registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK ) );
234 // the properties which need to be translated
235 registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
236 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
238 registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase ) );
239 registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
240 registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana ) );
241 registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions ) );
242 registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on ) );
243 registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks ) );
244 registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji ) );
245 registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms ) );
246 registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu ) );
247 registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa ) );
248 registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi ) );
249 registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu ) );
250 registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe ) );
251 registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya ) );
252 registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu ) );
253 registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation ) );
254 registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace ) );
255 registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
256 registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot ) );
258 read( );
261 //---------------------------------------------------------------------
262 //--- 20.08.01 18:19:57 -----------------------------------------------
264 FmSearchConfigItem::~FmSearchConfigItem()
266 commit( );
269 //---------------------------------------------------------------------
270 //--- 20.08.01 18:20:48 -----------------------------------------------
272 void FmSearchConfigItem::implTranslateFromConfig( )
274 // the search-for string
275 nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
277 // the search position
278 nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
280 // the transliteration flags
281 nTransliterationFlags = 0;
283 if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
284 if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
285 if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
286 if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
287 if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
288 if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
289 if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
290 if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
291 if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
292 if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
293 if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
294 if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
295 if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
296 if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
297 if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
299 if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
300 if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
301 if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
302 if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
305 //---------------------------------------------------------------------
306 //--- 20.08.01 18:42:23 -----------------------------------------------
308 void FmSearchConfigItem::implTranslateToConfig( )
310 // the search-for string
311 m_sSearchForType = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
313 // the search position
314 m_sSearchPosition = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
316 // the transliteration flags
318 m_bIsMatchCase = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
319 m_bIsMatchFullHalfWidthForms = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
320 m_bIsMatchHiraganaKatakana = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
321 m_bIsMatchContractions = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
322 m_bIsMatchMinusDashCho_on = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
323 m_bIsMatchRepeatCharMarks = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
324 m_bIsMatchVariantFormKanji = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
325 m_bIsMatchOldKanaForms = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
326 m_bIsMatch_DiZi_DuZu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
327 m_bIsMatch_BaVa_HaFa = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
328 m_bIsMatch_TsiThiChi_DhiZi = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
329 m_bIsMatch_HyuIyu_ByuVyu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
330 m_bIsMatch_SeShe_ZeJe = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
331 m_bIsMatch_IaIya = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
332 m_bIsMatch_KiKu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
334 m_bIsIgnorePunctuation = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
335 m_bIsIgnoreWhitespace = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
336 m_bIsIgnoreProlongedSoundMark = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
337 m_bIsIgnoreMiddleDot = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
340 //---------------------------------------------------------------------
341 //--- 20.08.01 18:20:01 -----------------------------------------------
343 const FmSearchParams& FmSearchConfigItem::getParams() const
345 // ensure that the properties which are not stored directly are up-to-date
346 const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
348 // and return our FmSearchParams part
349 return *this;
352 //---------------------------------------------------------------------
353 //--- 20.08.01 18:41:57 -----------------------------------------------
355 void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
357 // copy the FmSearchParams part
358 *static_cast< FmSearchParams* >( this ) = _rParams;
360 // translate the settings not represented by a direct config value
361 implTranslateToConfig();
364 //........................................................................
365 } // namespace svxform
366 //........................................................................