bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / form / fmsrccfg.cxx
blobf644f2d6fce94d10740a8c1066281bf12305053a
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"
22 #include <osl/diagnose.h>
23 #include <com/sun/star/i18n/TransliterationModules.hpp>
24 #include <comphelper/processfactory.hxx>
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::i18n;
29 namespace svxform
31 // search parameters
33 FmSearchParams::FmSearchParams()
34 :nTransliterationFlags( 0 )
35 ,nSearchForType ( 0 )
36 ,nPosition ( MATCHING_ANYWHERE )
37 ,nLevOther ( 2 )
38 ,nLevShorter ( 2 )
39 ,nLevLonger ( 2 )
40 ,bLevRelaxed ( true )
41 ,bAllFields ( false )
42 ,bUseFormatter ( true )
43 ,bBackwards ( false )
44 ,bWildcard ( false )
45 ,bRegular ( false )
46 ,bApproxSearch ( false )
47 ,bSoundsLikeCJK ( false )
49 nTransliterationFlags =
50 TransliterationModules_ignoreSpace_ja_JP
51 | TransliterationModules_ignoreMiddleDot_ja_JP
52 | TransliterationModules_ignoreProlongedSoundMark_ja_JP
53 | TransliterationModules_ignoreSeparator_ja_JP
54 | TransliterationModules_IGNORE_CASE;
57 bool FmSearchParams::isIgnoreWidthCJK( ) const
59 return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
62 bool FmSearchParams::isCaseSensitive( ) const
64 return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
67 void FmSearchParams::setCaseSensitive( bool _bCase )
69 if ( _bCase )
70 nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
71 else
72 nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
75 // maps from ascii values to int values
77 struct Ascii2Int16
79 const sal_Char* pAscii;
80 sal_Int16 nValue;
83 static const Ascii2Int16* lcl_getSearchForTypeValueMap()
85 static const Ascii2Int16 s_aSearchForTypeMap[] =
87 { "text", 0 },
88 { "null", 1 },
89 { "non-null", 2 },
90 { NULL, -1 }
92 return s_aSearchForTypeMap;
95 static const Ascii2Int16* lcl_getSearchPositionValueMap()
97 static const Ascii2Int16 s_aSearchPositionMap[] =
99 { "anywhere-in-field", MATCHING_ANYWHERE },
100 { "beginning-of-field", MATCHING_BEGINNING },
101 { "end-of-field", MATCHING_END },
102 { "complete-field", MATCHING_WHOLETEXT },
103 { NULL, -1 }
105 return s_aSearchPositionMap;
108 static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
110 // search the map for the given ascii value
111 const Ascii2Int16* pSearch = _pMap;
112 while ( pSearch && pSearch->pAscii )
114 if ( _rAsciiValue.equalsAscii( pSearch->pAscii ) )
115 // found
116 return pSearch->nValue;
117 ++pSearch;
120 SAL_WARN(
121 "svx.form", "could not convert the ascii value " << _rAsciiValue);
122 return -1;
125 static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
127 // search the map for the given integer value
128 const Ascii2Int16* pSearch = _pMap;
129 while ( pSearch && pSearch->pAscii )
131 if ( _nValue == pSearch->nValue )
132 // found
133 return pSearch->pAscii;
134 ++pSearch;
137 OSL_FAIL(
138 ( OString( "lcl_implMapIntValue: could not convert the integer value " )
139 += OString::number( _nValue )
140 += OString( " !" )
141 ).getStr()
143 static const sal_Char* s_pDummy = "";
144 // just as a fallback ....
145 return s_pDummy;
148 // class FmSearchConfigItem - a config item that stores search parameters
150 #define TA( c ) &c, cppu::UnoType<decltype(c)>::get()
152 FmSearchConfigItem::FmSearchConfigItem()
153 :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVCFlags::UPDATE_ACCESS | CVCFlags::LAZY_UPDATE, 2 )
155 // register our members so the data exchange with the node values is done automatically
157 registerExchangeLocation( "SearchHistory", TA( aHistory ) );
158 registerExchangeLocation( "LevenshteinOther", TA( nLevOther ) );
159 registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter ) );
160 registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger ) );
161 registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed ) );
162 registerExchangeLocation( "IsSearchAllFields", TA( bAllFields ) );
163 registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter ) );
164 registerExchangeLocation( "IsBackwards", TA( bBackwards ) );
165 registerExchangeLocation( "IsWildcardSearch", TA( bWildcard ) );
166 registerExchangeLocation( "IsUseRegularExpression", TA( bRegular ) );
167 registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch ) );
168 registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK ) );
170 // the properties which need to be translated
171 registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
172 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
174 registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase ) );
175 registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
176 registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana ) );
177 registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions ) );
178 registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on ) );
179 registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks ) );
180 registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji ) );
181 registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms ) );
182 registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu ) );
183 registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa ) );
184 registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi ) );
185 registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu ) );
186 registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe ) );
187 registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya ) );
188 registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu ) );
189 registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation ) );
190 registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace ) );
191 registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
192 registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot ) );
194 read( );
197 FmSearchConfigItem::~FmSearchConfigItem()
199 commit( );
202 void FmSearchConfigItem::implTranslateFromConfig( )
204 // the search-for string
205 nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
207 // the search position
208 nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
210 // the transliteration flags
211 nTransliterationFlags = 0;
213 if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
214 if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
215 if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
216 if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
217 if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
218 if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
219 if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
220 if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
221 if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
222 if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
223 if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
224 if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
225 if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
226 if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
227 if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
229 if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
230 if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
231 if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
232 if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
235 void FmSearchConfigItem::implTranslateToConfig( )
237 // the search-for string
238 m_sSearchForType = OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
240 // the search position
241 m_sSearchPosition = OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
243 // the transliteration flags
245 m_bIsMatchCase = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
246 m_bIsMatchFullHalfWidthForms = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
247 m_bIsMatchHiraganaKatakana = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
248 m_bIsMatchContractions = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
249 m_bIsMatchMinusDashCho_on = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
250 m_bIsMatchRepeatCharMarks = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
251 m_bIsMatchVariantFormKanji = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
252 m_bIsMatchOldKanaForms = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
253 m_bIsMatch_DiZi_DuZu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
254 m_bIsMatch_BaVa_HaFa = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
255 m_bIsMatch_TsiThiChi_DhiZi = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
256 m_bIsMatch_HyuIyu_ByuVyu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
257 m_bIsMatch_SeShe_ZeJe = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
258 m_bIsMatch_IaIya = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
259 m_bIsMatch_KiKu = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
261 m_bIsIgnorePunctuation = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
262 m_bIsIgnoreWhitespace = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
263 m_bIsIgnoreProlongedSoundMark = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
264 m_bIsIgnoreMiddleDot = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
267 const FmSearchParams& FmSearchConfigItem::getParams() const
269 // ensure that the properties which are not stored directly are up-to-date
270 const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
272 // and return our FmSearchParams part
273 return *this;
276 void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
278 // copy the FmSearchParams part
279 *static_cast< FmSearchParams* >( this ) = _rParams;
281 // translate the settings not represented by a direct config value
282 implTranslateToConfig();
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */