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 <osl/diagnose.h>
28 #include <i18nutil/transliteration.hxx>
31 using namespace com::sun::star::uno
;
33 #define MAX_FLAGS_OFFSET 29
35 class SvtSearchOptions_Impl
: public ConfigItem
40 SvtSearchOptions_Impl(const SvtSearchOptions_Impl
&) = delete;
41 SvtSearchOptions_Impl
& operator=(const SvtSearchOptions_Impl
&) = delete;
44 virtual void ImplCommit() override
;
47 bool IsModified() const { return bModified
; }
48 using ConfigItem::SetModified
;
49 void SetModified( bool bVal
);
53 static Sequence
< OUString
> GetPropertyNames();
56 SvtSearchOptions_Impl();
57 virtual ~SvtSearchOptions_Impl() override
;
59 virtual void Notify( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
61 bool GetFlag( sal_uInt16 nOffset
) const;
62 void SetFlag( sal_uInt16 nOffset
, bool bVal
);
63 void SetSearchAlgorithm( sal_uInt16 nOffset
, bool bVal
);
66 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
67 ConfigItem( u
"Office.Common/SearchOptions"_ustr
),
68 nFlags(0x0003FFFF) // set all options values to 'true'
75 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
77 assert(!IsModified()); // should have been committed
80 void SvtSearchOptions_Impl::ImplCommit()
86 void SvtSearchOptions_Impl::Notify( const Sequence
< OUString
>& )
90 bool SvtSearchOptions_Impl::GetFlag( sal_uInt16 nOffset
) const
92 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
93 return ((nFlags
>> nOffset
) & 0x01) != 0;
96 void SvtSearchOptions_Impl::SetFlag( sal_uInt16 nOffset
, bool bVal
)
98 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
99 sal_Int32 nOldFlags
= nFlags
;
100 sal_Int32 nMask
= (sal_Int32(1)) << nOffset
;
105 if (nFlags
!= nOldFlags
)
109 void SvtSearchOptions_Impl::SetModified( bool bVal
)
114 ConfigItem::SetModified();
118 Sequence
< OUString
> SvtSearchOptions_Impl::GetPropertyNames()
120 static constexpr OUString aPropNames
[ MAX_FLAGS_OFFSET
+ 1 ] =
122 u
"IsWholeWordsOnly"_ustr
, // 0
123 u
"IsBackwards"_ustr
, // 1
124 u
"IsUseRegularExpression"_ustr
, // 2
125 //"IsCurrentSelectionOnly", // interactively set or not...
126 u
"IsSearchForStyles"_ustr
, // 3
127 u
"IsSimilaritySearch"_ustr
, // 4
128 u
"IsUseAsianOptions"_ustr
, // 5
129 u
"IsMatchCase"_ustr
, // 6
130 u
"Japanese/IsMatchFullHalfWidthForms"_ustr
, // 7
131 u
"Japanese/IsMatchHiraganaKatakana"_ustr
, // 8
132 u
"Japanese/IsMatchContractions"_ustr
, // 9
133 u
"Japanese/IsMatchMinusDashCho-on"_ustr
, // 10
134 u
"Japanese/IsMatchRepeatCharMarks"_ustr
, // 11
135 u
"Japanese/IsMatchVariantFormKanji"_ustr
, // 12
136 u
"Japanese/IsMatchOldKanaForms"_ustr
, // 13
137 u
"Japanese/IsMatch_DiZi_DuZu"_ustr
, // 14
138 u
"Japanese/IsMatch_BaVa_HaFa"_ustr
, // 15
139 u
"Japanese/IsMatch_TsiThiChi_DhiZi"_ustr
, // 16
140 u
"Japanese/IsMatch_HyuIyu_ByuVyu"_ustr
, // 17
141 u
"Japanese/IsMatch_SeShe_ZeJe"_ustr
, // 18
142 u
"Japanese/IsMatch_IaIya"_ustr
, // 19
143 u
"Japanese/IsMatch_KiKu"_ustr
, // 20
144 u
"Japanese/IsIgnorePunctuation"_ustr
, // 21
145 u
"Japanese/IsIgnoreWhitespace"_ustr
, // 22
146 u
"Japanese/IsIgnoreProlongedSoundMark"_ustr
, // 23
147 u
"Japanese/IsIgnoreMiddleDot"_ustr
, // 24
148 u
"IsNotes"_ustr
, // 25
149 u
"IsIgnoreDiacritics_CTL"_ustr
, // 26
150 u
"IsIgnoreKashida_CTL"_ustr
, // 27
151 u
"IsSearchFormatted"_ustr
, // 28
152 u
"IsUseWildcard"_ustr
// 29
155 Sequence
< OUString
> aNames(std::size(aPropNames
));
156 OUString
* pNames
= aNames
.getArray();
157 for (std::size_t i
= 0; i
< std::size(aPropNames
); ++i
)
158 pNames
[i
] = aPropNames
[i
];
163 void SvtSearchOptions_Impl::SetSearchAlgorithm( sal_uInt16 nOffset
, bool bVal
)
167 // Search algorithms are mutually exclusive.
168 if (nOffset
!= 2 && GetFlag(2))
170 if (nOffset
!= 4 && GetFlag(4))
172 if (nOffset
!= 29 && GetFlag(29))
173 SetFlag( 29, false );
175 SetFlag( nOffset
, bVal
);
178 void SvtSearchOptions_Impl::Load()
182 Sequence
< OUString
> aNames
= GetPropertyNames();
183 sal_Int32 nProps
= aNames
.getLength();
185 const Sequence
< Any
> aValues
= GetProperties( aNames
);
186 DBG_ASSERT( aValues
.getLength() == aNames
.getLength(),
187 "GetProperties failed" );
188 //EnableNotification( aNames );
190 if (nProps
&& aValues
.getLength() == nProps
)
194 const Any
* pValues
= aValues
.getConstArray();
195 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
197 const Any
&rVal
= pValues
[i
];
198 DBG_ASSERT( rVal
.hasValue(), "property value missing" );
204 if (i
<= MAX_FLAGS_OFFSET
)
206 // use index in sequence as flag index
210 OSL_FAIL( "unexpected index" );
215 OSL_FAIL( "unexpected type" );
221 OSL_FAIL( "value missing" );
226 DBG_ASSERT( bSucc
, "LoadConfig failed" );
229 bool SvtSearchOptions_Impl::Save()
233 const Sequence
< OUString
> aNames
= GetPropertyNames();
234 sal_Int32 nProps
= aNames
.getLength();
236 Sequence
< Any
> aValues( nProps
);
237 Any
*pValue
= aValues
.getArray();
239 DBG_ASSERT( nProps
== MAX_FLAGS_OFFSET
+ 1,
240 "unexpected size of index" );
241 if (nProps
== MAX_FLAGS_OFFSET
+ 1)
243 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
244 pValue
[i
] <<= GetFlag(i
);
245 bSucc
|= PutProperties( aNames
, aValues
);
249 SetModified( false );
254 SvtSearchOptions::SvtSearchOptions()
255 : pImpl( new SvtSearchOptions_Impl
)
259 SvtSearchOptions::~SvtSearchOptions()
263 void SvtSearchOptions::Commit()
268 TransliterationFlags
SvtSearchOptions::GetTransliterationFlags() const
270 TransliterationFlags nRes
= TransliterationFlags::NONE
;
272 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
273 nRes
|= TransliterationFlags::IGNORE_CASE
;
274 if ( IsMatchFullHalfWidthForms())
275 nRes
|= TransliterationFlags::IGNORE_WIDTH
;
276 if ( IsMatchHiraganaKatakana())
277 nRes
|= TransliterationFlags::IGNORE_KANA
;
278 if ( IsMatchContractions())
279 nRes
|= TransliterationFlags::ignoreSize_ja_JP
;
280 if ( IsMatchMinusDashChoon())
281 nRes
|= TransliterationFlags::ignoreMinusSign_ja_JP
;
282 if ( IsMatchRepeatCharMarks())
283 nRes
|= TransliterationFlags::ignoreIterationMark_ja_JP
;
284 if ( IsMatchVariantFormKanji())
285 nRes
|= TransliterationFlags::ignoreTraditionalKanji_ja_JP
;
286 if ( IsMatchOldKanaForms())
287 nRes
|= TransliterationFlags::ignoreTraditionalKana_ja_JP
;
288 if ( IsMatchDiziDuzu())
289 nRes
|= TransliterationFlags::ignoreZiZu_ja_JP
;
290 if ( IsMatchBavaHafa())
291 nRes
|= TransliterationFlags::ignoreBaFa_ja_JP
;
292 if ( IsMatchTsithichiDhizi())
293 nRes
|= TransliterationFlags::ignoreTiJi_ja_JP
;
294 if ( IsMatchHyuiyuByuvyu())
295 nRes
|= TransliterationFlags::ignoreHyuByu_ja_JP
;
296 if ( IsMatchSesheZeje())
297 nRes
|= TransliterationFlags::ignoreSeZe_ja_JP
;
299 nRes
|= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP
;
301 nRes
|= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP
;
302 if ( IsIgnorePunctuation())
303 nRes
|= TransliterationFlags::ignoreSeparator_ja_JP
;
304 if ( IsIgnoreWhitespace())
305 nRes
|= TransliterationFlags::ignoreSpace_ja_JP
;
306 if ( IsIgnoreProlongedSoundMark())
307 nRes
|= TransliterationFlags::ignoreProlongedSoundMark_ja_JP
;
308 if ( IsIgnoreMiddleDot())
309 nRes
|= TransliterationFlags::ignoreMiddleDot_ja_JP
;
310 if ( IsIgnoreDiacritics_CTL())
311 nRes
|= TransliterationFlags::IGNORE_DIACRITICS_CTL
;
312 if ( IsIgnoreKashida_CTL())
313 nRes
|= TransliterationFlags::IGNORE_KASHIDA_CTL
;
317 bool SvtSearchOptions::IsWholeWordsOnly() const
319 return pImpl
->GetFlag( 0 );
322 void SvtSearchOptions::SetWholeWordsOnly( bool bVal
)
324 pImpl
->SetFlag( 0, bVal
);
327 bool SvtSearchOptions::IsBackwards() const
329 return pImpl
->GetFlag( 1 );
332 void SvtSearchOptions::SetBackwards( bool bVal
)
334 pImpl
->SetFlag( 1, bVal
);
337 bool SvtSearchOptions::IsUseRegularExpression() const
339 return pImpl
->GetFlag( 2 );
342 void SvtSearchOptions::SetUseRegularExpression( bool bVal
)
344 pImpl
->SetSearchAlgorithm( 2, bVal
);
347 void SvtSearchOptions::SetSearchForStyles( bool bVal
)
349 pImpl
->SetFlag( 3, bVal
);
352 bool SvtSearchOptions::IsSimilaritySearch() const
354 return pImpl
->GetFlag( 4 );
357 void SvtSearchOptions::SetSimilaritySearch( bool bVal
)
359 pImpl
->SetSearchAlgorithm( 4, bVal
);
362 bool SvtSearchOptions::IsUseAsianOptions() const
364 return pImpl
->GetFlag( 5 );
367 void SvtSearchOptions::SetUseAsianOptions( bool bVal
)
369 pImpl
->SetFlag( 5, bVal
);
372 bool SvtSearchOptions::IsMatchCase() const
374 return pImpl
->GetFlag( 6 );
377 void SvtSearchOptions::SetMatchCase( bool bVal
)
379 pImpl
->SetFlag( 6, bVal
);
382 bool SvtSearchOptions::IsMatchFullHalfWidthForms() const
384 return pImpl
->GetFlag( 7 );
387 void SvtSearchOptions::SetMatchFullHalfWidthForms( bool bVal
)
389 pImpl
->SetFlag( 7, bVal
);
392 bool SvtSearchOptions::IsMatchHiraganaKatakana() const
394 return pImpl
->GetFlag( 8 );
397 void SvtSearchOptions::SetMatchHiraganaKatakana( bool bVal
)
399 pImpl
->SetFlag( 8, bVal
);
402 bool SvtSearchOptions::IsMatchContractions() const
404 return pImpl
->GetFlag( 9 );
407 void SvtSearchOptions::SetMatchContractions( bool bVal
)
409 pImpl
->SetFlag( 9, bVal
);
412 bool SvtSearchOptions::IsMatchMinusDashChoon() const
414 return pImpl
->GetFlag( 10 );
417 void SvtSearchOptions::SetMatchMinusDashChoon( bool bVal
)
419 pImpl
->SetFlag( 10, bVal
);
422 bool SvtSearchOptions::IsMatchRepeatCharMarks() const
424 return pImpl
->GetFlag( 11 );
427 void SvtSearchOptions::SetMatchRepeatCharMarks( bool bVal
)
429 pImpl
->SetFlag( 11, bVal
);
432 bool SvtSearchOptions::IsMatchVariantFormKanji() const
434 return pImpl
->GetFlag( 12 );
437 void SvtSearchOptions::SetMatchVariantFormKanji( bool bVal
)
439 pImpl
->SetFlag( 12, bVal
);
442 bool SvtSearchOptions::IsMatchOldKanaForms() const
444 return pImpl
->GetFlag( 13 );
447 void SvtSearchOptions::SetMatchOldKanaForms( bool bVal
)
449 pImpl
->SetFlag( 13, bVal
);
452 bool SvtSearchOptions::IsMatchDiziDuzu() const
454 return pImpl
->GetFlag( 14 );
457 void SvtSearchOptions::SetMatchDiziDuzu( bool bVal
)
459 pImpl
->SetFlag( 14, bVal
);
462 bool SvtSearchOptions::IsMatchBavaHafa() const
464 return pImpl
->GetFlag( 15 );
467 void SvtSearchOptions::SetMatchBavaHafa( bool bVal
)
469 pImpl
->SetFlag( 15, bVal
);
472 bool SvtSearchOptions::IsMatchTsithichiDhizi() const
474 return pImpl
->GetFlag( 16 );
477 void SvtSearchOptions::SetMatchTsithichiDhizi( bool bVal
)
479 pImpl
->SetFlag( 16, bVal
);
482 bool SvtSearchOptions::IsMatchHyuiyuByuvyu() const
484 return pImpl
->GetFlag( 17 );
487 void SvtSearchOptions::SetMatchHyuiyuByuvyu( bool bVal
)
489 pImpl
->SetFlag( 17, bVal
);
492 bool SvtSearchOptions::IsMatchSesheZeje() const
494 return pImpl
->GetFlag( 18 );
497 void SvtSearchOptions::SetMatchSesheZeje( bool bVal
)
499 pImpl
->SetFlag( 18, bVal
);
502 bool SvtSearchOptions::IsMatchIaiya() const
504 return pImpl
->GetFlag( 19 );
507 void SvtSearchOptions::SetMatchIaiya( bool bVal
)
509 pImpl
->SetFlag( 19, bVal
);
512 bool SvtSearchOptions::IsMatchKiku() const
514 return pImpl
->GetFlag( 20 );
517 void SvtSearchOptions::SetMatchKiku( bool bVal
)
519 pImpl
->SetFlag( 20, bVal
);
522 bool SvtSearchOptions::IsIgnorePunctuation() const
524 return pImpl
->GetFlag( 21 );
527 void SvtSearchOptions::SetIgnorePunctuation( bool bVal
)
529 pImpl
->SetFlag( 21, bVal
);
532 bool SvtSearchOptions::IsIgnoreWhitespace() const
534 return pImpl
->GetFlag( 22 );
537 void SvtSearchOptions::SetIgnoreWhitespace( bool bVal
)
539 pImpl
->SetFlag( 22, bVal
);
542 bool SvtSearchOptions::IsIgnoreProlongedSoundMark() const
544 return pImpl
->GetFlag( 23 );
547 void SvtSearchOptions::SetIgnoreProlongedSoundMark( bool bVal
)
549 pImpl
->SetFlag( 23, bVal
);
552 bool SvtSearchOptions::IsIgnoreMiddleDot() const
554 return pImpl
->GetFlag( 24 );
557 void SvtSearchOptions::SetIgnoreMiddleDot( bool bVal
)
559 pImpl
->SetFlag( 24, bVal
);
562 bool SvtSearchOptions::IsNotes() const
564 return pImpl
->GetFlag( 25 );
567 void SvtSearchOptions::SetNotes( bool bVal
)
569 pImpl
->SetFlag( 25, bVal
);
572 bool SvtSearchOptions::IsIgnoreDiacritics_CTL() const
574 return pImpl
->GetFlag( 26 );
577 void SvtSearchOptions::SetIgnoreDiacritics_CTL( bool bVal
)
579 pImpl
->SetFlag( 26, bVal
);
582 bool SvtSearchOptions::IsIgnoreKashida_CTL() const
584 return pImpl
->GetFlag( 27 );
587 void SvtSearchOptions::SetIgnoreKashida_CTL( bool bVal
)
589 pImpl
->SetFlag( 27, bVal
);
592 bool SvtSearchOptions::IsSearchFormatted() const
594 return pImpl
->GetFlag( 28 );
597 void SvtSearchOptions::SetSearchFormatted( bool bVal
)
599 pImpl
->SetFlag( 28, bVal
);
602 bool SvtSearchOptions::IsUseWildcard() const
604 return pImpl
->GetFlag( 29 );
607 void SvtSearchOptions::SetUseWildcard( bool bVal
)
609 pImpl
->SetSearchAlgorithm( 29, bVal
);
612 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */