LibreOffice Module unotools (master) 1
searchopt.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 <sal/config.h>
21
23#include <tools/debug.hxx>
25#include <com/sun/star/uno/Sequence.hxx>
26#include <com/sun/star/uno/Any.h>
27#include <osl/diagnose.h>
29
30using namespace utl;
31using namespace com::sun::star::uno;
32
33#define MAX_FLAGS_OFFSET 29
34
36{
37 sal_Int32 nFlags;
39
42
43 // ConfigItem
44 virtual void ImplCommit() override;
45
46protected:
47 bool IsModified() const { return bModified; }
48 using ConfigItem::SetModified;
49 void SetModified( bool bVal );
50 void Load();
51 bool Save();
52
54
55public:
57 virtual ~SvtSearchOptions_Impl() override;
58
59 virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
60
61 bool GetFlag( sal_uInt16 nOffset ) const;
62 void SetFlag( sal_uInt16 nOffset, bool bVal );
63 void SetSearchAlgorithm( sal_uInt16 nOffset, bool bVal );
64};
65
67 ConfigItem( "Office.Common/SearchOptions" ),
68 nFlags(0x0003FFFF) // set all options values to 'true'
69
70{
71 Load();
72 SetModified( false );
73}
74
76{
77 assert(!IsModified()); // should have been committed
78}
79
81{
82 if (IsModified())
83 Save();
84}
85
87{
88}
89
90bool SvtSearchOptions_Impl::GetFlag( sal_uInt16 nOffset ) const
91{
92 DBG_ASSERT( nOffset <= MAX_FLAGS_OFFSET, "offset out of range");
93 return ((nFlags >> nOffset) & 0x01) != 0;
94}
95
96void SvtSearchOptions_Impl::SetFlag( sal_uInt16 nOffset, bool bVal )
97{
98 DBG_ASSERT( nOffset <= MAX_FLAGS_OFFSET, "offset out of range");
99 sal_Int32 nOldFlags = nFlags;
100 sal_Int32 nMask = (sal_Int32(1)) << nOffset;
101 if (bVal)
102 nFlags |= nMask;
103 else
104 nFlags &= ~nMask;
105 if (nFlags != nOldFlags)
106 SetModified( true );
107}
108
110{
111 bModified = bVal;
112 if (bModified)
113 {
114 ConfigItem::SetModified();
115 }
116}
117
119{
120 static const char* aPropNames[ MAX_FLAGS_OFFSET + 1 ] =
121 {
122 "IsWholeWordsOnly", // 0
123 "IsBackwards", // 1
124 "IsUseRegularExpression", // 2
125 //"IsCurrentSelectionOnly", // interactively set or not...
126 "IsSearchForStyles", // 3
127 "IsSimilaritySearch", // 4
128 "IsUseAsianOptions", // 5
129 "IsMatchCase", // 6
130 "Japanese/IsMatchFullHalfWidthForms", // 7
131 "Japanese/IsMatchHiraganaKatakana", // 8
132 "Japanese/IsMatchContractions", // 9
133 "Japanese/IsMatchMinusDashCho-on", // 10
134 "Japanese/IsMatchRepeatCharMarks", // 11
135 "Japanese/IsMatchVariantFormKanji", // 12
136 "Japanese/IsMatchOldKanaForms", // 13
137 "Japanese/IsMatch_DiZi_DuZu", // 14
138 "Japanese/IsMatch_BaVa_HaFa", // 15
139 "Japanese/IsMatch_TsiThiChi_DhiZi", // 16
140 "Japanese/IsMatch_HyuIyu_ByuVyu", // 17
141 "Japanese/IsMatch_SeShe_ZeJe", // 18
142 "Japanese/IsMatch_IaIya", // 19
143 "Japanese/IsMatch_KiKu", // 20
144 "Japanese/IsIgnorePunctuation", // 21
145 "Japanese/IsIgnoreWhitespace", // 22
146 "Japanese/IsIgnoreProlongedSoundMark", // 23
147 "Japanese/IsIgnoreMiddleDot", // 24
148 "IsNotes", // 25
149 "IsIgnoreDiacritics_CTL", // 26
150 "IsIgnoreKashida_CTL", // 27
151 "IsSearchFormatted", // 28
152 "IsUseWildcard" // 29
153 };
154
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] = OUString::createFromAscii( aPropNames[i] );
159
160 return aNames;
161}
162
163void SvtSearchOptions_Impl::SetSearchAlgorithm( sal_uInt16 nOffset, bool bVal )
164{
165 if (bVal)
166 {
167 // Search algorithms are mutually exclusive.
168 if (nOffset != 2 && GetFlag(2))
169 SetFlag( 2, false );
170 if (nOffset != 4 && GetFlag(4))
171 SetFlag( 4, false );
172 if (nOffset != 29 && GetFlag(29))
173 SetFlag( 29, false );
174 }
175 SetFlag( nOffset, bVal );
176}
177
179{
180 bool bSucc = false;
181
183 sal_Int32 nProps = aNames.getLength();
184
185 const Sequence< Any > aValues = GetProperties( aNames );
186 DBG_ASSERT( aValues.getLength() == aNames.getLength(),
187 "GetProperties failed" );
188 //EnableNotification( aNames );
189
190 if (nProps && aValues.getLength() == nProps)
191 {
192 bSucc = true;
193
194 const Any* pValues = aValues.getConstArray();
195 for (sal_Int32 i = 0; i < nProps; ++i)
196 {
197 const Any &rVal = pValues[i];
198 DBG_ASSERT( rVal.hasValue(), "property value missing" );
199 if (rVal.hasValue())
200 {
201 bool bVal = bool();
202 if (rVal >>= bVal)
203 {
204 if (i <= MAX_FLAGS_OFFSET)
205 {
206 // use index in sequence as flag index
207 SetFlag( i, bVal );
208 }
209 else {
210 OSL_FAIL( "unexpected index" );
211 }
212 }
213 else
214 {
215 OSL_FAIL( "unexpected type" );
216 bSucc = false;
217 }
218 }
219 else
220 {
221 OSL_FAIL( "value missing" );
222 bSucc = false;
223 }
224 }
225 }
226 DBG_ASSERT( bSucc, "LoadConfig failed" );
227}
228
230{
231 bool bSucc = false;
232
233 const Sequence< OUString > aNames = GetPropertyNames();
234 sal_Int32 nProps = aNames.getLength();
235
236 Sequence< Any > aValues( nProps );
237 Any *pValue = aValues.getArray();
238
239 DBG_ASSERT( nProps == MAX_FLAGS_OFFSET + 1,
240 "unexpected size of index" );
241 if (nProps == MAX_FLAGS_OFFSET + 1)
242 {
243 for (sal_Int32 i = 0; i < nProps; ++i)
244 pValue[i] <<= GetFlag(i);
245 bSucc |= PutProperties( aNames, aValues );
246 }
247
248 if (bSucc)
249 SetModified( false );
250
251 return bSucc;
252}
253
255 : pImpl( new SvtSearchOptions_Impl )
256{
257}
258
260{
261}
262
264{
265 pImpl->Commit();
266}
267
269{
270 TransliterationFlags nRes = TransliterationFlags::NONE;
271
272 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
273 nRes |= TransliterationFlags::IGNORE_CASE;
275 nRes |= TransliterationFlags::IGNORE_WIDTH;
277 nRes |= TransliterationFlags::IGNORE_KANA;
278 if ( IsMatchContractions())
279 nRes |= TransliterationFlags::ignoreSize_ja_JP;
281 nRes |= TransliterationFlags::ignoreMinusSign_ja_JP;
283 nRes |= TransliterationFlags::ignoreIterationMark_ja_JP;
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;
293 nRes |= TransliterationFlags::ignoreTiJi_ja_JP;
294 if ( IsMatchHyuiyuByuvyu())
295 nRes |= TransliterationFlags::ignoreHyuByu_ja_JP;
296 if ( IsMatchSesheZeje())
297 nRes |= TransliterationFlags::ignoreSeZe_ja_JP;
298 if ( IsMatchIaiya())
299 nRes |= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP;
300 if ( IsMatchKiku())
301 nRes |= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP;
302 if ( IsIgnorePunctuation())
303 nRes |= TransliterationFlags::ignoreSeparator_ja_JP;
304 if ( IsIgnoreWhitespace())
305 nRes |= TransliterationFlags::ignoreSpace_ja_JP;
307 nRes |= TransliterationFlags::ignoreProlongedSoundMark_ja_JP;
308 if ( IsIgnoreMiddleDot())
309 nRes |= TransliterationFlags::ignoreMiddleDot_ja_JP;
311 nRes |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
312 if ( IsIgnoreKashida_CTL())
313 nRes |= TransliterationFlags::IGNORE_KASHIDA_CTL;
314 return nRes;
315}
316
318{
319 return pImpl->GetFlag( 0 );
320}
321
323{
324 pImpl->SetFlag( 0, bVal );
325}
326
328{
329 return pImpl->GetFlag( 1 );
330}
331
333{
334 pImpl->SetFlag( 1, bVal );
335}
336
338{
339 return pImpl->GetFlag( 2 );
340}
341
343{
344 pImpl->SetSearchAlgorithm( 2, bVal );
345}
346
348{
349 pImpl->SetFlag( 3, bVal );
350}
351
353{
354 return pImpl->GetFlag( 4 );
355}
356
358{
359 pImpl->SetSearchAlgorithm( 4, bVal );
360}
361
363{
364 return pImpl->GetFlag( 5 );
365}
366
368{
369 pImpl->SetFlag( 5, bVal );
370}
371
373{
374 return pImpl->GetFlag( 6 );
375}
376
378{
379 pImpl->SetFlag( 6, bVal );
380}
381
383{
384 return pImpl->GetFlag( 7 );
385}
386
388{
389 pImpl->SetFlag( 7, bVal );
390}
391
393{
394 return pImpl->GetFlag( 8 );
395}
396
398{
399 pImpl->SetFlag( 8, bVal );
400}
401
403{
404 return pImpl->GetFlag( 9 );
405}
406
408{
409 pImpl->SetFlag( 9, bVal );
410}
411
413{
414 return pImpl->GetFlag( 10 );
415}
416
418{
419 pImpl->SetFlag( 10, bVal );
420}
421
423{
424 return pImpl->GetFlag( 11 );
425}
426
428{
429 pImpl->SetFlag( 11, bVal );
430}
431
433{
434 return pImpl->GetFlag( 12 );
435}
436
438{
439 pImpl->SetFlag( 12, bVal );
440}
441
443{
444 return pImpl->GetFlag( 13 );
445}
446
448{
449 pImpl->SetFlag( 13, bVal );
450}
451
453{
454 return pImpl->GetFlag( 14 );
455}
456
458{
459 pImpl->SetFlag( 14, bVal );
460}
461
463{
464 return pImpl->GetFlag( 15 );
465}
466
468{
469 pImpl->SetFlag( 15, bVal );
470}
471
473{
474 return pImpl->GetFlag( 16 );
475}
476
478{
479 pImpl->SetFlag( 16, bVal );
480}
481
483{
484 return pImpl->GetFlag( 17 );
485}
486
488{
489 pImpl->SetFlag( 17, bVal );
490}
491
493{
494 return pImpl->GetFlag( 18 );
495}
496
498{
499 pImpl->SetFlag( 18, bVal );
500}
501
503{
504 return pImpl->GetFlag( 19 );
505}
506
508{
509 pImpl->SetFlag( 19, bVal );
510}
511
513{
514 return pImpl->GetFlag( 20 );
515}
516
518{
519 pImpl->SetFlag( 20, bVal );
520}
521
523{
524 return pImpl->GetFlag( 21 );
525}
526
528{
529 pImpl->SetFlag( 21, bVal );
530}
531
533{
534 return pImpl->GetFlag( 22 );
535}
536
538{
539 pImpl->SetFlag( 22, bVal );
540}
541
543{
544 return pImpl->GetFlag( 23 );
545}
546
548{
549 pImpl->SetFlag( 23, bVal );
550}
551
553{
554 return pImpl->GetFlag( 24 );
555}
556
558{
559 pImpl->SetFlag( 24, bVal );
560}
561
563{
564 return pImpl->GetFlag( 25 );
565}
566
568{
569 pImpl->SetFlag( 25, bVal );
570}
571
573{
574 return pImpl->GetFlag( 26 );
575}
576
578{
579 pImpl->SetFlag( 26, bVal );
580}
581
583{
584 return pImpl->GetFlag( 27 );
585}
586
588{
589 pImpl->SetFlag( 27, bVal );
590}
591
593{
594 return pImpl->GetFlag( 28 );
595}
596
598{
599 pImpl->SetFlag( 28, bVal );
600}
601
603{
604 return pImpl->GetFlag( 29 );
605}
606
608{
609 pImpl->SetSearchAlgorithm( 29, bVal );
610}
611
612/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
static Sequence< OUString > GetPropertyNames()
Definition: searchopt.cxx:118
bool GetFlag(sal_uInt16 nOffset) const
Definition: searchopt.cxx:90
SvtSearchOptions_Impl & operator=(const SvtSearchOptions_Impl &)=delete
bool IsModified() const
Definition: searchopt.cxx:47
void SetFlag(sal_uInt16 nOffset, bool bVal)
Definition: searchopt.cxx:96
virtual void ImplCommit() override
writes the changed values into the sub tree.
Definition: searchopt.cxx:80
virtual ~SvtSearchOptions_Impl() override
Definition: searchopt.cxx:75
void SetSearchAlgorithm(sal_uInt16 nOffset, bool bVal)
Definition: searchopt.cxx:163
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
is called from the ConfigManager before application ends of from the PropertyChangeListener if the su...
Definition: searchopt.cxx:86
SvtSearchOptions_Impl(const SvtSearchOptions_Impl &)=delete
bool IsMatchBavaHafa() const
Definition: searchopt.cxx:462
bool IsMatchTsithichiDhizi() const
Definition: searchopt.cxx:472
bool IsMatchVariantFormKanji() const
Definition: searchopt.cxx:432
bool IsMatchIaiya() const
Definition: searchopt.cxx:502
bool IsMatchDiziDuzu() const
Definition: searchopt.cxx:452
void SetMatchVariantFormKanji(bool bVal)
Definition: searchopt.cxx:437
void SetSearchFormatted(bool bVal)
Definition: searchopt.cxx:597
void SetIgnoreKashida_CTL(bool bVal)
Definition: searchopt.cxx:587
void SetSimilaritySearch(bool bVal)
Definition: searchopt.cxx:357
bool IsMatchKiku() const
Definition: searchopt.cxx:512
bool IsMatchCase() const
Definition: searchopt.cxx:372
bool IsMatchHiraganaKatakana() const
Definition: searchopt.cxx:392
bool IsMatchFullHalfWidthForms() const
Definition: searchopt.cxx:382
bool IsIgnoreMiddleDot() const
Definition: searchopt.cxx:552
bool IsSearchFormatted() const
Definition: searchopt.cxx:592
void SetMatchHiraganaKatakana(bool bVal)
Definition: searchopt.cxx:397
bool IsWholeWordsOnly() const
Definition: searchopt.cxx:317
bool IsUseRegularExpression() const
Definition: searchopt.cxx:337
void SetUseWildcard(bool bVal)
Definition: searchopt.cxx:607
void SetMatchCase(bool bVal)
Definition: searchopt.cxx:377
bool IsIgnoreKashida_CTL() const
Definition: searchopt.cxx:582
bool IsMatchOldKanaForms() const
Definition: searchopt.cxx:442
void SetMatchBavaHafa(bool bVal)
Definition: searchopt.cxx:467
bool IsSimilaritySearch() const
Definition: searchopt.cxx:352
void SetMatchRepeatCharMarks(bool bVal)
Definition: searchopt.cxx:427
bool IsMatchContractions() const
Definition: searchopt.cxx:402
void SetMatchHyuiyuByuvyu(bool bVal)
Definition: searchopt.cxx:487
bool IsIgnorePunctuation() const
Definition: searchopt.cxx:522
bool IsUseWildcard() const
Definition: searchopt.cxx:602
void SetNotes(bool bVal)
Definition: searchopt.cxx:567
bool IsIgnoreProlongedSoundMark() const
Definition: searchopt.cxx:542
void SetIgnoreWhitespace(bool bVal)
Definition: searchopt.cxx:537
bool IsMatchRepeatCharMarks() const
Definition: searchopt.cxx:422
void SetMatchIaiya(bool bVal)
Definition: searchopt.cxx:507
void SetMatchSesheZeje(bool bVal)
Definition: searchopt.cxx:497
void SetUseAsianOptions(bool bVal)
Definition: searchopt.cxx:367
void SetWholeWordsOnly(bool bVal)
Definition: searchopt.cxx:322
void SetMatchContractions(bool bVal)
Definition: searchopt.cxx:407
bool IsIgnoreDiacritics_CTL() const
Definition: searchopt.cxx:572
bool IsIgnoreWhitespace() const
Definition: searchopt.cxx:532
void SetMatchKiku(bool bVal)
Definition: searchopt.cxx:517
bool IsMatchHyuiyuByuvyu() const
Definition: searchopt.cxx:482
void SetUseRegularExpression(bool bVal)
Definition: searchopt.cxx:342
bool IsBackwards() const
Definition: searchopt.cxx:327
void SetBackwards(bool bVal)
Definition: searchopt.cxx:332
void SetMatchFullHalfWidthForms(bool bVal)
Definition: searchopt.cxx:387
void SetMatchMinusDashChoon(bool bVal)
Definition: searchopt.cxx:417
std::unique_ptr< SvtSearchOptions_Impl > pImpl
Definition: searchopt.hxx:31
bool IsMatchMinusDashChoon() const
Definition: searchopt.cxx:412
void SetMatchOldKanaForms(bool bVal)
Definition: searchopt.cxx:447
void SetIgnoreMiddleDot(bool bVal)
Definition: searchopt.cxx:557
void SetIgnoreProlongedSoundMark(bool bVal)
Definition: searchopt.cxx:547
bool IsNotes() const
Definition: searchopt.cxx:562
void SetIgnoreDiacritics_CTL(bool bVal)
Definition: searchopt.cxx:577
bool IsMatchSesheZeje() const
Definition: searchopt.cxx:492
void SetSearchForStyles(bool bVal)
Definition: searchopt.cxx:347
void SetIgnorePunctuation(bool bVal)
Definition: searchopt.cxx:527
void SetMatchTsithichiDhizi(bool bVal)
Definition: searchopt.cxx:477
TransliterationFlags GetTransliterationFlags() const
Definition: searchopt.cxx:268
bool IsUseAsianOptions() const
Definition: searchopt.cxx:362
void SetMatchDiziDuzu(bool bVal)
Definition: searchopt.cxx:457
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
bool PutProperties(const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues)
#define DBG_ASSERT(sCon, aError)
int i
const PropertyStruct aPropNames[]
#define MAX_FLAGS_OFFSET
Definition: searchopt.cxx:33
TransliterationFlags