Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "svx/fmsrccfg.hxx"
21 : #include <svl/filerec.hxx>
22 : #include <com/sun/star/i18n/TransliterationModules.hpp>
23 : #include <comphelper/processfactory.hxx>
24 :
25 :
26 : using namespace ::com::sun::star::uno;
27 : using namespace ::com::sun::star::i18n;
28 :
29 : //........................................................................
30 : namespace svxform
31 : {
32 : //........................................................................
33 :
34 : // ====================================================================
35 : // = struct FmSearchParams - Parameter einer Suche
36 : // ====================================================================
37 :
38 0 : 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 0 : ,bSoundsLikeCJK ( sal_False )
53 : {
54 : nTransliterationFlags =
55 : TransliterationModules_ignoreSpace_ja_JP
56 : | TransliterationModules_ignoreMiddleDot_ja_JP
57 : | TransliterationModules_ignoreProlongedSoundMark_ja_JP
58 : | TransliterationModules_ignoreSeparator_ja_JP
59 0 : | TransliterationModules_IGNORE_CASE;
60 0 : }
61 :
62 0 : sal_Bool FmSearchParams::isIgnoreWidthCJK( ) const
63 : {
64 0 : return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
65 : }
66 :
67 0 : sal_Bool FmSearchParams::isCaseSensitive( ) const
68 : {
69 0 : return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
70 : }
71 :
72 0 : void FmSearchParams::setCaseSensitive( sal_Bool _bCase )
73 : {
74 0 : if ( _bCase )
75 0 : nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
76 : else
77 0 : nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
78 0 : }
79 :
80 : // ====================================================================
81 : // = maps from ascii values to int values
82 : // ====================================================================
83 :
84 : struct Ascii2Int16
85 : {
86 : const sal_Char* pAscii;
87 : sal_Int16 nValue;
88 : };
89 :
90 0 : static const Ascii2Int16* lcl_getSearchForTypeValueMap()
91 : {
92 : static const Ascii2Int16 s_aSearchForTypeMap[] =
93 : {
94 : { "text", 0 },
95 : { "null", 1 },
96 : { "non-null", 2 },
97 : { NULL, -1 }
98 : };
99 0 : return s_aSearchForTypeMap;
100 : }
101 :
102 0 : static const Ascii2Int16* lcl_getSearchPositionValueMap()
103 : {
104 : static const Ascii2Int16 s_aSearchPositionMap[] =
105 : {
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 }
111 : };
112 0 : return s_aSearchPositionMap;
113 : }
114 :
115 0 : static sal_Int16 lcl_implMapAsciiValue( const ::rtl::OUString& _rAsciiValue, const Ascii2Int16* _pMap )
116 : {
117 : // search the map for the given ascii value
118 0 : const Ascii2Int16* pSearch = _pMap;
119 0 : while ( pSearch && pSearch->pAscii )
120 : {
121 0 : if ( 0 == _rAsciiValue.compareToAscii( pSearch->pAscii ) )
122 : // found
123 0 : return pSearch->nValue;
124 0 : ++pSearch;
125 : }
126 :
127 : OSL_FAIL(
128 : ( ::rtl::OString( "lcl_implMapAsciiValue: could not convert the ascii value " )
129 : += ::rtl::OString( _rAsciiValue.getStr(), _rAsciiValue.getLength(), RTL_TEXTENCODING_ASCII_US )
130 : += ::rtl::OString( " !" )
131 : ).getStr()
132 : );
133 0 : return -1;
134 : }
135 :
136 0 : static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
137 : {
138 : // search the map for the given integer value
139 0 : const Ascii2Int16* pSearch = _pMap;
140 0 : while ( pSearch && pSearch->pAscii )
141 : {
142 0 : if ( _nValue == pSearch->nValue )
143 : // found
144 0 : return pSearch->pAscii;
145 0 : ++pSearch;
146 : }
147 :
148 : OSL_FAIL(
149 : ( ::rtl::OString( "lcl_implMapIntValue: could not convert the integer value " )
150 : += ::rtl::OString::valueOf( (sal_Int32)_nValue )
151 : += ::rtl::OString( " !" )
152 : ).getStr()
153 : );
154 : static const sal_Char* s_pDummy = "";
155 : // just as a fallback ....
156 0 : return s_pDummy;
157 : }
158 :
159 : // ====================================================================
160 : // = class FmSearchConfigItem - ein ConfigItem, dass sich Suchparameter merkt
161 : // ====================================================================
162 :
163 : #define TA( c ) &c, getCppuType( &c )
164 :
165 0 : FmSearchConfigItem::FmSearchConfigItem()
166 0 : :OConfigurationValueContainer( ::comphelper::getProcessServiceFactory(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
167 : {
168 : // register our members so the data exchange with the node values is done automatically
169 :
170 0 : registerExchangeLocation( "SearchHistory", TA( aHistory ) );
171 0 : registerExchangeLocation( "LevenshteinOther", TA( nLevOther ) );
172 0 : registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter ) );
173 0 : registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger ) );
174 0 : registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed ) );
175 0 : registerExchangeLocation( "IsSearchAllFields", TA( bAllFields ) );
176 0 : registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter ) );
177 0 : registerExchangeLocation( "IsBackwards", TA( bBackwards ) );
178 0 : registerExchangeLocation( "IsWildcardSearch", TA( bWildcard ) );
179 0 : registerExchangeLocation( "IsUseRegularExpression", TA( bRegular ) );
180 0 : registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch ) );
181 0 : registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK ) );
182 :
183 : // the properties which need to be translated
184 0 : registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
185 0 : registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
186 :
187 0 : registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase ) );
188 0 : registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
189 0 : registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana ) );
190 0 : registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions ) );
191 0 : registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on ) );
192 0 : registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks ) );
193 0 : registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji ) );
194 0 : registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms ) );
195 0 : registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu ) );
196 0 : registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa ) );
197 0 : registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi ) );
198 0 : registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu ) );
199 0 : registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe ) );
200 0 : registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya ) );
201 0 : registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu ) );
202 0 : registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation ) );
203 0 : registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace ) );
204 0 : registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
205 0 : registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot ) );
206 :
207 0 : read( );
208 0 : }
209 :
210 0 : FmSearchConfigItem::~FmSearchConfigItem()
211 : {
212 0 : commit( );
213 0 : }
214 :
215 0 : void FmSearchConfigItem::implTranslateFromConfig( )
216 : {
217 : // the search-for string
218 0 : nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
219 :
220 : // the search position
221 0 : nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
222 :
223 : // the transliteration flags
224 0 : nTransliterationFlags = 0;
225 :
226 0 : if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
227 0 : if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
228 0 : if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
229 0 : if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
230 0 : if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
231 0 : if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
232 0 : if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
233 0 : if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
234 0 : if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
235 0 : if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
236 0 : if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
237 0 : if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
238 0 : if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
239 0 : if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
240 0 : if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
241 :
242 0 : if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
243 0 : if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
244 0 : if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
245 0 : if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
246 0 : }
247 :
248 0 : void FmSearchConfigItem::implTranslateToConfig( )
249 : {
250 : // the search-for string
251 0 : m_sSearchForType = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
252 :
253 : // the search position
254 0 : m_sSearchPosition = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
255 :
256 : // the transliteration flags
257 :
258 0 : m_bIsMatchCase = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
259 0 : m_bIsMatchFullHalfWidthForms = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
260 0 : m_bIsMatchHiraganaKatakana = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
261 0 : m_bIsMatchContractions = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
262 0 : m_bIsMatchMinusDashCho_on = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
263 0 : m_bIsMatchRepeatCharMarks = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
264 0 : m_bIsMatchVariantFormKanji = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
265 0 : m_bIsMatchOldKanaForms = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
266 0 : m_bIsMatch_DiZi_DuZu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
267 0 : m_bIsMatch_BaVa_HaFa = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
268 0 : m_bIsMatch_TsiThiChi_DhiZi = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
269 0 : m_bIsMatch_HyuIyu_ByuVyu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
270 0 : m_bIsMatch_SeShe_ZeJe = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
271 0 : m_bIsMatch_IaIya = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
272 0 : m_bIsMatch_KiKu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
273 :
274 0 : m_bIsIgnorePunctuation = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
275 0 : m_bIsIgnoreWhitespace = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
276 0 : m_bIsIgnoreProlongedSoundMark = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
277 0 : m_bIsIgnoreMiddleDot = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
278 0 : }
279 :
280 0 : const FmSearchParams& FmSearchConfigItem::getParams() const
281 : {
282 : // ensure that the properties which are not stored directly are up-to-date
283 0 : const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
284 :
285 : // and return our FmSearchParams part
286 0 : return *this;
287 : }
288 :
289 0 : void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
290 : {
291 : // copy the FmSearchParams part
292 0 : *static_cast< FmSearchParams* >( this ) = _rParams;
293 :
294 : // translate the settings not represented by a direct config value
295 0 : implTranslateToConfig();
296 0 : }
297 :
298 : //........................................................................
299 : } // namespace svxform
300 : //........................................................................
301 :
302 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|