LCOV - code coverage report
Current view: top level - svx/source/dialog - srchdlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 1297 0.2 %
Date: 2014-04-11 Functions: 4 69 5.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10