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