update emoji autocorrect entries from po-files
[LibreOffice.git] / unotools / source / config / searchopt.cxx
blob97bd3962efb21e65caee87d7b28b1b9d779fda75
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 <sal/config.h>
22 #include <unotools/searchopt.hxx>
23 #include <tools/debug.hxx>
24 #include <unotools/configitem.hxx>
25 #include <com/sun/star/i18n/TransliterationModules.hpp>
26 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/Any.h>
29 #include <sal/macros.h>
30 #include <osl/diagnose.h>
32 using namespace utl;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::i18n;
36 #define MAX_FLAGS_OFFSET 27
38 class SvtSearchOptions_Impl : public ConfigItem
40 sal_Int32 nFlags;
41 bool bModified;
43 SvtSearchOptions_Impl(const SvtSearchOptions_Impl&) SAL_DELETED_FUNCTION;
44 SvtSearchOptions_Impl& operator=(const SvtSearchOptions_Impl&) SAL_DELETED_FUNCTION;
46 // ConfigItem
47 virtual void ImplCommit() SAL_OVERRIDE;
49 protected:
50 bool IsModified() const { return bModified; }
51 using ConfigItem::SetModified;
52 void SetModified( bool bVal );
53 bool Load();
54 bool Save();
56 static Sequence< OUString > GetPropertyNames();
58 public:
59 SvtSearchOptions_Impl();
60 virtual ~SvtSearchOptions_Impl();
62 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
64 bool GetFlag( sal_uInt16 nOffset ) const;
65 void SetFlag( sal_uInt16 nOffset, bool bVal );
68 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
69 ConfigItem( OUString("Office.Common/SearchOptions") )
71 nFlags = 0x0003FFFF; // set all options values to 'true'
72 Load();
73 SetModified( false );
76 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
78 assert(!IsModified()); // should have been committed
81 void SvtSearchOptions_Impl::ImplCommit()
83 if (IsModified())
84 Save();
87 void SvtSearchOptions_Impl::Notify( const Sequence< OUString >& )
91 bool SvtSearchOptions_Impl::GetFlag( sal_uInt16 nOffset ) const
93 DBG_ASSERT( nOffset <= MAX_FLAGS_OFFSET, "offset out of range");
94 return ((nFlags >> nOffset) & 0x01) != 0;
97 void SvtSearchOptions_Impl::SetFlag( sal_uInt16 nOffset, bool bVal )
99 DBG_ASSERT( nOffset <= MAX_FLAGS_OFFSET, "offset out of range");
100 sal_Int32 nOldFlags = nFlags;
101 sal_Int32 nMask = ((sal_Int32) 1) << nOffset;
102 if (bVal)
103 nFlags |= nMask;
104 else
105 nFlags &= ~nMask;
106 if (nFlags != nOldFlags)
107 SetModified( true );
110 void SvtSearchOptions_Impl::SetModified( bool bVal )
112 bModified = bVal;
113 if (bModified)
115 ConfigItem::SetModified();
119 Sequence< OUString > SvtSearchOptions_Impl::GetPropertyNames()
121 static const char* aPropNames[ MAX_FLAGS_OFFSET + 1 ] =
123 "IsWholeWordsOnly", // 0
124 "IsBackwards", // 1
125 "IsUseRegularExpression", // 2
126 //"IsCurrentSelectionOnly", // interactively set or not...
127 "IsSearchForStyles", // 3
128 "IsSimilaritySearch", // 4
129 "IsUseAsianOptions", // 5
130 "IsMatchCase", // 6
131 "Japanese/IsMatchFullHalfWidthForms", // 7
132 "Japanese/IsMatchHiraganaKatakana", // 8
133 "Japanese/IsMatchContractions", // 9
134 "Japanese/IsMatchMinusDashCho-on", // 10
135 "Japanese/IsMatchRepeatCharMarks", // 11
136 "Japanese/IsMatchVariantFormKanji", // 12
137 "Japanese/IsMatchOldKanaForms", // 13
138 "Japanese/IsMatch_DiZi_DuZu", // 14
139 "Japanese/IsMatch_BaVa_HaFa", // 15
140 "Japanese/IsMatch_TsiThiChi_DhiZi", // 16
141 "Japanese/IsMatch_HyuIyu_ByuVyu", // 17
142 "Japanese/IsMatch_SeShe_ZeJe", // 18
143 "Japanese/IsMatch_IaIya", // 19
144 "Japanese/IsMatch_KiKu", // 20
145 "Japanese/IsIgnorePunctuation", // 21
146 "Japanese/IsIgnoreWhitespace", // 22
147 "Japanese/IsIgnoreProlongedSoundMark", // 23
148 "Japanese/IsIgnoreMiddleDot", // 24
149 "IsNotes", // 25
150 "IsIgnoreDiacritics_CTL", // 26
151 "IsIgnoreKashida_CTL" // 27
154 const int nCount = SAL_N_ELEMENTS( aPropNames );
155 Sequence< OUString > aNames( nCount );
156 OUString* pNames = aNames.getArray();
157 for (sal_Int32 i = 0; i < nCount; ++i)
158 pNames[i] = OUString::createFromAscii( aPropNames[i] );
160 return aNames;
163 bool SvtSearchOptions_Impl::Load()
165 bool bSucc = false;
167 Sequence< OUString > aNames = GetPropertyNames();
168 sal_Int32 nProps = aNames.getLength();
170 const Sequence< Any > aValues = GetProperties( aNames );
171 DBG_ASSERT( aValues.getLength() == aNames.getLength(),
172 "GetProperties failed" );
173 //EnableNotification( aNames );
175 if (nProps && aValues.getLength() == nProps)
177 bSucc = true;
179 const Any* pValues = aValues.getConstArray();
180 for (sal_uInt16 i = 0; i < nProps; ++i)
182 const Any &rVal = pValues[i];
183 DBG_ASSERT( rVal.hasValue(), "property value missing" );
184 if (rVal.hasValue())
186 bool bVal = bool();
187 if (rVal >>= bVal)
189 if (i <= MAX_FLAGS_OFFSET)
191 // use index in sequence as flag index
192 SetFlag( i, bVal );
194 else {
195 OSL_FAIL( "unexpected index" );
198 else
200 OSL_FAIL( "unexpected type" );
201 bSucc = false;
204 else
206 OSL_FAIL( "value missing" );
207 bSucc = false;
211 DBG_ASSERT( bSucc, "LoadConfig failed" );
213 return bSucc;
216 bool SvtSearchOptions_Impl::Save()
218 bool bSucc = false;
220 const Sequence< OUString > aNames = GetPropertyNames();
221 sal_Int32 nProps = aNames.getLength();
223 Sequence< Any > aValues( nProps );
224 Any *pValue = aValues.getArray();
226 DBG_ASSERT( nProps == MAX_FLAGS_OFFSET + 1,
227 "unexpected size of index" );
228 if (nProps && nProps == MAX_FLAGS_OFFSET + 1)
230 for (sal_uInt16 i = 0; i < nProps; ++i)
231 pValue[i] <<= GetFlag(i);
232 bSucc |= PutProperties( aNames, aValues );
235 if (bSucc)
236 SetModified( false );
238 return bSucc;
241 SvtSearchOptions::SvtSearchOptions()
243 pImpl = new SvtSearchOptions_Impl;
246 SvtSearchOptions::~SvtSearchOptions()
248 delete pImpl;
251 void SvtSearchOptions::Commit()
253 pImpl->Commit();
256 sal_Int32 SvtSearchOptions::GetTransliterationFlags() const
258 sal_Int32 nRes = 0;
260 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
261 nRes |= TransliterationModules_IGNORE_CASE;
262 if ( IsMatchFullHalfWidthForms())
263 nRes |= TransliterationModules_IGNORE_WIDTH;
264 if ( IsMatchHiraganaKatakana())
265 nRes |= TransliterationModules_IGNORE_KANA;
266 if ( IsMatchContractions())
267 nRes |= TransliterationModules_ignoreSize_ja_JP;
268 if ( IsMatchMinusDashChoon())
269 nRes |= TransliterationModules_ignoreMinusSign_ja_JP;
270 if ( IsMatchRepeatCharMarks())
271 nRes |= TransliterationModules_ignoreIterationMark_ja_JP;
272 if ( IsMatchVariantFormKanji())
273 nRes |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
274 if ( IsMatchOldKanaForms())
275 nRes |= TransliterationModules_ignoreTraditionalKana_ja_JP;
276 if ( IsMatchDiziDuzu())
277 nRes |= TransliterationModules_ignoreZiZu_ja_JP;
278 if ( IsMatchBavaHafa())
279 nRes |= TransliterationModules_ignoreBaFa_ja_JP;
280 if ( IsMatchTsithichiDhizi())
281 nRes |= TransliterationModules_ignoreTiJi_ja_JP;
282 if ( IsMatchHyuiyuByuvyu())
283 nRes |= TransliterationModules_ignoreHyuByu_ja_JP;
284 if ( IsMatchSesheZeje())
285 nRes |= TransliterationModules_ignoreSeZe_ja_JP;
286 if ( IsMatchIaiya())
287 nRes |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
288 if ( IsMatchKiku())
289 nRes |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
290 if ( IsIgnorePunctuation())
291 nRes |= TransliterationModules_ignoreSeparator_ja_JP;
292 if ( IsIgnoreWhitespace())
293 nRes |= TransliterationModules_ignoreSpace_ja_JP;
294 if ( IsIgnoreProlongedSoundMark())
295 nRes |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
296 if ( IsIgnoreMiddleDot())
297 nRes |= TransliterationModules_ignoreMiddleDot_ja_JP;
298 if ( IsIgnoreDiacritics_CTL())
299 nRes |= TransliterationModulesExtra::IGNORE_DIACRITICS_CTL;
300 if ( IsIgnoreKashida_CTL())
301 nRes |= TransliterationModulesExtra::IGNORE_KASHIDA_CTL;
302 return nRes;
305 bool SvtSearchOptions::IsWholeWordsOnly() const
307 return pImpl->GetFlag( 0 );
310 void SvtSearchOptions::SetWholeWordsOnly( bool bVal )
312 pImpl->SetFlag( 0, bVal );
315 bool SvtSearchOptions::IsBackwards() const
317 return pImpl->GetFlag( 1 );
320 void SvtSearchOptions::SetBackwards( bool bVal )
322 pImpl->SetFlag( 1, bVal );
325 bool SvtSearchOptions::IsUseRegularExpression() const
327 return pImpl->GetFlag( 2 );
330 void SvtSearchOptions::SetUseRegularExpression( bool bVal )
332 pImpl->SetFlag( 2, bVal );
335 void SvtSearchOptions::SetSearchForStyles( bool bVal )
337 pImpl->SetFlag( 3, bVal );
340 bool SvtSearchOptions::IsSimilaritySearch() const
342 return pImpl->GetFlag( 4 );
345 void SvtSearchOptions::SetSimilaritySearch( bool bVal )
347 pImpl->SetFlag( 4, bVal );
350 bool SvtSearchOptions::IsUseAsianOptions() const
352 return pImpl->GetFlag( 5 );
355 void SvtSearchOptions::SetUseAsianOptions( bool bVal )
357 pImpl->SetFlag( 5, bVal );
360 bool SvtSearchOptions::IsMatchCase() const
362 return pImpl->GetFlag( 6 );
365 void SvtSearchOptions::SetMatchCase( bool bVal )
367 pImpl->SetFlag( 6, bVal );
370 bool SvtSearchOptions::IsMatchFullHalfWidthForms() const
372 return pImpl->GetFlag( 7 );
375 void SvtSearchOptions::SetMatchFullHalfWidthForms( bool bVal )
377 pImpl->SetFlag( 7, bVal );
380 bool SvtSearchOptions::IsMatchHiraganaKatakana() const
382 return pImpl->GetFlag( 8 );
385 void SvtSearchOptions::SetMatchHiraganaKatakana( bool bVal )
387 pImpl->SetFlag( 8, bVal );
390 bool SvtSearchOptions::IsMatchContractions() const
392 return pImpl->GetFlag( 9 );
395 void SvtSearchOptions::SetMatchContractions( bool bVal )
397 pImpl->SetFlag( 9, bVal );
400 bool SvtSearchOptions::IsMatchMinusDashChoon() const
402 return pImpl->GetFlag( 10 );
405 void SvtSearchOptions::SetMatchMinusDashChoon( bool bVal )
407 pImpl->SetFlag( 10, bVal );
410 bool SvtSearchOptions::IsMatchRepeatCharMarks() const
412 return pImpl->GetFlag( 11 );
415 void SvtSearchOptions::SetMatchRepeatCharMarks( bool bVal )
417 pImpl->SetFlag( 11, bVal );
420 bool SvtSearchOptions::IsMatchVariantFormKanji() const
422 return pImpl->GetFlag( 12 );
425 void SvtSearchOptions::SetMatchVariantFormKanji( bool bVal )
427 pImpl->SetFlag( 12, bVal );
430 bool SvtSearchOptions::IsMatchOldKanaForms() const
432 return pImpl->GetFlag( 13 );
435 void SvtSearchOptions::SetMatchOldKanaForms( bool bVal )
437 pImpl->SetFlag( 13, bVal );
440 bool SvtSearchOptions::IsMatchDiziDuzu() const
442 return pImpl->GetFlag( 14 );
445 void SvtSearchOptions::SetMatchDiziDuzu( bool bVal )
447 pImpl->SetFlag( 14, bVal );
450 bool SvtSearchOptions::IsMatchBavaHafa() const
452 return pImpl->GetFlag( 15 );
455 void SvtSearchOptions::SetMatchBavaHafa( bool bVal )
457 pImpl->SetFlag( 15, bVal );
460 bool SvtSearchOptions::IsMatchTsithichiDhizi() const
462 return pImpl->GetFlag( 16 );
465 void SvtSearchOptions::SetMatchTsithichiDhizi( bool bVal )
467 pImpl->SetFlag( 16, bVal );
470 bool SvtSearchOptions::IsMatchHyuiyuByuvyu() const
472 return pImpl->GetFlag( 17 );
475 void SvtSearchOptions::SetMatchHyuiyuByuvyu( bool bVal )
477 pImpl->SetFlag( 17, bVal );
480 bool SvtSearchOptions::IsMatchSesheZeje() const
482 return pImpl->GetFlag( 18 );
485 void SvtSearchOptions::SetMatchSesheZeje( bool bVal )
487 pImpl->SetFlag( 18, bVal );
490 bool SvtSearchOptions::IsMatchIaiya() const
492 return pImpl->GetFlag( 19 );
495 void SvtSearchOptions::SetMatchIaiya( bool bVal )
497 pImpl->SetFlag( 19, bVal );
500 bool SvtSearchOptions::IsMatchKiku() const
502 return pImpl->GetFlag( 20 );
505 void SvtSearchOptions::SetMatchKiku( bool bVal )
507 pImpl->SetFlag( 20, bVal );
510 bool SvtSearchOptions::IsIgnorePunctuation() const
512 return pImpl->GetFlag( 21 );
515 void SvtSearchOptions::SetIgnorePunctuation( bool bVal )
517 pImpl->SetFlag( 21, bVal );
520 bool SvtSearchOptions::IsIgnoreWhitespace() const
522 return pImpl->GetFlag( 22 );
525 void SvtSearchOptions::SetIgnoreWhitespace( bool bVal )
527 pImpl->SetFlag( 22, bVal );
530 bool SvtSearchOptions::IsIgnoreProlongedSoundMark() const
532 return pImpl->GetFlag( 23 );
535 void SvtSearchOptions::SetIgnoreProlongedSoundMark( bool bVal )
537 pImpl->SetFlag( 23, bVal );
540 bool SvtSearchOptions::IsIgnoreMiddleDot() const
542 return pImpl->GetFlag( 24 );
545 void SvtSearchOptions::SetIgnoreMiddleDot( bool bVal )
547 pImpl->SetFlag( 24, bVal );
550 bool SvtSearchOptions::IsNotes() const
552 return pImpl->GetFlag( 25 );
555 void SvtSearchOptions::SetNotes( bool bVal )
557 pImpl->SetFlag( 25, bVal );
560 bool SvtSearchOptions::IsIgnoreDiacritics_CTL() const
562 return pImpl->GetFlag( 26 );
565 void SvtSearchOptions::SetIgnoreDiacritics_CTL( bool bVal )
567 pImpl->SetFlag( 26, bVal );
570 bool SvtSearchOptions::IsIgnoreKashida_CTL() const
572 return pImpl->GetFlag( 27 );
575 void SvtSearchOptions::SetIgnoreKashida_CTL( bool bVal )
577 pImpl->SetFlag( 27, bVal );
580 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */