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 .
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/uno/Sequence.hxx>
27 #include <com/sun/star/uno/Any.h>
28 #include <rtl/logfile.hxx>
29 #include <sal/macros.h>
33 using namespace com::sun::star::uno
;
34 using namespace com::sun::star::i18n
;
37 #define MAX_FLAGS_OFFSET 25
39 //////////////////////////////////////////////////////////////////////
42 class SvtSearchOptions_Impl
: public ConfigItem
47 // disallow copy-constructor and assignment-operator for now
48 SvtSearchOptions_Impl( const SvtSearchOptions_Impl
& );
49 SvtSearchOptions_Impl
& operator = ( const SvtSearchOptions_Impl
& );
52 sal_Bool
IsModified() const { return bModified
; }
53 using ConfigItem::SetModified
;
54 void SetModified( sal_Bool bVal
);
58 Sequence
< OUString
> GetPropertyNames() const;
61 SvtSearchOptions_Impl();
62 virtual ~SvtSearchOptions_Impl();
65 virtual void Commit();
66 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& aPropertyNames
);
68 sal_Bool
GetFlag( sal_uInt16 nOffset
) const;
69 void SetFlag( sal_uInt16 nOffset
, sal_Bool bVal
);
74 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
75 ConfigItem( OUString("Office.Common/SearchOptions") )
77 RTL_LOGFILE_CONTEXT(aLog
, "unotools SvtSearchOptions_Impl::SvtSearchOptions_Impl()");
78 nFlags
= 0x0003FFFF; // set all options values to 'true'
80 SetModified( sal_False
);
84 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
90 void SvtSearchOptions_Impl::Commit()
96 void SvtSearchOptions_Impl::Notify( const Sequence
< OUString
>& )
101 sal_Bool
SvtSearchOptions_Impl::GetFlag( sal_uInt16 nOffset
) const
103 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
104 return ((nFlags
>> nOffset
) & 0x01) ? sal_True
: sal_False
;
108 void SvtSearchOptions_Impl::SetFlag( sal_uInt16 nOffset
, sal_Bool bVal
)
110 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
111 sal_Int32 nOldFlags
= nFlags
;
112 sal_Int32 nMask
= ((sal_Int32
) 1) << nOffset
;
117 if (nFlags
!= nOldFlags
)
118 SetModified( sal_True
);
122 void SvtSearchOptions_Impl::SetModified( sal_Bool bVal
)
127 ConfigItem::SetModified();
132 Sequence
< OUString
> SvtSearchOptions_Impl::GetPropertyNames() const
134 static const char* aPropNames
[ MAX_FLAGS_OFFSET
+ 1 ] =
136 "IsWholeWordsOnly", // 0
138 "IsUseRegularExpression", // 2
139 //"IsCurrentSelectionOnly", // interactively set or not...
140 "IsSearchForStyles", // 3
141 "IsSimilaritySearch", // 4
142 "IsUseAsianOptions", // 5
144 "Japanese/IsMatchFullHalfWidthForms", // 7
145 "Japanese/IsMatchHiraganaKatakana", // 8
146 "Japanese/IsMatchContractions", // 9
147 "Japanese/IsMatchMinusDashCho-on", // 10
148 "Japanese/IsMatchRepeatCharMarks", // 11
149 "Japanese/IsMatchVariantFormKanji", // 12
150 "Japanese/IsMatchOldKanaForms", // 13
151 "Japanese/IsMatch_DiZi_DuZu", // 14
152 "Japanese/IsMatch_BaVa_HaFa", // 15
153 "Japanese/IsMatch_TsiThiChi_DhiZi", // 16
154 "Japanese/IsMatch_HyuIyu_ByuVyu", // 17
155 "Japanese/IsMatch_SeShe_ZeJe", // 18
156 "Japanese/IsMatch_IaIya", // 19
157 "Japanese/IsMatch_KiKu", // 20
158 "Japanese/IsIgnorePunctuation", // 21
159 "Japanese/IsIgnoreWhitespace", // 22
160 "Japanese/IsIgnoreProlongedSoundMark", // 23
161 "Japanese/IsIgnoreMiddleDot", // 24
165 const int nCount
= SAL_N_ELEMENTS( aPropNames
);
166 Sequence
< OUString
> aNames( nCount
);
167 OUString
* pNames
= aNames
.getArray();
168 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
169 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
] );
175 sal_Bool
SvtSearchOptions_Impl::Load()
177 sal_Bool bSucc
= sal_False
;
179 Sequence
< OUString
> aNames
= GetPropertyNames();
180 sal_Int32 nProps
= aNames
.getLength();
182 const Sequence
< Any
> aValues
= GetProperties( aNames
);
183 DBG_ASSERT( aValues
.getLength() == aNames
.getLength(),
184 "GetProperties failed" );
185 //EnableNotification( aNames );
187 if (nProps
&& aValues
.getLength() == nProps
)
191 const Any
* pValues
= aValues
.getConstArray();
192 for (sal_uInt16 i
= 0; i
< nProps
; ++i
)
194 const Any
&rVal
= pValues
[i
];
195 DBG_ASSERT( rVal
.hasValue(), "property value missing" );
198 sal_Bool bVal
= sal_Bool();
201 if (i
<= MAX_FLAGS_OFFSET
)
203 // use index in sequence as flag index
207 OSL_FAIL( "unexpected index" );
212 OSL_FAIL( "unexpected type" );
218 OSL_FAIL( "value missing" );
223 DBG_ASSERT( bSucc
, "LoadConfig failed" );
229 sal_Bool
SvtSearchOptions_Impl::Save()
231 sal_Bool bSucc
= sal_False
;
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
&& nProps
== MAX_FLAGS_OFFSET
+ 1)
243 for (sal_uInt16 i
= 0; i
< nProps
; ++i
)
244 pValue
[i
] <<= (sal_Bool
) GetFlag(i
);
245 bSucc
|= PutProperties( aNames
, aValues
);
249 SetModified( sal_False
);
255 //////////////////////////////////////////////////////////////////////
257 SvtSearchOptions::SvtSearchOptions()
259 pImpl
= new SvtSearchOptions_Impl
;
263 SvtSearchOptions::~SvtSearchOptions()
269 sal_Int32
SvtSearchOptions::GetTransliterationFlags() const
273 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
274 nRes
|= TransliterationModules_IGNORE_CASE
;
275 if ( IsMatchFullHalfWidthForms())
276 nRes
|= TransliterationModules_IGNORE_WIDTH
;
277 if ( IsMatchHiraganaKatakana())
278 nRes
|= TransliterationModules_IGNORE_KANA
;
279 if ( IsMatchContractions())
280 nRes
|= TransliterationModules_ignoreSize_ja_JP
;
281 if ( IsMatchMinusDashChoon())
282 nRes
|= TransliterationModules_ignoreMinusSign_ja_JP
;
283 if ( IsMatchRepeatCharMarks())
284 nRes
|= TransliterationModules_ignoreIterationMark_ja_JP
;
285 if ( IsMatchVariantFormKanji())
286 nRes
|= TransliterationModules_ignoreTraditionalKanji_ja_JP
;
287 if ( IsMatchOldKanaForms())
288 nRes
|= TransliterationModules_ignoreTraditionalKana_ja_JP
;
289 if ( IsMatchDiziDuzu())
290 nRes
|= TransliterationModules_ignoreZiZu_ja_JP
;
291 if ( IsMatchBavaHafa())
292 nRes
|= TransliterationModules_ignoreBaFa_ja_JP
;
293 if ( IsMatchTsithichiDhizi())
294 nRes
|= TransliterationModules_ignoreTiJi_ja_JP
;
295 if ( IsMatchHyuiyuByuvyu())
296 nRes
|= TransliterationModules_ignoreHyuByu_ja_JP
;
297 if ( IsMatchSesheZeje())
298 nRes
|= TransliterationModules_ignoreSeZe_ja_JP
;
300 nRes
|= TransliterationModules_ignoreIandEfollowedByYa_ja_JP
;
302 nRes
|= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP
;
303 if ( IsIgnorePunctuation())
304 nRes
|= TransliterationModules_ignoreSeparator_ja_JP
;
305 if ( IsIgnoreWhitespace())
306 nRes
|= TransliterationModules_ignoreSpace_ja_JP
;
307 if ( IsIgnoreProlongedSoundMark())
308 nRes
|= TransliterationModules_ignoreProlongedSoundMark_ja_JP
;
309 if ( IsIgnoreMiddleDot())
310 nRes
|= TransliterationModules_ignoreMiddleDot_ja_JP
;
316 sal_Bool
SvtSearchOptions::IsWholeWordsOnly() const
318 return pImpl
->GetFlag( 0 );
322 void SvtSearchOptions::SetWholeWordsOnly( sal_Bool bVal
)
324 pImpl
->SetFlag( 0, bVal
);
328 sal_Bool
SvtSearchOptions::IsBackwards() const
330 return pImpl
->GetFlag( 1 );
334 void SvtSearchOptions::SetBackwards( sal_Bool bVal
)
336 pImpl
->SetFlag( 1, bVal
);
340 sal_Bool
SvtSearchOptions::IsUseRegularExpression() const
342 return pImpl
->GetFlag( 2 );
346 void SvtSearchOptions::SetUseRegularExpression( sal_Bool bVal
)
348 pImpl
->SetFlag( 2, bVal
);
351 void SvtSearchOptions::SetSearchForStyles( sal_Bool bVal
)
353 pImpl
->SetFlag( 3, bVal
);
357 sal_Bool
SvtSearchOptions::IsSimilaritySearch() const
359 return pImpl
->GetFlag( 4 );
363 void SvtSearchOptions::SetSimilaritySearch( sal_Bool bVal
)
365 pImpl
->SetFlag( 4, bVal
);
369 sal_Bool
SvtSearchOptions::IsUseAsianOptions() const
371 return pImpl
->GetFlag( 5 );
375 void SvtSearchOptions::SetUseAsianOptions( sal_Bool bVal
)
377 pImpl
->SetFlag( 5, bVal
);
381 sal_Bool
SvtSearchOptions::IsMatchCase() const
383 return pImpl
->GetFlag( 6 );
387 void SvtSearchOptions::SetMatchCase( sal_Bool bVal
)
389 pImpl
->SetFlag( 6, bVal
);
393 sal_Bool
SvtSearchOptions::IsMatchFullHalfWidthForms() const
395 return pImpl
->GetFlag( 7 );
399 void SvtSearchOptions::SetMatchFullHalfWidthForms( sal_Bool bVal
)
401 pImpl
->SetFlag( 7, bVal
);
405 sal_Bool
SvtSearchOptions::IsMatchHiraganaKatakana() const
407 return pImpl
->GetFlag( 8 );
411 void SvtSearchOptions::SetMatchHiraganaKatakana( sal_Bool bVal
)
413 pImpl
->SetFlag( 8, bVal
);
417 sal_Bool
SvtSearchOptions::IsMatchContractions() const
419 return pImpl
->GetFlag( 9 );
423 void SvtSearchOptions::SetMatchContractions( sal_Bool bVal
)
425 pImpl
->SetFlag( 9, bVal
);
429 sal_Bool
SvtSearchOptions::IsMatchMinusDashChoon() const
431 return pImpl
->GetFlag( 10 );
435 void SvtSearchOptions::SetMatchMinusDashChoon( sal_Bool bVal
)
437 pImpl
->SetFlag( 10, bVal
);
441 sal_Bool
SvtSearchOptions::IsMatchRepeatCharMarks() const
443 return pImpl
->GetFlag( 11 );
447 void SvtSearchOptions::SetMatchRepeatCharMarks( sal_Bool bVal
)
449 pImpl
->SetFlag( 11, bVal
);
453 sal_Bool
SvtSearchOptions::IsMatchVariantFormKanji() const
455 return pImpl
->GetFlag( 12 );
459 void SvtSearchOptions::SetMatchVariantFormKanji( sal_Bool bVal
)
461 pImpl
->SetFlag( 12, bVal
);
465 sal_Bool
SvtSearchOptions::IsMatchOldKanaForms() const
467 return pImpl
->GetFlag( 13 );
471 void SvtSearchOptions::SetMatchOldKanaForms( sal_Bool bVal
)
473 pImpl
->SetFlag( 13, bVal
);
477 sal_Bool
SvtSearchOptions::IsMatchDiziDuzu() const
479 return pImpl
->GetFlag( 14 );
483 void SvtSearchOptions::SetMatchDiziDuzu( sal_Bool bVal
)
485 pImpl
->SetFlag( 14, bVal
);
489 sal_Bool
SvtSearchOptions::IsMatchBavaHafa() const
491 return pImpl
->GetFlag( 15 );
495 void SvtSearchOptions::SetMatchBavaHafa( sal_Bool bVal
)
497 pImpl
->SetFlag( 15, bVal
);
501 sal_Bool
SvtSearchOptions::IsMatchTsithichiDhizi() const
503 return pImpl
->GetFlag( 16 );
507 void SvtSearchOptions::SetMatchTsithichiDhizi( sal_Bool bVal
)
509 pImpl
->SetFlag( 16, bVal
);
513 sal_Bool
SvtSearchOptions::IsMatchHyuiyuByuvyu() const
515 return pImpl
->GetFlag( 17 );
519 void SvtSearchOptions::SetMatchHyuiyuByuvyu( sal_Bool bVal
)
521 pImpl
->SetFlag( 17, bVal
);
525 sal_Bool
SvtSearchOptions::IsMatchSesheZeje() const
527 return pImpl
->GetFlag( 18 );
531 void SvtSearchOptions::SetMatchSesheZeje( sal_Bool bVal
)
533 pImpl
->SetFlag( 18, bVal
);
537 sal_Bool
SvtSearchOptions::IsMatchIaiya() const
539 return pImpl
->GetFlag( 19 );
543 void SvtSearchOptions::SetMatchIaiya( sal_Bool bVal
)
545 pImpl
->SetFlag( 19, bVal
);
549 sal_Bool
SvtSearchOptions::IsMatchKiku() const
551 return pImpl
->GetFlag( 20 );
555 void SvtSearchOptions::SetMatchKiku( sal_Bool bVal
)
557 pImpl
->SetFlag( 20, bVal
);
561 sal_Bool
SvtSearchOptions::IsIgnorePunctuation() const
563 return pImpl
->GetFlag( 21 );
567 void SvtSearchOptions::SetIgnorePunctuation( sal_Bool bVal
)
569 pImpl
->SetFlag( 21, bVal
);
573 sal_Bool
SvtSearchOptions::IsIgnoreWhitespace() const
575 return pImpl
->GetFlag( 22 );
579 void SvtSearchOptions::SetIgnoreWhitespace( sal_Bool bVal
)
581 pImpl
->SetFlag( 22, bVal
);
585 sal_Bool
SvtSearchOptions::IsIgnoreProlongedSoundMark() const
587 return pImpl
->GetFlag( 23 );
591 void SvtSearchOptions::SetIgnoreProlongedSoundMark( sal_Bool bVal
)
593 pImpl
->SetFlag( 23, bVal
);
597 sal_Bool
SvtSearchOptions::IsIgnoreMiddleDot() const
599 return pImpl
->GetFlag( 24 );
603 void SvtSearchOptions::SetIgnoreMiddleDot( sal_Bool bVal
)
605 pImpl
->SetFlag( 24, bVal
);
608 sal_Bool
SvtSearchOptions::IsNotes() const
610 return pImpl
->GetFlag( 25 );
614 void SvtSearchOptions::SetNotes( sal_Bool bVal
)
616 pImpl
->SetFlag( 25, bVal
);
619 //////////////////////////////////////////////////////////////////////
621 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */