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