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 <osl/diagnose.h>
23 #include <sal/log.hxx>
26 
27 using namespace ::com::sun::star::uno;
28 
29 namespace svxform
30 {
31  // search parameters
32 
34  :nTransliterationFlags( TransliterationFlags::NONE )
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 )
48  {
50  TransliterationFlags::ignoreSpace_ja_JP
51  | TransliterationFlags::ignoreMiddleDot_ja_JP
52  | TransliterationFlags::ignoreProlongedSoundMark_ja_JP
53  | TransliterationFlags::ignoreSeparator_ja_JP
54  | TransliterationFlags::IGNORE_CASE;
55  }
56 
58  {
59  return bool(nTransliterationFlags & TransliterationFlags::IGNORE_WIDTH);
60  }
61 
63  {
64  return !(nTransliterationFlags & TransliterationFlags::IGNORE_CASE);
65  }
66 
68  {
69  if ( _bCase )
71  else
72  nTransliterationFlags |= TransliterationFlags::IGNORE_CASE;
73  }
74 
75  // maps from ascii values to int values
76 
77  namespace {
78 
79  struct Ascii2Int16
80  {
81  const char* pAscii;
82  sal_Int16 const nValue;
83  };
84 
85  }
86 
87  static const Ascii2Int16* lcl_getSearchForTypeValueMap()
88  {
89  static const Ascii2Int16 s_aSearchForTypeMap[] =
90  {
91  { "text", 0 },
92  { "null", 1 },
93  { "non-null", 2 },
94  { nullptr, -1 }
95  };
96  return s_aSearchForTypeMap;
97  }
98 
99  static const Ascii2Int16* lcl_getSearchPositionValueMap()
100  {
101  static const Ascii2Int16 s_aSearchPositionMap[] =
102  {
103  { "anywhere-in-field", MATCHING_ANYWHERE },
104  { "beginning-of-field", MATCHING_BEGINNING },
105  { "end-of-field", MATCHING_END },
106  { "complete-field", MATCHING_WHOLETEXT },
107  { nullptr, -1 }
108  };
109  return s_aSearchPositionMap;
110  }
111 
112  static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
113  {
114  // search the map for the given ascii value
115  const Ascii2Int16* pSearch = _pMap;
116  while ( pSearch && pSearch->pAscii )
117  {
118  if ( _rAsciiValue.equalsAscii( pSearch->pAscii ) )
119  // found
120  return pSearch->nValue;
121  ++pSearch;
122  }
123 
124  SAL_WARN(
125  "svx.form", "could not convert the ascii value " << _rAsciiValue);
126  return -1;
127  }
128 
129  static const char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
130  {
131  // search the map for the given integer value
132  const Ascii2Int16* pSearch = _pMap;
133  while ( pSearch && pSearch->pAscii )
134  {
135  if ( _nValue == pSearch->nValue )
136  // found
137  return pSearch->pAscii;
138  ++pSearch;
139  }
140 
141  SAL_WARN( "svx", "lcl_implMapIntValue: could not convert the integer value "
142  << _nValue << " !");
143  static const char* const s_pDummy = "";
144  // just as a fallback...
145  return s_pDummy;
146  }
147 
148  // class FmSearchConfigItem - a config item that stores search parameters
149 
150 #define TA( c ) &c, cppu::UnoType<decltype(c)>::get()
151 
153  :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", 2 )
154  {
155  // register our members so the data exchange with the node values is done automatically
156 
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 ) );
169 
170  // the properties which need to be translated
171  registerExchangeLocation( "SearchType", TA( m_sSearchForType ) );
172  registerExchangeLocation( "SearchPosition", TA( m_sSearchPosition ) );
173 
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 ) );
193 
194  read( );
195  }
196 
198  {
199  commit( );
200  }
201 
203  {
204  // the search-for string
206 
207  // the search position
209 
210  // the transliteration flags
211  nTransliterationFlags = TransliterationFlags::NONE;
212 
213  if ( !m_bIsMatchCase ) nTransliterationFlags |= TransliterationFlags::IGNORE_CASE;
214  if ( m_bIsMatchFullHalfWidthForms ) nTransliterationFlags |= TransliterationFlags::IGNORE_WIDTH;
215  if ( m_bIsMatchHiraganaKatakana ) nTransliterationFlags |= TransliterationFlags::IGNORE_KANA;
216  if ( m_bIsMatchContractions ) nTransliterationFlags |= TransliterationFlags::ignoreSize_ja_JP;
217  if ( m_bIsMatchMinusDashCho_on ) nTransliterationFlags |= TransliterationFlags::ignoreMinusSign_ja_JP;
218  if ( m_bIsMatchRepeatCharMarks ) nTransliterationFlags |= TransliterationFlags::ignoreIterationMark_ja_JP;
219  if ( m_bIsMatchVariantFormKanji ) nTransliterationFlags |= TransliterationFlags::ignoreTraditionalKanji_ja_JP;
220  if ( m_bIsMatchOldKanaForms ) nTransliterationFlags |= TransliterationFlags::ignoreTraditionalKana_ja_JP;
221  if ( m_bIsMatch_DiZi_DuZu ) nTransliterationFlags |= TransliterationFlags::ignoreZiZu_ja_JP;
222  if ( m_bIsMatch_BaVa_HaFa ) nTransliterationFlags |= TransliterationFlags::ignoreBaFa_ja_JP;
223  if ( m_bIsMatch_TsiThiChi_DhiZi ) nTransliterationFlags |= TransliterationFlags::ignoreTiJi_ja_JP;
224  if ( m_bIsMatch_HyuIyu_ByuVyu ) nTransliterationFlags |= TransliterationFlags::ignoreHyuByu_ja_JP;
225  if ( m_bIsMatch_SeShe_ZeJe ) nTransliterationFlags |= TransliterationFlags::ignoreSeZe_ja_JP;
226  if ( m_bIsMatch_IaIya ) nTransliterationFlags |= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP;
227  if ( m_bIsMatch_KiKu ) nTransliterationFlags |= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP;
228 
229  if ( m_bIsIgnorePunctuation ) nTransliterationFlags |= TransliterationFlags::ignoreSeparator_ja_JP;
230  if ( m_bIsIgnoreWhitespace ) nTransliterationFlags |= TransliterationFlags::ignoreSpace_ja_JP;
231  if ( m_bIsIgnoreProlongedSoundMark ) nTransliterationFlags |= TransliterationFlags::ignoreProlongedSoundMark_ja_JP;
232  if ( m_bIsIgnoreMiddleDot ) nTransliterationFlags |= TransliterationFlags::ignoreMiddleDot_ja_JP;
233  }
234 
236  {
237  // the search-for string
239 
240  // the search position
242 
243  // the transliteration flags
244 
245  m_bIsMatchCase = !( nTransliterationFlags & TransliterationFlags::IGNORE_CASE );
246  m_bIsMatchFullHalfWidthForms = bool( nTransliterationFlags & TransliterationFlags::IGNORE_WIDTH );
247  m_bIsMatchHiraganaKatakana = bool( nTransliterationFlags & TransliterationFlags::IGNORE_KANA );
248  m_bIsMatchContractions = bool( nTransliterationFlags & TransliterationFlags::ignoreSize_ja_JP );
249  m_bIsMatchMinusDashCho_on = bool( nTransliterationFlags & TransliterationFlags::ignoreMinusSign_ja_JP );
250  m_bIsMatchRepeatCharMarks = bool( nTransliterationFlags & TransliterationFlags::ignoreIterationMark_ja_JP );
251  m_bIsMatchVariantFormKanji = bool( nTransliterationFlags & TransliterationFlags::ignoreTraditionalKanji_ja_JP );
252  m_bIsMatchOldKanaForms = bool( nTransliterationFlags & TransliterationFlags::ignoreTraditionalKana_ja_JP );
253  m_bIsMatch_DiZi_DuZu = bool( nTransliterationFlags & TransliterationFlags::ignoreZiZu_ja_JP );
254  m_bIsMatch_BaVa_HaFa = bool( nTransliterationFlags & TransliterationFlags::ignoreBaFa_ja_JP );
255  m_bIsMatch_TsiThiChi_DhiZi = bool( nTransliterationFlags & TransliterationFlags::ignoreTiJi_ja_JP );
256  m_bIsMatch_HyuIyu_ByuVyu = bool( nTransliterationFlags & TransliterationFlags::ignoreHyuByu_ja_JP );
257  m_bIsMatch_SeShe_ZeJe = bool( nTransliterationFlags & TransliterationFlags::ignoreSeZe_ja_JP );
258  m_bIsMatch_IaIya = bool( nTransliterationFlags & TransliterationFlags::ignoreIandEfollowedByYa_ja_JP );
259  m_bIsMatch_KiKu = bool( nTransliterationFlags & TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP );
260 
261  m_bIsIgnorePunctuation = bool( nTransliterationFlags & TransliterationFlags::ignoreSeparator_ja_JP );
262  m_bIsIgnoreWhitespace = bool( nTransliterationFlags & TransliterationFlags::ignoreSpace_ja_JP );
263  m_bIsIgnoreProlongedSoundMark = bool( nTransliterationFlags & TransliterationFlags::ignoreProlongedSoundMark_ja_JP );
264  m_bIsIgnoreMiddleDot = bool( nTransliterationFlags & TransliterationFlags::ignoreMiddleDot_ja_JP );
265  }
266 
268  {
269  // ensure that the properties which are not stored directly are up-to-date
270  const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
271 
272  // and return our FmSearchParams part
273  return *this;
274  }
275 
277  {
278  // copy the FmSearchParams part
279  *static_cast< FmSearchParams* >( this ) = _rParams;
280 
281  // translate the settings not represented by a direct config value
283  }
284 
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define MATCHING_END
Definition: fmsrccfg.hxx:31
void registerExchangeLocation(const char *_pRelativePathAscii, void *_pContainer, const css::uno::Type &_rValueType)
osl::Mutex m_aMutex
css::uno::Sequence< OUString > aHistory
Definition: fmsrccfg.hxx:57
#define TA(c)
Definition: fmsrccfg.cxx:150
static const char * lcl_implMapIntValue(const sal_Int16 _nValue, const Ascii2Int16 *_pMap)
Definition: fmsrccfg.cxx:129
static sal_Int16 lcl_implMapAsciiValue(const OUString &_rAsciiValue, const Ascii2Int16 *_pMap)
Definition: fmsrccfg.cxx:112
TransliterationFlags nTransliterationFlags
Definition: fmsrccfg.hxx:51
NONE
const char * pAscii
Definition: fmsrccfg.cxx:81
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
TransliterationFlags
void setParams(const FmSearchParams &_rParams)
Definition: fmsrccfg.cxx:276
SVX_DLLPRIVATE void implTranslateToConfig()
Definition: fmsrccfg.cxx:235
static const Ascii2Int16 * lcl_getSearchPositionValueMap()
Definition: fmsrccfg.cxx:99
const FmSearchParams & getParams() const
Definition: fmsrccfg.cxx:267
bool isIgnoreWidthCJK() const
Definition: fmsrccfg.cxx:57
#define MATCHING_ANYWHERE
Definition: fmsrccfg.hxx:29
static const Ascii2Int16 * lcl_getSearchForTypeValueMap()
Definition: fmsrccfg.cxx:87
SVX_DLLPRIVATE void implTranslateFromConfig()
Definition: fmsrccfg.cxx:202
sal_Int16 nSearchForType
Definition: fmsrccfg.hxx:60
#define MATCHING_BEGINNING
Definition: fmsrccfg.hxx:30
Reference< XComponentContext > getProcessComponentContext()
#define SAL_WARN(area, stream)
class FmSearchEngine - Impl class for FmSearchDialog
#define MATCHING_WHOLETEXT
Definition: fmsrccfg.hxx:32
bool isCaseSensitive() const
Definition: fmsrccfg.cxx:62
void setCaseSensitive(bool _bCase)
Definition: fmsrccfg.cxx:67