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