LibreOffice Module svx (master) 1
fmsrccfg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svx/fmsrccfg.hxx>
21
22#include <sal/log.hxx>
25
26using namespace ::com::sun::star::uno;
27
28namespace svxform
29{
30 // search parameters
31
33 :nTransliterationFlags( TransliterationFlags::NONE )
34 ,nSearchForType ( 0 )
35 ,nPosition ( MATCHING_ANYWHERE )
36 ,nLevOther ( 2 )
37 ,nLevShorter ( 2 )
38 ,nLevLonger ( 2 )
39 ,bLevRelaxed ( true )
40 ,bAllFields ( false )
41 ,bUseFormatter ( true )
42 ,bBackwards ( false )
43 ,bWildcard ( false )
44 ,bRegular ( false )
45 ,bApproxSearch ( false )
46 ,bSoundsLikeCJK ( false )
47 {
49 TransliterationFlags::ignoreSpace_ja_JP
50 | TransliterationFlags::ignoreMiddleDot_ja_JP
51 | TransliterationFlags::ignoreProlongedSoundMark_ja_JP
52 | TransliterationFlags::ignoreSeparator_ja_JP
53 | TransliterationFlags::IGNORE_CASE;
54 }
55
57 {
58 return bool(nTransliterationFlags & TransliterationFlags::IGNORE_WIDTH);
59 }
60
62 {
63 return !(nTransliterationFlags & TransliterationFlags::IGNORE_CASE);
64 }
65
67 {
68 if ( _bCase )
70 else
71 nTransliterationFlags |= TransliterationFlags::IGNORE_CASE;
72 }
73
74 // maps from ascii values to int values
75
76 namespace {
77
78 struct Ascii2Int16
79 {
80 const char* pAscii;
81 sal_Int16 nValue;
82 };
83
84 }
85
86 static const Ascii2Int16* lcl_getSearchForTypeValueMap()
87 {
88 static const Ascii2Int16 s_aSearchForTypeMap[] =
89 {
90 { "text", 0 },
91 { "null", 1 },
92 { "non-null", 2 },
93 { nullptr, -1 }
94 };
95 return s_aSearchForTypeMap;
96 }
97
98 static const Ascii2Int16* lcl_getSearchPositionValueMap()
99 {
100 static const Ascii2Int16 s_aSearchPositionMap[] =
101 {
102 { "anywhere-in-field", MATCHING_ANYWHERE },
103 { "beginning-of-field", MATCHING_BEGINNING },
104 { "end-of-field", MATCHING_END },
105 { "complete-field", MATCHING_WHOLETEXT },
106 { nullptr, -1 }
107 };
108 return s_aSearchPositionMap;
109 }
110
111 static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
112 {
113 // search the map for the given ascii value
114 const Ascii2Int16* pSearch = _pMap;
115 while ( pSearch && pSearch->pAscii )
116 {
117 if ( _rAsciiValue.equalsAscii( pSearch->pAscii ) )
118 // found
119 return pSearch->nValue;
120 ++pSearch;
121 }
122
123 SAL_WARN(
124 "svx.form", "could not convert the ascii value " << _rAsciiValue);
125 return -1;
126 }
127
128 static const char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
129 {
130 // search the map for the given integer value
131 const Ascii2Int16* pSearch = _pMap;
132 while ( pSearch && pSearch->pAscii )
133 {
134 if ( _nValue == pSearch->nValue )
135 // found
136 return pSearch->pAscii;
137 ++pSearch;
138 }
139
140 SAL_WARN( "svx", "lcl_implMapIntValue: could not convert the integer value "
141 << _nValue << " !");
142 static const char* const s_pDummy = "";
143 // just as a fallback...
144 return s_pDummy;
145 }
146
147 // class FmSearchConfigItem - a config item that stores search parameters
148
149#define TA( c ) &c, cppu::UnoType<decltype(c)>::get()
150
152 :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", 2 )
153 {
154 // register our members so the data exchange with the node values is done automatically
155
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 ) );
168
169 // the properties which need to be translated
170 registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
171 registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
172
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 ) );
192
193 read( );
194 }
195
197 {
198 commit( );
199 }
200
202 {
203 // the search-for string
205
206 // the search position
208
209 // the transliteration flags
210 nTransliterationFlags = TransliterationFlags::NONE;
211
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;
227
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;
232 }
233
235 {
236 // the search-for string
238
239 // the search position
241
242 // the transliteration flags
243
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 );
259
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 );
264 }
265
267 {
268 // ensure that the properties which are not stored directly are up-to-date
269 const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
270
271 // and return our FmSearchParams part
272 return *this;
273 }
274
276 {
277 // copy the FmSearchParams part
278 *static_cast< FmSearchParams* >( this ) = _rParams;
279
280 // translate the settings not represented by a direct config value
282 }
283
284}
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const FmSearchParams & getParams() const
Definition: fmsrccfg.cxx:266
SVX_DLLPRIVATE void implTranslateToConfig()
Definition: fmsrccfg.cxx:234
SVX_DLLPRIVATE void implTranslateFromConfig()
Definition: fmsrccfg.cxx:201
void setParams(const FmSearchParams &_rParams)
Definition: fmsrccfg.cxx:275
sal_Int32 _nValue
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
const char * pAscii
Definition: fmsrccfg.cxx:80
#define TA(c)
Definition: fmsrccfg.cxx:149
#define MATCHING_BEGINNING
Definition: fmsrccfg.hxx:30
#define MATCHING_ANYWHERE
Definition: fmsrccfg.hxx:29
#define MATCHING_WHOLETEXT
Definition: fmsrccfg.hxx:32
#define MATCHING_END
Definition: fmsrccfg.hxx:31
std::mutex m_aMutex
#define SAL_WARN(area, stream)
NONE
Reference< XComponentContext > getProcessComponentContext()
class FmSearchEngine - Impl class for FmSearchDialog
static sal_Int16 lcl_implMapAsciiValue(const OUString &_rAsciiValue, const Ascii2Int16 *_pMap)
Definition: fmsrccfg.cxx:111
static const char * lcl_implMapIntValue(const sal_Int16 _nValue, const Ascii2Int16 *_pMap)
Definition: fmsrccfg.cxx:128
static const Ascii2Int16 * lcl_getSearchPositionValueMap()
Definition: fmsrccfg.cxx:98
static const Ascii2Int16 * lcl_getSearchForTypeValueMap()
Definition: fmsrccfg.cxx:86
sal_Int16 nSearchForType
Definition: fmsrccfg.hxx:60
TransliterationFlags nTransliterationFlags
Definition: fmsrccfg.hxx:51
bool isIgnoreWidthCJK() const
Definition: fmsrccfg.cxx:56
bool isCaseSensitive() const
Definition: fmsrccfg.cxx:61
void setCaseSensitive(bool _bCase)
Definition: fmsrccfg.cxx:66
css::uno::Sequence< OUString > aHistory
Definition: fmsrccfg.hxx:57
TransliterationFlags