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