1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/log.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <i18nutil/transliteration.hxx>
26 using namespace ::com::sun::star::uno
;
32 FmSearchParams::FmSearchParams()
33 :nTransliterationFlags( TransliterationFlags::NONE
)
35 ,nPosition ( MATCHING_ANYWHERE
)
41 ,bUseFormatter ( true )
45 ,bApproxSearch ( false )
46 ,bSoundsLikeCJK ( false )
48 nTransliterationFlags
=
49 TransliterationFlags::ignoreSpace_ja_JP
50 | TransliterationFlags::ignoreMiddleDot_ja_JP
51 | TransliterationFlags::ignoreProlongedSoundMark_ja_JP
52 | TransliterationFlags::ignoreSeparator_ja_JP
53 | TransliterationFlags::IGNORE_CASE
;
56 bool FmSearchParams::isIgnoreWidthCJK( ) const
58 return bool(nTransliterationFlags
& TransliterationFlags::IGNORE_WIDTH
);
61 bool FmSearchParams::isCaseSensitive( ) const
63 return !(nTransliterationFlags
& TransliterationFlags::IGNORE_CASE
);
66 void FmSearchParams::setCaseSensitive( bool _bCase
)
69 nTransliterationFlags
&= ~TransliterationFlags::IGNORE_CASE
;
71 nTransliterationFlags
|= TransliterationFlags::IGNORE_CASE
;
74 // maps from ascii values to int values
86 static const Ascii2Int16
* lcl_getSearchForTypeValueMap()
88 static const Ascii2Int16 s_aSearchForTypeMap
[] =
95 return s_aSearchForTypeMap
;
98 static const Ascii2Int16
* lcl_getSearchPositionValueMap()
100 static const Ascii2Int16 s_aSearchPositionMap
[] =
102 { "anywhere-in-field", MATCHING_ANYWHERE
},
103 { "beginning-of-field", MATCHING_BEGINNING
},
104 { "end-of-field", MATCHING_END
},
105 { "complete-field", MATCHING_WHOLETEXT
},
108 return s_aSearchPositionMap
;
111 static sal_Int16
lcl_implMapAsciiValue( const OUString
& _rAsciiValue
, const Ascii2Int16
* _pMap
)
113 // search the map for the given ascii value
114 const Ascii2Int16
* pSearch
= _pMap
;
115 while ( pSearch
&& pSearch
->pAscii
)
117 if ( _rAsciiValue
.equalsAscii( pSearch
->pAscii
) )
119 return pSearch
->nValue
;
124 "svx.form", "could not convert the ascii value " << _rAsciiValue
);
128 static const char* lcl_implMapIntValue( const sal_Int16 _nValue
, const Ascii2Int16
* _pMap
)
130 // search the map for the given integer value
131 const Ascii2Int16
* pSearch
= _pMap
;
132 while ( pSearch
&& pSearch
->pAscii
)
134 if ( _nValue
== pSearch
->nValue
)
136 return pSearch
->pAscii
;
140 SAL_WARN( "svx", "lcl_implMapIntValue: could not convert the integer value "
142 static const char* const s_pDummy
= "";
143 // just as a fallback...
147 // class FmSearchConfigItem - a config item that stores search parameters
149 #define TA( c ) &c, cppu::UnoType<decltype(c)>::get()
151 FmSearchConfigItem::FmSearchConfigItem()
152 :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex
, "/org.openoffice.Office.DataAccess/FormSearchOptions", 2 )
154 // register our members so the data exchange with the node values is done automatically
156 registerExchangeLocation( "SearchHistory", TA( aHistory
) );
157 registerExchangeLocation( "LevenshteinOther", TA( nLevOther
) );
158 registerExchangeLocation( "LevenshteinShorter", TA( nLevShorter
) );
159 registerExchangeLocation( "LevenshteinLonger", TA( nLevLonger
) );
160 registerExchangeLocation( "IsLevenshteinRelaxed", TA( bLevRelaxed
) );
161 registerExchangeLocation( "IsSearchAllFields", TA( bAllFields
) );
162 registerExchangeLocation( "IsUseFormatter", TA( bUseFormatter
) );
163 registerExchangeLocation( "IsBackwards", TA( bBackwards
) );
164 registerExchangeLocation( "IsWildcardSearch", TA( bWildcard
) );
165 registerExchangeLocation( "IsUseRegularExpression", TA( bRegular
) );
166 registerExchangeLocation( "IsSimilaritySearch", TA( bApproxSearch
) );
167 registerExchangeLocation( "IsUseAsianOptions", TA( bSoundsLikeCJK
) );
169 // the properties which need to be translated
170 registerExchangeLocation( "SearchType", TA( m_sSearchForType
) );
171 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition
) );
173 registerExchangeLocation( "IsMatchCase", TA( m_bIsMatchCase
) );
174 registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms
) );
175 registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana", TA( m_bIsMatchHiraganaKatakana
) );
176 registerExchangeLocation( "Japanese/IsMatchContractions", TA( m_bIsMatchContractions
) );
177 registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on", TA( m_bIsMatchMinusDashCho_on
) );
178 registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks", TA( m_bIsMatchRepeatCharMarks
) );
179 registerExchangeLocation( "Japanese/IsMatchVariantFormKanji", TA( m_bIsMatchVariantFormKanji
) );
180 registerExchangeLocation( "Japanese/IsMatchOldKanaForms", TA( m_bIsMatchOldKanaForms
) );
181 registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu", TA( m_bIsMatch_DiZi_DuZu
) );
182 registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa", TA( m_bIsMatch_BaVa_HaFa
) );
183 registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi", TA( m_bIsMatch_TsiThiChi_DhiZi
) );
184 registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu", TA( m_bIsMatch_HyuIyu_ByuVyu
) );
185 registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe", TA( m_bIsMatch_SeShe_ZeJe
) );
186 registerExchangeLocation( "Japanese/IsMatch_IaIya", TA( m_bIsMatch_IaIya
) );
187 registerExchangeLocation( "Japanese/IsMatch_KiKu", TA( m_bIsMatch_KiKu
) );
188 registerExchangeLocation( "Japanese/IsIgnorePunctuation", TA( m_bIsIgnorePunctuation
) );
189 registerExchangeLocation( "Japanese/IsIgnoreWhitespace", TA( m_bIsIgnoreWhitespace
) );
190 registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark
) );
191 registerExchangeLocation( "Japanese/IsIgnoreMiddleDot", TA( m_bIsIgnoreMiddleDot
) );
196 FmSearchConfigItem::~FmSearchConfigItem()
201 void FmSearchConfigItem::implTranslateFromConfig( )
203 // the search-for string
204 nSearchForType
= lcl_implMapAsciiValue( m_sSearchForType
, lcl_getSearchForTypeValueMap() );
206 // the search position
207 nPosition
= lcl_implMapAsciiValue( m_sSearchPosition
, lcl_getSearchPositionValueMap() );
209 // the transliteration flags
210 nTransliterationFlags
= TransliterationFlags::NONE
;
212 if ( !m_bIsMatchCase
) nTransliterationFlags
|= TransliterationFlags::IGNORE_CASE
;
213 if ( m_bIsMatchFullHalfWidthForms
) nTransliterationFlags
|= TransliterationFlags::IGNORE_WIDTH
;
214 if ( m_bIsMatchHiraganaKatakana
) nTransliterationFlags
|= TransliterationFlags::IGNORE_KANA
;
215 if ( m_bIsMatchContractions
) nTransliterationFlags
|= TransliterationFlags::ignoreSize_ja_JP
;
216 if ( m_bIsMatchMinusDashCho_on
) nTransliterationFlags
|= TransliterationFlags::ignoreMinusSign_ja_JP
;
217 if ( m_bIsMatchRepeatCharMarks
) nTransliterationFlags
|= TransliterationFlags::ignoreIterationMark_ja_JP
;
218 if ( m_bIsMatchVariantFormKanji
) nTransliterationFlags
|= TransliterationFlags::ignoreTraditionalKanji_ja_JP
;
219 if ( m_bIsMatchOldKanaForms
) nTransliterationFlags
|= TransliterationFlags::ignoreTraditionalKana_ja_JP
;
220 if ( m_bIsMatch_DiZi_DuZu
) nTransliterationFlags
|= TransliterationFlags::ignoreZiZu_ja_JP
;
221 if ( m_bIsMatch_BaVa_HaFa
) nTransliterationFlags
|= TransliterationFlags::ignoreBaFa_ja_JP
;
222 if ( m_bIsMatch_TsiThiChi_DhiZi
) nTransliterationFlags
|= TransliterationFlags::ignoreTiJi_ja_JP
;
223 if ( m_bIsMatch_HyuIyu_ByuVyu
) nTransliterationFlags
|= TransliterationFlags::ignoreHyuByu_ja_JP
;
224 if ( m_bIsMatch_SeShe_ZeJe
) nTransliterationFlags
|= TransliterationFlags::ignoreSeZe_ja_JP
;
225 if ( m_bIsMatch_IaIya
) nTransliterationFlags
|= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP
;
226 if ( m_bIsMatch_KiKu
) nTransliterationFlags
|= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP
;
228 if ( m_bIsIgnorePunctuation
) nTransliterationFlags
|= TransliterationFlags::ignoreSeparator_ja_JP
;
229 if ( m_bIsIgnoreWhitespace
) nTransliterationFlags
|= TransliterationFlags::ignoreSpace_ja_JP
;
230 if ( m_bIsIgnoreProlongedSoundMark
) nTransliterationFlags
|= TransliterationFlags::ignoreProlongedSoundMark_ja_JP
;
231 if ( m_bIsIgnoreMiddleDot
) nTransliterationFlags
|= TransliterationFlags::ignoreMiddleDot_ja_JP
;
234 void FmSearchConfigItem::implTranslateToConfig( )
236 // the search-for string
237 m_sSearchForType
= OUString::createFromAscii( lcl_implMapIntValue( nSearchForType
, lcl_getSearchForTypeValueMap() ) );
239 // the search position
240 m_sSearchPosition
= OUString::createFromAscii( lcl_implMapIntValue( nPosition
, lcl_getSearchPositionValueMap() ) );
242 // the transliteration flags
244 m_bIsMatchCase
= !( nTransliterationFlags
& TransliterationFlags::IGNORE_CASE
);
245 m_bIsMatchFullHalfWidthForms
= bool( nTransliterationFlags
& TransliterationFlags::IGNORE_WIDTH
);
246 m_bIsMatchHiraganaKatakana
= bool( nTransliterationFlags
& TransliterationFlags::IGNORE_KANA
);
247 m_bIsMatchContractions
= bool( nTransliterationFlags
& TransliterationFlags::ignoreSize_ja_JP
);
248 m_bIsMatchMinusDashCho_on
= bool( nTransliterationFlags
& TransliterationFlags::ignoreMinusSign_ja_JP
);
249 m_bIsMatchRepeatCharMarks
= bool( nTransliterationFlags
& TransliterationFlags::ignoreIterationMark_ja_JP
);
250 m_bIsMatchVariantFormKanji
= bool( nTransliterationFlags
& TransliterationFlags::ignoreTraditionalKanji_ja_JP
);
251 m_bIsMatchOldKanaForms
= bool( nTransliterationFlags
& TransliterationFlags::ignoreTraditionalKana_ja_JP
);
252 m_bIsMatch_DiZi_DuZu
= bool( nTransliterationFlags
& TransliterationFlags::ignoreZiZu_ja_JP
);
253 m_bIsMatch_BaVa_HaFa
= bool( nTransliterationFlags
& TransliterationFlags::ignoreBaFa_ja_JP
);
254 m_bIsMatch_TsiThiChi_DhiZi
= bool( nTransliterationFlags
& TransliterationFlags::ignoreTiJi_ja_JP
);
255 m_bIsMatch_HyuIyu_ByuVyu
= bool( nTransliterationFlags
& TransliterationFlags::ignoreHyuByu_ja_JP
);
256 m_bIsMatch_SeShe_ZeJe
= bool( nTransliterationFlags
& TransliterationFlags::ignoreSeZe_ja_JP
);
257 m_bIsMatch_IaIya
= bool( nTransliterationFlags
& TransliterationFlags::ignoreIandEfollowedByYa_ja_JP
);
258 m_bIsMatch_KiKu
= bool( nTransliterationFlags
& TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP
);
260 m_bIsIgnorePunctuation
= bool( nTransliterationFlags
& TransliterationFlags::ignoreSeparator_ja_JP
);
261 m_bIsIgnoreWhitespace
= bool( nTransliterationFlags
& TransliterationFlags::ignoreSpace_ja_JP
);
262 m_bIsIgnoreProlongedSoundMark
= bool( nTransliterationFlags
& TransliterationFlags::ignoreProlongedSoundMark_ja_JP
);
263 m_bIsIgnoreMiddleDot
= bool( nTransliterationFlags
& TransliterationFlags::ignoreMiddleDot_ja_JP
);
266 const FmSearchParams
& FmSearchConfigItem::getParams() const
268 // ensure that the properties which are not stored directly are up-to-date
269 const_cast< FmSearchConfigItem
* >( this )->implTranslateFromConfig( );
271 // and return our FmSearchParams part
275 void FmSearchConfigItem::setParams( const FmSearchParams
& _rParams
)
277 // copy the FmSearchParams part
278 *static_cast< FmSearchParams
* >( this ) = _rParams
;
280 // translate the settings not represented by a direct config value
281 implTranslateToConfig();
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */