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