xref: /trunk/main/sw/source/ui/uiview/viewsrch.cxx (revision 69a74367)
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_sw.hxx"
26 
27 
28 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
29 #include <hintids.hxx>
30 #include <com/sun/star/util/SearchOptions.hpp>
31 #include <svl/cjkoptions.hxx>
32 #include <svl/ctloptions.hxx>
33 #include <svx/pageitem.hxx>
34 #include <svl/whiter.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <svl/stritem.hxx>
37 #include <svtools/txtcmp.hxx>
38 #include <svl/itempool.hxx>
39 #include <svl/eitem.hxx>
40 #include <svl/srchitem.hxx>
41 #include <sfx2/request.hxx>
42 #include <svx/srchdlg.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <vcl/wrkwin.hxx>
45 #include "editeng/unolingu.hxx"
46 #include <swmodule.hxx>
47 #include <swwait.hxx>
48 #include <workctrl.hxx>
49 #include <view.hxx>
50 #include <wrtsh.hxx>
51 #include <swundo.hxx>               	// fuer Undo-Ids
52 #include <uitool.hxx>
53 #include <cmdid.h>
54 #include <docsh.hxx>
55 
56 #include <view.hrc>
57 #include <SwRewriter.hxx>
58 #include <comcore.hrc>
59 
60 #include "PostItMgr.hxx"
61 
62 using namespace com::sun::star;
63 using namespace ::com::sun::star::i18n;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::util;
66 using namespace ::com::sun::star::i18n;
67 
68 #define SRCH_ATTR_OFF	0
69 #define SRCH_ATTR_ON    1
70 #define SRCH_ATTR_SET   2
71 
72 /*--------------------------------------------------------------------
73 	Beschreibung:	Search Parameter
74  --------------------------------------------------------------------*/
75 
76 struct SwSearchOptions
77 {
78 	SwDocPositions eStart, eEnd;
79 	sal_Bool bDontWrap;
80 
81 	SwSearchOptions( SwWrtShell* pSh, sal_Bool bBackward );
82 };
83 
84 
85 inline Window* GetParentWindow( SvxSearchDialog* pSrchDlg )
86 {
87 	Window* pWin;
88 	if( pSrchDlg && pSrchDlg->IsVisible() )
89 		pWin = LAYOUT_THIS_WINDOW (pSrchDlg);
90 	else
91 		pWin = 0;
92 	return pWin;
93 }
94 
95 
96 /*-----------------12.04.97 13:04-------------------
97 
98 --------------------------------------------------*/
99 
100 
101 void SwView::ExecSearch(SfxRequest& rReq, sal_Bool bNoMessage)
102 {
103 	const SfxItemSet* pArgs = rReq.GetArgs();
104 	const SfxPoolItem* pItem = 0;
105 	const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
106 	SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
107     sal_Bool bQuiet = sal_False;
108     if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SEARCH_QUIET, sal_False, &pItem))
109         bQuiet = ((const SfxBoolItem*) pItem)->GetValue();
110 
111     sal_Bool bApi = bQuiet | bNoMessage;
112 
113 	sal_uInt16 nSlot = rReq.GetSlot();
114 	if (nSlot == FN_REPEAT_SEARCH && !pSrchItem)
115 	{
116 		if(bApi)
117 		{
118 			rReq.SetReturnValue(SfxBoolItem(nSlot, sal_False));
119 			nSlot = 0;
120 		}
121 	}
122     if( pWrtShell->IsBlockMode() )
123         pWrtShell->LeaveBlockMode();
124 	switch (nSlot)
125 	{
126 	// erstmal Nichts tun
127 	case SID_SEARCH_ITEM:
128 	{
129 		delete pSrchItem;
130 		pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
131 	}
132 	break;
133 
134 	case FID_SEARCH_ON:
135 		bJustOpened = sal_True;
136 		GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
137 		break;
138 
139 	case FID_SEARCH_OFF:
140 		if(pArgs)
141 		{
142 			// Dialog abmelden
143 			delete pSrchItem;
144 			pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
145 
146 			DELETEZ( pSrchList );
147 			DELETEZ( pReplList );
148 
149 			if ( pWrp )
150 			{
151                 pSrchDlg = static_cast <SvxSearchDialog*> (pWrp->getDialog ());
152 				// die Search / Replace -Items merken wir uns
153 				const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
154 				if( pList && pList->Count() )
155 					pSrchList = new SearchAttrItemList( *pList );
156 
157 				if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
158 					pList->Count() )
159 					pReplList = new SearchAttrItemList( *pList );
160 			}
161 		}
162 		break;
163 
164 		case FN_REPEAT_SEARCH:
165 		case FID_SEARCH_NOW:
166         {
167 			{
168 				if(FID_SEARCH_NOW == nSlot && !rReq.IsAPI())
169 					SwView::SetMoveType(NID_SRCH_REP);
170 				if ( pWrp )
171 				{
172                     pSrchDlg = static_cast <SvxSearchDialog*> (pWrp->getDialog ());
173 				}
174 				else
175 					pSrchDlg = 0;
176 			}
177 
178 			if (pSrchDlg)
179 			{
180 				DELETEZ( pSrchList );
181 				DELETEZ( pReplList );
182 
183 				const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
184 				if( pList && pList->Count() )
185 					pSrchList = new SearchAttrItemList( *pList );
186 
187 				if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
188 					pList->Count() )
189 					pReplList = new SearchAttrItemList( *pList );
190 			}
191 
192 			if (nSlot == FN_REPEAT_SEARCH)
193 			{
194 				ASSERT(pSrchItem, "Search-Item fehlt");
195 				if( !pSrchItem )
196                     pSrchItem = new SvxSearchItem(SID_SEARCH_ITEM);
197 			}
198 			else
199 			{
200 				// SearchItem aus Request besorgen
201 				ASSERT(pArgs, "Args fehlen");
202                 if ( pArgs )
203                 {
204 				    delete pSrchItem;
205 				    pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
206                 }
207 			}
208 			switch (pSrchItem->GetCommand())
209 			{
210 			case SVX_SEARCHCMD_FIND:
211 			{
212 				sal_Bool bRet = SearchAndWrap(bApi);
213 				if( bRet )
214 					Scroll(pWrtShell->GetCharRect().SVRect());
215 				rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
216 				//IAccessibility2 Implementation 2009-----
217 				if ( Application::IsAccessibilityEnabled() )
218 				{
219 					const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
220 					SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
221 					if ( pWrp )
222 					{
223 						pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
224 						pSrchDlg->SetDocWin( (Window*)pEditWin );
225 						pSrchDlg->SetSrchFlag();
226 					}
227 				}
228 				//-----IAccessibility2 Implementation 2009
229 			}
230 			break;
231 			case SVX_SEARCHCMD_FIND_ALL:
232 			{
233 				sal_Bool bRet = SearchAll();
234 				if( !bRet )
235 				{
236 					if( !bApi )
237 					{
238 						Window* pParentWindow = GetParentWindow( pSrchDlg );
239 						InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
240 					}
241 					bFound = sal_False;
242 				}
243 				rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
244 				//IAccessibility2 Implementation 2009-----
245 				if ( Application::IsAccessibilityEnabled() )
246 				{
247 					const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
248 					SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
249 
250 					if ( pWrp )
251 					{
252 						pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
253 						pSrchDlg->SetDocWin( (Window*)pEditWin );
254 						pSrchDlg->SetSrchFlag();
255 					}
256 				}
257 				//-----IAccessibility2 Implementation 2009
258 			}
259 			break;
260 			case SVX_SEARCHCMD_REPLACE:
261 				{
262 
263 					// 1) Selektion ersetzen (nicht. wenn nur Attribute ersetzt
264 					//    werden sollen)
265 //JP 27.04.95: warum ?
266 // 		was ist, wenn man das gefundene nur attributieren will??
267 
268 					sal_uInt16 nCmd = SVX_SEARCHCMD_FIND;
269 					if( pSrchItem->GetReplaceString().Len() ||
270 						!pReplList )
271 					{
272 						// Verhindern, dass - falls der Suchstring im
273 						// Ersetzungsstring enthalten ist - der ersetzte String
274 						// noch einmal gefunden wird.
275 
276 						sal_Bool bBack = pSrchItem->GetBackward();
277 						if (bBack)
278 							pWrtShell->Push();
279                         String aReplace( pSrchItem->GetReplaceString() );
280                         SearchOptions aTmp( pSrchItem->GetSearchOptions() );
281                         String *pBackRef = ReplaceBackReferences( aTmp, pWrtShell->GetCrsr() );
282                         if( pBackRef )
283                             pSrchItem->SetReplaceString( *pBackRef );
284 						Replace();
285                         if( pBackRef )
286                         {
287                             pSrchItem->SetReplaceString( aReplace );
288                             delete pBackRef;
289                         }
290 						if (bBack)
291 						{
292 							pWrtShell->Pop();
293 							pWrtShell->SwapPam();
294 						}
295 					}
296 					else if( pReplList )
297 						nCmd = SVX_SEARCHCMD_REPLACE;
298 
299 					// 2) Weiter suchen (ohne zu ersetzen!)
300 
301 					sal_uInt16 nOldCmd = pSrchItem->GetCommand();
302 					pSrchItem->SetCommand( nCmd );
303 					sal_Bool bRet = SearchAndWrap(bApi);
304 					if( bRet )
305 						Scroll( pWrtShell->GetCharRect().SVRect());
306 					pSrchItem->SetCommand( nOldCmd );
307 					rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
308 				}
309 				//IAccessibility2 Implementation 2009-----
310 				{
311 					const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
312 					SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
313 
314 					if ( pWrp )
315 					{
316 						pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
317 						pSrchDlg->SetDocWin( (Window*)pEditWin );
318 						pSrchDlg->SetSrchFlag();
319 					}
320 				}
321 				//-----IAccessibility2 Implementation 2009
322 				break;
323 
324 			case SVX_SEARCHCMD_REPLACE_ALL:
325 				{
326 					SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
327 
328 
329 					if( !pSrchItem->GetSelection() )
330 					{
331 						// bestehende Selektionen aufheben,
332 						// wenn nicht in selektierten Bereichen gesucht werden soll
333 						(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
334 						if( DOCPOS_START == aOpts.eEnd )
335 							pWrtShell->EndDoc();
336 						else
337 							pWrtShell->SttDoc();
338 					}
339 
340 					bExtra = sal_False;
341 					sal_uLong nFound;
342 
343 					{	//Scope for SwWait-Object
344 						SwWait aWait( *GetDocShell(), sal_True );
345 						pWrtShell->StartAllAction();
346 						nFound = FUNC_Search( aOpts );
347 						pWrtShell->EndAllAction();
348 					}
349                     rReq.SetReturnValue(SfxBoolItem(nSlot, nFound != 0 && ULONG_MAX != nFound));
350 					if( !nFound )
351 					{
352 						if( !bApi )
353 						{
354 							Window* pParentWindow = GetParentWindow( pSrchDlg );
355 							InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
356 						}
357 						bFound = sal_False;
358 						return;
359 					}
360 
361                     if( !bApi && ULONG_MAX != nFound)
362 					{
363 						String aText( SW_RES( STR_NB_REPLACED ) );
364 						const xub_StrLen nPos = aText.Search( String::CreateFromAscii("XX") );
365 						aText.Erase( nPos, 2 );
366 						aText.Insert( String::CreateFromInt32( nFound ), nPos );
367 						Window* pParentWindow = GetParentWindow( pSrchDlg );
368 						InfoBox( pParentWindow, aText ).Execute();
369 					}
370 				}
371 				//IAccessibility2 Implementation 2009-----
372 				const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
373 				SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
374 
375 				if ( pWrp )
376 				{
377 					pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
378 					pSrchDlg->SetDocWin( (Window*)pEditWin );
379 					pSrchDlg->SetSrchFlag();
380 				}
381 				//-----IAccessibility2 Implementation 2009
382 				break;
383 			}
384 
385             uno::Reference< frame::XDispatchRecorder > xRecorder =
386                     GetViewFrame()->GetBindings().GetRecorder();
387             //prevent additional dialogs in recorded macros
388             if ( xRecorder.is() )
389                 rReq.AppendItem(SfxBoolItem(SID_SEARCH_QUIET, sal_True));
390 
391 			rReq.Done();
392         }
393         break;
394 		case FID_SEARCH_SEARCHSET:
395 		case FID_SEARCH_REPLACESET:
396 		{
397 			static const sal_uInt16 aNormalAttr[] =
398 			{
399 /* 0 */			RES_CHRATR_CASEMAP,		RES_CHRATR_CASEMAP,
400 /* 2 */			RES_CHRATR_COLOR, 		RES_CHRATR_POSTURE,
401 /* 4 */			RES_CHRATR_SHADOWED, 	RES_CHRATR_WORDLINEMODE,
402 /* 6 */			RES_CHRATR_BLINK,		RES_CHRATR_BLINK,
403 /* 8 */			RES_CHRATR_BACKGROUND,	RES_CHRATR_BACKGROUND,
404 /*10 */			RES_CHRATR_ROTATE,		RES_CHRATR_ROTATE,
405 /*12 */			RES_CHRATR_SCALEW,		RES_CHRATR_RELIEF,
406 // insert position for CJK/CTL attributes!
407 /*14 */			RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
408 /*16 */			RES_PARATR_REGISTER, 	RES_PARATR_REGISTER,
409 /*18 */			RES_PARATR_VERTALIGN, 	RES_PARATR_VERTALIGN,
410 /*20 */			RES_LR_SPACE, 			RES_UL_SPACE,
411 /*22 */			SID_ATTR_PARA_MODEL, 	SID_ATTR_PARA_KEEP,
412 /*24 */ 		0
413 			};
414 
415 			static const sal_uInt16 aCJKAttr[] =
416 			{
417 				RES_CHRATR_CJK_FONT,	RES_CHRATR_CJK_WEIGHT,
418 				RES_CHRATR_EMPHASIS_MARK, RES_CHRATR_TWO_LINES,
419 				RES_PARATR_SCRIPTSPACE, RES_PARATR_FORBIDDEN_RULES
420 			};
421 			static const sal_uInt16 aCTLAttr[] =
422 			{
423 				RES_CHRATR_CTL_FONT,	RES_CHRATR_CTL_WEIGHT
424 			};
425 
426 			SvUShorts aArr( 0, 16 );
427 			aArr.Insert(	aNormalAttr,
428 							sizeof( aNormalAttr ) / sizeof( aNormalAttr[0] ),
429 							0 );
430             if( SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
431 				aArr.Insert(	aCTLAttr,
432 								sizeof( aCTLAttr ) / sizeof( aCTLAttr[0] ),
433 								14 );
434 			SvtCJKOptions aCJKOpt;
435 			if( aCJKOpt.IsAnyEnabled() )
436 				aArr.Insert( 	aCJKAttr,
437 								sizeof( aCJKAttr ) / sizeof( aCJKAttr[0] ),
438 								14 );
439 
440 			SfxItemSet aSet( pWrtShell->GetAttrPool(), aArr.GetData() );
441 			sal_uInt16 nWhich = SID_SEARCH_SEARCHSET;
442 
443 			if ( FID_SEARCH_REPLACESET == nSlot )
444 			{
445 				nWhich = SID_SEARCH_REPLACESET;
446 
447 				if ( pReplList )
448 				{
449 					pReplList->Get( aSet );
450 					DELETEZ( pReplList );
451 				}
452 			}
453 			else if ( pSrchList )
454 			{
455 				pSrchList->Get( aSet );
456 				DELETEZ( pSrchList );
457 			}
458 			rReq.SetReturnValue( SvxSetItem( nWhich, aSet ) );
459 		}
460 		break;
461 		default:
462 #ifdef DBG_UTIL
463 			if(nSlot)
464 			{
465 				ByteString sStr( "nSlot: " );
466 				sStr += ByteString::CreateFromInt32( nSlot );
467 				sStr += " falscher Dispatcher (viewsrch.cxx)";
468 				DBG_ERROR( sStr.GetBuffer() );
469 			}
470 #endif
471 			return;
472 	}
473 }
474 
475 
476 sal_Bool SwView::SearchAndWrap(sal_Bool bApi)
477 {
478 	SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
479 
480 		// Startposition der Suche fuer WrapAround merken
481 		// Start- / EndAction wegen vielleicht bestehender Selektionen
482 		// aus 'Suche alle'
483 	pWrtShell->StartAllAction();
484 	pWrtShell->Push();
485 		// falls in selektierten Bereichen gesucht werden soll, duerfen sie
486 		// nicht aufgehoben werden
487 	if (!pSrchItem->GetSelection())
488 		(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
489 
490 	SwWait *pWait = new SwWait( *GetDocShell(), sal_True );
491 	if( FUNC_Search( aOpts ) )
492 	{
493 		bFound = sal_True;
494 		if(pWrtShell->IsSelFrmMode())
495 		{
496 			pWrtShell->UnSelectFrm();
497 			pWrtShell->LeaveSelFrmMode();
498 		}
499 		pWrtShell->Pop();
500 		pWrtShell->EndAllAction();
501 		delete pWait;
502 		return sal_True;
503 	}
504 	delete pWait, pWait = 0;
505 
506 		// Suchen in den Sonderbereichen, wenn keine
507 		// Suche in Selektionen vorliegt. Bei Suche in Selektionen
508 		// wird ohnehin in diesen Sonderbereichen gesucht
509 	sal_Bool bHasSrchInOther = bExtra;
510 	if (!pSrchItem->GetSelection() && !bExtra )
511 	{
512 		bExtra = sal_True;
513 		if( FUNC_Search( aOpts ) )
514 		{
515 			bFound = sal_True;
516 			pWrtShell->Pop();
517 			pWrtShell->EndAllAction();
518 			return sal_True;
519 		}
520 		bExtra = sal_False;
521 	}
522 	else
523 		bExtra = !bExtra;
524 
525 	const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
526 	SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
527 	pSrchDlg = pWrp ? static_cast <SvxSearchDialog*> (pWrp->getDialog ()) : 0;
528 
529 		// falls Startposition am Dokumentende / -anfang
530 	if (aOpts.bDontWrap)
531 	{
532 		pWrtShell->EndAllAction();
533 		if( !bApi )
534 		{
535 			Window* pParentWindow = GetParentWindow( pSrchDlg );
536 			InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
537 		}
538 		bFound = sal_False;
539 		pWrtShell->Pop();
540 		return sal_False;
541 	}
542 	pWrtShell->EndAllAction();
543 		// noch mal mit WrapAround versuchen?
544 
545 	if( bApi || RET_NO == QueryBox( GetParentWindow( pSrchDlg ),
546 										SW_RES( DOCPOS_START == aOpts.eEnd
547 											? MSG_SEARCH_START
548 											: MSG_SEARCH_END )
549 									).Execute() )
550 	{
551 		bFound = sal_False;
552 		pWrtShell->Pop();
553 		return sal_False;
554 	}
555 	pWrtShell->StartAllAction();
556 	pWrtShell->Pop(sal_False);
557 	pWait = new SwWait( *GetDocShell(), sal_True );
558 
559 	sal_Bool bSrchBkwrd = DOCPOS_START == aOpts.eEnd;
560 
561 	aOpts.eEnd =  bSrchBkwrd ? DOCPOS_START : DOCPOS_END;
562 	aOpts.eStart = bSrchBkwrd ? DOCPOS_END : DOCPOS_START;
563 
564 	if (bHasSrchInOther)
565 	{
566 		pWrtShell->ClearMark();
567 		if (bSrchBkwrd)
568 			pWrtShell->EndDoc();
569 		else
570 			pWrtShell->SttDoc();
571 	}
572 
573 	bFound = 0 != FUNC_Search( aOpts );
574 	pWrtShell->EndAllAction();
575 	delete pWait;
576 	if ( bFound )
577 		return bFound;
578 	if(!bApi)
579 	{
580 		Window* pParentWindow = GetParentWindow( pSrchDlg );
581 		InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
582 	}
583 	return bFound = sal_False;
584 }
585 
586 
587 sal_Bool SwView::SearchAll(sal_uInt16* pFound)
588 {
589 	SwWait aWait( *GetDocShell(), sal_True );
590 	pWrtShell->StartAllAction();
591 
592 	SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
593 
594 	if (!pSrchItem->GetSelection())
595 	{
596 		// bestehende Selektionen aufheben,
597 		// wenn nicht in selektierten Bereichen gesucht werden soll
598 		(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
599 
600 		if( DOCPOS_START == aOpts.eEnd )
601 			pWrtShell->EndDoc();
602 		else
603 			pWrtShell->SttDoc();
604 	}
605 	bExtra = sal_False;
606 	sal_uInt16 nFound = (sal_uInt16)FUNC_Search( aOpts );
607 	if(pFound)
608 		*pFound = nFound;
609 	bFound = 0 != nFound;
610 
611 	pWrtShell->EndAllAction();
612 	return bFound;
613 }
614 
615 
616 void SwView::Replace()
617 {
618 	SwWait aWait( *GetDocShell(), sal_True );
619 
620 	pWrtShell->StartAllAction();
621 
622 	if( pSrchItem->GetPattern() ) // Vorlagen?
623     {
624         SwRewriter aRewriter;
625         aRewriter.AddRule(UNDO_ARG1, pSrchItem->GetSearchString());
626         aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
627         aRewriter.AddRule(UNDO_ARG3, pSrchItem->GetReplaceString());
628 
629         pWrtShell->StartUndo(UNDO_UI_REPLACE_STYLE, &aRewriter); // #111827#
630 
631 		pWrtShell->SetTxtFmtColl( pWrtShell->GetParaStyle(
632 							pSrchItem->GetReplaceString(),
633 							SwWrtShell::GETSTYLE_CREATESOME ));
634 
635         pWrtShell->EndUndo(); // #111827#
636     }
637 	else
638 	{
639         if (GetPostItMgr()->HasActiveSidebarWin())
640 			GetPostItMgr()->Replace(pSrchItem);
641 		sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
642 											pSrchItem->GetRegExp());
643 
644 		if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
645 		{
646 			SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
647 									aTxtFmtCollSetRange );
648 			if( pReplList->Get( aReplSet ).Count() )
649 			{
650 				::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
651 				pWrtShell->SwEditShell::SetAttrSet( aReplSet );
652 			}
653 		}
654 	}
655 
656 	pWrtShell->EndAllAction();
657 }
658 
659 
660 
661 SwSearchOptions::SwSearchOptions( SwWrtShell* pSh, sal_Bool bBackward )
662 {
663 	eStart = DOCPOS_CURR;
664 	if( bBackward )
665 	{
666 		eEnd = DOCPOS_START;
667 		bDontWrap = pSh->IsEndOfDoc();
668 	}
669 	else
670 	{
671 		eEnd = DOCPOS_END;
672 		bDontWrap = pSh->IsStartOfDoc();
673 	}
674 }
675 
676 sal_uLong SwView::FUNC_Search( const SwSearchOptions& rOptions )
677 {
678 	sal_Bool bDoReplace = pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE ||
679 					  pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
680 
681 	int eRanges = pSrchItem->GetSelection() ?
682 		FND_IN_SEL : bExtra ? FND_IN_OTHER : FND_IN_BODY;
683 	if (pSrchItem->GetCommand() == SVX_SEARCHCMD_FIND_ALL    ||
684 		pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
685 		eRanges |= FND_IN_SELALL;
686 
687 	pWrtShell->SttSelect();
688 
689 	static sal_uInt16 __READONLY_DATA aSearchAttrRange[] = {
690 		RES_FRMATR_BEGIN, RES_FRMATR_END-1,
691 		RES_CHRATR_BEGIN, RES_CHRATR_END-1,
692 		RES_PARATR_BEGIN, RES_PARATR_END-1,
693 		SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
694 		0 };
695 
696 	SfxItemSet aSrchSet( pWrtShell->GetAttrPool(), aSearchAttrRange);
697 	if( pSrchList && pSrchList->Count() )
698 	{
699 		pSrchList->Get( aSrchSet );
700 
701 		/*  -- Seitenumbruch mit Seitenvorlage */
702 		::SfxToSwPageDescAttr( *pWrtShell, aSrchSet );
703 	}
704 
705 	SfxItemSet* pReplSet = 0;
706 	if( bDoReplace && pReplList && pReplList->Count() )
707 	{
708 		pReplSet = new SfxItemSet( pWrtShell->GetAttrPool(),
709 										aSearchAttrRange );
710 		pReplList->Get( *pReplSet );
711 
712 		/*  -- Seitenumbruch mit Seitenvorlage */
713 		::SfxToSwPageDescAttr( *pWrtShell, *pReplSet );
714 
715 		if( !pReplSet->Count() )		// schade, die Attribute
716 			DELETEZ( pReplSet );		// kennen wir nicht
717 	}
718 
719 	//
720 	// build SearchOptions to be used
721 	//
722 	SearchOptions aSearchOpt( pSrchItem->GetSearchOptions() );
723 	aSearchOpt.Locale = SvxCreateLocale( (sal_uInt16)GetAppLanguage() );
724 	if( !bDoReplace )
725 		aSearchOpt.replaceString = aEmptyStr;
726 
727 	sal_uLong nFound;
728 	if( aSrchSet.Count() || ( pReplSet && pReplSet->Count() ))
729 	{
730 		nFound = pWrtShell->SearchAttr(
731 			aSrchSet,
732 			!pSrchItem->GetPattern(),
733 			rOptions.eStart,
734 			rOptions.eEnd,
735 			FindRanges(eRanges),
736 			pSrchItem->GetSearchString().Len() ? &aSearchOpt : 0,
737 			pReplSet );
738 	}
739 	else if( pSrchItem->GetPattern() )
740 	{
741 		// Suchen (und ersetzen) von Vorlagen
742 		const String sRplStr( pSrchItem->GetReplaceString() );
743 		nFound = pWrtShell->SearchTempl( pSrchItem->GetSearchString(),
744 			rOptions.eStart,
745 			rOptions.eEnd,
746 			FindRanges(eRanges),
747 			bDoReplace ? &sRplStr : 0 );
748 	}
749 	else
750 	{
751 		// Normale Suche
752 		nFound = pWrtShell->SearchPattern(aSearchOpt, pSrchItem->GetNotes(),
753 										  rOptions.eStart,
754 										  rOptions.eEnd,
755 										  FindRanges(eRanges),
756 										  bDoReplace );
757 	}
758 	pWrtShell->EndSelect();
759 	return nFound;
760 }
761 
762 LAYOUT_NS Dialog* SwView::GetSearchDialog()
763 {
764 	const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
765 	SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)SfxViewFrame::Current()->GetChildWindow(nId);
766 	if ( pWrp )
767 		pSrchDlg = pWrp->getDialog ();
768 	else
769 		pSrchDlg = 0;
770 	return pSrchDlg;
771 }
772 
773 void SwView::StateSearch(SfxItemSet &rSet)
774 {
775 	SfxWhichIter aIter(rSet);
776 	sal_uInt16 nWhich = aIter.FirstWhich();
777 
778 	while(nWhich)
779 	{
780 		switch(nWhich)
781 		{
782 			case SID_SEARCH_OPTIONS:
783 			{
784 				sal_uInt16 nOpt = 0xFFFF;
785 				if( GetDocShell()->IsReadOnly() )
786 					nOpt &= ~( SEARCH_OPTIONS_REPLACE |
787 							   SEARCH_OPTIONS_REPLACE_ALL );
788 				rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt));
789 			}
790 			break;
791 			case SID_SEARCH_ITEM:
792 			{
793 				if ( !pSrchItem )
794 				{
795 					pSrchItem = new SvxSearchItem( SID_SEARCH_ITEM );
796 					pSrchItem->SetFamily(SFX_STYLE_FAMILY_PARA);
797 					pSrchItem->SetSearchString( pWrtShell->GetSelTxt() );
798 				}
799 
800 				if( bJustOpened && pWrtShell->IsSelection() )
801 				{
802 					String aTxt;
803 					if( 1 == pWrtShell->GetCrsrCnt() &&
804 						( aTxt = pWrtShell->SwCrsrShell::GetSelTxt() ).Len() )
805 					{
806 						pSrchItem->SetSearchString( aTxt );
807 						pSrchItem->SetSelection( sal_False );
808 					}
809 					else
810 						pSrchItem->SetSelection( sal_True );
811 				}
812 
813 				bJustOpened = sal_False;
814 				rSet.Put( *pSrchItem );
815 			}
816 			break;
817 
818 /*			case SID_SEARCH_REPLACESET:
819 			case SID_SEARCH_SEARCHSET:
820 			{
821 				static sal_uInt16 __READONLY_DATA aSearchAttrRange[] =
822 				{
823 						RES_CHRATR_CASEMAP,		RES_CHRATR_POSTURE,
824 						RES_CHRATR_SHADOWED, 	RES_CHRATR_WORDLINEMODE,
825 						RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
826 						RES_LR_SPACE, 			RES_UL_SPACE,
827 						SID_ATTR_PARA_MODEL, 	SID_ATTR_PARA_KEEP,
828 						0
829 				};
830 
831 				SfxItemSet aSet(pWrtShell->GetAttrPool(), aSearchAttrRange );
832 				if( SID_SEARCH_REPLACESET==nWhich )
833 				{
834 					if( pReplList )
835 					{
836 						pReplList->Get( aSet );
837 						DELETEZ( pReplList );
838 					}
839 				}
840 				else if( pSrchList )
841 				{
842 					pSrchList->Get( aSet );
843 					DELETEZ( pSrchList );
844 				}
845 				rSet.Put( SvxSetItem( nWhich, aSet ));
846 			}
847 			break;
848 */
849 		}
850 		nWhich = aIter.NextWhich();
851 	}
852 }
853 
854 
855 
856