1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: searchopt.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "searchopt.hxx"
35 #include <tools/solar.h>
36 #include <tools/debug.hxx>
37 #include <unotools/configitem.hxx>
38 #include <com/sun/star/i18n/TransliterationModules.hpp>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <com/sun/star/uno/Any.h>
41 #include <rtl/logfile.hxx>
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star::i18n
;
49 #define MAX_FLAGS_OFFSET 25
51 //////////////////////////////////////////////////////////////////////
54 class SvtSearchOptions_Impl
: public ConfigItem
59 // disallow copy-constructor and assignment-operator for now
60 SvtSearchOptions_Impl( const SvtSearchOptions_Impl
& );
61 SvtSearchOptions_Impl
& operator = ( const SvtSearchOptions_Impl
& );
64 BOOL
IsModified() const { return bModified
; }
65 using ConfigItem::SetModified
;
66 void SetModified( BOOL bVal
);
70 Sequence
< OUString
> GetPropertyNames() const;
73 SvtSearchOptions_Impl();
74 virtual ~SvtSearchOptions_Impl();
77 virtual void Commit();
79 BOOL
GetFlag( USHORT nOffset
) const;
80 void SetFlag( USHORT nOffset
, BOOL bVal
);
85 SvtSearchOptions_Impl::SvtSearchOptions_Impl() :
86 ConfigItem( OUString::createFromAscii( "Office.Common/SearchOptions" ) )
88 RTL_LOGFILE_CONTEXT(aLog
, "svtools SvtSearchOptions_Impl::SvtSearchOptions_Impl()");
89 nFlags
= 0x0003FFFF; // set all options values to 'true'
95 SvtSearchOptions_Impl::~SvtSearchOptions_Impl()
101 void SvtSearchOptions_Impl::Commit()
108 BOOL
SvtSearchOptions_Impl::GetFlag( USHORT nOffset
) const
110 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
111 return ((nFlags
>> nOffset
) & 0x01) ? TRUE
: FALSE
;
115 void SvtSearchOptions_Impl::SetFlag( USHORT nOffset
, BOOL bVal
)
117 DBG_ASSERT( nOffset
<= MAX_FLAGS_OFFSET
, "offset out of range");
118 INT32 nOldFlags
= nFlags
;
119 INT32 nMask
= ((INT32
) 1) << nOffset
;
124 if (nFlags
!= nOldFlags
)
129 void SvtSearchOptions_Impl::SetModified( BOOL bVal
)
134 ConfigItem::SetModified();
139 Sequence
< OUString
> SvtSearchOptions_Impl::GetPropertyNames() const
141 static const char* aPropNames
[ MAX_FLAGS_OFFSET
+ 1 ] =
143 "IsWholeWordsOnly", // 0
145 "IsUseRegularExpression", // 2
146 //"IsCurrentSelectionOnly", // interactively set or not...
147 "IsSearchForStyles", // 3
148 "IsSimilaritySearch", // 4
149 "IsUseAsianOptions", // 5
151 "Japanese/IsMatchFullHalfWidthForms", // 7
152 "Japanese/IsMatchHiraganaKatakana", // 8
153 "Japanese/IsMatchContractions", // 9
154 "Japanese/IsMatchMinusDashCho-on", // 10
155 "Japanese/IsMatchRepeatCharMarks", // 11
156 "Japanese/IsMatchVariantFormKanji", // 12
157 "Japanese/IsMatchOldKanaForms", // 13
158 "Japanese/IsMatch_DiZi_DuZu", // 14
159 "Japanese/IsMatch_BaVa_HaFa", // 15
160 "Japanese/IsMatch_TsiThiChi_DhiZi", // 16
161 "Japanese/IsMatch_HyuIyu_ByuVyu", // 17
162 "Japanese/IsMatch_SeShe_ZeJe", // 18
163 "Japanese/IsMatch_IaIya", // 19
164 "Japanese/IsMatch_KiKu", // 20
165 "Japanese/IsIgnorePunctuation", // 21
166 "Japanese/IsIgnoreWhitespace", // 22
167 "Japanese/IsIgnoreProlongedSoundMark", // 23
168 "Japanese/IsIgnoreMiddleDot", // 24
172 const int nCount
= sizeof( aPropNames
) / sizeof( aPropNames
[0] );
173 Sequence
< OUString
> aNames( nCount
);
174 OUString
* pNames
= aNames
.getArray();
175 for (INT32 i
= 0; i
< nCount
; ++i
)
176 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
] );
182 BOOL
SvtSearchOptions_Impl::Load()
186 Sequence
< OUString
> aNames
= GetPropertyNames();
187 INT32 nProps
= aNames
.getLength();
189 const Sequence
< Any
> aValues
= GetProperties( aNames
);
190 DBG_ASSERT( aValues
.getLength() == aNames
.getLength(),
191 "GetProperties failed" );
192 //EnableNotification( aNames );
194 if (nProps
&& aValues
.getLength() == nProps
)
198 const Any
* pValues
= aValues
.getConstArray();
199 for (USHORT i
= 0; i
< nProps
; ++i
)
201 const Any
&rVal
= pValues
[i
];
202 DBG_ASSERT( rVal
.hasValue(), "property value missing" );
208 if (i
<= MAX_FLAGS_OFFSET
)
210 // use index in sequence as flag index
214 DBG_ERROR( "unexpected index" );
219 DBG_ERROR( "unexpected type" );
225 DBG_ERROR( "value missing" );
230 DBG_ASSERT( bSucc
, "LoadConfig failed" );
236 BOOL
SvtSearchOptions_Impl::Save()
240 const Sequence
< OUString
> aNames
= GetPropertyNames();
241 INT32 nProps
= aNames
.getLength();
243 Sequence
< Any
> aValues( nProps
);
244 Any
*pValue
= aValues
.getArray();
246 DBG_ASSERT( nProps
== MAX_FLAGS_OFFSET
+ 1,
247 "unexpected size of index" );
248 if (nProps
&& nProps
== MAX_FLAGS_OFFSET
+ 1)
250 for (USHORT i
= 0; i
< nProps
; ++i
)
251 pValue
[i
] <<= (BOOL
) GetFlag(i
);
252 bSucc
|= PutProperties( aNames
, aValues
);
256 SetModified( FALSE
);
262 //////////////////////////////////////////////////////////////////////
264 SvtSearchOptions::SvtSearchOptions()
266 pImpl
= new SvtSearchOptions_Impl
;
270 SvtSearchOptions::~SvtSearchOptions()
276 INT32
SvtSearchOptions::GetTransliterationFlags() const
280 if (!IsMatchCase()) // 'IsMatchCase' means act case sensitive
281 nRes
|= TransliterationModules_IGNORE_CASE
;
282 if ( IsMatchFullHalfWidthForms())
283 nRes
|= TransliterationModules_IGNORE_WIDTH
;
284 if ( IsMatchHiraganaKatakana())
285 nRes
|= TransliterationModules_IGNORE_KANA
;
286 if ( IsMatchContractions())
287 nRes
|= TransliterationModules_ignoreSize_ja_JP
;
288 if ( IsMatchMinusDashChoon())
289 nRes
|= TransliterationModules_ignoreMinusSign_ja_JP
;
290 if ( IsMatchRepeatCharMarks())
291 nRes
|= TransliterationModules_ignoreIterationMark_ja_JP
;
292 if ( IsMatchVariantFormKanji())
293 nRes
|= TransliterationModules_ignoreTraditionalKanji_ja_JP
;
294 if ( IsMatchOldKanaForms())
295 nRes
|= TransliterationModules_ignoreTraditionalKana_ja_JP
;
296 if ( IsMatchDiziDuzu())
297 nRes
|= TransliterationModules_ignoreZiZu_ja_JP
;
298 if ( IsMatchBavaHafa())
299 nRes
|= TransliterationModules_ignoreBaFa_ja_JP
;
300 if ( IsMatchTsithichiDhizi())
301 nRes
|= TransliterationModules_ignoreTiJi_ja_JP
;
302 if ( IsMatchHyuiyuByuvyu())
303 nRes
|= TransliterationModules_ignoreHyuByu_ja_JP
;
304 if ( IsMatchSesheZeje())
305 nRes
|= TransliterationModules_ignoreSeZe_ja_JP
;
307 nRes
|= TransliterationModules_ignoreIandEfollowedByYa_ja_JP
;
309 nRes
|= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP
;
310 if ( IsIgnorePunctuation())
311 nRes
|= TransliterationModules_ignoreSeparator_ja_JP
;
312 if ( IsIgnoreWhitespace())
313 nRes
|= TransliterationModules_ignoreSpace_ja_JP
;
314 if ( IsIgnoreProlongedSoundMark())
315 nRes
|= TransliterationModules_ignoreProlongedSoundMark_ja_JP
;
316 if ( IsIgnoreMiddleDot())
317 nRes
|= TransliterationModules_ignoreMiddleDot_ja_JP
;
323 BOOL
SvtSearchOptions::IsWholeWordsOnly() const
325 return pImpl
->GetFlag( 0 );
329 void SvtSearchOptions::SetWholeWordsOnly( BOOL bVal
)
331 pImpl
->SetFlag( 0, bVal
);
335 BOOL
SvtSearchOptions::IsBackwards() const
337 return pImpl
->GetFlag( 1 );
341 void SvtSearchOptions::SetBackwards( BOOL bVal
)
343 pImpl
->SetFlag( 1, bVal
);
347 BOOL
SvtSearchOptions::IsUseRegularExpression() const
349 return pImpl
->GetFlag( 2 );
353 void SvtSearchOptions::SetUseRegularExpression( BOOL bVal
)
355 pImpl
->SetFlag( 2, bVal
);
359 BOOL
SvtSearchOptions::IsSearchForStyles() const
361 return pImpl
->GetFlag( 3 );
365 void SvtSearchOptions::SetSearchForStyles( BOOL bVal
)
367 pImpl
->SetFlag( 3, bVal
);
371 BOOL
SvtSearchOptions::IsSimilaritySearch() const
373 return pImpl
->GetFlag( 4 );
377 void SvtSearchOptions::SetSimilaritySearch( BOOL bVal
)
379 pImpl
->SetFlag( 4, bVal
);
383 BOOL
SvtSearchOptions::IsUseAsianOptions() const
385 return pImpl
->GetFlag( 5 );
389 void SvtSearchOptions::SetUseAsianOptions( BOOL bVal
)
391 pImpl
->SetFlag( 5, bVal
);
395 BOOL
SvtSearchOptions::IsMatchCase() const
397 return pImpl
->GetFlag( 6 );
401 void SvtSearchOptions::SetMatchCase( BOOL bVal
)
403 pImpl
->SetFlag( 6, bVal
);
407 BOOL
SvtSearchOptions::IsMatchFullHalfWidthForms() const
409 return pImpl
->GetFlag( 7 );
413 void SvtSearchOptions::SetMatchFullHalfWidthForms( BOOL bVal
)
415 pImpl
->SetFlag( 7, bVal
);
419 BOOL
SvtSearchOptions::IsMatchHiraganaKatakana() const
421 return pImpl
->GetFlag( 8 );
425 void SvtSearchOptions::SetMatchHiraganaKatakana( BOOL bVal
)
427 pImpl
->SetFlag( 8, bVal
);
431 BOOL
SvtSearchOptions::IsMatchContractions() const
433 return pImpl
->GetFlag( 9 );
437 void SvtSearchOptions::SetMatchContractions( BOOL bVal
)
439 pImpl
->SetFlag( 9, bVal
);
443 BOOL
SvtSearchOptions::IsMatchMinusDashChoon() const
445 return pImpl
->GetFlag( 10 );
449 void SvtSearchOptions::SetMatchMinusDashChoon( BOOL bVal
)
451 pImpl
->SetFlag( 10, bVal
);
455 BOOL
SvtSearchOptions::IsMatchRepeatCharMarks() const
457 return pImpl
->GetFlag( 11 );
461 void SvtSearchOptions::SetMatchRepeatCharMarks( BOOL bVal
)
463 pImpl
->SetFlag( 11, bVal
);
467 BOOL
SvtSearchOptions::IsMatchVariantFormKanji() const
469 return pImpl
->GetFlag( 12 );
473 void SvtSearchOptions::SetMatchVariantFormKanji( BOOL bVal
)
475 pImpl
->SetFlag( 12, bVal
);
479 BOOL
SvtSearchOptions::IsMatchOldKanaForms() const
481 return pImpl
->GetFlag( 13 );
485 void SvtSearchOptions::SetMatchOldKanaForms( BOOL bVal
)
487 pImpl
->SetFlag( 13, bVal
);
491 BOOL
SvtSearchOptions::IsMatchDiziDuzu() const
493 return pImpl
->GetFlag( 14 );
497 void SvtSearchOptions::SetMatchDiziDuzu( BOOL bVal
)
499 pImpl
->SetFlag( 14, bVal
);
503 BOOL
SvtSearchOptions::IsMatchBavaHafa() const
505 return pImpl
->GetFlag( 15 );
509 void SvtSearchOptions::SetMatchBavaHafa( BOOL bVal
)
511 pImpl
->SetFlag( 15, bVal
);
515 BOOL
SvtSearchOptions::IsMatchTsithichiDhizi() const
517 return pImpl
->GetFlag( 16 );
521 void SvtSearchOptions::SetMatchTsithichiDhizi( BOOL bVal
)
523 pImpl
->SetFlag( 16, bVal
);
527 BOOL
SvtSearchOptions::IsMatchHyuiyuByuvyu() const
529 return pImpl
->GetFlag( 17 );
533 void SvtSearchOptions::SetMatchHyuiyuByuvyu( BOOL bVal
)
535 pImpl
->SetFlag( 17, bVal
);
539 BOOL
SvtSearchOptions::IsMatchSesheZeje() const
541 return pImpl
->GetFlag( 18 );
545 void SvtSearchOptions::SetMatchSesheZeje( BOOL bVal
)
547 pImpl
->SetFlag( 18, bVal
);
551 BOOL
SvtSearchOptions::IsMatchIaiya() const
553 return pImpl
->GetFlag( 19 );
557 void SvtSearchOptions::SetMatchIaiya( BOOL bVal
)
559 pImpl
->SetFlag( 19, bVal
);
563 BOOL
SvtSearchOptions::IsMatchKiku() const
565 return pImpl
->GetFlag( 20 );
569 void SvtSearchOptions::SetMatchKiku( BOOL bVal
)
571 pImpl
->SetFlag( 20, bVal
);
575 BOOL
SvtSearchOptions::IsIgnorePunctuation() const
577 return pImpl
->GetFlag( 21 );
581 void SvtSearchOptions::SetIgnorePunctuation( BOOL bVal
)
583 pImpl
->SetFlag( 21, bVal
);
587 BOOL
SvtSearchOptions::IsIgnoreWhitespace() const
589 return pImpl
->GetFlag( 22 );
593 void SvtSearchOptions::SetIgnoreWhitespace( BOOL bVal
)
595 pImpl
->SetFlag( 22, bVal
);
599 BOOL
SvtSearchOptions::IsIgnoreProlongedSoundMark() const
601 return pImpl
->GetFlag( 23 );
605 void SvtSearchOptions::SetIgnoreProlongedSoundMark( BOOL bVal
)
607 pImpl
->SetFlag( 23, bVal
);
611 BOOL
SvtSearchOptions::IsIgnoreMiddleDot() const
613 return pImpl
->GetFlag( 24 );
617 void SvtSearchOptions::SetIgnoreMiddleDot( BOOL bVal
)
619 pImpl
->SetFlag( 24, bVal
);
622 BOOL
SvtSearchOptions::IsNotes() const
624 return pImpl
->GetFlag( 25 );
628 void SvtSearchOptions::SetNotes( BOOL bVal
)
630 pImpl
->SetFlag( 25, bVal
);
633 //////////////////////////////////////////////////////////////////////