xref: /AOO41X/main/svx/source/form/fmsrccfg.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
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 "svx/fmsrccfg.hxx"
27 #include <svl/filerec.hxx>
28 #include <com/sun/star/i18n/TransliterationModules.hpp>
29 #include <comphelper/processfactory.hxx>
30 
31 
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::i18n;
34 
35 //........................................................................
36 namespace svxform
37 {
38 //........................................................................
39 
40     // ====================================================================
41     // = struct FmSearchParams - Parameter einer Suche
42     // ====================================================================
43 
44     //---------------------------------------------------------------------
45     //--- 20.08.01 18:17:34 -----------------------------------------------
46 
FmSearchParams()47     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         ,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             |   TransliterationModules_IGNORE_CASE;
69     }
70 
71     //---------------------------------------------------------------------
72     //--- 21.08.01 13:31:48 -----------------------------------------------
73 
isIgnoreWidthCJK() const74     sal_Bool FmSearchParams::isIgnoreWidthCJK( ) const
75     {
76         return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
77     }
78 
79     //---------------------------------------------------------------------
80     //--- 21.08.01 13:32:03 -----------------------------------------------
81 
setIgnoreWidthCJK(sal_Bool _bIgnore)82     void FmSearchParams::setIgnoreWidthCJK( sal_Bool _bIgnore )
83     {
84         if ( _bIgnore )
85             nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
86         else
87             nTransliterationFlags &= ~TransliterationModules_IGNORE_WIDTH;
88     }
89 
90     //---------------------------------------------------------------------
91     //--- 21.08.01 13:47:52 -----------------------------------------------
92 
isCaseSensitive() const93     sal_Bool FmSearchParams::isCaseSensitive( ) const
94     {
95         return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
96     }
97 
98     //---------------------------------------------------------------------
99     //--- 21.08.01 13:48:00 -----------------------------------------------
100 
setCaseSensitive(sal_Bool _bCase)101     void FmSearchParams::setCaseSensitive( sal_Bool _bCase )
102     {
103         if ( _bCase )
104             nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
105         else
106             nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
107     }
108 
109     // ====================================================================
110     // = maps from ascii values to int values
111     // ====================================================================
112 
113     struct Ascii2Int16
114     {
115         const sal_Char* pAscii;
116         sal_Int16       nValue;
117     };
118 
119     //---------------------------------------------------------------------
120     //--- 20.08.01 18:28:38 -----------------------------------------------
121 
lcl_getSearchForTypeValueMap()122     static const Ascii2Int16* lcl_getSearchForTypeValueMap()
123     {
124         static const Ascii2Int16 s_aSearchForTypeMap[] =
125         {
126             { "text",       0 },
127             { "null",       1 },
128             { "non-null",   2 },
129             { NULL,         -1 }
130         };
131         return s_aSearchForTypeMap;
132     }
133 
134     //---------------------------------------------------------------------
135     //--- 20.08.01 18:28:38 -----------------------------------------------
136 
lcl_getSearchPositionValueMap()137     static const Ascii2Int16* lcl_getSearchPositionValueMap()
138     {
139         static const Ascii2Int16 s_aSearchPositionMap[] =
140         {
141             { "anywhere-in-field",      MATCHING_ANYWHERE },
142             { "beginning-of-field",     MATCHING_BEGINNING },
143             { "end-of-field",           MATCHING_END },
144             { "complete-field",         MATCHING_WHOLETEXT },
145             { NULL,                     -1 }
146         };
147         return s_aSearchPositionMap;
148     }
149 
150     //---------------------------------------------------------------------
151     //--- 20.08.01 18:30:15 -----------------------------------------------
152 
lcl_implMapAsciiValue(const::rtl::OUString & _rAsciiValue,const Ascii2Int16 * _pMap)153     static sal_Int16 lcl_implMapAsciiValue( const ::rtl::OUString& _rAsciiValue, const Ascii2Int16* _pMap )
154     {
155         // search the map for the given ascii value
156         const Ascii2Int16* pSearch = _pMap;
157         while ( pSearch && pSearch->pAscii )
158         {
159             if ( 0 == _rAsciiValue.compareToAscii( pSearch->pAscii ) )
160                 // found
161                 return pSearch->nValue;
162             ++pSearch;
163         }
164 
165         DBG_ERROR(
166             (   ::rtl::OString( "lcl_implMapAsciiValue: could not convert the ascii value " )
167             +=  ::rtl::OString( _rAsciiValue.getStr(), _rAsciiValue.getLength(), RTL_TEXTENCODING_ASCII_US )
168             +=  ::rtl::OString( " !" )
169             ).getStr()
170         );
171         return -1;
172     }
173 
174     //---------------------------------------------------------------------
175     //--- 20.08.01 18:33:06 -----------------------------------------------
176 
lcl_implMapIntValue(const sal_Int16 _nValue,const Ascii2Int16 * _pMap)177     static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
178     {
179         // search the map for the given integer value
180         const Ascii2Int16* pSearch = _pMap;
181         while ( pSearch && pSearch->pAscii )
182         {
183             if ( _nValue == pSearch->nValue )
184                 // found
185                 return pSearch->pAscii;
186             ++pSearch;
187         }
188 
189         DBG_ERROR(
190             (   ::rtl::OString( "lcl_implMapIntValue: could not convert the integer value " )
191             +=  ::rtl::OString::valueOf( (sal_Int32)_nValue )
192             +=  ::rtl::OString( " !" )
193             ).getStr()
194         );
195         static const sal_Char* s_pDummy = "";
196             // just as a fallback ....
197         return s_pDummy;
198     }
199 
200     // ====================================================================
201     // = class FmSearchConfigItem - ein ConfigItem, dass sich Suchparameter merkt
202     // ====================================================================
203 
204 #define TA( c )     &c, getCppuType( &c )
205 
206     //---------------------------------------------------------------------
207     //--- 20.08.01 18:19:59 -----------------------------------------------
208 
FmSearchConfigItem()209     FmSearchConfigItem::FmSearchConfigItem()
210         :OConfigurationValueContainer( ::comphelper::getProcessServiceFactory(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
211     {
212         // register our members so the data exchange with the node values is done automatically
213 
214         registerExchangeLocation( "SearchHistory",                      TA( aHistory ) );
215         registerExchangeLocation( "LevenshteinOther",                   TA( nLevOther ) );
216         registerExchangeLocation( "LevenshteinShorter",                 TA( nLevShorter ) );
217         registerExchangeLocation( "LevenshteinLonger",                  TA( nLevLonger ) );
218         registerExchangeLocation( "IsLevenshteinRelaxed",               TA( bLevRelaxed ) );
219         registerExchangeLocation( "IsSearchAllFields",                  TA( bAllFields ) );
220         registerExchangeLocation( "IsUseFormatter",                     TA( bUseFormatter ) );
221         registerExchangeLocation( "IsBackwards",                        TA( bBackwards ) );
222         registerExchangeLocation( "IsWildcardSearch",                   TA( bWildcard ) );
223         registerExchangeLocation( "IsUseRegularExpression",             TA( bRegular ) );
224         registerExchangeLocation( "IsSimilaritySearch",                 TA( bApproxSearch ) );
225         registerExchangeLocation( "IsUseAsianOptions",                  TA( bSoundsLikeCJK ) );
226 
227         // the properties which need to be translated
228         registerExchangeLocation( "SearchType",                         TA( m_sSearchForType ) );
229         registerExchangeLocation( "SearchPosition",                     TA( m_sSearchPosition ) );
230 
231         registerExchangeLocation( "IsMatchCase",                        TA( m_bIsMatchCase ) );
232         registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
233         registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana",   TA( m_bIsMatchHiraganaKatakana ) );
234         registerExchangeLocation( "Japanese/IsMatchContractions",       TA( m_bIsMatchContractions ) );
235         registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on",    TA( m_bIsMatchMinusDashCho_on ) );
236         registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks",    TA( m_bIsMatchRepeatCharMarks ) );
237         registerExchangeLocation( "Japanese/IsMatchVariantFormKanji",   TA( m_bIsMatchVariantFormKanji ) );
238         registerExchangeLocation( "Japanese/IsMatchOldKanaForms",       TA( m_bIsMatchOldKanaForms ) );
239         registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu",         TA( m_bIsMatch_DiZi_DuZu ) );
240         registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa",         TA( m_bIsMatch_BaVa_HaFa ) );
241         registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi",   TA( m_bIsMatch_TsiThiChi_DhiZi ) );
242         registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu",     TA( m_bIsMatch_HyuIyu_ByuVyu ) );
243         registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe",        TA( m_bIsMatch_SeShe_ZeJe ) );
244         registerExchangeLocation( "Japanese/IsMatch_IaIya",             TA( m_bIsMatch_IaIya ) );
245         registerExchangeLocation( "Japanese/IsMatch_KiKu",              TA( m_bIsMatch_KiKu ) );
246         registerExchangeLocation( "Japanese/IsIgnorePunctuation",       TA( m_bIsIgnorePunctuation ) );
247         registerExchangeLocation( "Japanese/IsIgnoreWhitespace",        TA( m_bIsIgnoreWhitespace ) );
248         registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
249         registerExchangeLocation( "Japanese/IsIgnoreMiddleDot",         TA( m_bIsIgnoreMiddleDot ) );
250 
251         read( );
252     }
253 
254     //---------------------------------------------------------------------
255     //--- 20.08.01 18:19:57 -----------------------------------------------
256 
~FmSearchConfigItem()257     FmSearchConfigItem::~FmSearchConfigItem()
258     {
259         commit( );
260     }
261 
262     //---------------------------------------------------------------------
263     //--- 20.08.01 18:20:48 -----------------------------------------------
264 
implTranslateFromConfig()265     void FmSearchConfigItem::implTranslateFromConfig( )
266     {
267         // the search-for string
268         nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
269 
270         // the search position
271         nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
272 
273         // the transliteration flags
274         nTransliterationFlags = 0;
275 
276         if ( !m_bIsMatchCase                )   nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
277         if ( m_bIsMatchFullHalfWidthForms   )   nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
278         if ( m_bIsMatchHiraganaKatakana     )   nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
279         if ( m_bIsMatchContractions         )   nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
280         if ( m_bIsMatchMinusDashCho_on      )   nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
281         if ( m_bIsMatchRepeatCharMarks      )   nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
282         if ( m_bIsMatchVariantFormKanji     )   nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
283         if ( m_bIsMatchOldKanaForms         )   nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
284         if ( m_bIsMatch_DiZi_DuZu           )   nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
285         if ( m_bIsMatch_BaVa_HaFa           )   nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
286         if ( m_bIsMatch_TsiThiChi_DhiZi     )   nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
287         if ( m_bIsMatch_HyuIyu_ByuVyu       )   nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
288         if ( m_bIsMatch_SeShe_ZeJe          )   nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
289         if ( m_bIsMatch_IaIya               )   nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
290         if ( m_bIsMatch_KiKu                )   nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
291 
292         if ( m_bIsIgnorePunctuation         )   nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
293         if ( m_bIsIgnoreWhitespace          )   nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
294         if ( m_bIsIgnoreProlongedSoundMark  )   nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
295         if ( m_bIsIgnoreMiddleDot           )   nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
296     }
297 
298     //---------------------------------------------------------------------
299     //--- 20.08.01 18:42:23 -----------------------------------------------
300 
implTranslateToConfig()301     void FmSearchConfigItem::implTranslateToConfig( )
302     {
303         // the search-for string
304         m_sSearchForType = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
305 
306         // the search position
307         m_sSearchPosition = ::rtl::OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
308 
309         // the transliteration flags
310 
311         m_bIsMatchCase                  = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
312         m_bIsMatchFullHalfWidthForms    = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
313         m_bIsMatchHiraganaKatakana      = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
314         m_bIsMatchContractions          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
315         m_bIsMatchMinusDashCho_on       = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
316         m_bIsMatchRepeatCharMarks       = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
317         m_bIsMatchVariantFormKanji      = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
318         m_bIsMatchOldKanaForms          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
319         m_bIsMatch_DiZi_DuZu            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
320         m_bIsMatch_BaVa_HaFa            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
321         m_bIsMatch_TsiThiChi_DhiZi      = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
322         m_bIsMatch_HyuIyu_ByuVyu        = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
323         m_bIsMatch_SeShe_ZeJe           = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
324         m_bIsMatch_IaIya                = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
325         m_bIsMatch_KiKu                 = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
326 
327         m_bIsIgnorePunctuation          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
328         m_bIsIgnoreWhitespace           = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
329         m_bIsIgnoreProlongedSoundMark   = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
330         m_bIsIgnoreMiddleDot            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
331     }
332 
333     //---------------------------------------------------------------------
334     //--- 20.08.01 18:20:01 -----------------------------------------------
335 
getParams() const336     const FmSearchParams& FmSearchConfigItem::getParams() const
337     {
338         // ensure that the properties which are not stored directly are up-to-date
339         const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
340 
341         // and return our FmSearchParams part
342         return *this;
343     }
344 
345     //---------------------------------------------------------------------
346     //--- 20.08.01 18:41:57 -----------------------------------------------
347 
setParams(const FmSearchParams & _rParams)348     void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
349     {
350         // copy the FmSearchParams part
351         *static_cast< FmSearchParams* >( this ) = _rParams;
352 
353         // translate the settings not represented by a direct config value
354         implTranslateToConfig();
355     }
356 
357 //........................................................................
358 }   // namespace svxform
359 //........................................................................
360