Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / form / fmsrccfg.cxx
blobd17ce0dad4073acf0ae1060606322a928f524a29
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 <com/sun/star/i18n/TransliterationModules.hpp>
22 #include <comphelper/processfactory.hxx>
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::i18n;
27 namespace svxform
29 // search parameters
31 FmSearchParams::FmSearchParams()
32 :nTransliterationFlags( 0 )
33 ,nSearchForType ( 0 )
34 ,nPosition ( MATCHING_ANYWHERE )
35 ,nLevOther ( 2 )
36 ,nLevShorter ( 2 )
37 ,nLevLonger ( 2 )
38 ,bLevRelaxed ( true )
39 ,bAllFields ( false )
40 ,bUseFormatter ( true )
41 ,bBackwards ( false )
42 ,bWildcard ( false )
43 ,bRegular ( false )
44 ,bApproxSearch ( false )
45 ,bSoundsLikeCJK ( false )
47 nTransliterationFlags =
48 TransliterationModules_ignoreSpace_ja_JP
49 | TransliterationModules_ignoreMiddleDot_ja_JP
50 | TransliterationModules_ignoreProlongedSoundMark_ja_JP
51 | TransliterationModules_ignoreSeparator_ja_JP
52 | TransliterationModules_IGNORE_CASE;
55 bool FmSearchParams::isIgnoreWidthCJK( ) const
57 return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
60 bool FmSearchParams::isCaseSensitive( ) const
62 return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
65 void FmSearchParams::setCaseSensitive( bool _bCase )
67 if ( _bCase )
68 nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
69 else
70 nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
73 // maps from ascii values to int values
75 struct Ascii2Int16
77 const sal_Char* pAscii;
78 sal_Int16 nValue;
81 static const Ascii2Int16* lcl_getSearchForTypeValueMap()
83 static const Ascii2Int16 s_aSearchForTypeMap[] =
85 { "text", 0 },
86 { "null", 1 },
87 { "non-null", 2 },
88 { NULL, -1 }
90 return s_aSearchForTypeMap;
93 static const Ascii2Int16* lcl_getSearchPositionValueMap()
95 static const Ascii2Int16 s_aSearchPositionMap[] =
97 { "anywhere-in-field", MATCHING_ANYWHERE },
98 { "beginning-of-field", MATCHING_BEGINNING },
99 { "end-of-field", MATCHING_END },
100 { "complete-field", MATCHING_WHOLETEXT },
101 { NULL, -1 }
103 return s_aSearchPositionMap;
106 static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
108 // search the map for the given ascii value
109 const Ascii2Int16* pSearch = _pMap;
110 while ( pSearch && pSearch->pAscii )
112 if ( _rAsciiValue.equalsAscii( pSearch->pAscii ) )
113 // found
114 return pSearch->nValue;
115 ++pSearch;
118 OSL_FAIL("lcl_implMapAsciiValue: could not convert the ascii value " + _rAsciiValue + " !");
119 return -1;
122 static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
124 // search the map for the given integer value
125 const Ascii2Int16* pSearch = _pMap;
126 while ( pSearch && pSearch->pAscii )
128 if ( _nValue == pSearch->nValue )
129 // found
130 return pSearch->pAscii;
131 ++pSearch;
134 OSL_FAIL(
135 ( OString( "lcl_implMapIntValue: could not convert the integer value " )
136 += OString::number( _nValue )
137 += OString( " !" )
138 ).getStr()
140 static const sal_Char* s_pDummy = "";
141 // just as a fallback ....
142 return s_pDummy;
145 // class FmSearchConfigItem - a config item that stores search parameters
147 #define TA( c ) &c, getCppuType( &c )
149 FmSearchConfigItem::FmSearchConfigItem()
150 :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
152 // register our members so the data exchange with the node values is done automatically
154 registerExchangeLocation( "SearchHistory", TA( aHistory ) );
155 registerExchangeLocation( "LevenshteinOther", TA( nLevOther ) );
156 registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter ) );
157 registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger ) );
158 registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed ) );
159 registerExchangeLocation( "IsSearchAllFields", TA( bAllFields ) );
160 registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter ) );
161 registerExchangeLocation( "IsBackwards", TA( bBackwards ) );
162 registerExchangeLocation( "IsWildcardSearch", TA( bWildcard ) );
163 registerExchangeLocation( "IsUseRegularExpression", TA( bRegular ) );
164 registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch ) );
165 registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK ) );
167 // the properties which need to be translated
168 registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
169 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
171 registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase ) );
172 registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
173 registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana ) );
174 registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions ) );
175 registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on ) );
176 registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks ) );
177 registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji ) );
178 registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms ) );
179 registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu ) );
180 registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa ) );
181 registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi ) );
182 registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu ) );
183 registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe ) );
184 registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya ) );
185 registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu ) );
186 registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation ) );
187 registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace ) );
188 registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
189 registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot ) );
191 read( );
194 FmSearchConfigItem::~FmSearchConfigItem()
196 commit( );
199 void FmSearchConfigItem::implTranslateFromConfig( )
201 // the search-for string
202 nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
204 // the search position
205 nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
207 // the transliteration flags
208 nTransliterationFlags = 0;
210 if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
211 if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
212 if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
213 if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
214 if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
215 if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
216 if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
217 if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
218 if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
219 if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
220 if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
221 if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
222 if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
223 if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
224 if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
226 if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
227 if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
228 if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
229 if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
232 void FmSearchConfigItem::implTranslateToConfig( )
234 // the search-for string
235 m_sSearchForType = OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
237 // the search position
238 m_sSearchPosition = OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
240 // the transliteration flags
242 m_bIsMatchCase = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
243 m_bIsMatchFullHalfWidthForms = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
244 m_bIsMatchHiraganaKatakana = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
245 m_bIsMatchContractions = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
246 m_bIsMatchMinusDashCho_on = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
247 m_bIsMatchRepeatCharMarks = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
248 m_bIsMatchVariantFormKanji = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
249 m_bIsMatchOldKanaForms = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
250 m_bIsMatch_DiZi_DuZu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
251 m_bIsMatch_BaVa_HaFa = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
252 m_bIsMatch_TsiThiChi_DhiZi = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
253 m_bIsMatch_HyuIyu_ByuVyu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
254 m_bIsMatch_SeShe_ZeJe = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
255 m_bIsMatch_IaIya = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
256 m_bIsMatch_KiKu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
258 m_bIsIgnorePunctuation = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
259 m_bIsIgnoreWhitespace = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
260 m_bIsIgnoreProlongedSoundMark = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
261 m_bIsIgnoreMiddleDot = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
264 const FmSearchParams& FmSearchConfigItem::getParams() const
266 // ensure that the properties which are not stored directly are up-to-date
267 const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
269 // and return our FmSearchParams part
270 return *this;
273 void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
275 // copy the FmSearchParams part
276 *static_cast< FmSearchParams* >( this ) = _rParams;
278 // translate the settings not represented by a direct config value
279 implTranslateToConfig();
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */