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
;
36 using ::rtl::OUString
;
38 #define MAX_FLAGS_OFFSET 25
40 //////////////////////////////////////////////////////////////////////
43 class SvtSearchOptions_Impl
: public ConfigItem
48 // disallow copy-constructor and assignment-operator for now
49 SvtSearchOptions_Impl( const SvtSearchOptions_Impl
& );
50 SvtSearchOptions_Impl
& operator = ( const SvtSearchOptions_Impl
& );
53 sal_Bool
IsModified() const { return bModified
; }
54 using ConfigItem::SetModified
;
55 void SetModified( sal_Bool bVal
);
59 Sequence
< OUString
> GetPropertyNames() const;
62 SvtSearchOptions_Impl();
63 virtual ~SvtSearchOptions_Impl();
66 virtual void Commit();
67 virtual void Notify( const com::sun::star::uno::Sequence
< rtl::OUString
>& aPropertyNames
);
69 sal_Bool
GetFlag( sal_uInt16 nOffset
) const;
70 void SetFlag( sal_uInt16 nOffset
, sal_Bool bVal
);
75 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
76 ConfigItem( OUString("Office.Common/SearchOptions") )
78 RTL_LOGFILE_CONTEXT(aLog
, "unotools SvtSearchOptions_Impl::SvtSearchOptions_Impl()");
79 nFlags
= 0x0003FFFF; // set all options values to 'true'
81 SetModified( sal_False
);
85 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
91 void SvtSearchOptions_Impl::Commit()
97 void SvtSearchOptions_Impl::Notify( const Sequence
< rtl::OUString
>& )
102 sal_Bool
SvtSearchOptions_Impl::GetFlag( sal_uInt16 nOffset
) const
104 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
105 return ((nFlags
>> nOffset
) & 0x01) ? sal_True
: sal_False
;
109 void SvtSearchOptions_Impl::SetFlag( sal_uInt16 nOffset
, sal_Bool bVal
)
111 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
112 sal_Int32 nOldFlags
= nFlags
;
113 sal_Int32 nMask
= ((sal_Int32
) 1) << nOffset
;
118 if (nFlags
!= nOldFlags
)
119 SetModified( sal_True
);
123 void SvtSearchOptions_Impl::SetModified( sal_Bool bVal
)
128 ConfigItem::SetModified();
133 Sequence
< OUString
> SvtSearchOptions_Impl::GetPropertyNames() const
135 static const char* aPropNames
[ MAX_FLAGS_OFFSET
+ 1 ] =
137 "IsWholeWordsOnly", // 0
139 "IsUseRegularExpression", // 2
140 //"IsCurrentSelectionOnly", // interactively set or not...
141 "IsSearchForStyles", // 3
142 "IsSimilaritySearch", // 4
143 "IsUseAsianOptions", // 5
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
166 const int nCount
= SAL_N_ELEMENTS( aPropNames
);
167 Sequence
< OUString
> aNames( nCount
);
168 OUString
* pNames
= aNames
.getArray();
169 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
170 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
] );
176 sal_Bool
SvtSearchOptions_Impl::Load()
178 sal_Bool bSucc
= sal_False
;
180 Sequence
< OUString
> aNames
= GetPropertyNames();
181 sal_Int32 nProps
= aNames
.getLength();
183 const Sequence
< Any
> aValues
= GetProperties( aNames
);
184 DBG_ASSERT( aValues
.getLength() == aNames
.getLength(),
185 "GetProperties failed" );
186 //EnableNotification( aNames );
188 if (nProps
&& aValues
.getLength() == nProps
)
192 const Any
* pValues
= aValues
.getConstArray();
193 for (sal_uInt16 i
= 0; i
< nProps
; ++i
)
195 const Any
&rVal
= pValues
[i
];
196 DBG_ASSERT( rVal
.hasValue(), "property value missing" );
199 sal_Bool bVal
= sal_Bool();
202 if (i
<= MAX_FLAGS_OFFSET
)
204 // use index in sequence as flag index
208 OSL_FAIL( "unexpected index" );
213 OSL_FAIL( "unexpected type" );
219 OSL_FAIL( "value missing" );
224 DBG_ASSERT( bSucc
, "LoadConfig failed" );
230 sal_Bool
SvtSearchOptions_Impl::Save()
232 sal_Bool bSucc
= sal_False
;
234 const Sequence
< OUString
> aNames
= GetPropertyNames();
235 sal_Int32 nProps
= aNames
.getLength();
237 Sequence
< Any
> aValues( nProps
);
238 Any
*pValue
= aValues
.getArray();
240 DBG_ASSERT( nProps
== MAX_FLAGS_OFFSET
+ 1,
241 "unexpected size of index" );
242 if (nProps
&& nProps
== MAX_FLAGS_OFFSET
+ 1)
244 for (sal_uInt16 i
= 0; i
< nProps
; ++i
)
245 pValue
[i
] <<= (sal_Bool
) GetFlag(i
);
246 bSucc
|= PutProperties( aNames
, aValues
);
250 SetModified( sal_False
);
256 //////////////////////////////////////////////////////////////////////
258 SvtSearchOptions::SvtSearchOptions()
260 pImpl
= new SvtSearchOptions_Impl
;
264 SvtSearchOptions::~SvtSearchOptions()
270 sal_Int32
SvtSearchOptions::GetTransliterationFlags() const
274 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
275 nRes
|= TransliterationModules_IGNORE_CASE
;
276 if ( IsMatchFullHalfWidthForms())
277 nRes
|= TransliterationModules_IGNORE_WIDTH
;
278 if ( IsMatchHiraganaKatakana())
279 nRes
|= TransliterationModules_IGNORE_KANA
;
280 if ( IsMatchContractions())
281 nRes
|= TransliterationModules_ignoreSize_ja_JP
;
282 if ( IsMatchMinusDashChoon())
283 nRes
|= TransliterationModules_ignoreMinusSign_ja_JP
;
284 if ( IsMatchRepeatCharMarks())
285 nRes
|= TransliterationModules_ignoreIterationMark_ja_JP
;
286 if ( IsMatchVariantFormKanji())
287 nRes
|= TransliterationModules_ignoreTraditionalKanji_ja_JP
;
288 if ( IsMatchOldKanaForms())
289 nRes
|= TransliterationModules_ignoreTraditionalKana_ja_JP
;
290 if ( IsMatchDiziDuzu())
291 nRes
|= TransliterationModules_ignoreZiZu_ja_JP
;
292 if ( IsMatchBavaHafa())
293 nRes
|= TransliterationModules_ignoreBaFa_ja_JP
;
294 if ( IsMatchTsithichiDhizi())
295 nRes
|= TransliterationModules_ignoreTiJi_ja_JP
;
296 if ( IsMatchHyuiyuByuvyu())
297 nRes
|= TransliterationModules_ignoreHyuByu_ja_JP
;
298 if ( IsMatchSesheZeje())
299 nRes
|= TransliterationModules_ignoreSeZe_ja_JP
;
301 nRes
|= TransliterationModules_ignoreIandEfollowedByYa_ja_JP
;
303 nRes
|= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP
;
304 if ( IsIgnorePunctuation())
305 nRes
|= TransliterationModules_ignoreSeparator_ja_JP
;
306 if ( IsIgnoreWhitespace())
307 nRes
|= TransliterationModules_ignoreSpace_ja_JP
;
308 if ( IsIgnoreProlongedSoundMark())
309 nRes
|= TransliterationModules_ignoreProlongedSoundMark_ja_JP
;
310 if ( IsIgnoreMiddleDot())
311 nRes
|= TransliterationModules_ignoreMiddleDot_ja_JP
;
317 sal_Bool
SvtSearchOptions::IsWholeWordsOnly() const
319 return pImpl
->GetFlag( 0 );
323 void SvtSearchOptions::SetWholeWordsOnly( sal_Bool bVal
)
325 pImpl
->SetFlag( 0, bVal
);
329 sal_Bool
SvtSearchOptions::IsBackwards() const
331 return pImpl
->GetFlag( 1 );
335 void SvtSearchOptions::SetBackwards( sal_Bool bVal
)
337 pImpl
->SetFlag( 1, bVal
);
341 sal_Bool
SvtSearchOptions::IsUseRegularExpression() const
343 return pImpl
->GetFlag( 2 );
347 void SvtSearchOptions::SetUseRegularExpression( sal_Bool bVal
)
349 pImpl
->SetFlag( 2, bVal
);
352 void SvtSearchOptions::SetSearchForStyles( sal_Bool bVal
)
354 pImpl
->SetFlag( 3, bVal
);
358 sal_Bool
SvtSearchOptions::IsSimilaritySearch() const
360 return pImpl
->GetFlag( 4 );
364 void SvtSearchOptions::SetSimilaritySearch( sal_Bool bVal
)
366 pImpl
->SetFlag( 4, bVal
);
370 sal_Bool
SvtSearchOptions::IsUseAsianOptions() const
372 return pImpl
->GetFlag( 5 );
376 void SvtSearchOptions::SetUseAsianOptions( sal_Bool bVal
)
378 pImpl
->SetFlag( 5, bVal
);
382 sal_Bool
SvtSearchOptions::IsMatchCase() const
384 return pImpl
->GetFlag( 6 );
388 void SvtSearchOptions::SetMatchCase( sal_Bool bVal
)
390 pImpl
->SetFlag( 6, bVal
);
394 sal_Bool
SvtSearchOptions::IsMatchFullHalfWidthForms() const
396 return pImpl
->GetFlag( 7 );
400 void SvtSearchOptions::SetMatchFullHalfWidthForms( sal_Bool bVal
)
402 pImpl
->SetFlag( 7, bVal
);
406 sal_Bool
SvtSearchOptions::IsMatchHiraganaKatakana() const
408 return pImpl
->GetFlag( 8 );
412 void SvtSearchOptions::SetMatchHiraganaKatakana( sal_Bool bVal
)
414 pImpl
->SetFlag( 8, bVal
);
418 sal_Bool
SvtSearchOptions::IsMatchContractions() const
420 return pImpl
->GetFlag( 9 );
424 void SvtSearchOptions::SetMatchContractions( sal_Bool bVal
)
426 pImpl
->SetFlag( 9, bVal
);
430 sal_Bool
SvtSearchOptions::IsMatchMinusDashChoon() const
432 return pImpl
->GetFlag( 10 );
436 void SvtSearchOptions::SetMatchMinusDashChoon( sal_Bool bVal
)
438 pImpl
->SetFlag( 10, bVal
);
442 sal_Bool
SvtSearchOptions::IsMatchRepeatCharMarks() const
444 return pImpl
->GetFlag( 11 );
448 void SvtSearchOptions::SetMatchRepeatCharMarks( sal_Bool bVal
)
450 pImpl
->SetFlag( 11, bVal
);
454 sal_Bool
SvtSearchOptions::IsMatchVariantFormKanji() const
456 return pImpl
->GetFlag( 12 );
460 void SvtSearchOptions::SetMatchVariantFormKanji( sal_Bool bVal
)
462 pImpl
->SetFlag( 12, bVal
);
466 sal_Bool
SvtSearchOptions::IsMatchOldKanaForms() const
468 return pImpl
->GetFlag( 13 );
472 void SvtSearchOptions::SetMatchOldKanaForms( sal_Bool bVal
)
474 pImpl
->SetFlag( 13, bVal
);
478 sal_Bool
SvtSearchOptions::IsMatchDiziDuzu() const
480 return pImpl
->GetFlag( 14 );
484 void SvtSearchOptions::SetMatchDiziDuzu( sal_Bool bVal
)
486 pImpl
->SetFlag( 14, bVal
);
490 sal_Bool
SvtSearchOptions::IsMatchBavaHafa() const
492 return pImpl
->GetFlag( 15 );
496 void SvtSearchOptions::SetMatchBavaHafa( sal_Bool bVal
)
498 pImpl
->SetFlag( 15, bVal
);
502 sal_Bool
SvtSearchOptions::IsMatchTsithichiDhizi() const
504 return pImpl
->GetFlag( 16 );
508 void SvtSearchOptions::SetMatchTsithichiDhizi( sal_Bool bVal
)
510 pImpl
->SetFlag( 16, bVal
);
514 sal_Bool
SvtSearchOptions::IsMatchHyuiyuByuvyu() const
516 return pImpl
->GetFlag( 17 );
520 void SvtSearchOptions::SetMatchHyuiyuByuvyu( sal_Bool bVal
)
522 pImpl
->SetFlag( 17, bVal
);
526 sal_Bool
SvtSearchOptions::IsMatchSesheZeje() const
528 return pImpl
->GetFlag( 18 );
532 void SvtSearchOptions::SetMatchSesheZeje( sal_Bool bVal
)
534 pImpl
->SetFlag( 18, bVal
);
538 sal_Bool
SvtSearchOptions::IsMatchIaiya() const
540 return pImpl
->GetFlag( 19 );
544 void SvtSearchOptions::SetMatchIaiya( sal_Bool bVal
)
546 pImpl
->SetFlag( 19, bVal
);
550 sal_Bool
SvtSearchOptions::IsMatchKiku() const
552 return pImpl
->GetFlag( 20 );
556 void SvtSearchOptions::SetMatchKiku( sal_Bool bVal
)
558 pImpl
->SetFlag( 20, bVal
);
562 sal_Bool
SvtSearchOptions::IsIgnorePunctuation() const
564 return pImpl
->GetFlag( 21 );
568 void SvtSearchOptions::SetIgnorePunctuation( sal_Bool bVal
)
570 pImpl
->SetFlag( 21, bVal
);
574 sal_Bool
SvtSearchOptions::IsIgnoreWhitespace() const
576 return pImpl
->GetFlag( 22 );
580 void SvtSearchOptions::SetIgnoreWhitespace( sal_Bool bVal
)
582 pImpl
->SetFlag( 22, bVal
);
586 sal_Bool
SvtSearchOptions::IsIgnoreProlongedSoundMark() const
588 return pImpl
->GetFlag( 23 );
592 void SvtSearchOptions::SetIgnoreProlongedSoundMark( sal_Bool bVal
)
594 pImpl
->SetFlag( 23, bVal
);
598 sal_Bool
SvtSearchOptions::IsIgnoreMiddleDot() const
600 return pImpl
->GetFlag( 24 );
604 void SvtSearchOptions::SetIgnoreMiddleDot( sal_Bool bVal
)
606 pImpl
->SetFlag( 24, bVal
);
609 sal_Bool
SvtSearchOptions::IsNotes() const
611 return pImpl
->GetFlag( 25 );
615 void SvtSearchOptions::SetNotes( sal_Bool bVal
)
617 pImpl
->SetFlag( 25, bVal
);
620 //////////////////////////////////////////////////////////////////////
622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */