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