xref: /aoo42x/main/sw/source/ui/uiview/viewsrch.cxx (revision efeef26f)
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 			}
217 			break;
218 			case SVX_SEARCHCMD_FIND_ALL:
219 			{
220 				sal_Bool bRet = SearchAll();
221 				if( !bRet )
222 				{
223 					if( !bApi )
224 					{
225 						Window* pParentWindow = GetParentWindow( pSrchDlg );
226 						InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
227 					}
228 					bFound = sal_False;
229 				}
230 				rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
231 			}
232 			break;
233 			case SVX_SEARCHCMD_REPLACE:
234 				{
235 
236 					// 1) Selektion ersetzen (nicht. wenn nur Attribute ersetzt
237 					//    werden sollen)
238 //JP 27.04.95: warum ?
239 // 		was ist, wenn man das gefundene nur attributieren will??
240 
241 					sal_uInt16 nCmd = SVX_SEARCHCMD_FIND;
242 					if( pSrchItem->GetReplaceString().Len() ||
243 						!pReplList )
244 					{
245 						// Verhindern, dass - falls der Suchstring im
246 						// Ersetzungsstring enthalten ist - der ersetzte String
247 						// noch einmal gefunden wird.
248 
249 						sal_Bool bBack = pSrchItem->GetBackward();
250 						if (bBack)
251 							pWrtShell->Push();
252                         String aReplace( pSrchItem->GetReplaceString() );
253                         SearchOptions aTmp( pSrchItem->GetSearchOptions() );
254                         String *pBackRef = ReplaceBackReferences( aTmp, pWrtShell->GetCrsr() );
255                         if( pBackRef )
256                             pSrchItem->SetReplaceString( *pBackRef );
257 						Replace();
258                         if( pBackRef )
259                         {
260                             pSrchItem->SetReplaceString( aReplace );
261                             delete pBackRef;
262                         }
263 						if (bBack)
264 						{
265 							pWrtShell->Pop();
266 							pWrtShell->SwapPam();
267 						}
268 					}
269 					else if( pReplList )
270 						nCmd = SVX_SEARCHCMD_REPLACE;
271 
272 					// 2) Weiter suchen (ohne zu ersetzen!)
273 
274 					sal_uInt16 nOldCmd = pSrchItem->GetCommand();
275 					pSrchItem->SetCommand( nCmd );
276 					sal_Bool bRet = SearchAndWrap(bApi);
277 					if( bRet )
278 						Scroll( pWrtShell->GetCharRect().SVRect());
279 					pSrchItem->SetCommand( nOldCmd );
280 					rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
281 				}
282 				break;
283 
284 			case SVX_SEARCHCMD_REPLACE_ALL:
285 				{
286 					SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
287 
288 
289 					if( !pSrchItem->GetSelection() )
290 					{
291 						// bestehende Selektionen aufheben,
292 						// wenn nicht in selektierten Bereichen gesucht werden soll
293 						(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
294 						if( DOCPOS_START == aOpts.eEnd )
295 							pWrtShell->EndDoc();
296 						else
297 							pWrtShell->SttDoc();
298 					}
299 
300 					bExtra = sal_False;
301 					sal_uLong nFound;
302 
303 					{	//Scope for SwWait-Object
304 						SwWait aWait( *GetDocShell(), sal_True );
305 						pWrtShell->StartAllAction();
306 						nFound = FUNC_Search( aOpts );
307 						pWrtShell->EndAllAction();
308 					}
309                     rReq.SetReturnValue(SfxBoolItem(nSlot, nFound != 0 && ULONG_MAX != nFound));
310 					if( !nFound )
311 					{
312 						if( !bApi )
313 						{
314 							Window* pParentWindow = GetParentWindow( pSrchDlg );
315 							InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
316 						}
317 						bFound = sal_False;
318 						return;
319 					}
320 
321                     if( !bApi && ULONG_MAX != nFound)
322 					{
323 						String aText( SW_RES( STR_NB_REPLACED ) );
324 						const xub_StrLen nPos = aText.Search( String::CreateFromAscii("XX") );
325 						aText.Erase( nPos, 2 );
326 						aText.Insert( String::CreateFromInt32( nFound ), nPos );
327 						Window* pParentWindow = GetParentWindow( pSrchDlg );
328 						InfoBox( pParentWindow, aText ).Execute();
329 					}
330 				}
331 				break;
332 			}
333 
334             uno::Reference< frame::XDispatchRecorder > xRecorder =
335                     GetViewFrame()->GetBindings().GetRecorder();
336             //prevent additional dialogs in recorded macros
337             if ( xRecorder.is() )
338                 rReq.AppendItem(SfxBoolItem(SID_SEARCH_QUIET, sal_True));
339 
340 			rReq.Done();
341         }
342         break;
343 		case FID_SEARCH_SEARCHSET:
344 		case FID_SEARCH_REPLACESET:
345 		{
346 			static const sal_uInt16 aNormalAttr[] =
347 			{
348 /* 0 */			RES_CHRATR_CASEMAP,		RES_CHRATR_CASEMAP,
349 /* 2 */			RES_CHRATR_COLOR, 		RES_CHRATR_POSTURE,
350 /* 4 */			RES_CHRATR_SHADOWED, 	RES_CHRATR_WORDLINEMODE,
351 /* 6 */			RES_CHRATR_BLINK,		RES_CHRATR_BLINK,
352 /* 8 */			RES_CHRATR_BACKGROUND,	RES_CHRATR_BACKGROUND,
353 /*10 */			RES_CHRATR_ROTATE,		RES_CHRATR_ROTATE,
354 /*12 */			RES_CHRATR_SCALEW,		RES_CHRATR_RELIEF,
355 // insert position for CJK/CTL attributes!
356 /*14 */			RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
357 /*16 */			RES_PARATR_REGISTER, 	RES_PARATR_REGISTER,
358 /*18 */			RES_PARATR_VERTALIGN, 	RES_PARATR_VERTALIGN,
359 /*20 */			RES_LR_SPACE, 			RES_UL_SPACE,
360 /*22 */			SID_ATTR_PARA_MODEL, 	SID_ATTR_PARA_KEEP,
361 /*24 */ 		0
362 			};
363 
364 			static const sal_uInt16 aCJKAttr[] =
365 			{
366 				RES_CHRATR_CJK_FONT,	RES_CHRATR_CJK_WEIGHT,
367 				RES_CHRATR_EMPHASIS_MARK, RES_CHRATR_TWO_LINES,
368 				RES_PARATR_SCRIPTSPACE, RES_PARATR_FORBIDDEN_RULES
369 			};
370 			static const sal_uInt16 aCTLAttr[] =
371 			{
372 				RES_CHRATR_CTL_FONT,	RES_CHRATR_CTL_WEIGHT
373 			};
374 
375 			SvUShorts aArr( 0, 16 );
376 			aArr.Insert(	aNormalAttr,
377 							sizeof( aNormalAttr ) / sizeof( aNormalAttr[0] ),
378 							0 );
379             if( SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
380 				aArr.Insert(	aCTLAttr,
381 								sizeof( aCTLAttr ) / sizeof( aCTLAttr[0] ),
382 								14 );
383 			SvtCJKOptions aCJKOpt;
384 			if( aCJKOpt.IsAnyEnabled() )
385 				aArr.Insert( 	aCJKAttr,
386 								sizeof( aCJKAttr ) / sizeof( aCJKAttr[0] ),
387 								14 );
388 
389 			SfxItemSet aSet( pWrtShell->GetAttrPool(), aArr.GetData() );
390 			sal_uInt16 nWhich = SID_SEARCH_SEARCHSET;
391 
392 			if ( FID_SEARCH_REPLACESET == nSlot )
393 			{
394 				nWhich = SID_SEARCH_REPLACESET;
395 
396 				if ( pReplList )
397 				{
398 					pReplList->Get( aSet );
399 					DELETEZ( pReplList );
400 				}
401 			}
402 			else if ( pSrchList )
403 			{
404 				pSrchList->Get( aSet );
405 				DELETEZ( pSrchList );
406 			}
407 			rReq.SetReturnValue( SvxSetItem( nWhich, aSet ) );
408 		}
409 		break;
410 		default:
411 #ifdef DBG_UTIL
412 			if(nSlot)
413 			{
414 				ByteString sStr( "nSlot: " );
415 				sStr += ByteString::CreateFromInt32( nSlot );
416 				sStr += " falscher Dispatcher (viewsrch.cxx)";
417 				DBG_ERROR( sStr.GetBuffer() );
418 			}
419 #endif
420 			return;
421 	}
422 }
423 
424 
425 sal_Bool SwView::SearchAndWrap(sal_Bool bApi)
426 {
427 	SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
428 
429 		// Startposition der Suche fuer WrapAround merken
430 		// Start- / EndAction wegen vielleicht bestehender Selektionen
431 		// aus 'Suche alle'
432 	pWrtShell->StartAllAction();
433 	pWrtShell->Push();
434 		// falls in selektierten Bereichen gesucht werden soll, duerfen sie
435 		// nicht aufgehoben werden
436 	if (!pSrchItem->GetSelection())
437 		(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
438 
439 	SwWait *pWait = new SwWait( *GetDocShell(), sal_True );
440 	if( FUNC_Search( aOpts ) )
441 	{
442 		bFound = sal_True;
443 		if(pWrtShell->IsSelFrmMode())
444 		{
445 			pWrtShell->UnSelectFrm();
446 			pWrtShell->LeaveSelFrmMode();
447 		}
448 		pWrtShell->Pop();
449 		pWrtShell->EndAllAction();
450 		delete pWait;
451 		return sal_True;
452 	}
453 	delete pWait, pWait = 0;
454 
455 		// Suchen in den Sonderbereichen, wenn keine
456 		// Suche in Selektionen vorliegt. Bei Suche in Selektionen
457 		// wird ohnehin in diesen Sonderbereichen gesucht
458 	sal_Bool bHasSrchInOther = bExtra;
459 	if (!pSrchItem->GetSelection() && !bExtra )
460 	{
461 		bExtra = sal_True;
462 		if( FUNC_Search( aOpts ) )
463 		{
464 			bFound = sal_True;
465 			pWrtShell->Pop();
466 			pWrtShell->EndAllAction();
467 			return sal_True;
468 		}
469 		bExtra = sal_False;
470 	}
471 	else
472 		bExtra = !bExtra;
473 
474 	const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
475 	SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
476 	pSrchDlg = pWrp ? static_cast <SvxSearchDialog*> (pWrp->getDialog ()) : 0;
477 
478 		// falls Startposition am Dokumentende / -anfang
479 	if (aOpts.bDontWrap)
480 	{
481 		pWrtShell->EndAllAction();
482 		if( !bApi )
483 		{
484 			Window* pParentWindow = GetParentWindow( pSrchDlg );
485 			InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
486 		}
487 		bFound = sal_False;
488 		pWrtShell->Pop();
489 		return sal_False;
490 	}
491 	pWrtShell->EndAllAction();
492 		// noch mal mit WrapAround versuchen?
493 
494 	if( bApi || RET_NO == QueryBox( GetParentWindow( pSrchDlg ),
495 										SW_RES( DOCPOS_START == aOpts.eEnd
496 											? MSG_SEARCH_START
497 											: MSG_SEARCH_END )
498 									).Execute() )
499 	{
500 		bFound = sal_False;
501 		pWrtShell->Pop();
502 		return sal_False;
503 	}
504 	pWrtShell->StartAllAction();
505 	pWrtShell->Pop(sal_False);
506 	pWait = new SwWait( *GetDocShell(), sal_True );
507 
508 	sal_Bool bSrchBkwrd = DOCPOS_START == aOpts.eEnd;
509 
510 	aOpts.eEnd =  bSrchBkwrd ? DOCPOS_START : DOCPOS_END;
511 	aOpts.eStart = bSrchBkwrd ? DOCPOS_END : DOCPOS_START;
512 
513 	if (bHasSrchInOther)
514 	{
515 		pWrtShell->ClearMark();
516 		if (bSrchBkwrd)
517 			pWrtShell->EndDoc();
518 		else
519 			pWrtShell->SttDoc();
520 	}
521 
522 	bFound = 0 != FUNC_Search( aOpts );
523 	pWrtShell->EndAllAction();
524 	delete pWait;
525 	if ( bFound )
526 		return bFound;
527 	if(!bApi)
528 	{
529 		Window* pParentWindow = GetParentWindow( pSrchDlg );
530 		InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
531 	}
532 	return bFound = sal_False;
533 }
534 
535 
536 sal_Bool SwView::SearchAll(sal_uInt16* pFound)
537 {
538 	SwWait aWait( *GetDocShell(), sal_True );
539 	pWrtShell->StartAllAction();
540 
541 	SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
542 
543 	if (!pSrchItem->GetSelection())
544 	{
545 		// bestehende Selektionen aufheben,
546 		// wenn nicht in selektierten Bereichen gesucht werden soll
547 		(pWrtShell->*pWrtShell->fnKillSel)(0, sal_False);
548 
549 		if( DOCPOS_START == aOpts.eEnd )
550 			pWrtShell->EndDoc();
551 		else
552 			pWrtShell->SttDoc();
553 	}
554 	bExtra = sal_False;
555 	sal_uInt16 nFound = (sal_uInt16)FUNC_Search( aOpts );
556 	if(pFound)
557 		*pFound = nFound;
558 	bFound = 0 != nFound;
559 
560 	pWrtShell->EndAllAction();
561 	return bFound;
562 }
563 
564 
565 void SwView::Replace()
566 {
567 	SwWait aWait( *GetDocShell(), sal_True );
568 
569 	pWrtShell->StartAllAction();
570 
571 	if( pSrchItem->GetPattern() ) // Vorlagen?
572     {
573         SwRewriter aRewriter;
574         aRewriter.AddRule(UNDO_ARG1, pSrchItem->GetSearchString());
575         aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
576         aRewriter.AddRule(UNDO_ARG3, pSrchItem->GetReplaceString());
577 
578         pWrtShell->StartUndo(UNDO_UI_REPLACE_STYLE, &aRewriter); // #111827#
579 
580 		pWrtShell->SetTxtFmtColl( pWrtShell->GetParaStyle(
581 							pSrchItem->GetReplaceString(),
582 							SwWrtShell::GETSTYLE_CREATESOME ));
583 
584         pWrtShell->EndUndo(); // #111827#
585     }
586 	else
587 	{
588         if (GetPostItMgr()->HasActiveSidebarWin())
589 			GetPostItMgr()->Replace(pSrchItem);
590 		sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
591 											pSrchItem->GetRegExp());
592 
593 		if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
594 		{
595 			SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
596 									aTxtFmtCollSetRange );
597 			if( pReplList->Get( aReplSet ).Count() )
598 			{
599 				::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
600 				pWrtShell->SwEditShell::SetAttr( aReplSet );
601 			}
602 		}
603 	}
604 
605 	pWrtShell->EndAllAction();
606 }
607 
608 
609 
610 SwSearchOptions::SwSearchOptions( SwWrtShell* pSh, sal_Bool bBackward )
611 {
612 	eStart = DOCPOS_CURR;
613 	if( bBackward )
614 	{
615 		eEnd = DOCPOS_START;
616 		bDontWrap = pSh->IsEndOfDoc();
617 	}
618 	else
619 	{
620 		eEnd = DOCPOS_END;
621 		bDontWrap = pSh->IsStartOfDoc();
622 	}
623 }
624 
625 sal_uLong SwView::FUNC_Search( const SwSearchOptions& rOptions )
626 {
627 	sal_Bool bDoReplace = pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE ||
628 					  pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
629 
630 	int eRanges = pSrchItem->GetSelection() ?
631 		FND_IN_SEL : bExtra ? FND_IN_OTHER : FND_IN_BODY;
632 	if (pSrchItem->GetCommand() == SVX_SEARCHCMD_FIND_ALL    ||
633 		pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
634 		eRanges |= FND_IN_SELALL;
635 
636 	pWrtShell->SttSelect();
637 
638 	static sal_uInt16 __READONLY_DATA aSearchAttrRange[] = {
639 		RES_FRMATR_BEGIN, RES_FRMATR_END-1,
640 		RES_CHRATR_BEGIN, RES_CHRATR_END-1,
641 		RES_PARATR_BEGIN, RES_PARATR_END-1,
642 		SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
643 		0 };
644 
645 	SfxItemSet aSrchSet( pWrtShell->GetAttrPool(), aSearchAttrRange);
646 	if( pSrchList && pSrchList->Count() )
647 	{
648 		pSrchList->Get( aSrchSet );
649 
650 		/*  -- Seitenumbruch mit Seitenvorlage */
651 		::SfxToSwPageDescAttr( *pWrtShell, aSrchSet );
652 	}
653 
654 	SfxItemSet* pReplSet = 0;
655 	if( bDoReplace && pReplList && pReplList->Count() )
656 	{
657 		pReplSet = new SfxItemSet( pWrtShell->GetAttrPool(),
658 										aSearchAttrRange );
659 		pReplList->Get( *pReplSet );
660 
661 		/*  -- Seitenumbruch mit Seitenvorlage */
662 		::SfxToSwPageDescAttr( *pWrtShell, *pReplSet );
663 
664 		if( !pReplSet->Count() )		// schade, die Attribute
665 			DELETEZ( pReplSet );		// kennen wir nicht
666 	}
667 
668 	//
669 	// build SearchOptions to be used
670 	//
671 	SearchOptions aSearchOpt( pSrchItem->GetSearchOptions() );
672 	aSearchOpt.Locale = SvxCreateLocale( (sal_uInt16)GetAppLanguage() );
673 	if( !bDoReplace )
674 		aSearchOpt.replaceString = aEmptyStr;
675 
676 	sal_uLong nFound;
677 	if( aSrchSet.Count() || ( pReplSet && pReplSet->Count() ))
678 	{
679 		nFound = pWrtShell->SearchAttr(
680 			aSrchSet,
681 			!pSrchItem->GetPattern(),
682 			rOptions.eStart,
683 			rOptions.eEnd,
684 			FindRanges(eRanges),
685 			pSrchItem->GetSearchString().Len() ? &aSearchOpt : 0,
686 			pReplSet );
687 	}
688 	else if( pSrchItem->GetPattern() )
689 	{
690 		// Suchen (und ersetzen) von Vorlagen
691 		const String sRplStr( pSrchItem->GetReplaceString() );
692 		nFound = pWrtShell->SearchTempl( pSrchItem->GetSearchString(),
693 			rOptions.eStart,
694 			rOptions.eEnd,
695 			FindRanges(eRanges),
696 			bDoReplace ? &sRplStr : 0 );
697 	}
698 	else
699 	{
700 		// Normale Suche
701 		nFound = pWrtShell->SearchPattern(aSearchOpt, pSrchItem->GetNotes(),
702 										  rOptions.eStart,
703 										  rOptions.eEnd,
704 										  FindRanges(eRanges),
705 										  bDoReplace );
706 	}
707 	pWrtShell->EndSelect();
708 	return nFound;
709 }
710 
711 LAYOUT_NS Dialog* SwView::GetSearchDialog()
712 {
713 	const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
714 	SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)SfxViewFrame::Current()->GetChildWindow(nId);
715 	if ( pWrp )
716 		pSrchDlg = pWrp->getDialog ();
717 	else
718 		pSrchDlg = 0;
719 	return pSrchDlg;
720 }
721 
722 void SwView::StateSearch(SfxItemSet &rSet)
723 {
724 	SfxWhichIter aIter(rSet);
725 	sal_uInt16 nWhich = aIter.FirstWhich();
726 
727 	while(nWhich)
728 	{
729 		switch(nWhich)
730 		{
731 			case SID_SEARCH_OPTIONS:
732 			{
733 				sal_uInt16 nOpt = 0xFFFF;
734 				if( GetDocShell()->IsReadOnly() )
735 					nOpt &= ~( SEARCH_OPTIONS_REPLACE |
736 							   SEARCH_OPTIONS_REPLACE_ALL );
737 				rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt));
738 			}
739 			break;
740 			case SID_SEARCH_ITEM:
741 			{
742 				if ( !pSrchItem )
743 				{
744 					pSrchItem = new SvxSearchItem( SID_SEARCH_ITEM );
745 					pSrchItem->SetFamily(SFX_STYLE_FAMILY_PARA);
746 					pSrchItem->SetSearchString( pWrtShell->GetSelTxt() );
747 				}
748 
749 				if( bJustOpened && pWrtShell->IsSelection() )
750 				{
751 					String aTxt;
752 					if( 1 == pWrtShell->GetCrsrCnt() &&
753 						( aTxt = pWrtShell->SwCrsrShell::GetSelTxt() ).Len() )
754 					{
755 						pSrchItem->SetSearchString( aTxt );
756 						pSrchItem->SetSelection( sal_False );
757 					}
758 					else
759 						pSrchItem->SetSelection( sal_True );
760 				}
761 
762 				bJustOpened = sal_False;
763 				rSet.Put( *pSrchItem );
764 			}
765 			break;
766 
767 /*			case SID_SEARCH_REPLACESET:
768 			case SID_SEARCH_SEARCHSET:
769 			{
770 				static sal_uInt16 __READONLY_DATA aSearchAttrRange[] =
771 				{
772 						RES_CHRATR_CASEMAP,		RES_CHRATR_POSTURE,
773 						RES_CHRATR_SHADOWED, 	RES_CHRATR_WORDLINEMODE,
774 						RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
775 						RES_LR_SPACE, 			RES_UL_SPACE,
776 						SID_ATTR_PARA_MODEL, 	SID_ATTR_PARA_KEEP,
777 						0
778 				};
779 
780 				SfxItemSet aSet(pWrtShell->GetAttrPool(), aSearchAttrRange );
781 				if( SID_SEARCH_REPLACESET==nWhich )
782 				{
783 					if( pReplList )
784 					{
785 						pReplList->Get( aSet );
786 						DELETEZ( pReplList );
787 					}
788 				}
789 				else if( pSrchList )
790 				{
791 					pSrchList->Get( aSet );
792 					DELETEZ( pSrchList );
793 				}
794 				rSet.Put( SvxSetItem( nWhich, aSet ));
795 			}
796 			break;
797 */
798 		}
799 		nWhich = aIter.NextWhich();
800 	}
801 }
802 
803 
804 
805