LibreOffice Module cui (master)  1
optjsearch.cxx
Go to the documentation of this file.
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 #include <tools/debug.hxx>
21 #include <unotools/searchopt.hxx>
23 #include "optjsearch.hxx"
24 
25 using namespace com::sun::star::i18n;
26 
27 
29  : SfxTabPage(pPage, pController, "cui/ui/optjsearchpage.ui", "OptJSearchPage", &rSet)
30  , m_xMatchCase(m_xBuilder->weld_check_button("matchcase"))
31  , m_xMatchFullHalfWidth(m_xBuilder->weld_check_button("matchfullhalfwidth"))
32  , m_xMatchHiraganaKatakana(m_xBuilder->weld_check_button("matchhiraganakatakana"))
33  , m_xMatchContractions(m_xBuilder->weld_check_button("matchcontractions"))
34  , m_xMatchMinusDashChoon(m_xBuilder->weld_check_button("matchminusdashchoon"))
35  , m_xMatchRepeatCharMarks(m_xBuilder->weld_check_button("matchrepeatcharmarks"))
36  , m_xMatchVariantFormKanji(m_xBuilder->weld_check_button("matchvariantformkanji"))
37  , m_xMatchOldKanaForms(m_xBuilder->weld_check_button("matcholdkanaforms"))
38  , m_xMatchDiziDuzu(m_xBuilder->weld_check_button("matchdiziduzu"))
39  , m_xMatchBavaHafa(m_xBuilder->weld_check_button("matchbavahafa"))
40  , m_xMatchTsithichiDhizi(m_xBuilder->weld_check_button("matchtsithichidhizi"))
41  , m_xMatchHyuiyuByuvyu(m_xBuilder->weld_check_button("matchhyuiyubyuvyu"))
42  , m_xMatchSesheZeje(m_xBuilder->weld_check_button("matchseshezeje"))
43  , m_xMatchIaiya(m_xBuilder->weld_check_button("matchiaiya"))
44  , m_xMatchKiku(m_xBuilder->weld_check_button("matchkiku"))
45  , m_xMatchProlongedSoundMark(m_xBuilder->weld_check_button("matchprolongedsoundmark"))
46  , m_xIgnorePunctuation(m_xBuilder->weld_check_button("ignorepunctuation"))
47  , m_xIgnoreWhitespace(m_xBuilder->weld_check_button("ignorewhitespace"))
48  , m_xIgnoreMiddleDot(m_xBuilder->weld_check_button("ignoremiddledot"))
49 {
50  bSaveOptions = true;
51  nTransliterationFlags = TransliterationFlags::NONE;
52 }
53 
55 {
56 }
57 
58 std::unique_ptr<SfxTabPage> SvxJSearchOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
59 {
60  return std::make_unique<SvxJSearchOptionsPage>(pPage, pController, *rSet);
61 }
62 
64 {
65  bool bVal(nSettings & TransliterationFlags::IGNORE_CASE);
66  m_xMatchCase ->set_active( bVal );
67  bVal = bool(nSettings & TransliterationFlags::IGNORE_WIDTH);
68  m_xMatchFullHalfWidth ->set_active( bVal );
69  bVal = bool(nSettings & TransliterationFlags::IGNORE_KANA);
70  m_xMatchHiraganaKatakana ->set_active( bVal );
71  bVal = bool(nSettings & TransliterationFlags::ignoreSize_ja_JP);
72  m_xMatchContractions ->set_active( bVal );
73  bVal = bool(nSettings & TransliterationFlags::ignoreMinusSign_ja_JP);
74  m_xMatchMinusDashChoon ->set_active( bVal );
75  bVal = bool(nSettings & TransliterationFlags::ignoreIterationMark_ja_JP);
76  m_xMatchRepeatCharMarks ->set_active( bVal );
77  bVal = bool(nSettings & TransliterationFlags::ignoreTraditionalKanji_ja_JP);
78  m_xMatchVariantFormKanji ->set_active( bVal );
79  bVal = bool(nSettings & TransliterationFlags::ignoreTraditionalKana_ja_JP);
80  m_xMatchOldKanaForms ->set_active( bVal );
81  bVal = bool(nSettings & TransliterationFlags::ignoreZiZu_ja_JP);
82  m_xMatchDiziDuzu ->set_active( bVal );
83  bVal = bool(nSettings & TransliterationFlags::ignoreBaFa_ja_JP);
84  m_xMatchBavaHafa ->set_active( bVal );
85  bVal = bool(nSettings & TransliterationFlags::ignoreTiJi_ja_JP);
86  m_xMatchTsithichiDhizi ->set_active( bVal );
87  bVal = bool(nSettings & TransliterationFlags::ignoreHyuByu_ja_JP);
88  m_xMatchHyuiyuByuvyu ->set_active( bVal );
89  bVal = bool(nSettings & TransliterationFlags::ignoreSeZe_ja_JP);
90  m_xMatchSesheZeje ->set_active( bVal );
91  bVal = bool(nSettings & TransliterationFlags::ignoreIandEfollowedByYa_ja_JP);
92  m_xMatchIaiya ->set_active( bVal );
93  bVal = bool(nSettings & TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP);
94  m_xMatchKiku ->set_active( bVal );
95  bVal = bool(nSettings & TransliterationFlags::ignoreSeparator_ja_JP);
96  m_xIgnorePunctuation ->set_active( bVal );
97  bVal = bool(nSettings & TransliterationFlags::ignoreSpace_ja_JP);
98  m_xIgnoreWhitespace ->set_active( bVal );
99  bVal = bool(nSettings & TransliterationFlags::ignoreProlongedSoundMark_ja_JP);
100  m_xMatchProlongedSoundMark->set_active( bVal );
101  bVal = bool(nSettings & TransliterationFlags::ignoreMiddleDot_ja_JP);
102  m_xIgnoreMiddleDot ->set_active( bVal );
103 
104  nTransliterationFlags = nSettings;
105 }
106 
108 {
109  TransliterationFlags nTmp = TransliterationFlags::NONE;
110  if (m_xMatchCase->get_active())
111  nTmp |= TransliterationFlags::IGNORE_CASE;
112  if (m_xMatchFullHalfWidth->get_active())
113  nTmp |= TransliterationFlags::IGNORE_WIDTH;
114  if (m_xMatchHiraganaKatakana->get_active())
115  nTmp |= TransliterationFlags::IGNORE_KANA;
116  if (m_xMatchContractions->get_active())
117  nTmp |= TransliterationFlags::ignoreSize_ja_JP;
118  if (m_xMatchMinusDashChoon->get_active())
119  nTmp |= TransliterationFlags::ignoreMinusSign_ja_JP;
120  if (m_xMatchRepeatCharMarks->get_active())
121  nTmp |= TransliterationFlags::ignoreIterationMark_ja_JP;
122  if (m_xMatchVariantFormKanji->get_active())
123  nTmp |= TransliterationFlags::ignoreTraditionalKanji_ja_JP;
124  if (m_xMatchOldKanaForms->get_active())
125  nTmp |= TransliterationFlags::ignoreTraditionalKana_ja_JP;
126  if (m_xMatchDiziDuzu->get_active())
127  nTmp |= TransliterationFlags::ignoreZiZu_ja_JP;
128  if (m_xMatchBavaHafa->get_active())
129  nTmp |= TransliterationFlags::ignoreBaFa_ja_JP;
130  if (m_xMatchTsithichiDhizi->get_active())
131  nTmp |= TransliterationFlags::ignoreTiJi_ja_JP;
132  if (m_xMatchHyuiyuByuvyu->get_active())
133  nTmp |= TransliterationFlags::ignoreHyuByu_ja_JP;
134  if (m_xMatchSesheZeje->get_active())
135  nTmp |= TransliterationFlags::ignoreSeZe_ja_JP;
136  if (m_xMatchIaiya->get_active())
137  nTmp |= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP;
138  if (m_xMatchKiku->get_active())
139  nTmp |= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP;
140  if (m_xIgnorePunctuation->get_active())
141  nTmp |= TransliterationFlags::ignoreSeparator_ja_JP;
142  if (m_xIgnoreWhitespace->get_active())
143  nTmp |= TransliterationFlags::ignoreSpace_ja_JP;
144  if (m_xMatchProlongedSoundMark->get_active())
145  nTmp |= TransliterationFlags::ignoreProlongedSoundMark_ja_JP;
146  if (m_xIgnoreMiddleDot->get_active())
147  nTmp |= TransliterationFlags::ignoreMiddleDot_ja_JP;
148 
149  nTransliterationFlags = nTmp;
150  return nTransliterationFlags;
151 }
152 
153 
155 {
156  SvtSearchOptions aOpt;
157 
158  // read settings from configuration
159  m_xMatchCase ->set_active(!aOpt.IsMatchCase() );
160  m_xMatchFullHalfWidth ->set_active( aOpt.IsMatchFullHalfWidthForms() );
161  m_xMatchHiraganaKatakana ->set_active( aOpt.IsMatchHiraganaKatakana() );
162  m_xMatchContractions ->set_active( aOpt.IsMatchContractions() );
163  m_xMatchMinusDashChoon ->set_active( aOpt.IsMatchMinusDashChoon() );
164  m_xMatchRepeatCharMarks ->set_active( aOpt.IsMatchRepeatCharMarks() );
165  m_xMatchVariantFormKanji ->set_active( aOpt.IsMatchVariantFormKanji() );
166  m_xMatchOldKanaForms ->set_active( aOpt.IsMatchOldKanaForms() );
167  m_xMatchDiziDuzu ->set_active( aOpt.IsMatchDiziDuzu() );
168  m_xMatchBavaHafa ->set_active( aOpt.IsMatchBavaHafa() );
169  m_xMatchTsithichiDhizi ->set_active( aOpt.IsMatchTsithichiDhizi() );
170  m_xMatchHyuiyuByuvyu ->set_active( aOpt.IsMatchHyuiyuByuvyu() );
171  m_xMatchSesheZeje ->set_active( aOpt.IsMatchSesheZeje() );
172  m_xMatchIaiya ->set_active( aOpt.IsMatchIaiya() );
173  m_xMatchKiku ->set_active( aOpt.IsMatchKiku() );
174  m_xIgnorePunctuation ->set_active( aOpt.IsIgnorePunctuation() );
175  m_xIgnoreWhitespace ->set_active( aOpt.IsIgnoreWhitespace() );
177  m_xIgnoreMiddleDot ->set_active( aOpt.IsIgnoreMiddleDot() );
178 
181  "Transliteration settings different" );
182 
183  m_xMatchCase ->save_state();
184  m_xMatchFullHalfWidth ->save_state();
185  m_xMatchHiraganaKatakana ->save_state();
186  m_xMatchContractions ->save_state();
187  m_xMatchMinusDashChoon ->save_state();
188  m_xMatchRepeatCharMarks ->save_state();
189  m_xMatchVariantFormKanji ->save_state();
190  m_xMatchOldKanaForms ->save_state();
191  m_xMatchDiziDuzu ->save_state();
192  m_xMatchBavaHafa ->save_state();
193  m_xMatchTsithichiDhizi ->save_state();
194  m_xMatchHyuiyuByuvyu ->save_state();
195  m_xMatchSesheZeje ->save_state();
196  m_xMatchIaiya ->save_state();
197  m_xMatchKiku ->save_state();
198  m_xIgnorePunctuation ->save_state();
199  m_xIgnoreWhitespace ->save_state();
200  m_xMatchProlongedSoundMark ->save_state();
201  m_xIgnoreMiddleDot ->save_state();
202 }
203 
204 
206 {
209  bool bModified = nOldVal != nTransliterationFlags;
210 
211  if (!bSaveOptions)
212  return bModified;
213 
214  bModified = false;
215  SvtSearchOptions aOpt;
216  bool bNewVal, bChanged;
217 
218  bNewVal = m_xMatchCase->get_active();
219  bChanged = m_xMatchCase->get_state_changed_from_saved();
220  if (bChanged)
221  {
222  aOpt.SetMatchCase(!bNewVal );
223  bModified = true;
224  }
225  bNewVal = m_xMatchFullHalfWidth->get_active();
226  bChanged = m_xMatchFullHalfWidth->get_state_changed_from_saved();
227  if (bChanged)
228  {
229  aOpt.SetMatchFullHalfWidthForms( bNewVal );
230  bModified = true;
231  }
232  bNewVal = m_xMatchHiraganaKatakana->get_active();
233  bChanged = m_xMatchHiraganaKatakana->get_state_changed_from_saved();
234  if (bChanged)
235  {
236  aOpt.SetMatchHiraganaKatakana( bNewVal );
237  bModified = true;
238  }
239  bNewVal = m_xMatchContractions->get_active();
240  bChanged = m_xMatchContractions->get_state_changed_from_saved();
241  if (bChanged)
242  {
243  aOpt.SetMatchContractions( bNewVal );
244  bModified = true;
245  }
246  bNewVal = m_xMatchMinusDashChoon->get_active();
247  bChanged = m_xMatchMinusDashChoon->get_state_changed_from_saved();
248  if (bChanged)
249  {
250  aOpt.SetMatchMinusDashChoon( bNewVal );
251  bModified = true;
252  }
253  bNewVal = m_xMatchRepeatCharMarks->get_active();
254  bChanged = m_xMatchRepeatCharMarks->get_state_changed_from_saved();
255  if (bChanged)
256  {
257  aOpt.SetMatchRepeatCharMarks( bNewVal );
258  bModified = true;
259  }
260  bNewVal = m_xMatchVariantFormKanji->get_active();
261  bChanged = m_xMatchVariantFormKanji->get_state_changed_from_saved();
262  if (bChanged)
263  {
264  aOpt.SetMatchVariantFormKanji( bNewVal );
265  bModified = true;
266  }
267  bNewVal = m_xMatchOldKanaForms->get_active();
268  bChanged = m_xMatchOldKanaForms->get_state_changed_from_saved();
269  if (bChanged)
270  {
271  aOpt.SetMatchOldKanaForms( bNewVal );
272  bModified = true;
273  }
274  bNewVal = m_xMatchDiziDuzu->get_active();
275  bChanged = m_xMatchDiziDuzu->get_state_changed_from_saved();
276  if (bChanged)
277  {
278  aOpt.SetMatchDiziDuzu( bNewVal );
279  bModified = true;
280  }
281  bNewVal = m_xMatchBavaHafa->get_active();
282  bChanged = m_xMatchBavaHafa->get_state_changed_from_saved();
283  if (bChanged)
284  {
285  aOpt.SetMatchBavaHafa( bNewVal );
286  bModified = true;
287  }
288  bNewVal = m_xMatchTsithichiDhizi->get_active();
289  bChanged = m_xMatchTsithichiDhizi->get_state_changed_from_saved();
290  if (bChanged)
291  {
292  aOpt.SetMatchTsithichiDhizi( bNewVal );
293  bModified = true;
294  }
295  bNewVal = m_xMatchHyuiyuByuvyu->get_active();
296  bChanged = m_xMatchHyuiyuByuvyu->get_state_changed_from_saved();
297  if (bChanged)
298  {
299  aOpt.SetMatchHyuiyuByuvyu( bNewVal );
300  bModified = true;
301  }
302  bNewVal = m_xMatchSesheZeje->get_active();
303  bChanged = m_xMatchSesheZeje->get_state_changed_from_saved();
304  if (bChanged)
305  {
306  aOpt.SetMatchSesheZeje( bNewVal );
307  bModified = true;
308  }
309  bNewVal = m_xMatchIaiya->get_active();
310  bChanged = m_xMatchIaiya->get_state_changed_from_saved();
311  if (bChanged)
312  {
313  aOpt.SetMatchIaiya( bNewVal );
314  bModified = true;
315  }
316  bNewVal = m_xMatchKiku->get_active();
317  bChanged = m_xMatchKiku->get_state_changed_from_saved();
318  if (bChanged)
319  {
320  aOpt.SetMatchKiku( bNewVal );
321  bModified = true;
322  }
323  bNewVal = m_xIgnorePunctuation->get_active();
324  bChanged = m_xIgnorePunctuation->get_state_changed_from_saved();
325  if (bChanged)
326  {
327  aOpt.SetIgnorePunctuation( bNewVal );
328  bModified = true;
329  }
330  bNewVal = m_xIgnoreWhitespace->get_active();
331  bChanged = m_xIgnoreWhitespace->get_state_changed_from_saved();
332  if (bChanged)
333  {
334  aOpt.SetIgnoreWhitespace( bNewVal );
335  bModified = true;
336  }
337  bNewVal = m_xMatchProlongedSoundMark->get_active();
338  bChanged = m_xMatchProlongedSoundMark->get_state_changed_from_saved();
339  if (bChanged)
340  {
341  aOpt.SetIgnoreProlongedSoundMark( bNewVal );
342  bModified = true;
343  }
344  bNewVal = m_xIgnoreMiddleDot->get_active();
345  bChanged = m_xIgnoreMiddleDot->get_state_changed_from_saved();
346  if (bChanged)
347  {
348  aOpt.SetIgnoreMiddleDot( bNewVal );
349  bModified = true;
350  }
351 
352  if (bModified)
353  aOpt.Commit();
354 
355  return bModified;
356 }
357 
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::CheckButton > m_xIgnoreWhitespace
Definition: optjsearch.hxx:50
std::unique_ptr< weld::CheckButton > m_xMatchContractions
Definition: optjsearch.hxx:35
TransliterationFlags GetTransliterationFlags_Impl()
Definition: optjsearch.cxx:107
std::unique_ptr< weld::CheckButton > m_xMatchFullHalfWidth
Definition: optjsearch.hxx:33
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optjsearch.cxx:58
std::unique_ptr< weld::CheckButton > m_xIgnorePunctuation
Definition: optjsearch.hxx:49
std::unique_ptr< weld::CheckButton > m_xMatchBavaHafa
Definition: optjsearch.hxx:41
std::unique_ptr< weld::CheckButton > m_xMatchHiraganaKatakana
Definition: optjsearch.hxx:34
std::unique_ptr< weld::CheckButton > m_xMatchVariantFormKanji
Definition: optjsearch.hxx:38
bool IsMatchFullHalfWidthForms() const
bool IsMatchMinusDashChoon() const
void SetMatchTsithichiDhizi(bool bVal)
bool IsMatchContractions() const
void SetMatchMinusDashChoon(bool bVal)
bool IsMatchVariantFormKanji() const
std::unique_ptr< weld::CheckButton > m_xMatchTsithichiDhizi
Definition: optjsearch.hxx:42
virtual void Reset(const SfxItemSet *rSet) override
Definition: optjsearch.cxx:154
void SetMatchSesheZeje(bool bVal)
void SetIgnoreWhitespace(bool bVal)
void SetMatchContractions(bool bVal)
void SetMatchHyuiyuByuvyu(bool bVal)
bool IsMatchDiziDuzu() const
std::unique_ptr< weld::CheckButton > m_xMatchCase
Definition: optjsearch.hxx:32
bool IsIgnorePunctuation() const
bool IsMatchSesheZeje() const
std::unique_ptr< weld::CheckButton > m_xMatchProlongedSoundMark
Definition: optjsearch.hxx:47
bool IsIgnoreMiddleDot() const
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optjsearch.cxx:205
void SetIgnoreProlongedSoundMark(bool bVal)
TransliterationFlags
std::unique_ptr< weld::CheckButton > m_xMatchSesheZeje
Definition: optjsearch.hxx:44
std::unique_ptr< weld::CheckButton > m_xMatchOldKanaForms
Definition: optjsearch.hxx:39
bool IsMatchIaiya() const
bool IsMatchCase() const
bool IsMatchTsithichiDhizi() const
#define DBG_ASSERT(sCon, aError)
std::unique_ptr< weld::CheckButton > m_xIgnoreMiddleDot
Definition: optjsearch.hxx:51
std::unique_ptr< weld::CheckButton > m_xMatchIaiya
Definition: optjsearch.hxx:45
virtual ~SvxJSearchOptionsPage() override
Definition: optjsearch.cxx:54
bool IsIgnoreProlongedSoundMark() const
void SetMatchDiziDuzu(bool bVal)
bool IsIgnoreWhitespace() const
void SetMatchFullHalfWidthForms(bool bVal)
std::unique_ptr< weld::CheckButton > m_xMatchKiku
Definition: optjsearch.hxx:46
bool IsMatchRepeatCharMarks() const
void SetMatchRepeatCharMarks(bool bVal)
void SetMatchHiraganaKatakana(bool bVal)
TransliterationFlags nTransliterationFlags
Definition: optjsearch.hxx:53
void SetMatchKiku(bool bVal)
void SetMatchIaiya(bool bVal)
void SetTransliterationFlags(TransliterationFlags nSettings)
Definition: optjsearch.cxx:63
void SetMatchVariantFormKanji(bool bVal)
bool IsMatchHyuiyuByuvyu() const
void SetIgnoreMiddleDot(bool bVal)
std::unique_ptr< weld::CheckButton > m_xMatchDiziDuzu
Definition: optjsearch.hxx:40
void SetMatchCase(bool bVal)
std::unique_ptr< weld::CheckButton > m_xMatchMinusDashChoon
Definition: optjsearch.hxx:36
bool IsMatchBavaHafa() const
std::unique_ptr< weld::CheckButton > m_xMatchHyuiyuByuvyu
Definition: optjsearch.hxx:43
bool IsMatchOldKanaForms() const
void SetMatchOldKanaForms(bool bVal)
bool IsMatchKiku() const
bool IsMatchHiraganaKatakana() const
void SetIgnorePunctuation(bool bVal)
SvxJSearchOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optjsearch.cxx:28
std::unique_ptr< weld::CheckButton > m_xMatchRepeatCharMarks
Definition: optjsearch.hxx:37
void SetMatchBavaHafa(bool bVal)
TransliterationFlags GetTransliterationFlags() const