1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <boost/scoped_ptr.hpp>
25 #include <hintids.hxx>
26 #include <com/sun/star/util/SearchOptions.hpp>
27 #include <svl/cjkoptions.hxx>
28 #include <svl/ctloptions.hxx>
29 #include <svx/pageitem.hxx>
30 #include <svl/whiter.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <svl/stritem.hxx>
33 #include <unotools/textsearch.hxx>
34 #include <svl/itempool.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/srchitem.hxx>
37 #include <sal/macros.h>
38 #include <sfx2/request.hxx>
39 #include <svx/srchdlg.hxx>
40 #include <svx/dialmgr.hxx>
41 #include <svx/dialogs.hrc>
42 #include <vcl/msgbox.hxx>
43 #include <vcl/wrkwin.hxx>
44 #include "editeng/unolingu.hxx"
45 #include <swmodule.hxx>
47 #include <workctrl.hxx>
50 #include <swundo.hxx> // fuer Undo-Ids
55 #include <unocrsr.hxx>
58 #include <SwRewriter.hxx>
59 #include <comcore.hrc>
61 #include "PostItMgr.hxx"
63 using namespace com::sun::star
;
64 using namespace ::com::sun::star::i18n
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::util
;
68 /*--------------------------------------------------------------------
69 Beschreibung: Search Parameter
70 --------------------------------------------------------------------*/
72 struct SwSearchOptions
74 SwDocPositions eStart
, eEnd
;
77 SwSearchOptions( SwWrtShell
* pSh
, sal_Bool bBackward
);
81 inline Window
* GetParentWindow( SvxSearchDialog
* m_pSrchDlg
)
84 if( m_pSrchDlg
&& m_pSrchDlg
->IsVisible() )
91 inline void ShowNotFoundInfoBox( SvxSearchDialog
* m_pSrchDlg
)
93 Window
* pParentWindow
= GetParentWindow( m_pSrchDlg
);
94 InfoBox
aBox( pParentWindow
, SW_RES(MSG_NOT_FOUND
));
97 aBox
.SetText(pParentWindow
->GetText());
101 aBox
.SetText(SVX_RESSTR(RID_SVXSTR_FINDBAR_FIND
));
106 void SwView::ExecSearch(SfxRequest
& rReq
, sal_Bool bNoMessage
)
108 const SfxItemSet
* pArgs
= rReq
.GetArgs();
109 const SfxPoolItem
* pItem
= 0;
110 const sal_uInt16 nId
= SvxSearchDialogWrapper::GetChildWindowId();
111 SvxSearchDialogWrapper
*pWrp
= (SvxSearchDialogWrapper
*)GetViewFrame()->GetChildWindow(nId
);
112 sal_Bool bQuiet
= sal_False
;
113 if(pArgs
&& SFX_ITEM_SET
== pArgs
->GetItemState(SID_SEARCH_QUIET
, sal_False
, &pItem
))
114 bQuiet
= ((const SfxBoolItem
*) pItem
)->GetValue();
116 sal_Bool bApi
= bQuiet
| bNoMessage
;
118 sal_uInt16 nSlot
= rReq
.GetSlot();
119 if (nSlot
== FN_REPEAT_SEARCH
&& !m_pSrchItem
)
123 rReq
.SetReturnValue(SfxBoolItem(nSlot
, sal_False
));
127 if( m_pWrtShell
->IsBlockMode() )
128 m_pWrtShell
->LeaveBlockMode();
131 // erstmal Nichts tun
132 case SID_SEARCH_ITEM
:
135 m_pSrchItem
= (SvxSearchItem
*) pArgs
->Get(SID_SEARCH_ITEM
).Clone();
140 m_bJustOpened
= true;
141 GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM
);
149 m_pSrchItem
= (SvxSearchItem
*) pArgs
->Get(SID_SEARCH_ITEM
).Clone();
151 DELETEZ( m_pSrchList
);
152 DELETEZ( m_pReplList
);
156 m_pSrchDlg
= static_cast <SvxSearchDialog
*> (pWrp
->getDialog ());
157 // die Search / Replace -Items merken wir uns
158 const SearchAttrItemList
* pList
= m_pSrchDlg
->GetSearchItemList();
159 if( pList
&& pList
->Count() )
160 m_pSrchList
= new SearchAttrItemList( *pList
);
162 if( 0 != (pList
= m_pSrchDlg
->GetReplaceItemList() ) &&
164 m_pReplList
= new SearchAttrItemList( *pList
);
169 case FN_REPEAT_SEARCH
:
173 if(FID_SEARCH_NOW
== nSlot
&& !rReq
.IsAPI())
174 SwView::SetMoveType(NID_SRCH_REP
);
177 m_pSrchDlg
= static_cast <SvxSearchDialog
*> (pWrp
->getDialog ());
185 DELETEZ( m_pSrchList
);
186 DELETEZ( m_pReplList
);
188 const SearchAttrItemList
* pList
= m_pSrchDlg
->GetSearchItemList();
189 if( pList
&& pList
->Count() )
190 m_pSrchList
= new SearchAttrItemList( *pList
);
192 if( 0 != (pList
= m_pSrchDlg
->GetReplaceItemList() ) &&
194 m_pReplList
= new SearchAttrItemList( *pList
);
197 if (nSlot
== FN_REPEAT_SEARCH
)
199 OSL_ENSURE(m_pSrchItem
, "SearchItem missing");
201 m_pSrchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
205 // SearchItem aus Request besorgen
206 OSL_ENSURE(pArgs
, "Args missing");
210 m_pSrchItem
= (SvxSearchItem
*) pArgs
->Get(SID_SEARCH_ITEM
).Clone();
213 switch (m_pSrchItem
->GetCommand())
215 case SVX_SEARCHCMD_FIND
:
217 sal_Bool bRet
= SearchAndWrap(bApi
);
219 Scroll(m_pWrtShell
->GetCharRect().SVRect());
220 rReq
.SetReturnValue(SfxBoolItem(nSlot
, bRet
));
223 case SVX_SEARCHCMD_FIND_ALL
:
225 sal_Bool bRet
= SearchAll();
230 ShowNotFoundInfoBox( m_pSrchDlg
);
232 m_bFound
= sal_False
;
234 rReq
.SetReturnValue(SfxBoolItem(nSlot
, bRet
));
237 case SVX_SEARCHCMD_REPLACE
:
240 // 1) Selektion ersetzen (nicht. wenn nur Attribute ersetzt
242 //JP 27.04.95: warum ?
243 // was ist, wenn man das gefundene nur attributieren will??
245 sal_uInt16 nCmd
= SVX_SEARCHCMD_FIND
;
246 if( m_pSrchItem
->GetReplaceString().Len() ||
249 // Verhindern, dass - falls der Suchstring im
250 // Ersetzungsstring enthalten ist - der ersetzte String
251 // noch einmal gefunden wird.
253 sal_Bool bBack
= m_pSrchItem
->GetBackward();
256 String
aReplace( m_pSrchItem
->GetReplaceString() );
257 SearchOptions
aTmp( m_pSrchItem
->GetSearchOptions() );
258 String
*pBackRef
= ReplaceBackReferences( aTmp
, m_pWrtShell
->GetCrsr() );
260 m_pSrchItem
->SetReplaceString( *pBackRef
);
264 m_pSrchItem
->SetReplaceString( aReplace
);
270 m_pWrtShell
->SwapPam();
273 else if( m_pReplList
)
274 nCmd
= SVX_SEARCHCMD_REPLACE
;
276 // 2) Weiter suchen (ohne zu ersetzen!)
278 sal_uInt16 nOldCmd
= m_pSrchItem
->GetCommand();
279 m_pSrchItem
->SetCommand( nCmd
);
280 sal_Bool bRet
= SearchAndWrap(bApi
);
282 Scroll( m_pWrtShell
->GetCharRect().SVRect());
283 m_pSrchItem
->SetCommand( nOldCmd
);
284 rReq
.SetReturnValue(SfxBoolItem(nSlot
, bRet
));
288 case SVX_SEARCHCMD_REPLACE_ALL
:
290 SwSearchOptions
aOpts( m_pWrtShell
, m_pSrchItem
->GetBackward() );
291 m_bExtra
= sal_False
;
294 { //Scope for SwWait-Object
295 SwWait
aWait( *GetDocShell(), sal_True
);
296 m_pWrtShell
->StartAllAction();
297 if (!m_pSrchItem
->GetSelection())
299 // if we don't want to search in the selection...
300 m_pWrtShell
->KillSelection(0, false);
301 // i#8288 "replace all" should not change cursor
302 // position, so save current cursor
304 if (DOCPOS_START
== aOpts
.eEnd
)
306 m_pWrtShell
->EndDoc();
310 m_pWrtShell
->SttDoc();
313 nFound
= FUNC_Search( aOpts
);
314 if (!m_pSrchItem
->GetSelection())
316 // create it just to overwrite it with stack cursor
317 m_pWrtShell
->CreateCrsr();
318 // i#8288 restore the original cursor position
319 m_pWrtShell
->Pop(false);
321 m_pWrtShell
->EndAllAction();
324 rReq
.SetReturnValue(SfxBoolItem(nSlot
, nFound
!= 0 && ULONG_MAX
!= nFound
));
329 ShowNotFoundInfoBox( m_pSrchDlg
);
331 m_bFound
= sal_False
;
335 if( !bApi
&& ULONG_MAX
!= nFound
)
337 String
aText( SW_RES( STR_NB_REPLACED
) );
338 const xub_StrLen nPos
= aText
.Search( OUString("XX") );
339 aText
.Erase( nPos
, 2 );
340 aText
.Insert( OUString::number( nFound
), nPos
);
341 Window
* pParentWindow
= GetParentWindow( m_pSrchDlg
);
342 InfoBox( pParentWindow
, aText
).Execute();
348 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
349 GetViewFrame()->GetBindings().GetRecorder();
350 //prevent additional dialogs in recorded macros
351 if ( xRecorder
.is() )
352 rReq
.AppendItem(SfxBoolItem(SID_SEARCH_QUIET
, sal_True
));
357 case FID_SEARCH_SEARCHSET
:
358 case FID_SEARCH_REPLACESET
:
360 static const sal_uInt16 aNormalAttr
[] =
362 /* 0 */ RES_CHRATR_CASEMAP
, RES_CHRATR_CASEMAP
,
363 /* 2 */ RES_CHRATR_COLOR
, RES_CHRATR_POSTURE
,
364 /* 4 */ RES_CHRATR_SHADOWED
, RES_CHRATR_WORDLINEMODE
,
365 /* 6 */ RES_CHRATR_BLINK
, RES_CHRATR_BLINK
,
366 /* 8 */ RES_CHRATR_BACKGROUND
, RES_CHRATR_BACKGROUND
,
367 /*10 */ RES_CHRATR_ROTATE
, RES_CHRATR_ROTATE
,
368 /*12 */ RES_CHRATR_SCALEW
, RES_CHRATR_RELIEF
,
369 // insert position for CJK/CTL attributes!
370 /*14 */ RES_PARATR_LINESPACING
, RES_PARATR_HYPHENZONE
,
371 /*16 */ RES_PARATR_REGISTER
, RES_PARATR_REGISTER
,
372 /*18 */ RES_PARATR_VERTALIGN
, RES_PARATR_VERTALIGN
,
373 /*20 */ RES_LR_SPACE
, RES_UL_SPACE
,
374 /*22 */ SID_ATTR_PARA_MODEL
, SID_ATTR_PARA_KEEP
,
378 static const sal_uInt16 aCJKAttr
[] =
380 RES_CHRATR_CJK_FONT
, RES_CHRATR_CJK_WEIGHT
,
381 RES_CHRATR_EMPHASIS_MARK
, RES_CHRATR_TWO_LINES
,
382 RES_PARATR_SCRIPTSPACE
, RES_PARATR_FORBIDDEN_RULES
384 static const sal_uInt16 aCTLAttr
[] =
386 RES_CHRATR_CTL_FONT
, RES_CHRATR_CTL_WEIGHT
389 std::vector
<sal_uInt16
> aArr
;
390 aArr
.insert( aArr
.begin(), aNormalAttr
,
391 aNormalAttr
+ SAL_N_ELEMENTS( aNormalAttr
));
392 if( SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
394 aArr
.insert( aArr
.begin() + 14, aCTLAttr
,
395 aCTLAttr
+ SAL_N_ELEMENTS( aCTLAttr
));
397 SvtCJKOptions aCJKOpt
;
398 if( aCJKOpt
.IsAnyEnabled() )
400 aArr
.insert( aArr
.begin() + 14, aCJKAttr
,
401 aCJKAttr
+ SAL_N_ELEMENTS( aCJKAttr
));
404 SfxItemSet
aSet( m_pWrtShell
->GetAttrPool(), &aArr
[0] );
405 sal_uInt16 nWhich
= SID_SEARCH_SEARCHSET
;
407 if ( FID_SEARCH_REPLACESET
== nSlot
)
409 nWhich
= SID_SEARCH_REPLACESET
;
413 m_pReplList
->Get( aSet
);
414 DELETEZ( m_pReplList
);
417 else if ( m_pSrchList
)
419 m_pSrchList
->Get( aSet
);
420 DELETEZ( m_pSrchList
);
422 rReq
.SetReturnValue( SvxSetItem( nWhich
, aSet
) );
426 #if OSL_DEBUG_LEVEL > 1
429 OString
sStr("nSlot: " + OString::number(nSlot
) + " wrong Dispatcher (viewsrch.cxx)");
430 OSL_FAIL(sStr
.getStr());
438 sal_Bool
SwView::SearchAndWrap(sal_Bool bApi
)
440 SwSearchOptions
aOpts( m_pWrtShell
, m_pSrchItem
->GetBackward() );
442 // Startposition der Suche fuer WrapAround merken
443 // Start- / EndAction wegen vielleicht bestehender Selektionen
445 m_pWrtShell
->StartAllAction();
448 // fdo#65014 : Ensure that the point of the cursor is at the extremity of the
449 // selection closest to the end being searched to as to exclude the selected
450 // region from the search. (This doesn't work in the case of multiple
451 // selected regions as the cursor doesn't mark the selection in that case.)
452 m_pWrtShell
->GetCrsr()->Normalize( m_pSrchItem
->GetBackward() );
454 // falls in selektierten Bereichen gesucht werden soll, duerfen sie
455 // nicht aufgehoben werden
456 if (!m_pSrchItem
->GetSelection())
457 m_pWrtShell
->KillSelection(0, false);
459 SwWait
*pWait
= new SwWait( *GetDocShell(), sal_True
);
460 if( FUNC_Search( aOpts
) )
463 if(m_pWrtShell
->IsSelFrmMode())
465 m_pWrtShell
->UnSelectFrm();
466 m_pWrtShell
->LeaveSelFrmMode();
469 m_pWrtShell
->EndAllAction();
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
= m_bExtra
;
479 if (!m_pSrchItem
->GetSelection() && !m_bExtra
)
482 if( FUNC_Search( aOpts
) )
486 m_pWrtShell
->EndAllAction();
492 m_bExtra
= !m_bExtra
;
494 const sal_uInt16 nId
= SvxSearchDialogWrapper::GetChildWindowId();
495 SvxSearchDialogWrapper
*pWrp
= (SvxSearchDialogWrapper
*)GetViewFrame()->GetChildWindow(nId
);
496 m_pSrchDlg
= pWrp
? static_cast <SvxSearchDialog
*> (pWrp
->getDialog ()) : 0;
498 // falls Startposition am Dokumentende / -anfang
501 m_pWrtShell
->EndAllAction();
504 ShowNotFoundInfoBox( m_pSrchDlg
);
506 m_bFound
= sal_False
;
510 m_pWrtShell
->EndAllAction();
511 // noch mal mit WrapAround versuchen?
513 if( bApi
|| RET_NO
== QueryBox( GetParentWindow( m_pSrchDlg
),
514 SW_RES( DOCPOS_START
== aOpts
.eEnd
519 m_bFound
= sal_False
;
523 m_pWrtShell
->StartAllAction();
524 m_pWrtShell
->Pop(sal_False
);
525 pWait
= new SwWait( *GetDocShell(), sal_True
);
527 bool bSrchBkwrd
= DOCPOS_START
== aOpts
.eEnd
;
529 aOpts
.eEnd
= bSrchBkwrd
? DOCPOS_START
: DOCPOS_END
;
530 aOpts
.eStart
= bSrchBkwrd
? DOCPOS_END
: DOCPOS_START
;
534 m_pWrtShell
->ClearMark();
536 m_pWrtShell
->EndDoc();
538 m_pWrtShell
->SttDoc();
541 m_bFound
= 0 != FUNC_Search( aOpts
);
542 m_pWrtShell
->EndAllAction();
548 ShowNotFoundInfoBox( m_pSrchDlg
);
550 return m_bFound
= sal_False
;
554 sal_Bool
SwView::SearchAll(sal_uInt16
* pFound
)
556 SwWait
aWait( *GetDocShell(), sal_True
);
557 m_pWrtShell
->StartAllAction();
559 SwSearchOptions
aOpts( m_pWrtShell
, m_pSrchItem
->GetBackward() );
561 if (!m_pSrchItem
->GetSelection())
563 // bestehende Selektionen aufheben,
564 // wenn nicht in selektierten Bereichen gesucht werden soll
565 m_pWrtShell
->KillSelection(0, false);
567 if( DOCPOS_START
== aOpts
.eEnd
)
568 m_pWrtShell
->EndDoc();
570 m_pWrtShell
->SttDoc();
573 sal_uInt16 nFound
= (sal_uInt16
)FUNC_Search( aOpts
);
576 m_bFound
= 0 != nFound
;
578 m_pWrtShell
->EndAllAction();
583 void SwView::Replace()
585 SwWait
aWait( *GetDocShell(), sal_True
);
587 m_pWrtShell
->StartAllAction();
589 if( m_pSrchItem
->GetPattern() ) // Vorlagen?
591 SwRewriter aRewriter
;
592 aRewriter
.AddRule(UndoArg1
, m_pSrchItem
->GetSearchString());
593 aRewriter
.AddRule(UndoArg2
, SW_RESSTR(STR_YIELDS
));
594 aRewriter
.AddRule(UndoArg3
, m_pSrchItem
->GetReplaceString());
596 m_pWrtShell
->StartUndo(UNDO_UI_REPLACE_STYLE
, &aRewriter
);
598 m_pWrtShell
->SetTxtFmtColl( m_pWrtShell
->GetParaStyle(
599 m_pSrchItem
->GetReplaceString(),
600 SwWrtShell::GETSTYLE_CREATESOME
));
602 m_pWrtShell
->EndUndo();
606 if (GetPostItMgr()->HasActiveSidebarWin())
607 GetPostItMgr()->Replace(m_pSrchItem
);
609 sal_Bool bReqReplace
= true;
611 if(m_pWrtShell
->HasSelection())
613 /* check that the selection match the search string*/
615 SwPosition aStartPos
= (* m_pWrtShell
->GetSwCrsr()->Start());
616 SwPosition aEndPos
= (* m_pWrtShell
->GetSwCrsr()->End());
617 sal_Bool bHasSelection
= m_pSrchItem
->GetSelection();
618 sal_uInt16 nOldCmd
= m_pSrchItem
->GetCommand();
620 //set state for checking if current selection has a match
621 m_pSrchItem
->SetCommand( SVX_SEARCHCMD_FIND
);
622 m_pSrchItem
->SetSelection(true);
625 SwSearchOptions
aOpts( m_pWrtShell
, m_pSrchItem
->GetBackward() );
626 if( ! FUNC_Search(aOpts
) )
629 //no matching therefore should not replace selection
630 // => remove selection
632 if(! m_pSrchItem
->GetBackward() )
634 (* m_pWrtShell
->GetSwCrsr()->Start()) = aStartPos
;
635 (* m_pWrtShell
->GetSwCrsr()->End()) = aEndPos
;
639 (* m_pWrtShell
->GetSwCrsr()->Start()) = aEndPos
;
640 (* m_pWrtShell
->GetSwCrsr()->End()) = aStartPos
;
645 //set back old search state
646 m_pSrchItem
->SetCommand( nOldCmd
);
647 m_pSrchItem
->SetSelection(bHasSelection
);
650 * remove current selection
651 * otherwise it is always replaced
652 * no matter if the search string exists or not in the selection
653 * Now the selection is removed and the next matching string is selected
659 sal_Bool bReplaced
= m_pWrtShell
->SwEditShell::Replace( m_pSrchItem
->GetReplaceString(),
660 m_pSrchItem
->GetRegExp());
661 if( bReplaced
&& m_pReplList
&& m_pReplList
->Count() && m_pWrtShell
->HasSelection() )
663 SfxItemSet
aReplSet( m_pWrtShell
->GetAttrPool(),
664 aTxtFmtCollSetRange
);
665 if( m_pReplList
->Get( aReplSet
).Count() )
667 ::SfxToSwPageDescAttr( *m_pWrtShell
, aReplSet
);
668 m_pWrtShell
->SwEditShell::SetAttr( aReplSet
);
674 m_pWrtShell
->EndAllAction();
679 SwSearchOptions::SwSearchOptions( SwWrtShell
* pSh
, sal_Bool bBackward
)
681 eStart
= DOCPOS_CURR
;
685 bDontWrap
= pSh
->IsEndOfDoc();
690 bDontWrap
= pSh
->IsStartOfDoc();
694 sal_uLong
SwView::FUNC_Search( const SwSearchOptions
& rOptions
)
696 sal_Bool bDoReplace
= m_pSrchItem
->GetCommand() == SVX_SEARCHCMD_REPLACE
||
697 m_pSrchItem
->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL
;
699 int eRanges
= m_pSrchItem
->GetSelection() ?
700 FND_IN_SEL
: m_bExtra
? FND_IN_OTHER
: FND_IN_BODY
;
701 if (m_pSrchItem
->GetCommand() == SVX_SEARCHCMD_FIND_ALL
||
702 m_pSrchItem
->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL
)
703 eRanges
|= FND_IN_SELALL
;
705 m_pWrtShell
->SttSelect();
707 static sal_uInt16 aSearchAttrRange
[] = {
708 RES_FRMATR_BEGIN
, RES_FRMATR_END
-1,
709 RES_CHRATR_BEGIN
, RES_CHRATR_END
-1,
710 RES_PARATR_BEGIN
, RES_PARATR_END
-1,
711 SID_ATTR_PARA_MODEL
, SID_ATTR_PARA_KEEP
,
714 SfxItemSet
aSrchSet( m_pWrtShell
->GetAttrPool(), aSearchAttrRange
);
715 if( m_pSrchList
&& m_pSrchList
->Count() )
717 m_pSrchList
->Get( aSrchSet
);
719 /* -- Seitenumbruch mit Seitenvorlage */
720 ::SfxToSwPageDescAttr( *m_pWrtShell
, aSrchSet
);
723 SfxItemSet
* pReplSet
= 0;
724 if( bDoReplace
&& m_pReplList
&& m_pReplList
->Count() )
726 pReplSet
= new SfxItemSet( m_pWrtShell
->GetAttrPool(),
728 m_pReplList
->Get( *pReplSet
);
730 /* -- Seitenumbruch mit Seitenvorlage */
731 ::SfxToSwPageDescAttr( *m_pWrtShell
, *pReplSet
);
733 if( !pReplSet
->Count() ) // schade, die Attribute
734 DELETEZ( pReplSet
); // kennen wir nicht
738 // build SearchOptions to be used
740 SearchOptions
aSearchOpt( m_pSrchItem
->GetSearchOptions() );
741 aSearchOpt
.Locale
= GetAppLanguageTag().getLocale();
743 aSearchOpt
.replaceString
= aEmptyStr
;
746 if( aSrchSet
.Count() || ( pReplSet
&& pReplSet
->Count() ))
748 nFound
= m_pWrtShell
->SearchAttr(
750 !m_pSrchItem
->GetPattern(),
754 m_pSrchItem
->GetSearchString().Len() ? &aSearchOpt
: 0,
757 else if( m_pSrchItem
->GetPattern() )
759 // Suchen (und ersetzen) von Vorlagen
760 const String
sRplStr( m_pSrchItem
->GetReplaceString() );
761 nFound
= m_pWrtShell
->SearchTempl( m_pSrchItem
->GetSearchString(),
765 bDoReplace
? &sRplStr
: 0 );
770 nFound
= m_pWrtShell
->SearchPattern(aSearchOpt
, m_pSrchItem
->GetNotes(),
776 m_pWrtShell
->EndSelect();
780 Dialog
* SwView::GetSearchDialog()
782 const sal_uInt16 nId
= SvxSearchDialogWrapper::GetChildWindowId();
783 SvxSearchDialogWrapper
*pWrp
= (SvxSearchDialogWrapper
*)SfxViewFrame::Current()->GetChildWindow(nId
);
785 m_pSrchDlg
= pWrp
->getDialog ();
791 void SwView::StateSearch(SfxItemSet
&rSet
)
793 SfxWhichIter
aIter(rSet
);
794 sal_uInt16 nWhich
= aIter
.FirstWhich();
800 case SID_SEARCH_OPTIONS
:
802 sal_uInt16 nOpt
= 0xFFFF;
803 if( GetDocShell()->IsReadOnly() )
804 nOpt
&= ~( SEARCH_OPTIONS_REPLACE
|
805 SEARCH_OPTIONS_REPLACE_ALL
);
806 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, nOpt
));
809 case SID_SEARCH_ITEM
:
813 m_pSrchItem
= new SvxSearchItem( SID_SEARCH_ITEM
);
814 m_pSrchItem
->SetFamily(SFX_STYLE_FAMILY_PARA
);
815 m_pSrchItem
->SetSearchString( m_pWrtShell
->GetSelTxt() );
818 if( m_bJustOpened
&& m_pWrtShell
->IsSelection() )
821 if( 1 == m_pWrtShell
->GetCrsrCnt() &&
822 ( aTxt
= m_pWrtShell
->SwCrsrShell::GetSelTxt() ).Len() )
824 m_pSrchItem
->SetSearchString( aTxt
);
825 m_pSrchItem
->SetSelection( sal_False
);
828 m_pSrchItem
->SetSelection( sal_True
);
831 m_bJustOpened
= false;
832 rSet
.Put( *m_pSrchItem
);
836 nWhich
= aIter
.NextWhich();
842 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */