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 <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>
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
43 SvtSearchOptions_Impl(const SvtSearchOptions_Impl
&) SAL_DELETED_FUNCTION
;
44 SvtSearchOptions_Impl
& operator=(const SvtSearchOptions_Impl
&) SAL_DELETED_FUNCTION
;
47 virtual void ImplCommit() SAL_OVERRIDE
;
50 bool IsModified() const { return bModified
; }
51 using ConfigItem::SetModified
;
52 void SetModified( bool bVal
);
56 static Sequence
< OUString
> GetPropertyNames();
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'
76 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
78 assert(!IsModified()); // should have been committed
81 void SvtSearchOptions_Impl::ImplCommit()
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
;
106 if (nFlags
!= nOldFlags
)
110 void SvtSearchOptions_Impl::SetModified( bool bVal
)
115 ConfigItem::SetModified();
119 Sequence
< OUString
> SvtSearchOptions_Impl::GetPropertyNames()
121 static const char* aPropNames
[ MAX_FLAGS_OFFSET
+ 1 ] =
123 "IsWholeWordsOnly", // 0
125 "IsUseRegularExpression", // 2
126 //"IsCurrentSelectionOnly", // interactively set or not...
127 "IsSearchForStyles", // 3
128 "IsSimilaritySearch", // 4
129 "IsUseAsianOptions", // 5
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
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
] );
163 bool SvtSearchOptions_Impl::Load()
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
)
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" );
189 if (i
<= MAX_FLAGS_OFFSET
)
191 // use index in sequence as flag index
195 OSL_FAIL( "unexpected index" );
200 OSL_FAIL( "unexpected type" );
206 OSL_FAIL( "value missing" );
211 DBG_ASSERT( bSucc
, "LoadConfig failed" );
216 bool SvtSearchOptions_Impl::Save()
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
);
236 SetModified( false );
241 SvtSearchOptions::SvtSearchOptions()
243 pImpl
= new SvtSearchOptions_Impl
;
246 SvtSearchOptions::~SvtSearchOptions()
251 void SvtSearchOptions::Commit()
256 sal_Int32
SvtSearchOptions::GetTransliterationFlags() const
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
;
287 nRes
|= TransliterationModules_ignoreIandEfollowedByYa_ja_JP
;
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
;
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: */