bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / form / fmsrccfg.cxx
blob32f58ced422946753b3615d6887d098683156c72
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "svx/fmsrccfg.hxx"
21 #include <svl/filerec.hxx>
22 #include <com/sun/star/i18n/TransliterationModules.hpp>
23 #include <comphelper/processfactory.hxx>
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::i18n;
29 //........................................................................
30 namespace svxform
32 //........................................................................
34 // ====================================================================
35 // = struct FmSearchParams - Parameter einer Suche
36 // ====================================================================
38 FmSearchParams::FmSearchParams()
39 :nTransliterationFlags( 0 )
40 ,nSearchForType ( 0 )
41 ,nPosition ( MATCHING_ANYWHERE )
42 ,nLevOther ( 2 )
43 ,nLevShorter ( 2 )
44 ,nLevLonger ( 2 )
45 ,bLevRelaxed ( sal_True )
46 ,bAllFields ( sal_False )
47 ,bUseFormatter ( sal_True )
48 ,bBackwards ( sal_False )
49 ,bWildcard ( sal_False )
50 ,bRegular ( sal_False )
51 ,bApproxSearch ( sal_False )
52 ,bSoundsLikeCJK ( sal_False )
54 nTransliterationFlags =
55 TransliterationModules_ignoreSpace_ja_JP
56 | TransliterationModules_ignoreMiddleDot_ja_JP
57 | TransliterationModules_ignoreProlongedSoundMark_ja_JP
58 | TransliterationModules_ignoreSeparator_ja_JP
59 | TransliterationModules_IGNORE_CASE;
62 sal_Bool FmSearchParams::isIgnoreWidthCJK( ) const
64 return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
67 sal_Bool FmSearchParams::isCaseSensitive( ) const
69 return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
72 void FmSearchParams::setCaseSensitive( sal_Bool _bCase )
74 if ( _bCase )
75 nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
76 else
77 nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
80 // ====================================================================
81 // = maps from ascii values to int values
82 // ====================================================================
84 struct Ascii2Int16
86 const sal_Char* pAscii;
87 sal_Int16 nValue;
90 static const Ascii2Int16* lcl_getSearchForTypeValueMap()
92 static const Ascii2Int16 s_aSearchForTypeMap[] =
94 { "text", 0 },
95 { "null", 1 },
96 { "non-null", 2 },
97 { NULL, -1 }
99 return s_aSearchForTypeMap;
102 static const Ascii2Int16* lcl_getSearchPositionValueMap()
104 static const Ascii2Int16 s_aSearchPositionMap[] =
106 { "anywhere-in-field", MATCHING_ANYWHERE },
107 { "beginning-of-field", MATCHING_BEGINNING },
108 { "end-of-field", MATCHING_END },
109 { "complete-field", MATCHING_WHOLETEXT },
110 { NULL, -1 }
112 return s_aSearchPositionMap;
115 static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
117 // search the map for the given ascii value
118 const Ascii2Int16* pSearch = _pMap;
119 while ( pSearch && pSearch->pAscii )
121 if ( 0 == _rAsciiValue.compareToAscii( pSearch->pAscii ) )
122 // found
123 return pSearch->nValue;
124 ++pSearch;
127 OSL_FAIL(
128 ( OString( "lcl_implMapAsciiValue: could not convert the ascii value " )
129 += OString( _rAsciiValue.getStr(), _rAsciiValue.getLength(), RTL_TEXTENCODING_ASCII_US )
130 += OString( " !" )
131 ).getStr()
133 return -1;
136 static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
138 // search the map for the given integer value
139 const Ascii2Int16* pSearch = _pMap;
140 while ( pSearch && pSearch->pAscii )
142 if ( _nValue == pSearch->nValue )
143 // found
144 return pSearch->pAscii;
145 ++pSearch;
148 OSL_FAIL(
149 ( OString( "lcl_implMapIntValue: could not convert the integer value " )
150 += OString::valueOf( (sal_Int32)_nValue )
151 += OString( " !" )
152 ).getStr()
154 static const sal_Char* s_pDummy = "";
155 // just as a fallback ....
156 return s_pDummy;
159 // ====================================================================
160 // = class FmSearchConfigItem - ein ConfigItem, dass sich Suchparameter merkt
161 // ====================================================================
163 #define TA( c ) &c, getCppuType( &c )
165 FmSearchConfigItem::FmSearchConfigItem()
166 :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
168 // register our members so the data exchange with the node values is done automatically
170 registerExchangeLocation( "SearchHistory", TA( aHistory ) );
171 registerExchangeLocation( "LevenshteinOther", TA( nLevOther ) );
172 registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter ) );
173 registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger ) );
174 registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed ) );
175 registerExchangeLocation( "IsSearchAllFields", TA( bAllFields ) );
176 registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter ) );
177 registerExchangeLocation( "IsBackwards", TA( bBackwards ) );
178 registerExchangeLocation( "IsWildcardSearch", TA( bWildcard ) );
179 registerExchangeLocation( "IsUseRegularExpression", TA( bRegular ) );
180 registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch ) );
181 registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK ) );
183 // the properties which need to be translated
184 registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
185 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
187 registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase ) );
188 registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
189 registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana ) );
190 registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions ) );
191 registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on ) );
192 registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks ) );
193 registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji ) );
194 registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms ) );
195 registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu ) );
196 registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa ) );
197 registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi ) );
198 registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu ) );
199 registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe ) );
200 registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya ) );
201 registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu ) );
202 registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation ) );
203 registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace ) );
204 registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
205 registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot ) );
207 read( );
210 FmSearchConfigItem::~FmSearchConfigItem()
212 commit( );
215 void FmSearchConfigItem::implTranslateFromConfig( )
217 // the search-for string
218 nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
220 // the search position
221 nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
223 // the transliteration flags
224 nTransliterationFlags = 0;
226 if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
227 if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
228 if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
229 if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
230 if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
231 if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
232 if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
233 if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
234 if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
235 if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
236 if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
237 if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
238 if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
239 if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
240 if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
242 if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
243 if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
244 if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
245 if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
248 void FmSearchConfigItem::implTranslateToConfig( )
250 // the search-for string
251 m_sSearchForType = OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
253 // the search position
254 m_sSearchPosition = OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
256 // the transliteration flags
258 m_bIsMatchCase = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
259 m_bIsMatchFullHalfWidthForms = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
260 m_bIsMatchHiraganaKatakana = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
261 m_bIsMatchContractions = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
262 m_bIsMatchMinusDashCho_on = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
263 m_bIsMatchRepeatCharMarks = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
264 m_bIsMatchVariantFormKanji = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
265 m_bIsMatchOldKanaForms = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
266 m_bIsMatch_DiZi_DuZu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
267 m_bIsMatch_BaVa_HaFa = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
268 m_bIsMatch_TsiThiChi_DhiZi = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
269 m_bIsMatch_HyuIyu_ByuVyu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
270 m_bIsMatch_SeShe_ZeJe = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
271 m_bIsMatch_IaIya = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
272 m_bIsMatch_KiKu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
274 m_bIsIgnorePunctuation = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
275 m_bIsIgnoreWhitespace = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
276 m_bIsIgnoreProlongedSoundMark = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
277 m_bIsIgnoreMiddleDot = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
280 const FmSearchParams& FmSearchConfigItem::getParams() const
282 // ensure that the properties which are not stored directly are up-to-date
283 const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
285 // and return our FmSearchParams part
286 return *this;
289 void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
291 // copy the FmSearchParams part
292 *static_cast< FmSearchParams* >( this ) = _rParams;
294 // translate the settings not represented by a direct config value
295 implTranslateToConfig();
298 //........................................................................
299 } // namespace svxform
300 //........................................................................
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */