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