1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/string.hxx>
33 #include <svx/svxdlg.hxx>
34 #include <o3tl/string_view.hxx>
36 using namespace css::uno
;
37 using namespace css::i18n
;
38 using namespace ::svxform
;
39 using namespace css::sdbc
;
40 using namespace css::util
;
42 #define MAX_HISTORY_ENTRIES 50
44 void FmSearchDialog::initCommon( const Reference
< XResultSet
>& _rxCursor
)
47 DBG_ASSERT( m_pSearchEngine
, "FmSearchDialog::initCommon: have no engine!" );
48 m_pSearchEngine
->SetProgressHandler(LINK(this, FmSearchDialog
, OnSearchProgress
));
50 // some layout changes according to available CJK options
51 if (!SvtCJKOptions::IsJapaneseFindEnabled())
53 // hide the options for the japanese search
54 m_pSoundsLikeCJK
->hide();
55 m_pSoundsLikeCJKSettings
->hide();
58 if (!SvtCJKOptions::IsCJKFontEnabled())
60 m_pHalfFullFormsCJK
->hide();
62 // never ignore the width (ignoring is expensive) if the option is not available at all
63 m_pSearchEngine
->SetIgnoreWidthCJK( false );
66 // some initial record texts
67 m_pftRecord
->set_label( OUString::number(_rxCursor
->getRow()) );
68 m_pbClose
->set_tooltip_text(OUString());
71 FmSearchDialog::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")
74 , m_sCancel( GetStandardText( StandardButtonType::Cancel
) )
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"))
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();
107 DBG_ASSERT(m_lnkContextSupplier
.IsSet(), "FmSearchDialog::FmSearchDialog : have no ContextSupplier !");
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
)
118 DBG_ASSERT(arrField
.is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
120 #endif // (OSL_DEBUG_LEVEL > 1) || DBG_UTIL
122 for ( std::vector
< OUString
>::const_iterator context
= _rContexts
.begin();
123 context
!= _rContexts
.end();
127 m_arrContextFields
.emplace_back();
128 m_plbForm
->append_text(*context
);
130 m_plbForm
->set_active(nInitialContext
);
132 m_plbForm
->connect_changed(LINK(this, FmSearchDialog
, OnContextSelection
));
134 if (m_arrContextFields
.size() == 1)
136 // hide dispensable controls
141 m_pSearchEngine
.reset( new FmSearchEngine(
142 ::comphelper::getProcessComponentContext(), fmscInitial
.xCursor
, fmscInitial
.strUsedFields
, fmscInitial
.arrFields
) );
143 initCommon( fmscInitial
.xCursor
);
145 if ( !fmscInitial
.sFieldDisplayNames
.isEmpty() )
146 { // use the display names if supplied
147 DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial
.sFieldDisplayNames
, ';') == comphelper::string::getTokenCount(fmscInitial
.strUsedFields
, ';'),
148 "FmSearchDialog::FmSearchDialog : invalid initial context description !");
149 Init(fmscInitial
.sFieldDisplayNames
, sInitialText
);
152 Init(fmscInitial
.strUsedFields
, sInitialText
);
155 FmSearchDialog::~FmSearchDialog()
160 m_pSearchEngine
.reset();
163 void FmSearchDialog::Init(std::u16string_view strVisibleFields
, const OUString
& sInitialText
)
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
));
170 m_prbAllFields
->connect_toggled(LINK(this, FmSearchDialog
, OnToggledFieldRadios
));
171 m_prbSingleField
->connect_toggled(LINK(this, FmSearchDialog
, OnToggledFieldRadios
));
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
));
177 m_plbPosition
->connect_changed(LINK(this, FmSearchDialog
, OnPositionSelected
));
178 m_plbField
->connect_changed(LINK(this, FmSearchDialog
, OnFieldSelected
));
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
));
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
));
194 // fill the listboxes
195 // method of field comparison
196 const TranslateId aResIds
[] = {
197 RID_STR_SEARCH_ANYWHERE
,
198 RID_STR_SEARCH_BEGINNING
,
202 for (auto const & pResId
: aResIds
)
203 m_plbPosition
->append_text(CuiResId(pResId
));
204 m_plbPosition
->set_active(MATCHING_ANYWHERE
);
207 if (!strVisibleFields
.empty())
211 m_plbField
->append_text(OUString(o3tl::getToken(strVisibleFields
, 0, ';', nPos
)));
216 m_pConfig
.reset( new FmSearchConfigItem
);
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
);
229 EnableSearchUI(true);
231 if ( m_prbSearchForText
->get_active() )
232 m_pcmbSearchText
->grab_focus();
236 short FmSearchDialog::run()
238 short nRet
= weld::GenericDialogController::run();
239 m_pSearchEngine
->CancelSearch();
243 IMPL_LINK(FmSearchDialog
, OnToggledSearchRadio
, weld::Toggleable
&, rButton
, void)
245 if (!rButton
.get_active())
247 EnableSearchForDependees(true);
250 IMPL_LINK(FmSearchDialog
, OnToggledFieldRadios
, weld::Toggleable
&, rButton
, void)
252 if (!rButton
.get_active())
255 // en- or disable field list box accordingly
256 if (m_prbSingleField
->get_active())
258 m_plbField
->set_sensitive(true);
259 m_pSearchEngine
->RebuildUsedFields(m_plbField
->get_active());
263 m_plbField
->set_sensitive(false);
264 m_pSearchEngine
->RebuildUsedFields(-1);
268 IMPL_LINK_NOARG(FmSearchDialog
, OnClickedSearchAgain
, weld::Button
&, void)
270 if (m_pbClose
->get_sensitive())
271 { // the button has the function 'search'
272 OUString strThisRoundText
= m_pcmbSearchText
->get_active_text();
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);
281 // take out the 'overflow' hint
282 m_pftHint
->set_label(OUString());
284 if (m_pcbStartOver
->get_active())
286 m_pcbStartOver
->set_active(false);
287 EnableSearchUI(false);
288 if (m_prbSearchForText
->get_active())
289 m_pSearchEngine
->StartOver(strThisRoundText
);
291 m_pSearchEngine
->StartOverSpecial(m_prbSearchForNull
->get_active());
295 EnableSearchUI(false);
296 if (m_prbSearchForText
->get_active())
297 m_pSearchEngine
->SearchNext(strThisRoundText
);
299 m_pSearchEngine
->SearchNextSpecial(m_prbSearchForNull
->get_active());
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
310 IMPL_LINK(FmSearchDialog
, OnClickedSpecialSettings
, weld::Button
&, rButton
, void)
312 if (m_ppbApproxSettings
.get() == &rButton
)
314 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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
){
320 if (nResult
== RET_OK
)
322 m_pSearchEngine
->SetLevRelaxed( pDlg
->IsRelaxed() );
323 m_pSearchEngine
->SetLevOther( pDlg
->GetOther() );
324 m_pSearchEngine
->SetLevShorter(pDlg
->GetShorter() );
325 m_pSearchEngine
->SetLevLonger( pDlg
->GetLonger() );
330 else if (m_pSoundsLikeCJKSettings
.get() == &rButton
)
332 SfxItemSet
aSet( SfxGetpApp()->GetPool() );
333 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
334 ScopedVclPtr
<AbstractSvxJSearchOptionsDialog
> aDlg(pFact
->CreateSvxJSearchOptionsDialog(m_xDialog
.get(), aSet
, m_pSearchEngine
->GetTransliterationFlags() ));
337 TransliterationFlags nFlags
= aDlg
->GetTransliterationFlags();
338 m_pSearchEngine
->SetTransliterationFlags(nFlags
);
340 m_pcbCase
->set_active(m_pSearchEngine
->GetCaseSensitive());
341 OnCheckBoxToggled( *m_pcbCase
);
342 m_pHalfFullFormsCJK
->set_active( !m_pSearchEngine
->GetIgnoreWidthCJK() );
343 OnCheckBoxToggled( *m_pHalfFullFormsCJK
);
347 IMPL_LINK_NOARG(FmSearchDialog
, OnSearchTextModified
, weld::ComboBox
&, void)
349 if ((!m_pcmbSearchText
->get_active_text().isEmpty()) || !m_prbSearchForText
->get_active())
350 m_pbSearchAgain
->set_sensitive(true);
352 m_pbSearchAgain
->set_sensitive(false);
354 m_pSearchEngine
->InvalidatePreviousLoc();
357 IMPL_LINK_NOARG(FmSearchDialog
, OnFocusGrabbed
, weld::Widget
&, void)
359 m_pcmbSearchText
->select_entry_region(0, -1);
362 IMPL_LINK_NOARG(FmSearchDialog
, OnPositionSelected
, weld::ComboBox
&, void)
364 m_pSearchEngine
->SetPosition(m_plbPosition
->get_active());
367 IMPL_LINK_NOARG(FmSearchDialog
, OnFieldSelected
, weld::ComboBox
&, void)
369 m_pSearchEngine
->RebuildUsedFields(m_prbAllFields
->get_active() ? -1 : m_plbField
->get_active());
370 // calls m_pSearchEngine->InvalidatePreviousLoc too
372 int nCurrentContext
= m_plbForm
->get_active();
373 if (nCurrentContext
!= -1)
374 m_arrContextFields
[nCurrentContext
] = m_plbField
->get_active_text();
377 IMPL_LINK(FmSearchDialog
, OnCheckBoxToggled
, weld::Toggleable
&, rBox
, void)
379 bool bChecked
= rBox
.get_active();
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())
389 m_pcbStartOver
->set_label( CuiResId( bChecked
? RID_STR_FROM_BOTTOM
: RID_STR_FROM_TOP
) );
390 m_pSearchEngine
->SetDirection(!bChecked
);
392 // similarity-search or regular expression
393 else if ((&rBox
== m_pcbApprox
.get()) || (&rBox
== m_pcbRegular
.get()) || (&rBox
== m_pcbWildCard
.get()))
395 weld::CheckButton
* pBoxes
[] = { m_pcbWildCard
.get(), m_pcbRegular
.get(), m_pcbApprox
.get() };
396 for (weld::CheckButton
* pBoxe
: pBoxes
)
401 pBoxe
->set_sensitive(false);
403 pBoxe
->set_sensitive(true);
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)
413 // adjust the Position-Listbox (which is not allowed during Wildcard-search)
414 if (&rBox
== m_pcbWildCard
.get())
418 m_pftPosition
->set_sensitive(false);
419 m_plbPosition
->set_sensitive(false);
423 m_pftPosition
->set_sensitive(true);
424 m_plbPosition
->set_sensitive(true);
428 // and the button for similarity-search
429 if (&rBox
== m_pcbApprox
.get())
432 m_ppbApproxSettings
->set_sensitive(true);
434 m_ppbApproxSettings
->set_sensitive(false);
437 else if (&rBox
== m_pHalfFullFormsCJK
.get())
439 // forward to the search engine
440 m_pSearchEngine
->SetIgnoreWidthCJK( !bChecked
);
442 else if (&rBox
== m_pSoundsLikeCJK
.get())
444 m_pSoundsLikeCJKSettings
->set_sensitive(bChecked
);
446 // two other buttons which depend on this one
447 bool bEnable
= ( m_prbSearchForText
->get_active()
448 && !m_pSoundsLikeCJK
->get_active()
450 || !SvtCJKOptions::IsJapaneseFindEnabled();
451 m_pcbCase
->set_sensitive(bEnable
);
452 m_pHalfFullFormsCJK
->set_sensitive(bEnable
);
454 // forward to the search engine
455 m_pSearchEngine
->SetTransliteration( bChecked
);
459 void FmSearchDialog::InitContext(sal_Int16 nContext
)
461 FmSearchContext fmscContext
;
462 fmscContext
.nContext
= nContext
;
464 sal_uInt32 nResult
= m_lnkContextSupplier
.Call(fmscContext
);
465 DBG_ASSERT(nResult
> 0, "FmSearchDialog::InitContext : ContextSupplier didn't give me any controls !");
467 // put the field names into the respective listbox
470 if (!fmscContext
.sFieldDisplayNames
.isEmpty())
472 // use the display names if supplied
473 DBG_ASSERT(comphelper::string::getTokenCount(fmscContext
.sFieldDisplayNames
, ';') == comphelper::string::getTokenCount(fmscContext
.strUsedFields
, ';'),
474 "FmSearchDialog::InitContext : invalid context description supplied !");
477 m_plbField
->append_text(fmscContext
.sFieldDisplayNames
.getToken(0, ';', nPos
));
480 else if (!fmscContext
.strUsedFields
.isEmpty())
482 // else use the field names
485 m_plbField
->append_text(fmscContext
.strUsedFields
.getToken(0, ';', nPos
));
489 if (nContext
< static_cast<sal_Int32
>(m_arrContextFields
.size()) && !m_arrContextFields
[nContext
].isEmpty())
491 m_plbField
->set_active_text(m_arrContextFields
[nContext
]);
495 m_plbField
->set_active(0);
496 if (m_prbSingleField
->get_active() && (m_plbField
->get_count() > 1))
497 m_plbField
->grab_focus();
500 m_pSearchEngine
->SwitchToContext(fmscContext
.xCursor
, fmscContext
.strUsedFields
, fmscContext
.arrFields
,
501 m_prbAllFields
->get_active() ? -1 : 0);
503 m_pftRecord
->set_label(OUString::number(fmscContext
.xCursor
->getRow()));
506 IMPL_LINK(FmSearchDialog
, OnContextSelection
, weld::ComboBox
&, rBox
, void)
508 InitContext(rBox
.get_active());
511 void FmSearchDialog::EnableSearchUI(bool bEnable
)
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
);
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
);
527 EnableSearchForDependees(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);
537 void FmSearchDialog::EnableSearchForDependees(bool bEnable
)
539 bool bSearchingForText
= m_prbSearchForText
->get_active();
540 m_pbSearchAgain
->set_sensitive(bEnable
&& (!bSearchingForText
|| (!m_pcmbSearchText
->get_active_text().isEmpty())));
542 bEnable
= bEnable
&& bSearchingForText
;
544 bool bEnableRedundants
= !m_pSoundsLikeCJK
->get_active() || !SvtCJKOptions::IsJapaneseFindEnabled();
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
);
560 void FmSearchDialog::OnFound(const css::uno::Any
& aCursorPos
, sal_Int16 nFieldPos
)
562 FmFoundRecordInformation friInfo
;
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
;
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
573 m_lnkFoundHandler
.Call(friInfo
);
575 m_pcmbSearchText
->grab_focus();
578 IMPL_LINK(FmSearchDialog
, OnSearchProgress
, const FmSearchProgress
*, pProgress
, void)
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)
584 switch (pProgress
->aSearchState
)
586 case FmSearchProgress::State::Progress
:
587 if (pProgress
->bOverflow
)
589 OUString
sHint( CuiResId( m_pcbBackwards
->get_active() ? RID_STR_OVERFLOW_BACKWARD
: RID_STR_OVERFLOW_FORWARD
) );
590 m_pftHint
->set_label( sHint
);
593 m_pftRecord
->set_label(OUString::number(1 + pProgress
->nCurrentRecord
));
596 case FmSearchProgress::State::ProgressCounting
:
597 m_pftHint
->set_label(CuiResId(RID_STR_SEARCH_COUNTING
));
598 m_pftRecord
->set_label(OUString::number(pProgress
->nCurrentRecord
));
601 case FmSearchProgress::State::Successful
:
602 OnFound(pProgress
->aBookmark
, static_cast<sal_Int16
>(pProgress
->nFieldIndex
));
603 EnableSearchUI(true);
606 case FmSearchProgress::State::Error
:
607 case FmSearchProgress::State::NothingFound
:
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
)));
617 case FmSearchProgress::State::Canceled
:
618 EnableSearchUI(true);
619 if (m_lnkCanceledNotFoundHdl
.IsSet())
621 FmFoundRecordInformation friInfo
;
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
);
630 m_pftRecord
->set_label(OUString::number(1 + pProgress
->nCurrentRecord
));
633 void FmSearchDialog::LoadParams()
635 FmSearchParams
aParams(m_pConfig
->getParams());
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
);
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
646 int nInitialField
= m_plbField
->find_text( aParams
.sSingleSearchField
);
647 if (nInitialField
== -1)
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
)
654 m_prbSingleField
->set_active(false);
655 m_prbAllFields
->set_active(true);
656 OnToggledFieldRadios(*m_prbAllFields
);
657 // OnToggledFieldRadios also calls to RebuildUsedFields
661 m_prbAllFields
->set_active(false);
662 m_prbSingleField
->set_active(true);
663 OnToggledFieldRadios(*m_prbSingleField
);
666 m_plbPosition
->set_active(aParams
.nPosition
);
667 OnPositionSelected(*m_plbPosition
);
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
);
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
);
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
);
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();
700 pToCheck
->set_active(true);
701 OnCheckBoxToggled(*pToCheck
);
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
);
710 m_pSearchEngine
->SetTransliterationFlags( aParams
.getTransliterationFlags( ) );
712 m_prbSearchForText
->set_active(false);
713 m_prbSearchForNull
->set_active(false);
714 m_prbSearchForNotNull
->set_active(false);
715 switch (aParams
.nSearchForType
)
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;
721 OnToggledFieldRadios(*m_prbSearchForText
);
724 void FmSearchDialog::SaveParams() const
729 FmSearchParams aCurrentSettings
;
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
);
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();
751 aCurrentSettings
.bSoundsLikeCJK
= m_pSearchEngine
->GetTransliteration();
752 aCurrentSettings
.setTransliterationFlags ( m_pSearchEngine
->GetTransliterationFlags() );
754 if (m_prbSearchForNull
->get_active())
755 aCurrentSettings
.nSearchForType
= 1;
756 else if (m_prbSearchForNotNull
->get_active())
757 aCurrentSettings
.nSearchForType
= 2;
759 aCurrentSettings
.nSearchForType
= 0;
761 m_pConfig
->setParams( aCurrentSettings
);
764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */