Line data Source code
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/layout.hxx>
22 : #include <vcl/svapp.hxx>
23 : #include <dialmgr.hxx>
24 : #include <sfx2/tabdlg.hxx>
25 : #include <osl/mutex.hxx>
26 : #include <sfx2/app.hxx>
27 : #include <cuires.hrc>
28 : #include <svx/fmsrccfg.hxx>
29 : #include <svx/fmsrcimp.hxx>
30 : #include "fmsearch.hrc"
31 : #include "cuifmsearch.hxx"
32 : #include <svx/srchdlg.hxx>
33 : #include <svl/cjkoptions.hxx>
34 : #include <com/sun/star/i18n/TransliterationModules.hpp>
35 : #include <comphelper/processfactory.hxx>
36 : #include <comphelper/string.hxx>
37 : #include <svx/svxdlg.hxx>
38 : #include <sal/macros.h>
39 : #include <boost/scoped_ptr.hpp>
40 :
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::i18n;
43 : using namespace ::svxform;
44 : using namespace ::com::sun::star::sdbc;
45 : using namespace ::com::sun::star::util;
46 :
47 : #define MAX_HISTORY_ENTRIES 50
48 :
49 0 : void FmSearchDialog::initCommon( const Reference< XResultSet >& _rxCursor )
50 : {
51 : // init the engine
52 : DBG_ASSERT( m_pSearchEngine, "FmSearchDialog::initCommon: have no engine!" );
53 0 : m_pSearchEngine->SetProgressHandler(LINK(this, FmSearchDialog, OnSearchProgress));
54 :
55 : // some layout changes according to available CJK options
56 0 : SvtCJKOptions aCJKOptions;
57 0 : if (!aCJKOptions.IsJapaneseFindEnabled())
58 : {
59 : // hide the options for the japanese search
60 0 : m_pSoundsLikeCJK->Hide();
61 0 : m_pSoundsLikeCJKSettings->Hide();
62 : }
63 :
64 0 : if (!aCJKOptions.IsCJKFontEnabled())
65 : {
66 0 : m_pHalfFullFormsCJK->Hide();
67 :
68 : // never ignore the width (ignoring is expensive) if the option is not available at all
69 0 : m_pSearchEngine->SetIgnoreWidthCJK( false );
70 : }
71 :
72 : // some initial record texts
73 0 : m_pftRecord->SetText( OUString::number(_rxCursor->getRow()) );
74 0 : m_pbClose->SetHelpText(OUString());
75 0 : }
76 :
77 0 : FmSearchDialog::FmSearchDialog(vcl::Window* pParent, const OUString& sInitialText, const ::std::vector< OUString >& _rContexts, sal_Int16 nInitialContext,
78 : const Link& lnkContextSupplier)
79 : :ModalDialog(pParent, "RecordSearchDialog", "cui/ui/fmsearchdialog.ui")
80 : ,m_sCancel ( Button::GetStandardText( BUTTON_CANCEL ) )
81 : ,m_pPreSearchFocus( NULL )
82 : ,m_lnkContextSupplier(lnkContextSupplier)
83 0 : ,m_pConfig( NULL )
84 : {
85 0 : get(m_prbSearchForText,"rbSearchForText");
86 0 : get(m_prbSearchForNull,"rbSearchForNull");
87 0 : get(m_prbSearchForNotNull,"rbSearchForNotNull");
88 0 : get(m_pcmbSearchText,"cmbSearchText");
89 0 : m_pcmbSearchText->set_width_request(m_pcmbSearchText->approximate_char_width() * 42);
90 0 : get(m_plbForm,"lbForm");
91 0 : m_plbForm->set_width_request(m_plbForm->approximate_char_width() * 42);
92 0 : get(m_prbAllFields,"rbAllFields");
93 0 : get(m_prbSingleField,"rbSingleField");
94 0 : get(m_plbField,"lbField");
95 0 : get(m_plbPosition,"lbPosition");
96 0 : get(m_pcbUseFormat,"cbUseFormat");
97 0 : get(m_pcbCase,"cbCase");
98 0 : get(m_pcbBackwards,"cbBackwards");
99 0 : get(m_pcbStartOver,"cbStartOver");
100 0 : get(m_pcbWildCard,"cbWildCard");
101 0 : get(m_pcbRegular,"cbRegular");
102 0 : get(m_pcbApprox,"cbApprox");
103 0 : get(m_ppbApproxSettings,"pbApproxSettings");
104 0 : get(m_pHalfFullFormsCJK,"HalfFullFormsCJK");
105 0 : get(m_pSoundsLikeCJK,"SoundsLikeCJK");
106 0 : get(m_pSoundsLikeCJKSettings,"SoundsLikeCJKSettings");
107 0 : get(m_pbSearchAgain,"pbSearchAgain");
108 0 : m_sSearch = m_pbSearchAgain->GetText();
109 0 : get(m_pftRecord,"ftRecord");
110 0 : get(m_pftHint,"ftHint");
111 0 : get(m_pftPosition,"ftPosition");
112 0 : get(m_pftForm,"ftForm");
113 0 : get(m_pbClose,"close");
114 :
115 : DBG_ASSERT(m_lnkContextSupplier.IsSet(), "FmSearchDialog::FmSearchDialog : have no ContextSupplier !");
116 :
117 0 : FmSearchContext fmscInitial;
118 0 : fmscInitial.nContext = nInitialContext;
119 0 : m_lnkContextSupplier.Call(&fmscInitial);
120 : DBG_ASSERT(fmscInitial.xCursor.is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
121 : DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';') == (sal_Int32)fmscInitial.arrFields.size(),
122 : "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplied !");
123 : #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
124 : for (sal_Int32 i=0; i<(sal_Int32)fmscInitial.arrFields.size(); ++i)
125 : DBG_ASSERT(fmscInitial.arrFields.at(i).is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
126 : #endif // (OSL_DEBUG_LEVEL > 1) || DBG_UTIL
127 :
128 0 : for ( ::std::vector< OUString >::const_iterator context = _rContexts.begin();
129 0 : context != _rContexts.end();
130 : ++context
131 : )
132 : {
133 0 : m_arrContextFields.push_back(OUString());
134 0 : m_plbForm->InsertEntry(*context);
135 : }
136 0 : m_plbForm->SelectEntryPos(nInitialContext);
137 :
138 0 : m_plbForm->SetSelectHdl(LINK(this, FmSearchDialog, OnContextSelection));
139 :
140 0 : if (m_arrContextFields.size() == 1)
141 : {
142 : // hide dispensable controls
143 0 : m_pftForm->Hide();
144 0 : m_plbForm->Hide();
145 : }
146 :
147 : m_pSearchEngine = new FmSearchEngine(
148 0 : ::comphelper::getProcessComponentContext(), fmscInitial.xCursor, fmscInitial.strUsedFields, fmscInitial.arrFields, SM_ALLOWSCHEDULE );
149 0 : initCommon( fmscInitial.xCursor );
150 :
151 0 : if ( !fmscInitial.sFieldDisplayNames.isEmpty() )
152 : { // use the display names if supplied
153 : DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.sFieldDisplayNames, ';') == comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';'),
154 : "FmSearchDialog::FmSearchDialog : invalid initial context description !");
155 0 : Init(fmscInitial.sFieldDisplayNames, sInitialText);
156 : }
157 : else
158 0 : Init(fmscInitial.strUsedFields, sInitialText);
159 0 : }
160 :
161 0 : FmSearchDialog::~FmSearchDialog()
162 : {
163 0 : if (m_aDelayedPaint.IsActive())
164 0 : m_aDelayedPaint.Stop();
165 :
166 0 : SaveParams();
167 :
168 0 : if (m_pConfig)
169 : {
170 0 : delete m_pConfig;
171 0 : m_pConfig = NULL;
172 : }
173 :
174 0 : delete m_pSearchEngine;
175 0 : }
176 :
177 0 : void FmSearchDialog::Init(const OUString& strVisibleFields, const OUString& sInitialText)
178 : {
179 : //the initialization of all the Controls
180 0 : m_prbSearchForText->SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
181 0 : m_prbSearchForNull->SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
182 0 : m_prbSearchForNotNull->SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
183 :
184 0 : m_prbAllFields->SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
185 0 : m_prbSingleField->SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
186 :
187 0 : m_pbSearchAgain->SetClickHdl(LINK(this, FmSearchDialog, OnClickedSearchAgain));
188 0 : m_ppbApproxSettings->SetClickHdl(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
189 0 : m_pSoundsLikeCJKSettings->SetClickHdl(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
190 :
191 0 : m_plbPosition->SetSelectHdl(LINK(this, FmSearchDialog, OnPositionSelected));
192 0 : m_plbField->SetSelectHdl(LINK(this, FmSearchDialog, OnFieldSelected));
193 :
194 0 : m_pcmbSearchText->SetModifyHdl(LINK(this, FmSearchDialog, OnSearchTextModified));
195 0 : m_pcmbSearchText->EnableAutocomplete(false);
196 0 : m_pcmbSearchText->SetGetFocusHdl(LINK(this, FmSearchDialog, OnFocusGrabbed));
197 :
198 0 : m_pcbUseFormat->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
199 0 : m_pcbBackwards->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
200 0 : m_pcbStartOver->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
201 0 : m_pcbCase->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
202 0 : m_pcbWildCard->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
203 0 : m_pcbRegular->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
204 0 : m_pcbApprox->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
205 0 : m_pHalfFullFormsCJK->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
206 0 : m_pSoundsLikeCJK->SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
207 :
208 : // fill the listboxes
209 : // method of field comparison
210 : sal_uInt16 nResIds[] = {
211 : RID_STR_SEARCH_ANYWHERE,
212 : RID_STR_SEARCH_BEGINNING,
213 : RID_STR_SEARCH_END,
214 : RID_STR_SEARCH_WHOLE
215 0 : };
216 0 : for ( size_t i=0; i<SAL_N_ELEMENTS(nResIds); ++i )
217 0 : m_plbPosition->InsertEntry( OUString( CUI_RES( nResIds[i] ) ) );
218 0 : m_plbPosition->SelectEntryPos(MATCHING_ANYWHERE);
219 :
220 : // the field listbox
221 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(strVisibleFields, ';'); ++i)
222 0 : m_plbField->InsertEntry(comphelper::string::getToken(strVisibleFields, i, ';'));
223 :
224 :
225 0 : m_pConfig = new FmSearchConfigItem;
226 0 : LoadParams();
227 :
228 0 : m_pcmbSearchText->SetText(sInitialText);
229 : // if the Edit-line has changed the text (e.g. because it contains
230 : // control characters, as can be the case with memo fields), I use
231 : // an empty OUString.
232 0 : OUString sRealSetText = m_pcmbSearchText->GetText();
233 0 : if (!sRealSetText.equals(sInitialText))
234 0 : m_pcmbSearchText->SetText(OUString());
235 0 : LINK(this, FmSearchDialog, OnSearchTextModified).Call(m_pcmbSearchText);
236 :
237 : // initial
238 0 : m_aDelayedPaint.SetTimeoutHdl(LINK(this, FmSearchDialog, OnDelayedPaint));
239 0 : m_aDelayedPaint.SetTimeout(500);
240 0 : EnableSearchUI(true);
241 :
242 0 : if ( m_prbSearchForText->IsChecked() )
243 0 : m_pcmbSearchText->GrabFocus();
244 :
245 0 : }
246 :
247 0 : bool FmSearchDialog::Close()
248 : {
249 : // If the close button is disabled and ESC is pressed in a dialog,
250 : // then Frame will call Close anyway, which I don't want to happen
251 : // while I'm in the middle of a search (maybe one that's running
252 : // in its own thread)
253 0 : if (!m_pbClose->IsEnabled())
254 0 : return false;
255 0 : return ModalDialog::Close();
256 : }
257 :
258 0 : IMPL_LINK(FmSearchDialog, OnClickedFieldRadios, Button*, pButton)
259 : {
260 0 : if ((pButton == m_prbSearchForText) || (pButton == m_prbSearchForNull) || (pButton == m_prbSearchForNotNull))
261 : {
262 0 : EnableSearchForDependees(true);
263 : }
264 : else
265 : // en- or disable field list box accordingly
266 0 : if (pButton == m_prbSingleField)
267 : {
268 0 : m_plbField->Enable();
269 0 : m_pSearchEngine->RebuildUsedFields(m_plbField->GetSelectEntryPos());
270 : }
271 : else
272 : {
273 0 : m_plbField->Disable();
274 0 : m_pSearchEngine->RebuildUsedFields(-1);
275 : }
276 :
277 0 : return 0;
278 : }
279 :
280 0 : IMPL_LINK_NOARG(FmSearchDialog, OnClickedSearchAgain)
281 : {
282 0 : if (m_pbClose->IsEnabled())
283 : { // the button has the function 'search'
284 0 : OUString strThisRoundText = m_pcmbSearchText->GetText();
285 : // to history
286 0 : m_pcmbSearchText->RemoveEntry(strThisRoundText);
287 0 : m_pcmbSearchText->InsertEntry(strThisRoundText, 0);
288 : // the remove/insert makes sure that a) the OUString does not appear twice and
289 : // that b) the last searched strings are at the beginning and limit the list length
290 0 : while (m_pcmbSearchText->GetEntryCount() > MAX_HISTORY_ENTRIES)
291 0 : m_pcmbSearchText->RemoveEntryAt(m_pcmbSearchText->GetEntryCount()-1);
292 :
293 : // take out the 'overflow' hint
294 0 : m_pftHint->SetText(OUString());
295 0 : m_pftHint->Invalidate();
296 :
297 0 : if (m_pcbStartOver->IsChecked())
298 : {
299 0 : m_pcbStartOver->Check(false);
300 0 : EnableSearchUI(false);
301 0 : if (m_prbSearchForText->IsChecked())
302 0 : m_pSearchEngine->StartOver(strThisRoundText);
303 : else
304 0 : m_pSearchEngine->StartOverSpecial(m_prbSearchForNull->IsChecked());
305 : }
306 : else
307 : {
308 0 : EnableSearchUI(false);
309 0 : if (m_prbSearchForText->IsChecked())
310 0 : m_pSearchEngine->SearchNext(strThisRoundText);
311 : else
312 0 : m_pSearchEngine->SearchNextSpecial(m_prbSearchForNull->IsChecked());
313 0 : }
314 : }
315 : else
316 : { // the button has the function 'cancel'
317 : DBG_ASSERT(m_pSearchEngine->GetSearchMode() != SM_BRUTE, "FmSearchDialog, OnClickedSearchAgain : falscher Modus !");
318 : // the CancelButton is usually only disabled, when working in a thread or with reschedule
319 0 : m_pSearchEngine->CancelSearch();
320 : // the ProgressHandler is called when it's really finished, here it's only a demand
321 : }
322 0 : return 0;
323 : }
324 :
325 0 : IMPL_LINK(FmSearchDialog, OnClickedSpecialSettings, Button*, pButton )
326 : {
327 0 : if (m_ppbApproxSettings == pButton)
328 : {
329 0 : boost::scoped_ptr<AbstractSvxSearchSimilarityDialog> pDlg;
330 :
331 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
332 0 : if ( pFact )
333 0 : pDlg.reset(pFact->CreateSvxSearchSimilarityDialog( this, m_pSearchEngine->GetLevRelaxed(), m_pSearchEngine->GetLevOther(),
334 0 : m_pSearchEngine->GetLevShorter(), m_pSearchEngine->GetLevLonger() ));
335 : DBG_ASSERT( pDlg, "FmSearchDialog, OnClickedSpecialSettings: could not load the dialog!" );
336 :
337 0 : if ( pDlg && pDlg->Execute() == RET_OK )
338 : {
339 0 : m_pSearchEngine->SetLevRelaxed( pDlg->IsRelaxed() );
340 0 : m_pSearchEngine->SetLevOther( pDlg->GetOther() );
341 0 : m_pSearchEngine->SetLevShorter(pDlg->GetShorter() );
342 0 : m_pSearchEngine->SetLevLonger( pDlg->GetLonger() );
343 0 : }
344 : }
345 0 : else if (m_pSoundsLikeCJKSettings == pButton)
346 : {
347 0 : SfxItemSet aSet( SfxGetpApp()->GetPool() );
348 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
349 0 : if(pFact)
350 : {
351 0 : boost::scoped_ptr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog( this, aSet, m_pSearchEngine->GetTransliterationFlags() ));
352 : DBG_ASSERT(aDlg, "Dialog creation failed!");
353 0 : aDlg->Execute();
354 :
355 :
356 0 : sal_Int32 nFlags = aDlg->GetTransliterationFlags();
357 0 : m_pSearchEngine->SetTransliterationFlags(nFlags);
358 :
359 0 : m_pcbCase->Check(m_pSearchEngine->GetCaseSensitive());
360 0 : OnCheckBoxToggled( m_pcbCase );
361 0 : m_pHalfFullFormsCJK->Check( !m_pSearchEngine->GetIgnoreWidthCJK() );
362 0 : OnCheckBoxToggled( m_pHalfFullFormsCJK );
363 0 : }
364 : }
365 :
366 0 : return 0;
367 : }
368 :
369 0 : IMPL_LINK_NOARG(FmSearchDialog, OnSearchTextModified)
370 : {
371 0 : if ((!m_pcmbSearchText->GetText().isEmpty()) || !m_prbSearchForText->IsChecked())
372 0 : m_pbSearchAgain->Enable();
373 : else
374 0 : m_pbSearchAgain->Disable();
375 :
376 0 : m_pSearchEngine->InvalidatePreviousLoc();
377 0 : return 0;
378 : }
379 :
380 0 : IMPL_LINK(FmSearchDialog, OnFocusGrabbed, ComboBox*, EMPTYARG)
381 : {
382 0 : m_pcmbSearchText->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
383 0 : return 0;
384 : }
385 :
386 0 : IMPL_LINK(FmSearchDialog, OnPositionSelected, ListBox*, pBox)
387 : {
388 : (void) pBox; // avoid warning
389 : DBG_ASSERT(pBox->GetSelectEntryCount() == 1, "FmSearchDialog::OnMethodSelected : unerwartet : nicht genau ein Eintrag selektiert !");
390 :
391 0 : m_pSearchEngine->SetPosition(m_plbPosition->GetSelectEntryPos());
392 0 : return 0;
393 : }
394 :
395 0 : IMPL_LINK(FmSearchDialog, OnFieldSelected, ListBox*, pBox)
396 : {
397 : (void) pBox; // avoid warning
398 : DBG_ASSERT(pBox->GetSelectEntryCount() == 1, "FmSearchDialog::OnFieldSelected : unerwartet : nicht genau ein Eintrag selektiert !");
399 :
400 0 : m_pSearchEngine->RebuildUsedFields(m_prbAllFields->IsChecked() ? -1 : (sal_Int16)m_plbField->GetSelectEntryPos());
401 : // calls m_pSearchEngine->InvalidatePreviousLoc too
402 :
403 0 : sal_Int32 nCurrentContext = m_plbForm->GetSelectEntryPos();
404 0 : if (nCurrentContext != LISTBOX_ENTRY_NOTFOUND)
405 0 : m_arrContextFields[nCurrentContext] = OUString(m_plbField->GetSelectEntry());
406 0 : return 0;
407 : }
408 :
409 0 : IMPL_LINK(FmSearchDialog, OnCheckBoxToggled, CheckBox*, pBox)
410 : {
411 0 : bool bChecked = pBox->IsChecked();
412 :
413 : // formatter or case -> pass on to the engine
414 0 : if (pBox == m_pcbUseFormat)
415 0 : m_pSearchEngine->SetFormatterUsing(bChecked);
416 0 : else if (pBox == m_pcbCase)
417 0 : m_pSearchEngine->SetCaseSensitive(bChecked);
418 : // direction -> pass on and reset the checkbox-text for StartOver
419 0 : else if (pBox == m_pcbBackwards)
420 : {
421 0 : m_pcbStartOver->SetText( OUString( CUI_RES( bChecked ? RID_STR_FROM_BOTTOM : RID_STR_FROM_TOP ) ) );
422 0 : m_pSearchEngine->SetDirection(!bChecked);
423 : }
424 : // similarity-search or regular expression
425 0 : else if ((pBox == m_pcbApprox) || (pBox == m_pcbRegular) || (pBox == m_pcbWildCard))
426 : {
427 0 : CheckBox* pBoxes[] = { m_pcbWildCard, m_pcbRegular, m_pcbApprox };
428 0 : for (sal_uInt32 i=0; i< SAL_N_ELEMENTS(pBoxes); ++i)
429 : {
430 0 : if (pBoxes[i] != pBox)
431 : {
432 0 : if (bChecked)
433 0 : pBoxes[i]->Disable();
434 : else
435 0 : pBoxes[i]->Enable();
436 : }
437 : }
438 :
439 : // pass on to the engine
440 0 : m_pSearchEngine->SetWildcard(m_pcbWildCard->IsEnabled() ? m_pcbWildCard->IsChecked() : sal_False);
441 0 : m_pSearchEngine->SetRegular(m_pcbRegular->IsEnabled() ? m_pcbRegular->IsChecked() : sal_False);
442 0 : m_pSearchEngine->SetLevenshtein(m_pcbApprox->IsEnabled() ? m_pcbApprox->IsChecked() : sal_False);
443 : // (disabled boxes have to be passed to the engine as sal_False)
444 :
445 : // adjust the Position-Listbox (which is not allowed during Wildcard-search)
446 0 : if (pBox == m_pcbWildCard)
447 : {
448 0 : if (bChecked)
449 : {
450 0 : m_pftPosition->Disable();
451 0 : m_plbPosition->Disable();
452 : }
453 : else
454 : {
455 0 : m_pftPosition->Enable();
456 0 : m_plbPosition->Enable();
457 : }
458 : }
459 :
460 : // and the button for similarity-search
461 0 : if (pBox == m_pcbApprox)
462 : {
463 0 : if (bChecked)
464 0 : m_ppbApproxSettings->Enable();
465 : else
466 0 : m_ppbApproxSettings->Disable();
467 0 : }
468 : }
469 0 : else if (pBox == m_pHalfFullFormsCJK)
470 : {
471 : // forward to the search engine
472 0 : m_pSearchEngine->SetIgnoreWidthCJK( !bChecked );
473 : }
474 0 : else if (pBox == m_pSoundsLikeCJK)
475 : {
476 0 : m_pSoundsLikeCJKSettings->Enable(bChecked);
477 :
478 : // two other buttons which depend on this one
479 0 : bool bEnable = ( m_prbSearchForText->IsChecked()
480 0 : && !m_pSoundsLikeCJK->IsChecked()
481 : )
482 0 : || !SvtCJKOptions().IsJapaneseFindEnabled();
483 0 : m_pcbCase->Enable(bEnable);
484 0 : m_pHalfFullFormsCJK->Enable(bEnable);
485 :
486 : // forward to the search engine
487 0 : m_pSearchEngine->SetTransliteration( bChecked );
488 : }
489 :
490 0 : return 0;
491 : }
492 :
493 0 : void FmSearchDialog::InitContext(sal_Int16 nContext)
494 : {
495 0 : FmSearchContext fmscContext;
496 0 : fmscContext.nContext = nContext;
497 :
498 : #ifdef DBG_UTIL
499 : sal_uInt32 nResult =
500 : #endif
501 0 : m_lnkContextSupplier.Call(&fmscContext);
502 : DBG_ASSERT(nResult > 0, "FmSearchDialog::InitContext : ContextSupplier didn't give me any controls !");
503 :
504 : // put the field names into the respective listbox
505 0 : m_plbField->Clear();
506 :
507 0 : if (!fmscContext.sFieldDisplayNames.isEmpty())
508 : {
509 : // use the display names if supplied
510 : DBG_ASSERT(comphelper::string::getTokenCount(fmscContext.sFieldDisplayNames, ';') == comphelper::string::getTokenCount(fmscContext.strUsedFields, ';'),
511 : "FmSearchDialog::InitContext : invalid context description supplied !");
512 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(fmscContext.sFieldDisplayNames, ';'); ++i)
513 0 : m_plbField->InsertEntry(comphelper::string::getToken(fmscContext.sFieldDisplayNames, i, ';'));
514 : }
515 : else
516 : {
517 : // else use the field names
518 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(fmscContext.strUsedFields, ';'); ++i)
519 0 : m_plbField->InsertEntry(comphelper::string::getToken(fmscContext.strUsedFields, i, ';'));
520 : }
521 :
522 0 : if (nContext < (sal_Int32)m_arrContextFields.size() && !m_arrContextFields[nContext].isEmpty())
523 : {
524 0 : m_plbField->SelectEntry(m_arrContextFields[nContext]);
525 : }
526 : else
527 : {
528 0 : m_plbField->SelectEntryPos(0);
529 0 : if (m_prbSingleField->IsChecked() && (m_plbField->GetEntryCount() > 1))
530 0 : m_plbField->GrabFocus();
531 : }
532 :
533 : m_pSearchEngine->SwitchToContext(fmscContext.xCursor, fmscContext.strUsedFields, fmscContext.arrFields,
534 0 : m_prbAllFields->IsChecked() ? -1 : 0);
535 :
536 0 : m_pftRecord->SetText(OUString::number(fmscContext.xCursor->getRow()));
537 0 : }
538 :
539 0 : IMPL_LINK( FmSearchDialog, OnContextSelection, ListBox*, pBox)
540 : {
541 0 : InitContext(pBox->GetSelectEntryPos());
542 0 : return 0L;
543 : }
544 :
545 0 : void FmSearchDialog::EnableSearchUI(bool bEnable)
546 : {
547 : // when the controls shall be disabled their paint is turned off and then turned on again after a delay
548 0 : if (!bEnable)
549 0 : EnableControlPaint(false);
550 : else
551 : {
552 0 : if (m_aDelayedPaint.IsActive())
553 0 : m_aDelayedPaint.Stop();
554 : }
555 : // (the whole thing goes on below)
556 : // this small intricateness hopfully leads to no flickering when turning the SearchUI off
557 : // and on again shortly after (like it's the case during a short search process)
558 :
559 0 : if ( !bEnable )
560 : {
561 : // if one of my children has the focus, remember it
562 0 : vcl::Window* pFocusWindow = Application::GetFocusWindow( );
563 0 : if ( pFocusWindow && IsChild( pFocusWindow ) )
564 0 : m_pPreSearchFocus = pFocusWindow;
565 : else
566 0 : m_pPreSearchFocus = NULL;
567 : }
568 :
569 : // the search button has two functions -> adjust its text accordingly
570 0 : OUString sButtonText( bEnable ? m_sSearch : m_sCancel );
571 0 : m_pbSearchAgain->SetText( sButtonText );
572 :
573 0 : if (m_pSearchEngine->GetSearchMode() != SM_BRUTE)
574 : {
575 0 : m_prbSearchForText->Enable (bEnable);
576 0 : m_prbSearchForNull->Enable (bEnable);
577 0 : m_prbSearchForNotNull->Enable (bEnable);
578 0 : m_plbForm->Enable (bEnable);
579 0 : m_prbAllFields->Enable (bEnable);
580 0 : m_prbSingleField->Enable (bEnable);
581 0 : m_plbField->Enable (bEnable && m_prbSingleField->IsChecked());
582 0 : m_pcbBackwards->Enable (bEnable);
583 0 : m_pcbStartOver->Enable (bEnable);
584 0 : m_pbClose->Enable (bEnable);
585 0 : EnableSearchForDependees (bEnable);
586 :
587 0 : if ( !bEnable )
588 : { // this means we're preparing for starting a search
589 : // In this case, EnableSearchForDependees disabled the search button
590 : // But as we're about to use it for cancelling the search, we really need to enable it, again
591 0 : m_pbSearchAgain->Enable( true );
592 : }
593 : }
594 :
595 0 : if (!bEnable)
596 0 : m_aDelayedPaint.Start();
597 : else
598 0 : EnableControlPaint(true);
599 :
600 0 : if ( bEnable )
601 : { // restore focus
602 0 : if ( m_pPreSearchFocus )
603 : {
604 0 : m_pPreSearchFocus->GrabFocus();
605 0 : if ( WINDOW_EDIT == m_pPreSearchFocus->GetType() )
606 : {
607 0 : Edit* pEdit = static_cast< Edit* >( m_pPreSearchFocus );
608 0 : pEdit->SetSelection( Selection( 0, pEdit->GetText().getLength() ) );
609 : }
610 : }
611 0 : m_pPreSearchFocus = NULL;
612 0 : }
613 :
614 0 : }
615 :
616 0 : void FmSearchDialog::EnableSearchForDependees(bool bEnable)
617 : {
618 0 : bool bSearchingForText = m_prbSearchForText->IsChecked();
619 0 : m_pbSearchAgain->Enable(bEnable && (!bSearchingForText || (!m_pcmbSearchText->GetText().isEmpty())));
620 :
621 0 : bEnable = bEnable && bSearchingForText;
622 :
623 0 : bool bEnableRedundants = !m_pSoundsLikeCJK->IsChecked() || !SvtCJKOptions().IsJapaneseFindEnabled();
624 :
625 0 : m_pcmbSearchText->Enable (bEnable);
626 0 : m_pftPosition->Enable (bEnable && !m_pcbWildCard->IsChecked());
627 0 : m_pcbWildCard->Enable (bEnable && !m_pcbRegular->IsChecked() && !m_pcbApprox->IsChecked());
628 0 : m_pcbRegular->Enable (bEnable && !m_pcbWildCard->IsChecked() && !m_pcbApprox->IsChecked());
629 0 : m_pcbApprox->Enable (bEnable && !m_pcbWildCard->IsChecked() && !m_pcbRegular->IsChecked());
630 0 : m_ppbApproxSettings->Enable (bEnable && m_pcbApprox->IsChecked());
631 0 : m_pHalfFullFormsCJK->Enable (bEnable && bEnableRedundants);
632 0 : m_pSoundsLikeCJK->Enable (bEnable);
633 0 : m_pSoundsLikeCJKSettings->Enable (bEnable && m_pSoundsLikeCJK->IsChecked());
634 0 : m_plbPosition->Enable (bEnable && !m_pcbWildCard->IsChecked());
635 0 : m_pcbUseFormat->Enable (bEnable);
636 0 : m_pcbCase->Enable (bEnable && bEnableRedundants);
637 0 : }
638 :
639 0 : void FmSearchDialog::EnableControlPaint(bool bEnable)
640 : {
641 : Control* pAffectedControls[] = { m_prbSearchForText, m_pcmbSearchText, m_prbSearchForNull, m_prbSearchForNotNull,
642 : m_prbSearchForText, m_prbAllFields, m_prbSingleField, m_plbField, m_pftPosition, m_plbPosition,
643 : m_pcbUseFormat, m_pcbCase, m_pcbBackwards, m_pcbStartOver, m_pcbWildCard, m_pcbRegular, m_pcbApprox, m_ppbApproxSettings,
644 0 : m_pbSearchAgain, m_pbClose };
645 :
646 0 : if (!bEnable)
647 0 : for (sal_uInt32 i=0; i<SAL_N_ELEMENTS(pAffectedControls); ++i)
648 : {
649 0 : pAffectedControls[i]->SetUpdateMode(bEnable);
650 0 : pAffectedControls[i]->EnablePaint(bEnable);
651 : }
652 : else
653 0 : for (sal_uInt32 i=0; i<SAL_N_ELEMENTS(pAffectedControls); ++i)
654 : {
655 0 : pAffectedControls[i]->EnablePaint(bEnable);
656 0 : pAffectedControls[i]->SetUpdateMode(bEnable);
657 : }
658 0 : }
659 :
660 0 : IMPL_LINK_NOARG(FmSearchDialog, OnDelayedPaint)
661 : {
662 0 : EnableControlPaint(true);
663 0 : return 0L;
664 : }
665 :
666 0 : void FmSearchDialog::OnFound(const ::com::sun::star::uno::Any& aCursorPos, sal_Int16 nFieldPos)
667 : {
668 0 : FmFoundRecordInformation friInfo;
669 0 : friInfo.nContext = m_plbForm->GetSelectEntryPos();
670 : // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
671 0 : friInfo.aPosition = aCursorPos;
672 0 : if (m_prbAllFields->IsChecked())
673 0 : friInfo.nFieldPos = nFieldPos;
674 : else
675 0 : friInfo.nFieldPos = m_plbField->GetSelectEntryPos();
676 : // this of course implies that I have really searched in the field that is selected in the listbox,
677 : // which is made sure in RebuildUsedFields
678 :
679 0 : m_lnkFoundHandler.Call(&friInfo);
680 :
681 0 : m_pcmbSearchText->GrabFocus();
682 0 : }
683 :
684 0 : IMPL_LINK(FmSearchDialog, OnSearchProgress, FmSearchProgress*, pProgress)
685 : {
686 0 : SolarMutexGuard aGuard;
687 : // make this single method thread-safe (it's an overkill to block the whole application for this,
688 : // but we don't have another safety concept at the moment)
689 :
690 0 : switch (pProgress->aSearchState)
691 : {
692 : case FmSearchProgress::STATE_PROGRESS:
693 0 : if (pProgress->bOverflow)
694 : {
695 0 : OUString sHint( CUI_RES( m_pcbBackwards->IsChecked() ? RID_STR_OVERFLOW_BACKWARD : RID_STR_OVERFLOW_FORWARD ) );
696 0 : m_pftHint->SetText( sHint );
697 0 : m_pftHint->Invalidate();
698 : }
699 :
700 0 : m_pftRecord->SetText(OUString::number(1 + pProgress->nCurrentRecord));
701 0 : m_pftRecord->Invalidate();
702 0 : break;
703 :
704 : case FmSearchProgress::STATE_PROGRESS_COUNTING:
705 0 : m_pftHint->SetText(CUI_RESSTR(RID_STR_SEARCH_COUNTING));
706 0 : m_pftHint->Invalidate();
707 :
708 0 : m_pftRecord->SetText(OUString::number(pProgress->nCurrentRecord));
709 0 : m_pftRecord->Invalidate();
710 0 : break;
711 :
712 : case FmSearchProgress::STATE_SUCCESSFULL:
713 0 : OnFound(pProgress->aBookmark, (sal_Int16)pProgress->nFieldIndex);
714 0 : EnableSearchUI(true);
715 0 : break;
716 :
717 : case FmSearchProgress::STATE_ERROR:
718 : case FmSearchProgress::STATE_NOTHINGFOUND:
719 : {
720 0 : sal_uInt16 nErrorId = (FmSearchProgress::STATE_ERROR == pProgress->aSearchState)
721 : ? RID_STR_SEARCH_GENERAL_ERROR
722 0 : : RID_STR_SEARCH_NORECORD;
723 0 : MessageDialog(this, CUI_RES(nErrorId)).Execute();
724 : }
725 : // NO break !
726 : case FmSearchProgress::STATE_CANCELED:
727 0 : EnableSearchUI(true);
728 0 : if (m_lnkCanceledNotFoundHdl.IsSet())
729 : {
730 0 : FmFoundRecordInformation friInfo;
731 0 : friInfo.nContext = m_plbForm->GetSelectEntryPos();
732 : // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
733 0 : friInfo.aPosition = pProgress->aBookmark;
734 0 : m_lnkCanceledNotFoundHdl.Call(&friInfo);
735 : }
736 0 : break;
737 : }
738 :
739 0 : m_pftRecord->SetText(OUString::number(1 + pProgress->nCurrentRecord));
740 :
741 0 : return 0L;
742 : }
743 :
744 0 : void FmSearchDialog::LoadParams()
745 : {
746 0 : FmSearchParams aParams(m_pConfig->getParams());
747 :
748 0 : const OUString* pHistory = aParams.aHistory.getConstArray();
749 0 : const OUString* pHistoryEnd = pHistory + aParams.aHistory.getLength();
750 0 : for (; pHistory != pHistoryEnd; ++pHistory)
751 0 : m_pcmbSearchText->InsertEntry( *pHistory );
752 :
753 : // I do the settings at my UI-elements and then I simply call the respective change-handler,
754 : // that way the data is handed on to the SearchEngine and all dependent settings are done
755 :
756 : // current field
757 0 : sal_Int32 nInitialField = m_plbField->GetEntryPos( OUString( aParams.sSingleSearchField ) );
758 0 : if (nInitialField == LISTBOX_ENTRY_NOTFOUND)
759 0 : nInitialField = 0;
760 0 : m_plbField->SelectEntryPos(nInitialField);
761 0 : LINK(this, FmSearchDialog, OnFieldSelected).Call(m_plbField);
762 : // all fields/single field (AFTER selcting the field because OnClickedFieldRadios expects a valid value there)
763 0 : if (aParams.bAllFields)
764 : {
765 0 : m_prbSingleField->Check(false);
766 0 : m_prbAllFields->Check(true);
767 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(m_prbAllFields);
768 : // OnClickedFieldRadios also calls to RebuildUsedFields
769 : }
770 : else
771 : {
772 0 : m_prbAllFields->Check(false);
773 0 : m_prbSingleField->Check(true);
774 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(m_prbSingleField);
775 : }
776 :
777 0 : m_plbPosition->SelectEntryPos(aParams.nPosition);
778 0 : LINK(this, FmSearchDialog, OnPositionSelected).Call(m_plbPosition);
779 :
780 : // field formatting/case sensitivity/direction
781 0 : m_pcbUseFormat->Check(aParams.bUseFormatter);
782 0 : m_pcbCase->Check( aParams.isCaseSensitive() );
783 0 : m_pcbBackwards->Check(aParams.bBackwards);
784 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbUseFormat);
785 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbCase);
786 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbBackwards);
787 :
788 0 : m_pHalfFullFormsCJK->Check( !aParams.isIgnoreWidthCJK( ) ); // BEWARE: this checkbox has a inverse semantics!
789 0 : m_pSoundsLikeCJK->Check( aParams.bSoundsLikeCJK );
790 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pHalfFullFormsCJK);
791 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pSoundsLikeCJK);
792 :
793 0 : m_pcbWildCard->Check(false);
794 0 : m_pcbRegular->Check(false);
795 0 : m_pcbApprox->Check(false);
796 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbWildCard);
797 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbRegular);
798 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(m_pcbApprox);
799 :
800 0 : CheckBox* pToCheck = NULL;
801 0 : if (aParams.bWildcard)
802 0 : pToCheck = m_pcbWildCard;
803 0 : if (aParams.bRegular)
804 0 : pToCheck = m_pcbRegular;
805 0 : if (aParams.bApproxSearch)
806 0 : pToCheck = m_pcbApprox;
807 0 : if (aParams.bSoundsLikeCJK)
808 0 : pToCheck = m_pSoundsLikeCJK;
809 0 : if (pToCheck)
810 : {
811 0 : pToCheck->Check(true);
812 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(pToCheck);
813 : }
814 :
815 : // set Levenshtein-parameters directly at the SearchEngine
816 0 : m_pSearchEngine->SetLevRelaxed(aParams.bLevRelaxed);
817 0 : m_pSearchEngine->SetLevOther(aParams.nLevOther);
818 0 : m_pSearchEngine->SetLevShorter(aParams.nLevShorter);
819 0 : m_pSearchEngine->SetLevLonger(aParams.nLevLonger);
820 :
821 0 : m_pSearchEngine->SetTransliterationFlags( aParams.getTransliterationFlags( ) );
822 :
823 0 : m_prbSearchForText->Check(false);
824 0 : m_prbSearchForNull->Check(false);
825 0 : m_prbSearchForNotNull->Check(false);
826 0 : switch (aParams.nSearchForType)
827 : {
828 0 : case 1: m_prbSearchForNull->Check(true); break;
829 0 : case 2: m_prbSearchForNotNull->Check(true); break;
830 0 : default: m_prbSearchForText->Check(true); break;
831 : }
832 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(m_prbSearchForText);
833 0 : }
834 :
835 0 : void FmSearchDialog::SaveParams() const
836 : {
837 0 : if (!m_pConfig)
838 0 : return;
839 :
840 0 : FmSearchParams aCurrentSettings;
841 :
842 0 : aCurrentSettings.aHistory.realloc( m_pcmbSearchText->GetEntryCount() );
843 0 : OUString* pHistory = aCurrentSettings.aHistory.getArray();
844 0 : for (sal_Int32 i=0; i<m_pcmbSearchText->GetEntryCount(); ++i, ++pHistory)
845 0 : *pHistory = m_pcmbSearchText->GetEntry(i);
846 :
847 0 : aCurrentSettings.sSingleSearchField = m_plbField->GetSelectEntry();
848 0 : aCurrentSettings.bAllFields = m_prbAllFields->IsChecked();
849 0 : aCurrentSettings.nPosition = m_pSearchEngine->GetPosition();
850 0 : aCurrentSettings.bUseFormatter = m_pSearchEngine->GetFormatterUsing();
851 0 : aCurrentSettings.setCaseSensitive ( m_pSearchEngine->GetCaseSensitive() );
852 0 : aCurrentSettings.bBackwards = !m_pSearchEngine->GetDirection();
853 0 : aCurrentSettings.bWildcard = m_pSearchEngine->GetWildcard();
854 0 : aCurrentSettings.bRegular = m_pSearchEngine->GetRegular();
855 0 : aCurrentSettings.bApproxSearch = m_pSearchEngine->GetLevenshtein();
856 0 : aCurrentSettings.bLevRelaxed = m_pSearchEngine->GetLevRelaxed();
857 0 : aCurrentSettings.nLevOther = m_pSearchEngine->GetLevOther();
858 0 : aCurrentSettings.nLevShorter = m_pSearchEngine->GetLevShorter();
859 0 : aCurrentSettings.nLevLonger = m_pSearchEngine->GetLevLonger();
860 :
861 0 : aCurrentSettings.bSoundsLikeCJK = m_pSearchEngine->GetTransliteration();
862 0 : aCurrentSettings.setTransliterationFlags ( m_pSearchEngine->GetTransliterationFlags() );
863 :
864 0 : if (m_prbSearchForNull->IsChecked())
865 0 : aCurrentSettings.nSearchForType = 1;
866 0 : else if (m_prbSearchForNotNull->IsChecked())
867 0 : aCurrentSettings.nSearchForType = 2;
868 : else
869 0 : aCurrentSettings.nSearchForType = 0;
870 :
871 0 : m_pConfig->setParams( aCurrentSettings );
872 0 : }
873 :
874 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|