bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / dialog / srchdlg.cxx
blob157af301ffcdaa098d312d019212f6eca1ce18e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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 <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/i18n/TransliterationModules.hpp>
38 #include <com/sun/star/frame/XDispatch.hpp>
39 #include <com/sun/star/frame/XDispatchProvider.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/configuration/theDefaultProvider.hpp>
42 #include <com/sun/star/frame/ModuleManager.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <svl/itempool.hxx>
45 #include <svl/intitem.hxx>
47 #include <sfx2/app.hxx>
48 #include <toolkit/unohlp.hxx>
50 #include "svx/srchdlg.hxx"
52 #include <svx/dialogs.hrc>
53 #include <svx/svxitems.hrc>
55 #include <svl/srchitem.hxx>
56 #include <svx/pageitem.hxx>
57 #include "srchctrl.hxx"
58 #include <svx/dialmgr.hxx>
59 #include "svx/dlgutil.hxx"
60 #include <editeng/brushitem.hxx>
61 #include <tools/resary.hxx>
62 #include <svx/svxdlg.hxx>
64 using namespace com::sun::star::i18n;
65 using namespace com::sun::star;
66 using namespace comphelper;
68 // -----------------------------------------------------------------------
70 #define REMEMBER_SIZE 10
72 #define MODIFY_SEARCH 0x00000001
73 #define MODIFY_REPLACE 0x00000002
74 #define MODIFY_WORD 0x00000004
75 #define MODIFY_EXACT 0x00000008
76 #define MODIFY_BACKWARDS 0x00000010
77 #define MODIFY_SELECTION 0x00000020
78 #define MODIFY_REGEXP 0x00000040
79 #define MODIFY_LAYOUT 0x00000080
80 #define MODIFY_SIMILARITY 0x00000100
81 #define MODIFY_FORMULAS 0x00000200
82 #define MODIFY_VALUES 0x00000400
83 #define MODIFY_CALC_NOTES 0x00000800
84 #define MODIFY_ROWS 0x00001000
85 #define MODIFY_COLUMNS 0x00002000
86 #define MODIFY_ALLTABLES 0x00004000
87 #define MODIFY_NOTES 0x00008000
89 namespace
91 bool GetCheckBoxValue(const CheckBox *pBox)
93 return pBox->IsEnabled() ? pBox->IsChecked() : false;
97 struct SearchDlg_Impl
99 FixedText* m_pSearchFormats;
100 FixedText* m_pReplaceFormats;
102 sal_Bool bMultiLineEdit : 1,
103 bSaveToModule : 1,
104 bFocusOnSearch : 1;
105 sal_uInt16* pRanges;
106 Timer aSelectionTimer;
108 uno::Reference< frame::XDispatch > xCommand1Dispatch;
109 uno::Reference< frame::XDispatch > xCommand2Dispatch;
110 util::URL aCommand1URL;
111 util::URL aCommand2URL;
113 SearchDlg_Impl( SvxSearchDialog* pParent )
114 : bMultiLineEdit(false)
115 , bSaveToModule(true)
116 , bFocusOnSearch(true)
117 , pRanges(NULL)
119 pParent->get(m_pSearchFormats, "searchformat");
120 m_pSearchFormats->SetStyle(m_pSearchFormats->GetStyle() | WB_PATHELLIPSIS);
121 pParent->get(m_pReplaceFormats, "replaceformat");
122 m_pReplaceFormats->SetStyle(m_pReplaceFormats->GetStyle() | WB_PATHELLIPSIS);
123 aCommand1URL.Complete = aCommand1URL.Main = OUString("vnd.sun.search:SearchViaComponent1");
124 aCommand1URL.Protocol = OUString("vnd.sun.search:");
125 aCommand1URL.Path = OUString("SearchViaComponent1");
126 aCommand2URL.Complete = aCommand2URL.Main = OUString("vnd.sun.search:SearchViaComponent2");
127 aCommand2URL.Protocol = OUString("vnd.sun.search:");
128 aCommand2URL.Path = OUString("SearchViaComponent2");
130 ~SearchDlg_Impl() { delete[] pRanges; }
133 void ListToStrArr_Impl( sal_uInt16 nId, std::vector<OUString>& rStrLst, ComboBox& rCBox )
135 SfxStringListItem* pSrchItem =
136 (SfxStringListItem*)SFX_APP()->GetItem( nId );
138 if (pSrchItem)
140 std::vector<String> aLst = pSrchItem->GetList();
142 for ( sal_uInt16 i = 0; i < aLst.size(); ++i )
144 rStrLst.push_back(aLst[i]);
145 rCBox.InsertEntry(aLst[i]);
150 void StrArrToList_Impl( sal_uInt16 nId, const std::vector<OUString>& rStrLst )
152 DBG_ASSERT( !rStrLst.empty(), "check in advance");
153 std::vector<String> aLst;
155 for (std::vector<OUString>::const_iterator i = rStrLst.begin(); i != rStrLst.end(); ++i)
156 aLst.push_back(String(*i));
158 SFX_APP()->PutItem( SfxStringListItem( nId, &aLst ) );
161 // class SearchAttrItemList ----------------------------------------------
163 SearchAttrItemList::SearchAttrItemList( const SearchAttrItemList& rList ) :
164 SrchAttrItemList(rList)
166 for ( sal_uInt16 i = 0; i < size(); ++i )
167 if ( !IsInvalidItem( (*this)[i].pItem ) )
168 (*this)[i].pItem = (*this)[i].pItem->Clone();
171 // -----------------------------------------------------------------------
173 SearchAttrItemList::~SearchAttrItemList()
175 Clear();
178 // -----------------------------------------------------------------------
180 void SearchAttrItemList::Put( const SfxItemSet& rSet )
182 if ( !rSet.Count() )
183 return;
185 SfxItemPool* pPool = rSet.GetPool();
186 SfxItemIter aIter( rSet );
187 SearchAttrItem aItem;
188 const SfxPoolItem* pItem = aIter.GetCurItem();
189 sal_uInt16 nWhich;
191 while ( true )
193 // only test that it is available?
194 if( IsInvalidItem( pItem ) )
196 nWhich = rSet.GetWhichByPos( aIter.GetCurPos() );
197 aItem.pItem = (SfxPoolItem*)pItem;
199 else
201 nWhich = pItem->Which();
202 aItem.pItem = pItem->Clone();
205 aItem.nSlot = pPool->GetSlotId( nWhich );
206 Insert( aItem );
208 if ( aIter.IsAtEnd() )
209 break;
210 pItem = aIter.NextItem();
214 // -----------------------------------------------------------------------
216 SfxItemSet& SearchAttrItemList::Get( SfxItemSet& rSet )
218 SfxItemPool* pPool = rSet.GetPool();
220 for ( sal_uInt16 i = 0; i < size(); ++i )
221 if ( IsInvalidItem( (*this)[i].pItem ) )
222 rSet.InvalidateItem( pPool->GetWhich( (*this)[i].nSlot ) );
223 else
224 rSet.Put( *(*this)[i].pItem );
225 return rSet;
228 // -----------------------------------------------------------------------
230 void SearchAttrItemList::Clear()
232 for ( sal_uInt16 i = 0; i < size(); ++i )
233 if ( !IsInvalidItem( (*this)[i].pItem ) )
234 delete (*this)[i].pItem;
235 SrchAttrItemList::clear();
238 // -----------------------------------------------------------------------
240 // Deletes the pointer to the items
241 void SearchAttrItemList::Remove(size_t nPos, size_t nLen)
243 if ( nPos + nLen > size() )
244 nLen = size() - nPos;
246 for ( sal_uInt16 i = nPos; i < nPos + nLen; ++i )
247 if ( !IsInvalidItem( (*this)[i].pItem ) )
248 delete (*this)[i].pItem;
250 SrchAttrItemList::erase( begin() + nPos, begin() + nPos + nLen );
253 // class SvxSearchDialog -------------------------------------------------
255 SvxSearchDialog::SvxSearchDialog( Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind )
256 : SfxModelessDialog(&rBind, pChildWin, pParent, "FindReplaceDialog",
257 "svx/ui/findreplacedialog.ui")
258 , rBindings(rBind)
259 , bWriter(false)
260 , bSearch(true)
261 , bFormat(false)
262 , nOptions(USHRT_MAX)
263 , bSet(false)
264 , bReadOnly(false)
265 , bConstruct(true)
266 , nModifyFlag(0)
267 , pImpl(NULL)
268 , pSearchList(NULL)
269 , pReplaceList(new SearchAttrItemList)
270 , pSearchItem(NULL)
271 , pSearchController(NULL)
272 , pOptionsController(NULL)
273 , pFamilyController(NULL)
274 , pSearchSetController(NULL)
275 , pReplaceSetController(NULL)
276 , nTransliterationFlags(0x00000000)
278 get(m_pSearchFrame, "searchframe");
279 get(m_pSearchLB, "searchterm");
280 get(m_pSearchTmplLB, "searchlist");
281 m_pSearchTmplLB->SetStyle(m_pSearchTmplLB->GetStyle() | WB_SORT);
282 get(m_pSearchBtn, "search");
283 get(m_pSearchAllBtn, "searchall");
284 get(m_pSearchAttrText, "searchdesc");
285 m_pSearchAttrText->SetStyle(m_pSearchAttrText->GetStyle() | WB_PATHELLIPSIS);
287 get(m_pReplaceFrame, "replaceframe");
288 get(m_pReplaceLB, "replaceterm");
289 get(m_pReplaceTmplLB, "replacelist");
290 m_pReplaceTmplLB->SetStyle(m_pReplaceTmplLB->GetStyle() | WB_SORT);
291 get(m_pReplaceBtn, "replace");
292 get(m_pReplaceAllBtn, "replaceall");
293 get(m_pReplaceAttrText, "replacedesc");
294 m_pReplaceAttrText->SetStyle(m_pReplaceAttrText->GetStyle() | WB_PATHELLIPSIS);
296 get(m_pComponentFrame, "componentframe");
297 get(m_pSearchComponent1PB, "component1");
298 get(m_pSearchComponent2PB, "component2");
300 get(m_pMatchCaseCB, "matchcase");
301 get(m_pWordBtn, "wholewords");
302 aCalcStr = get<FixedText>("entirecells")->GetText();
304 get(m_pCloseBtn, "close");
306 get(m_pSelectionBtn, "selection");
307 get(m_pBackwardsBtn, "backwards");
308 get(m_pRegExpBtn, "regexp");
309 get(m_pSimilarityBox, "similarity");
310 get(m_pSimilarityBtn, "similaritybtn");
311 get(m_pLayoutBtn, "layout");
312 get(m_pNotesBtn, "notes");
313 get(m_pJapMatchFullHalfWidthCB, "matchcharwidth");
314 get(m_pJapOptionsCB, "soundslike");
315 get(m_pJapOptionsBtn, "soundslikebtn");
317 get(m_pAttributeBtn, "attributes");
318 get(m_pFormatBtn, "format");
319 get(m_pNoFormatBtn, "noformat");
321 get(m_pCalcGrid, "calcgrid");
322 get(m_pCalcSearchInFT, "searchinlabel");
323 get(m_pCalcSearchInLB, "calcsearchin");
324 get(m_pCalcSearchDirFT, "searchdir");
325 get(m_pRowsBtn, "rows");
326 get(m_pColumnsBtn, "cols");
327 get(m_pAllSheetsCB, "allsheets");
329 m_pSimilarityBtn->set_height_request(m_pSimilarityBox->get_preferred_size().Height());
330 m_pJapOptionsBtn->set_height_request(m_pJapOptionsCB->get_preferred_size().Height());
332 long nTermWidth = approximate_char_width() * 32;
333 m_pSearchLB->set_width_request(nTermWidth);
334 m_pSearchTmplLB->set_width_request(nTermWidth);
335 m_pReplaceLB->set_width_request(nTermWidth);
336 m_pReplaceTmplLB->set_width_request(nTermWidth);
338 Construct_Impl();
341 // -----------------------------------------------------------------------
343 SvxSearchDialog::~SvxSearchDialog()
345 Hide();
347 rBindings.EnterRegistrations();
348 delete pSearchController;
349 delete pOptionsController;
350 delete pFamilyController;
351 delete pSearchSetController;
352 delete pReplaceSetController;
353 rBindings.LeaveRegistrations();
355 delete pSearchItem;
356 delete pImpl;
357 delete pSearchList;
358 delete pReplaceList;
361 void SvxSearchDialog::Construct_Impl()
363 // temporary to avoid incompatibility
364 pImpl = new SearchDlg_Impl( this );
365 pImpl->aSelectionTimer.SetTimeout( 500 );
366 pImpl->aSelectionTimer.SetTimeoutHdl(
367 LINK( this, SvxSearchDialog, TimeoutHdl_Impl ) );
368 EnableControls_Impl( 0 );
370 // Store old Text from m_pWordBtn
371 aCalcStr += sal_Unicode('#');
372 aCalcStr += m_pWordBtn->GetText();
374 aLayoutStr = SVX_RESSTR( RID_SVXSTR_SEARCH_STYLES );
375 aLayoutWriterStr = SVX_RESSTR( RID_SVXSTR_WRITER_STYLES );
376 aLayoutCalcStr = SVX_RESSTR( RID_SVXSTR_CALC_STYLES );
377 aStylesStr = m_pLayoutBtn->GetText();
379 // Get stored search-strings from the application
380 ListToStrArr_Impl(SID_SEARCHDLG_SEARCHSTRINGS,
381 aSearchStrings, *m_pSearchLB);
382 ListToStrArr_Impl(SID_SEARCHDLG_REPLACESTRINGS,
383 aReplaceStrings, *m_pReplaceLB);
385 InitControls_Impl();
387 // Get attribut sets only once in construtor()
388 const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
389 const SvxSetItem* pSrchSetItem =
390 (const SvxSetItem*) rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SFX_CALLMODE_SLOT, ppArgs );
392 if ( pSrchSetItem )
393 InitAttrList_Impl( &pSrchSetItem->GetItemSet(), 0 );
395 const SvxSetItem* pReplSetItem =
396 (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SFX_CALLMODE_SLOT, ppArgs );
398 if ( pReplSetItem )
399 InitAttrList_Impl( 0, &pReplSetItem->GetItemSet() );
401 // Create controller and update at once
402 rBindings.EnterRegistrations();
403 pSearchController =
404 new SvxSearchController( SID_SEARCH_ITEM, rBindings, *this );
405 pOptionsController =
406 new SvxSearchController( SID_SEARCH_OPTIONS, rBindings, *this );
407 rBindings.LeaveRegistrations();
408 rBindings.GetDispatcher()->Execute( FID_SEARCH_ON, SFX_CALLMODE_SLOT, ppArgs );
409 pImpl->aSelectionTimer.Start();
412 SvtCJKOptions aCJKOptions;
413 if(!aCJKOptions.IsJapaneseFindEnabled())
415 m_pJapOptionsCB->Check( sal_False );
416 m_pJapOptionsCB->Hide();
417 m_pJapOptionsBtn->Hide();
419 if(!aCJKOptions.IsCJKFontEnabled())
421 m_pJapMatchFullHalfWidthCB->Hide();
424 //component extension - show component search buttons if the commands
425 // vnd.sun.star::SearchViaComponent1 and 2 are supported
426 const uno::Reference< frame::XFrame >xFrame = rBindings.GetActiveFrame();
427 const uno::Reference< frame::XDispatchProvider > xDispatchProv(xFrame, uno::UNO_QUERY);
428 OUString sTarget("_self");
430 bool bSearchComponent1 = false;
431 bool bSearchComponent2 = false;
432 if(xDispatchProv.is() &&
433 (pImpl->xCommand1Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand1URL, sTarget, 0)).is())
435 bSearchComponent1 = true;
437 if(xDispatchProv.is() &&
438 (pImpl->xCommand2Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand2URL, sTarget, 0)).is())
440 bSearchComponent2 = true;
443 if( bSearchComponent1 || bSearchComponent2 )
447 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
448 configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
449 uno::Sequence< uno::Any > aArgs(1);
450 OUString sPath( "/org.openoffice.Office.Common/SearchOptions/");
451 aArgs[0] <<= sPath;
453 uno::Reference< uno::XInterface > xIFace = xConfigurationProvider->createInstanceWithArguments(
454 OUString( "com.sun.star.configuration.ConfigurationUpdateAccess"),
455 aArgs);
456 uno::Reference< container::XNameAccess> xDirectAccess(xIFace, uno::UNO_QUERY);
457 if(xDirectAccess.is())
459 OUString sTemp;
460 OUString sProperty( "ComponentSearchGroupLabel");
461 uno::Any aRet = xDirectAccess->getByName(sProperty);
462 aRet >>= sTemp;
463 m_pComponentFrame->get_label_widget()->SetText(sTemp);
464 aRet = xDirectAccess->getByName(OUString( "ComponentSearchCommandLabel1"));
465 aRet >>= sTemp;
466 m_pSearchComponent1PB->SetText( sTemp );
467 aRet = xDirectAccess->getByName(OUString( "ComponentSearchCommandLabel2"));
468 aRet >>= sTemp;
469 m_pSearchComponent2PB->SetText( sTemp );
472 catch(uno::Exception&){}
474 if(!m_pSearchComponent1PB->GetText().isEmpty() && bSearchComponent1 )
476 m_pComponentFrame->Show();
477 m_pSearchComponent1PB->Show();
479 if( !m_pSearchComponent2PB->GetText().isEmpty() )
481 m_pComponentFrame->Show();
482 m_pSearchComponent2PB->Show();
487 // -----------------------------------------------------------------------
489 sal_Bool SvxSearchDialog::Close()
491 // remember strings speichern
492 if (!aSearchStrings.empty())
493 StrArrToList_Impl( SID_SEARCHDLG_SEARCHSTRINGS, aSearchStrings );
495 if (!aReplaceStrings.empty())
496 StrArrToList_Impl( SID_SEARCHDLG_REPLACESTRINGS, aReplaceStrings );
498 // save settings to configuration
499 SvtSearchOptions aOpt;
500 aOpt.SetWholeWordsOnly ( m_pWordBtn->IsChecked() );
501 aOpt.SetBackwards ( m_pBackwardsBtn->IsChecked() );
502 aOpt.SetUseRegularExpression ( m_pRegExpBtn->IsChecked() );
503 aOpt.SetSearchForStyles ( m_pLayoutBtn->IsChecked() );
504 aOpt.SetSimilaritySearch ( m_pSimilarityBox->IsChecked() );
505 aOpt.SetUseAsianOptions ( m_pJapOptionsCB->IsChecked() );
506 aOpt.SetNotes ( m_pNotesBtn->IsChecked() );
508 const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
509 rBindings.GetDispatcher()->Execute( FID_SEARCH_OFF, SFX_CALLMODE_SLOT, ppArgs );
510 rBindings.Execute( SID_SEARCH_DLG );
512 return sal_True;
515 // -----------------------------------------------------------------------
517 sal_Int32 SvxSearchDialog::GetTransliterationFlags() const
519 if (!m_pMatchCaseCB->IsChecked())
520 nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
521 else
522 nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
523 if ( !m_pJapMatchFullHalfWidthCB->IsChecked())
524 nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
525 else
526 nTransliterationFlags &= ~TransliterationModules_IGNORE_WIDTH;
527 return nTransliterationFlags;
530 void SvxSearchDialog::SetSaveToModule(bool b)
532 pImpl->bSaveToModule = b;
535 // -----------------------------------------------------------------------
537 void SvxSearchDialog::ApplyTransliterationFlags_Impl( sal_Int32 nSettings )
539 nTransliterationFlags = nSettings;
540 sal_Bool bVal = 0 != (nSettings & TransliterationModules_IGNORE_CASE);
541 m_pMatchCaseCB->Check(!bVal );
542 bVal = 0 != (nSettings & TransliterationModules_IGNORE_WIDTH);
543 m_pJapMatchFullHalfWidthCB->Check( !bVal );
546 // -----------------------------------------------------------------------
548 void SvxSearchDialog::Activate()
550 // apply possible transliteration changes of the SvxSearchItem member
551 DBG_ASSERT( pSearchItem, "SearchItem missing" );
552 if (pSearchItem)
554 m_pMatchCaseCB->Check( pSearchItem->GetExact() );
555 m_pJapMatchFullHalfWidthCB->Check( !pSearchItem->IsMatchFullHalfWidthForms() );
559 // -----------------------------------------------------------------------
561 void SvxSearchDialog::InitControls_Impl()
563 // CaseSensitives AutoComplete
564 m_pSearchLB->EnableAutocomplete( sal_True, sal_True );
565 m_pSearchLB->Show();
566 m_pReplaceLB->EnableAutocomplete( sal_True, sal_True );
567 m_pReplaceLB->Show();
569 m_pFormatBtn->Disable();
570 m_pAttributeBtn->Disable();
572 m_pSearchLB->SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
573 m_pReplaceLB->SetModifyHdl( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
575 Link aLink = LINK( this, SvxSearchDialog, FocusHdl_Impl );
576 m_pSearchLB->SetGetFocusHdl( aLink );
577 pImpl->m_pSearchFormats->SetGetFocusHdl( aLink );
579 m_pReplaceLB->SetGetFocusHdl( aLink );
580 pImpl->m_pReplaceFormats->SetGetFocusHdl( aLink );
582 aLink = LINK( this, SvxSearchDialog, LoseFocusHdl_Impl );
583 m_pSearchLB->SetLoseFocusHdl( aLink );
584 m_pReplaceLB->SetLoseFocusHdl( aLink );
586 m_pSearchTmplLB->SetLoseFocusHdl( aLink );
587 m_pReplaceTmplLB->SetLoseFocusHdl( aLink );
589 aLink = LINK( this, SvxSearchDialog, CommandHdl_Impl );
590 m_pSearchBtn->SetClickHdl( aLink );
591 m_pSearchAllBtn->SetClickHdl( aLink );
592 m_pReplaceBtn->SetClickHdl( aLink );
593 m_pReplaceAllBtn->SetClickHdl( aLink );
594 m_pCloseBtn->SetClickHdl( aLink );
595 m_pSimilarityBtn->SetClickHdl( aLink );
596 m_pJapOptionsBtn->SetClickHdl( aLink );
597 m_pSearchComponent1PB->SetClickHdl( aLink );
598 m_pSearchComponent2PB->SetClickHdl( aLink );
600 aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
601 m_pWordBtn->SetClickHdl( aLink );
602 m_pSelectionBtn->SetClickHdl( aLink );
603 m_pMatchCaseCB->SetClickHdl( aLink );
604 m_pRegExpBtn->SetClickHdl( aLink );
605 m_pBackwardsBtn->SetClickHdl( aLink );
606 m_pNotesBtn->SetClickHdl( aLink );
607 m_pSimilarityBox->SetClickHdl( aLink );
608 m_pJapOptionsCB->SetClickHdl( aLink );
609 m_pJapMatchFullHalfWidthCB->SetClickHdl( aLink );
611 m_pLayoutBtn->SetClickHdl( LINK( this, SvxSearchDialog, TemplateHdl_Impl ) );
612 m_pFormatBtn->SetClickHdl( LINK( this, SvxSearchDialog, FormatHdl_Impl ) );
613 m_pNoFormatBtn->SetClickHdl(
614 LINK( this, SvxSearchDialog, NoFormatHdl_Impl ) );
615 m_pAttributeBtn->SetClickHdl(
616 LINK( this, SvxSearchDialog, AttributeHdl_Impl ) );
619 namespace
621 SvtModuleOptions::EFactory getModule(SfxBindings& rBindings)
623 SvtModuleOptions::EFactory eFactory(SvtModuleOptions::E_UNKNOWN_FACTORY);
626 const uno::Reference< frame::XFrame > xFrame =
627 rBindings.GetActiveFrame();
628 uno::Reference< frame::XModuleManager2 > xModuleManager(
629 frame::ModuleManager::create(::comphelper::getProcessComponentContext()));
631 OUString aModuleIdentifier = xModuleManager->identify( xFrame );
632 eFactory = SvtModuleOptions::ClassifyFactoryByServiceName(aModuleIdentifier);
634 catch (const uno::Exception&)
637 return eFactory;
641 void SvxSearchDialog::ShowOptionalControls_Impl()
643 DBG_ASSERT( pSearchItem, "no search item" );
645 SvtCJKOptions aCJKOptions;
647 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
648 bool bDrawApp = eFactory == SvtModuleOptions::E_DRAW;
649 bool bWriterApp =
650 eFactory == SvtModuleOptions::E_WRITER ||
651 eFactory == SvtModuleOptions::E_WRITERWEB ||
652 eFactory == SvtModuleOptions::E_WRITERGLOBAL;
653 bool bCalcApp = eFactory == SvtModuleOptions::E_CALC;
655 m_pLayoutBtn->Show(!bDrawApp);
656 m_pNotesBtn->Show(bWriterApp);
657 m_pBackwardsBtn->Show();
658 m_pRegExpBtn->Show(!bDrawApp);
659 m_pSimilarityBox->Show();
660 m_pSimilarityBtn->Show();
661 m_pSelectionBtn->Show();
663 m_pJapMatchFullHalfWidthCB->Show(aCJKOptions.IsCJKFontEnabled());
664 m_pJapOptionsCB->Show(aCJKOptions.IsJapaneseFindEnabled());
665 m_pJapOptionsBtn->Show(aCJKOptions.IsJapaneseFindEnabled());
667 if (bWriter)
669 m_pAttributeBtn->Show();
670 m_pFormatBtn->Show();
671 m_pNoFormatBtn->Show();
674 if (bCalcApp)
676 m_pCalcSearchInFT->Show();
677 m_pCalcSearchInLB->Show();
678 m_pCalcSearchDirFT->Show();
679 m_pRowsBtn->Show();
680 m_pColumnsBtn->Show();
681 m_pAllSheetsCB->Show();
685 // -----------------------------------------------------------------------
687 namespace {
689 class ToggleSaveToModule
691 public:
692 ToggleSaveToModule(SvxSearchDialog& rDialog, bool bValue) :
693 mrDialog(rDialog), mbValue(bValue)
695 mrDialog.SetSaveToModule(mbValue);
698 ~ToggleSaveToModule()
700 mrDialog.SetSaveToModule(!mbValue);
702 private:
703 SvxSearchDialog& mrDialog;
704 bool mbValue;
709 void SvxSearchDialog::Init_Impl( int bSearchPattern )
711 DBG_ASSERT( pSearchItem, "SearchItem == 0" );
713 // We don't want to save any intermediate state to the module while the
714 // dialog is being initialized.
715 ToggleSaveToModule aNoModuleSave(*this, false);
717 bWriter = ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_WRITER );
719 pImpl->bMultiLineEdit = sal_False;
721 if ( !pImpl->bMultiLineEdit )
723 pImpl->m_pSearchFormats->Hide();
724 m_pSearchAttrText->Show();
725 pImpl->m_pReplaceFormats->Hide();
726 m_pReplaceAttrText->Show();
728 else
730 String aText = m_pSearchAttrText->GetText();
731 m_pSearchAttrText->Hide();
733 if ( aText.Len() )
734 pImpl->m_pSearchFormats->SetText( aText );
735 pImpl->m_pSearchFormats->Show();
736 aText = m_pReplaceAttrText->GetText();
737 m_pReplaceAttrText->Hide();
739 if ( aText.Len() )
740 pImpl->m_pReplaceFormats->SetText( aText );
741 pImpl->m_pReplaceFormats->Show();
744 if ( ( nModifyFlag & MODIFY_WORD ) == 0 )
745 m_pWordBtn->Check( pSearchItem->GetWordOnly() );
746 if ( ( nModifyFlag & MODIFY_EXACT ) == 0 )
747 m_pMatchCaseCB->Check( pSearchItem->GetExact() );
748 if ( ( nModifyFlag & MODIFY_BACKWARDS ) == 0 )
749 m_pBackwardsBtn->Check( pSearchItem->GetBackward() );
750 if ( ( nModifyFlag & MODIFY_NOTES ) == 0 )
751 m_pNotesBtn->Check( pSearchItem->GetNotes() );
752 if ( ( nModifyFlag & MODIFY_SELECTION ) == 0 )
753 m_pSelectionBtn->Check( pSearchItem->GetSelection() );
754 if ( ( nModifyFlag & MODIFY_REGEXP ) == 0 )
755 m_pRegExpBtn->Check( pSearchItem->GetRegExp() );
756 if ( ( nModifyFlag & MODIFY_LAYOUT ) == 0 )
757 m_pLayoutBtn->Check( pSearchItem->GetPattern() );
758 if (m_pNotesBtn->IsChecked())
759 m_pLayoutBtn->Disable();
760 m_pSimilarityBox->Check( pSearchItem->IsLevenshtein() );
761 if( m_pJapOptionsCB->IsVisible() )
762 m_pJapOptionsCB->Check( pSearchItem->IsUseAsianOptions() );
763 ApplyTransliterationFlags_Impl( pSearchItem->GetTransliterationFlags() );
765 ShowOptionalControls_Impl();
767 bool bDraw = false;
768 if ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_CALC )
770 m_pCalcGrid->Show();
771 Link aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
772 m_pCalcSearchInLB->SetSelectHdl( aLink );
773 m_pRowsBtn->SetClickHdl( aLink );
774 m_pColumnsBtn->SetClickHdl( aLink );
775 m_pAllSheetsCB->SetClickHdl( aLink );
777 switch ( pSearchItem->GetCellType() )
779 case SVX_SEARCHIN_FORMULA:
780 if ( ( nModifyFlag & MODIFY_FORMULAS ) == 0 )
781 m_pCalcSearchInLB->SelectEntryPos( SVX_SEARCHIN_FORMULA );
782 break;
784 case SVX_SEARCHIN_VALUE:
785 if ( ( nModifyFlag & MODIFY_VALUES ) == 0 )
786 m_pCalcSearchInLB->SelectEntryPos( SVX_SEARCHIN_VALUE );
787 break;
789 case SVX_SEARCHIN_NOTE:
790 if ( ( nModifyFlag & MODIFY_CALC_NOTES ) == 0 )
791 m_pCalcSearchInLB->SelectEntryPos( SVX_SEARCHIN_NOTE );
792 break;
794 m_pWordBtn->SetText( aCalcStr.GetToken( 0, '#' ) );
796 if ( pSearchItem->GetRowDirection() &&
797 ( nModifyFlag & MODIFY_ROWS ) == 0 )
798 m_pRowsBtn->Check();
799 else if ( !pSearchItem->GetRowDirection() &&
800 ( nModifyFlag & MODIFY_COLUMNS ) == 0 )
801 m_pColumnsBtn->Check();
803 if ( ( nModifyFlag & MODIFY_ALLTABLES ) == 0 )
804 m_pAllSheetsCB->Check( pSearchItem->IsAllTables() );
806 // only look for formatting in Writer
807 m_pFormatBtn->Hide();
808 m_pNoFormatBtn->Hide();
809 m_pAttributeBtn->Hide();
811 else
813 m_pWordBtn->SetText( aCalcStr.GetToken( 1, '#' ) );
815 if ( pSearchItem->GetAppFlag() == SVX_SEARCHAPP_DRAW )
817 m_pSearchAllBtn->Hide();
819 m_pRegExpBtn->Hide();
820 m_pLayoutBtn->Hide();
822 // only look for formatting in Writer
823 m_pFormatBtn->Hide();
824 m_pNoFormatBtn->Hide();
825 m_pAttributeBtn->Hide();
826 bDraw = sal_True;
828 else
830 if ( !pSearchList )
832 // Get attribute sets, if it not has been done already
833 const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
834 const SvxSetItem* pSrchSetItem =
835 (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SFX_CALLMODE_SLOT, ppArgs );
837 if ( pSrchSetItem )
838 InitAttrList_Impl( &pSrchSetItem->GetItemSet(), 0 );
840 const SvxSetItem* pReplSetItem =
841 (const SvxSetItem*)rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SFX_CALLMODE_SLOT, ppArgs );
843 if ( pReplSetItem )
844 InitAttrList_Impl( 0, &pReplSetItem->GetItemSet() );
849 if ( 0 && !bDraw ) //!!!!!
851 m_pRegExpBtn->Show();
852 m_pLayoutBtn->Show();
855 // similarity search?
856 if ( ( nModifyFlag & MODIFY_SIMILARITY ) == 0 )
857 m_pSimilarityBox->Check( pSearchItem->IsLevenshtein() );
858 bSet = sal_True;
860 FlagHdl_Impl(m_pSimilarityBox);
861 FlagHdl_Impl(m_pJapOptionsCB);
863 bool bDisableSearch = false;
864 SfxViewShell* pViewShell = SfxViewShell::Current();
866 if ( pViewShell )
868 sal_Bool bText = !bSearchPattern;
870 if ( pViewShell->HasSelection( bText ) )
871 EnableControl_Impl(m_pSelectionBtn);
872 else
874 m_pSelectionBtn->Check( sal_False );
875 m_pSelectionBtn->Disable();
879 // Pattern Search and there were no AttrSets given
880 if ( bSearchPattern )
882 SfxObjectShell* pShell = SfxObjectShell::Current();
884 if ( pShell && pShell->GetStyleSheetPool() )
886 // Templates designed
887 m_pSearchTmplLB->Clear();
888 m_pReplaceTmplLB->Clear();
889 SfxStyleSheetBasePool* pStylePool = pShell->GetStyleSheetPool();
890 pStylePool->SetSearchMask( pSearchItem->GetFamily(),
891 SFXSTYLEBIT_ALL );
892 SfxStyleSheetBase* pBase = pStylePool->First();
894 while ( pBase )
896 if ( pBase->IsUsed() )
897 m_pSearchTmplLB->InsertEntry( pBase->GetName() );
898 m_pReplaceTmplLB->InsertEntry( pBase->GetName() );
899 pBase = pStylePool->Next();
901 m_pSearchTmplLB->SelectEntry( pSearchItem->GetSearchString() );
902 m_pReplaceTmplLB->SelectEntry( pSearchItem->GetReplaceString() );
905 m_pSearchTmplLB->Show();
907 if ( bConstruct )
908 // Grab focus only after creating
909 m_pSearchTmplLB->GrabFocus();
910 m_pReplaceTmplLB->Show();
911 m_pSearchLB->Hide();
912 m_pReplaceLB->Hide();
914 m_pWordBtn->Disable();
915 m_pRegExpBtn->Disable();
916 m_pMatchCaseCB->Disable();
918 bDisableSearch = !m_pSearchTmplLB->GetEntryCount();
920 else
922 bool bSetSearch = ( ( nModifyFlag & MODIFY_SEARCH ) == 0 );
923 bool bSetReplace = ( ( nModifyFlag & MODIFY_REPLACE ) == 0 );
925 if ( pSearchItem->GetSearchString().Len() && bSetSearch )
926 m_pSearchLB->SetText( pSearchItem->GetSearchString() );
927 else if (!aSearchStrings.empty())
929 bool bAttributes =
930 ( ( pSearchList && pSearchList->Count() ) ||
931 ( pReplaceList && pReplaceList->Count() ) );
933 if ( bSetSearch && !bAttributes )
934 m_pSearchLB->SetText(aSearchStrings[0]);
936 String aReplaceTxt = pSearchItem->GetReplaceString();
938 if (!aReplaceStrings.empty())
939 aReplaceTxt = aReplaceStrings[0];
941 if ( bSetReplace && !bAttributes )
942 m_pReplaceLB->SetText( aReplaceTxt );
944 m_pSearchLB->Show();
946 if ( bConstruct )
947 // Grab focus only after creating
948 m_pSearchLB->GrabFocus();
949 m_pReplaceLB->Show();
950 m_pSearchTmplLB->Hide();
951 m_pReplaceTmplLB->Hide();
953 EnableControl_Impl(m_pRegExpBtn);
954 EnableControl_Impl(m_pMatchCaseCB);
956 if ( m_pRegExpBtn->IsChecked() )
957 m_pWordBtn->Disable();
958 else
959 EnableControl_Impl(m_pWordBtn);
961 OUString aSrchAttrTxt;
963 if ( pImpl->bMultiLineEdit )
964 aSrchAttrTxt = pImpl->m_pSearchFormats->GetText();
965 else
966 aSrchAttrTxt = m_pSearchAttrText->GetText();
968 bDisableSearch = m_pSearchLB->GetText().isEmpty() && aSrchAttrTxt.isEmpty();
970 FocusHdl_Impl(m_pSearchLB);
972 if ( bDisableSearch )
974 m_pSearchBtn->Disable();
975 m_pSearchAllBtn->Disable();
976 m_pReplaceBtn->Disable();
977 m_pReplaceAllBtn->Disable();
978 m_pComponentFrame->Enable(sal_False);
980 else
982 EnableControl_Impl(m_pSearchBtn);
983 EnableControl_Impl(m_pReplaceBtn);
984 if (!bWriter || (bWriter && !m_pNotesBtn->IsChecked()))
986 EnableControl_Impl(m_pSearchAllBtn);
987 EnableControl_Impl(m_pReplaceAllBtn);
989 if (bWriter && pSearchItem->GetNotes())
991 m_pSearchAllBtn->Disable();
992 m_pReplaceAllBtn->Disable();
996 if ( ( !pImpl->bMultiLineEdit && !m_pSearchAttrText->GetText().isEmpty() ) ||
997 ( pImpl->bMultiLineEdit && !pImpl->m_pSearchFormats->GetText().isEmpty() ) )
998 EnableControl_Impl(m_pNoFormatBtn);
999 else
1000 m_pNoFormatBtn->Disable();
1002 if ( !pSearchList )
1004 m_pAttributeBtn->Disable();
1005 m_pFormatBtn->Disable();
1008 if ( m_pLayoutBtn->IsChecked() )
1010 pImpl->bSaveToModule = sal_False;
1011 TemplateHdl_Impl(m_pLayoutBtn);
1012 pImpl->bSaveToModule = sal_True;
1016 // -----------------------------------------------------------------------
1018 void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
1019 const SfxItemSet* pRSet )
1021 if ( !pSSet && !pRSet )
1022 return;
1024 if ( !pImpl->pRanges && pSSet )
1026 sal_sSize nCnt = 0;
1027 const sal_uInt16* pPtr = pSSet->GetRanges();
1028 const sal_uInt16* pTmp = pPtr;
1030 while( *pPtr )
1032 nCnt += ( *(pPtr+1) - *pPtr ) + 1;
1033 pPtr += 2;
1035 nCnt = pPtr - pTmp + 1;
1036 pImpl->pRanges = new sal_uInt16[nCnt];
1037 memcpy( pImpl->pRanges, pTmp, sizeof(sal_uInt16) * nCnt );
1040 // See to it that are the texts of the attributes are correct
1041 String aDesc;
1043 if ( pSSet )
1045 delete pSearchList;
1046 pSearchList = new SearchAttrItemList;
1048 if ( pSSet->Count() )
1050 pSearchList->Put( *pSSet );
1052 if ( !pImpl->bMultiLineEdit )
1053 m_pSearchAttrText->SetText( BuildAttrText_Impl( aDesc, sal_True ) );
1054 else
1055 pImpl->m_pSearchFormats->SetText( BuildAttrText_Impl( aDesc, sal_True ) );
1057 if ( aDesc.Len() )
1058 bFormat |= sal_True;
1062 if ( pRSet )
1064 delete pReplaceList;
1065 pReplaceList = new SearchAttrItemList;
1067 if ( pRSet->Count() )
1069 pReplaceList->Put( *pRSet );
1071 if ( !pImpl->bMultiLineEdit )
1072 m_pReplaceAttrText->SetText( BuildAttrText_Impl( aDesc, sal_False ) );
1073 else
1074 pImpl->m_pReplaceFormats->SetText( BuildAttrText_Impl( aDesc, sal_False ) );
1076 if ( aDesc.Len() )
1077 bFormat |= sal_True;
1082 // -----------------------------------------------------------------------
1084 IMPL_LINK( SvxSearchDialog, FlagHdl_Impl, Control *, pCtrl )
1086 if ( pCtrl && !bSet )
1087 SetModifyFlag_Impl( pCtrl );
1088 else
1089 bSet = sal_False;
1091 if (pCtrl == m_pSimilarityBox)
1093 sal_Bool bIsChecked = m_pSimilarityBox->IsChecked();
1095 if ( bIsChecked )
1097 m_pSimilarityBtn->Enable();
1098 m_pRegExpBtn->Check( sal_False );
1099 m_pRegExpBtn->Disable();
1100 EnableControl_Impl(m_pWordBtn);
1102 if ( m_pLayoutBtn->IsChecked() )
1104 EnableControl_Impl(m_pMatchCaseCB);
1105 m_pLayoutBtn->Check( sal_False );
1107 m_pRegExpBtn->Disable();
1108 m_pLayoutBtn->Disable();
1109 m_pFormatBtn->Disable();
1110 m_pNoFormatBtn->Disable();
1111 m_pAttributeBtn->Disable();
1113 else
1115 EnableControl_Impl(m_pRegExpBtn);
1116 if (!m_pNotesBtn->IsChecked())
1117 EnableControl_Impl(m_pLayoutBtn);
1118 EnableControl_Impl(m_pFormatBtn);
1119 EnableControl_Impl(m_pAttributeBtn);
1120 m_pSimilarityBtn->Disable();
1122 pSearchItem->SetLevenshtein( bIsChecked );
1124 else if (pCtrl == m_pNotesBtn)
1126 if (m_pNotesBtn->IsChecked())
1128 m_pLayoutBtn->Disable();
1129 m_pSearchAllBtn->Disable();
1130 m_pReplaceAllBtn->Disable();
1132 else
1134 EnableControl_Impl(m_pLayoutBtn);
1135 ModifyHdl_Impl(m_pSearchLB);
1138 else
1140 if ( m_pLayoutBtn->IsChecked() && !bFormat )
1142 m_pWordBtn->Check( sal_False );
1143 m_pWordBtn->Disable();
1144 m_pRegExpBtn->Check( sal_False );
1145 m_pRegExpBtn->Disable();
1146 m_pMatchCaseCB->Check( sal_False );
1147 m_pMatchCaseCB->Disable();
1148 m_pNotesBtn->Disable();
1150 if ( m_pSearchTmplLB->GetEntryCount() )
1152 EnableControl_Impl(m_pSearchBtn);
1153 EnableControl_Impl(m_pSearchAllBtn);
1154 EnableControl_Impl(m_pReplaceBtn);
1155 EnableControl_Impl(m_pReplaceAllBtn);
1158 else
1160 EnableControl_Impl(m_pRegExpBtn);
1161 EnableControl_Impl(m_pMatchCaseCB);
1162 EnableControl_Impl(m_pNotesBtn);
1164 if ( m_pRegExpBtn->IsChecked() )
1166 m_pWordBtn->Check( sal_False );
1167 m_pWordBtn->Disable();
1168 m_pSimilarityBox->Disable();
1169 m_pSimilarityBtn->Disable();
1171 else
1173 EnableControl_Impl(m_pWordBtn);
1174 EnableControl_Impl(m_pSimilarityBox);
1177 // Search-string in place? then enable Buttons
1178 bSet = sal_True;
1179 ModifyHdl_Impl(m_pSearchLB);
1183 if (m_pAllSheetsCB == pCtrl)
1185 if ( m_pAllSheetsCB->IsChecked() )
1186 m_pSearchAllBtn->Disable();
1187 else
1189 bSet = sal_True;
1190 ModifyHdl_Impl(m_pSearchLB);
1194 if (m_pJapOptionsCB == pCtrl)
1196 sal_Bool bEnableJapOpt = m_pJapOptionsCB->IsChecked();
1197 m_pMatchCaseCB->Enable(!bEnableJapOpt );
1198 m_pJapMatchFullHalfWidthCB->Enable(!bEnableJapOpt );
1199 m_pJapOptionsBtn->Enable( bEnableJapOpt );
1202 if ( pImpl->bSaveToModule )
1203 SaveToModule_Impl();
1204 return 0;
1207 // -----------------------------------------------------------------------
1209 IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
1211 bool bInclusive = ( m_pLayoutBtn->GetText() == OUString(aLayoutStr) );
1213 if ( ( pBtn == m_pSearchBtn ) ||
1214 ( pBtn == m_pSearchAllBtn )||
1215 ( pBtn == m_pReplaceBtn ) ||
1216 ( pBtn == m_pReplaceAllBtn ) )
1218 if ( m_pLayoutBtn->IsChecked() && !bInclusive )
1220 pSearchItem->SetSearchString ( m_pSearchTmplLB->GetSelectEntry() );
1221 pSearchItem->SetReplaceString( m_pReplaceTmplLB->GetSelectEntry() );
1223 else
1225 pSearchItem->SetSearchString ( m_pSearchLB->GetText() );
1226 pSearchItem->SetReplaceString( m_pReplaceLB->GetText() );
1228 if ( pBtn == m_pReplaceBtn )
1229 Remember_Impl( m_pReplaceLB->GetText(), sal_False );
1230 else
1232 Remember_Impl( m_pSearchLB->GetText(), sal_True );
1234 if ( pBtn == m_pReplaceAllBtn )
1235 Remember_Impl( m_pReplaceLB->GetText(), sal_False );
1239 pSearchItem->SetRegExp( sal_False );
1240 pSearchItem->SetLevenshtein( sal_False );
1241 if (GetCheckBoxValue(m_pRegExpBtn))
1242 pSearchItem->SetRegExp( sal_True );
1243 else if (GetCheckBoxValue(m_pSimilarityBox))
1244 pSearchItem->SetLevenshtein( sal_True );
1246 pSearchItem->SetWordOnly(GetCheckBoxValue(m_pWordBtn));
1247 pSearchItem->SetBackward(GetCheckBoxValue(m_pBackwardsBtn));
1248 pSearchItem->SetNotes(GetCheckBoxValue(m_pNotesBtn));
1249 pSearchItem->SetPattern(GetCheckBoxValue(m_pLayoutBtn));
1250 pSearchItem->SetSelection(GetCheckBoxValue(m_pSelectionBtn));
1252 pSearchItem->SetUseAsianOptions(GetCheckBoxValue(m_pJapOptionsCB));
1253 sal_Int32 nFlags = GetTransliterationFlags();
1254 if( !pSearchItem->IsUseAsianOptions())
1255 nFlags &= (TransliterationModules_IGNORE_CASE |
1256 TransliterationModules_IGNORE_WIDTH );
1257 pSearchItem->SetTransliterationFlags( nFlags );
1259 if ( !bWriter )
1261 if ( m_pCalcSearchInLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
1262 pSearchItem->SetCellType( m_pCalcSearchInLB->GetSelectEntryPos() );
1264 pSearchItem->SetRowDirection( m_pRowsBtn->IsChecked() );
1265 pSearchItem->SetAllTables( m_pAllSheetsCB->IsChecked() );
1268 if (pBtn == m_pSearchBtn)
1269 pSearchItem->SetCommand( SVX_SEARCHCMD_FIND );
1270 else if ( pBtn == m_pSearchAllBtn )
1271 pSearchItem->SetCommand( SVX_SEARCHCMD_FIND_ALL );
1272 else if ( pBtn == m_pReplaceBtn )
1273 pSearchItem->SetCommand( SVX_SEARCHCMD_REPLACE );
1274 else if ( pBtn == m_pReplaceAllBtn )
1275 pSearchItem->SetCommand( SVX_SEARCHCMD_REPLACE_ALL );
1277 // when looking for templates, delete format lists
1278 if ( !bFormat && pSearchItem->GetPattern() )
1280 if ( pSearchList )
1281 pSearchList->Clear();
1283 if ( pReplaceList )
1284 pReplaceList->Clear();
1286 nModifyFlag = 0;
1287 const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
1288 rBindings.ExecuteSynchron( FID_SEARCH_NOW, ppArgs, 0L );
1290 else if ( pBtn == m_pCloseBtn )
1292 if ( !m_pLayoutBtn->IsChecked() || bInclusive )
1294 String aStr( m_pSearchLB->GetText() );
1296 if ( aStr.Len() )
1297 Remember_Impl( aStr, sal_True );
1298 aStr = m_pReplaceLB->GetText();
1300 if ( aStr.Len() )
1301 Remember_Impl( aStr, sal_False );
1303 SaveToModule_Impl();
1304 Close();
1306 else if (pBtn == m_pSimilarityBtn)
1308 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1309 if(pFact)
1311 AbstractSvxSearchSimilarityDialog* pDlg = pFact->CreateSvxSearchSimilarityDialog( this,
1312 pSearchItem->IsLEVRelaxed(),
1313 pSearchItem->GetLEVOther(),
1314 pSearchItem->GetLEVShorter(),
1315 pSearchItem->GetLEVLonger() );
1316 DBG_ASSERT(pDlg, "Dialogdiet fail!");
1317 if ( pDlg && pDlg->Execute() == RET_OK )
1319 pSearchItem->SetLEVRelaxed( pDlg->IsRelaxed() );
1320 pSearchItem->SetLEVOther( pDlg->GetOther() );
1321 pSearchItem->SetLEVShorter( pDlg->GetShorter() );
1322 pSearchItem->SetLEVLonger( pDlg->GetLonger() );
1323 SaveToModule_Impl();
1325 delete pDlg;
1328 else if (pBtn == m_pJapOptionsBtn)
1330 SfxItemSet aSet( SFX_APP()->GetPool() );
1331 pSearchItem->SetTransliterationFlags( GetTransliterationFlags() );
1332 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1333 if(pFact)
1335 AbstractSvxJSearchOptionsDialog* aDlg = pFact->CreateSvxJSearchOptionsDialog( this, aSet,
1336 pSearchItem->GetTransliterationFlags() );
1337 DBG_ASSERT(aDlg, "Dialogdiet fail!");
1338 int nRet = aDlg->Execute();
1339 if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true
1341 sal_Int32 nFlags = aDlg->GetTransliterationFlags();
1342 pSearchItem->SetTransliterationFlags( nFlags );
1343 ApplyTransliterationFlags_Impl( nFlags );
1345 delete aDlg;
1348 else if (pBtn == m_pSearchComponent1PB || pBtn == m_pSearchComponent2PB)
1350 uno::Sequence < beans::PropertyValue > aArgs(2);
1351 beans::PropertyValue* pArgs = aArgs.getArray();
1352 pArgs[0].Name = OUString("SearchString");
1353 pArgs[0].Value <<= OUString(m_pSearchLB->GetText());
1354 pArgs[1].Name = OUString("ParentWindow");
1355 pArgs[1].Value <<= VCLUnoHelper::GetInterface( this );
1356 if(pBtn == m_pSearchComponent1PB)
1358 if ( pImpl->xCommand1Dispatch.is() )
1359 pImpl->xCommand1Dispatch->dispatch(pImpl->aCommand1URL, aArgs);
1361 else
1363 if ( pImpl->xCommand2Dispatch.is() )
1364 pImpl->xCommand2Dispatch->dispatch(pImpl->aCommand2URL, aArgs);
1368 return 0;
1371 // -----------------------------------------------------------------------
1373 IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, ComboBox *, pEd )
1375 if ( !bSet )
1376 SetModifyFlag_Impl( pEd );
1377 else
1378 bSet = sal_False;
1380 // Calc allows searching for empty cells.
1381 bool bAllowEmptySearch = (pSearchItem->GetAppFlag() == SVX_SEARCHAPP_CALC);
1383 if ( pEd == m_pSearchLB || pEd == m_pReplaceLB )
1385 sal_Int32 nSrchTxtLen = m_pSearchLB->GetText().getLength();
1386 sal_Int32 nReplTxtLen = 0;
1387 if (bAllowEmptySearch)
1388 nReplTxtLen = m_pReplaceLB->GetText().getLength();
1389 xub_StrLen nAttrTxtLen = 0;
1391 if ( !pImpl->bMultiLineEdit )
1392 nAttrTxtLen = m_pSearchAttrText->GetText().getLength();
1393 else
1394 nAttrTxtLen = pImpl->m_pSearchFormats->GetText().getLength();
1396 if (nSrchTxtLen || nReplTxtLen || nAttrTxtLen)
1398 EnableControl_Impl(m_pSearchBtn);
1399 EnableControl_Impl(m_pReplaceBtn);
1400 if (!bWriter || (bWriter && !m_pNotesBtn->IsChecked()))
1402 EnableControl_Impl(m_pSearchAllBtn);
1403 EnableControl_Impl(m_pReplaceAllBtn);
1406 else
1408 m_pComponentFrame->Enable(sal_False);
1409 m_pSearchBtn->Disable();
1410 m_pSearchAllBtn->Disable();
1411 m_pReplaceBtn->Disable();
1412 m_pReplaceAllBtn->Disable();
1415 return 0;
1418 // -----------------------------------------------------------------------
1420 IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl)
1422 if ( pImpl->bSaveToModule )
1423 SaveToModule_Impl();
1425 if ( bFormat )
1426 return 0;
1427 String sDesc;
1429 if ( m_pLayoutBtn->IsChecked() )
1431 if ( !pFamilyController )
1433 sal_uInt16 nId = 0;
1435 // Enable templates controller
1436 switch ( pSearchItem->GetFamily() )
1438 case SFX_STYLE_FAMILY_CHAR:
1439 nId = SID_STYLE_FAMILY1; break;
1441 case SFX_STYLE_FAMILY_PARA:
1442 nId = SID_STYLE_FAMILY2; break;
1444 case SFX_STYLE_FAMILY_FRAME:
1445 nId = SID_STYLE_FAMILY3; break;
1447 case SFX_STYLE_FAMILY_PAGE:
1448 nId = SID_STYLE_FAMILY4; break;
1450 case SFX_STYLE_FAMILY_ALL:
1451 break;
1453 default:
1454 OSL_FAIL( "StyleSheetFamily was changed?" );
1457 rBindings.EnterRegistrations();
1458 pFamilyController =
1459 new SvxSearchController( nId, rBindings, *this );
1460 rBindings.LeaveRegistrations();
1461 m_pSearchTmplLB->Clear();
1462 m_pReplaceTmplLB->Clear();
1464 m_pSearchTmplLB->Show();
1465 m_pReplaceTmplLB->Show();
1466 m_pSearchLB->Hide();
1467 m_pReplaceLB->Hide();
1469 if ( !pImpl->bMultiLineEdit )
1471 m_pSearchAttrText->SetText( sDesc );
1472 m_pReplaceAttrText->SetText( sDesc );
1474 else
1476 pImpl->m_pSearchFormats->SetText( sDesc );
1477 pImpl->m_pReplaceFormats->SetText( sDesc );
1480 m_pFormatBtn->Disable();
1481 m_pNoFormatBtn->Disable();
1482 m_pAttributeBtn->Disable();
1483 m_pSimilarityBox->Disable();
1484 m_pSimilarityBtn->Disable();
1486 else
1488 // Disable templates controller
1489 rBindings.EnterRegistrations();
1490 DELETEZ( pFamilyController );
1491 rBindings.LeaveRegistrations();
1493 m_pSearchLB->Show();
1494 m_pReplaceLB->Show();
1495 m_pSearchTmplLB->Hide();
1496 m_pReplaceTmplLB->Hide();
1498 if ( !pImpl->bMultiLineEdit )
1500 m_pSearchAttrText->SetText( BuildAttrText_Impl( sDesc, sal_True ) );
1501 m_pReplaceAttrText->SetText( BuildAttrText_Impl( sDesc, sal_False ) );
1503 else
1505 pImpl->m_pSearchFormats->SetText( BuildAttrText_Impl( sDesc, sal_True ) );
1506 pImpl->m_pReplaceFormats->SetText( BuildAttrText_Impl( sDesc, sal_False ) );
1509 EnableControl_Impl(m_pFormatBtn);
1510 EnableControl_Impl(m_pAttributeBtn);
1511 EnableControl_Impl(m_pSimilarityBox);
1513 FocusHdl_Impl( bSearch ? m_pSearchLB : m_pReplaceLB );
1515 bSet = sal_True;
1516 pImpl->bSaveToModule = sal_False;
1517 FlagHdl_Impl(m_pLayoutBtn);
1518 pImpl->bSaveToModule = sal_True;
1519 return 0;
1522 // -----------------------------------------------------------------------
1524 void SvxSearchDialog::Remember_Impl( const String &rStr,sal_Bool _bSearch )
1526 if ( !rStr.Len() )
1527 return;
1529 std::vector<OUString>* pArr = _bSearch ? &aSearchStrings : &aReplaceStrings;
1530 ComboBox* pListBox = _bSearch ? m_pSearchLB : m_pReplaceLB;
1532 // ignore identical strings
1533 for (std::vector<OUString>::const_iterator i = pArr->begin(); i != pArr->end(); ++i)
1535 if ((*i).equals(rStr))
1536 return;
1539 // delete oldest entry at maximum occupancy (ListBox and Array)
1540 if(REMEMBER_SIZE < pArr->size())
1542 pListBox->RemoveEntry( sal_uInt16(REMEMBER_SIZE - 1) );
1543 (*pArr)[REMEMBER_SIZE - 1] = rStr;
1544 pArr->erase(pArr->begin() + REMEMBER_SIZE - 1);
1547 pArr->insert(pArr->begin(), rStr);
1548 pListBox->InsertEntry(rStr, 0);
1551 // -----------------------------------------------------------------------
1553 void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool )
1555 String aOldSrch( m_pSearchTmplLB->GetSelectEntry() );
1556 String aOldRepl( m_pReplaceTmplLB->GetSelectEntry() );
1557 m_pSearchTmplLB->Clear();
1558 m_pReplaceTmplLB->Clear();
1559 rPool.SetSearchMask( pSearchItem->GetFamily(), SFXSTYLEBIT_ALL );
1560 m_pSearchTmplLB->SetUpdateMode( sal_False );
1561 m_pReplaceTmplLB->SetUpdateMode( sal_False );
1562 SfxStyleSheetBase* pBase = rPool.First();
1564 while ( pBase )
1566 if ( pBase->IsUsed() )
1567 m_pSearchTmplLB->InsertEntry( pBase->GetName() );
1568 m_pReplaceTmplLB->InsertEntry( pBase->GetName() );
1569 pBase = rPool.Next();
1571 m_pSearchTmplLB->SetUpdateMode( sal_True );
1572 m_pReplaceTmplLB->SetUpdateMode( sal_True );
1573 m_pSearchTmplLB->SelectEntryPos(0);
1575 if ( aOldSrch.Len() )
1576 m_pSearchTmplLB->SelectEntry( aOldSrch );
1577 m_pReplaceTmplLB->SelectEntryPos(0);
1579 if ( aOldRepl.Len() )
1580 m_pReplaceTmplLB->SelectEntry( aOldRepl );
1582 if ( m_pSearchTmplLB->GetEntryCount() )
1584 EnableControl_Impl(m_pSearchBtn);
1585 EnableControl_Impl(m_pSearchAllBtn);
1586 EnableControl_Impl(m_pReplaceBtn);
1587 EnableControl_Impl(m_pReplaceAllBtn);
1591 // -----------------------------------------------------------------------
1593 void SvxSearchDialog::EnableControls_Impl( const sal_uInt16 nFlags )
1595 if ( nFlags == nOptions )
1596 return;
1597 else
1598 nOptions = nFlags;
1600 if ( !nOptions )
1602 if ( IsVisible() )
1604 Hide();
1605 return;
1608 else if ( !IsVisible() )
1609 Show();
1610 bool bNoSearch = true;
1612 sal_Bool bEnableSearch = ( SEARCH_OPTIONS_SEARCH & nOptions ) != 0;
1613 m_pSearchBtn->Enable(bEnableSearch);
1615 if( bEnableSearch )
1616 bNoSearch = false;
1619 if ( ( SEARCH_OPTIONS_SEARCH_ALL & nOptions ) != 0 )
1621 m_pSearchAllBtn->Enable();
1622 bNoSearch = false;
1624 else
1625 m_pSearchAllBtn->Disable();
1626 if ( ( SEARCH_OPTIONS_REPLACE & nOptions ) != 0 )
1628 m_pReplaceBtn->Enable();
1629 m_pReplaceFrame->get_label_widget()->Enable();
1630 m_pReplaceLB->Enable();
1631 m_pReplaceTmplLB->Enable();
1632 bNoSearch = false;
1634 else
1636 m_pReplaceBtn->Disable();
1637 m_pReplaceFrame->get_label_widget()->Disable();
1638 m_pReplaceLB->Disable();
1639 m_pReplaceTmplLB->Disable();
1641 if ( ( SEARCH_OPTIONS_REPLACE_ALL & nOptions ) != 0 )
1643 m_pReplaceAllBtn->Enable();
1644 bNoSearch = false;
1646 else
1647 m_pReplaceAllBtn->Disable();
1648 m_pComponentFrame->Enable(!bNoSearch);
1649 m_pSearchBtn->Enable( !bNoSearch );
1650 m_pSearchFrame->get_label_widget()->Enable( !bNoSearch );
1651 m_pSearchLB->Enable( !bNoSearch );
1652 m_pNotesBtn->Enable();
1654 if ( ( SEARCH_OPTIONS_WHOLE_WORDS & nOptions ) != 0 )
1655 m_pWordBtn->Enable();
1656 else
1657 m_pWordBtn->Disable();
1658 if ( ( SEARCH_OPTIONS_BACKWARDS & nOptions ) != 0 )
1659 m_pBackwardsBtn->Enable();
1660 else
1661 m_pBackwardsBtn->Disable();
1662 if ( ( SEARCH_OPTIONS_REG_EXP & nOptions ) != 0 )
1663 m_pRegExpBtn->Enable();
1664 else
1665 m_pRegExpBtn->Disable();
1666 if ( ( SEARCH_OPTIONS_EXACT & nOptions ) != 0 )
1667 m_pMatchCaseCB->Enable();
1668 else
1669 m_pMatchCaseCB->Disable();
1670 if ( ( SEARCH_OPTIONS_SELECTION & nOptions ) != 0 )
1671 m_pSelectionBtn->Enable();
1672 else
1673 m_pSelectionBtn->Disable();
1674 if ( ( SEARCH_OPTIONS_FAMILIES & nOptions ) != 0 )
1675 m_pLayoutBtn->Enable();
1676 else
1677 m_pLayoutBtn->Disable();
1678 if ( ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1680 m_pAttributeBtn->Enable();
1681 m_pFormatBtn->Enable();
1682 m_pNoFormatBtn->Enable();
1684 else
1686 m_pAttributeBtn->Disable();
1687 m_pFormatBtn->Disable();
1688 m_pNoFormatBtn->Disable();
1691 if ( ( SEARCH_OPTIONS_SIMILARITY & nOptions ) != 0 )
1693 m_pSimilarityBox->Enable();
1694 m_pSimilarityBtn->Enable();
1696 else
1698 m_pSimilarityBox->Disable();
1699 m_pSimilarityBtn->Disable();
1702 if ( pSearchItem )
1703 Init_Impl( pSearchItem->GetPattern() &&
1704 ( !pSearchList || !pSearchList->Count() ) );
1707 // -----------------------------------------------------------------------
1709 void SvxSearchDialog::EnableControl_Impl( Control* pCtrl )
1711 if (m_pSearchBtn == pCtrl && ( SEARCH_OPTIONS_SEARCH & nOptions ) != 0)
1713 m_pComponentFrame->Enable();
1714 m_pSearchBtn->Enable();
1715 return;
1717 if ( m_pSearchAllBtn == pCtrl &&
1718 ( SEARCH_OPTIONS_SEARCH_ALL & nOptions ) != 0 )
1720 m_pSearchAllBtn->Enable( ( bWriter || !m_pAllSheetsCB->IsChecked() ) );
1721 return;
1723 if ( m_pReplaceBtn == pCtrl && ( SEARCH_OPTIONS_REPLACE & nOptions ) != 0 )
1725 m_pReplaceBtn->Enable();
1726 return;
1728 if ( m_pReplaceAllBtn == pCtrl &&
1729 ( SEARCH_OPTIONS_REPLACE_ALL & nOptions ) != 0 )
1731 m_pReplaceAllBtn->Enable();
1732 return;
1734 if ( m_pWordBtn == pCtrl && ( SEARCH_OPTIONS_WHOLE_WORDS & nOptions ) != 0 )
1736 m_pWordBtn->Enable();
1737 return;
1739 if ( m_pBackwardsBtn == pCtrl && ( SEARCH_OPTIONS_BACKWARDS & nOptions ) != 0 )
1741 m_pBackwardsBtn->Enable();
1742 return;
1744 if (m_pNotesBtn == pCtrl)
1746 m_pNotesBtn->Enable();
1747 return;
1749 if ( m_pRegExpBtn == pCtrl && ( SEARCH_OPTIONS_REG_EXP & nOptions ) != 0
1750 && !m_pSimilarityBox->IsChecked())
1752 m_pRegExpBtn->Enable();
1753 return;
1755 if ( m_pMatchCaseCB == pCtrl && ( SEARCH_OPTIONS_EXACT & nOptions ) != 0 )
1757 if (!m_pJapOptionsCB->IsChecked())
1758 m_pMatchCaseCB->Enable();
1759 return;
1761 if ( m_pSelectionBtn == pCtrl && ( SEARCH_OPTIONS_SELECTION & nOptions ) != 0 )
1763 m_pSelectionBtn->Enable();
1764 return;
1766 if ( m_pLayoutBtn == pCtrl && ( SEARCH_OPTIONS_FAMILIES & nOptions ) != 0 )
1768 m_pLayoutBtn->Enable();
1769 return;
1771 if ( m_pAttributeBtn == pCtrl
1772 && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0
1773 && pSearchList )
1775 m_pAttributeBtn->Enable( pImpl->bFocusOnSearch );
1777 if ( m_pFormatBtn == pCtrl && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1779 m_pFormatBtn->Enable();
1780 return;
1782 if ( m_pNoFormatBtn == pCtrl && ( SEARCH_OPTIONS_FORMAT & nOptions ) != 0 )
1784 m_pNoFormatBtn->Enable();
1785 return;
1787 if ( m_pSimilarityBox == pCtrl &&
1788 ( SEARCH_OPTIONS_SIMILARITY & nOptions ) != 0 )
1790 m_pSimilarityBox->Enable();
1792 if ( m_pSimilarityBox->IsChecked() )
1793 m_pSimilarityBtn->Enable();
1797 // -----------------------------------------------------------------------
1799 void SvxSearchDialog::SetItem_Impl( const SvxSearchItem* pItem )
1801 if ( pItem )
1803 delete pSearchItem;
1804 pSearchItem = (SvxSearchItem*)pItem->Clone();
1805 Init_Impl( pSearchItem->GetPattern() &&
1806 ( !pSearchList || !pSearchList->Count() ) );
1810 // -----------------------------------------------------------------------
1812 IMPL_LINK( SvxSearchDialog, FocusHdl_Impl, Control *, pCtrl )
1814 sal_Int32 nTxtLen;
1815 if ( !pImpl->bMultiLineEdit )
1816 nTxtLen = m_pSearchAttrText->GetText().getLength();
1817 else
1818 nTxtLen = pImpl->m_pSearchFormats->GetText().getLength();
1820 if ( pCtrl == m_pSearchLB || pCtrl == pImpl->m_pSearchFormats )
1822 if ( pCtrl->HasChildPathFocus() )
1823 pImpl->bFocusOnSearch = sal_True;
1824 pCtrl = m_pSearchLB;
1825 bSearch = sal_True;
1827 if( nTxtLen )
1828 EnableControl_Impl(m_pNoFormatBtn);
1829 else
1830 m_pNoFormatBtn->Disable();
1831 EnableControl_Impl(m_pAttributeBtn);
1833 else
1835 pImpl->bFocusOnSearch = sal_False;
1836 pCtrl = m_pReplaceLB;
1837 bSearch = sal_False;
1839 if ( ( !pImpl->bMultiLineEdit && !m_pReplaceAttrText->GetText().isEmpty() ) ||
1840 ( pImpl->bMultiLineEdit && !pImpl->m_pReplaceFormats->GetText().isEmpty() ) )
1841 EnableControl_Impl(m_pNoFormatBtn);
1842 else
1843 m_pNoFormatBtn->Disable();
1844 m_pAttributeBtn->Disable();
1846 bSet = sal_True;
1848 ( (ComboBox*)pCtrl )->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
1850 ModifyHdl_Impl( (ComboBox*)pCtrl );
1852 if (bFormat && nTxtLen)
1853 m_pLayoutBtn->SetText(aLayoutStr);
1854 else
1856 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
1857 bool bWriterApp =
1858 eFactory == SvtModuleOptions::E_WRITER ||
1859 eFactory == SvtModuleOptions::E_WRITERWEB ||
1860 eFactory == SvtModuleOptions::E_WRITERGLOBAL;
1861 bool bCalcApp = eFactory == SvtModuleOptions::E_CALC;
1863 if (bWriterApp)
1864 m_pLayoutBtn->SetText(aLayoutWriterStr);
1865 else
1867 if (bCalcApp)
1868 m_pLayoutBtn->SetText(aLayoutCalcStr);
1869 else
1870 m_pLayoutBtn->SetText(aStylesStr);
1873 return 0;
1876 // -----------------------------------------------------------------------
1878 IMPL_LINK_NOARG(SvxSearchDialog, LoseFocusHdl_Impl)
1880 SaveToModule_Impl();
1881 return 0;
1884 // -----------------------------------------------------------------------
1886 IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
1888 SfxObjectShell* pSh = SfxObjectShell::Current();
1890 DBG_ASSERT( pSh, "no DocShell" );
1892 if ( !pSh || !pImpl->pRanges )
1893 return 0;
1895 sal_sSize nCnt = 0;
1896 const sal_uInt16* pPtr = pImpl->pRanges;
1897 const sal_uInt16* pTmp = pPtr;
1899 while( *pTmp )
1900 pTmp++;
1901 nCnt = pTmp - pPtr + 7;
1902 sal_uInt16* pWhRanges = new sal_uInt16[nCnt];
1903 sal_uInt16 nPos = 0;
1905 while( *pPtr )
1907 pWhRanges[nPos++] = *pPtr++;
1910 pWhRanges[nPos++] = SID_ATTR_PARA_MODEL;
1911 pWhRanges[nPos++] = SID_ATTR_PARA_MODEL;
1913 sal_uInt16 nBrushWhich = pSh->GetPool().GetWhich(SID_ATTR_BRUSH);
1914 pWhRanges[nPos++] = nBrushWhich;
1915 pWhRanges[nPos++] = nBrushWhich;
1916 pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION;
1917 pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION;
1918 pWhRanges[nPos] = 0;
1919 SfxItemPool& rPool = pSh->GetPool();
1920 SfxItemSet aSet( rPool, pWhRanges );
1921 String aTxt;
1923 aSet.InvalidateAllItems();
1924 aSet.Put(SvxBrushItem(nBrushWhich));
1925 aSet.Put(SfxUInt16Item(SID_PARA_BACKGRND_DESTINATION, PARA_DEST_CHAR));
1927 if ( bSearch )
1929 aTxt = SVX_RESSTR( RID_SVXSTR_SEARCH );
1930 pSearchList->Get( aSet );
1932 else
1934 aTxt = SVX_RESSTR( RID_SVXSTR_REPLACE );
1935 pReplaceList->Get( aSet );
1937 aSet.DisableItem(SID_ATTR_PARA_MODEL);
1938 aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_PAGEBREAK));
1939 aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_KEEP));
1942 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1943 if(pFact)
1945 SfxAbstractTabDialog* pDlg = pFact->CreateTabItemDialog( this, aSet, RID_SVXDLG_SEARCHFORMAT );
1946 DBG_ASSERT(pDlg, "Dialogdiet fail!");
1947 aTxt.Insert( pDlg->GetText(), 0 );
1948 pDlg->SetText( aTxt );
1950 if ( pDlg->Execute() == RET_OK )
1952 DBG_ASSERT( pDlg->GetOutputItemSet(), "invalid Output-Set" );
1953 SfxItemSet aOutSet( *pDlg->GetOutputItemSet() );
1955 SearchAttrItemList* pList = bSearch ? pSearchList : pReplaceList;
1957 SearchAttrItem* pAItem;
1958 const SfxPoolItem* pItem;
1959 for( sal_uInt16 n = 0; n < pList->Count(); ++n )
1960 if( !IsInvalidItem( (pAItem = &pList->GetObject(n))->pItem ) &&
1961 SFX_ITEM_SET == aOutSet.GetItemState(
1962 pAItem->pItem->Which(), sal_False, &pItem ) )
1964 delete pAItem->pItem;
1965 pAItem->pItem = pItem->Clone();
1966 aOutSet.ClearItem( pAItem->pItem->Which() );
1969 if( aOutSet.Count() )
1970 pList->Put( aOutSet );
1972 PaintAttrText_Impl(); // Set AttributText in GroupBox
1974 delete pDlg;
1976 delete[] pWhRanges;
1977 return 0;
1980 // -----------------------------------------------------------------------
1982 IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl)
1984 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
1985 bool bWriterApp =
1986 eFactory == SvtModuleOptions::E_WRITER ||
1987 eFactory == SvtModuleOptions::E_WRITERWEB ||
1988 eFactory == SvtModuleOptions::E_WRITERGLOBAL;
1989 bool bCalcApp = eFactory == SvtModuleOptions::E_CALC;
1991 if (bCalcApp)
1992 m_pLayoutBtn->SetText( aLayoutCalcStr );
1993 else
1995 if (bWriterApp)
1996 m_pLayoutBtn->SetText( aLayoutWriterStr);
1997 else
1998 m_pLayoutBtn->SetText( aStylesStr );
2001 bFormat = sal_False;
2002 m_pLayoutBtn->Check( sal_False );
2004 if ( bSearch )
2006 if ( !pImpl->bMultiLineEdit )
2007 m_pSearchAttrText->SetText( String() );
2008 else
2009 pImpl->m_pSearchFormats->SetText( String() );
2010 pSearchList->Clear();
2012 else
2014 if ( !pImpl->bMultiLineEdit )
2015 m_pReplaceAttrText->SetText( String() );
2016 else
2017 pImpl->m_pReplaceFormats->SetText( String() );
2018 pReplaceList->Clear();
2020 pImpl->bSaveToModule = sal_False;
2021 TemplateHdl_Impl(m_pLayoutBtn);
2022 pImpl->bSaveToModule = sal_True;
2023 m_pNoFormatBtn->Disable();
2024 return 0;
2027 // -----------------------------------------------------------------------
2029 IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl)
2031 if ( !pSearchList || !pImpl->pRanges )
2032 return 0;
2034 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2035 if(pFact)
2037 VclAbstractDialog* pDlg = pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges );
2038 DBG_ASSERT(pDlg, "Dialogdiet fail!");
2039 pDlg->Execute();
2040 delete pDlg;
2042 PaintAttrText_Impl();
2043 return 0;
2046 // -----------------------------------------------------------------------
2048 IMPL_LINK( SvxSearchDialog, TimeoutHdl_Impl, Timer *, pTimer )
2050 SfxViewShell* pViewShell = SfxViewShell::Current();
2052 if ( pViewShell )
2054 if ( pViewShell->HasSelection( m_pSearchLB->IsVisible() ) )
2055 EnableControl_Impl(m_pSelectionBtn);
2056 else
2058 m_pSelectionBtn->Check( sal_False );
2059 m_pSelectionBtn->Disable();
2063 pTimer->Start();
2064 return 0;
2067 // -----------------------------------------------------------------------
2069 String& SvxSearchDialog::BuildAttrText_Impl( String& rStr,
2070 sal_Bool bSrchFlag ) const
2072 if ( rStr.Len() )
2073 rStr.Erase();
2075 SfxObjectShell* pSh = SfxObjectShell::Current();
2076 DBG_ASSERT( pSh, "no DocShell" );
2078 if ( !pSh )
2079 return rStr;
2081 SfxItemPool& rPool = pSh->GetPool();
2082 SearchAttrItemList* pList = bSrchFlag ? pSearchList : pReplaceList;
2084 if ( !pList )
2085 return rStr;
2087 // Metric query
2088 SfxMapUnit eMapUnit = SFX_MAPUNIT_CM;
2089 FieldUnit eFieldUnit = pSh->GetModule()->GetFieldUnit();
2090 switch ( eFieldUnit )
2092 case FUNIT_MM: eMapUnit = SFX_MAPUNIT_MM; break;
2093 case FUNIT_CM:
2094 case FUNIT_M:
2095 case FUNIT_KM: eMapUnit = SFX_MAPUNIT_CM; break;
2096 case FUNIT_TWIP: eMapUnit = SFX_MAPUNIT_TWIP; break;
2097 case FUNIT_POINT:
2098 case FUNIT_PICA: eMapUnit = SFX_MAPUNIT_POINT; break;
2099 case FUNIT_INCH:
2100 case FUNIT_FOOT:
2101 case FUNIT_MILE: eMapUnit = SFX_MAPUNIT_INCH; break;
2102 case FUNIT_100TH_MM: eMapUnit = SFX_MAPUNIT_100TH_MM; break;
2103 default: ;//prevent warning
2106 ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) );
2108 for ( sal_uInt16 i = 0; i < pList->Count(); ++i )
2110 const SearchAttrItem& rItem = pList->GetObject(i);
2112 if ( rStr.Len() )
2113 rStr.AppendAscii( ", " );
2115 if ( !IsInvalidItem( rItem.pItem ) )
2117 OUString aStr;
2118 rPool.GetPresentation( *rItem.pItem,
2119 SFX_ITEM_PRESENTATION_COMPLETE,
2120 eMapUnit, aStr );
2121 rStr += aStr;
2123 else if ( rItem.nSlot == SID_ATTR_BRUSH_CHAR )
2125 // Special treatment for text background
2126 rStr += SVX_RESSTR( RID_SVXITEMS_BRUSH_CHAR );
2128 else
2130 sal_uInt32 nId = aAttrNames.FindIndex( rItem.nSlot );
2131 if ( RESARRAY_INDEX_NOTFOUND != nId )
2132 rStr += aAttrNames.GetString( nId );
2135 return rStr;
2138 // -----------------------------------------------------------------------
2140 void SvxSearchDialog::PaintAttrText_Impl()
2142 String aDesc;
2143 BuildAttrText_Impl( aDesc, bSearch );
2145 if ( !bFormat && aDesc.Len() )
2146 bFormat = sal_True;
2148 if ( bSearch )
2150 if ( !pImpl->bMultiLineEdit )
2151 m_pSearchAttrText->SetText( aDesc );
2152 else
2153 pImpl->m_pSearchFormats->SetText( aDesc );
2154 FocusHdl_Impl(m_pSearchLB);
2156 else
2158 if ( !pImpl->bMultiLineEdit )
2159 m_pReplaceAttrText->SetText( aDesc );
2160 else
2161 pImpl->m_pReplaceFormats->SetText( aDesc );
2162 FocusHdl_Impl(m_pReplaceLB);
2166 // -----------------------------------------------------------------------
2168 void SvxSearchDialog::SetModifyFlag_Impl( const Control* pCtrl )
2170 if ( m_pSearchLB == (ComboBox*)pCtrl )
2171 nModifyFlag |= MODIFY_SEARCH;
2172 else if ( m_pReplaceLB == (ComboBox*)pCtrl )
2173 nModifyFlag |= MODIFY_REPLACE;
2174 else if ( m_pWordBtn == (CheckBox*)pCtrl )
2175 nModifyFlag |= MODIFY_WORD;
2176 else if ( m_pMatchCaseCB == (CheckBox*)pCtrl )
2177 nModifyFlag |= MODIFY_EXACT;
2178 else if ( m_pBackwardsBtn == (CheckBox*)pCtrl )
2179 nModifyFlag |= MODIFY_BACKWARDS;
2180 else if ( m_pNotesBtn == (CheckBox*)pCtrl )
2181 nModifyFlag |= MODIFY_NOTES;
2182 else if ( m_pSelectionBtn == (CheckBox*)pCtrl )
2183 nModifyFlag |= MODIFY_SELECTION;
2184 else if ( m_pRegExpBtn == (CheckBox*)pCtrl )
2185 nModifyFlag |= MODIFY_REGEXP;
2186 else if ( m_pLayoutBtn == (CheckBox*)pCtrl )
2187 nModifyFlag |= MODIFY_LAYOUT;
2188 else if ( m_pSimilarityBox == (CheckBox*)pCtrl )
2189 nModifyFlag |= MODIFY_SIMILARITY;
2190 else if ( m_pCalcSearchInLB == (ListBox*)pCtrl )
2192 nModifyFlag |= MODIFY_FORMULAS;
2193 nModifyFlag |= MODIFY_VALUES;
2194 nModifyFlag |= MODIFY_CALC_NOTES;
2196 else if ( m_pRowsBtn == (RadioButton*)pCtrl )
2197 nModifyFlag |= MODIFY_ROWS;
2198 else if ( m_pColumnsBtn == (RadioButton*)pCtrl )
2199 nModifyFlag |= MODIFY_COLUMNS;
2200 else if ( m_pAllSheetsCB == (CheckBox*)pCtrl )
2201 nModifyFlag |= MODIFY_ALLTABLES;
2204 // -----------------------------------------------------------------------
2206 void SvxSearchDialog::SaveToModule_Impl()
2208 if ( !pSearchItem )
2209 return;
2211 if ( m_pLayoutBtn->IsChecked() )
2213 pSearchItem->SetSearchString ( m_pSearchTmplLB->GetSelectEntry() );
2214 pSearchItem->SetReplaceString( m_pReplaceTmplLB->GetSelectEntry() );
2216 else
2218 pSearchItem->SetSearchString ( m_pSearchLB->GetText() );
2219 pSearchItem->SetReplaceString( m_pReplaceLB->GetText() );
2220 Remember_Impl( m_pSearchLB->GetText(), sal_True );
2223 pSearchItem->SetRegExp( sal_False );
2224 pSearchItem->SetLevenshtein( sal_False );
2225 if (GetCheckBoxValue(m_pRegExpBtn))
2226 pSearchItem->SetRegExp( sal_True );
2227 else if (GetCheckBoxValue(m_pSimilarityBox))
2228 pSearchItem->SetLevenshtein( sal_True );
2230 pSearchItem->SetWordOnly(GetCheckBoxValue(m_pWordBtn));
2231 pSearchItem->SetBackward(GetCheckBoxValue(m_pBackwardsBtn));
2232 pSearchItem->SetNotes(GetCheckBoxValue(m_pNotesBtn));
2233 pSearchItem->SetPattern(GetCheckBoxValue(m_pLayoutBtn));
2234 pSearchItem->SetSelection(GetCheckBoxValue(m_pSelectionBtn));
2236 pSearchItem->SetUseAsianOptions(GetCheckBoxValue(m_pJapOptionsCB));
2237 sal_Int32 nFlags = GetTransliterationFlags();
2238 if( !pSearchItem->IsUseAsianOptions())
2239 nFlags &= (TransliterationModules_IGNORE_CASE |
2240 TransliterationModules_IGNORE_WIDTH );
2241 pSearchItem->SetTransliterationFlags( nFlags );
2243 if ( !bWriter )
2245 if ( m_pCalcSearchInLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
2246 pSearchItem->SetCellType( m_pCalcSearchInLB->GetSelectEntryPos() );
2248 pSearchItem->SetRowDirection( m_pRowsBtn->IsChecked() );
2249 pSearchItem->SetAllTables( m_pAllSheetsCB->IsChecked() );
2252 pSearchItem->SetCommand( SVX_SEARCHCMD_FIND );
2253 nModifyFlag = 0;
2254 const SfxPoolItem* ppArgs[] = { pSearchItem, 0 };
2255 rBindings.GetDispatcher()->Execute( SID_SEARCH_ITEM, SFX_CALLMODE_SLOT, ppArgs );
2258 // class SvxSearchDialogWrapper ------------------------------------------
2260 SFX_IMPL_CHILDWINDOW_WITHID(SvxSearchDialogWrapper, SID_SEARCH_DLG);
2262 // -----------------------------------------------------------------------
2264 SvxSearchDialogWrapper::SvxSearchDialogWrapper( Window* _pParent, sal_uInt16 nId,
2265 SfxBindings* pBindings,
2266 SfxChildWinInfo* pInfo )
2267 : SfxChildWindow( _pParent, nId )
2268 , dialog (new SvxSearchDialog (_pParent, this, *pBindings))
2270 pWindow = dialog;
2271 dialog->Initialize( pInfo );
2273 pBindings->Update( SID_SEARCH_ITEM );
2274 pBindings->Update( SID_SEARCH_OPTIONS );
2275 pBindings->Update( SID_SEARCH_SEARCHSET );
2276 pBindings->Update( SID_SEARCH_REPLACESET );
2277 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
2278 dialog->bConstruct = sal_False;
2281 SvxSearchDialogWrapper::~SvxSearchDialogWrapper ()
2285 SvxSearchDialog *SvxSearchDialogWrapper::getDialog ()
2287 return dialog;
2290 // -----------------------------------------------------------------------
2292 SfxChildWinInfo SvxSearchDialogWrapper::GetInfo() const
2294 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
2295 aInfo.bVisible = sal_False;
2296 return aInfo;
2299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */