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