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