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