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/uno/Sequence.hxx>
26 #include <com/sun/star/uno/Any.h>
27 #include <sal/macros.h>
28 #include <osl/diagnose.h>
29 #include <i18nutil/transliteration.hxx>
32 using namespace com::sun::star::uno
;
34 #define MAX_FLAGS_OFFSET 29
36 class SvtSearchOptions_Impl
: public ConfigItem
41 SvtSearchOptions_Impl(const SvtSearchOptions_Impl
&) = delete;
42 SvtSearchOptions_Impl
& operator=(const SvtSearchOptions_Impl
&) = delete;
45 virtual void ImplCommit() override
;
48 bool IsModified() const { return bModified
; }
49 using ConfigItem::SetModified
;
50 void SetModified( bool bVal
);
54 static Sequence
< OUString
> GetPropertyNames();
57 SvtSearchOptions_Impl();
58 virtual ~SvtSearchOptions_Impl() override
;
60 virtual void Notify( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
62 bool GetFlag( sal_uInt16 nOffset
) const;
63 void SetFlag( sal_uInt16 nOffset
, bool bVal
);
64 void SetSearchAlgorithm( sal_uInt16 nOffset
, bool bVal
);
67 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
68 ConfigItem( "Office.Common/SearchOptions" ),
69 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
152 "IsSearchFormatted", // 28
153 "IsUseWildcard" // 29
156 const int nCount
= SAL_N_ELEMENTS( aPropNames
);
157 Sequence
< OUString
> aNames( nCount
);
158 OUString
* pNames
= aNames
.getArray();
159 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
160 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
] );
165 void SvtSearchOptions_Impl::SetSearchAlgorithm( sal_uInt16 nOffset
, bool bVal
)
169 // Search algorithms are mutually exclusive.
170 if (nOffset
!= 2 && GetFlag(2))
172 if (nOffset
!= 4 && GetFlag(4))
174 if (nOffset
!= 29 && GetFlag(29))
175 SetFlag( 29, false );
177 SetFlag( nOffset
, bVal
);
180 void SvtSearchOptions_Impl::Load()
184 Sequence
< OUString
> aNames
= GetPropertyNames();
185 sal_Int32 nProps
= aNames
.getLength();
187 const Sequence
< Any
> aValues
= GetProperties( aNames
);
188 DBG_ASSERT( aValues
.getLength() == aNames
.getLength(),
189 "GetProperties failed" );
190 //EnableNotification( aNames );
192 if (nProps
&& aValues
.getLength() == nProps
)
196 const Any
* pValues
= aValues
.getConstArray();
197 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
199 const Any
&rVal
= pValues
[i
];
200 DBG_ASSERT( rVal
.hasValue(), "property value missing" );
206 if (i
<= MAX_FLAGS_OFFSET
)
208 // use index in sequence as flag index
212 OSL_FAIL( "unexpected index" );
217 OSL_FAIL( "unexpected type" );
223 OSL_FAIL( "value missing" );
228 DBG_ASSERT( bSucc
, "LoadConfig failed" );
231 bool SvtSearchOptions_Impl::Save()
235 const Sequence
< OUString
> aNames
= GetPropertyNames();
236 sal_Int32 nProps
= aNames
.getLength();
238 Sequence
< Any
> aValues( nProps
);
239 Any
*pValue
= aValues
.getArray();
241 DBG_ASSERT( nProps
== MAX_FLAGS_OFFSET
+ 1,
242 "unexpected size of index" );
243 if (nProps
== MAX_FLAGS_OFFSET
+ 1)
245 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
246 pValue
[i
] <<= GetFlag(i
);
247 bSucc
|= PutProperties( aNames
, aValues
);
251 SetModified( false );
256 SvtSearchOptions::SvtSearchOptions()
257 : pImpl( new SvtSearchOptions_Impl
)
261 SvtSearchOptions::~SvtSearchOptions()
265 void SvtSearchOptions::Commit()
270 TransliterationFlags
SvtSearchOptions::GetTransliterationFlags() const
272 TransliterationFlags nRes
= TransliterationFlags::NONE
;
274 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
275 nRes
|= TransliterationFlags::IGNORE_CASE
;
276 if ( IsMatchFullHalfWidthForms())
277 nRes
|= TransliterationFlags::IGNORE_WIDTH
;
278 if ( IsMatchHiraganaKatakana())
279 nRes
|= TransliterationFlags::IGNORE_KANA
;
280 if ( IsMatchContractions())
281 nRes
|= TransliterationFlags::ignoreSize_ja_JP
;
282 if ( IsMatchMinusDashChoon())
283 nRes
|= TransliterationFlags::ignoreMinusSign_ja_JP
;
284 if ( IsMatchRepeatCharMarks())
285 nRes
|= TransliterationFlags::ignoreIterationMark_ja_JP
;
286 if ( IsMatchVariantFormKanji())
287 nRes
|= TransliterationFlags::ignoreTraditionalKanji_ja_JP
;
288 if ( IsMatchOldKanaForms())
289 nRes
|= TransliterationFlags::ignoreTraditionalKana_ja_JP
;
290 if ( IsMatchDiziDuzu())
291 nRes
|= TransliterationFlags::ignoreZiZu_ja_JP
;
292 if ( IsMatchBavaHafa())
293 nRes
|= TransliterationFlags::ignoreBaFa_ja_JP
;
294 if ( IsMatchTsithichiDhizi())
295 nRes
|= TransliterationFlags::ignoreTiJi_ja_JP
;
296 if ( IsMatchHyuiyuByuvyu())
297 nRes
|= TransliterationFlags::ignoreHyuByu_ja_JP
;
298 if ( IsMatchSesheZeje())
299 nRes
|= TransliterationFlags::ignoreSeZe_ja_JP
;
301 nRes
|= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP
;
303 nRes
|= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP
;
304 if ( IsIgnorePunctuation())
305 nRes
|= TransliterationFlags::ignoreSeparator_ja_JP
;
306 if ( IsIgnoreWhitespace())
307 nRes
|= TransliterationFlags::ignoreSpace_ja_JP
;
308 if ( IsIgnoreProlongedSoundMark())
309 nRes
|= TransliterationFlags::ignoreProlongedSoundMark_ja_JP
;
310 if ( IsIgnoreMiddleDot())
311 nRes
|= TransliterationFlags::ignoreMiddleDot_ja_JP
;
312 if ( IsIgnoreDiacritics_CTL())
313 nRes
|= TransliterationFlags::IGNORE_DIACRITICS_CTL
;
314 if ( IsIgnoreKashida_CTL())
315 nRes
|= TransliterationFlags::IGNORE_KASHIDA_CTL
;
319 bool SvtSearchOptions::IsWholeWordsOnly() const
321 return pImpl
->GetFlag( 0 );
324 void SvtSearchOptions::SetWholeWordsOnly( bool bVal
)
326 pImpl
->SetFlag( 0, bVal
);
329 bool SvtSearchOptions::IsBackwards() const
331 return pImpl
->GetFlag( 1 );
334 void SvtSearchOptions::SetBackwards( bool bVal
)
336 pImpl
->SetFlag( 1, bVal
);
339 bool SvtSearchOptions::IsUseRegularExpression() const
341 return pImpl
->GetFlag( 2 );
344 void SvtSearchOptions::SetUseRegularExpression( bool bVal
)
346 pImpl
->SetSearchAlgorithm( 2, bVal
);
349 void SvtSearchOptions::SetSearchForStyles( bool bVal
)
351 pImpl
->SetFlag( 3, bVal
);
354 bool SvtSearchOptions::IsSimilaritySearch() const
356 return pImpl
->GetFlag( 4 );
359 void SvtSearchOptions::SetSimilaritySearch( bool bVal
)
361 pImpl
->SetSearchAlgorithm( 4, bVal
);
364 bool SvtSearchOptions::IsUseAsianOptions() const
366 return pImpl
->GetFlag( 5 );
369 void SvtSearchOptions::SetUseAsianOptions( bool bVal
)
371 pImpl
->SetFlag( 5, bVal
);
374 bool SvtSearchOptions::IsMatchCase() const
376 return pImpl
->GetFlag( 6 );
379 void SvtSearchOptions::SetMatchCase( bool bVal
)
381 pImpl
->SetFlag( 6, bVal
);
384 bool SvtSearchOptions::IsMatchFullHalfWidthForms() const
386 return pImpl
->GetFlag( 7 );
389 void SvtSearchOptions::SetMatchFullHalfWidthForms( bool bVal
)
391 pImpl
->SetFlag( 7, bVal
);
394 bool SvtSearchOptions::IsMatchHiraganaKatakana() const
396 return pImpl
->GetFlag( 8 );
399 void SvtSearchOptions::SetMatchHiraganaKatakana( bool bVal
)
401 pImpl
->SetFlag( 8, bVal
);
404 bool SvtSearchOptions::IsMatchContractions() const
406 return pImpl
->GetFlag( 9 );
409 void SvtSearchOptions::SetMatchContractions( bool bVal
)
411 pImpl
->SetFlag( 9, bVal
);
414 bool SvtSearchOptions::IsMatchMinusDashChoon() const
416 return pImpl
->GetFlag( 10 );
419 void SvtSearchOptions::SetMatchMinusDashChoon( bool bVal
)
421 pImpl
->SetFlag( 10, bVal
);
424 bool SvtSearchOptions::IsMatchRepeatCharMarks() const
426 return pImpl
->GetFlag( 11 );
429 void SvtSearchOptions::SetMatchRepeatCharMarks( bool bVal
)
431 pImpl
->SetFlag( 11, bVal
);
434 bool SvtSearchOptions::IsMatchVariantFormKanji() const
436 return pImpl
->GetFlag( 12 );
439 void SvtSearchOptions::SetMatchVariantFormKanji( bool bVal
)
441 pImpl
->SetFlag( 12, bVal
);
444 bool SvtSearchOptions::IsMatchOldKanaForms() const
446 return pImpl
->GetFlag( 13 );
449 void SvtSearchOptions::SetMatchOldKanaForms( bool bVal
)
451 pImpl
->SetFlag( 13, bVal
);
454 bool SvtSearchOptions::IsMatchDiziDuzu() const
456 return pImpl
->GetFlag( 14 );
459 void SvtSearchOptions::SetMatchDiziDuzu( bool bVal
)
461 pImpl
->SetFlag( 14, bVal
);
464 bool SvtSearchOptions::IsMatchBavaHafa() const
466 return pImpl
->GetFlag( 15 );
469 void SvtSearchOptions::SetMatchBavaHafa( bool bVal
)
471 pImpl
->SetFlag( 15, bVal
);
474 bool SvtSearchOptions::IsMatchTsithichiDhizi() const
476 return pImpl
->GetFlag( 16 );
479 void SvtSearchOptions::SetMatchTsithichiDhizi( bool bVal
)
481 pImpl
->SetFlag( 16, bVal
);
484 bool SvtSearchOptions::IsMatchHyuiyuByuvyu() const
486 return pImpl
->GetFlag( 17 );
489 void SvtSearchOptions::SetMatchHyuiyuByuvyu( bool bVal
)
491 pImpl
->SetFlag( 17, bVal
);
494 bool SvtSearchOptions::IsMatchSesheZeje() const
496 return pImpl
->GetFlag( 18 );
499 void SvtSearchOptions::SetMatchSesheZeje( bool bVal
)
501 pImpl
->SetFlag( 18, bVal
);
504 bool SvtSearchOptions::IsMatchIaiya() const
506 return pImpl
->GetFlag( 19 );
509 void SvtSearchOptions::SetMatchIaiya( bool bVal
)
511 pImpl
->SetFlag( 19, bVal
);
514 bool SvtSearchOptions::IsMatchKiku() const
516 return pImpl
->GetFlag( 20 );
519 void SvtSearchOptions::SetMatchKiku( bool bVal
)
521 pImpl
->SetFlag( 20, bVal
);
524 bool SvtSearchOptions::IsIgnorePunctuation() const
526 return pImpl
->GetFlag( 21 );
529 void SvtSearchOptions::SetIgnorePunctuation( bool bVal
)
531 pImpl
->SetFlag( 21, bVal
);
534 bool SvtSearchOptions::IsIgnoreWhitespace() const
536 return pImpl
->GetFlag( 22 );
539 void SvtSearchOptions::SetIgnoreWhitespace( bool bVal
)
541 pImpl
->SetFlag( 22, bVal
);
544 bool SvtSearchOptions::IsIgnoreProlongedSoundMark() const
546 return pImpl
->GetFlag( 23 );
549 void SvtSearchOptions::SetIgnoreProlongedSoundMark( bool bVal
)
551 pImpl
->SetFlag( 23, bVal
);
554 bool SvtSearchOptions::IsIgnoreMiddleDot() const
556 return pImpl
->GetFlag( 24 );
559 void SvtSearchOptions::SetIgnoreMiddleDot( bool bVal
)
561 pImpl
->SetFlag( 24, bVal
);
564 bool SvtSearchOptions::IsNotes() const
566 return pImpl
->GetFlag( 25 );
569 void SvtSearchOptions::SetNotes( bool bVal
)
571 pImpl
->SetFlag( 25, bVal
);
574 bool SvtSearchOptions::IsIgnoreDiacritics_CTL() const
576 return pImpl
->GetFlag( 26 );
579 void SvtSearchOptions::SetIgnoreDiacritics_CTL( bool bVal
)
581 pImpl
->SetFlag( 26, bVal
);
584 bool SvtSearchOptions::IsIgnoreKashida_CTL() const
586 return pImpl
->GetFlag( 27 );
589 void SvtSearchOptions::SetIgnoreKashida_CTL( bool bVal
)
591 pImpl
->SetFlag( 27, bVal
);
594 bool SvtSearchOptions::IsSearchFormatted() const
596 return pImpl
->GetFlag( 28 );
599 void SvtSearchOptions::SetSearchFormatted( bool bVal
)
601 pImpl
->SetFlag( 28, bVal
);
604 bool SvtSearchOptions::IsUseWildcard() const
606 return pImpl
->GetFlag( 29 );
609 void SvtSearchOptions::SetUseWildcard( bool bVal
)
611 pImpl
->SetSearchAlgorithm( 29, bVal
);
614 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */