xref: /aoo41x/main/cui/source/options/optjsearch.cxx (revision 2ee96f1c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 #include <tools/shl.hxx>
28 #include <unotools/searchopt.hxx>
29 #include <com/sun/star/i18n/TransliterationModules.hpp>
30 #include <cuires.hrc>
31 #include <dialmgr.hxx>
32 #include <optjsearch.hxx>
33 #include "optjsearch.hrc"
34 
35 using namespace com::sun::star::i18n;
36 
37 //////////////////////////////////////////////////////////////////////
38 
SvxJSearchOptionsPage(Window * pParent,const SfxItemSet & rSet)39 SvxJSearchOptionsPage::SvxJSearchOptionsPage( Window* pParent, const SfxItemSet& rSet ) :
40 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_JSEARCH_OPTIONS ), rSet ),
41 
42 	aTreatAsEqual				( this, CUI_RES( FL_TREAT_AS_EQUAL ) ),
43 	aMatchCase					( this, CUI_RES( CB_MATCH_CASE ) ),
44 	aMatchFullHalfWidth			( this, CUI_RES( CB_MATCH_FULL_HALF_WIDTH ) ),
45 	aMatchHiraganaKatakana		( this, CUI_RES( CB_MATCH_HIRAGANA_KATAKANA ) ),
46 	aMatchContractions			( this, CUI_RES( CB_MATCH_CONTRACTIONS ) ),
47 	aMatchMinusDashChoon		( this, CUI_RES( CB_MATCH_MINUS_DASH_CHOON ) ),
48 	aMatchRepeatCharMarks		( this, CUI_RES( CB_MATCH_REPEAT_CHAR_MARKS ) ),
49 	aMatchVariantFormKanji		( this, CUI_RES( CB_MATCH_VARIANT_FORM_KANJI ) ),
50 	aMatchOldKanaForms			( this, CUI_RES( CB_MATCH_OLD_KANA_FORMS ) ),
51 	aMatchDiziDuzu				( this, CUI_RES( CB_MATCH_DIZI_DUZU ) ),
52 	aMatchBavaHafa				( this, CUI_RES( CB_MATCH_BAVA_HAFA ) ),
53 	aMatchTsithichiDhizi		( this, CUI_RES( CB_MATCH_TSITHICHI_DHIZI ) ),
54 	aMatchHyuiyuByuvyu			( this, CUI_RES( CB_MATCH_HYUFYU_BYUVYU ) ),
55 	aMatchSesheZeje				( this, CUI_RES( CB_MATCH_SESHE_ZEJE ) ),
56 	aMatchIaiya					( this, CUI_RES( CB_MATCH_IAIYA ) ),
57 	aMatchKiku					( this, CUI_RES( CB_MATCH_KIKU ) ),
58     aMatchProlongedSoundMark    ( this, CUI_RES( CB_MATCH_PROLONGED_SOUNDMARK ) ),
59     aIgnore                     ( this, CUI_RES( FL_IGNORE ) ),
60 	aIgnorePunctuation			( this, CUI_RES( CB_IGNORE_PUNCTUATION ) ),
61 	aIgnoreWhitespace			( this, CUI_RES( CB_IGNORE_WHITESPACES ) ),
62     aIgnoreMiddleDot            ( this, CUI_RES( CB_IGNORE_MIDDLE_DOT ) )
63 {
64 	FreeResource();
65 	bSaveOptions = sal_True;
66 	nTransliterationFlags = 0x00000000;
67 }
68 
69 
~SvxJSearchOptionsPage()70 SvxJSearchOptionsPage::~SvxJSearchOptionsPage()
71 {
72 }
73 
74 
Create(Window * pParent,const SfxItemSet & rSet)75 SfxTabPage*  SvxJSearchOptionsPage::Create( Window* pParent, const SfxItemSet& rSet )
76 {
77 	return new SvxJSearchOptionsPage( pParent, rSet );
78 }
79 
80 
SetTransliterationFlags(sal_Int32 nSettings)81 void SvxJSearchOptionsPage::SetTransliterationFlags( sal_Int32 nSettings )
82 {
83 	sal_Bool  bVal = 0 != (nSettings & TransliterationModules_IGNORE_CASE);
84     aMatchCase               .Check( bVal );    //! treat as equal uppercase/lowercase
85 	bVal = 0 != (nSettings & TransliterationModules_IGNORE_WIDTH);
86     aMatchFullHalfWidth      .Check( bVal );
87 	bVal = 0 != (nSettings & TransliterationModules_IGNORE_KANA);
88     aMatchHiraganaKatakana   .Check( bVal );
89 	bVal = 0 != (nSettings & TransliterationModules_ignoreSize_ja_JP);
90     aMatchContractions       .Check( bVal );
91 	bVal = 0 != (nSettings & TransliterationModules_ignoreMinusSign_ja_JP);
92     aMatchMinusDashChoon     .Check( bVal );
93 	bVal = 0 != (nSettings & TransliterationModules_ignoreIterationMark_ja_JP);
94     aMatchRepeatCharMarks    .Check( bVal );
95 	bVal = 0 != (nSettings & TransliterationModules_ignoreTraditionalKanji_ja_JP);
96     aMatchVariantFormKanji   .Check( bVal );
97 	bVal = 0 != (nSettings & TransliterationModules_ignoreTraditionalKana_ja_JP);
98     aMatchOldKanaForms       .Check( bVal );
99 	bVal = 0 != (nSettings & TransliterationModules_ignoreZiZu_ja_JP);
100     aMatchDiziDuzu           .Check( bVal );
101 	bVal = 0 != (nSettings & TransliterationModules_ignoreBaFa_ja_JP);
102     aMatchBavaHafa           .Check( bVal );
103 	bVal = 0 != (nSettings & TransliterationModules_ignoreTiJi_ja_JP);
104     aMatchTsithichiDhizi     .Check( bVal );
105 	bVal = 0 != (nSettings & TransliterationModules_ignoreHyuByu_ja_JP);
106     aMatchHyuiyuByuvyu       .Check( bVal );
107 	bVal = 0 != (nSettings & TransliterationModules_ignoreSeZe_ja_JP);
108     aMatchSesheZeje          .Check( bVal );
109 	bVal = 0 != (nSettings & TransliterationModules_ignoreIandEfollowedByYa_ja_JP);
110     aMatchIaiya              .Check( bVal );
111 	bVal = 0 != (nSettings & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP);
112     aMatchKiku               .Check( bVal );
113 	bVal = 0 != (nSettings & TransliterationModules_ignoreSeparator_ja_JP);
114 	aIgnorePunctuation		 .Check( bVal );
115 	bVal = 0 != (nSettings & TransliterationModules_ignoreSpace_ja_JP);
116 	aIgnoreWhitespace		 .Check( bVal );
117 	bVal = 0 != (nSettings & TransliterationModules_ignoreProlongedSoundMark_ja_JP);
118     aMatchProlongedSoundMark.Check( bVal );
119 	bVal = 0 != (nSettings & TransliterationModules_ignoreMiddleDot_ja_JP);
120 	aIgnoreMiddleDot		 .Check( bVal );
121 
122 	nTransliterationFlags = nSettings;
123 }
124 
125 
GetTransliterationFlags_Impl()126 sal_Int32 SvxJSearchOptionsPage::GetTransliterationFlags_Impl()
127 {
128 	sal_Int32 nTmp = 0;
129     if (aMatchCase.IsChecked()) //! treat as equal uppercase/lowercase
130 		nTmp |= TransliterationModules_IGNORE_CASE;
131     if (aMatchFullHalfWidth.IsChecked())
132 		nTmp |= TransliterationModules_IGNORE_WIDTH;
133     if (aMatchHiraganaKatakana.IsChecked())
134 		nTmp |= TransliterationModules_IGNORE_KANA;
135     if (aMatchContractions.IsChecked())
136 		nTmp |= TransliterationModules_ignoreSize_ja_JP;
137     if (aMatchMinusDashChoon.IsChecked())
138 		nTmp |= TransliterationModules_ignoreMinusSign_ja_JP;
139     if (aMatchRepeatCharMarks.IsChecked())
140 		nTmp |= TransliterationModules_ignoreIterationMark_ja_JP;
141     if (aMatchVariantFormKanji.IsChecked())
142 		nTmp |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
143     if (aMatchOldKanaForms.IsChecked())
144 		nTmp |= TransliterationModules_ignoreTraditionalKana_ja_JP;
145     if (aMatchDiziDuzu.IsChecked())
146 		nTmp |= TransliterationModules_ignoreZiZu_ja_JP;
147     if (aMatchBavaHafa.IsChecked())
148 		nTmp |= TransliterationModules_ignoreBaFa_ja_JP;
149     if (aMatchTsithichiDhizi.IsChecked())
150 		nTmp |= TransliterationModules_ignoreTiJi_ja_JP;
151     if (aMatchHyuiyuByuvyu.IsChecked())
152 		nTmp |= TransliterationModules_ignoreHyuByu_ja_JP;
153     if (aMatchSesheZeje.IsChecked())
154 		nTmp |= TransliterationModules_ignoreSeZe_ja_JP;
155     if (aMatchIaiya.IsChecked())
156 		nTmp |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
157     if (aMatchKiku.IsChecked())
158 		nTmp |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
159     if (aIgnorePunctuation.IsChecked())
160 		nTmp |= TransliterationModules_ignoreSeparator_ja_JP;
161     if (aIgnoreWhitespace.IsChecked())
162 		nTmp |= TransliterationModules_ignoreSpace_ja_JP;
163     if (aMatchProlongedSoundMark.IsChecked())
164 		nTmp |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
165     if (aIgnoreMiddleDot.IsChecked())
166 		nTmp |= TransliterationModules_ignoreMiddleDot_ja_JP;
167 
168 	nTransliterationFlags = nTmp;
169 	return nTransliterationFlags;
170 }
171 
172 
Reset(const SfxItemSet &)173 void SvxJSearchOptionsPage::Reset( const SfxItemSet& )
174 {
175 	SvtSearchOptions aOpt;
176 
177 	// read settings from configuration
178     aMatchCase               .Check(!aOpt.IsMatchCase() );  //! treat as equal uppercase/lowercase
179 	aMatchFullHalfWidth		 .Check( aOpt.IsMatchFullHalfWidthForms() );
180 	aMatchHiraganaKatakana	 .Check( aOpt.IsMatchHiraganaKatakana() );
181 	aMatchContractions		 .Check( aOpt.IsMatchContractions() );
182 	aMatchMinusDashChoon	 .Check( aOpt.IsMatchMinusDashChoon() );
183 	aMatchRepeatCharMarks	 .Check( aOpt.IsMatchRepeatCharMarks() );
184 	aMatchVariantFormKanji	 .Check( aOpt.IsMatchVariantFormKanji() );
185 	aMatchOldKanaForms		 .Check( aOpt.IsMatchOldKanaForms() );
186 	aMatchDiziDuzu			 .Check( aOpt.IsMatchDiziDuzu() );
187 	aMatchBavaHafa			 .Check( aOpt.IsMatchBavaHafa() );
188 	aMatchTsithichiDhizi	 .Check( aOpt.IsMatchTsithichiDhizi() );
189 	aMatchHyuiyuByuvyu		 .Check( aOpt.IsMatchHyuiyuByuvyu() );
190 	aMatchSesheZeje			 .Check( aOpt.IsMatchSesheZeje() );
191 	aMatchIaiya				 .Check( aOpt.IsMatchIaiya() );
192 	aMatchKiku				 .Check( aOpt.IsMatchKiku() );
193 	aIgnorePunctuation		 .Check( aOpt.IsIgnorePunctuation() );
194 	aIgnoreWhitespace		 .Check( aOpt.IsIgnoreWhitespace() );
195     aMatchProlongedSoundMark .Check( aOpt.IsIgnoreProlongedSoundMark() );
196 	aIgnoreMiddleDot		 .Check( aOpt.IsIgnoreMiddleDot() );
197 
198 	nTransliterationFlags = GetTransliterationFlags_Impl();
199 	DBG_ASSERT( nTransliterationFlags == aOpt.GetTransliterationFlags(),
200 			"Transliteration settings different" );
201 
202 	aMatchCase				 .SaveValue();
203 	aMatchFullHalfWidth		 .SaveValue();
204 	aMatchHiraganaKatakana	 .SaveValue();
205 	aMatchContractions		 .SaveValue();
206 	aMatchMinusDashChoon	 .SaveValue();
207 	aMatchRepeatCharMarks	 .SaveValue();
208 	aMatchVariantFormKanji	 .SaveValue();
209 	aMatchOldKanaForms		 .SaveValue();
210 	aMatchDiziDuzu			 .SaveValue();
211 	aMatchBavaHafa			 .SaveValue();
212 	aMatchTsithichiDhizi	 .SaveValue();
213 	aMatchHyuiyuByuvyu		 .SaveValue();
214 	aMatchSesheZeje			 .SaveValue();
215 	aMatchIaiya				 .SaveValue();
216 	aMatchKiku				 .SaveValue();
217 	aIgnorePunctuation		 .SaveValue();
218 	aIgnoreWhitespace		 .SaveValue();
219     aMatchProlongedSoundMark .SaveValue();
220 	aIgnoreMiddleDot		 .SaveValue();
221 }
222 
223 
FillItemSet(SfxItemSet &)224 sal_Bool SvxJSearchOptionsPage::FillItemSet( SfxItemSet& )
225 {
226 	sal_Bool bModified = sal_False;
227 
228     sal_Int32 nOldVal = nTransliterationFlags;
229 	nTransliterationFlags = GetTransliterationFlags_Impl();
230     bModified = nOldVal != nTransliterationFlags;
231 
232 	if (!IsSaveOptions())
233 		return bModified;
234 
235     bModified = sal_False;
236 	SvtSearchOptions aOpt;
237 	sal_Bool bNewVal, bChanged;
238 
239     bNewVal  = aMatchCase.IsChecked();  //! treat as equal uppercase/lowercase
240 	bChanged = bNewVal != aMatchCase.GetSavedValue();
241 	if (bChanged)
242 	{
243         aOpt.SetMatchCase(!bNewVal );
244 		bModified = sal_True;
245 	}
246 	bNewVal  = aMatchFullHalfWidth.IsChecked();
247 	bChanged = bNewVal != aMatchFullHalfWidth.GetSavedValue();
248 	if (bChanged)
249 	{
250 		aOpt.SetMatchFullHalfWidthForms( bNewVal );
251 		bModified = sal_True;
252 	}
253 	bNewVal  = aMatchHiraganaKatakana.IsChecked();
254 	bChanged = bNewVal != aMatchHiraganaKatakana.GetSavedValue();
255 	if (bChanged)
256 	{
257 		aOpt.SetMatchHiraganaKatakana( bNewVal );
258 		bModified = sal_True;
259 	}
260 	bNewVal  = aMatchContractions.IsChecked();
261 	bChanged = bNewVal != aMatchContractions.GetSavedValue();
262 	if (bChanged)
263 	{
264 		aOpt.SetMatchContractions( bNewVal );
265 		bModified = sal_True;
266 	}
267 	bNewVal  = aMatchMinusDashChoon.IsChecked();
268 	bChanged = bNewVal != aMatchMinusDashChoon.GetSavedValue();
269 	if (bChanged)
270 	{
271 		aOpt.SetMatchMinusDashChoon( bNewVal );
272 		bModified = sal_True;
273 	}
274 	bNewVal  = aMatchRepeatCharMarks.IsChecked();
275 	bChanged = bNewVal != aMatchRepeatCharMarks.GetSavedValue();
276 	if (bChanged)
277 	{
278 		aOpt.SetMatchRepeatCharMarks( bNewVal );
279 		bModified = sal_True;
280 	}
281 	bNewVal  = aMatchVariantFormKanji.IsChecked();
282 	bChanged = bNewVal != aMatchVariantFormKanji.GetSavedValue();
283 	if (bChanged)
284 	{
285 		aOpt.SetMatchVariantFormKanji( bNewVal );
286 		bModified = sal_True;
287 	}
288 	bNewVal  = aMatchOldKanaForms.IsChecked();
289 	bChanged = bNewVal != aMatchOldKanaForms.GetSavedValue();
290 	if (bChanged)
291 	{
292 		aOpt.SetMatchOldKanaForms( bNewVal );
293 		bModified = sal_True;
294 	}
295 	bNewVal  = aMatchDiziDuzu.IsChecked();
296 	bChanged = bNewVal != aMatchDiziDuzu.GetSavedValue();
297 	if (bChanged)
298 	{
299 		aOpt.SetMatchDiziDuzu( bNewVal );
300 		bModified = sal_True;
301 	}
302 	bNewVal  = aMatchBavaHafa.IsChecked();
303 	bChanged = bNewVal != aMatchBavaHafa.GetSavedValue();
304 	if (bChanged)
305 	{
306 		aOpt.SetMatchBavaHafa( bNewVal );
307 		bModified = sal_True;
308 	}
309 	bNewVal  = aMatchTsithichiDhizi.IsChecked();
310 	bChanged = bNewVal != aMatchTsithichiDhizi.GetSavedValue();
311 	if (bChanged)
312 	{
313 		aOpt.SetMatchTsithichiDhizi( bNewVal );
314 		bModified = sal_True;
315 	}
316 	bNewVal  = aMatchHyuiyuByuvyu.IsChecked();
317 	bChanged = bNewVal != aMatchHyuiyuByuvyu.GetSavedValue();
318 	if (bChanged)
319 	{
320 		aOpt.SetMatchHyuiyuByuvyu( bNewVal );
321 		bModified = sal_True;
322 	}
323 	bNewVal  = aMatchSesheZeje.IsChecked();
324 	bChanged = bNewVal != aMatchSesheZeje.GetSavedValue();
325 	if (bChanged)
326 	{
327 		aOpt.SetMatchSesheZeje( bNewVal );
328 		bModified = sal_True;
329 	}
330 	bNewVal  = aMatchIaiya.IsChecked();
331 	bChanged = bNewVal != aMatchIaiya.GetSavedValue();
332 	if (bChanged)
333 	{
334 		aOpt.SetMatchIaiya( bNewVal );
335 		bModified = sal_True;
336 	}
337 	bNewVal  = aMatchKiku.IsChecked();
338 	bChanged = bNewVal != aMatchKiku.GetSavedValue();
339 	if (bChanged)
340 	{
341 		aOpt.SetMatchKiku( bNewVal );
342 		bModified = sal_True;
343 	}
344 	bNewVal  = aIgnorePunctuation.IsChecked();
345 	bChanged = bNewVal != aIgnorePunctuation.GetSavedValue();
346 	if (bChanged)
347 	{
348 		aOpt.SetIgnorePunctuation( bNewVal );
349 		bModified = sal_True;
350 	}
351 	bNewVal  = aIgnoreWhitespace.IsChecked();
352 	bChanged = bNewVal != aIgnoreWhitespace.GetSavedValue();
353 	if (bChanged)
354 	{
355 		aOpt.SetIgnoreWhitespace( bNewVal );
356 		bModified = sal_True;
357 	}
358     bNewVal  = aMatchProlongedSoundMark.IsChecked();
359     bChanged = bNewVal != aMatchProlongedSoundMark.GetSavedValue();
360 	if (bChanged)
361 	{
362         aOpt.SetIgnoreProlongedSoundMark( bNewVal );
363 		bModified = sal_True;
364 	}
365 	bNewVal  = aIgnoreMiddleDot.IsChecked();
366 	bChanged = bNewVal != aIgnoreMiddleDot.GetSavedValue();
367 	if (bChanged)
368 	{
369 		aOpt.SetIgnoreMiddleDot( bNewVal );
370 		bModified = sal_True;
371 	}
372 
373 	return bModified;
374 }
375 
376 
377 //////////////////////////////////////////////////////////////////////
378 
379