update dev300-m58
[ooovba.git] / sw / source / ui / uiview / viewsrch.cxx
blob1735041b3d80674ce2407d7838b71fd3a191f379
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewsrch.cxx,v $
10 * $Revision: 1.32 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
36 #include <hintids.hxx>
37 #include <com/sun/star/util/SearchOptions.hpp>
38 #include <svtools/cjkoptions.hxx>
39 #include <svtools/ctloptions.hxx>
40 #include <svx/pageitem.hxx>
41 #include <svtools/whiter.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <svtools/stritem.hxx>
44 #ifndef _T2XTCMP_HXX //autogen
45 #include <svtools/txtcmp.hxx>
46 #endif
47 #include <svtools/itempool.hxx>
48 #include <svtools/eitem.hxx>
49 #include <svx/srchitem.hxx>
50 #include <sfx2/request.hxx>
51 #include <svx/srchdlg.hxx>
52 #include <vcl/msgbox.hxx>
53 #include <vcl/wrkwin.hxx>
54 #include "svx/unolingu.hxx"
55 #include <swmodule.hxx>
56 #include <swwait.hxx>
57 #include <workctrl.hxx>
58 #ifndef _VIEW_HXX
59 #include <view.hxx>
60 #endif
61 #include <wrtsh.hxx>
62 #include <swundo.hxx> // fuer Undo-Ids
63 #include <uitool.hxx>
64 #ifndef _CMDID_H
65 #include <cmdid.h>
66 #endif
67 #ifndef _DOCSH_HXX
68 #include <docsh.hxx>
69 #endif
71 #ifndef _VIEW_HRC
72 #include <view.hrc>
73 #endif
74 #include <SwRewriter.hxx>
75 #include <undobj.hxx>
76 #ifndef _COMCORE_HRC
77 #include <comcore.hrc>
78 #endif
80 #include "PostItMgr.hxx"
82 using namespace com::sun::star;
83 using namespace ::com::sun::star::i18n;
84 using namespace ::com::sun::star::lang;
85 using namespace ::com::sun::star::util;
86 using namespace ::com::sun::star::i18n;
88 #define SRCH_ATTR_OFF 0
89 #define SRCH_ATTR_ON 1
90 #define SRCH_ATTR_SET 2
92 /*--------------------------------------------------------------------
93 Beschreibung: Search Parameter
94 --------------------------------------------------------------------*/
96 struct SwSearchOptions
98 SwDocPositions eStart, eEnd;
99 BOOL bDontWrap;
101 SwSearchOptions( SwWrtShell* pSh, BOOL bBackward );
105 inline Window* GetParentWindow( SvxSearchDialog* pSrchDlg )
107 Window* pWin;
108 if( pSrchDlg && pSrchDlg->IsVisible() )
109 pWin = LAYOUT_THIS_WINDOW (pSrchDlg);
110 else
111 pWin = 0;
112 return pWin;
116 /*-----------------12.04.97 13:04-------------------
118 --------------------------------------------------*/
121 void SwView::ExecSearch(SfxRequest& rReq, BOOL bNoMessage)
123 const SfxItemSet* pArgs = rReq.GetArgs();
124 const SfxPoolItem* pItem = 0;
125 const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
126 SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
127 BOOL bQuiet = FALSE;
128 if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SEARCH_QUIET, FALSE, &pItem))
129 bQuiet = ((const SfxBoolItem*) pItem)->GetValue();
131 BOOL bApi = bQuiet | bNoMessage;
133 USHORT nSlot = rReq.GetSlot();
134 if (nSlot == FN_REPEAT_SEARCH && !pSrchItem)
136 if(bApi)
138 rReq.SetReturnValue(SfxBoolItem(nSlot, FALSE));
139 nSlot = 0;
142 if( pWrtShell->IsBlockMode() )
143 pWrtShell->LeaveBlockMode();
144 switch (nSlot)
146 // erstmal Nichts tun
147 case SID_SEARCH_ITEM:
149 delete pSrchItem;
150 pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
152 break;
154 case FID_SEARCH_ON:
155 bJustOpened = TRUE;
156 GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
157 break;
159 case FID_SEARCH_OFF:
160 if(pArgs)
162 // Dialog abmelden
163 delete pSrchItem;
164 pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
166 DELETEZ( pSrchList );
167 DELETEZ( pReplList );
169 if ( pWrp )
171 pSrchDlg = static_cast <SvxSearchDialog*> (pWrp->getDialog ());
172 // die Search / Replace -Items merken wir uns
173 const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
174 if( pList && pList->Count() )
175 pSrchList = new SearchAttrItemList( *pList );
177 if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
178 pList->Count() )
179 pReplList = new SearchAttrItemList( *pList );
182 break;
184 case FN_REPEAT_SEARCH:
185 case FID_SEARCH_NOW:
188 if(FID_SEARCH_NOW == nSlot && !rReq.IsAPI())
189 SwView::SetMoveType(NID_SRCH_REP);
190 if ( pWrp )
192 pSrchDlg = static_cast <SvxSearchDialog*> (pWrp->getDialog ());
194 else
195 pSrchDlg = 0;
198 if (pSrchDlg)
200 DELETEZ( pSrchList );
201 DELETEZ( pReplList );
203 const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
204 if( pList && pList->Count() )
205 pSrchList = new SearchAttrItemList( *pList );
207 if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
208 pList->Count() )
209 pReplList = new SearchAttrItemList( *pList );
212 if (nSlot == FN_REPEAT_SEARCH)
214 ASSERT(pSrchItem, "Search-Item fehlt");
215 if( !pSrchItem )
216 pSrchItem = new SvxSearchItem(SID_SEARCH_ITEM);
218 else
220 // SearchItem aus Request besorgen
221 ASSERT(pArgs, "Args fehlen");
222 if ( pArgs )
224 delete pSrchItem;
225 pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
228 switch (pSrchItem->GetCommand())
230 case SVX_SEARCHCMD_FIND:
232 BOOL bRet = SearchAndWrap(bApi);
233 if( bRet )
234 Scroll(pWrtShell->GetCharRect().SVRect());
235 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
237 break;
238 case SVX_SEARCHCMD_FIND_ALL:
240 BOOL bRet = SearchAll();
241 if( !bRet )
243 if( !bApi )
245 Window* pParentWindow = GetParentWindow( pSrchDlg );
246 InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
248 bFound = FALSE;
250 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
252 break;
253 case SVX_SEARCHCMD_REPLACE:
256 // 1) Selektion ersetzen (nicht. wenn nur Attribute ersetzt
257 // werden sollen)
258 //JP 27.04.95: warum ?
259 // was ist, wenn man das gefundene nur attributieren will??
261 USHORT nCmd = SVX_SEARCHCMD_FIND;
262 if( pSrchItem->GetReplaceString().Len() ||
263 !pReplList )
265 // Verhindern, dass - falls der Suchstring im
266 // Ersetzungsstring enthalten ist - der ersetzte String
267 // noch einmal gefunden wird.
269 BOOL bBack = pSrchItem->GetBackward();
270 if (bBack)
271 pWrtShell->Push();
272 String aReplace( pSrchItem->GetReplaceString() );
273 SearchOptions aTmp( pSrchItem->GetSearchOptions() );
274 String *pBackRef = ReplaceBackReferences( aTmp, pWrtShell->GetCrsr() );
275 if( pBackRef )
276 pSrchItem->SetReplaceString( *pBackRef );
277 Replace();
278 if( pBackRef )
280 pSrchItem->SetReplaceString( aReplace );
281 delete pBackRef;
283 if (bBack)
285 pWrtShell->Pop();
286 pWrtShell->SwapPam();
289 else if( pReplList )
290 nCmd = SVX_SEARCHCMD_REPLACE;
292 // 2) Weiter suchen (ohne zu ersetzen!)
294 USHORT nOldCmd = pSrchItem->GetCommand();
295 pSrchItem->SetCommand( nCmd );
296 BOOL bRet = SearchAndWrap(bApi);
297 if( bRet )
298 Scroll( pWrtShell->GetCharRect().SVRect());
299 pSrchItem->SetCommand( nOldCmd );
300 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
302 break;
304 case SVX_SEARCHCMD_REPLACE_ALL:
306 SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
309 if( !pSrchItem->GetSelection() )
311 // bestehende Selektionen aufheben,
312 // wenn nicht in selektierten Bereichen gesucht werden soll
313 (pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
314 if( DOCPOS_START == aOpts.eEnd )
315 pWrtShell->EndDoc();
316 else
317 pWrtShell->SttDoc();
320 bExtra = FALSE;
321 ULONG nFound;
323 { //Scope for SwWait-Object
324 SwWait aWait( *GetDocShell(), TRUE );
325 pWrtShell->StartAllAction();
326 nFound = FUNC_Search( aOpts );
327 pWrtShell->EndAllAction();
329 rReq.SetReturnValue(SfxBoolItem(nSlot, nFound != 0 && ULONG_MAX != nFound));
330 if( !nFound )
332 if( !bApi )
334 Window* pParentWindow = GetParentWindow( pSrchDlg );
335 InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
337 bFound = FALSE;
338 return;
341 if( !bApi && ULONG_MAX != nFound)
343 String aText( SW_RES( STR_NB_REPLACED ) );
344 const xub_StrLen nPos = aText.Search( String::CreateFromAscii("XX") );
345 aText.Erase( nPos, 2 );
346 aText.Insert( String::CreateFromInt32( nFound ), nPos );
347 Window* pParentWindow = GetParentWindow( pSrchDlg );
348 InfoBox( pParentWindow, aText ).Execute();
351 break;
354 uno::Reference< frame::XDispatchRecorder > xRecorder =
355 GetViewFrame()->GetBindings().GetRecorder();
356 //prevent additional dialogs in recorded macros
357 if ( xRecorder.is() )
358 rReq.AppendItem(SfxBoolItem(SID_SEARCH_QUIET, sal_True));
360 rReq.Done();
362 break;
363 case FID_SEARCH_SEARCHSET:
364 case FID_SEARCH_REPLACESET:
366 static const USHORT aNormalAttr[] =
368 /* 0 */ RES_CHRATR_CASEMAP, RES_CHRATR_CASEMAP,
369 /* 2 */ RES_CHRATR_COLOR, RES_CHRATR_POSTURE,
370 /* 4 */ RES_CHRATR_SHADOWED, RES_CHRATR_WORDLINEMODE,
371 /* 6 */ RES_CHRATR_BLINK, RES_CHRATR_BLINK,
372 /* 8 */ RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND,
373 /*10 */ RES_CHRATR_ROTATE, RES_CHRATR_ROTATE,
374 /*12 */ RES_CHRATR_SCALEW, RES_CHRATR_RELIEF,
375 // insert position for CJK/CTL attributes!
376 /*14 */ RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
377 /*16 */ RES_PARATR_REGISTER, RES_PARATR_REGISTER,
378 /*18 */ RES_PARATR_VERTALIGN, RES_PARATR_VERTALIGN,
379 /*20 */ RES_LR_SPACE, RES_UL_SPACE,
380 /*22 */ SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
381 /*24 */ 0
384 static const USHORT aCJKAttr[] =
386 RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_WEIGHT,
387 RES_CHRATR_EMPHASIS_MARK, RES_CHRATR_TWO_LINES,
388 RES_PARATR_SCRIPTSPACE, RES_PARATR_FORBIDDEN_RULES
390 static const USHORT aCTLAttr[] =
392 RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_WEIGHT
395 SvUShorts aArr( 0, 16 );
396 aArr.Insert( aNormalAttr,
397 sizeof( aNormalAttr ) / sizeof( aNormalAttr[0] ),
398 0 );
399 if( SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
400 aArr.Insert( aCTLAttr,
401 sizeof( aCTLAttr ) / sizeof( aCTLAttr[0] ),
402 14 );
403 SvtCJKOptions aCJKOpt;
404 if( aCJKOpt.IsAnyEnabled() )
405 aArr.Insert( aCJKAttr,
406 sizeof( aCJKAttr ) / sizeof( aCJKAttr[0] ),
407 14 );
409 SfxItemSet aSet( pWrtShell->GetAttrPool(), aArr.GetData() );
410 USHORT nWhich = SID_SEARCH_SEARCHSET;
412 if ( FID_SEARCH_REPLACESET == nSlot )
414 nWhich = SID_SEARCH_REPLACESET;
416 if ( pReplList )
418 pReplList->Get( aSet );
419 DELETEZ( pReplList );
422 else if ( pSrchList )
424 pSrchList->Get( aSet );
425 DELETEZ( pSrchList );
427 rReq.SetReturnValue( SvxSetItem( nWhich, aSet ) );
429 break;
430 default:
431 #ifndef PRODUCT
432 if(nSlot)
434 ByteString sStr( "nSlot: " );
435 sStr += ByteString::CreateFromInt32( nSlot );
436 sStr += " falscher Dispatcher (viewsrch.cxx)";
437 DBG_ERROR( sStr.GetBuffer() );
439 #endif
440 return;
445 BOOL SwView::SearchAndWrap(BOOL bApi)
447 SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
449 // Startposition der Suche fuer WrapAround merken
450 // Start- / EndAction wegen vielleicht bestehender Selektionen
451 // aus 'Suche alle'
452 pWrtShell->StartAllAction();
453 pWrtShell->Push();
454 // falls in selektierten Bereichen gesucht werden soll, duerfen sie
455 // nicht aufgehoben werden
456 if (!pSrchItem->GetSelection())
457 (pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
459 SwWait *pWait = new SwWait( *GetDocShell(), TRUE );
460 if( FUNC_Search( aOpts ) )
462 bFound = TRUE;
463 if(pWrtShell->IsSelFrmMode())
465 pWrtShell->UnSelectFrm();
466 pWrtShell->LeaveSelFrmMode();
468 pWrtShell->Pop();
469 pWrtShell->EndAllAction();
470 delete pWait;
471 return TRUE;
473 delete pWait, pWait = 0;
475 // Suchen in den Sonderbereichen, wenn keine
476 // Suche in Selektionen vorliegt. Bei Suche in Selektionen
477 // wird ohnehin in diesen Sonderbereichen gesucht
478 BOOL bHasSrchInOther = bExtra;
479 if (!pSrchItem->GetSelection() && !bExtra )
481 bExtra = TRUE;
482 if( FUNC_Search( aOpts ) )
484 bFound = TRUE;
485 pWrtShell->Pop();
486 pWrtShell->EndAllAction();
487 return TRUE;
489 bExtra = FALSE;
491 else
492 bExtra = !bExtra;
494 const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
495 SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
496 pSrchDlg = pWrp ? static_cast <SvxSearchDialog*> (pWrp->getDialog ()) : 0;
498 // falls Startposition am Dokumentende / -anfang
499 if (aOpts.bDontWrap)
501 pWrtShell->EndAllAction();
502 if( !bApi )
504 Window* pParentWindow = GetParentWindow( pSrchDlg );
505 InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
507 bFound = FALSE;
508 pWrtShell->Pop();
509 return FALSE;
511 pWrtShell->EndAllAction();
512 // noch mal mit WrapAround versuchen?
514 if( bApi || RET_NO == QueryBox( GetParentWindow( pSrchDlg ),
515 SW_RES( DOCPOS_START == aOpts.eEnd
516 ? MSG_SEARCH_START
517 : MSG_SEARCH_END )
518 ).Execute() )
520 bFound = FALSE;
521 pWrtShell->Pop();
522 return FALSE;
524 pWrtShell->StartAllAction();
525 pWrtShell->Pop(FALSE);
526 pWait = new SwWait( *GetDocShell(), TRUE );
528 BOOL bSrchBkwrd = DOCPOS_START == aOpts.eEnd;
530 aOpts.eEnd = bSrchBkwrd ? DOCPOS_START : DOCPOS_END;
531 aOpts.eStart = bSrchBkwrd ? DOCPOS_END : DOCPOS_START;
533 if (bHasSrchInOther)
535 pWrtShell->ClearMark();
536 if (bSrchBkwrd)
537 pWrtShell->EndDoc();
538 else
539 pWrtShell->SttDoc();
542 bFound = 0 != FUNC_Search( aOpts );
543 pWrtShell->EndAllAction();
544 delete pWait;
545 if ( bFound )
546 return bFound;
547 if(!bApi)
549 Window* pParentWindow = GetParentWindow( pSrchDlg );
550 InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
552 return bFound = FALSE;
556 BOOL SwView::SearchAll(USHORT* pFound)
558 SwWait aWait( *GetDocShell(), TRUE );
559 pWrtShell->StartAllAction();
561 SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
563 if (!pSrchItem->GetSelection())
565 // bestehende Selektionen aufheben,
566 // wenn nicht in selektierten Bereichen gesucht werden soll
567 (pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
569 if( DOCPOS_START == aOpts.eEnd )
570 pWrtShell->EndDoc();
571 else
572 pWrtShell->SttDoc();
574 bExtra = FALSE;
575 USHORT nFound = (USHORT)FUNC_Search( aOpts );
576 if(pFound)
577 *pFound = nFound;
578 bFound = 0 != nFound;
580 pWrtShell->EndAllAction();
581 return bFound;
585 void SwView::Replace()
587 SwWait aWait( *GetDocShell(), TRUE );
589 pWrtShell->StartAllAction();
591 if( pSrchItem->GetPattern() ) // Vorlagen?
593 SwRewriter aRewriter;
594 aRewriter.AddRule(UNDO_ARG1, pSrchItem->GetSearchString());
595 aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
596 aRewriter.AddRule(UNDO_ARG3, pSrchItem->GetReplaceString());
598 pWrtShell->StartUndo(UNDO_UI_REPLACE_STYLE, &aRewriter); // #111827#
600 pWrtShell->SetTxtFmtColl( pWrtShell->GetParaStyle(
601 pSrchItem->GetReplaceString(),
602 SwWrtShell::GETSTYLE_CREATESOME ));
604 pWrtShell->EndUndo(UNDO_UI_REPLACE_STYLE); // #111827#
606 else
608 if (GetPostItMgr()->GetActivePostIt())
609 GetPostItMgr()->Replace(pSrchItem);
610 sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
611 pSrchItem->GetRegExp());
613 if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
615 SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
616 aTxtFmtCollSetRange );
617 if( pReplList->Get( aReplSet ).Count() )
619 ::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
620 pWrtShell->SwEditShell::SetAttr( aReplSet );
625 pWrtShell->EndAllAction();
630 SwSearchOptions::SwSearchOptions( SwWrtShell* pSh, BOOL bBackward )
632 eStart = DOCPOS_CURR;
633 if( bBackward )
635 eEnd = DOCPOS_START;
636 bDontWrap = pSh->IsEndOfDoc();
638 else
640 eEnd = DOCPOS_END;
641 bDontWrap = pSh->IsStartOfDoc();
645 ULONG SwView::FUNC_Search( const SwSearchOptions& rOptions )
647 BOOL bDoReplace = pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE ||
648 pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
650 int eRanges = pSrchItem->GetSelection() ?
651 FND_IN_SEL : bExtra ? FND_IN_OTHER : FND_IN_BODY;
652 if (pSrchItem->GetCommand() == SVX_SEARCHCMD_FIND_ALL ||
653 pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
654 eRanges |= FND_IN_SELALL;
656 pWrtShell->SttSelect();
658 static USHORT __READONLY_DATA aSearchAttrRange[] = {
659 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
660 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
661 RES_PARATR_BEGIN, RES_PARATR_END-1,
662 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
663 0 };
665 SfxItemSet aSrchSet( pWrtShell->GetAttrPool(), aSearchAttrRange);
666 if( pSrchList && pSrchList->Count() )
668 pSrchList->Get( aSrchSet );
670 /* -- Seitenumbruch mit Seitenvorlage */
671 ::SfxToSwPageDescAttr( *pWrtShell, aSrchSet );
674 SfxItemSet* pReplSet = 0;
675 if( bDoReplace && pReplList && pReplList->Count() )
677 pReplSet = new SfxItemSet( pWrtShell->GetAttrPool(),
678 aSearchAttrRange );
679 pReplList->Get( *pReplSet );
681 /* -- Seitenumbruch mit Seitenvorlage */
682 ::SfxToSwPageDescAttr( *pWrtShell, *pReplSet );
684 if( !pReplSet->Count() ) // schade, die Attribute
685 DELETEZ( pReplSet ); // kennen wir nicht
689 // build SearchOptions to be used
691 SearchOptions aSearchOpt( pSrchItem->GetSearchOptions() );
692 aSearchOpt.Locale = SvxCreateLocale( (USHORT)GetAppLanguage() );
693 if( !bDoReplace )
694 aSearchOpt.replaceString = aEmptyStr;
696 ULONG nFound;
697 if( aSrchSet.Count() || ( pReplSet && pReplSet->Count() ))
699 nFound = pWrtShell->SearchAttr(
700 aSrchSet,
701 !pSrchItem->GetPattern(),
702 rOptions.eStart,
703 rOptions.eEnd,
704 FindRanges(eRanges),
705 pSrchItem->GetSearchString().Len() ? &aSearchOpt : 0,
706 pReplSet );
708 else if( pSrchItem->GetPattern() )
710 // Suchen (und ersetzen) von Vorlagen
711 const String sRplStr( pSrchItem->GetReplaceString() );
712 nFound = pWrtShell->SearchTempl( pSrchItem->GetSearchString(),
713 rOptions.eStart,
714 rOptions.eEnd,
715 FindRanges(eRanges),
716 bDoReplace ? &sRplStr : 0 );
718 else
720 // Normale Suche
721 nFound = pWrtShell->SearchPattern(aSearchOpt, pSrchItem->GetNotes(),
722 rOptions.eStart,
723 rOptions.eEnd,
724 FindRanges(eRanges),
725 bDoReplace );
727 pWrtShell->EndSelect();
728 return nFound;
731 LAYOUT_NS Dialog* SwView::GetSearchDialog()
733 const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
734 SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)SfxViewFrame::Current()->GetChildWindow(nId);
735 if ( pWrp )
736 pSrchDlg = pWrp->getDialog ();
737 else
738 pSrchDlg = 0;
739 return pSrchDlg;
742 void SwView::StateSearch(SfxItemSet &rSet)
744 SfxWhichIter aIter(rSet);
745 USHORT nWhich = aIter.FirstWhich();
747 while(nWhich)
749 switch(nWhich)
751 case SID_SEARCH_OPTIONS:
753 UINT16 nOpt = 0xFFFF;
754 if( GetDocShell()->IsReadOnly() )
755 nOpt &= ~( SEARCH_OPTIONS_REPLACE |
756 SEARCH_OPTIONS_REPLACE_ALL );
757 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt));
759 break;
760 case SID_SEARCH_ITEM:
762 if ( !pSrchItem )
764 pSrchItem = new SvxSearchItem( SID_SEARCH_ITEM );
765 pSrchItem->SetFamily(SFX_STYLE_FAMILY_PARA);
766 pSrchItem->SetSearchString( pWrtShell->GetSelTxt() );
769 if( bJustOpened && pWrtShell->IsSelection() )
771 String aTxt;
772 if( 1 == pWrtShell->GetCrsrCnt() &&
773 ( aTxt = pWrtShell->SwCrsrShell::GetSelTxt() ).Len() )
775 pSrchItem->SetSearchString( aTxt );
776 pSrchItem->SetSelection( FALSE );
778 else
779 pSrchItem->SetSelection( TRUE );
782 bJustOpened = FALSE;
783 rSet.Put( *pSrchItem );
785 break;
787 /* case SID_SEARCH_REPLACESET:
788 case SID_SEARCH_SEARCHSET:
790 static USHORT __READONLY_DATA aSearchAttrRange[] =
792 RES_CHRATR_CASEMAP, RES_CHRATR_POSTURE,
793 RES_CHRATR_SHADOWED, RES_CHRATR_WORDLINEMODE,
794 RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
795 RES_LR_SPACE, RES_UL_SPACE,
796 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
800 SfxItemSet aSet(pWrtShell->GetAttrPool(), aSearchAttrRange );
801 if( SID_SEARCH_REPLACESET==nWhich )
803 if( pReplList )
805 pReplList->Get( aSet );
806 DELETEZ( pReplList );
809 else if( pSrchList )
811 pSrchList->Get( aSet );
812 DELETEZ( pSrchList );
814 rSet.Put( SvxSetItem( nWhich, aSet ));
816 break;
819 nWhich = aIter.NextWhich();