Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/debug.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : : #include <vcl/svapp.hxx>
32 : : #include <tools/shl.hxx>
33 : : #include <dialmgr.hxx>
34 : : #include <sfx2/tabdlg.hxx>
35 : : #include <osl/mutex.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <cuires.hrc>
38 : : #include <svl/filerec.hxx>
39 : : #include <svx/fmsrccfg.hxx>
40 : : #include <svx/fmsrcimp.hxx>
41 : : #include "fmsearch.hrc"
42 : : #include "cuifmsearch.hxx"
43 : : #include <svx/srchdlg.hxx>
44 : : #include <svl/cjkoptions.hxx>
45 : : #include <com/sun/star/i18n/TransliterationModules.hpp>
46 : : #include <comphelper/processfactory.hxx>
47 : : #include <comphelper/string.hxx>
48 : : #include <svx/svxdlg.hxx>
49 : : #include <sal/macros.h>
50 : :
51 : : using namespace ::com::sun::star::uno;
52 : : using namespace ::com::sun::star::i18n;
53 : : using namespace ::svxform;
54 : : using namespace ::com::sun::star::sdbc;
55 : : using namespace ::com::sun::star::util;
56 : :
57 : : #define MAX_HISTORY_ENTRIES 50
58 : :
59 : : //------------------------------------------------------------------------
60 : 0 : void FmSearchDialog::initCommon( const Reference< XResultSet >& _rxCursor )
61 : : {
62 : : // init the engine
63 : : DBG_ASSERT( m_pSearchEngine, "FmSearchDialog::initCommon: have no engine!" );
64 [ # # ]: 0 : m_pSearchEngine->SetProgressHandler(LINK(this, FmSearchDialog, OnSearchProgress));
65 : :
66 : : // some layout changes according to available CJK options
67 [ # # ]: 0 : SvtCJKOptions aCJKOptions;
68 [ # # ][ # # ]: 0 : if (!aCJKOptions.IsJapaneseFindEnabled())
69 : : {
70 [ # # ]: 0 : sal_Int32 nUpper = m_cbApprox.GetPosPixel().Y();
71 [ # # ]: 0 : sal_Int32 nDifference = m_aSoundsLikeCJKSettings.GetPosPixel().Y() - nUpper;
72 : :
73 : : // hide the options for the japanese search
74 : 0 : Control* pFieldsToMove[] = { &m_flState, &m_ftRecordLabel, &m_ftRecord, &m_ftHint };
75 [ # # ]: 0 : implMoveControls(pFieldsToMove, SAL_N_ELEMENTS(pFieldsToMove), nDifference, &m_flOptions);
76 : :
77 [ # # ]: 0 : m_aSoundsLikeCJK.Hide();
78 [ # # ]: 0 : m_aSoundsLikeCJKSettings.Hide();
79 : : }
80 : :
81 [ # # ][ # # ]: 0 : if (!aCJKOptions.IsCJKFontEnabled())
82 : : {
83 [ # # ]: 0 : m_aHalfFullFormsCJK.Hide();
84 : :
85 : : // never ignore the width (ignoring is expensive) if the option is not available at all
86 [ # # ]: 0 : m_pSearchEngine->SetIgnoreWidthCJK( sal_False );
87 : : }
88 : :
89 : : // some initial record texts
90 [ # # ][ # # ]: 0 : m_ftRecord.SetText( String::CreateFromInt32( _rxCursor->getRow() ) );
[ # # ][ # # ]
[ # # ]
91 [ # # ][ # # ]: 0 : m_pbClose.SetHelpText(String());
[ # # ][ # # ]
92 : 0 : }
93 : :
94 : : //------------------------------------------------------------------------
95 : 0 : FmSearchDialog::FmSearchDialog(Window* pParent, const UniString& sInitialText, const ::std::vector< String >& _rContexts, sal_Int16 nInitialContext,
96 : : const Link& lnkContextSupplier)
97 : 0 : :ModalDialog(pParent, CUI_RES(RID_SVXDLG_SEARCHFORM))
98 [ # # ]: 0 : ,m_flSearchFor (this, CUI_RES(FL_SEARCHFOR))
99 [ # # ]: 0 : ,m_rbSearchForText (this, CUI_RES(RB_SEARCHFORTEXT))
100 [ # # ]: 0 : ,m_rbSearchForNull (this, CUI_RES(RB_SEARCHFORNULL))
101 [ # # ]: 0 : ,m_rbSearchForNotNull (this, CUI_RES(RB_SEARCHFORNOTNULL))
102 [ # # ]: 0 : ,m_cmbSearchText (this, CUI_RES(CMB_SEARCHTEXT))
103 [ # # ]: 0 : ,m_flWhere (this, CUI_RES(FL_WHERE))
104 [ # # ]: 0 : ,m_ftForm (this, CUI_RES(FT_FORM))
105 [ # # ]: 0 : ,m_lbForm (this, CUI_RES(LB_FORM))
106 [ # # ]: 0 : ,m_rbAllFields (this, CUI_RES(RB_ALLFIELDS))
107 [ # # ]: 0 : ,m_rbSingleField (this, CUI_RES(RB_SINGLEFIELD))
108 [ # # ]: 0 : ,m_lbField (this, CUI_RES(LB_FIELD))
109 [ # # ]: 0 : ,m_flOptions (this, CUI_RES(FL_OPTIONS))
110 [ # # ]: 0 : ,m_ftPosition (this, CUI_RES(FT_POSITION))
111 [ # # ]: 0 : ,m_lbPosition (this, CUI_RES(LB_POSITION))
112 [ # # ]: 0 : ,m_cbUseFormat (this, CUI_RES(CB_USEFORMATTER))
113 [ # # ]: 0 : ,m_cbCase (this, CUI_RES(CB_CASE))
114 [ # # ]: 0 : ,m_cbBackwards (this, CUI_RES(CB_BACKWARD))
115 [ # # ]: 0 : ,m_cbStartOver (this, CUI_RES(CB_STARTOVER))
116 [ # # ]: 0 : ,m_cbWildCard (this, CUI_RES(CB_WILDCARD))
117 [ # # ]: 0 : ,m_cbRegular (this, CUI_RES(CB_REGULAR))
118 [ # # ]: 0 : ,m_cbApprox (this, CUI_RES(CB_APPROX))
119 [ # # ]: 0 : ,m_pbApproxSettings (this, CUI_RES(PB_APPROXSETTINGS))
120 [ # # ]: 0 : ,m_aHalfFullFormsCJK (this, CUI_RES(CB_HALFFULLFORMS))
121 [ # # ]: 0 : ,m_aSoundsLikeCJK (this, CUI_RES(CB_SOUNDSLIKECJK))
122 [ # # ]: 0 : ,m_aSoundsLikeCJKSettings (this, CUI_RES(PB_SOUNDSLIKESETTINGS))
123 [ # # ]: 0 : ,m_flState (this, CUI_RES(FL_STATE))
124 [ # # ]: 0 : ,m_ftRecordLabel (this, CUI_RES(FT_RECORDLABEL))
125 [ # # ]: 0 : ,m_ftRecord (this, CUI_RES(FT_RECORD))
126 [ # # ]: 0 : ,m_ftHint (this, CUI_RES(FT_HINT))
127 [ # # ]: 0 : ,m_pbSearchAgain (this, CUI_RES(PB_SEARCH))
128 [ # # ]: 0 : ,m_pbClose (this, CUI_RES(1))
129 [ # # ]: 0 : ,m_pbHelp (this, CUI_RES(1))
130 : : ,m_sSearch ( m_pbSearchAgain.GetText() )
131 : : ,m_sCancel ( Button::GetStandardText( BUTTON_CANCEL ) )
132 : : ,m_pPreSearchFocus( NULL )
133 : : ,m_lnkContextSupplier(lnkContextSupplier)
134 [ # # ][ # # ]: 0 : ,m_pConfig( NULL )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
135 : : {
136 : : DBG_ASSERT(m_lnkContextSupplier.IsSet(), "FmSearchDialog::FmSearchDialog : have no ContextSupplier !");
137 : :
138 [ # # ]: 0 : FmSearchContext fmscInitial;
139 : 0 : fmscInitial.nContext = nInitialContext;
140 [ # # ]: 0 : m_lnkContextSupplier.Call(&fmscInitial);
141 : : DBG_ASSERT(fmscInitial.xCursor.is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
142 : : DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';') == (xub_StrLen)fmscInitial.arrFields.size(),
143 : : "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplied !");
144 : : #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
145 : : for (sal_Int32 i=0; i<(sal_Int32)fmscInitial.arrFields.size(); ++i)
146 : : DBG_ASSERT(fmscInitial.arrFields.at(i).is(), "FmSearchDialog::FmSearchDialog : invalid data supplied by ContextSupplier !");
147 : : #endif // (OSL_DEBUG_LEVEL > 1) || DBG_UTIL
148 : :
149 [ # # # # ]: 0 : for ( ::std::vector< String >::const_iterator context = _rContexts.begin();
[ # # ]
150 : 0 : context != _rContexts.end();
151 : : ++context
152 : : )
153 : : {
154 [ # # ][ # # ]: 0 : m_arrContextFields.push_back(String());
[ # # ]
155 [ # # ][ # # ]: 0 : m_lbForm.InsertEntry(*context);
156 : : }
157 [ # # ]: 0 : m_lbForm.SelectEntryPos(nInitialContext);
158 : :
159 [ # # ]: 0 : m_lbForm.SetSelectHdl(LINK(this, FmSearchDialog, OnContextSelection));
160 : :
161 [ # # ]: 0 : if (m_arrContextFields.size() == 1)
162 : : { // remove the context selection listbox and rearrange the controls accordingly
163 [ # # ]: 0 : sal_Int32 nUpper = m_lbForm.GetPosPixel().Y();
164 [ # # ]: 0 : sal_Int32 nDifference = m_rbAllFields.GetPosPixel().Y() - nUpper;
165 : :
166 : : // move all controls below the affected ones up
167 : : Control* pFieldsToMove[] = { &m_rbAllFields, &m_rbSingleField, &m_lbField, &m_flOptions, &m_ftPosition, &m_lbPosition,
168 : : &m_cbUseFormat, &m_cbCase, &m_cbBackwards, &m_cbStartOver, &m_cbWildCard, &m_cbRegular, &m_cbApprox,
169 : : &m_pbApproxSettings, &m_aHalfFullFormsCJK, &m_aSoundsLikeCJK, &m_aSoundsLikeCJKSettings,
170 : 0 : &m_flState, &m_ftRecordLabel, &m_ftRecord, &m_ftHint };
171 : :
172 [ # # ]: 0 : implMoveControls(pFieldsToMove, SAL_N_ELEMENTS(pFieldsToMove), nDifference, &m_flWhere);
173 : :
174 [ # # ]: 0 : Point pt = m_rbAllFields.GetPosPixel();
175 [ # # ]: 0 : pt.X() = m_ftForm.GetPosPixel().X();
176 [ # # ]: 0 : m_rbAllFields.SetPosPixel( pt );
177 [ # # ]: 0 : pt = m_rbSingleField.GetPosPixel();
178 [ # # ]: 0 : pt.X() = m_ftForm.GetPosPixel().X();
179 [ # # ]: 0 : m_rbSingleField.SetPosPixel( pt );
180 : :
181 : : // hide dispensable controls
182 [ # # ]: 0 : m_ftForm.Hide();
183 [ # # ]: 0 : m_lbForm.Hide();
184 : : }
185 : :
186 : : m_pSearchEngine = new FmSearchEngine(
187 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory(), fmscInitial.xCursor, fmscInitial.strUsedFields, fmscInitial.arrFields, SM_ALLOWSCHEDULE );
[ # # ][ # # ]
188 [ # # ]: 0 : initCommon( fmscInitial.xCursor );
189 : :
190 [ # # ]: 0 : if (fmscInitial.sFieldDisplayNames.Len() != 0)
191 : : { // use the display names if supplied
192 : : DBG_ASSERT(comphelper::string::getTokenCount(fmscInitial.sFieldDisplayNames, ';') == comphelper::string::getTokenCount(fmscInitial.strUsedFields, ';'),
193 : : "FmSearchDialog::FmSearchDialog : invalid initial context description !");
194 [ # # ]: 0 : Init(fmscInitial.sFieldDisplayNames, sInitialText);
195 : : }
196 : : else
197 [ # # ][ # # ]: 0 : Init(fmscInitial.strUsedFields, sInitialText);
198 : 0 : }
199 : :
200 : : //------------------------------------------------------------------------
201 : 0 : void FmSearchDialog::implMoveControls(
202 : : Control** _ppControls,
203 : : sal_Int32 _nControls,
204 : : sal_Int32 _nUp,
205 : : Control* /*_pToResize*/)
206 : : {
207 [ # # ]: 0 : for (sal_Int32 i=0; i<_nControls; ++i)
208 : : {
209 [ # # ]: 0 : Point pt = _ppControls[i]->GetPosPixel();
210 : 0 : pt.Y() -= _nUp;
211 [ # # ]: 0 : _ppControls[i]->SetPosPixel(pt);
212 : : }
213 : :
214 : : // resize myself
215 [ # # ]: 0 : Size sz = GetSizePixel();
216 : 0 : sz.Height() -= _nUp;
217 [ # # ]: 0 : SetSizePixel(sz);
218 : 0 : }
219 : :
220 : : //------------------------------------------------------------------------
221 [ # # ][ # # ]: 0 : FmSearchDialog::~FmSearchDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
222 : : {
223 [ # # ]: 0 : if (m_aDelayedPaint.IsActive())
224 [ # # ]: 0 : m_aDelayedPaint.Stop();
225 : :
226 [ # # ]: 0 : SaveParams();
227 : :
228 [ # # ]: 0 : if (m_pConfig)
229 : : {
230 [ # # ][ # # ]: 0 : delete m_pConfig;
231 : 0 : m_pConfig = NULL;
232 : : }
233 : :
234 [ # # ][ # # ]: 0 : delete m_pSearchEngine;
235 [ # # ]: 0 : }
236 : :
237 : : //------------------------------------------------------------------------
238 : 0 : void FmSearchDialog::Init(const UniString& strVisibleFields, const UniString& sInitialText)
239 : : {
240 : : //the initialization of all the Controls
241 [ # # ]: 0 : m_rbSearchForText.SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
242 [ # # ]: 0 : m_rbSearchForNull.SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
243 [ # # ]: 0 : m_rbSearchForNotNull.SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
244 : :
245 [ # # ]: 0 : m_rbAllFields.SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
246 [ # # ]: 0 : m_rbSingleField.SetClickHdl(LINK(this, FmSearchDialog, OnClickedFieldRadios));
247 : :
248 [ # # ]: 0 : m_pbSearchAgain.SetClickHdl(LINK(this, FmSearchDialog, OnClickedSearchAgain));
249 [ # # ]: 0 : m_pbApproxSettings.SetClickHdl(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
250 [ # # ]: 0 : m_aSoundsLikeCJKSettings.SetClickHdl(LINK(this, FmSearchDialog, OnClickedSpecialSettings));
251 : :
252 [ # # ]: 0 : m_lbPosition.SetSelectHdl(LINK(this, FmSearchDialog, OnPositionSelected));
253 [ # # ]: 0 : m_lbField.SetSelectHdl(LINK(this, FmSearchDialog, OnFieldSelected));
254 : :
255 [ # # ]: 0 : m_cmbSearchText.SetModifyHdl(LINK(this, FmSearchDialog, OnSearchTextModified));
256 [ # # ]: 0 : m_cmbSearchText.EnableAutocomplete(sal_False);
257 : :
258 [ # # ]: 0 : m_cbUseFormat.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
259 [ # # ]: 0 : m_cbBackwards.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
260 [ # # ]: 0 : m_cbStartOver.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
261 [ # # ]: 0 : m_cbCase.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
262 [ # # ]: 0 : m_cbWildCard.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
263 [ # # ]: 0 : m_cbRegular.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
264 [ # # ]: 0 : m_cbApprox.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
265 [ # # ]: 0 : m_aHalfFullFormsCJK.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
266 [ # # ]: 0 : m_aSoundsLikeCJK.SetToggleHdl(LINK(this, FmSearchDialog, OnCheckBoxToggled));
267 : :
268 : : // fill the listboxes
269 : : // method of field comparison
270 : : sal_uInt16 nResIds[] = {
271 : : RID_STR_SEARCH_ANYWHERE,
272 : : RID_STR_SEARCH_BEGINNING,
273 : : RID_STR_SEARCH_END,
274 : : RID_STR_SEARCH_WHOLE
275 : 0 : };
276 [ # # ]: 0 : for ( size_t i=0; i<SAL_N_ELEMENTS(nResIds); ++i )
277 [ # # ][ # # ]: 0 : m_lbPosition.InsertEntry( String( CUI_RES( nResIds[i] ) ) );
[ # # ][ # # ]
278 [ # # ]: 0 : m_lbPosition.SelectEntryPos(MATCHING_ANYWHERE);
279 : :
280 : : // the field listbox
281 [ # # ][ # # ]: 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(strVisibleFields, ';'); ++i)
[ # # ]
282 [ # # ][ # # ]: 0 : m_lbField.InsertEntry(comphelper::string::getToken(strVisibleFields, i, ';'));
[ # # ][ # # ]
283 : :
284 : :
285 [ # # ][ # # ]: 0 : m_pConfig = new FmSearchConfigItem;
286 [ # # ]: 0 : LoadParams();
287 : :
288 [ # # ]: 0 : m_cmbSearchText.SetText(sInitialText);
289 : : // if the Edit-line has changed the text (e.g. because it contains
290 : : // control characters, as can be the case with memo fields), I use
291 : : // an empty UniString.
292 [ # # ]: 0 : UniString sRealSetText = m_cmbSearchText.GetText();
293 [ # # ][ # # ]: 0 : if (!sRealSetText.Equals(sInitialText))
294 [ # # ][ # # ]: 0 : m_cmbSearchText.SetText(UniString());
[ # # ]
295 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnSearchTextModified).Call(&m_cmbSearchText);
296 : :
297 : : // initial
298 [ # # ]: 0 : m_aDelayedPaint.SetTimeoutHdl(LINK(this, FmSearchDialog, OnDelayedPaint));
299 [ # # ]: 0 : m_aDelayedPaint.SetTimeout(500);
300 [ # # ]: 0 : EnableSearchUI(sal_True);
301 : :
302 [ # # ]: 0 : if ( m_rbSearchForText.IsChecked() )
303 [ # # ]: 0 : m_cmbSearchText.GrabFocus();
304 : :
305 [ # # ][ # # ]: 0 : FreeResource();
306 : 0 : }
307 : :
308 : : //------------------------------------------------------------------------
309 : 0 : sal_Bool FmSearchDialog::Close()
310 : : {
311 : : // If the close button is disabled and ESC is pressed in a dialog,
312 : : // then Frame will call Close anyway, which I don't want to happen
313 : : // while I'm in the middle of a search (maybe one that's running
314 : : // in its own thread)
315 [ # # ]: 0 : if (!m_pbClose.IsEnabled())
316 : 0 : return sal_False;
317 : 0 : return ModalDialog::Close();
318 : : }
319 : :
320 : : //------------------------------------------------------------------------
321 : 0 : IMPL_LINK(FmSearchDialog, OnClickedFieldRadios, Button*, pButton)
322 : : {
323 [ # # ][ # # ]: 0 : if ((pButton == &m_rbSearchForText) || (pButton == &m_rbSearchForNull) || (pButton == &m_rbSearchForNotNull))
[ # # ]
324 : : {
325 : 0 : EnableSearchForDependees(sal_True);
326 : : }
327 : : else
328 : : // en- or disable field list box accordingly
329 [ # # ]: 0 : if (pButton == &m_rbSingleField)
330 : : {
331 : 0 : m_lbField.Enable();
332 : 0 : m_pSearchEngine->RebuildUsedFields(m_lbField.GetSelectEntryPos());
333 : : }
334 : : else
335 : : {
336 : 0 : m_lbField.Disable();
337 : 0 : m_pSearchEngine->RebuildUsedFields(-1);
338 : : }
339 : :
340 : 0 : return 0;
341 : : }
342 : :
343 : : //------------------------------------------------------------------------
344 : 0 : IMPL_LINK_NOARG(FmSearchDialog, OnClickedSearchAgain)
345 : : {
346 [ # # ]: 0 : if (m_pbClose.IsEnabled())
347 : : { // the button has the function 'search'
348 [ # # ]: 0 : UniString strThisRoundText = m_cmbSearchText.GetText();
349 : : // to history
350 [ # # ]: 0 : m_cmbSearchText.RemoveEntry(strThisRoundText);
351 [ # # ]: 0 : m_cmbSearchText.InsertEntry(strThisRoundText, 0);
352 : : // the remove/insert makes sure that a) the UniString does not appear twice and
353 : : // that b) the last searched strings are at the beginning and limit the list length
354 [ # # ][ # # ]: 0 : while (m_cmbSearchText.GetEntryCount() > MAX_HISTORY_ENTRIES)
355 [ # # ][ # # ]: 0 : m_cmbSearchText.RemoveEntry(m_cmbSearchText.GetEntryCount()-1);
356 : :
357 : : // take out the 'overflow' hint
358 [ # # ][ # # ]: 0 : m_ftHint.SetText(UniString());
[ # # ]
359 [ # # ]: 0 : m_ftHint.Invalidate();
360 : :
361 [ # # ][ # # ]: 0 : if (m_cbStartOver.IsChecked())
362 : : {
363 [ # # ]: 0 : m_cbStartOver.Check(sal_False);
364 [ # # ]: 0 : EnableSearchUI(sal_False);
365 [ # # ]: 0 : if (m_rbSearchForText.IsChecked())
366 [ # # ][ # # ]: 0 : m_pSearchEngine->StartOver(strThisRoundText);
367 : : else
368 [ # # ]: 0 : m_pSearchEngine->StartOverSpecial(m_rbSearchForNull.IsChecked());
369 : : }
370 : : else
371 : : {
372 [ # # ]: 0 : EnableSearchUI(sal_False);
373 [ # # ]: 0 : if (m_rbSearchForText.IsChecked())
374 [ # # ][ # # ]: 0 : m_pSearchEngine->SearchNext(strThisRoundText);
375 : : else
376 [ # # ]: 0 : m_pSearchEngine->SearchNextSpecial(m_rbSearchForNull.IsChecked());
377 [ # # ]: 0 : }
378 : : }
379 : : else
380 : : { // the button has the function 'cancel'
381 : : DBG_ASSERT(m_pSearchEngine->GetSearchMode() != SM_BRUTE, "FmSearchDialog, OnClickedSearchAgain : falscher Modus !");
382 : : // the CancelButton is usually only disabled, when working in a thread or with reschedule
383 : 0 : m_pSearchEngine->CancelSearch();
384 : : // the ProgressHandler is called when it's really finished, here it's only a demand
385 : : }
386 : 0 : return 0;
387 : : }
388 : :
389 : : //------------------------------------------------------------------------
390 : 0 : IMPL_LINK(FmSearchDialog, OnClickedSpecialSettings, Button*, pButton )
391 : : {
392 [ # # ]: 0 : if (&m_pbApproxSettings == pButton)
393 : : {
394 : 0 : AbstractSvxSearchSimilarityDialog* pDlg = NULL;
395 : :
396 : 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
397 [ # # ]: 0 : if ( pFact )
398 : 0 : pDlg = pFact->CreateSvxSearchSimilarityDialog( this, m_pSearchEngine->GetLevRelaxed(), m_pSearchEngine->GetLevOther(),
399 : 0 : m_pSearchEngine->GetLevShorter(), m_pSearchEngine->GetLevLonger() );
400 : : DBG_ASSERT( pDlg, "FmSearchDialog, OnClickedSpecialSettings: could not load the dialog!" );
401 : :
402 [ # # ][ # # ]: 0 : if ( pDlg && pDlg->Execute() == RET_OK )
[ # # ]
403 : : {
404 : 0 : m_pSearchEngine->SetLevRelaxed( pDlg->IsRelaxed() );
405 : 0 : m_pSearchEngine->SetLevOther( pDlg->GetOther() );
406 : 0 : m_pSearchEngine->SetLevShorter(pDlg->GetShorter() );
407 : 0 : m_pSearchEngine->SetLevLonger( pDlg->GetLonger() );
408 : : }
409 [ # # ]: 0 : delete pDlg;
410 : : }
411 [ # # ]: 0 : else if (&m_aSoundsLikeCJKSettings == pButton)
412 : : {
413 [ # # ][ # # ]: 0 : SfxItemSet aSet( SFX_APP()->GetPool() );
414 [ # # ]: 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
415 [ # # ]: 0 : if(pFact)
416 : : {
417 [ # # ]: 0 : AbstractSvxJSearchOptionsDialog* aDlg = pFact->CreateSvxJSearchOptionsDialog( this, aSet, m_pSearchEngine->GetTransliterationFlags() );
418 : : DBG_ASSERT(aDlg, "Dialogdiet fail!");
419 [ # # ]: 0 : aDlg->Execute();
420 : :
421 : :
422 [ # # ]: 0 : sal_Int32 nFlags = aDlg->GetTransliterationFlags();
423 : 0 : m_pSearchEngine->SetTransliterationFlags(nFlags);
424 : :
425 [ # # ][ # # ]: 0 : m_cbCase.Check(m_pSearchEngine->GetCaseSensitive());
426 [ # # ]: 0 : OnCheckBoxToggled( &m_cbCase );
427 [ # # ][ # # ]: 0 : m_aHalfFullFormsCJK.Check( !m_pSearchEngine->GetIgnoreWidthCJK() );
428 [ # # ]: 0 : OnCheckBoxToggled( &m_aHalfFullFormsCJK );
429 [ # # ][ # # ]: 0 : delete aDlg;
430 [ # # ]: 0 : }
431 : : }
432 : :
433 : 0 : return 0;
434 : : }
435 : :
436 : : //------------------------------------------------------------------------
437 : 0 : IMPL_LINK_NOARG(FmSearchDialog, OnSearchTextModified)
438 : : {
439 [ # # ][ # # ]: 0 : if ((m_cmbSearchText.GetText().Len() != 0) || !m_rbSearchForText.IsChecked())
[ # # ][ # # ]
[ # # # # ]
440 : 0 : m_pbSearchAgain.Enable();
441 : : else
442 : 0 : m_pbSearchAgain.Disable();
443 : :
444 : 0 : m_pSearchEngine->InvalidatePreviousLoc();
445 : 0 : return 0;
446 : : }
447 : :
448 : : //------------------------------------------------------------------------
449 : 0 : IMPL_LINK(FmSearchDialog, OnPositionSelected, ListBox*, pBox)
450 : : {
451 : : (void) pBox; // avoid warning
452 : : DBG_ASSERT(pBox->GetSelectEntryCount() == 1, "FmSearchDialog::OnMethodSelected : unerwartet : nicht genau ein Eintrag selektiert !");
453 : :
454 : 0 : m_pSearchEngine->SetPosition(m_lbPosition.GetSelectEntryPos());
455 : 0 : return 0;
456 : : }
457 : :
458 : : //------------------------------------------------------------------------
459 : 0 : IMPL_LINK(FmSearchDialog, OnFieldSelected, ListBox*, pBox)
460 : : {
461 : : (void) pBox; // avoid warning
462 : : DBG_ASSERT(pBox->GetSelectEntryCount() == 1, "FmSearchDialog::OnFieldSelected : unerwartet : nicht genau ein Eintrag selektiert !");
463 : :
464 [ # # ]: 0 : m_pSearchEngine->RebuildUsedFields(m_rbAllFields.IsChecked() ? -1 : (sal_Int16)m_lbField.GetSelectEntryPos());
465 : : // calls m_pSearchEngine->InvalidatePreviousLoc too
466 : :
467 : 0 : sal_Int32 nCurrentContext = m_lbForm.GetSelectEntryPos();
468 [ # # ]: 0 : if (nCurrentContext != LISTBOX_ENTRY_NOTFOUND)
469 [ # # ][ # # ]: 0 : m_arrContextFields[nCurrentContext] = UniString(m_lbField.GetSelectEntry());
470 : 0 : return 0;
471 : : }
472 : :
473 : : //------------------------------------------------------------------------
474 : 0 : IMPL_LINK(FmSearchDialog, OnCheckBoxToggled, CheckBox*, pBox)
475 : : {
476 : 0 : sal_Bool bChecked = pBox->IsChecked();
477 : :
478 : : // formatter or case -> pass on to the engine
479 [ # # ]: 0 : if (pBox == &m_cbUseFormat)
480 : 0 : m_pSearchEngine->SetFormatterUsing(bChecked);
481 [ # # ]: 0 : else if (pBox == &m_cbCase)
482 : 0 : m_pSearchEngine->SetCaseSensitive(bChecked);
483 : : // direction -> pass on and reset the checkbox-text for StartOver
484 [ # # ]: 0 : else if (pBox == &m_cbBackwards)
485 : : {
486 [ # # ][ # # ]: 0 : m_cbStartOver.SetText( String( CUI_RES( bChecked ? RID_STR_FROM_BOTTOM : RID_STR_FROM_TOP ) ) );
[ # # ][ # # ]
487 : 0 : m_pSearchEngine->SetDirection(!bChecked);
488 : : }
489 : : // similarity-search or regular expression
490 [ # # ][ # # ]: 0 : else if ((pBox == &m_cbApprox) || (pBox == &m_cbRegular) || (pBox == &m_cbWildCard))
[ # # ]
491 : : {
492 : 0 : CheckBox* pBoxes[] = { &m_cbWildCard, &m_cbRegular, &m_cbApprox };
493 [ # # ]: 0 : for (sal_uInt32 i=0; i< SAL_N_ELEMENTS(pBoxes); ++i)
494 : : {
495 [ # # ]: 0 : if (pBoxes[i] != pBox)
496 : : {
497 [ # # ]: 0 : if (bChecked)
498 [ # # ]: 0 : pBoxes[i]->Disable();
499 : : else
500 [ # # ]: 0 : pBoxes[i]->Enable();
501 : : }
502 : : }
503 : :
504 : : // pass on to the engine
505 [ # # ][ # # ]: 0 : m_pSearchEngine->SetWildcard(m_cbWildCard.IsEnabled() ? m_cbWildCard.IsChecked() : sal_False);
[ # # ]
506 [ # # ][ # # ]: 0 : m_pSearchEngine->SetRegular(m_cbRegular.IsEnabled() ? m_cbRegular.IsChecked() : sal_False);
[ # # ]
507 [ # # ][ # # ]: 0 : m_pSearchEngine->SetLevenshtein(m_cbApprox.IsEnabled() ? m_cbApprox.IsChecked() : sal_False);
[ # # ]
508 : : // (disabled boxes have to be passed to the engine as sal_False)
509 : :
510 : : // adjust the Position-Listbox (which is not allowed during Wildcard-search)
511 [ # # ]: 0 : if (pBox == &m_cbWildCard)
512 : : {
513 [ # # ]: 0 : if (bChecked)
514 : : {
515 [ # # ]: 0 : m_ftPosition.Disable();
516 [ # # ]: 0 : m_lbPosition.Disable();
517 : : }
518 : : else
519 : : {
520 [ # # ]: 0 : m_ftPosition.Enable();
521 [ # # ]: 0 : m_lbPosition.Enable();
522 : : }
523 : : }
524 : :
525 : : // and the button for similarity-search
526 [ # # ]: 0 : if (pBox == &m_cbApprox)
527 : : {
528 [ # # ]: 0 : if (bChecked)
529 [ # # ]: 0 : m_pbApproxSettings.Enable();
530 : : else
531 [ # # ]: 0 : m_pbApproxSettings.Disable();
532 : 0 : }
533 : : }
534 [ # # ]: 0 : else if (pBox == &m_aHalfFullFormsCJK)
535 : : {
536 : : // forward to the search engine
537 : 0 : m_pSearchEngine->SetIgnoreWidthCJK( !bChecked );
538 : : }
539 [ # # ]: 0 : else if (pBox == &m_aSoundsLikeCJK)
540 : : {
541 : 0 : m_aSoundsLikeCJKSettings.Enable(bChecked);
542 : :
543 : : // two other buttons which depend on this one
544 : 0 : sal_Bool bEnable = ( m_rbSearchForText.IsChecked()
545 [ # # ]: 0 : && !m_aSoundsLikeCJK.IsChecked()
546 : : )
547 [ # # ][ # # ]: 0 : || !SvtCJKOptions().IsJapaneseFindEnabled();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
548 : 0 : m_cbCase.Enable(bEnable);
549 : 0 : m_aHalfFullFormsCJK.Enable(bEnable);
550 : :
551 : : // forward to the search engine
552 : 0 : m_pSearchEngine->SetTransliteration( bChecked );
553 : : }
554 : :
555 : 0 : return 0;
556 : : }
557 : :
558 : : //------------------------------------------------------------------------
559 : 0 : void FmSearchDialog::InitContext(sal_Int16 nContext)
560 : : {
561 [ # # ]: 0 : FmSearchContext fmscContext;
562 : 0 : fmscContext.nContext = nContext;
563 : :
564 : : #ifdef DBG_UTIL
565 : : sal_uInt32 nResult =
566 : : #endif
567 [ # # ]: 0 : m_lnkContextSupplier.Call(&fmscContext);
568 : : DBG_ASSERT(nResult > 0, "FmSearchDialog::InitContext : ContextSupplier didn't give me any controls !");
569 : :
570 : : // put teh field names into the respective listbox
571 [ # # ]: 0 : m_lbField.Clear();
572 : :
573 [ # # ]: 0 : if (fmscContext.sFieldDisplayNames.Len() != 0)
574 : : {
575 : : // use the display names if supplied
576 : : DBG_ASSERT(comphelper::string::getTokenCount(fmscContext.sFieldDisplayNames, ';') == comphelper::string::getTokenCount(fmscContext.strUsedFields, ';'),
577 : : "FmSearchDialog::InitContext : invalid context description supplied !");
578 [ # # ][ # # ]: 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(fmscContext.sFieldDisplayNames, ';'); ++i)
[ # # ]
579 [ # # ][ # # ]: 0 : m_lbField.InsertEntry(comphelper::string::getToken(fmscContext.sFieldDisplayNames, i, ';'));
[ # # ][ # # ]
580 : : }
581 : : else
582 : : {
583 : : // else use the field names
584 [ # # ][ # # ]: 0 : for (sal_Int32 i=0; i < comphelper::string::getTokenCount(fmscContext.strUsedFields, ';'); ++i)
[ # # ]
585 [ # # ][ # # ]: 0 : m_lbField.InsertEntry(comphelper::string::getToken(fmscContext.strUsedFields, i, ';'));
[ # # ][ # # ]
586 : : }
587 : :
588 [ # # ][ # # ]: 0 : if (nContext < (sal_Int32)m_arrContextFields.size() && m_arrContextFields[nContext].Len())
[ # # ][ # # ]
589 : : {
590 [ # # ][ # # ]: 0 : m_lbField.SelectEntry(m_arrContextFields[nContext]);
591 : : }
592 : : else
593 : : {
594 [ # # ]: 0 : m_lbField.SelectEntryPos(0);
595 [ # # ][ # # ]: 0 : if (m_rbSingleField.IsChecked() && (m_lbField.GetEntryCount() > 1))
[ # # ][ # # ]
596 [ # # ]: 0 : m_lbField.GrabFocus();
597 : : }
598 : :
599 : : m_pSearchEngine->SwitchToContext(fmscContext.xCursor, fmscContext.strUsedFields, fmscContext.arrFields,
600 [ # # ][ # # ]: 0 : m_rbAllFields.IsChecked() ? -1 : 0);
[ # # ]
601 : :
602 [ # # ][ # # ]: 0 : m_ftRecord.SetText(String::CreateFromInt32(fmscContext.xCursor->getRow()));
[ # # ][ # # ]
[ # # ][ # # ]
603 : 0 : }
604 : :
605 : : //------------------------------------------------------------------------
606 : 0 : IMPL_LINK( FmSearchDialog, OnContextSelection, ListBox*, pBox)
607 : : {
608 : 0 : InitContext(pBox->GetSelectEntryPos());
609 : 0 : return 0L;
610 : : }
611 : :
612 : : //------------------------------------------------------------------------
613 : 0 : void FmSearchDialog::EnableSearchUI(sal_Bool bEnable)
614 : : {
615 : : // when the controls shall be disabled their paint is turned off and then turned on again after a delay
616 [ # # ]: 0 : if (!bEnable)
617 [ # # ]: 0 : EnableControlPaint(sal_False);
618 : : else
619 : : {
620 [ # # ]: 0 : if (m_aDelayedPaint.IsActive())
621 [ # # ]: 0 : m_aDelayedPaint.Stop();
622 : : }
623 : : // (the whole thing goes on below)
624 : : // this small intricateness hopfully leads to no flickering when turning the SearchUI off
625 : : // and on again shortly after (like it's the case during a short search process)
626 : :
627 [ # # ]: 0 : if ( !bEnable )
628 : : {
629 : : // if one of my children has the focus, remember it
630 [ # # ]: 0 : Window* pFocusWindow = Application::GetFocusWindow( );
631 [ # # ][ # # ]: 0 : if ( pFocusWindow && IsChild( pFocusWindow ) )
[ # # ][ # # ]
632 : 0 : m_pPreSearchFocus = pFocusWindow;
633 : : else
634 : 0 : m_pPreSearchFocus = NULL;
635 : : }
636 : :
637 : : // the search button has two functions -> adjust its text accordingly
638 [ # # ][ # # ]: 0 : String sButtonText( bEnable ? m_sSearch : m_sCancel );
639 [ # # ]: 0 : m_pbSearchAgain.SetText( sButtonText );
640 : :
641 [ # # ]: 0 : if (m_pSearchEngine->GetSearchMode() != SM_BRUTE)
642 : : {
643 [ # # ]: 0 : m_flSearchFor.Enable (bEnable);
644 [ # # ]: 0 : m_rbSearchForText.Enable (bEnable);
645 [ # # ]: 0 : m_rbSearchForNull.Enable (bEnable);
646 [ # # ]: 0 : m_rbSearchForNotNull.Enable (bEnable);
647 [ # # ]: 0 : m_flWhere.Enable (bEnable);
648 [ # # ]: 0 : m_ftForm.Enable (bEnable);
649 [ # # ]: 0 : m_lbForm.Enable (bEnable);
650 [ # # ]: 0 : m_rbAllFields.Enable (bEnable);
651 [ # # ]: 0 : m_rbSingleField.Enable (bEnable);
652 [ # # ][ # # ]: 0 : m_lbField.Enable (bEnable && m_rbSingleField.IsChecked());
[ # # ]
653 [ # # ]: 0 : m_flOptions.Enable (bEnable);
654 [ # # ]: 0 : m_cbBackwards.Enable (bEnable);
655 [ # # ]: 0 : m_cbStartOver.Enable (bEnable);
656 [ # # ]: 0 : m_pbClose.Enable (bEnable);
657 [ # # ]: 0 : EnableSearchForDependees (bEnable);
658 : :
659 [ # # ]: 0 : if ( !bEnable )
660 : : { // this means we're preparing for starting a search
661 : : // In this case, EnableSearchForDependees disabled the search button
662 : : // But as we're about to use it for cancelling the search, we really need to enable it, again
663 [ # # ]: 0 : m_pbSearchAgain.Enable( sal_True );
664 : : }
665 : : }
666 : :
667 [ # # ]: 0 : if (!bEnable)
668 [ # # ]: 0 : m_aDelayedPaint.Start();
669 : : else
670 [ # # ]: 0 : EnableControlPaint(sal_True);
671 : :
672 [ # # ]: 0 : if ( bEnable )
673 : : { // restore focus
674 [ # # ]: 0 : if ( m_pPreSearchFocus )
675 : : {
676 [ # # ]: 0 : m_pPreSearchFocus->GrabFocus();
677 [ # # ][ # # ]: 0 : if ( WINDOW_EDIT == m_pPreSearchFocus->GetType() )
678 : : {
679 : 0 : Edit* pEdit = static_cast< Edit* >( m_pPreSearchFocus );
680 [ # # ][ # # ]: 0 : pEdit->SetSelection( Selection( 0, pEdit->GetText().Len() ) );
[ # # ]
681 : : }
682 : : }
683 : 0 : m_pPreSearchFocus = NULL;
684 [ # # ]: 0 : }
685 : :
686 : 0 : }
687 : :
688 : : //------------------------------------------------------------------------
689 : 0 : void FmSearchDialog::EnableSearchForDependees(sal_Bool bEnable)
690 : : {
691 : 0 : sal_Bool bSearchingForText = m_rbSearchForText.IsChecked();
692 [ # # ][ # # ]: 0 : m_pbSearchAgain.Enable(bEnable && (!bSearchingForText || (m_cmbSearchText.GetText().Len() != 0)));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
693 : :
694 [ # # ][ # # ]: 0 : bEnable = bEnable && bSearchingForText;
695 : :
696 [ # # ][ # # ]: 0 : sal_Bool bEnableRedundants = !m_aSoundsLikeCJK.IsChecked() || !SvtCJKOptions().IsJapaneseFindEnabled();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
697 : :
698 : 0 : m_cmbSearchText.Enable (bEnable);
699 [ # # ][ # # ]: 0 : m_ftPosition.Enable (bEnable && !m_cbWildCard.IsChecked());
700 [ # # ][ # # ]: 0 : m_cbWildCard.Enable (bEnable && !m_cbRegular.IsChecked() && !m_cbApprox.IsChecked());
[ # # ]
701 [ # # ][ # # ]: 0 : m_cbRegular.Enable (bEnable && !m_cbWildCard.IsChecked() && !m_cbApprox.IsChecked());
[ # # ]
702 [ # # ][ # # ]: 0 : m_cbApprox.Enable (bEnable && !m_cbWildCard.IsChecked() && !m_cbRegular.IsChecked());
[ # # ]
703 [ # # ][ # # ]: 0 : m_pbApproxSettings.Enable (bEnable && m_cbApprox.IsChecked());
704 [ # # ][ # # ]: 0 : m_aHalfFullFormsCJK.Enable (bEnable && bEnableRedundants);
705 : 0 : m_aSoundsLikeCJK.Enable (bEnable);
706 [ # # ][ # # ]: 0 : m_aSoundsLikeCJKSettings.Enable (bEnable && m_aSoundsLikeCJK.IsChecked());
707 [ # # ][ # # ]: 0 : m_lbPosition.Enable (bEnable && !m_cbWildCard.IsChecked());
708 : 0 : m_cbUseFormat.Enable (bEnable);
709 [ # # ][ # # ]: 0 : m_cbCase.Enable (bEnable && bEnableRedundants);
710 : 0 : }
711 : :
712 : : //------------------------------------------------------------------------
713 : 0 : void FmSearchDialog::EnableControlPaint(sal_Bool bEnable)
714 : : {
715 : : Control* pAffectedControls[] = { &m_flSearchFor, &m_rbSearchForText, &m_cmbSearchText, &m_rbSearchForNull, &m_rbSearchForNotNull,
716 : : &m_rbSearchForText, &m_flWhere, &m_rbAllFields, &m_rbSingleField, &m_lbField, &m_flOptions, &m_ftPosition, &m_lbPosition,
717 : : &m_cbUseFormat, &m_cbCase, &m_cbBackwards, &m_cbStartOver, &m_cbWildCard, &m_cbRegular, &m_cbApprox, &m_pbApproxSettings,
718 : 0 : &m_pbSearchAgain, &m_pbClose };
719 : :
720 [ # # ]: 0 : if (!bEnable)
721 [ # # ]: 0 : for (sal_uInt32 i=0; i<SAL_N_ELEMENTS(pAffectedControls); ++i)
722 : : {
723 [ # # ]: 0 : pAffectedControls[i]->SetUpdateMode(bEnable);
724 [ # # ]: 0 : pAffectedControls[i]->EnablePaint(bEnable);
725 : : }
726 : : else
727 [ # # ]: 0 : for (sal_uInt32 i=0; i<SAL_N_ELEMENTS(pAffectedControls); ++i)
728 : : {
729 [ # # ]: 0 : pAffectedControls[i]->EnablePaint(bEnable);
730 [ # # ]: 0 : pAffectedControls[i]->SetUpdateMode(bEnable);
731 : : }
732 : 0 : }
733 : :
734 : : //------------------------------------------------------------------------
735 : 0 : IMPL_LINK_NOARG(FmSearchDialog, OnDelayedPaint)
736 : : {
737 : 0 : EnableControlPaint(sal_True);
738 : 0 : return 0L;
739 : : }
740 : :
741 : : //------------------------------------------------------------------------
742 : 0 : void FmSearchDialog::OnFound(const ::com::sun::star::uno::Any& aCursorPos, sal_Int16 nFieldPos)
743 : : {
744 : 0 : FmFoundRecordInformation friInfo;
745 [ # # ]: 0 : friInfo.nContext = m_lbForm.GetSelectEntryPos();
746 : : // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
747 : 0 : friInfo.aPosition = aCursorPos;
748 [ # # ]: 0 : if (m_rbAllFields.IsChecked())
749 : 0 : friInfo.nFieldPos = nFieldPos;
750 : : else
751 [ # # ]: 0 : friInfo.nFieldPos = m_lbField.GetSelectEntryPos();
752 : : // this of course implies that I have really searched in the field that is selected in the listbox,
753 : : // which is made sure in RebuildUsedFields
754 : :
755 [ # # ]: 0 : m_lnkFoundHandler.Call(&friInfo);
756 : :
757 [ # # ]: 0 : m_cmbSearchText.GrabFocus();
758 : 0 : }
759 : :
760 : : //------------------------------------------------------------------------
761 : 0 : IMPL_LINK(FmSearchDialog, OnSearchProgress, FmSearchProgress*, pProgress)
762 : : {
763 [ # # ]: 0 : SolarMutexGuard aGuard;
764 : : // make this single method thread-safe (it's an overkill to block the whole application for this,
765 : : // but we don't have another safety concept at the moment)
766 : :
767 [ # # # # : 0 : switch (pProgress->aSearchState)
# # ]
768 : : {
769 : : case FmSearchProgress::STATE_PROGRESS:
770 [ # # ]: 0 : if (pProgress->bOverflow)
771 : : {
772 [ # # ][ # # ]: 0 : String sHint( CUI_RES( m_cbBackwards.IsChecked() ? RID_STR_OVERFLOW_BACKWARD : RID_STR_OVERFLOW_FORWARD ) );
[ # # ][ # # ]
773 [ # # ]: 0 : m_ftHint.SetText( sHint );
774 [ # # ][ # # ]: 0 : m_ftHint.Invalidate();
775 : : }
776 : :
777 [ # # ][ # # ]: 0 : m_ftRecord.SetText(String::CreateFromInt32(1 + pProgress->nCurrentRecord));
[ # # ]
778 [ # # ]: 0 : m_ftRecord.Invalidate();
779 : 0 : break;
780 : :
781 : : case FmSearchProgress::STATE_PROGRESS_COUNTING:
782 [ # # ][ # # ]: 0 : m_ftHint.SetText(CUI_RESSTR(RID_STR_SEARCH_COUNTING));
[ # # ][ # # ]
[ # # ]
783 [ # # ]: 0 : m_ftHint.Invalidate();
784 : :
785 [ # # ][ # # ]: 0 : m_ftRecord.SetText(String::CreateFromInt32(pProgress->nCurrentRecord));
[ # # ]
786 [ # # ]: 0 : m_ftRecord.Invalidate();
787 : 0 : break;
788 : :
789 : : case FmSearchProgress::STATE_SUCCESSFULL:
790 [ # # ]: 0 : OnFound(pProgress->aBookmark, (sal_Int16)pProgress->nFieldIndex);
791 [ # # ]: 0 : EnableSearchUI(sal_True);
792 : 0 : break;
793 : :
794 : : case FmSearchProgress::STATE_ERROR:
795 : : case FmSearchProgress::STATE_NOTHINGFOUND:
796 : : {
797 : : sal_uInt16 nErrorId = (FmSearchProgress::STATE_ERROR == pProgress->aSearchState)
798 : : ? RID_SVXERR_SEARCH_GENERAL_ERROR
799 [ # # ]: 0 : : RID_SVXERR_SEARCH_NORECORD;
800 [ # # ][ # # ]: 0 : ErrorBox(this, CUI_RES(nErrorId)).Execute();
[ # # ][ # # ]
801 : : }
802 : : // NO break !
803 : : case FmSearchProgress::STATE_CANCELED:
804 [ # # ]: 0 : EnableSearchUI(sal_True);
805 [ # # ][ # # ]: 0 : if (m_lnkCanceledNotFoundHdl.IsSet())
806 : : {
807 : 0 : FmFoundRecordInformation friInfo;
808 [ # # ]: 0 : friInfo.nContext = m_lbForm.GetSelectEntryPos();
809 : : // if I don't do a search in a context, this has an invalid value - but then it doesn't matter anyway
810 : 0 : friInfo.aPosition = pProgress->aBookmark;
811 [ # # ]: 0 : m_lnkCanceledNotFoundHdl.Call(&friInfo);
812 : : }
813 : 0 : break;
814 : : }
815 : :
816 [ # # ][ # # ]: 0 : m_ftRecord.SetText(String::CreateFromInt32(1 + pProgress->nCurrentRecord));
[ # # ]
817 : :
818 [ # # ]: 0 : return 0L;
819 : : }
820 : :
821 : : //------------------------------------------------------------------------
822 : 0 : void FmSearchDialog::LoadParams()
823 : : {
824 [ # # ][ # # ]: 0 : FmSearchParams aParams(m_pConfig->getParams());
825 : :
826 : 0 : const ::rtl::OUString* pHistory = aParams.aHistory.getConstArray();
827 : 0 : const ::rtl::OUString* pHistoryEnd = pHistory + aParams.aHistory.getLength();
828 [ # # ]: 0 : for (; pHistory != pHistoryEnd; ++pHistory)
829 [ # # ][ # # ]: 0 : m_cmbSearchText.InsertEntry( *pHistory );
[ # # ]
830 : :
831 : : // I do the settings at my UI-elements and then I simply call the respective change-handler,
832 : : // that way the data is handed on to the SearchEngine and all dependent settings are done
833 : :
834 : : // current field
835 [ # # ][ # # ]: 0 : sal_uInt16 nInitialField = m_lbField.GetEntryPos( String( aParams.sSingleSearchField ) );
[ # # ]
836 [ # # ]: 0 : if (nInitialField == COMBOBOX_ENTRY_NOTFOUND)
837 : 0 : nInitialField = 0;
838 [ # # ]: 0 : m_lbField.SelectEntryPos(nInitialField);
839 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnFieldSelected).Call(&m_lbField);
840 : : // all fields/single field (AFTER selcting the field because OnClickedFieldRadios expects a valid value there)
841 [ # # ]: 0 : if (aParams.bAllFields)
842 : : {
843 [ # # ]: 0 : m_rbSingleField.Check(sal_False);
844 [ # # ]: 0 : m_rbAllFields.Check(sal_True);
845 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(&m_rbAllFields);
846 : : // OnClickedFieldRadios also calls to RebuildUsedFields
847 : : }
848 : : else
849 : : {
850 [ # # ]: 0 : m_rbAllFields.Check(sal_False);
851 [ # # ]: 0 : m_rbSingleField.Check(sal_True);
852 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(&m_rbSingleField);
853 : : }
854 : :
855 [ # # ]: 0 : m_lbPosition.SelectEntryPos(aParams.nPosition);
856 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnPositionSelected).Call(&m_lbPosition);
857 : :
858 : : // field formatting/case sensitivity/direction
859 [ # # ]: 0 : m_cbUseFormat.Check(aParams.bUseFormatter);
860 [ # # ][ # # ]: 0 : m_cbCase.Check( aParams.isCaseSensitive() );
861 [ # # ]: 0 : m_cbBackwards.Check(aParams.bBackwards);
862 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbUseFormat);
863 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbCase);
864 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbBackwards);
865 : :
866 [ # # ][ # # ]: 0 : m_aHalfFullFormsCJK.Check( !aParams.isIgnoreWidthCJK( ) ); // BEWARE: this checkbox has a inverse semantics!
867 [ # # ]: 0 : m_aSoundsLikeCJK.Check( aParams.bSoundsLikeCJK );
868 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_aHalfFullFormsCJK);
869 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_aSoundsLikeCJK);
870 : :
871 [ # # ]: 0 : m_cbWildCard.Check(sal_False);
872 [ # # ]: 0 : m_cbRegular.Check(sal_False);
873 [ # # ]: 0 : m_cbApprox.Check(sal_False);
874 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbWildCard);
875 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbRegular);
876 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(&m_cbApprox);
877 : :
878 : 0 : CheckBox* pToCheck = NULL;
879 [ # # ]: 0 : if (aParams.bWildcard)
880 : 0 : pToCheck = &m_cbWildCard;
881 [ # # ]: 0 : if (aParams.bRegular)
882 : 0 : pToCheck = &m_cbRegular;
883 [ # # ]: 0 : if (aParams.bApproxSearch)
884 : 0 : pToCheck = &m_cbApprox;
885 [ # # ]: 0 : if (aParams.bSoundsLikeCJK)
886 : 0 : pToCheck = &m_aSoundsLikeCJK;
887 [ # # ]: 0 : if (pToCheck)
888 : : {
889 [ # # ]: 0 : pToCheck->Check(sal_True);
890 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnCheckBoxToggled).Call(pToCheck);
891 : : }
892 : :
893 : : // set Levenshtein-parameters directly at the SearchEngine
894 : 0 : m_pSearchEngine->SetLevRelaxed(aParams.bLevRelaxed);
895 : 0 : m_pSearchEngine->SetLevOther(aParams.nLevOther);
896 : 0 : m_pSearchEngine->SetLevShorter(aParams.nLevShorter);
897 : 0 : m_pSearchEngine->SetLevLonger(aParams.nLevLonger);
898 : :
899 : 0 : m_pSearchEngine->SetTransliterationFlags( aParams.getTransliterationFlags( ) );
900 : :
901 [ # # ]: 0 : m_rbSearchForText.Check(sal_False);
902 [ # # ]: 0 : m_rbSearchForNull.Check(sal_False);
903 [ # # ]: 0 : m_rbSearchForNotNull.Check(sal_False);
904 [ # # # ]: 0 : switch (aParams.nSearchForType)
905 : : {
906 [ # # ]: 0 : case 1: m_rbSearchForNull.Check(sal_True); break;
907 [ # # ]: 0 : case 2: m_rbSearchForNotNull.Check(sal_True); break;
908 [ # # ]: 0 : default: m_rbSearchForText.Check(sal_True); break;
909 : : }
910 [ # # ][ # # ]: 0 : LINK(this, FmSearchDialog, OnClickedFieldRadios).Call(&m_rbSearchForText);
[ # # ]
911 : 0 : }
912 : :
913 : : //------------------------------------------------------------------------
914 : 0 : void FmSearchDialog::SaveParams() const
915 : : {
916 [ # # ]: 0 : if (!m_pConfig)
917 : 0 : return;
918 : :
919 [ # # ]: 0 : FmSearchParams aCurrentSettings;
920 : :
921 [ # # ][ # # ]: 0 : aCurrentSettings.aHistory.realloc( m_cmbSearchText.GetEntryCount() );
922 [ # # ]: 0 : ::rtl::OUString* pHistory = aCurrentSettings.aHistory.getArray();
923 [ # # ][ # # ]: 0 : for (sal_uInt16 i=0; i<m_cmbSearchText.GetEntryCount(); ++i, ++pHistory)
924 [ # # ][ # # ]: 0 : *pHistory = m_cmbSearchText.GetEntry(i);
[ # # ]
925 : :
926 [ # # ][ # # ]: 0 : aCurrentSettings.sSingleSearchField = m_lbField.GetSelectEntry();
[ # # ]
927 : 0 : aCurrentSettings.bAllFields = m_rbAllFields.IsChecked();
928 : 0 : aCurrentSettings.nPosition = m_pSearchEngine->GetPosition();
929 : 0 : aCurrentSettings.bUseFormatter = m_pSearchEngine->GetFormatterUsing();
930 [ # # ][ # # ]: 0 : aCurrentSettings.setCaseSensitive ( m_pSearchEngine->GetCaseSensitive() );
931 : 0 : aCurrentSettings.bBackwards = !m_pSearchEngine->GetDirection();
932 : 0 : aCurrentSettings.bWildcard = m_pSearchEngine->GetWildcard();
933 : 0 : aCurrentSettings.bRegular = m_pSearchEngine->GetRegular();
934 : 0 : aCurrentSettings.bApproxSearch = m_pSearchEngine->GetLevenshtein();
935 : 0 : aCurrentSettings.bLevRelaxed = m_pSearchEngine->GetLevRelaxed();
936 : 0 : aCurrentSettings.nLevOther = m_pSearchEngine->GetLevOther();
937 : 0 : aCurrentSettings.nLevShorter = m_pSearchEngine->GetLevShorter();
938 : 0 : aCurrentSettings.nLevLonger = m_pSearchEngine->GetLevLonger();
939 : :
940 : 0 : aCurrentSettings.bSoundsLikeCJK = m_pSearchEngine->GetTransliteration();
941 : 0 : aCurrentSettings.setTransliterationFlags ( m_pSearchEngine->GetTransliterationFlags() );
942 : :
943 [ # # ]: 0 : if (m_rbSearchForNull.IsChecked())
944 : 0 : aCurrentSettings.nSearchForType = 1;
945 [ # # ]: 0 : else if (m_rbSearchForNotNull.IsChecked())
946 : 0 : aCurrentSettings.nSearchForType = 2;
947 : : else
948 : 0 : aCurrentSettings.nSearchForType = 0;
949 : :
950 [ # # ][ # # ]: 0 : m_pConfig->setParams( aCurrentSettings );
951 : : }
952 : :
953 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|