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