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