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 :
21 : #include <sal/macros.h>
22 : #include <vcl/wrkwin.hxx>
23 : #include <vcl/morebtn.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <svl/slstitm.hxx>
26 : #include <svl/itemiter.hxx>
27 : #include <svl/style.hxx>
28 : #include <unotools/searchopt.hxx>
29 : #include <sfx2/dispatch.hxx>
30 : #include <sfx2/objsh.hxx>
31 : #include <sfx2/module.hxx>
32 : #include <sfx2/viewsh.hxx>
33 : #include <sfx2/basedlgs.hxx>
34 : #include <svl/cjkoptions.hxx>
35 : #include <com/sun/star/container/XNameAccess.hpp>
36 : #include <com/sun/star/i18n/TransliterationModules.hpp>
37 : #include <com/sun/star/frame/XDispatch.hpp>
38 : #include <com/sun/star/frame/XDispatchProvider.hpp>
39 : #include <com/sun/star/beans/PropertyValue.hpp>
40 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
41 : #include <com/sun/star/frame/ModuleManager.hpp>
42 : #include <comphelper/processfactory.hxx>
43 : #include <svl/itempool.hxx>
44 : #include <svl/intitem.hxx>
45 :
46 : #include <sfx2/app.hxx>
47 : #include <toolkit/unohlp.hxx>
48 :
49 : #define _SVX_SRCHDLG_CXX
50 : #include "svx/srchdlg.hxx"
51 :
52 : #include <svx/dialogs.hrc>
53 : #include <svx/svxitems.hrc>
54 : #include "srchdlg.hrc"
55 :
56 :
57 : #define ITEMID_SETITEM 0
58 :
59 : #include <svl/srchitem.hxx>
60 : #include <svx/pageitem.hxx>
61 : #include "srchctrl.hxx"
62 : #include <svx/dialmgr.hxx>
63 : #include "svx/dlgutil.hxx"
64 : #include <editeng/brshitem.hxx>
65 : #include <tools/resary.hxx>
66 : #include <svx/svxdlg.hxx>
67 :
68 : using namespace com::sun::star::i18n;
69 : using namespace com::sun::star;
70 : using namespace comphelper;
71 :
72 : // -----------------------------------------------------------------------
73 :
74 : #define REMEMBER_SIZE 10
75 :
76 : #define MODIFY_SEARCH 0x00000001
77 : #define MODIFY_REPLACE 0x00000002
78 : #define MODIFY_WORD 0x00000004
79 : #define MODIFY_EXACT 0x00000008
80 : #define MODIFY_BACKWARDS 0x00000010
81 : #define MODIFY_SELECTION 0x00000020
82 : #define MODIFY_REGEXP 0x00000040
83 : #define MODIFY_LAYOUT 0x00000080
84 : #define MODIFY_SIMILARITY 0x00000100
85 : #define MODIFY_FORMULAS 0x00000200
86 : #define MODIFY_VALUES 0x00000400
87 : #define MODIFY_CALC_NOTES 0x00000800
88 : #define MODIFY_ROWS 0x00001000
89 : #define MODIFY_COLUMNS 0x00002000
90 : #define MODIFY_ALLTABLES 0x00004000
91 : #define MODIFY_NOTES 0x00008000
92 :
93 : #define GetCheckBoxValue( rBox ) \
94 : rBox.IsEnabled() ? rBox.IsChecked() : sal_False
95 :
96 : struct SearchDlg_Impl
97 : {
98 : FixedText aSearchFormats;
99 : FixedText aReplaceFormats;
100 :
101 : sal_Bool bMultiLineEdit : 1,
102 : bSaveToModule : 1,
103 : bFocusOnSearch : 1,
104 : bDeltaCalculated : 1;
105 : sal_uInt16* pRanges;
106 : Timer aSelectionTimer;
107 :
108 : uno::Reference< frame::XDispatch > xCommand1Dispatch;
109 : uno::Reference< frame::XDispatch > xCommand2Dispatch;
110 : util::URL aCommand1URL;
111 : util::URL aCommand2URL;
112 :
113 0 : SearchDlg_Impl( Window* pParent ) :
114 0 : aSearchFormats ( pParent, SVX_RES( FT_SEARCH_FORMATS ) ),
115 0 : aReplaceFormats ( pParent, SVX_RES( FT_REPLACE_FORMATS ) ),
116 : bMultiLineEdit ( sal_False ),
117 : bSaveToModule ( sal_True ),
118 : bFocusOnSearch ( sal_True ),
119 : bDeltaCalculated( sal_False ),
120 0 : pRanges ( NULL )
121 : {
122 0 : aCommand1URL.Complete = aCommand1URL.Main = rtl::OUString("vnd.sun.search:SearchViaComponent1");
123 0 : aCommand1URL.Protocol = rtl::OUString("vnd.sun.search:");
124 0 : aCommand1URL.Path = rtl::OUString("SearchViaComponent1");
125 0 : aCommand2URL.Complete = aCommand2URL.Main = rtl::OUString("vnd.sun.search:SearchViaComponent2");
126 0 : aCommand2URL.Protocol = rtl::OUString("vnd.sun.search:");
127 0 : aCommand2URL.Path = rtl::OUString("SearchViaComponent2");
128 0 : }
129 0 : ~SearchDlg_Impl() { delete[] pRanges; }
130 : };
131 :
132 0 : void ListToStrArr_Impl( sal_uInt16 nId, std::vector<rtl::OUString>& rStrLst, ComboBox& rCBox )
133 : {
134 : SfxStringListItem* pSrchItem =
135 0 : (SfxStringListItem*)SFX_APP()->GetItem( nId );
136 :
137 0 : if (pSrchItem)
138 : {
139 0 : std::vector<String> aLst = pSrchItem->GetList();
140 :
141 0 : for ( sal_uInt16 i = 0; i < aLst.size(); ++i )
142 : {
143 0 : rStrLst.push_back(aLst[i]);
144 0 : rCBox.InsertEntry(aLst[i]);
145 0 : }
146 : }
147 0 : }
148 :
149 0 : void StrArrToList_Impl( sal_uInt16 nId, const std::vector<rtl::OUString>& rStrLst )
150 : {
151 : DBG_ASSERT( !rStrLst.empty(), "check in advance");
152 0 : std::vector<String> aLst;
153 :
154 0 : for (std::vector<rtl::OUString>::const_iterator i = rStrLst.begin(); i != rStrLst.end(); ++i)
155 0 : aLst.push_back(String(*i));
156 :
157 0 : SFX_APP()->PutItem( SfxStringListItem( nId, &aLst ) );
158 0 : }
159 :
160 : // class SearchAttrItemList ----------------------------------------------
161 :
162 0 : SearchAttrItemList::SearchAttrItemList( const SearchAttrItemList& rList ) :
163 0 : SrchAttrItemList(rList)
164 : {
165 0 : for ( sal_uInt16 i = 0; i < size(); ++i )
166 0 : if ( !IsInvalidItem( (*this)[i].pItem ) )
167 0 : (*this)[i].pItem = (*this)[i].pItem->Clone();
168 0 : }
169 :
170 : // -----------------------------------------------------------------------
171 :
172 0 : SearchAttrItemList::~SearchAttrItemList()
173 : {
174 0 : Clear();
175 0 : }
176 :
177 : // -----------------------------------------------------------------------
178 :
179 0 : void SearchAttrItemList::Put( const SfxItemSet& rSet )
180 : {
181 0 : if ( !rSet.Count() )
182 0 : return;
183 :
184 0 : SfxItemPool* pPool = rSet.GetPool();
185 0 : SfxItemIter aIter( rSet );
186 : SearchAttrItem aItem;
187 0 : const SfxPoolItem* pItem = aIter.GetCurItem();
188 : sal_uInt16 nWhich;
189 :
190 0 : while ( sal_True )
191 : {
192 : // only test that it is available?
193 0 : if( IsInvalidItem( pItem ) )
194 : {
195 0 : nWhich = rSet.GetWhichByPos( aIter.GetCurPos() );
196 0 : aItem.pItem = (SfxPoolItem*)pItem;
197 : }
198 : else
199 : {
200 0 : nWhich = pItem->Which();
201 0 : aItem.pItem = pItem->Clone();
202 : }
203 :
204 0 : aItem.nSlot = pPool->GetSlotId( nWhich );
205 0 : Insert( aItem );
206 :
207 0 : if ( aIter.IsAtEnd() )
208 0 : break;
209 0 : pItem = aIter.NextItem();
210 0 : }
211 : }
212 :
213 : // -----------------------------------------------------------------------
214 :
215 0 : SfxItemSet& SearchAttrItemList::Get( SfxItemSet& rSet )
216 : {
217 0 : SfxItemPool* pPool = rSet.GetPool();
218 :
219 0 : for ( sal_uInt16 i = 0; i < size(); ++i )
220 0 : if ( IsInvalidItem( (*this)[i].pItem ) )
221 0 : rSet.InvalidateItem( pPool->GetWhich( (*this)[i].nSlot ) );
222 : else
223 0 : rSet.Put( *(*this)[i].pItem );
224 0 : return rSet;
225 : }
226 :
227 : // -----------------------------------------------------------------------
228 :
229 0 : void SearchAttrItemList::Clear()
230 : {
231 0 : for ( sal_uInt16 i = 0; i < size(); ++i )
232 0 : if ( !IsInvalidItem( (*this)[i].pItem ) )
233 0 : delete (*this)[i].pItem;
234 0 : SrchAttrItemList::clear();
235 0 : }
236 :
237 : // -----------------------------------------------------------------------
238 :
239 : // Deletes the pointer to the items
240 0 : void SearchAttrItemList::Remove(size_t nPos, size_t nLen)
241 : {
242 0 : if ( nPos + nLen > size() )
243 0 : nLen = size() - nPos;
244 :
245 0 : for ( sal_uInt16 i = nPos; i < nPos + nLen; ++i )
246 0 : if ( !IsInvalidItem( (*this)[i].pItem ) )
247 0 : delete (*this)[i].pItem;
248 :
249 0 : SrchAttrItemList::erase( begin() + nPos, begin() + nPos + nLen );
250 0 : }
251 :
252 : #undef INI_LIST
253 : #define INI_LIST() \
254 : aSearchText ( this, SVX_RES( FT_SEARCH ) ), \
255 : aSearchLB ( this, SVX_RES( ED_SEARCH ) ), \
256 : aSearchTmplLB ( this, SVX_RES( LB_SEARCH ) ), \
257 : aSearchAttrText ( this, SVX_RES( FT_SEARCH_ATTR ) ), \
258 : aReplaceText ( this, SVX_RES( FT_REPLACE ) ), \
259 : aReplaceLB ( this, SVX_RES( ED_REPLACE ) ), \
260 : aReplaceTmplLB ( this, SVX_RES( LB_REPLACE ) ), \
261 : aReplaceAttrText( this, SVX_RES( FT_REPLACE_ATTR ) ), \
262 : aSearchBtn ( this, SVX_RES( BTN_SEARCH ) ), \
263 : aSearchAllBtn ( this, SVX_RES( BTN_SEARCH_ALL ) ), \
264 : aSearchCmdLine ( this, SVX_RES( FL_SEARCH_COMMAND ) ), \
265 : aReplaceBtn ( this, SVX_RES( BTN_REPLACE ) ), \
266 : aReplaceAllBtn ( this, SVX_RES( BTN_REPLACE_ALL ) ), \
267 : aSearchComponentFL( this, SVX_RES( FL_SEARCH_COMPONENT ) ), \
268 : aSearchComponent1PB( this, SVX_RES( BTN_COMPONENT_1 ) ), \
269 : aSearchComponent2PB( this, SVX_RES( BTN_COMPONENT_2 ) ), \
270 : aMatchCaseCB ( this, SVX_RES( CB_MATCH_CASE ) ), \
271 : aWordBtn ( this, SVX_RES( CB_WHOLE_WORDS ) ), \
272 : aButtonsFL ( this, SVX_RES( FL_BUTTONS ) ), \
273 : pMoreBtn ( new MoreButton( this, SVX_RES( BTN_MORE ) ) ), \
274 : aHelpBtn ( this, SVX_RES( BTN_HELP ) ), \
275 : aCloseBtn ( this, SVX_RES( BTN_CLOSE ) ), \
276 : aOptionsFL ( this, SVX_RES( FL_OPTIONS ) ), \
277 : aSelectionBtn ( this, SVX_RES( CB_SELECTIONS ) ), \
278 : aBackwardsBtn ( this, SVX_RES( CB_BACKWARDS ) ), \
279 : aRegExpBtn ( this, SVX_RES( CB_REGEXP ) ), \
280 : aSimilarityBox ( this, SVX_RES( CB_SIMILARITY) ), \
281 : aSimilarityBtn ( this, SVX_RES( PB_SIMILARITY) ), \
282 : aLayoutBtn ( this, SVX_RES( CB_LAYOUTS ) ), \
283 : aNotesBtn ( this, SVX_RES( CB_COMMENTS ) ), \
284 : aJapMatchFullHalfWidthCB( this, SVX_RES( CB_JAP_MATCH_FULL_HALF_WIDTH ) ),\
285 : aJapOptionsCB ( this, SVX_RES( CB_JAP_SOUNDS_LIKE ) ), \
286 : aJapOptionsBtn ( this, SVX_RES( PB_JAP_OPTIONS ) ), \
287 : aAttributeBtn ( this, SVX_RES( BTN_ATTRIBUTE ) ), \
288 : aFormatBtn ( this, SVX_RES( BTN_FORMAT ) ), \
289 : aNoFormatBtn ( this, SVX_RES( BTN_NOFORMAT ) ), \
290 : aCalcFL ( this, SVX_RES( FL_CALC ) ), \
291 : aCalcSearchInFT ( this, SVX_RES( FT_CALC_SEARCHIN ) ), \
292 : aCalcSearchInLB ( this, SVX_RES( LB_CALC_SEARCHIN ) ), \
293 : aCalcSearchDirFT( this, SVX_RES( FT_CALC_SEARCHDIR ) ), \
294 : aRowsBtn ( this, SVX_RES( RB_CALC_ROWS ) ), \
295 : aColumnsBtn ( this, SVX_RES( RB_CALC_COLUMNS ) ), \
296 : aAllSheetsCB ( this, SVX_RES( CB_ALL_SHEETS ) ), \
297 : rBindings ( rBind ), \
298 : bWriter ( sal_False ), \
299 : bSearch ( sal_True ), \
300 : bFormat ( sal_False ), \
301 : nOptions ( USHRT_MAX ), \
302 : bSet ( sal_False ), \
303 : bReadOnly ( sal_False ), \
304 : bConstruct ( sal_True ), \
305 : nModifyFlag ( 0 ), \
306 : aCalcStr ( SVX_RES( STR_WORDCALC ) ), \
307 : pImpl ( NULL ), \
308 : pSearchList ( NULL ), \
309 : pReplaceList ( new SearchAttrItemList ), \
310 : pSearchItem ( NULL ), \
311 : pSearchController ( NULL ), \
312 : pOptionsController ( NULL ), \
313 : pFamilyController ( NULL ), \
314 : pSearchSetController ( NULL ), \
315 : pReplaceSetController ( NULL ), \
316 : nTransliterationFlags ( 0x00000000 )
317 :
318 : // class SvxSearchDialog -------------------------------------------------
319 :
320 0 : SvxSearchDialog::SvxSearchDialog( Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind ) :
321 :
322 0 : SfxModelessDialog( &rBind, pChildWin, pParent, SVX_RES( RID_SVXDLG_SEARCH ) ),
323 :
324 0 : INI_LIST()
325 :
326 : {
327 0 : Construct_Impl();
328 0 : }
329 :
330 : #undef INI_LIST
331 :
332 : // -----------------------------------------------------------------------
333 :
334 0 : SvxSearchDialog::~SvxSearchDialog()
335 : {
336 0 : Hide();
337 :
338 0 : rBindings.EnterRegistrations();
339 0 : delete pSearchController;
340 0 : delete pOptionsController;
341 0 : delete pFamilyController;
342 0 : delete pSearchSetController;
343 0 : delete pReplaceSetController;
344 0 : rBindings.LeaveRegistrations();
345 :
346 0 : delete pSearchItem;
347 0 : delete pImpl;
348 0 : delete pSearchList;
349 0 : delete pReplaceList;
350 0 : delete pMoreBtn;
351 0 : }
352 :
353 0 : static void lcl_MoveDown( Window& rWindow, sal_Int32 nOffset )
354 : {
355 0 : Point aPos(rWindow.GetPosPixel());
356 0 : aPos.Y() += nOffset;
357 0 : rWindow.SetPosPixel(aPos);
358 0 : }
359 :
360 0 : void SvxSearchDialog::Construct_Impl()
361 : {
362 : // temporary to avoid incompatibility
363 0 : pImpl = new SearchDlg_Impl( this );
364 0 : pImpl->aSelectionTimer.SetTimeout( 500 );
365 : pImpl->aSelectionTimer.SetTimeoutHdl(
366 0 : LINK( this, SvxSearchDialog, TimeoutHdl_Impl ) );
367 0 : EnableControls_Impl( 0 );
368 :
369 : // Store old Text from aWordBtn
370 0 : aCalcStr += sal_Unicode('#');
371 0 : aCalcStr += aWordBtn.GetText();
372 :
373 0 : aLayoutStr = SVX_RESSTR( RID_SVXSTR_SEARCH_STYLES );
374 0 : aStylesStr = aLayoutBtn.GetText();
375 :
376 : // Get stored search-strings from the application
377 : ListToStrArr_Impl( SID_SEARCHDLG_SEARCHSTRINGS,
378 0 : aSearchStrings, aSearchLB );
379 : ListToStrArr_Impl( SID_SEARCHDLG_REPLACESTRINGS,
380 0 : aReplaceStrings, aReplaceLB );
381 :
382 0 : pMoreBtn->SetMoreText( String( SVX_RES( STR_MORE_BTN ) ) );
383 0 : pMoreBtn->SetLessText( String( SVX_RES( STR_LESS_BTN ) ) );
384 :
385 0 : FreeResource();
386 0 : InitControls_Impl();
387 :
388 : // Get attribut sets only once in construtor()
389 0 : const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
390 : const SvxSetItem* pSrchSetItem =
391 0 : (const SvxSetItem*) rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SFX_CALLMODE_SLOT, ppArgs );
392 :
393 0 : if ( pSrchSetItem )
394 0 : InitAttrList_Impl( &pSrchSetItem->GetItemSet(), 0 );
395 :
396 : const SvxSetItem* pReplSetItem =
397 0 : (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SFX_CALLMODE_SLOT, ppArgs );
398 :
399 0 : if ( pReplSetItem )
400 0 : InitAttrList_Impl( 0, &pReplSetItem->GetItemSet() );
401 :
402 : // Create controller and update at once
403 0 : rBindings.EnterRegistrations();
404 : pSearchController =
405 0 : new SvxSearchController( SID_SEARCH_ITEM, rBindings, *this );
406 : pOptionsController =
407 0 : new SvxSearchController( SID_SEARCH_OPTIONS, rBindings, *this );
408 0 : rBindings.LeaveRegistrations();
409 0 : rBindings.GetDispatcher()->Execute( FID_SEARCH_ON, SFX_CALLMODE_SLOT, ppArgs );
410 0 : pImpl->aSelectionTimer.Start();
411 :
412 :
413 0 : SvtCJKOptions aCJKOptions;
414 0 : if(!aCJKOptions.IsJapaneseFindEnabled())
415 : {
416 0 : aJapOptionsCB.Check( sal_False );
417 0 : aJapOptionsCB.Hide();
418 0 : aJapOptionsBtn.Hide();
419 : }
420 0 : if(!aCJKOptions.IsCJKFontEnabled())
421 : {
422 0 : aJapMatchFullHalfWidthCB.Hide();
423 : }
424 :
425 0 : aSimilarityBtn.SetAccessibleRelationLabeledBy(&aSimilarityBox);
426 0 : aSimilarityBtn.SetAccessibleRelationMemberOf(&aOptionsFL);
427 0 : aJapOptionsBtn.SetAccessibleRelationLabeledBy(&aJapOptionsCB);
428 0 : aJapOptionsBtn.SetAccessibleRelationMemberOf(&aOptionsFL);
429 0 : aRowsBtn.SetAccessibleRelationMemberOf(&aCalcSearchDirFT);
430 0 : aColumnsBtn.SetAccessibleRelationMemberOf(&aCalcSearchDirFT);
431 :
432 : //component extension - show component search buttons if the commands
433 : // vnd.sun.star::SearchViaComponent1 and 2 are supported
434 0 : const uno::Reference< frame::XFrame >xFrame = rBindings.GetActiveFrame();
435 0 : const uno::Reference< frame::XDispatchProvider > xDispatchProv(xFrame, uno::UNO_QUERY);
436 0 : rtl::OUString sTarget("_self");
437 :
438 0 : bool bSearchComponent1 = false;
439 0 : bool bSearchComponent2 = false;
440 0 : if(xDispatchProv.is() &&
441 0 : (pImpl->xCommand1Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand1URL, sTarget, 0)).is())
442 : {
443 0 : bSearchComponent1 = true;
444 : }
445 0 : if(xDispatchProv.is() &&
446 0 : (pImpl->xCommand2Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand2URL, sTarget, 0)).is())
447 : {
448 0 : bSearchComponent2 = true;
449 : }
450 :
451 0 : if( bSearchComponent1 || bSearchComponent2 )
452 : {
453 : try
454 : {
455 0 : uno::Reference< lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
456 : uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
457 0 : configuration::theDefaultProvider::get( comphelper::getComponentContext(xMgr) );
458 0 : uno::Sequence< uno::Any > aArgs(1);
459 0 : ::rtl::OUString sPath( "/org.openoffice.Office.Common/SearchOptions/");
460 0 : aArgs[0] <<= sPath;
461 :
462 0 : uno::Reference< uno::XInterface > xIFace = xConfigurationProvider->createInstanceWithArguments(
463 : ::rtl::OUString( "com.sun.star.configuration.ConfigurationUpdateAccess"),
464 0 : aArgs);
465 0 : uno::Reference< container::XNameAccess> xDirectAccess(xIFace, uno::UNO_QUERY);
466 0 : if(xDirectAccess.is())
467 : {
468 0 : ::rtl::OUString sTemp;
469 0 : ::rtl::OUString sProperty( "ComponentSearchGroupLabel");
470 0 : uno::Any aRet = xDirectAccess->getByName(sProperty);
471 0 : aRet >>= sTemp;
472 0 : aSearchComponentFL.SetText( sTemp );
473 0 : aRet = xDirectAccess->getByName(::rtl::OUString( "ComponentSearchCommandLabel1"));
474 0 : aRet >>= sTemp;
475 0 : aSearchComponent1PB.SetText( sTemp );
476 0 : aRet = xDirectAccess->getByName(::rtl::OUString( "ComponentSearchCommandLabel2"));
477 0 : aRet >>= sTemp;
478 0 : aSearchComponent2PB.SetText( sTemp );
479 0 : }
480 : }
481 0 : catch(uno::Exception&){}
482 :
483 0 : if(aSearchComponent1PB.GetText().Len() && bSearchComponent1 )
484 : {
485 0 : aSearchComponentFL.Show();
486 0 : aSearchComponent1PB.Show();
487 : }
488 0 : if( aSearchComponent2PB.GetText().Len() )
489 : {
490 0 : if(!aSearchComponent1PB.IsVisible())
491 : {
492 0 : aSearchComponent2PB.SetPosPixel(aSearchComponent1PB.GetPosPixel());
493 : }
494 0 : aSearchComponentFL.Show();
495 0 : aSearchComponent2PB.Show();
496 : }
497 0 : if( aSearchComponentFL.IsVisible() && aSearchComponent1PB.IsVisible() )
498 : {
499 :
500 : //dialog must be resized
501 0 : Size aDlgSize(GetSizePixel());
502 0 : sal_Int32 nOffset = aSearchCmdLine.GetPosPixel().Y() - aSearchAllBtn.GetPosPixel().Y()
503 0 : - aButtonsFL.GetPosPixel().Y() + aSearchComponent2PB.GetPosPixel().Y();
504 :
505 0 : aDlgSize.Height() += nOffset;
506 : Window* aWindows[] =
507 : {
508 : &aOptionsFL,
509 : &aSelectionBtn,
510 : &aBackwardsBtn,
511 : &aRegExpBtn,
512 : &aSimilarityBox,
513 : &aSimilarityBtn,
514 : &aLayoutBtn,
515 : &aNotesBtn,
516 : &aJapMatchFullHalfWidthCB,
517 : &aJapOptionsCB,
518 : &aJapOptionsBtn,
519 : &aAttributeBtn,
520 : &aFormatBtn,
521 : &aNoFormatBtn,
522 : &aCalcFL,
523 : &aCalcSearchInFT,
524 : &aCalcSearchInLB,
525 : &aCalcSearchDirFT,
526 : &aRowsBtn,
527 : &aColumnsBtn,
528 : &aAllSheetsCB,
529 : &aButtonsFL,
530 : &aHelpBtn,
531 : &aCloseBtn,
532 : pMoreBtn,
533 : 0
534 0 : };
535 0 : sal_Int32 nWindow = 0;
536 0 : do
537 : {
538 0 : lcl_MoveDown( *aWindows[nWindow], nOffset );
539 : }
540 0 : while(aWindows[++nWindow]);
541 :
542 0 : SetSizePixel(aDlgSize);
543 : }
544 0 : }
545 0 : }
546 :
547 : // -----------------------------------------------------------------------
548 :
549 0 : sal_Bool SvxSearchDialog::Close()
550 : {
551 : // remember strings speichern
552 0 : if (!aSearchStrings.empty())
553 0 : StrArrToList_Impl( SID_SEARCHDLG_SEARCHSTRINGS, aSearchStrings );
554 :
555 0 : if (!aReplaceStrings.empty())
556 0 : StrArrToList_Impl( SID_SEARCHDLG_REPLACESTRINGS, aReplaceStrings );
557 :
558 : // save settings to configuration
559 0 : SvtSearchOptions aOpt;
560 0 : aOpt.SetWholeWordsOnly ( aWordBtn .IsChecked() );
561 0 : aOpt.SetBackwards ( aBackwardsBtn .IsChecked() );
562 0 : aOpt.SetUseRegularExpression ( aRegExpBtn .IsChecked() );
563 0 : aOpt.SetSearchForStyles ( aLayoutBtn .IsChecked() );
564 0 : aOpt.SetSimilaritySearch ( aSimilarityBox .IsChecked() );
565 0 : aOpt.SetUseAsianOptions ( aJapOptionsCB .IsChecked() );
566 0 : aOpt.SetNotes ( aNotesBtn .IsChecked() );
567 :
568 0 : const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
569 0 : rBindings.GetDispatcher()->Execute( FID_SEARCH_OFF, SFX_CALLMODE_SLOT, ppArgs );
570 0 : rBindings.Execute( SID_SEARCH_DLG );
571 :
572 0 : return sal_True;
573 : }
574 :
575 : // -----------------------------------------------------------------------
576 :
577 0 : sal_Int32 SvxSearchDialog::GetTransliterationFlags() const
578 : {
579 0 : if (!aMatchCaseCB.IsChecked())
580 0 : nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
581 : else
582 0 : nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
583 0 : if ( !aJapMatchFullHalfWidthCB.IsChecked())
584 0 : nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
585 : else
586 0 : nTransliterationFlags &= ~TransliterationModules_IGNORE_WIDTH;
587 0 : return nTransliterationFlags;
588 : }
589 :
590 0 : void SvxSearchDialog::SetSaveToModule(bool b)
591 : {
592 0 : pImpl->bSaveToModule = b;
593 0 : }
594 :
595 : // -----------------------------------------------------------------------
596 :
597 0 : void SvxSearchDialog::ApplyTransliterationFlags_Impl( sal_Int32 nSettings )
598 : {
599 0 : nTransliterationFlags = nSettings;
600 0 : sal_Bool bVal = 0 != (nSettings & TransliterationModules_IGNORE_CASE);
601 0 : aMatchCaseCB .Check(!bVal );
602 0 : bVal = 0 != (nSettings & TransliterationModules_IGNORE_WIDTH);
603 0 : aJapMatchFullHalfWidthCB.Check( !bVal );
604 0 : }
605 :
606 : // -----------------------------------------------------------------------
607 :
608 0 : void SvxSearchDialog::Activate()
609 : {
610 : // apply possible transliteration changes of the SvxSearchItem member
611 : DBG_ASSERT( pSearchItem, "SearchItem missing" );
612 0 : if (pSearchItem)
613 : {
614 0 : aMatchCaseCB .Check( pSearchItem->GetExact() );
615 0 : aJapMatchFullHalfWidthCB.Check( !pSearchItem->IsMatchFullHalfWidthForms() );
616 : }
617 0 : }
618 :
619 : // -----------------------------------------------------------------------
620 :
621 0 : void SvxSearchDialog::InitControls_Impl()
622 : {
623 : // CaseSensitives AutoComplete
624 0 : aSearchLB.EnableAutocomplete( sal_True, sal_True );
625 0 : aSearchLB.Show();
626 0 : aReplaceLB.EnableAutocomplete( sal_True, sal_True );
627 0 : aReplaceLB.Show();
628 :
629 0 : aFormatBtn.Disable();
630 0 : aAttributeBtn.Disable();
631 :
632 0 : aSearchLB.SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
633 0 : aReplaceLB.SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
634 :
635 0 : Link aLink = LINK( this, SvxSearchDialog, FocusHdl_Impl );
636 0 : aSearchLB.SetGetFocusHdl( aLink );
637 0 : pImpl->aSearchFormats.SetGetFocusHdl( aLink );
638 :
639 0 : aReplaceLB.SetGetFocusHdl( aLink );
640 0 : pImpl->aReplaceFormats.SetGetFocusHdl( aLink );
641 :
642 0 : aLink = LINK( this, SvxSearchDialog, LoseFocusHdl_Impl );
643 0 : aSearchLB.SetLoseFocusHdl( aLink );
644 0 : aReplaceLB.SetLoseFocusHdl( aLink );
645 :
646 0 : aSearchTmplLB.SetLoseFocusHdl( aLink );
647 0 : aReplaceTmplLB.SetLoseFocusHdl( aLink );
648 :
649 0 : aLink = LINK( this, SvxSearchDialog, CommandHdl_Impl );
650 0 : aSearchBtn.SetClickHdl( aLink );
651 0 : aSearchAllBtn.SetClickHdl( aLink );
652 0 : aReplaceBtn.SetClickHdl( aLink );
653 0 : aReplaceAllBtn.SetClickHdl( aLink );
654 0 : aCloseBtn.SetClickHdl( aLink );
655 0 : aSimilarityBtn.SetClickHdl( aLink );
656 0 : aJapOptionsBtn.SetClickHdl( aLink );
657 0 : aSearchComponent1PB.SetClickHdl( aLink );
658 0 : aSearchComponent2PB.SetClickHdl( aLink );
659 :
660 0 : aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
661 0 : aWordBtn.SetClickHdl( aLink );
662 0 : aSelectionBtn.SetClickHdl( aLink );
663 0 : aMatchCaseCB.SetClickHdl( aLink );
664 0 : aRegExpBtn.SetClickHdl( aLink );
665 0 : aBackwardsBtn.SetClickHdl( aLink );
666 0 : aNotesBtn.SetClickHdl( aLink );
667 0 : aSimilarityBox.SetClickHdl( aLink );
668 0 : aJapOptionsCB.SetClickHdl( aLink );
669 0 : aJapMatchFullHalfWidthCB.SetClickHdl( aLink );
670 :
671 0 : aLayoutBtn.SetClickHdl( LINK( this, SvxSearchDialog, TemplateHdl_Impl ) );
672 0 : aFormatBtn.SetClickHdl( LINK( this, SvxSearchDialog, FormatHdl_Impl ) );
673 : aNoFormatBtn.SetClickHdl(
674 0 : LINK( this, SvxSearchDialog, NoFormatHdl_Impl ) );
675 : aAttributeBtn.SetClickHdl(
676 0 : LINK( this, SvxSearchDialog, AttributeHdl_Impl ) );
677 :
678 : // check if buttontext is to wide
679 : long nTxtW = Max( pMoreBtn->GetCtrlTextWidth( pMoreBtn->GetMoreText() ),
680 0 : pMoreBtn->GetCtrlTextWidth( pMoreBtn->GetLessText() ) );
681 0 : nTxtW += ( pMoreBtn->GetTextHeight() * 2 ); // add image size + offset
682 0 : long nBtnW = pMoreBtn->GetSizePixel().Width();
683 0 : if ( nTxtW > nBtnW )
684 : {
685 : // broaden the button
686 0 : const long nMinDelta = 10;
687 0 : long nDelta = Max( nTxtW - nBtnW, nMinDelta );
688 0 : Size aNewSize = pMoreBtn->GetSizePixel();
689 0 : aNewSize.Width() += nDelta;
690 0 : pMoreBtn->SetSizePixel( aNewSize );
691 : }
692 0 : }
693 :
694 : // -----------------------------------------------------------------------
695 :
696 0 : void SvxSearchDialog::CalculateDelta_Impl()
697 : {
698 : DBG_ASSERT( pSearchItem, "no search item" );
699 :
700 0 : bool bDrawApp = false;
701 0 : bool bCalcApp = false;
702 0 : bool bWriterApp = false;
703 0 : bool bImpressApp = false;
704 0 : const uno::Reference< frame::XFrame > xFrame = rBindings.GetActiveFrame();
705 0 : uno::Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(::comphelper::getProcessComponentContext()) );
706 : try
707 : {
708 0 : ::rtl::OUString aModuleIdentifier = xModuleManager->identify( xFrame );
709 0 : bCalcApp = aModuleIdentifier == "com.sun.star.sheet.SpreadsheetDocument";
710 0 : bDrawApp = aModuleIdentifier == "com.sun.star.drawing.DrawingDocument";
711 0 : bImpressApp = aModuleIdentifier == "com.sun.star.presentation.PresentationDocument";
712 0 : bWriterApp = aModuleIdentifier == "com.sun.star.text.TextDocument";
713 : }
714 0 : catch ( uno::Exception& )
715 : {
716 : }
717 :
718 0 : if ( pImpl->bDeltaCalculated )
719 0 : return;
720 : else
721 0 : pImpl->bDeltaCalculated = sal_True;
722 :
723 0 : sal_uIntPtr nDelta = 187, nOffset = 0;
724 0 : SvtCJKOptions aCJKOptions;
725 :
726 0 : pMoreBtn->AddWindow( &aOptionsFL );
727 0 : if ( !bDrawApp )
728 0 : pMoreBtn->AddWindow( &aLayoutBtn );
729 0 : if ( bWriterApp )
730 0 : pMoreBtn->AddWindow( &aNotesBtn );
731 : else
732 : {
733 0 : aNotesBtn.Hide();
734 0 : nOffset = !bDrawApp ? 13 : 0;
735 : }
736 0 : pMoreBtn->AddWindow( &aBackwardsBtn );
737 0 : if ( !bDrawApp )
738 0 : pMoreBtn->AddWindow( &aRegExpBtn );
739 0 : pMoreBtn->AddWindow( &aSimilarityBox );
740 0 : pMoreBtn->AddWindow( &aSimilarityBtn );
741 0 : pMoreBtn->AddWindow( &aSelectionBtn );
742 :
743 0 : if ( aCJKOptions.IsCJKFontEnabled() )
744 0 : pMoreBtn->AddWindow( &aJapMatchFullHalfWidthCB );
745 : else
746 0 : nOffset += 13;
747 0 : if ( aCJKOptions.IsJapaneseFindEnabled() )
748 : {
749 0 : pMoreBtn->AddWindow( &aJapOptionsCB );
750 0 : pMoreBtn->AddWindow( &aJapOptionsBtn );
751 : }
752 : else
753 0 : nOffset += 17;
754 :
755 0 : if ( bWriter )
756 : {
757 0 : pMoreBtn->AddWindow( &aAttributeBtn );
758 0 : pMoreBtn->AddWindow( &aFormatBtn );
759 0 : pMoreBtn->AddWindow( &aNoFormatBtn );
760 : }
761 :
762 0 : if (bDrawApp || bImpressApp)
763 : {
764 : // "Find All" button is hidden--align "Find" vertically to the
765 : // search listbox
766 0 : Point aNewPt(aSearchBtn.GetPosPixel());
767 0 : const Size aBtnSz(aSearchBtn.GetSizePixel());
768 0 : const Size aLBSz(aSearchLB.GetSizePixel());
769 0 : const int nOff((aLBSz.Height() - aBtnSz.Height()) / 2);
770 0 : aNewPt.Y() = aSearchLB.GetPosPixel().Y() + nOff;
771 0 : aSearchBtn.SetPosPixel(aNewPt);
772 : }
773 :
774 0 : if ( bDrawApp )
775 : {
776 : // Draw App: "Regular expressions" and "Search for Styles" check boxes are hidden
777 : // so align the other buttons
778 0 : const long nAppFontHeight = 13; // checkbox height + space between in APPFONT
779 0 : long nH = LogicToPixel( Size( 0, nAppFontHeight ), MAP_APPFONT ).Height();
780 :
781 0 : Point aNewPos = aSimilarityBox.GetPosPixel();
782 0 : aNewPos.Y() -= nH;
783 0 : aSimilarityBox.SetPosPixel( aNewPos );
784 0 : aNewPos = aSimilarityBtn.GetPosPixel();
785 0 : aNewPos.Y() -= nH;
786 0 : aSimilarityBtn.SetPosPixel( aNewPos );
787 0 : nH *= 3;
788 0 : nOffset += ( 3 * nAppFontHeight );
789 0 : if ( aCJKOptions.IsCJKFontEnabled() )
790 : {
791 0 : aNewPos = aJapMatchFullHalfWidthCB.GetPosPixel();
792 0 : aNewPos.Y() -= nH;
793 0 : aJapMatchFullHalfWidthCB.SetPosPixel( aNewPos );
794 : }
795 0 : if ( aCJKOptions.IsJapaneseFindEnabled() )
796 : {
797 0 : aNewPos = aJapOptionsCB.GetPosPixel();
798 0 : aNewPos.Y() -= nH;
799 0 : aJapOptionsCB.SetPosPixel( aNewPos );
800 0 : aNewPos = aJapOptionsBtn.GetPosPixel();
801 0 : aNewPos.Y() -= nH;
802 0 : aJapOptionsBtn.SetPosPixel( aNewPos );
803 : }
804 : }
805 :
806 0 : if ( bCalcApp || bImpressApp )
807 : {
808 : Window* pWins[] =
809 : {
810 : &aCalcFL, &aCalcSearchInFT, &aCalcSearchInLB, &aCalcSearchDirFT,
811 : &aRowsBtn, &aColumnsBtn, &aAllSheetsCB, &aJapMatchFullHalfWidthCB,
812 : &aJapOptionsCB, &aJapOptionsBtn
813 0 : };
814 0 : Window** pCurrent = pWins;
815 0 : sal_uInt32 i = 0;
816 0 : const sal_uInt32 nCalcCtrlCount = 7;
817 0 : if ( nOffset > 0 )
818 : {
819 0 : long nH = LogicToPixel( Size( 0, nOffset ), MAP_APPFONT ).Height();
820 0 : for ( i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
821 : {
822 0 : if ( ( bCalcApp && i < nCalcCtrlCount )
823 0 : || ( i == nCalcCtrlCount && aCJKOptions.IsCJKFontEnabled() )
824 0 : || ( i > nCalcCtrlCount && aCJKOptions.IsJapaneseFindEnabled() ) )
825 : {
826 0 : Point aNewPos = (*pCurrent)->GetPosPixel();
827 0 : aNewPos.Y() -= nH;
828 0 : (*pCurrent)->SetPosPixel( aNewPos );
829 : }
830 : }
831 : }
832 :
833 0 : if ( bCalcApp)
834 : {
835 0 : pCurrent = pWins;
836 0 : for ( i = 0; i < nCalcCtrlCount; ++i, ++pCurrent )
837 0 : pMoreBtn->AddWindow( *pCurrent );
838 : }
839 : else
840 0 : nOffset += 64;
841 : }
842 : else
843 0 : nOffset += 64;
844 :
845 0 : pMoreBtn->SetDelta( nDelta - nOffset );
846 0 : pMoreBtn->Show();
847 0 : pMoreBtn->Enable();
848 : }
849 :
850 : // -----------------------------------------------------------------------
851 :
852 : namespace {
853 :
854 : class ToggleSaveToModule
855 : {
856 : public:
857 0 : ToggleSaveToModule(SvxSearchDialog& rDialog, bool bValue) :
858 0 : mrDialog(rDialog), mbValue(bValue)
859 : {
860 0 : mrDialog.SetSaveToModule(mbValue);
861 0 : }
862 :
863 0 : ~ToggleSaveToModule()
864 : {
865 0 : mrDialog.SetSaveToModule(!mbValue);
866 0 : }
867 : private:
868 : SvxSearchDialog& mrDialog;
869 : bool mbValue;
870 : };
871 :
872 : }
873 :
874 0 : void SvxSearchDialog::Init_Impl( int bSearchPattern )
875 : {
876 : DBG_ASSERT( pSearchItem, "SearchItem == 0" );
877 :
878 : // We don't want to save any intermediate state to the module while the
879 : // dialog is being initialized.
880 0 : ToggleSaveToModule aNoModuleSave(*this, false);
881 :
882 0 : bWriter = ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_WRITER );
883 :
884 0 : pImpl->bMultiLineEdit = sal_False;
885 :
886 0 : if ( !pImpl->bMultiLineEdit )
887 : {
888 0 : pImpl->aSearchFormats.Hide();
889 0 : aSearchAttrText.Show();
890 0 : pImpl->aReplaceFormats.Hide();
891 0 : aReplaceAttrText.Show();
892 : }
893 : else
894 : {
895 0 : String aText = aSearchAttrText.GetText();
896 0 : aSearchAttrText.Hide();
897 :
898 0 : if ( aText.Len() )
899 0 : pImpl->aSearchFormats.SetText( aText );
900 0 : pImpl->aSearchFormats.Show();
901 0 : aText = aReplaceAttrText.GetText();
902 0 : aReplaceAttrText.Hide();
903 :
904 0 : if ( aText.Len() )
905 0 : pImpl->aReplaceFormats.SetText( aText );
906 0 : pImpl->aReplaceFormats.Show();
907 : }
908 :
909 0 : if ( ( nModifyFlag & MODIFY_WORD ) == 0 )
910 0 : aWordBtn.Check( pSearchItem->GetWordOnly() );
911 0 : if ( ( nModifyFlag & MODIFY_EXACT ) == 0 )
912 0 : aMatchCaseCB.Check( pSearchItem->GetExact() );
913 0 : if ( ( nModifyFlag & MODIFY_BACKWARDS ) == 0 )
914 0 : aBackwardsBtn.Check( pSearchItem->GetBackward() );
915 0 : if ( ( nModifyFlag & MODIFY_NOTES ) == 0 )
916 0 : aNotesBtn.Check( pSearchItem->GetNotes() );
917 0 : if ( ( nModifyFlag & MODIFY_SELECTION ) == 0 )
918 0 : aSelectionBtn.Check( pSearchItem->GetSelection() );
919 0 : if ( ( nModifyFlag & MODIFY_REGEXP ) == 0 )
920 0 : aRegExpBtn.Check( pSearchItem->GetRegExp() );
921 0 : if ( ( nModifyFlag & MODIFY_LAYOUT ) == 0 )
922 0 : aLayoutBtn.Check( pSearchItem->GetPattern() );
923 0 : if (aNotesBtn.IsChecked())
924 0 : aLayoutBtn.Disable();
925 0 : aSimilarityBox.Check( pSearchItem->IsLevenshtein() );
926 0 : if( aJapOptionsCB.IsVisible() )
927 0 : aJapOptionsCB.Check( pSearchItem->IsUseAsianOptions() );
928 0 : ApplyTransliterationFlags_Impl( pSearchItem->GetTransliterationFlags() );
929 :
930 0 : CalculateDelta_Impl();
931 :
932 0 : bool bDraw = false;
933 0 : if ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_CALC )
934 : {
935 0 : Link aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
936 0 : aCalcSearchInLB.SetSelectHdl( aLink );
937 0 : aRowsBtn.SetClickHdl( aLink );
938 0 : aColumnsBtn.SetClickHdl( aLink );
939 0 : aAllSheetsCB.SetClickHdl( aLink );
940 :
941 0 : switch ( pSearchItem->GetCellType() )
942 : {
943 : case SVX_SEARCHIN_FORMULA:
944 0 : if ( ( nModifyFlag & MODIFY_FORMULAS ) == 0 )
945 0 : aCalcSearchInLB.SelectEntryPos( SVX_SEARCHIN_FORMULA );
946 0 : break;
947 :
948 : case SVX_SEARCHIN_VALUE:
949 0 : if ( ( nModifyFlag & MODIFY_VALUES ) == 0 )
950 0 : aCalcSearchInLB.SelectEntryPos( SVX_SEARCHIN_VALUE );
951 0 : break;
952 :
953 : case SVX_SEARCHIN_NOTE:
954 0 : if ( ( nModifyFlag & MODIFY_CALC_NOTES ) == 0 )
955 0 : aCalcSearchInLB.SelectEntryPos( SVX_SEARCHIN_NOTE );
956 0 : break;
957 : }
958 0 : aWordBtn.SetText( aCalcStr.GetToken( 0, '#' ) );
959 :
960 0 : if ( pSearchItem->GetRowDirection() &&
961 : ( nModifyFlag & MODIFY_ROWS ) == 0 )
962 0 : aRowsBtn.Check();
963 0 : else if ( !pSearchItem->GetRowDirection() &&
964 : ( nModifyFlag & MODIFY_COLUMNS ) == 0 )
965 0 : aColumnsBtn.Check();
966 :
967 0 : if ( ( nModifyFlag & MODIFY_ALLTABLES ) == 0 )
968 0 : aAllSheetsCB.Check( pSearchItem->IsAllTables() );
969 :
970 : // only look for formatting in Writer
971 0 : aFormatBtn.Hide();
972 0 : aNoFormatBtn.Hide();
973 0 : aAttributeBtn.Hide();
974 : }
975 : else
976 : {
977 0 : aWordBtn.SetText( aCalcStr.GetToken( 1, '#' ) );
978 :
979 0 : if ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_DRAW )
980 : {
981 0 : aSearchAllBtn.Hide();
982 :
983 0 : aRegExpBtn.Hide();
984 0 : aLayoutBtn.Hide();
985 :
986 : // only look for formatting in Writer
987 0 : aFormatBtn.Hide();
988 0 : aNoFormatBtn.Hide();
989 0 : aAttributeBtn.Hide();
990 0 : bDraw = sal_True;
991 : }
992 : else
993 : {
994 0 : if ( !pSearchList )
995 : {
996 : // Get attribute sets, if it not has been done already
997 0 : const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
998 : const SvxSetItem* pSrchSetItem =
999 0 : (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SFX_CALLMODE_SLOT, ppArgs );
1000 :
1001 0 : if ( pSrchSetItem )
1002 0 : InitAttrList_Impl( &pSrchSetItem->GetItemSet(), 0 );
1003 :
1004 : const SvxSetItem* pReplSetItem =
1005 0 : (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SFX_CALLMODE_SLOT, ppArgs );
1006 :
1007 0 : if ( pReplSetItem )
1008 0 : InitAttrList_Impl( 0, &pReplSetItem->GetItemSet() );
1009 : }
1010 : }
1011 : }
1012 :
1013 : if ( 0 && !bDraw ) //!!!!!
1014 : {
1015 : aRegExpBtn.Show();
1016 : aLayoutBtn.Show();
1017 : }
1018 :
1019 : // similarity search?
1020 0 : if ( ( nModifyFlag & MODIFY_SIMILARITY ) == 0 )
1021 0 : aSimilarityBox.Check( pSearchItem->IsLevenshtein() );
1022 0 : bSet = sal_True;
1023 :
1024 0 : FlagHdl_Impl( &aSimilarityBox );
1025 0 : FlagHdl_Impl( &aJapOptionsCB );
1026 :
1027 0 : bool bDisableSearch = false;
1028 0 : SfxViewShell* pViewShell = SfxViewShell::Current();
1029 :
1030 0 : if ( pViewShell )
1031 : {
1032 0 : sal_Bool bText = !bSearchPattern;
1033 :
1034 0 : if ( pViewShell->HasSelection( bText ) )
1035 0 : EnableControl_Impl( &aSelectionBtn );
1036 : else
1037 : {
1038 0 : aSelectionBtn.Check( sal_False );
1039 0 : aSelectionBtn.Disable();
1040 : }
1041 : }
1042 :
1043 : // Pattern Search and there were no AttrSets given
1044 0 : if ( bSearchPattern )
1045 : {
1046 0 : SfxObjectShell* pShell = SfxObjectShell::Current();
1047 :
1048 0 : if ( pShell && pShell->GetStyleSheetPool() )
1049 : {
1050 : // Templates designed
1051 0 : aSearchTmplLB .Clear();
1052 0 : aReplaceTmplLB.Clear();
1053 0 : SfxStyleSheetBasePool* pStylePool = pShell->GetStyleSheetPool();
1054 : pStylePool->SetSearchMask( pSearchItem->GetFamily(),
1055 0 : SFXSTYLEBIT_ALL );
1056 0 : SfxStyleSheetBase* pBase = pStylePool->First();
1057 :
1058 0 : while ( pBase )
1059 : {
1060 0 : if ( pBase->IsUsed() )
1061 0 : aSearchTmplLB.InsertEntry( pBase->GetName() );
1062 0 : aReplaceTmplLB.InsertEntry( pBase->GetName() );
1063 0 : pBase = pStylePool->Next();
1064 : }
1065 0 : aSearchTmplLB.SelectEntry( pSearchItem->GetSearchString() );
1066 0 : aReplaceTmplLB.SelectEntry( pSearchItem->GetReplaceString() );
1067 :
1068 : }
1069 0 : aSearchTmplLB.Show();
1070 :
1071 0 : if ( bConstruct )
1072 : // Grab focus only after creating
1073 0 : aSearchTmplLB.GrabFocus();
1074 0 : aReplaceTmplLB.Show();
1075 0 : aSearchLB.Hide();
1076 0 : aReplaceLB.Hide();
1077 :
1078 0 : aWordBtn.Disable();
1079 0 : aRegExpBtn.Disable();
1080 0 : aMatchCaseCB.Disable();
1081 :
1082 0 : bDisableSearch = !aSearchTmplLB.GetEntryCount();
1083 : }
1084 : else
1085 : {
1086 0 : bool bSetSearch = ( ( nModifyFlag & MODIFY_SEARCH ) == 0 );
1087 0 : bool bSetReplace = ( ( nModifyFlag & MODIFY_REPLACE ) == 0 );
1088 :
1089 0 : if ( pSearchItem->GetSearchString().Len() && bSetSearch )
1090 0 : aSearchLB.SetText( pSearchItem->GetSearchString() );
1091 0 : else if (!aSearchStrings.empty())
1092 : {
1093 : bool bAttributes =
1094 0 : ( ( pSearchList && pSearchList->Count() ) ||
1095 0 : ( pReplaceList && pReplaceList->Count() ) );
1096 :
1097 0 : if ( bSetSearch && !bAttributes )
1098 0 : aSearchLB.SetText(aSearchStrings[0]);
1099 :
1100 0 : String aReplaceTxt = pSearchItem->GetReplaceString();
1101 :
1102 0 : if (!aReplaceStrings.empty())
1103 0 : aReplaceTxt = aReplaceStrings[0];
1104 :
1105 0 : if ( bSetReplace && !bAttributes )
1106 0 : aReplaceLB.SetText( aReplaceTxt );
1107 : }
1108 0 : aSearchLB.Show();
1109 :
1110 0 : if ( bConstruct )
1111 : // Grab focus only after creating
1112 0 : aSearchLB.GrabFocus();
1113 0 : aReplaceLB.Show();
1114 0 : aSearchTmplLB.Hide();
1115 0 : aReplaceTmplLB.Hide();
1116 :
1117 0 : EnableControl_Impl( &aRegExpBtn );
1118 0 : EnableControl_Impl( &aMatchCaseCB );
1119 :
1120 0 : if ( aRegExpBtn.IsChecked() )
1121 0 : aWordBtn.Disable();
1122 : else
1123 0 : EnableControl_Impl( &aWordBtn );
1124 :
1125 0 : String aSrchAttrTxt;
1126 :
1127 0 : if ( pImpl->bMultiLineEdit )
1128 0 : aSrchAttrTxt = pImpl->aSearchFormats.GetText();
1129 : else
1130 0 : aSrchAttrTxt = aSearchAttrText.GetText();
1131 :
1132 0 : bDisableSearch = !aSearchLB.GetText().Len() && !aSrchAttrTxt.Len();
1133 : }
1134 0 : FocusHdl_Impl( &aSearchLB );
1135 :
1136 0 : if ( bDisableSearch )
1137 : {
1138 0 : aSearchBtn.Disable();
1139 0 : aSearchAllBtn.Disable();
1140 0 : aReplaceBtn.Disable();
1141 0 : aReplaceAllBtn.Disable();
1142 0 : aSearchComponentFL.Enable(sal_False);
1143 0 : aSearchComponent1PB.Enable(sal_False);
1144 0 : aSearchComponent2PB.Enable(sal_False);
1145 : }
1146 : else
1147 : {
1148 0 : EnableControl_Impl( &aSearchBtn );
1149 0 : EnableControl_Impl( &aReplaceBtn );
1150 0 : if (!bWriter || (bWriter && !aNotesBtn.IsChecked()))
1151 : {
1152 0 : EnableControl_Impl( &aSearchAllBtn );
1153 0 : EnableControl_Impl( &aReplaceAllBtn );
1154 : }
1155 0 : if (bWriter && pSearchItem->GetNotes())
1156 : {
1157 0 : aSearchAllBtn.Disable();
1158 0 : aReplaceAllBtn.Disable();
1159 : }
1160 : }
1161 :
1162 0 : if ( ( !pImpl->bMultiLineEdit && aSearchAttrText.GetText().Len() ) ||
1163 0 : ( pImpl->bMultiLineEdit && pImpl->aSearchFormats.GetText().Len() ) )
1164 0 : EnableControl_Impl( &aNoFormatBtn );
1165 : else
1166 0 : aNoFormatBtn.Disable();
1167 :
1168 0 : if ( !pSearchList )
1169 : {
1170 0 : aAttributeBtn.Disable();
1171 0 : aFormatBtn.Disable();
1172 : }
1173 :
1174 0 : if ( aLayoutBtn.IsChecked() )
1175 : {
1176 0 : pImpl->bSaveToModule = sal_False;
1177 0 : TemplateHdl_Impl( &aLayoutBtn );
1178 0 : pImpl->bSaveToModule = sal_True;
1179 0 : }
1180 0 : }
1181 :
1182 : // -----------------------------------------------------------------------
1183 :
1184 0 : void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
1185 : const SfxItemSet* pRSet )
1186 : {
1187 0 : if ( !pSSet && !pRSet )
1188 0 : return;
1189 :
1190 0 : if ( !pImpl->pRanges && pSSet )
1191 : {
1192 0 : sal_sSize nCnt = 0;
1193 0 : const sal_uInt16* pPtr = pSSet->GetRanges();
1194 0 : const sal_uInt16* pTmp = pPtr;
1195 :
1196 0 : while( *pPtr )
1197 : {
1198 0 : nCnt += ( *(pPtr+1) - *pPtr ) + 1;
1199 0 : pPtr += 2;
1200 : }
1201 0 : nCnt = pPtr - pTmp + 1;
1202 0 : pImpl->pRanges = new sal_uInt16[nCnt];
1203 0 : memcpy( pImpl->pRanges, pTmp, sizeof(sal_uInt16) * nCnt );
1204 : }
1205 :
1206 : // See to it that are the texts of the attributes are correct
1207 0 : String aDesc;
1208 :
1209 0 : if ( pSSet )
1210 : {
1211 0 : delete pSearchList;
1212 0 : pSearchList = new SearchAttrItemList;
1213 :
1214 0 : if ( pSSet->Count() )
1215 : {
1216 0 : pSearchList->Put( *pSSet );
1217 :
1218 0 : if ( !pImpl->bMultiLineEdit )
1219 0 : aSearchAttrText.SetText( BuildAttrText_Impl( aDesc, sal_True ) );
1220 : else
1221 0 : pImpl->aSearchFormats.SetText( BuildAttrText_Impl( aDesc, sal_True ) );
1222 :
1223 0 : if ( aDesc.Len() )
1224 0 : bFormat |= sal_True;
1225 : }
1226 : }
1227 :
1228 0 : if ( pRSet )
1229 : {
1230 0 : delete pReplaceList;
1231 0 : pReplaceList = new SearchAttrItemList;
1232 :
1233 0 : if ( pRSet->Count() )
1234 : {
1235 0 : pReplaceList->Put( *pRSet );
1236 :
1237 0 : if ( !pImpl->bMultiLineEdit )
1238 0 : aReplaceAttrText.SetText( BuildAttrText_Impl( aDesc, sal_False ) );
1239 : else
1240 0 : pImpl->aReplaceFormats.SetText( BuildAttrText_Impl( aDesc, sal_False ) );
1241 :
1242 0 : if ( aDesc.Len() )
1243 0 : bFormat |= sal_True;
1244 : }
1245 0 : }
1246 : }
1247 :
1248 : // -----------------------------------------------------------------------
1249 :
1250 0 : IMPL_LINK( SvxSearchDialog, FlagHdl_Impl, Control *, pCtrl )
1251 : {
1252 0 : if ( pCtrl && !bSet )
1253 0 : SetModifyFlag_Impl( pCtrl );
1254 : else
1255 0 : bSet = sal_False;
1256 :
1257 0 : if ( pCtrl == &aSimilarityBox )
1258 : {
1259 0 : sal_Bool bIsChecked = aSimilarityBox.IsChecked();
1260 :
1261 0 : if ( bIsChecked )
1262 : {
1263 0 : aSimilarityBtn.Enable();
1264 0 : aRegExpBtn.Check( sal_False );
1265 0 : aRegExpBtn.Disable();
1266 0 : EnableControl_Impl( &aWordBtn );
1267 :
1268 0 : if ( aLayoutBtn.IsChecked() )
1269 : {
1270 0 : EnableControl_Impl( &aMatchCaseCB );
1271 0 : aLayoutBtn.Check( sal_False );
1272 : }
1273 0 : aRegExpBtn.Disable();
1274 0 : aLayoutBtn.Disable();
1275 0 : aFormatBtn.Disable();
1276 0 : aNoFormatBtn.Disable();
1277 0 : aAttributeBtn.Disable();
1278 : }
1279 : else
1280 : {
1281 0 : EnableControl_Impl( &aRegExpBtn );
1282 0 : if (!aNotesBtn.IsChecked())
1283 0 : EnableControl_Impl( &aLayoutBtn );
1284 0 : EnableControl_Impl( &aFormatBtn );
1285 0 : EnableControl_Impl( &aAttributeBtn );
1286 0 : aSimilarityBtn.Disable();
1287 : }
1288 0 : pSearchItem->SetLevenshtein( bIsChecked );
1289 : }
1290 : else
1291 0 : if ( pCtrl == &aNotesBtn)
1292 : {
1293 0 : if (aNotesBtn.IsChecked())
1294 : {
1295 0 : aLayoutBtn.Disable();
1296 0 : aSearchAllBtn.Disable();
1297 0 : aReplaceAllBtn.Disable();
1298 : }
1299 : else
1300 : {
1301 0 : EnableControl_Impl( &aLayoutBtn );
1302 0 : ModifyHdl_Impl( &aSearchLB );
1303 : }
1304 : }
1305 : else
1306 : {
1307 0 : if ( aLayoutBtn.IsChecked() && !bFormat )
1308 : {
1309 0 : aWordBtn.Check( sal_False );
1310 0 : aWordBtn.Disable();
1311 0 : aRegExpBtn.Check( sal_False );
1312 0 : aRegExpBtn.Disable();
1313 0 : aMatchCaseCB.Check( sal_False );
1314 0 : aMatchCaseCB.Disable();
1315 0 : aNotesBtn.Disable();
1316 :
1317 0 : if ( aSearchTmplLB.GetEntryCount() )
1318 : {
1319 0 : EnableControl_Impl( &aSearchBtn );
1320 0 : EnableControl_Impl( &aSearchAllBtn );
1321 0 : EnableControl_Impl( &aReplaceBtn );
1322 0 : EnableControl_Impl( &aReplaceAllBtn );
1323 : }
1324 : }
1325 : else
1326 : {
1327 0 : EnableControl_Impl( &aRegExpBtn );
1328 0 : EnableControl_Impl( &aMatchCaseCB );
1329 0 : EnableControl_Impl( &aNotesBtn );
1330 :
1331 0 : if ( aRegExpBtn.IsChecked() )
1332 : {
1333 0 : aWordBtn.Check( sal_False );
1334 0 : aWordBtn.Disable();
1335 0 : aSimilarityBox.Disable();
1336 0 : aSimilarityBtn.Disable();
1337 : }
1338 : else
1339 : {
1340 0 : EnableControl_Impl( &aWordBtn );
1341 0 : EnableControl_Impl( &aSimilarityBox );
1342 : }
1343 :
1344 : // Search-string in place? then enable Buttons
1345 0 : bSet = sal_True;
1346 0 : ModifyHdl_Impl( &aSearchLB );
1347 : }
1348 : }
1349 :
1350 0 : if ( &aAllSheetsCB == pCtrl )
1351 : {
1352 0 : if ( aAllSheetsCB.IsChecked() )
1353 0 : aSearchAllBtn.Disable();
1354 : else
1355 : {
1356 0 : bSet = sal_True;
1357 0 : ModifyHdl_Impl( &aSearchLB );
1358 : }
1359 : }
1360 :
1361 0 : if ( &aJapOptionsCB == pCtrl )
1362 : {
1363 0 : sal_Bool bEnableJapOpt = aJapOptionsCB.IsChecked();
1364 0 : aMatchCaseCB .Enable(!bEnableJapOpt );
1365 0 : aJapMatchFullHalfWidthCB.Enable(!bEnableJapOpt );
1366 0 : aJapOptionsBtn .Enable( bEnableJapOpt );
1367 : }
1368 :
1369 0 : if ( pImpl->bSaveToModule )
1370 0 : SaveToModule_Impl();
1371 0 : return 0;
1372 : }
1373 :
1374 : // -----------------------------------------------------------------------
1375 :
1376 0 : IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
1377 : {
1378 0 : bool bInclusive = ( aLayoutBtn.GetText() == aLayoutStr );
1379 :
1380 0 : if ( ( pBtn == &aSearchBtn ) ||
1381 : ( pBtn == &aSearchAllBtn ) ||
1382 : ( pBtn == &aReplaceBtn ) ||
1383 : ( pBtn == &aReplaceAllBtn ) )
1384 : {
1385 0 : if ( aLayoutBtn.IsChecked() && !bInclusive )
1386 : {
1387 0 : pSearchItem->SetSearchString ( aSearchTmplLB.GetSelectEntry() );
1388 0 : pSearchItem->SetReplaceString( aReplaceTmplLB.GetSelectEntry() );
1389 : }
1390 : else
1391 : {
1392 0 : pSearchItem->SetSearchString ( aSearchLB.GetText() );
1393 0 : pSearchItem->SetReplaceString( aReplaceLB.GetText() );
1394 :
1395 0 : if ( pBtn == &aReplaceBtn )
1396 0 : Remember_Impl( aReplaceLB.GetText(), sal_False );
1397 : else
1398 : {
1399 0 : Remember_Impl( aSearchLB.GetText(), sal_True );
1400 :
1401 0 : if ( pBtn == &aReplaceAllBtn )
1402 0 : Remember_Impl( aReplaceLB.GetText(), sal_False );
1403 : }
1404 : }
1405 :
1406 0 : pSearchItem->SetRegExp( sal_False );
1407 0 : pSearchItem->SetLevenshtein( sal_False );
1408 0 : if (GetCheckBoxValue( aRegExpBtn ))
1409 0 : pSearchItem->SetRegExp( sal_True );
1410 0 : else if (GetCheckBoxValue( aSimilarityBox ))
1411 0 : pSearchItem->SetLevenshtein( sal_True );
1412 :
1413 0 : pSearchItem->SetWordOnly( GetCheckBoxValue( aWordBtn ) );
1414 0 : pSearchItem->SetBackward( GetCheckBoxValue( aBackwardsBtn ) );
1415 0 : pSearchItem->SetNotes( GetCheckBoxValue( aNotesBtn ) );
1416 0 : pSearchItem->SetPattern( GetCheckBoxValue( aLayoutBtn ) );
1417 0 : pSearchItem->SetSelection( GetCheckBoxValue( aSelectionBtn ) );
1418 :
1419 0 : pSearchItem->SetUseAsianOptions( GetCheckBoxValue( aJapOptionsCB ) );
1420 0 : sal_Int32 nFlags = GetTransliterationFlags();
1421 0 : if( !pSearchItem->IsUseAsianOptions())
1422 : nFlags &= (TransliterationModules_IGNORE_CASE |
1423 0 : TransliterationModules_IGNORE_WIDTH );
1424 0 : pSearchItem->SetTransliterationFlags( nFlags );
1425 :
1426 0 : if ( !bWriter )
1427 : {
1428 0 : if ( aCalcSearchInLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
1429 0 : pSearchItem->SetCellType( aCalcSearchInLB.GetSelectEntryPos() );
1430 :
1431 0 : pSearchItem->SetRowDirection( aRowsBtn.IsChecked() );
1432 0 : pSearchItem->SetAllTables( aAllSheetsCB.IsChecked() );
1433 : }
1434 :
1435 0 : if ( pBtn == &aSearchBtn )
1436 0 : pSearchItem->SetCommand( SVX_SEARCHCMD_FIND );
1437 0 : else if ( pBtn == &aSearchAllBtn )
1438 0 : pSearchItem->SetCommand( SVX_SEARCHCMD_FIND_ALL );
1439 0 : else if ( pBtn == &aReplaceBtn )
1440 0 : pSearchItem->SetCommand( SVX_SEARCHCMD_REPLACE );
1441 0 : else if ( pBtn == &aReplaceAllBtn )
1442 0 : pSearchItem->SetCommand( SVX_SEARCHCMD_REPLACE_ALL );
1443 :
1444 : // when looking for templates, delete format lists
1445 0 : if ( !bFormat && pSearchItem->GetPattern() )
1446 : {
1447 0 : if ( pSearchList )
1448 0 : pSearchList->Clear();
1449 :
1450 0 : if ( pReplaceList )
1451 0 : pReplaceList->Clear();
1452 : }
1453 0 : nModifyFlag = 0;
1454 0 : const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
1455 0 : rBindings.ExecuteSynchron( FID_SEARCH_NOW, ppArgs, 0L );
1456 : }
1457 0 : else if ( pBtn == &aCloseBtn )
1458 : {
1459 0 : if ( !aLayoutBtn.IsChecked() || bInclusive )
1460 : {
1461 0 : String aStr( aSearchLB.GetText() );
1462 :
1463 0 : if ( aStr.Len() )
1464 0 : Remember_Impl( aStr, sal_True );
1465 0 : aStr = aReplaceLB.GetText();
1466 :
1467 0 : if ( aStr.Len() )
1468 0 : Remember_Impl( aStr, sal_False );
1469 : }
1470 0 : SaveToModule_Impl();
1471 0 : Close();
1472 : }
1473 0 : else if ( pBtn == &aSimilarityBtn )
1474 : {
1475 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1476 0 : if(pFact)
1477 : {
1478 : AbstractSvxSearchSimilarityDialog* pDlg = pFact->CreateSvxSearchSimilarityDialog( this,
1479 0 : pSearchItem->IsLEVRelaxed(),
1480 0 : pSearchItem->GetLEVOther(),
1481 0 : pSearchItem->GetLEVShorter(),
1482 0 : pSearchItem->GetLEVLonger() );
1483 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
1484 0 : if ( pDlg && pDlg->Execute() == RET_OK )
1485 : {
1486 0 : pSearchItem->SetLEVRelaxed( pDlg->IsRelaxed() );
1487 0 : pSearchItem->SetLEVOther( pDlg->GetOther() );
1488 0 : pSearchItem->SetLEVShorter( pDlg->GetShorter() );
1489 0 : pSearchItem->SetLEVLonger( pDlg->GetLonger() );
1490 0 : SaveToModule_Impl();
1491 : }
1492 0 : delete pDlg;
1493 : }
1494 : }
1495 0 : else if ( pBtn == &aJapOptionsBtn )
1496 : {
1497 0 : SfxItemSet aSet( SFX_APP()->GetPool() );
1498 0 : pSearchItem->SetTransliterationFlags( GetTransliterationFlags() );
1499 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1500 0 : if(pFact)
1501 : {
1502 : AbstractSvxJSearchOptionsDialog* aDlg = pFact->CreateSvxJSearchOptionsDialog( this, aSet,
1503 0 : pSearchItem->GetTransliterationFlags() );
1504 : DBG_ASSERT(aDlg, "Dialogdiet fail!");
1505 0 : int nRet = aDlg->Execute();
1506 0 : if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true
1507 : {
1508 0 : sal_Int32 nFlags = aDlg->GetTransliterationFlags();
1509 0 : pSearchItem->SetTransliterationFlags( nFlags );
1510 0 : ApplyTransliterationFlags_Impl( nFlags );
1511 : }
1512 0 : delete aDlg;
1513 0 : }
1514 : }
1515 0 : else if(pBtn == &aSearchComponent1PB || pBtn == &aSearchComponent2PB )
1516 : {
1517 0 : uno::Sequence < beans::PropertyValue > aArgs(2);
1518 0 : beans::PropertyValue* pArgs = aArgs.getArray();
1519 0 : pArgs[0].Name = ::rtl::OUString("SearchString");
1520 0 : pArgs[0].Value <<= ::rtl::OUString(aSearchLB.GetText());
1521 0 : pArgs[1].Name = ::rtl::OUString("ParentWindow");
1522 0 : pArgs[1].Value <<= VCLUnoHelper::GetInterface( this );
1523 0 : if(pBtn == &aSearchComponent1PB)
1524 : {
1525 0 : if ( pImpl->xCommand1Dispatch.is() )
1526 0 : pImpl->xCommand1Dispatch->dispatch(pImpl->aCommand1URL, aArgs);
1527 : }
1528 : else
1529 : {
1530 0 : if ( pImpl->xCommand2Dispatch.is() )
1531 0 : pImpl->xCommand2Dispatch->dispatch(pImpl->aCommand2URL, aArgs);
1532 0 : }
1533 : }
1534 :
1535 0 : return 0;
1536 : }
1537 :
1538 : // -----------------------------------------------------------------------
1539 :
1540 0 : IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, ComboBox *, pEd )
1541 : {
1542 0 : if ( !bSet )
1543 0 : SetModifyFlag_Impl( pEd );
1544 : else
1545 0 : bSet = sal_False;
1546 :
1547 : // Calc allows searching for empty cells.
1548 0 : bool bAllowEmptySearch = (pSearchItem->GetAppFlag() == SVX_SEARCHAPP_CALC);
1549 :
1550 0 : if ( pEd == &aSearchLB || pEd == &aReplaceLB )
1551 : {
1552 0 : xub_StrLen nSrchTxtLen = aSearchLB.GetText().Len();
1553 0 : xub_StrLen nReplTxtLen = 0;
1554 0 : if (bAllowEmptySearch)
1555 0 : nReplTxtLen = aReplaceLB.GetText().Len();
1556 0 : xub_StrLen nAttrTxtLen = 0;
1557 :
1558 0 : if ( !pImpl->bMultiLineEdit )
1559 0 : nAttrTxtLen = aSearchAttrText.GetText().Len();
1560 : else
1561 0 : nAttrTxtLen = pImpl->aSearchFormats.GetText().Len();
1562 :
1563 0 : if (nSrchTxtLen || nReplTxtLen || nAttrTxtLen)
1564 : {
1565 0 : EnableControl_Impl( &aSearchBtn );
1566 0 : EnableControl_Impl( &aReplaceBtn );
1567 0 : if (!bWriter || (bWriter && !aNotesBtn.IsChecked()))
1568 : {
1569 0 : EnableControl_Impl( &aSearchAllBtn );
1570 0 : EnableControl_Impl( &aReplaceAllBtn );
1571 : }
1572 : }
1573 : else
1574 : {
1575 0 : aSearchComponentFL.Enable(sal_False);
1576 0 : aSearchComponent1PB.Enable(sal_False);
1577 0 : aSearchComponent2PB.Enable(sal_False);
1578 0 : aSearchBtn.Disable();
1579 0 : aSearchAllBtn.Disable();
1580 0 : aReplaceBtn.Disable();
1581 0 : aReplaceAllBtn.Disable();
1582 : }
1583 : }
1584 0 : return 0;
1585 : }
1586 :
1587 : // -----------------------------------------------------------------------
1588 :
1589 0 : IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl)
1590 : {
1591 0 : if ( pImpl->bSaveToModule )
1592 0 : SaveToModule_Impl();
1593 :
1594 0 : if ( bFormat )
1595 0 : return 0;
1596 0 : String sDesc;
1597 :
1598 0 : if ( aLayoutBtn.IsChecked() )
1599 : {
1600 0 : if ( !pFamilyController )
1601 : {
1602 0 : sal_uInt16 nId = 0;
1603 :
1604 : // Enable templates controller
1605 0 : switch ( pSearchItem->GetFamily() )
1606 : {
1607 : case SFX_STYLE_FAMILY_CHAR:
1608 0 : nId = SID_STYLE_FAMILY1; break;
1609 :
1610 : case SFX_STYLE_FAMILY_PARA:
1611 0 : nId = SID_STYLE_FAMILY2; break;
1612 :
1613 : case SFX_STYLE_FAMILY_FRAME:
1614 0 : nId = SID_STYLE_FAMILY3; break;
1615 :
1616 : case SFX_STYLE_FAMILY_PAGE:
1617 0 : nId = SID_STYLE_FAMILY4; break;
1618 :
1619 : case SFX_STYLE_FAMILY_ALL:
1620 0 : break;
1621 :
1622 : default:
1623 : OSL_FAIL( "StyleSheetFamily was changed?" );
1624 : }
1625 :
1626 0 : rBindings.EnterRegistrations();
1627 : pFamilyController =
1628 0 : new SvxSearchController( nId, rBindings, *this );
1629 0 : rBindings.LeaveRegistrations();
1630 0 : aSearchTmplLB.Clear();
1631 0 : aReplaceTmplLB.Clear();
1632 :
1633 0 : aSearchTmplLB.Show();
1634 0 : aReplaceTmplLB.Show();
1635 0 : aSearchLB.Hide();
1636 0 : aReplaceLB.Hide();
1637 :
1638 0 : if ( !pImpl->bMultiLineEdit )
1639 : {
1640 0 : aSearchAttrText.SetText( sDesc );
1641 0 : aReplaceAttrText.SetText( sDesc );
1642 : }
1643 : else
1644 : {
1645 0 : pImpl->aSearchFormats.SetText( sDesc );
1646 0 : pImpl->aReplaceFormats.SetText( sDesc );
1647 : }
1648 : }
1649 0 : aFormatBtn.Disable();
1650 0 : aNoFormatBtn.Disable();
1651 0 : aAttributeBtn.Disable();
1652 0 : aSimilarityBox.Disable();
1653 0 : aSimilarityBtn.Disable();
1654 : }
1655 : else
1656 : {
1657 : // Disable templates controller
1658 0 : rBindings.EnterRegistrations();
1659 0 : DELETEZ( pFamilyController );
1660 0 : rBindings.LeaveRegistrations();
1661 :
1662 0 : aSearchLB.Show();
1663 0 : aReplaceLB.Show();
1664 0 : aSearchTmplLB.Hide();
1665 0 : aReplaceTmplLB.Hide();
1666 :
1667 0 : if ( !pImpl->bMultiLineEdit )
1668 : {
1669 0 : aSearchAttrText.SetText( BuildAttrText_Impl( sDesc, sal_True ) );
1670 0 : aReplaceAttrText.SetText( BuildAttrText_Impl( sDesc, sal_False ) );
1671 : }
1672 : else
1673 : {
1674 0 : pImpl->aSearchFormats.SetText( BuildAttrText_Impl( sDesc, sal_True ) );
1675 0 : pImpl->aReplaceFormats.SetText( BuildAttrText_Impl( sDesc, sal_False ) );
1676 : }
1677 :
1678 0 : EnableControl_Impl( &aFormatBtn );
1679 0 : EnableControl_Impl( &aAttributeBtn );
1680 0 : EnableControl_Impl( &aSimilarityBox );
1681 :
1682 0 : FocusHdl_Impl( bSearch ? &aSearchLB : &aReplaceLB );
1683 : }
1684 0 : bSet = sal_True;
1685 0 : pImpl->bSaveToModule = sal_False;
1686 0 : FlagHdl_Impl( &aLayoutBtn );
1687 0 : pImpl->bSaveToModule = sal_True;
1688 0 : return 0;
1689 : }
1690 :
1691 : // -----------------------------------------------------------------------
1692 :
1693 0 : void SvxSearchDialog::Remember_Impl( const String &rStr,sal_Bool _bSearch )
1694 : {
1695 0 : if ( !rStr.Len() )
1696 0 : return;
1697 :
1698 0 : std::vector<rtl::OUString>* pArr = _bSearch ? &aSearchStrings : &aReplaceStrings;
1699 0 : ComboBox* pListBox = _bSearch ? &aSearchLB : &aReplaceLB;
1700 :
1701 : // ignore identical strings
1702 0 : for (std::vector<rtl::OUString>::const_iterator i = pArr->begin(); i != pArr->end(); ++i)
1703 : {
1704 0 : if ((*i).equals(rStr))
1705 : return;
1706 : }
1707 :
1708 : // delete oldest entry at maximum occupancy (ListBox and Array)
1709 0 : if(REMEMBER_SIZE < pArr->size())
1710 : {
1711 0 : pListBox->RemoveEntry( sal_uInt16(REMEMBER_SIZE - 1) );
1712 0 : (*pArr)[REMEMBER_SIZE - 1] = rStr;
1713 0 : pArr->erase(pArr->begin() + REMEMBER_SIZE - 1);
1714 : }
1715 :
1716 0 : pArr->insert(pArr->begin(), rStr);
1717 0 : pListBox->InsertEntry(rStr, 0);
1718 : }
1719 :
1720 : // -----------------------------------------------------------------------
1721 :
1722 0 : void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool )
1723 : {
1724 0 : String aOldSrch( aSearchTmplLB .GetSelectEntry() );
1725 0 : String aOldRepl( aReplaceTmplLB.GetSelectEntry() );
1726 0 : aSearchTmplLB .Clear();
1727 0 : aReplaceTmplLB.Clear();
1728 0 : rPool.SetSearchMask( pSearchItem->GetFamily(), SFXSTYLEBIT_ALL );
1729 0 : aSearchTmplLB.SetUpdateMode( sal_False );
1730 0 : aReplaceTmplLB.SetUpdateMode( sal_False );
1731 0 : SfxStyleSheetBase* pBase = rPool.First();
1732 :
1733 0 : while ( pBase )
1734 : {
1735 0 : if ( pBase->IsUsed() )
1736 0 : aSearchTmplLB.InsertEntry( pBase->GetName() );
1737 0 : aReplaceTmplLB.InsertEntry( pBase->GetName() );
1738 0 : pBase = rPool.Next();
1739 : }
1740 0 : aSearchTmplLB.SetUpdateMode( sal_True );
1741 0 : aReplaceTmplLB.SetUpdateMode( sal_True );
1742 0 : aSearchTmplLB.SelectEntryPos(0);
1743 :
1744 0 : if ( aOldSrch.Len() )
1745 0 : aSearchTmplLB .SelectEntry( aOldSrch );
1746 0 : aReplaceTmplLB.SelectEntryPos(0);
1747 :
1748 0 : if ( aOldRepl.Len() )
1749 0 : aReplaceTmplLB.SelectEntry( aOldRepl );
1750 :
1751 0 : if ( aSearchTmplLB.GetEntryCount() )
1752 : {
1753 0 : EnableControl_Impl( &aSearchBtn );
1754 0 : EnableControl_Impl( &aSearchAllBtn );
1755 0 : EnableControl_Impl( &aReplaceBtn );
1756 0 : EnableControl_Impl( &aReplaceAllBtn );
1757 0 : }
1758 0 : }
1759 :
1760 : // -----------------------------------------------------------------------
1761 :
1762 0 : void SvxSearchDialog::EnableControls_Impl( const sal_uInt16 nFlags )
1763 : {
1764 0 : if ( nFlags == nOptions )
1765 0 : return;
1766 : else
1767 0 : nOptions = nFlags;
1768 :
1769 0 : if ( !nOptions )
1770 : {
1771 0 : if ( IsVisible() )
1772 : {
1773 0 : Hide();
1774 0 : return;
1775 : }
1776 : }
1777 0 : else if ( !IsVisible() )
1778 0 : Show();
1779 0 : bool bNoSearch = true;
1780 :
1781 0 : sal_Bool bEnableSearch = ( SEARCH_OPTIONS_SEARCH & nOptions ) != 0;
1782 0 : aSearchBtn.Enable(bEnableSearch);
1783 :
1784 0 : if( bEnableSearch )
1785 0 : bNoSearch = false;
1786 :
1787 :
1788 0 : if ( ( SEARCH_OPTIONS_SEARCH_ALL & nOptions ) != 0 )
1789 : {
1790 0 : aSearchAllBtn.Enable();
1791 0 : bNoSearch = false;
1792 : }
1793 : else
1794 0 : aSearchAllBtn.Disable();
1795 0 : if ( ( SEARCH_OPTIONS_REPLACE & nOptions ) != 0 )
1796 : {
1797 0 : aReplaceBtn.Enable();
1798 0 : aReplaceText.Enable();
1799 0 : aReplaceLB.Enable();
1800 0 : aReplaceTmplLB.Enable();
1801 0 : bNoSearch = false;
1802 : }
1803 : else
1804 : {
1805 0 : aReplaceBtn.Disable();
1806 0 : aReplaceText.Disable();
1807 0 : aReplaceLB.Disable();
1808 0 : aReplaceTmplLB.Disable();
1809 : }
1810 0 : if ( ( SEARCH_OPTIONS_REPLACE_ALL & nOptions ) != 0 )
1811 : {
1812 0 : aReplaceAllBtn.Enable();
1813 0 : bNoSearch = false;
1814 : }
1815 : else
1816 0 : aReplaceAllBtn.Disable();
1817 0 : aSearchComponentFL.Enable(!bNoSearch);
1818 0 : aSearchComponent1PB.Enable(!bNoSearch);
1819 0 : aSearchComponent2PB.Enable(!bNoSearch);
1820 0 : aSearchBtn.Enable( !bNoSearch );
1821 0 : aSearchText.Enable( !bNoSearch );
1822 0 : aSearchLB.Enable( !bNoSearch );
1823 :
1824 0 : if ( ( SEARCH_OPTIONS_WHOLE_WORDS & nOptions ) != 0 )
1825 0 : aWordBtn.Enable();
1826 : else
1827 0 : aWordBtn.Disable();
1828 0 : if ( ( SEARCH_OPTIONS_BACKWARDS & nOptions ) != 0 )
1829 0 : aBackwardsBtn.Enable();
1830 : else
1831 0 : aBackwardsBtn.Disable();
1832 0 : aNotesBtn.Enable();
1833 0 : if ( ( SEARCH_OPTIONS_REG_EXP & nOptions ) != 0 )
1834 0 : aRegExpBtn.Enable();
1835 : else
1836 0 : aRegExpBtn.Disable();
1837 0 : if ( ( SEARCH_OPTIONS_EXACT & nOptions ) != 0 )
1838 0 : aMatchCaseCB.Enable();
1839 : else
1840 0 : aMatchCaseCB.Disable();
1841 0 : if ( ( SEARCH_OPTIONS_SELECTION & nOptions ) != 0 )
1842 0 : aSelectionBtn.Enable();
1843 : else
1844 0 : aSelectionBtn.Disable();
1845 0 : if ( ( SEARCH_OPTIONS_FAMILIES & nOptions ) != 0 )
1846 0 : aLayoutBtn.Enable();
1847 : else
1848 0 : aLayoutBtn.Disable();
1849 0 : if ( ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1850 : {
1851 0 : aAttributeBtn.Enable();
1852 0 : aFormatBtn.Enable();
1853 0 : aNoFormatBtn.Enable();
1854 : }
1855 : else
1856 : {
1857 0 : aAttributeBtn.Disable();
1858 0 : aFormatBtn.Disable();
1859 0 : aNoFormatBtn.Disable();
1860 : }
1861 :
1862 0 : if ( ( SEARCH_OPTIONS_SIMILARITY & nOptions ) != 0 )
1863 : {
1864 0 : aSimilarityBox.Enable();
1865 0 : aSimilarityBtn.Enable();
1866 : }
1867 : else
1868 : {
1869 0 : aSimilarityBox.Disable();
1870 0 : aSimilarityBtn.Disable();
1871 : }
1872 :
1873 0 : if ( pSearchItem )
1874 0 : Init_Impl( pSearchItem->GetPattern() &&
1875 0 : ( !pSearchList || !pSearchList->Count() ) );
1876 : }
1877 :
1878 : // -----------------------------------------------------------------------
1879 :
1880 0 : void SvxSearchDialog::EnableControl_Impl( Control* pCtrl )
1881 : {
1882 0 : if ( &aSearchBtn == pCtrl && ( SEARCH_OPTIONS_SEARCH & nOptions ) != 0 )
1883 : {
1884 0 : aSearchComponentFL.Enable();
1885 0 : aSearchComponent1PB.Enable();
1886 0 : aSearchComponent2PB.Enable();
1887 0 : aSearchBtn.Enable();
1888 0 : return;
1889 : }
1890 0 : if ( &aSearchAllBtn == pCtrl &&
1891 : ( SEARCH_OPTIONS_SEARCH_ALL & nOptions ) != 0 )
1892 : {
1893 0 : aSearchAllBtn.Enable( ( bWriter || !aAllSheetsCB.IsChecked() ) );
1894 0 : return;
1895 : }
1896 0 : if ( &aReplaceBtn == pCtrl && ( SEARCH_OPTIONS_REPLACE & nOptions ) != 0 )
1897 : {
1898 0 : aReplaceBtn.Enable();
1899 0 : return;
1900 : }
1901 0 : if ( &aReplaceAllBtn == pCtrl &&
1902 : ( SEARCH_OPTIONS_REPLACE_ALL & nOptions ) != 0 )
1903 : {
1904 0 : aReplaceAllBtn.Enable();
1905 0 : return;
1906 : }
1907 0 : if ( &aWordBtn == pCtrl && ( SEARCH_OPTIONS_WHOLE_WORDS & nOptions ) != 0 )
1908 : {
1909 0 : aWordBtn.Enable();
1910 0 : return;
1911 : }
1912 0 : if ( &aBackwardsBtn == pCtrl && ( SEARCH_OPTIONS_BACKWARDS & nOptions ) != 0 )
1913 : {
1914 0 : aBackwardsBtn.Enable();
1915 0 : return;
1916 : }
1917 0 : if ( &aNotesBtn == pCtrl )
1918 : {
1919 0 : aNotesBtn.Enable();
1920 0 : return;
1921 : }
1922 0 : if ( &aRegExpBtn == pCtrl && ( SEARCH_OPTIONS_REG_EXP & nOptions ) != 0
1923 0 : && !aSimilarityBox.IsChecked())
1924 : {
1925 0 : aRegExpBtn.Enable();
1926 0 : return;
1927 : }
1928 0 : if ( &aMatchCaseCB == pCtrl && ( SEARCH_OPTIONS_EXACT & nOptions ) != 0 )
1929 : {
1930 0 : if (!aJapOptionsCB.IsChecked())
1931 0 : aMatchCaseCB.Enable();
1932 0 : return;
1933 : }
1934 0 : if ( &aSelectionBtn == pCtrl && ( SEARCH_OPTIONS_SELECTION & nOptions ) != 0 )
1935 : {
1936 0 : aSelectionBtn.Enable();
1937 0 : return;
1938 : }
1939 0 : if ( &aLayoutBtn == pCtrl && ( SEARCH_OPTIONS_FAMILIES & nOptions ) != 0 )
1940 : {
1941 0 : aLayoutBtn.Enable();
1942 0 : return;
1943 : }
1944 0 : if ( &aAttributeBtn == pCtrl
1945 : && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0
1946 : && pSearchList )
1947 : {
1948 0 : aAttributeBtn.Enable( pImpl->bFocusOnSearch );
1949 : }
1950 0 : if ( &aFormatBtn == pCtrl && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1951 : {
1952 0 : aFormatBtn.Enable();
1953 0 : return;
1954 : }
1955 0 : if ( &aNoFormatBtn == pCtrl && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1956 : {
1957 0 : aNoFormatBtn.Enable();
1958 0 : return;
1959 : }
1960 0 : if ( &aSimilarityBox == pCtrl &&
1961 : ( SEARCH_OPTIONS_SIMILARITY & nOptions ) != 0 )
1962 : {
1963 0 : aSimilarityBox.Enable();
1964 :
1965 0 : if ( aSimilarityBox.IsChecked() )
1966 0 : aSimilarityBtn.Enable();
1967 : }
1968 : }
1969 :
1970 : // -----------------------------------------------------------------------
1971 :
1972 0 : void SvxSearchDialog::SetItem_Impl( const SvxSearchItem* pItem )
1973 : {
1974 0 : if ( pItem )
1975 : {
1976 0 : delete pSearchItem;
1977 0 : pSearchItem = (SvxSearchItem*)pItem->Clone();
1978 0 : Init_Impl( pSearchItem->GetPattern() &&
1979 0 : ( !pSearchList || !pSearchList->Count() ) );
1980 : }
1981 0 : }
1982 :
1983 : // -----------------------------------------------------------------------
1984 :
1985 0 : IMPL_LINK( SvxSearchDialog, FocusHdl_Impl, Control *, pCtrl )
1986 : {
1987 : xub_StrLen nTxtLen;
1988 :
1989 0 : if ( !pImpl->bMultiLineEdit )
1990 0 : nTxtLen = aSearchAttrText.GetText().Len();
1991 : else
1992 0 : nTxtLen = pImpl->aSearchFormats.GetText().Len();
1993 :
1994 0 : if ( pCtrl == &aSearchLB || pCtrl == &pImpl->aSearchFormats )
1995 : {
1996 0 : if ( pCtrl->HasChildPathFocus() )
1997 0 : pImpl->bFocusOnSearch = sal_True;
1998 0 : pCtrl = &aSearchLB;
1999 0 : bSearch = sal_True;
2000 :
2001 0 : if( nTxtLen )
2002 0 : EnableControl_Impl( &aNoFormatBtn );
2003 : else
2004 0 : aNoFormatBtn.Disable();
2005 0 : EnableControl_Impl( &aAttributeBtn );
2006 : }
2007 : else
2008 : {
2009 0 : pImpl->bFocusOnSearch = sal_False;
2010 0 : pCtrl = &aReplaceLB;
2011 0 : bSearch = sal_False;
2012 :
2013 0 : if ( ( !pImpl->bMultiLineEdit && aReplaceAttrText.GetText().Len() ) ||
2014 0 : ( pImpl->bMultiLineEdit && pImpl->aReplaceFormats.GetText().Len() ) )
2015 0 : EnableControl_Impl( &aNoFormatBtn );
2016 : else
2017 0 : aNoFormatBtn.Disable();
2018 0 : aAttributeBtn.Disable();
2019 : }
2020 0 : bSet = sal_True;
2021 :
2022 0 : aSearchLB.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
2023 :
2024 0 : ModifyHdl_Impl( (ComboBox*)pCtrl );
2025 :
2026 0 : aLayoutBtn.SetText( bFormat && nTxtLen ? aLayoutStr : aStylesStr );
2027 0 : return 0;
2028 : }
2029 :
2030 : // -----------------------------------------------------------------------
2031 :
2032 0 : IMPL_LINK_NOARG(SvxSearchDialog, LoseFocusHdl_Impl)
2033 : {
2034 0 : SaveToModule_Impl();
2035 0 : return 0;
2036 : }
2037 :
2038 : // -----------------------------------------------------------------------
2039 :
2040 0 : IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
2041 : {
2042 0 : SfxObjectShell* pSh = SfxObjectShell::Current();
2043 :
2044 : DBG_ASSERT( pSh, "no DocShell" );
2045 :
2046 0 : if ( !pSh || !pImpl->pRanges )
2047 0 : return 0;
2048 :
2049 0 : sal_sSize nCnt = 0;
2050 0 : const sal_uInt16* pPtr = pImpl->pRanges;
2051 0 : const sal_uInt16* pTmp = pPtr;
2052 :
2053 0 : while( *pTmp )
2054 0 : pTmp++;
2055 0 : nCnt = pTmp - pPtr + 7;
2056 0 : sal_uInt16* pWhRanges = new sal_uInt16[nCnt];
2057 0 : sal_uInt16 nPos = 0;
2058 :
2059 0 : while( *pPtr )
2060 : {
2061 0 : pWhRanges[nPos++] = *pPtr++;
2062 : }
2063 :
2064 0 : pWhRanges[nPos++] = SID_ATTR_PARA_MODEL;
2065 0 : pWhRanges[nPos++] = SID_ATTR_PARA_MODEL;
2066 :
2067 0 : sal_uInt16 nBrushWhich = pSh->GetPool().GetWhich(SID_ATTR_BRUSH);
2068 0 : pWhRanges[nPos++] = nBrushWhich;
2069 0 : pWhRanges[nPos++] = nBrushWhich;
2070 0 : pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION;
2071 0 : pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION;
2072 0 : pWhRanges[nPos] = 0;
2073 0 : SfxItemPool& rPool = pSh->GetPool();
2074 0 : SfxItemSet aSet( rPool, pWhRanges );
2075 0 : String aTxt;
2076 :
2077 0 : aSet.InvalidateAllItems();
2078 0 : aSet.Put(SvxBrushItem(nBrushWhich));
2079 0 : aSet.Put(SfxUInt16Item(SID_PARA_BACKGRND_DESTINATION, PARA_DEST_CHAR));
2080 :
2081 0 : if ( bSearch )
2082 : {
2083 0 : aTxt = SVX_RESSTR( RID_SVXSTR_SEARCH );
2084 0 : pSearchList->Get( aSet );
2085 : }
2086 : else
2087 : {
2088 0 : aTxt = SVX_RESSTR( RID_SVXSTR_REPLACE );
2089 0 : pReplaceList->Get( aSet );
2090 : }
2091 0 : aSet.DisableItem(SID_ATTR_PARA_MODEL);
2092 0 : aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_PAGEBREAK));
2093 0 : aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_KEEP));
2094 :
2095 :
2096 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2097 0 : if(pFact)
2098 : {
2099 0 : SfxAbstractTabDialog* pDlg = pFact->CreateTabItemDialog( this, aSet, RID_SVXDLG_SEARCHFORMAT );
2100 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
2101 0 : aTxt.Insert( pDlg->GetText(), 0 );
2102 0 : pDlg->SetText( aTxt );
2103 :
2104 0 : if ( pDlg->Execute() == RET_OK )
2105 : {
2106 : DBG_ASSERT( pDlg->GetOutputItemSet(), "invalid Output-Set" );
2107 0 : SfxItemSet aOutSet( *pDlg->GetOutputItemSet() );
2108 :
2109 0 : SearchAttrItemList* pList = bSearch ? pSearchList : pReplaceList;
2110 :
2111 : SearchAttrItem* pAItem;
2112 : const SfxPoolItem* pItem;
2113 0 : for( sal_uInt16 n = 0; n < pList->Count(); ++n )
2114 0 : if( !IsInvalidItem( (pAItem = &pList->GetObject(n))->pItem ) &&
2115 : SFX_ITEM_SET == aOutSet.GetItemState(
2116 0 : pAItem->pItem->Which(), sal_False, &pItem ) )
2117 : {
2118 0 : delete pAItem->pItem;
2119 0 : pAItem->pItem = pItem->Clone();
2120 0 : aOutSet.ClearItem( pAItem->pItem->Which() );
2121 : }
2122 :
2123 0 : if( aOutSet.Count() )
2124 0 : pList->Put( aOutSet );
2125 :
2126 0 : PaintAttrText_Impl(); // Set AttributText in GroupBox
2127 : }
2128 0 : delete pDlg;
2129 : }
2130 0 : delete[] pWhRanges;
2131 0 : return 0;
2132 : }
2133 :
2134 : // -----------------------------------------------------------------------
2135 :
2136 0 : IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl)
2137 : {
2138 0 : aLayoutBtn.SetText( aStylesStr );
2139 0 : bFormat = sal_False;
2140 0 : aLayoutBtn.Check( sal_False );
2141 :
2142 0 : if ( bSearch )
2143 : {
2144 0 : if ( !pImpl->bMultiLineEdit )
2145 0 : aSearchAttrText.SetText( String() );
2146 : else
2147 0 : pImpl->aSearchFormats.SetText( String() );
2148 0 : pSearchList->Clear();
2149 : }
2150 : else
2151 : {
2152 0 : if ( !pImpl->bMultiLineEdit )
2153 0 : aReplaceAttrText.SetText( String() );
2154 : else
2155 0 : pImpl->aReplaceFormats.SetText( String() );
2156 0 : pReplaceList->Clear();
2157 : }
2158 0 : pImpl->bSaveToModule = sal_False;
2159 0 : TemplateHdl_Impl( &aLayoutBtn );
2160 0 : pImpl->bSaveToModule = sal_True;
2161 0 : aNoFormatBtn.Disable();
2162 0 : return 0;
2163 : }
2164 :
2165 : // -----------------------------------------------------------------------
2166 :
2167 0 : IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl)
2168 : {
2169 0 : if ( !pSearchList || !pImpl->pRanges )
2170 0 : return 0;
2171 :
2172 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2173 0 : if(pFact)
2174 : {
2175 0 : VclAbstractDialog* pDlg = pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges );
2176 : DBG_ASSERT(pDlg, "Dialogdiet fail!");
2177 0 : pDlg->Execute();
2178 0 : delete pDlg;
2179 : }
2180 0 : PaintAttrText_Impl();
2181 0 : return 0;
2182 : }
2183 :
2184 : // -----------------------------------------------------------------------
2185 :
2186 0 : IMPL_LINK( SvxSearchDialog, TimeoutHdl_Impl, Timer *, pTimer )
2187 : {
2188 0 : SfxViewShell* pViewShell = SfxViewShell::Current();
2189 :
2190 0 : if ( pViewShell )
2191 : {
2192 0 : if ( pViewShell->HasSelection( aSearchLB.IsVisible() ) )
2193 0 : EnableControl_Impl( &aSelectionBtn );
2194 : else
2195 : {
2196 0 : aSelectionBtn.Check( sal_False );
2197 0 : aSelectionBtn.Disable();
2198 : }
2199 : }
2200 :
2201 0 : pTimer->Start();
2202 0 : return 0;
2203 : }
2204 :
2205 : // -----------------------------------------------------------------------
2206 :
2207 0 : String& SvxSearchDialog::BuildAttrText_Impl( String& rStr,
2208 : sal_Bool bSrchFlag ) const
2209 : {
2210 0 : if ( rStr.Len() )
2211 0 : rStr.Erase();
2212 :
2213 0 : SfxObjectShell* pSh = SfxObjectShell::Current();
2214 : DBG_ASSERT( pSh, "no DocShell" );
2215 :
2216 0 : if ( !pSh )
2217 0 : return rStr;
2218 :
2219 0 : SfxItemPool& rPool = pSh->GetPool();
2220 0 : SearchAttrItemList* pList = bSrchFlag ? pSearchList : pReplaceList;
2221 :
2222 0 : if ( !pList )
2223 0 : return rStr;
2224 :
2225 : // Metric query
2226 0 : SfxMapUnit eMapUnit = SFX_MAPUNIT_CM;
2227 0 : FieldUnit eFieldUnit = pSh->GetModule()->GetFieldUnit();
2228 0 : switch ( eFieldUnit )
2229 : {
2230 0 : case FUNIT_MM: eMapUnit = SFX_MAPUNIT_MM; break;
2231 : case FUNIT_CM:
2232 : case FUNIT_M:
2233 0 : case FUNIT_KM: eMapUnit = SFX_MAPUNIT_CM; break;
2234 0 : case FUNIT_TWIP: eMapUnit = SFX_MAPUNIT_TWIP; break;
2235 : case FUNIT_POINT:
2236 0 : case FUNIT_PICA: eMapUnit = SFX_MAPUNIT_POINT; break;
2237 : case FUNIT_INCH:
2238 : case FUNIT_FOOT:
2239 0 : case FUNIT_MILE: eMapUnit = SFX_MAPUNIT_INCH; break;
2240 0 : case FUNIT_100TH_MM: eMapUnit = SFX_MAPUNIT_100TH_MM; break;
2241 : default: ;//prevent warning
2242 : }
2243 :
2244 0 : ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) );
2245 :
2246 0 : for ( sal_uInt16 i = 0; i < pList->Count(); ++i )
2247 : {
2248 0 : const SearchAttrItem& rItem = pList->GetObject(i);
2249 :
2250 0 : if ( rStr.Len() )
2251 0 : rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
2252 :
2253 0 : if ( !IsInvalidItem( rItem.pItem ) )
2254 : {
2255 0 : String aStr;
2256 : rPool.GetPresentation( *rItem.pItem,
2257 : SFX_ITEM_PRESENTATION_COMPLETE,
2258 0 : eMapUnit, aStr );
2259 0 : rStr += aStr;
2260 : }
2261 0 : else if ( rItem.nSlot == SID_ATTR_BRUSH_CHAR )
2262 : {
2263 : // Special treatment for text background
2264 0 : rStr += SVX_RESSTR( RID_SVXITEMS_BRUSH_CHAR );
2265 : }
2266 : else
2267 : {
2268 0 : sal_uInt32 nId = aAttrNames.FindIndex( rItem.nSlot );
2269 0 : if ( RESARRAY_INDEX_NOTFOUND != nId )
2270 0 : rStr += aAttrNames.GetString( nId );
2271 : }
2272 : }
2273 0 : return rStr;
2274 : }
2275 :
2276 : // -----------------------------------------------------------------------
2277 :
2278 0 : void SvxSearchDialog::PaintAttrText_Impl()
2279 : {
2280 0 : String aDesc;
2281 0 : BuildAttrText_Impl( aDesc, bSearch );
2282 :
2283 0 : if ( !bFormat && aDesc.Len() )
2284 0 : bFormat = sal_True;
2285 :
2286 0 : if ( bSearch )
2287 : {
2288 0 : if ( !pImpl->bMultiLineEdit )
2289 0 : aSearchAttrText.SetText( aDesc );
2290 : else
2291 0 : pImpl->aSearchFormats.SetText( aDesc );
2292 0 : FocusHdl_Impl( &aSearchLB );
2293 : }
2294 : else
2295 : {
2296 0 : if ( !pImpl->bMultiLineEdit )
2297 0 : aReplaceAttrText.SetText( aDesc );
2298 : else
2299 0 : pImpl->aReplaceFormats.SetText( aDesc );
2300 0 : FocusHdl_Impl( &aReplaceLB );
2301 0 : }
2302 0 : }
2303 :
2304 : // -----------------------------------------------------------------------
2305 :
2306 0 : void SvxSearchDialog::SetModifyFlag_Impl( const Control* pCtrl )
2307 : {
2308 0 : if ( &aSearchLB == (ComboBox*)pCtrl )
2309 0 : nModifyFlag |= MODIFY_SEARCH;
2310 0 : else if ( &aReplaceLB == (ComboBox*)pCtrl )
2311 0 : nModifyFlag |= MODIFY_REPLACE;
2312 0 : else if ( &aWordBtn == (CheckBox*)pCtrl )
2313 0 : nModifyFlag |= MODIFY_WORD;
2314 0 : else if ( &aMatchCaseCB == (CheckBox*)pCtrl )
2315 0 : nModifyFlag |= MODIFY_EXACT;
2316 0 : else if ( &aBackwardsBtn == (CheckBox*)pCtrl )
2317 0 : nModifyFlag |= MODIFY_BACKWARDS;
2318 0 : else if ( &aNotesBtn == (CheckBox*)pCtrl )
2319 0 : nModifyFlag |= MODIFY_NOTES;
2320 0 : else if ( &aSelectionBtn == (CheckBox*)pCtrl )
2321 0 : nModifyFlag |= MODIFY_SELECTION;
2322 0 : else if ( &aRegExpBtn == (CheckBox*)pCtrl )
2323 0 : nModifyFlag |= MODIFY_REGEXP;
2324 0 : else if ( &aLayoutBtn == (CheckBox*)pCtrl )
2325 0 : nModifyFlag |= MODIFY_LAYOUT;
2326 0 : else if ( &aSimilarityBox == (CheckBox*)pCtrl )
2327 0 : nModifyFlag |= MODIFY_SIMILARITY;
2328 0 : else if ( &aCalcSearchInLB == (ListBox*)pCtrl )
2329 : {
2330 0 : nModifyFlag |= MODIFY_FORMULAS;
2331 0 : nModifyFlag |= MODIFY_VALUES;
2332 0 : nModifyFlag |= MODIFY_CALC_NOTES;
2333 : }
2334 0 : else if ( &aRowsBtn == (RadioButton*)pCtrl )
2335 0 : nModifyFlag |= MODIFY_ROWS;
2336 0 : else if ( &aColumnsBtn == (RadioButton*)pCtrl )
2337 0 : nModifyFlag |= MODIFY_COLUMNS;
2338 0 : else if ( &aAllSheetsCB == (CheckBox*)pCtrl )
2339 0 : nModifyFlag |= MODIFY_ALLTABLES;
2340 0 : }
2341 :
2342 : // -----------------------------------------------------------------------
2343 :
2344 0 : void SvxSearchDialog::SaveToModule_Impl()
2345 : {
2346 0 : if ( !pSearchItem )
2347 0 : return;
2348 :
2349 0 : if ( aLayoutBtn.IsChecked() )
2350 : {
2351 0 : pSearchItem->SetSearchString ( aSearchTmplLB.GetSelectEntry() );
2352 0 : pSearchItem->SetReplaceString( aReplaceTmplLB.GetSelectEntry() );
2353 : }
2354 : else
2355 : {
2356 0 : pSearchItem->SetSearchString ( aSearchLB.GetText() );
2357 0 : pSearchItem->SetReplaceString( aReplaceLB.GetText() );
2358 0 : Remember_Impl( aSearchLB.GetText(), sal_True );
2359 : }
2360 :
2361 0 : pSearchItem->SetRegExp( sal_False );
2362 0 : pSearchItem->SetLevenshtein( sal_False );
2363 0 : if (GetCheckBoxValue( aRegExpBtn ))
2364 0 : pSearchItem->SetRegExp( sal_True );
2365 0 : else if (GetCheckBoxValue( aSimilarityBox ))
2366 0 : pSearchItem->SetLevenshtein( sal_True );
2367 :
2368 0 : pSearchItem->SetWordOnly( GetCheckBoxValue( aWordBtn ) );
2369 0 : pSearchItem->SetBackward( GetCheckBoxValue( aBackwardsBtn ) );
2370 0 : pSearchItem->SetNotes( GetCheckBoxValue( aNotesBtn ) );
2371 0 : pSearchItem->SetPattern( GetCheckBoxValue( aLayoutBtn ) );
2372 0 : pSearchItem->SetSelection( GetCheckBoxValue( aSelectionBtn ) );
2373 :
2374 0 : pSearchItem->SetUseAsianOptions( GetCheckBoxValue( aJapOptionsCB ) );
2375 0 : sal_Int32 nFlags = GetTransliterationFlags();
2376 0 : if( !pSearchItem->IsUseAsianOptions())
2377 : nFlags &= (TransliterationModules_IGNORE_CASE |
2378 0 : TransliterationModules_IGNORE_WIDTH );
2379 0 : pSearchItem->SetTransliterationFlags( nFlags );
2380 :
2381 0 : if ( !bWriter )
2382 : {
2383 0 : if ( aCalcSearchInLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
2384 0 : pSearchItem->SetCellType( aCalcSearchInLB.GetSelectEntryPos() );
2385 :
2386 0 : pSearchItem->SetRowDirection( aRowsBtn.IsChecked() );
2387 0 : pSearchItem->SetAllTables( aAllSheetsCB.IsChecked() );
2388 : }
2389 :
2390 0 : pSearchItem->SetCommand( SVX_SEARCHCMD_FIND );
2391 0 : nModifyFlag = 0;
2392 0 : const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
2393 0 : rBindings.GetDispatcher()->Execute( SID_SEARCH_ITEM, SFX_CALLMODE_SLOT, ppArgs );
2394 : }
2395 :
2396 : // class SvxSearchDialogWrapper ------------------------------------------
2397 :
2398 1003 : SFX_IMPL_CHILDWINDOW_WITHID(SvxSearchDialogWrapper, SID_SEARCH_DLG);
2399 :
2400 : // -----------------------------------------------------------------------
2401 :
2402 0 : SvxSearchDialogWrapper::SvxSearchDialogWrapper( Window* _pParent, sal_uInt16 nId,
2403 : SfxBindings* pBindings,
2404 : SfxChildWinInfo* pInfo )
2405 : : SfxChildWindow( _pParent, nId )
2406 0 : , dialog (new SvxSearchDialog (_pParent, this, *pBindings))
2407 : {
2408 0 : pWindow = dialog;
2409 0 : dialog->Initialize( pInfo );
2410 :
2411 0 : pBindings->Update( SID_SEARCH_ITEM );
2412 0 : pBindings->Update( SID_SEARCH_OPTIONS );
2413 0 : pBindings->Update( SID_SEARCH_SEARCHSET );
2414 0 : pBindings->Update( SID_SEARCH_REPLACESET );
2415 0 : eChildAlignment = SFX_ALIGN_NOALIGNMENT;
2416 0 : dialog->bConstruct = sal_False;
2417 0 : }
2418 :
2419 0 : SvxSearchDialogWrapper::~SvxSearchDialogWrapper ()
2420 : {
2421 0 : }
2422 :
2423 0 : SvxSearchDialog *SvxSearchDialogWrapper::getDialog ()
2424 : {
2425 0 : return dialog;
2426 : }
2427 :
2428 : // -----------------------------------------------------------------------
2429 :
2430 0 : SfxChildWinInfo SvxSearchDialogWrapper::GetInfo() const
2431 : {
2432 0 : SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
2433 0 : aInfo.bVisible = sal_False;
2434 0 : return aInfo;
2435 57 : }
2436 :
2437 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|