LibreOffice Module cui (master)  1
cuifmsearch.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 <vcl/stdtext.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <dialmgr.hxx>
25 #include <sfx2/app.hxx>
26 #include <svx/fmsrccfg.hxx>
27 #include <svx/fmsrcimp.hxx>
28 #include <strings.hrc>
29 #include <cuifmsearch.hxx>
30 #include <svl/cjkoptions.hxx>
32 #include <comphelper/string.hxx>
33 #include <svx/svxdlg.hxx>
34 
35 using namespace css::uno;
36 using namespace css::i18n;
37 using namespace ::svxform;
38 using namespace css::sdbc;
39 using namespace css::util;
40 
41 #define MAX_HISTORY_ENTRIES 50
42 
43 void FmSearchDialog::initCommon( const Reference< XResultSet >& _rxCursor )
44 {
45  // init the engine
46  DBG_ASSERT( m_pSearchEngine, "FmSearchDialog::initCommon: have no engine!" );
47  m_pSearchEngine->SetProgressHandler(LINK(this, FmSearchDialog, OnSearchProgress));
48 
49  // some layout changes according to available CJK options
51  {
52  // hide the options for the japanese search
53  m_pSoundsLikeCJK->hide();
54  m_pSoundsLikeCJKSettings->hide();
55  }
56 
58  {
59  m_pHalfFullFormsCJK->hide();
60 
61  // never ignore the width (ignoring is expensive) if the option is not available at all
62  m_pSearchEngine->SetIgnoreWidthCJK( false );
63  }
64 
65  // some initial record texts
66  m_pftRecord->set_label( OUString::number(_rxCursor->getRow()) );
67  m_pbClose->set_tooltip_text(OUString());
68 }
69 
70 FmSearchDialog::FmSearchDialog(weld::Window* pParent, const OUString& sInitialText, const std::vector< OUString >& _rContexts, sal_Int16 nInitialContext,
71  const Link<FmSearchContext&,sal_uInt32>& lnkContextSupplier)
72  : GenericDialogController(pParent, "cui/ui/fmsearchdialog.ui", "RecordSearchDialog")
73  , m_sCancel( GetStandardText( StandardButtonType::Cancel ) )
74  , m_lnkContextSupplier(lnkContextSupplier)
75  , m_prbSearchForText(m_xBuilder->weld_radio_button("rbSearchForText"))
76  , m_prbSearchForNull(m_xBuilder->weld_radio_button("rbSearchForNull"))
77  , m_prbSearchForNotNull(m_xBuilder->weld_radio_button("rbSearchForNotNull"))
78  , m_pcmbSearchText(m_xBuilder->weld_combo_box("cmbSearchText"))
79  , m_pftForm(m_xBuilder->weld_label("ftForm"))
80  , m_plbForm(m_xBuilder->weld_combo_box("lbForm"))
81  , m_prbAllFields(m_xBuilder->weld_radio_button("rbAllFields"))
82  , m_prbSingleField(m_xBuilder->weld_radio_button("rbSingleField"))
83  , m_plbField(m_xBuilder->weld_combo_box("lbField"))
84  , m_pftPosition(m_xBuilder->weld_label("ftPosition"))
85  , m_plbPosition(m_xBuilder->weld_combo_box("lbPosition"))
86  , m_pcbUseFormat(m_xBuilder->weld_check_button("cbUseFormat"))
87  , m_pcbCase(m_xBuilder->weld_check_button("cbCase"))
88  , m_pcbBackwards(m_xBuilder->weld_check_button("cbBackwards"))
89  , m_pcbStartOver(m_xBuilder->weld_check_button("cbStartOver"))
90  , m_pcbWildCard(m_xBuilder->weld_check_button("cbWildCard"))
91  , m_pcbRegular(m_xBuilder->weld_check_button("cbRegular"))
92  , m_pcbApprox(m_xBuilder->weld_check_button("cbApprox"))
93  , m_ppbApproxSettings(m_xBuilder->weld_button("pbApproxSettings"))
94  , m_pHalfFullFormsCJK(m_xBuilder->weld_check_button("HalfFullFormsCJK"))
95  , m_pSoundsLikeCJK(m_xBuilder->weld_check_button("SoundsLikeCJK"))
96  , m_pSoundsLikeCJKSettings(m_xBuilder->weld_button("SoundsLikeCJKSettings"))
97  , m_pftRecord(m_xBuilder->weld_label("ftRecord"))
98  , m_pftHint(m_xBuilder->weld_label("ftHint"))
99  , m_pbSearchAgain(m_xBuilder->weld_button("pbSearchAgain"))
100  , m_pbClose(m_xBuilder->weld_button("close"))
101 {
102  m_pcmbSearchText->set_size_request(m_pcmbSearchText->get_approximate_digit_width() * 38, -1);
103  m_plbForm->set_size_request(m_plbForm->get_approximate_digit_width() * 38, -1);
104  m_sSearch = m_pbSearchAgain->get_label();
105 
106  DBG_ASSERT(m_lnkContextSupplier.IsSet(), "FmSearchDialog::FmSearchDialog : have no ContextSupplier !");
107 
108  FmSearchContext fmscInitial;
109  fmscInitial.nContext = nInitialContext;
110  m_lnkContextSupplier.Call(fmscInitial);
111  DBG_ASSERT(fmscInitial.xCursor.is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
112  DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';') == static_cast<sal_Int32>(fmscInitial.arrFields.size()),
113  "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplied !");
114 #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
115  for (const Reference<XInterface> & arrField : fmscInitial.arrFields)
116  {
117  DBG_ASSERT(arrField.is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
118  }
119 #endif // (OSL_DEBUG_LEVEL > 1) || DBG_UTIL
120 
121  for ( std::vector< OUString >::const_iterator context = _rContexts.begin();
122  context != _rContexts.end();
123  ++context
124  )
125  {
126  m_arrContextFields.emplace_back();
127  m_plbForm->append_text(*context);
128  }
129  m_plbForm->set_active(nInitialContext);
130 
131  m_plbForm->connect_changed(LINK(this, FmSearchDialog, OnContextSelection));
132 
133  if (m_arrContextFields.size() == 1)
134  {
135  // hide dispensable controls
136  m_pftForm->hide();
137  m_plbForm->hide();
138  }
139 
140  m_pSearchEngine.reset( new FmSearchEngine(
141  ::comphelper::getProcessComponentContext(), fmscInitial.xCursor, fmscInitial.strUsedFields, fmscInitial.arrFields ) );
142  initCommon( fmscInitial.xCursor );
143 
144  if ( !fmscInitial.sFieldDisplayNames.isEmpty() )
145  { // use the display names if supplied
146  DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.sFieldDisplayNames, ';') == comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';'),
147  "FmSearchDialog::FmSearchDialog : invalid initial context description !");
148  Init(fmscInitial.sFieldDisplayNames, sInitialText);
149  }
150  else
151  Init(fmscInitial.strUsedFields, sInitialText);
152 }
153 
155 {
156  SaveParams();
157 
158  m_pConfig.reset();
159  m_pSearchEngine.reset();
160 }
161 
162 void FmSearchDialog::Init(const OUString& strVisibleFields, const OUString& sInitialText)
163 {
164  //the initialization of all the Controls
165  m_prbSearchForText->connect_toggled(LINK(this, FmSearchDialog, OnToggledSearchRadio));
166  m_prbSearchForNull->connect_toggled(LINK(this, FmSearchDialog, OnToggledSearchRadio));
167  m_prbSearchForNotNull->connect_toggled(LINK(this, FmSearchDialog, OnToggledSearchRadio));
168 
169  m_prbAllFields->connect_toggled(LINK(this, FmSearchDialog, OnToggledFieldRadios));
170  m_prbSingleField->connect_toggled(LINK(this, FmSearchDialog, OnToggledFieldRadios));
171 
172  m_pbSearchAgain->connect_clicked(LINK(this, FmSearchDialog, OnClickedSearchAgain));
173  m_ppbApproxSettings->connect_clicked(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
174  m_pSoundsLikeCJKSettings->connect_clicked(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
175 
176  m_plbPosition->connect_changed(LINK(this, FmSearchDialog, OnPositionSelected));
177  m_plbField->connect_changed(LINK(this, FmSearchDialog, OnFieldSelected));
178 
179  m_pcmbSearchText->connect_changed(LINK(this, FmSearchDialog, OnSearchTextModified));
180  m_pcmbSearchText->set_entry_completion(false);
181  m_pcmbSearchText->connect_focus_in(LINK(this, FmSearchDialog, OnFocusGrabbed));
182 
183  m_pcbUseFormat->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
184  m_pcbBackwards->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
185  m_pcbStartOver->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
186  m_pcbCase->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
187  m_pcbWildCard->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
188  m_pcbRegular->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
189  m_pcbApprox->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
190  m_pHalfFullFormsCJK->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
191  m_pSoundsLikeCJK->connect_toggled(LINK(this, FmSearchDialog, OnCheckBoxToggled));
192 
193  // fill the listboxes
194  // method of field comparison
195  const TranslateId aResIds[] = {
196  RID_STR_SEARCH_ANYWHERE,
197  RID_STR_SEARCH_BEGINNING,
198  RID_STR_SEARCH_END,
199  RID_STR_SEARCH_WHOLE
200  };
201  for (auto const & pResId : aResIds)
202  m_plbPosition->append_text(CuiResId(pResId));
203  m_plbPosition->set_active(MATCHING_ANYWHERE);
204 
205  // the field listbox
206  if (!strVisibleFields.isEmpty())
207  {
208  sal_Int32 nPos {0};
209  do {
210  m_plbField->append_text(strVisibleFields.getToken(0, ';', nPos));
211  } while (nPos>=0);
212  }
213 
214 
215  m_pConfig.reset( new FmSearchConfigItem );
216  LoadParams();
217 
218  m_pcmbSearchText->set_entry_text(sInitialText);
219  // if the Edit-line has changed the text (e.g. because it contains
220  // control characters, as can be the case with memo fields), I use
221  // an empty OUString.
222  OUString sRealSetText = m_pcmbSearchText->get_active_text();
223  if (sRealSetText != sInitialText)
224  m_pcmbSearchText->set_entry_text(OUString());
225  OnSearchTextModified(*m_pcmbSearchText);
226 
227  // initial
228  EnableSearchUI(true);
229 
230  if ( m_prbSearchForText->get_active() )
231  m_pcmbSearchText->grab_focus();
232 
233 }
234 
236 {
237  short nRet = weld::GenericDialogController::run();
238  m_pSearchEngine->CancelSearch();
239  return nRet;
240 }
241 
242 IMPL_LINK(FmSearchDialog, OnToggledSearchRadio, weld::Toggleable&, rButton, void)
243 {
244  if (!rButton.get_active())
245  return;
246  EnableSearchForDependees(true);
247 }
248 
249 IMPL_LINK(FmSearchDialog, OnToggledFieldRadios, weld::Toggleable&, rButton, void)
250 {
251  if (!rButton.get_active())
252  return;
253 
254  // en- or disable field list box accordingly
255  if (m_prbSingleField->get_active())
256  {
257  m_plbField->set_sensitive(true);
258  m_pSearchEngine->RebuildUsedFields(m_plbField->get_active());
259  }
260  else
261  {
262  m_plbField->set_sensitive(false);
263  m_pSearchEngine->RebuildUsedFields(-1);
264  }
265 }
266 
267 IMPL_LINK_NOARG(FmSearchDialog, OnClickedSearchAgain, weld::Button&, void)
268 {
269  if (m_pbClose->get_sensitive())
270  { // the button has the function 'search'
271  OUString strThisRoundText = m_pcmbSearchText->get_active_text();
272  // to history
273  m_pcmbSearchText->remove_text(strThisRoundText);
274  m_pcmbSearchText->insert_text(0, strThisRoundText);
275  // the remove/insert makes sure that a) the OUString does not appear twice and
276  // that b) the last searched strings are at the beginning and limit the list length
277  while (m_pcmbSearchText->get_count() > MAX_HISTORY_ENTRIES)
278  m_pcmbSearchText->remove(m_pcmbSearchText->get_count()-1);
279 
280  // take out the 'overflow' hint
281  m_pftHint->set_label(OUString());
282 
283  if (m_pcbStartOver->get_active())
284  {
285  m_pcbStartOver->set_active(false);
286  EnableSearchUI(false);
287  if (m_prbSearchForText->get_active())
288  m_pSearchEngine->StartOver(strThisRoundText);
289  else
290  m_pSearchEngine->StartOverSpecial(m_prbSearchForNull->get_active());
291  }
292  else
293  {
294  EnableSearchUI(false);
295  if (m_prbSearchForText->get_active())
296  m_pSearchEngine->SearchNext(strThisRoundText);
297  else
298  m_pSearchEngine->SearchNextSpecial(m_prbSearchForNull->get_active());
299  }
300  }
301  else
302  { // the button has the function 'cancel'
303  // the CancelButton is usually only disabled, when working in a thread or with reschedule
304  m_pSearchEngine->CancelSearch();
305  // the ProgressHandler is called when it's really finished, here it's only a demand
306  }
307 }
308 
309 IMPL_LINK(FmSearchDialog, OnClickedSpecialSettings, weld::Button&, rButton, void)
310 {
311  if (m_ppbApproxSettings.get() == &rButton)
312  {
314  ScopedVclPtr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog(m_xDialog.get(), m_pSearchEngine->GetLevRelaxed(), m_pSearchEngine->GetLevOther(),
315  m_pSearchEngine->GetLevShorter(), m_pSearchEngine->GetLevLonger() ));
316  if (pDlg->Execute() == RET_OK)
317  {
318  m_pSearchEngine->SetLevRelaxed( pDlg->IsRelaxed() );
319  m_pSearchEngine->SetLevOther( pDlg->GetOther() );
320  m_pSearchEngine->SetLevShorter(pDlg->GetShorter() );
321  m_pSearchEngine->SetLevLonger( pDlg->GetLonger() );
322  }
323  }
324  else if (m_pSoundsLikeCJKSettings.get() == &rButton)
325  {
326  SfxItemSet aSet( SfxGetpApp()->GetPool() );
328  ScopedVclPtr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog(m_xDialog.get(), aSet, m_pSearchEngine->GetTransliterationFlags() ));
329  aDlg->Execute();
330 
332  m_pSearchEngine->SetTransliterationFlags(nFlags);
333 
334  m_pcbCase->set_active(m_pSearchEngine->GetCaseSensitive());
335  OnCheckBoxToggled( *m_pcbCase );
336  m_pHalfFullFormsCJK->set_active( !m_pSearchEngine->GetIgnoreWidthCJK() );
337  OnCheckBoxToggled( *m_pHalfFullFormsCJK );
338  }
339 }
340 
341 IMPL_LINK_NOARG(FmSearchDialog, OnSearchTextModified, weld::ComboBox&, void)
342 {
343  if ((!m_pcmbSearchText->get_active_text().isEmpty()) || !m_prbSearchForText->get_active())
344  m_pbSearchAgain->set_sensitive(true);
345  else
346  m_pbSearchAgain->set_sensitive(false);
347 
348  m_pSearchEngine->InvalidatePreviousLoc();
349 }
350 
352 {
353  m_pcmbSearchText->select_entry_region(0, -1);
354 }
355 
356 IMPL_LINK_NOARG(FmSearchDialog, OnPositionSelected, weld::ComboBox&, void)
357 {
358  m_pSearchEngine->SetPosition(m_plbPosition->get_active());
359 }
360 
362 {
363  m_pSearchEngine->RebuildUsedFields(m_prbAllFields->get_active() ? -1 : m_plbField->get_active());
364  // calls m_pSearchEngine->InvalidatePreviousLoc too
365 
366  int nCurrentContext = m_plbForm->get_active();
367  if (nCurrentContext != -1)
368  m_arrContextFields[nCurrentContext] = m_plbField->get_active_text();
369 }
370 
371 IMPL_LINK(FmSearchDialog, OnCheckBoxToggled, weld::Toggleable&, rBox, void)
372 {
373  bool bChecked = rBox.get_active();
374 
375  // formatter or case -> pass on to the engine
376  if (&rBox == m_pcbUseFormat.get())
377  m_pSearchEngine->SetFormatterUsing(bChecked);
378  else if (&rBox == m_pcbCase.get())
379  m_pSearchEngine->SetCaseSensitive(bChecked);
380  // direction -> pass on and reset the checkbox-text for StartOver
381  else if (&rBox == m_pcbBackwards.get())
382  {
383  m_pcbStartOver->set_label( CuiResId( bChecked ? RID_STR_FROM_BOTTOM : RID_STR_FROM_TOP ) );
384  m_pSearchEngine->SetDirection(!bChecked);
385  }
386  // similarity-search or regular expression
387  else if ((&rBox == m_pcbApprox.get()) || (&rBox == m_pcbRegular.get()) || (&rBox == m_pcbWildCard.get()))
388  {
389  weld::CheckButton* pBoxes[] = { m_pcbWildCard.get(), m_pcbRegular.get(), m_pcbApprox.get() };
390  for (weld::CheckButton* pBoxe : pBoxes)
391  {
392  if (pBoxe != &rBox)
393  {
394  if (bChecked)
395  pBoxe->set_sensitive(false);
396  else
397  pBoxe->set_sensitive(true);
398  }
399  }
400 
401  // pass on to the engine
402  m_pSearchEngine->SetWildcard(m_pcbWildCard->get_sensitive() && m_pcbWildCard->get_active());
403  m_pSearchEngine->SetRegular(m_pcbRegular->get_sensitive() && m_pcbRegular->get_active());
404  m_pSearchEngine->SetLevenshtein(m_pcbApprox->get_sensitive() && m_pcbApprox->get_active());
405  // (disabled boxes have to be passed to the engine as sal_False)
406 
407  // adjust the Position-Listbox (which is not allowed during Wildcard-search)
408  if (&rBox == m_pcbWildCard.get())
409  {
410  if (bChecked)
411  {
412  m_pftPosition->set_sensitive(false);
413  m_plbPosition->set_sensitive(false);
414  }
415  else
416  {
417  m_pftPosition->set_sensitive(true);
418  m_plbPosition->set_sensitive(true);
419  }
420  }
421 
422  // and the button for similarity-search
423  if (&rBox == m_pcbApprox.get())
424  {
425  if (bChecked)
426  m_ppbApproxSettings->set_sensitive(true);
427  else
428  m_ppbApproxSettings->set_sensitive(false);
429  }
430  }
431  else if (&rBox == m_pHalfFullFormsCJK.get())
432  {
433  // forward to the search engine
434  m_pSearchEngine->SetIgnoreWidthCJK( !bChecked );
435  }
436  else if (&rBox == m_pSoundsLikeCJK.get())
437  {
438  m_pSoundsLikeCJKSettings->set_sensitive(bChecked);
439 
440  // two other buttons which depend on this one
441  bool bEnable = ( m_prbSearchForText->get_active()
442  && !m_pSoundsLikeCJK->get_active()
443  )
445  m_pcbCase->set_sensitive(bEnable);
446  m_pHalfFullFormsCJK->set_sensitive(bEnable);
447 
448  // forward to the search engine
449  m_pSearchEngine->SetTransliteration( bChecked );
450  }
451 }
452 
453 void FmSearchDialog::InitContext(sal_Int16 nContext)
454 {
455  FmSearchContext fmscContext;
456  fmscContext.nContext = nContext;
457 
458  sal_uInt32 nResult = m_lnkContextSupplier.Call(fmscContext);
459  DBG_ASSERT(nResult > 0, "FmSearchDialog::InitContext : ContextSupplier didn't give me any controls !");
460 
461  // put the field names into the respective listbox
462  m_plbField->clear();
463 
464  if (!fmscContext.sFieldDisplayNames.isEmpty())
465  {
466  // use the display names if supplied
468  "FmSearchDialog::InitContext : invalid context description supplied !");
469  sal_Int32 nPos {0};
470  do {
471  m_plbField->append_text(fmscContext.sFieldDisplayNames.getToken(0, ';', nPos));
472  } while (nPos>=0);
473  }
474  else if (!fmscContext.strUsedFields.isEmpty())
475  {
476  // else use the field names
477  sal_Int32 nPos {0};
478  do {
479  m_plbField->append_text(fmscContext.strUsedFields.getToken(0, ';', nPos));
480  } while (nPos>=0);
481  }
482 
483  if (nContext < static_cast<sal_Int32>(m_arrContextFields.size()) && !m_arrContextFields[nContext].isEmpty())
484  {
485  m_plbField->set_active_text(m_arrContextFields[nContext]);
486  }
487  else
488  {
489  m_plbField->set_active(0);
490  if (m_prbSingleField->get_active() && (m_plbField->get_count() > 1))
491  m_plbField->grab_focus();
492  }
493 
494  m_pSearchEngine->SwitchToContext(fmscContext.xCursor, fmscContext.strUsedFields, fmscContext.arrFields,
495  m_prbAllFields->get_active() ? -1 : 0);
496 
497  m_pftRecord->set_label(OUString::number(fmscContext.xCursor->getRow()));
498 }
499 
500 IMPL_LINK(FmSearchDialog, OnContextSelection, weld::ComboBox&, rBox, void)
501 {
502  InitContext(rBox.get_active());
503 }
504 
506 {
507  // the search button has two functions -> adjust its text accordingly
508  OUString sButtonText( bEnable ? m_sSearch : m_sCancel );
509  m_pbSearchAgain->set_label(sButtonText);
510 
511  m_prbSearchForText->set_sensitive(bEnable);
512  m_prbSearchForNull->set_sensitive(bEnable);
513  m_prbSearchForNotNull->set_sensitive(bEnable);
514  m_plbForm->set_sensitive(bEnable);
515  m_prbAllFields->set_sensitive(bEnable);
516  m_prbSingleField->set_sensitive(bEnable);
517  m_plbField->set_sensitive(bEnable && m_prbSingleField->get_active());
518  m_pcbBackwards->set_sensitive(bEnable);
519  m_pcbStartOver->set_sensitive(bEnable);
520  m_pbClose->set_sensitive(bEnable);
521  EnableSearchForDependees(bEnable);
522 
523  if ( !bEnable )
524  { // this means we're preparing for starting a search
525  // In this case, EnableSearchForDependees disabled the search button
526  // But as we're about to use it for cancelling the search, we really need to enable it, again
527  m_pbSearchAgain->set_sensitive(true);
528  }
529 }
530 
532 {
533  bool bSearchingForText = m_prbSearchForText->get_active();
534  m_pbSearchAgain->set_sensitive(bEnable && (!bSearchingForText || (!m_pcmbSearchText->get_active_text().isEmpty())));
535 
536  bEnable = bEnable && bSearchingForText;
537 
538  bool bEnableRedundants = !m_pSoundsLikeCJK->get_active() || !SvtCJKOptions::IsJapaneseFindEnabled();
539 
540  m_pcmbSearchText->set_sensitive(bEnable);
541  m_pftPosition->set_sensitive(bEnable && !m_pcbWildCard->get_active());
542  m_pcbWildCard->set_sensitive(bEnable && !m_pcbRegular->get_active() && !m_pcbApprox->get_active());
543  m_pcbRegular->set_sensitive(bEnable && !m_pcbWildCard->get_active() && !m_pcbApprox->get_active());
544  m_pcbApprox->set_sensitive(bEnable && !m_pcbWildCard->get_active() && !m_pcbRegular->get_active());
545  m_ppbApproxSettings->set_sensitive(bEnable && m_pcbApprox->get_active());
546  m_pHalfFullFormsCJK->set_sensitive(bEnable && bEnableRedundants);
547  m_pSoundsLikeCJK->set_sensitive(bEnable);
548  m_pSoundsLikeCJKSettings->set_sensitive(bEnable && m_pSoundsLikeCJK->get_active());
549  m_plbPosition->set_sensitive(bEnable && !m_pcbWildCard->get_active());
550  m_pcbUseFormat->set_sensitive(bEnable);
551  m_pcbCase->set_sensitive(bEnable && bEnableRedundants);
552 }
553 
554 void FmSearchDialog::OnFound(const css::uno::Any& aCursorPos, sal_Int16 nFieldPos)
555 {
556  FmFoundRecordInformation friInfo;
557  friInfo.nContext = m_plbForm->get_active();
558  // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
559  friInfo.aPosition = aCursorPos;
560  if (m_prbAllFields->get_active())
561  friInfo.nFieldPos = nFieldPos;
562  else
563  friInfo.nFieldPos = m_plbField->get_active();
564  // this of course implies that I have really searched in the field that is selected in the listbox,
565  // which is made sure in RebuildUsedFields
566 
567  m_lnkFoundHandler.Call(friInfo);
568 
569  m_pcmbSearchText->grab_focus();
570 }
571 
572 IMPL_LINK(FmSearchDialog, OnSearchProgress, const FmSearchProgress*, pProgress, void)
573 {
574  SolarMutexGuard aGuard;
575  // make this single method thread-safe (it's an overkill to block the whole application for this,
576  // but we don't have another safety concept at the moment)
577 
578  switch (pProgress->aSearchState)
579  {
581  if (pProgress->bOverflow)
582  {
583  OUString sHint( CuiResId( m_pcbBackwards->get_active() ? RID_STR_OVERFLOW_BACKWARD : RID_STR_OVERFLOW_FORWARD ) );
584  m_pftHint->set_label( sHint );
585  }
586 
587  m_pftRecord->set_label(OUString::number(1 + pProgress->nCurrentRecord));
588  break;
589 
591  m_pftHint->set_label(CuiResId(RID_STR_SEARCH_COUNTING));
592  m_pftRecord->set_label(OUString::number(pProgress->nCurrentRecord));
593  break;
594 
596  OnFound(pProgress->aBookmark, static_cast<sal_Int16>(pProgress->nFieldIndex));
597  EnableSearchUI(true);
598  break;
599 
602  {
603  TranslateId pErrorId = (FmSearchProgress::State::Error == pProgress->aSearchState)
604  ? RID_STR_SEARCH_GENERAL_ERROR
605  : RID_STR_SEARCH_NORECORD;
606  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
607  VclMessageType::Warning, VclButtonsType::Ok, CuiResId(pErrorId)));
608  xBox->run();
609  [[fallthrough]];
610  }
612  EnableSearchUI(true);
613  if (m_lnkCanceledNotFoundHdl.IsSet())
614  {
615  FmFoundRecordInformation friInfo;
616  friInfo.nContext = m_plbForm->get_active();
617  // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
618  friInfo.aPosition = pProgress->aBookmark;
619  m_lnkCanceledNotFoundHdl.Call(friInfo);
620  }
621  break;
622  }
623 
624  m_pftRecord->set_label(OUString::number(1 + pProgress->nCurrentRecord));
625 }
626 
628 {
629  FmSearchParams aParams(m_pConfig->getParams());
630 
631  const OUString* pHistory = aParams.aHistory.getConstArray();
632  const OUString* pHistoryEnd = pHistory + aParams.aHistory.getLength();
633  for (; pHistory != pHistoryEnd; ++pHistory)
634  m_pcmbSearchText->append_text( *pHistory );
635 
636  // I do the settings at my UI-elements and then I simply call the respective change-handler,
637  // that way the data is handed on to the SearchEngine and all dependent settings are done
638 
639  // current field
640  int nInitialField = m_plbField->find_text( aParams.sSingleSearchField );
641  if (nInitialField == -1)
642  nInitialField = 0;
643  m_plbField->set_active(nInitialField);
644  OnFieldSelected(*m_plbField);
645  // all fields/single field (AFTER selecting the field because OnToggledFieldRadios expects a valid value there)
646  if (aParams.bAllFields)
647  {
648  m_prbSingleField->set_active(false);
649  m_prbAllFields->set_active(true);
650  OnToggledFieldRadios(*m_prbAllFields);
651  // OnToggledFieldRadios also calls to RebuildUsedFields
652  }
653  else
654  {
655  m_prbAllFields->set_active(false);
656  m_prbSingleField->set_active(true);
657  OnToggledFieldRadios(*m_prbSingleField);
658  }
659 
660  m_plbPosition->set_active(aParams.nPosition);
661  OnPositionSelected(*m_plbPosition);
662 
663  // field formatting/case sensitivity/direction
664  m_pcbUseFormat->set_active(aParams.bUseFormatter);
665  m_pcbCase->set_active( aParams.isCaseSensitive() );
666  m_pcbBackwards->set_active(aParams.bBackwards);
667  OnCheckBoxToggled(*m_pcbUseFormat);
668  OnCheckBoxToggled(*m_pcbCase);
669  OnCheckBoxToggled(*m_pcbBackwards);
670 
671  m_pHalfFullFormsCJK->set_active( !aParams.isIgnoreWidthCJK( ) ); // BEWARE: this checkbox has an inverse semantics!
672  m_pSoundsLikeCJK->set_active( aParams.bSoundsLikeCJK );
673  OnCheckBoxToggled(*m_pHalfFullFormsCJK);
674  OnCheckBoxToggled(*m_pSoundsLikeCJK);
675 
676  m_pcbWildCard->set_active(false);
677  m_pcbRegular->set_active(false);
678  m_pcbApprox->set_active(false);
679  OnCheckBoxToggled(*m_pcbWildCard);
680  OnCheckBoxToggled(*m_pcbRegular);
681  OnCheckBoxToggled(*m_pcbApprox);
682 
683  weld::CheckButton* pToCheck = nullptr;
684  if (aParams.bWildcard)
685  pToCheck = m_pcbWildCard.get();
686  if (aParams.bRegular)
687  pToCheck = m_pcbRegular.get();
688  if (aParams.bApproxSearch)
689  pToCheck = m_pcbApprox.get();
690  if (aParams.bSoundsLikeCJK)
691  pToCheck = m_pSoundsLikeCJK.get();
692  if (pToCheck)
693  {
694  pToCheck->set_active(true);
695  OnCheckBoxToggled(*pToCheck);
696  }
697 
698  // set Levenshtein-parameters directly at the SearchEngine
699  m_pSearchEngine->SetLevRelaxed(aParams.bLevRelaxed);
700  m_pSearchEngine->SetLevOther(aParams.nLevOther);
701  m_pSearchEngine->SetLevShorter(aParams.nLevShorter);
702  m_pSearchEngine->SetLevLonger(aParams.nLevLonger);
703 
704  m_pSearchEngine->SetTransliterationFlags( aParams.getTransliterationFlags( ) );
705 
706  m_prbSearchForText->set_active(false);
707  m_prbSearchForNull->set_active(false);
708  m_prbSearchForNotNull->set_active(false);
709  switch (aParams.nSearchForType)
710  {
711  case 1: m_prbSearchForNull->set_active(true); break;
712  case 2: m_prbSearchForNotNull->set_active(true); break;
713  default: m_prbSearchForText->set_active(true); break;
714  }
715  OnToggledFieldRadios(*m_prbSearchForText);
716 }
717 
719 {
720  if (!m_pConfig)
721  return;
722 
723  FmSearchParams aCurrentSettings;
724 
725  int nCount = m_pcmbSearchText->get_count();
726  aCurrentSettings.aHistory.realloc(nCount);
727  OUString* pHistory = aCurrentSettings.aHistory.getArray();
728  for (int i = 0; i < nCount; ++i, ++pHistory)
729  *pHistory = m_pcmbSearchText->get_text(i);
730 
731  aCurrentSettings.sSingleSearchField = m_plbField->get_active_text();
732  aCurrentSettings.bAllFields = m_prbAllFields->get_active();
733  aCurrentSettings.nPosition = m_pSearchEngine->GetPosition();
734  aCurrentSettings.bUseFormatter = m_pSearchEngine->GetFormatterUsing();
735  aCurrentSettings.setCaseSensitive ( m_pSearchEngine->GetCaseSensitive() );
736  aCurrentSettings.bBackwards = !m_pSearchEngine->GetDirection();
737  aCurrentSettings.bWildcard = m_pSearchEngine->GetWildcard();
738  aCurrentSettings.bRegular = m_pSearchEngine->GetRegular();
739  aCurrentSettings.bApproxSearch = m_pSearchEngine->GetLevenshtein();
740  aCurrentSettings.bLevRelaxed = m_pSearchEngine->GetLevRelaxed();
741  aCurrentSettings.nLevOther = m_pSearchEngine->GetLevOther();
742  aCurrentSettings.nLevShorter = m_pSearchEngine->GetLevShorter();
743  aCurrentSettings.nLevLonger = m_pSearchEngine->GetLevLonger();
744 
745  aCurrentSettings.bSoundsLikeCJK = m_pSearchEngine->GetTransliteration();
746  aCurrentSettings.setTransliterationFlags ( m_pSearchEngine->GetTransliterationFlags() );
747 
748  if (m_prbSearchForNull->get_active())
749  aCurrentSettings.nSearchForType = 1;
750  else if (m_prbSearchForNotNull->get_active())
751  aCurrentSettings.nSearchForType = 2;
752  else
753  aCurrentSettings.nSearchForType = 0;
754 
755  m_pConfig->setParams( aCurrentSettings );
756 }
757 
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
StandardButtonType
std::unique_ptr< weld::ComboBox > m_plbPosition
Definition: cuifmsearch.hxx:71
std::unique_ptr< weld::Button > m_pSoundsLikeCJKSettings
Definition: cuifmsearch.hxx:82
void SaveParams() const
bool IsCJKFontEnabled()
OUString GetStandardText(StandardButtonType eButton)
std::unique_ptr< weld::RadioButton > m_prbSingleField
Definition: cuifmsearch.hxx:68
std::unique_ptr< weld::ComboBox > m_plbForm
Definition: cuifmsearch.hxx:66
static SvxAbstractDialogFactory * Create()
std::unique_ptr< weld::CheckButton > m_pcbCase
Definition: cuifmsearch.hxx:73
::std::vector< css::uno::Reference< css::uno::XInterface > > arrFields
std::unique_ptr< weld::Button > m_pbClose
Definition: cuifmsearch.hxx:86
std::unique_ptr< weld::CheckButton > m_pcbStartOver
Definition: cuifmsearch.hxx:75
std::unique_ptr< weld::ComboBox > m_pcmbSearchText
Definition: cuifmsearch.hxx:64
SfxApplication * SfxGetpApp()
#define MAX_HISTORY_ENTRIES
Definition: cuifmsearch.cxx:41
std::unique_ptr< weld::CheckButton > m_pcbBackwards
Definition: cuifmsearch.hxx:74
void EnableSearchUI(bool bEnable)
friend class FmSearchEngine
Definition: cuifmsearch.hxx:41
std::unique_ptr< weld::Label > m_pftPosition
Definition: cuifmsearch.hxx:70
bool IsJapaneseFindEnabled()
std::unique_ptr< weld::Label > m_pftRecord
Definition: cuifmsearch.hxx:83
int nCount
Link< FmFoundRecordInformation &, void > m_lnkFoundHandler
Handler for "found".
Definition: cuifmsearch.hxx:46
css::uno::Reference< css::sdbc::XResultSet > xCursor
std::unique_ptr< weld::Label > m_pftForm
Definition: cuifmsearch.hxx:65
TransliterationFlags
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
std::unique_ptr< weld::RadioButton > m_prbSearchForNull
Definition: cuifmsearch.hxx:62
OUString m_sCancel
Definition: cuifmsearch.hxx:44
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
virtual VclPtr< AbstractSvxSearchSimilarityDialog > CreateSvxSearchSimilarityDialog(weld::Window *pParent, bool bRelax, sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)=0
OUString sFieldDisplayNames
IMPL_LINK_NOARG(FmSearchDialog, OnClickedSearchAgain, weld::Button &, void)
std::unique_ptr< weld::CheckButton > m_pcbRegular
Definition: cuifmsearch.hxx:77
#define DBG_ASSERT(sCon, aError)
int i
std::unique_ptr< weld::CheckButton > m_pSoundsLikeCJK
Definition: cuifmsearch.hxx:81
std::unique_ptr< weld::ComboBox > m_plbField
Definition: cuifmsearch.hxx:69
virtual void set_active(bool active)=0
std::unique_ptr< weld::Button > m_ppbApproxSettings
Definition: cuifmsearch.hxx:79
virtual sal_uInt16 GetLonger()=0
std::unique_ptr< weld::CheckButton > m_pHalfFullFormsCJK
Definition: cuifmsearch.hxx:80
virtual TransliterationFlags GetTransliterationFlags() const =0
std::vector< OUString > m_arrContextFields
memorize the currently selected field for every context
Definition: cuifmsearch.hxx:53
std::unique_ptr< weld::CheckButton > m_pcbWildCard
Definition: cuifmsearch.hxx:76
#define MATCHING_ANYWHERE
FmSearchDialog(weld::Window *pParent, const OUString &strInitialText, const std::vector< OUString > &_rContexts, sal_Int16 nInitialContext, const Link< FmSearchContext &, sal_uInt32 > &lnkContextSupplier)
This can search in different sets of fields.
Definition: cuifmsearch.cxx:70
std::unique_ptr< weld::RadioButton > m_prbSearchForText
Definition: cuifmsearch.hxx:61
IMPL_LINK(FmSearchDialog, OnToggledSearchRadio, weld::Toggleable &, rButton, void)
OUString strUsedFields
void EnableSearchForDependees(bool bEnable)
std::unique_ptr< FmSearchEngine > m_pSearchEngine
Definition: cuifmsearch.hxx:55
Dialog for searching in Forms/Tables.
Definition: cuifmsearch.hxx:39
std::unique_ptr< weld::Button > m_pbSearchAgain
Definition: cuifmsearch.hxx:85
std::unique_ptr< weld::CheckButton > m_pcbApprox
Definition: cuifmsearch.hxx:78
virtual VclPtr< AbstractSvxJSearchOptionsDialog > CreateSvxJSearchOptionsDialog(weld::Window *pParent, const SfxItemSet &rOptionsSet, TransliterationFlags nInitialFlags)=0
std::unique_ptr< weld::RadioButton > m_prbAllFields
Definition: cuifmsearch.hxx:67
virtual sal_uInt16 GetOther()=0
void initCommon(const css::uno::Reference< css::sdbc::XResultSet > &_rxCursor)
Definition: cuifmsearch.cxx:43
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
RET_OK
Reference< XExecutableDialog > m_xDialog
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
std::unique_ptr< weld::CheckButton > m_pcbUseFormat
Definition: cuifmsearch.hxx:72
void InitContext(sal_Int16 nContext)
std::unique_ptr< weld::RadioButton > m_prbSearchForNotNull
Definition: cuifmsearch.hxx:63
std::unique_ptr<::svxform::FmSearchConfigItem > m_pConfig
Definition: cuifmsearch.hxx:58
OUString m_sSearch
Definition: cuifmsearch.hxx:43
virtual ~FmSearchDialog() override
virtual sal_uInt16 GetShorter()=0
void Init(const OUString &strVisibleFields, const OUString &strInitialText)
sal_Int16 nContext
void OnFound(const css::uno::Any &aCursorPos, sal_Int16 nFieldPos)
Link< FmSearchContext &, sal_uInt32 > m_lnkContextSupplier
for search in contexts
Definition: cuifmsearch.hxx:50
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt16 nPos
virtual void set_sensitive(bool sensitive)=0
virtual short run() override