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 ScopedVclPtr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog(m_xDialog.get(), m_pSearchEngine->GetLevRelaxed(), m_pSearchEngine->GetLevOther(),
316 m_pSearchEngine->GetLevShorter(), m_pSearchEngine->GetLevLonger() ));
317 if (pDlg->Execute() == RET_OK)
318 {
319 m_pSearchEngine->SetLevRelaxed( pDlg->IsRelaxed() );
320 m_pSearchEngine->SetLevOther( pDlg->GetOther() );
321 m_pSearchEngine->SetLevShorter(pDlg->GetShorter() );
322 m_pSearchEngine->SetLevLonger( pDlg->GetLonger() );
323 }
324 }
325 else if (m_pSoundsLikeCJKSettings.get() == &rButton)
326 {
327 SfxItemSet aSet( SfxGetpApp()->GetPool() );
329 ScopedVclPtr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog(m_xDialog.get(), aSet, m_pSearchEngine->GetTransliterationFlags() ));
330 aDlg->Execute();
331
332 TransliterationFlags nFlags = aDlg->GetTransliterationFlags();
333 m_pSearchEngine->SetTransliterationFlags(nFlags);
334
335 m_pcbCase->set_active(m_pSearchEngine->GetCaseSensitive());
336 OnCheckBoxToggled( *m_pcbCase );
337 m_pHalfFullFormsCJK->set_active( !m_pSearchEngine->GetIgnoreWidthCJK() );
338 OnCheckBoxToggled( *m_pHalfFullFormsCJK );
339 }
340}
341
342IMPL_LINK_NOARG(FmSearchDialog, OnSearchTextModified, weld::ComboBox&, void)
343{
344 if ((!m_pcmbSearchText->get_active_text().isEmpty()) || !m_prbSearchForText->get_active())
345 m_pbSearchAgain->set_sensitive(true);
346 else
347 m_pbSearchAgain->set_sensitive(false);
348
349 m_pSearchEngine->InvalidatePreviousLoc();
350}
351
353{
354 m_pcmbSearchText->select_entry_region(0, -1);
355}
356
358{
359 m_pSearchEngine->SetPosition(m_plbPosition->get_active());
360}
361
363{
364 m_pSearchEngine->RebuildUsedFields(m_prbAllFields->get_active() ? -1 : m_plbField->get_active());
365 // calls m_pSearchEngine->InvalidatePreviousLoc too
366
367 int nCurrentContext = m_plbForm->get_active();
368 if (nCurrentContext != -1)
369 m_arrContextFields[nCurrentContext] = m_plbField->get_active_text();
370}
371
372IMPL_LINK(FmSearchDialog, OnCheckBoxToggled, weld::Toggleable&, rBox, void)
373{
374 bool bChecked = rBox.get_active();
375
376 // formatter or case -> pass on to the engine
377 if (&rBox == m_pcbUseFormat.get())
378 m_pSearchEngine->SetFormatterUsing(bChecked);
379 else if (&rBox == m_pcbCase.get())
380 m_pSearchEngine->SetCaseSensitive(bChecked);
381 // direction -> pass on and reset the checkbox-text for StartOver
382 else if (&rBox == m_pcbBackwards.get())
383 {
384 m_pcbStartOver->set_label( CuiResId( bChecked ? RID_STR_FROM_BOTTOM : RID_STR_FROM_TOP ) );
385 m_pSearchEngine->SetDirection(!bChecked);
386 }
387 // similarity-search or regular expression
388 else if ((&rBox == m_pcbApprox.get()) || (&rBox == m_pcbRegular.get()) || (&rBox == m_pcbWildCard.get()))
389 {
390 weld::CheckButton* pBoxes[] = { m_pcbWildCard.get(), m_pcbRegular.get(), m_pcbApprox.get() };
391 for (weld::CheckButton* pBoxe : pBoxes)
392 {
393 if (pBoxe != &rBox)
394 {
395 if (bChecked)
396 pBoxe->set_sensitive(false);
397 else
398 pBoxe->set_sensitive(true);
399 }
400 }
401
402 // pass on to the engine
403 m_pSearchEngine->SetWildcard(m_pcbWildCard->get_sensitive() && m_pcbWildCard->get_active());
404 m_pSearchEngine->SetRegular(m_pcbRegular->get_sensitive() && m_pcbRegular->get_active());
405 m_pSearchEngine->SetLevenshtein(m_pcbApprox->get_sensitive() && m_pcbApprox->get_active());
406 // (disabled boxes have to be passed to the engine as sal_False)
407
408 // adjust the Position-Listbox (which is not allowed during Wildcard-search)
409 if (&rBox == m_pcbWildCard.get())
410 {
411 if (bChecked)
412 {
413 m_pftPosition->set_sensitive(false);
414 m_plbPosition->set_sensitive(false);
415 }
416 else
417 {
418 m_pftPosition->set_sensitive(true);
419 m_plbPosition->set_sensitive(true);
420 }
421 }
422
423 // and the button for similarity-search
424 if (&rBox == m_pcbApprox.get())
425 {
426 if (bChecked)
427 m_ppbApproxSettings->set_sensitive(true);
428 else
429 m_ppbApproxSettings->set_sensitive(false);
430 }
431 }
432 else if (&rBox == m_pHalfFullFormsCJK.get())
433 {
434 // forward to the search engine
435 m_pSearchEngine->SetIgnoreWidthCJK( !bChecked );
436 }
437 else if (&rBox == m_pSoundsLikeCJK.get())
438 {
439 m_pSoundsLikeCJKSettings->set_sensitive(bChecked);
440
441 // two other buttons which depend on this one
442 bool bEnable = ( m_prbSearchForText->get_active()
443 && !m_pSoundsLikeCJK->get_active()
444 )
446 m_pcbCase->set_sensitive(bEnable);
447 m_pHalfFullFormsCJK->set_sensitive(bEnable);
448
449 // forward to the search engine
450 m_pSearchEngine->SetTransliteration( bChecked );
451 }
452}
453
454void FmSearchDialog::InitContext(sal_Int16 nContext)
455{
456 FmSearchContext fmscContext;
457 fmscContext.nContext = nContext;
458
459 sal_uInt32 nResult = m_lnkContextSupplier.Call(fmscContext);
460 DBG_ASSERT(nResult > 0, "FmSearchDialog::InitContext : ContextSupplier didn't give me any controls !");
461
462 // put the field names into the respective listbox
463 m_plbField->clear();
464
465 if (!fmscContext.sFieldDisplayNames.isEmpty())
466 {
467 // use the display names if supplied
469 "FmSearchDialog::InitContext : invalid context description supplied !");
470 sal_Int32 nPos {0};
471 do {
472 m_plbField->append_text(fmscContext.sFieldDisplayNames.getToken(0, ';', nPos));
473 } while (nPos>=0);
474 }
475 else if (!fmscContext.strUsedFields.isEmpty())
476 {
477 // else use the field names
478 sal_Int32 nPos {0};
479 do {
480 m_plbField->append_text(fmscContext.strUsedFields.getToken(0, ';', nPos));
481 } while (nPos>=0);
482 }
483
484 if (nContext < static_cast<sal_Int32>(m_arrContextFields.size()) && !m_arrContextFields[nContext].isEmpty())
485 {
486 m_plbField->set_active_text(m_arrContextFields[nContext]);
487 }
488 else
489 {
490 m_plbField->set_active(0);
491 if (m_prbSingleField->get_active() && (m_plbField->get_count() > 1))
492 m_plbField->grab_focus();
493 }
494
495 m_pSearchEngine->SwitchToContext(fmscContext.xCursor, fmscContext.strUsedFields, fmscContext.arrFields,
496 m_prbAllFields->get_active() ? -1 : 0);
497
498 m_pftRecord->set_label(OUString::number(fmscContext.xCursor->getRow()));
499}
500
501IMPL_LINK(FmSearchDialog, OnContextSelection, weld::ComboBox&, rBox, void)
502{
503 InitContext(rBox.get_active());
504}
505
507{
508 // the search button has two functions -> adjust its text accordingly
509 OUString sButtonText( bEnable ? m_sSearch : m_sCancel );
510 m_pbSearchAgain->set_label(sButtonText);
511
512 m_prbSearchForText->set_sensitive(bEnable);
513 m_prbSearchForNull->set_sensitive(bEnable);
514 m_prbSearchForNotNull->set_sensitive(bEnable);
515 m_plbForm->set_sensitive(bEnable);
516 m_prbAllFields->set_sensitive(bEnable);
517 m_prbSingleField->set_sensitive(bEnable);
518 m_plbField->set_sensitive(bEnable && m_prbSingleField->get_active());
519 m_pcbBackwards->set_sensitive(bEnable);
520 m_pcbStartOver->set_sensitive(bEnable);
521 m_pbClose->set_sensitive(bEnable);
523
524 if ( !bEnable )
525 { // this means we're preparing for starting a search
526 // In this case, EnableSearchForDependees disabled the search button
527 // But as we're about to use it for cancelling the search, we really need to enable it, again
528 m_pbSearchAgain->set_sensitive(true);
529 }
530}
531
533{
534 bool bSearchingForText = m_prbSearchForText->get_active();
535 m_pbSearchAgain->set_sensitive(bEnable && (!bSearchingForText || (!m_pcmbSearchText->get_active_text().isEmpty())));
536
537 bEnable = bEnable && bSearchingForText;
538
539 bool bEnableRedundants = !m_pSoundsLikeCJK->get_active() || !SvtCJKOptions::IsJapaneseFindEnabled();
540
541 m_pcmbSearchText->set_sensitive(bEnable);
542 m_pftPosition->set_sensitive(bEnable && !m_pcbWildCard->get_active());
543 m_pcbWildCard->set_sensitive(bEnable && !m_pcbRegular->get_active() && !m_pcbApprox->get_active());
544 m_pcbRegular->set_sensitive(bEnable && !m_pcbWildCard->get_active() && !m_pcbApprox->get_active());
545 m_pcbApprox->set_sensitive(bEnable && !m_pcbWildCard->get_active() && !m_pcbRegular->get_active());
546 m_ppbApproxSettings->set_sensitive(bEnable && m_pcbApprox->get_active());
547 m_pHalfFullFormsCJK->set_sensitive(bEnable && bEnableRedundants);
548 m_pSoundsLikeCJK->set_sensitive(bEnable);
549 m_pSoundsLikeCJKSettings->set_sensitive(bEnable && m_pSoundsLikeCJK->get_active());
550 m_plbPosition->set_sensitive(bEnable && !m_pcbWildCard->get_active());
551 m_pcbUseFormat->set_sensitive(bEnable);
552 m_pcbCase->set_sensitive(bEnable && bEnableRedundants);
553}
554
555void FmSearchDialog::OnFound(const css::uno::Any& aCursorPos, sal_Int16 nFieldPos)
556{
558 friInfo.nContext = m_plbForm->get_active();
559 // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
560 friInfo.aPosition = aCursorPos;
561 if (m_prbAllFields->get_active())
562 friInfo.nFieldPos = nFieldPos;
563 else
564 friInfo.nFieldPos = m_plbField->get_active();
565 // this of course implies that I have really searched in the field that is selected in the listbox,
566 // which is made sure in RebuildUsedFields
567
568 m_lnkFoundHandler.Call(friInfo);
569
570 m_pcmbSearchText->grab_focus();
571}
572
573IMPL_LINK(FmSearchDialog, OnSearchProgress, const FmSearchProgress*, pProgress, void)
574{
575 SolarMutexGuard aGuard;
576 // make this single method thread-safe (it's an overkill to block the whole application for this,
577 // but we don't have another safety concept at the moment)
578
579 switch (pProgress->aSearchState)
580 {
582 if (pProgress->bOverflow)
583 {
584 OUString sHint( CuiResId( m_pcbBackwards->get_active() ? RID_STR_OVERFLOW_BACKWARD : RID_STR_OVERFLOW_FORWARD ) );
585 m_pftHint->set_label( sHint );
586 }
587
588 m_pftRecord->set_label(OUString::number(1 + pProgress->nCurrentRecord));
589 break;
590
592 m_pftHint->set_label(CuiResId(RID_STR_SEARCH_COUNTING));
593 m_pftRecord->set_label(OUString::number(pProgress->nCurrentRecord));
594 break;
595
597 OnFound(pProgress->aBookmark, static_cast<sal_Int16>(pProgress->nFieldIndex));
598 EnableSearchUI(true);
599 break;
600
603 {
604 TranslateId pErrorId = (FmSearchProgress::State::Error == pProgress->aSearchState)
605 ? RID_STR_SEARCH_GENERAL_ERROR
606 : RID_STR_SEARCH_NORECORD;
607 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
608 VclMessageType::Warning, VclButtonsType::Ok, CuiResId(pErrorId)));
609 xBox->run();
610 [[fallthrough]];
611 }
613 EnableSearchUI(true);
614 if (m_lnkCanceledNotFoundHdl.IsSet())
615 {
617 friInfo.nContext = m_plbForm->get_active();
618 // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
619 friInfo.aPosition = pProgress->aBookmark;
620 m_lnkCanceledNotFoundHdl.Call(friInfo);
621 }
622 break;
623 }
624
625 m_pftRecord->set_label(OUString::number(1 + pProgress->nCurrentRecord));
626}
627
629{
630 FmSearchParams aParams(m_pConfig->getParams());
631
632 const OUString* pHistory = aParams.aHistory.getConstArray();
633 const OUString* pHistoryEnd = pHistory + aParams.aHistory.getLength();
634 for (; pHistory != pHistoryEnd; ++pHistory)
635 m_pcmbSearchText->append_text( *pHistory );
636
637 // I do the settings at my UI-elements and then I simply call the respective change-handler,
638 // that way the data is handed on to the SearchEngine and all dependent settings are done
639
640 // current field
641 int nInitialField = m_plbField->find_text( aParams.sSingleSearchField );
642 if (nInitialField == -1)
643 nInitialField = 0;
644 m_plbField->set_active(nInitialField);
645 OnFieldSelected(*m_plbField);
646 // all fields/single field (AFTER selecting the field because OnToggledFieldRadios expects a valid value there)
647 if (aParams.bAllFields)
648 {
649 m_prbSingleField->set_active(false);
650 m_prbAllFields->set_active(true);
651 OnToggledFieldRadios(*m_prbAllFields);
652 // OnToggledFieldRadios also calls to RebuildUsedFields
653 }
654 else
655 {
656 m_prbAllFields->set_active(false);
657 m_prbSingleField->set_active(true);
658 OnToggledFieldRadios(*m_prbSingleField);
659 }
660
661 m_plbPosition->set_active(aParams.nPosition);
662 OnPositionSelected(*m_plbPosition);
663
664 // field formatting/case sensitivity/direction
665 m_pcbUseFormat->set_active(aParams.bUseFormatter);
666 m_pcbCase->set_active( aParams.isCaseSensitive() );
667 m_pcbBackwards->set_active(aParams.bBackwards);
668 OnCheckBoxToggled(*m_pcbUseFormat);
669 OnCheckBoxToggled(*m_pcbCase);
670 OnCheckBoxToggled(*m_pcbBackwards);
671
672 m_pHalfFullFormsCJK->set_active( !aParams.isIgnoreWidthCJK( ) ); // BEWARE: this checkbox has an inverse semantics!
673 m_pSoundsLikeCJK->set_active( aParams.bSoundsLikeCJK );
674 OnCheckBoxToggled(*m_pHalfFullFormsCJK);
675 OnCheckBoxToggled(*m_pSoundsLikeCJK);
676
677 m_pcbWildCard->set_active(false);
678 m_pcbRegular->set_active(false);
679 m_pcbApprox->set_active(false);
680 OnCheckBoxToggled(*m_pcbWildCard);
681 OnCheckBoxToggled(*m_pcbRegular);
682 OnCheckBoxToggled(*m_pcbApprox);
683
684 weld::CheckButton* pToCheck = nullptr;
685 if (aParams.bWildcard)
686 pToCheck = m_pcbWildCard.get();
687 if (aParams.bRegular)
688 pToCheck = m_pcbRegular.get();
689 if (aParams.bApproxSearch)
690 pToCheck = m_pcbApprox.get();
691 if (aParams.bSoundsLikeCJK)
692 pToCheck = m_pSoundsLikeCJK.get();
693 if (pToCheck)
694 {
695 pToCheck->set_active(true);
696 OnCheckBoxToggled(*pToCheck);
697 }
698
699 // set Levenshtein-parameters directly at the SearchEngine
700 m_pSearchEngine->SetLevRelaxed(aParams.bLevRelaxed);
701 m_pSearchEngine->SetLevOther(aParams.nLevOther);
702 m_pSearchEngine->SetLevShorter(aParams.nLevShorter);
703 m_pSearchEngine->SetLevLonger(aParams.nLevLonger);
704
705 m_pSearchEngine->SetTransliterationFlags( aParams.getTransliterationFlags( ) );
706
707 m_prbSearchForText->set_active(false);
708 m_prbSearchForNull->set_active(false);
709 m_prbSearchForNotNull->set_active(false);
710 switch (aParams.nSearchForType)
711 {
712 case 1: m_prbSearchForNull->set_active(true); break;
713 case 2: m_prbSearchForNotNull->set_active(true); break;
714 default: m_prbSearchForText->set_active(true); break;
715 }
716 OnToggledFieldRadios(*m_prbSearchForText);
717}
718
720{
721 if (!m_pConfig)
722 return;
723
724 FmSearchParams aCurrentSettings;
725
726 int nCount = m_pcmbSearchText->get_count();
727 aCurrentSettings.aHistory.realloc(nCount);
728 OUString* pHistory = aCurrentSettings.aHistory.getArray();
729 for (int i = 0; i < nCount; ++i, ++pHistory)
730 *pHistory = m_pcmbSearchText->get_text(i);
731
732 aCurrentSettings.sSingleSearchField = m_plbField->get_active_text();
733 aCurrentSettings.bAllFields = m_prbAllFields->get_active();
734 aCurrentSettings.nPosition = m_pSearchEngine->GetPosition();
735 aCurrentSettings.bUseFormatter = m_pSearchEngine->GetFormatterUsing();
736 aCurrentSettings.setCaseSensitive ( m_pSearchEngine->GetCaseSensitive() );
737 aCurrentSettings.bBackwards = !m_pSearchEngine->GetDirection();
738 aCurrentSettings.bWildcard = m_pSearchEngine->GetWildcard();
739 aCurrentSettings.bRegular = m_pSearchEngine->GetRegular();
740 aCurrentSettings.bApproxSearch = m_pSearchEngine->GetLevenshtein();
741 aCurrentSettings.bLevRelaxed = m_pSearchEngine->GetLevRelaxed();
742 aCurrentSettings.nLevOther = m_pSearchEngine->GetLevOther();
743 aCurrentSettings.nLevShorter = m_pSearchEngine->GetLevShorter();
744 aCurrentSettings.nLevLonger = m_pSearchEngine->GetLevLonger();
745
746 aCurrentSettings.bSoundsLikeCJK = m_pSearchEngine->GetTransliteration();
747 aCurrentSettings.setTransliterationFlags ( m_pSearchEngine->GetTransliterationFlags() );
748
749 if (m_prbSearchForNull->get_active())
750 aCurrentSettings.nSearchForType = 1;
751 else if (m_prbSearchForNotNull->get_active())
752 aCurrentSettings.nSearchForType = 2;
753 else
754 aCurrentSettings.nSearchForType = 0;
755
756 m_pConfig->setParams( aCurrentSettings );
757}
758
759/* 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, bool bMobile=false)
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