2000-09-18 16:15:01 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* $RCSfile: viewsrch.cxx,v $
|
2008-04-11 13:04:48 +00:00
|
|
|
* $Revision: 1.31 $
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 20:52:16 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 22:26:40 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sw.hxx"
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#include <string> // HACK: prevent conflict between STLPORT and Workshop headers
|
2001-03-27 20:47:24 +00:00
|
|
|
#include <hintids.hxx>
|
2001-03-12 07:18:49 +00:00
|
|
|
#include <com/sun/star/util/SearchOptions.hpp>
|
2001-10-31 14:55:46 +00:00
|
|
|
#include <svtools/cjkoptions.hxx>
|
2003-03-27 14:45:43 +00:00
|
|
|
#include <svtools/ctloptions.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <svx/pageitem.hxx>
|
|
|
|
#include <svtools/whiter.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <svtools/stritem.hxx>
|
2004-02-03 15:59:24 +00:00
|
|
|
#ifndef _T2XTCMP_HXX //autogen
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <svtools/txtcmp.hxx>
|
|
|
|
#endif
|
|
|
|
#include <svtools/itempool.hxx>
|
|
|
|
#include <svtools/eitem.hxx>
|
|
|
|
#include <svx/srchitem.hxx>
|
|
|
|
#include <sfx2/request.hxx>
|
|
|
|
#include <svx/srchdlg.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <vcl/wrkwin.hxx>
|
2004-08-23 08:11:21 +00:00
|
|
|
#include "svx/unolingu.hxx"
|
2003-05-22 07:49:31 +00:00
|
|
|
#include <swmodule.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <swwait.hxx>
|
2001-03-27 20:47:24 +00:00
|
|
|
#include <workctrl.hxx>
|
|
|
|
#ifndef _VIEW_HXX
|
|
|
|
#include <view.hxx>
|
|
|
|
#endif
|
|
|
|
#include <wrtsh.hxx>
|
|
|
|
#include <swundo.hxx> // fuer Undo-Ids
|
|
|
|
#include <uitool.hxx>
|
|
|
|
#ifndef _CMDID_H
|
|
|
|
#include <cmdid.h>
|
|
|
|
#endif
|
|
|
|
#ifndef _DOCSH_HXX
|
|
|
|
#include <docsh.hxx>
|
|
|
|
#endif
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2001-03-27 20:47:24 +00:00
|
|
|
#ifndef _VIEW_HRC
|
|
|
|
#include <view.hrc>
|
|
|
|
#endif
|
2004-09-08 14:04:41 +00:00
|
|
|
#include <SwRewriter.hxx>
|
|
|
|
#include <undobj.hxx>
|
|
|
|
#ifndef _COMCORE_HRC
|
|
|
|
#include <comcore.hrc>
|
|
|
|
#endif
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2008-04-11 13:04:48 +00:00
|
|
|
#include "PostItMgr.hxx"
|
|
|
|
|
2001-03-12 07:18:49 +00:00
|
|
|
using namespace com::sun::star;
|
2007-09-27 11:38:59 +00:00
|
|
|
using namespace ::com::sun::star::i18n;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::i18n;
|
2001-03-12 07:18:49 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
#define SRCH_ATTR_OFF 0
|
|
|
|
#define SRCH_ATTR_ON 1
|
|
|
|
#define SRCH_ATTR_SET 2
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
Beschreibung: Search Parameter
|
|
|
|
--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct SwSearchOptions
|
|
|
|
{
|
|
|
|
SwDocPositions eStart, eEnd;
|
|
|
|
BOOL bDontWrap;
|
|
|
|
|
|
|
|
SwSearchOptions( SwWrtShell* pSh, BOOL bBackward );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline Window* GetParentWindow( SvxSearchDialog* pSrchDlg )
|
|
|
|
{
|
|
|
|
Window* pWin;
|
|
|
|
if( pSrchDlg && pSrchDlg->IsVisible() )
|
|
|
|
pWin = pSrchDlg;
|
|
|
|
else
|
|
|
|
pWin = 0;
|
|
|
|
return pWin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------12.04.97 13:04-------------------
|
|
|
|
|
|
|
|
--------------------------------------------------*/
|
|
|
|
|
|
|
|
|
2001-10-31 14:55:46 +00:00
|
|
|
void SwView::ExecSearch(SfxRequest& rReq, BOOL bNoMessage)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
const SfxItemSet* pArgs = rReq.GetArgs();
|
|
|
|
const SfxPoolItem* pItem = 0;
|
2002-06-27 08:01:46 +00:00
|
|
|
const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
|
|
|
|
SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
|
2003-04-28 14:18:08 +00:00
|
|
|
BOOL bQuiet = FALSE;
|
|
|
|
if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_SEARCH_QUIET, FALSE, &pItem))
|
|
|
|
bQuiet = ((const SfxBoolItem*) pItem)->GetValue();
|
|
|
|
|
|
|
|
BOOL bApi = bQuiet | bNoMessage;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
USHORT nSlot = rReq.GetSlot();
|
|
|
|
if (nSlot == FN_REPEAT_SEARCH && !pSrchItem)
|
|
|
|
{
|
|
|
|
if(bApi)
|
|
|
|
{
|
|
|
|
rReq.SetReturnValue(SfxBoolItem(nSlot, FALSE));
|
|
|
|
nSlot = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (nSlot)
|
|
|
|
{
|
|
|
|
// erstmal Nichts tun
|
|
|
|
case SID_SEARCH_ITEM:
|
|
|
|
{
|
|
|
|
delete pSrchItem;
|
|
|
|
pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FID_SEARCH_ON:
|
|
|
|
bJustOpened = TRUE;
|
|
|
|
GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FID_SEARCH_OFF:
|
|
|
|
if(pArgs)
|
|
|
|
{
|
|
|
|
// Dialog abmelden
|
|
|
|
delete pSrchItem;
|
|
|
|
pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
|
|
|
|
|
|
|
|
DELETEZ( pSrchList );
|
|
|
|
DELETEZ( pReplList );
|
|
|
|
|
|
|
|
if ( pWrp )
|
|
|
|
{
|
|
|
|
pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
|
|
|
|
// die Search / Replace -Items merken wir uns
|
|
|
|
const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
|
|
|
|
if( pList && pList->Count() )
|
|
|
|
pSrchList = new SearchAttrItemList( *pList );
|
|
|
|
|
|
|
|
if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
|
|
|
|
pList->Count() )
|
|
|
|
pReplList = new SearchAttrItemList( *pList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FN_REPEAT_SEARCH:
|
|
|
|
case FID_SEARCH_NOW:
|
2003-04-28 14:18:08 +00:00
|
|
|
{
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
if(FID_SEARCH_NOW == nSlot && !rReq.IsAPI())
|
|
|
|
SwView::SetMoveType(NID_SRCH_REP);
|
|
|
|
if ( pWrp )
|
|
|
|
{
|
|
|
|
pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pSrchDlg = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pSrchDlg)
|
|
|
|
{
|
|
|
|
DELETEZ( pSrchList );
|
|
|
|
DELETEZ( pReplList );
|
|
|
|
|
|
|
|
const SearchAttrItemList* pList = pSrchDlg->GetSearchItemList();
|
|
|
|
if( pList && pList->Count() )
|
|
|
|
pSrchList = new SearchAttrItemList( *pList );
|
|
|
|
|
|
|
|
if( 0 != (pList = pSrchDlg->GetReplaceItemList() ) &&
|
|
|
|
pList->Count() )
|
|
|
|
pReplList = new SearchAttrItemList( *pList );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nSlot == FN_REPEAT_SEARCH)
|
|
|
|
{
|
|
|
|
ASSERT(pSrchItem, "Search-Item fehlt");
|
2000-10-20 13:52:05 +00:00
|
|
|
if( !pSrchItem )
|
2007-05-10 15:26:31 +00:00
|
|
|
pSrchItem = new SvxSearchItem(SID_SEARCH_ITEM);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SearchItem aus Request besorgen
|
|
|
|
ASSERT(pArgs, "Args fehlen");
|
2007-11-19 16:16:54 +00:00
|
|
|
if ( pArgs )
|
|
|
|
{
|
|
|
|
delete pSrchItem;
|
|
|
|
pSrchItem = (SvxSearchItem*) pArgs->Get(SID_SEARCH_ITEM).Clone();
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (pSrchItem->GetCommand())
|
|
|
|
{
|
|
|
|
case SVX_SEARCHCMD_FIND:
|
|
|
|
{
|
|
|
|
BOOL bRet = SearchAndWrap(bApi);
|
|
|
|
if( bRet )
|
|
|
|
Scroll(pWrtShell->GetCharRect().SVRect());
|
|
|
|
rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SVX_SEARCHCMD_FIND_ALL:
|
|
|
|
{
|
|
|
|
BOOL bRet = SearchAll();
|
|
|
|
if( !bRet )
|
|
|
|
{
|
|
|
|
if( !bApi )
|
|
|
|
{
|
|
|
|
Window* pParentWindow = GetParentWindow( pSrchDlg );
|
|
|
|
InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
|
|
|
|
}
|
|
|
|
bFound = FALSE;
|
|
|
|
}
|
|
|
|
rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SVX_SEARCHCMD_REPLACE:
|
|
|
|
{
|
|
|
|
|
|
|
|
// 1) Selektion ersetzen (nicht. wenn nur Attribute ersetzt
|
|
|
|
// werden sollen)
|
|
|
|
//JP 27.04.95: warum ?
|
|
|
|
// was ist, wenn man das gefundene nur attributieren will??
|
|
|
|
|
|
|
|
USHORT nCmd = SVX_SEARCHCMD_FIND;
|
|
|
|
if( pSrchItem->GetReplaceString().Len() ||
|
|
|
|
!pReplList )
|
|
|
|
{
|
|
|
|
// Verhindern, dass - falls der Suchstring im
|
|
|
|
// Ersetzungsstring enthalten ist - der ersetzte String
|
|
|
|
// noch einmal gefunden wird.
|
|
|
|
|
|
|
|
BOOL bBack = pSrchItem->GetBackward();
|
|
|
|
if (bBack)
|
|
|
|
pWrtShell->Push();
|
2007-12-05 15:44:36 +00:00
|
|
|
String aReplace( pSrchItem->GetReplaceString() );
|
|
|
|
SearchOptions aTmp( pSrchItem->GetSearchOptions() );
|
|
|
|
String *pBackRef = ReplaceBackReferences( aTmp, pWrtShell->GetCrsr() );
|
|
|
|
if( pBackRef )
|
|
|
|
pSrchItem->SetReplaceString( *pBackRef );
|
2000-09-18 16:15:01 +00:00
|
|
|
Replace();
|
2007-12-05 15:44:36 +00:00
|
|
|
if( pBackRef )
|
|
|
|
{
|
|
|
|
pSrchItem->SetReplaceString( aReplace );
|
|
|
|
delete pBackRef;
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
if (bBack)
|
|
|
|
{
|
|
|
|
pWrtShell->Pop();
|
|
|
|
pWrtShell->SwapPam();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( pReplList )
|
|
|
|
nCmd = SVX_SEARCHCMD_REPLACE;
|
|
|
|
|
|
|
|
// 2) Weiter suchen (ohne zu ersetzen!)
|
|
|
|
|
|
|
|
USHORT nOldCmd = pSrchItem->GetCommand();
|
|
|
|
pSrchItem->SetCommand( nCmd );
|
|
|
|
BOOL bRet = SearchAndWrap(bApi);
|
|
|
|
if( bRet )
|
|
|
|
Scroll( pWrtShell->GetCharRect().SVRect());
|
|
|
|
pSrchItem->SetCommand( nOldCmd );
|
|
|
|
rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SVX_SEARCHCMD_REPLACE_ALL:
|
|
|
|
{
|
|
|
|
SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
|
|
|
|
|
|
|
|
|
|
|
|
if( !pSrchItem->GetSelection() )
|
|
|
|
{
|
|
|
|
// bestehende Selektionen aufheben,
|
|
|
|
// wenn nicht in selektierten Bereichen gesucht werden soll
|
|
|
|
(pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
|
|
|
|
if( DOCPOS_START == aOpts.eEnd )
|
|
|
|
pWrtShell->EndDoc();
|
|
|
|
else
|
|
|
|
pWrtShell->SttDoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
bExtra = FALSE;
|
|
|
|
ULONG nFound;
|
|
|
|
|
|
|
|
{ //Scope for SwWait-Object
|
|
|
|
SwWait aWait( *GetDocShell(), TRUE );
|
|
|
|
pWrtShell->StartAllAction();
|
|
|
|
nFound = FUNC_Search( aOpts );
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
}
|
2002-09-13 12:19:33 +00:00
|
|
|
rReq.SetReturnValue(SfxBoolItem(nSlot, nFound != 0 && ULONG_MAX != nFound));
|
2000-09-18 16:15:01 +00:00
|
|
|
if( !nFound )
|
|
|
|
{
|
|
|
|
if( !bApi )
|
|
|
|
{
|
|
|
|
Window* pParentWindow = GetParentWindow( pSrchDlg );
|
|
|
|
InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
|
|
|
|
}
|
|
|
|
bFound = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-19 13:43:50 +00:00
|
|
|
if( !bApi && ULONG_MAX != nFound)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
String aText( SW_RES( STR_NB_REPLACED ) );
|
|
|
|
const xub_StrLen nPos = aText.Search( String::CreateFromAscii("XX") );
|
|
|
|
aText.Erase( nPos, 2 );
|
|
|
|
aText.Insert( String::CreateFromInt32( nFound ), nPos );
|
|
|
|
Window* pParentWindow = GetParentWindow( pSrchDlg );
|
|
|
|
InfoBox( pParentWindow, aText ).Execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-04-11 13:04:48 +00:00
|
|
|
|
2007-09-27 11:38:59 +00:00
|
|
|
uno::Reference< frame::XDispatchRecorder > xRecorder =
|
2003-04-28 14:18:08 +00:00
|
|
|
GetViewFrame()->GetBindings().GetRecorder();
|
|
|
|
//prevent additional dialogs in recorded macros
|
|
|
|
if ( xRecorder.is() )
|
|
|
|
rReq.AppendItem(SfxBoolItem(SID_SEARCH_QUIET, sal_True));
|
2002-06-27 08:01:46 +00:00
|
|
|
|
|
|
|
rReq.Done();
|
2003-04-28 14:18:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-09-18 16:15:01 +00:00
|
|
|
case FID_SEARCH_SEARCHSET:
|
|
|
|
case FID_SEARCH_REPLACESET:
|
|
|
|
{
|
2001-10-31 14:55:46 +00:00
|
|
|
static const USHORT aNormalAttr[] =
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-10-31 14:55:46 +00:00
|
|
|
/* 0 */ RES_CHRATR_CASEMAP, RES_CHRATR_CASEMAP,
|
|
|
|
/* 2 */ RES_CHRATR_COLOR, RES_CHRATR_POSTURE,
|
|
|
|
/* 4 */ RES_CHRATR_SHADOWED, RES_CHRATR_WORDLINEMODE,
|
|
|
|
/* 6 */ RES_CHRATR_BLINK, RES_CHRATR_BLINK,
|
|
|
|
/* 8 */ RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND,
|
|
|
|
/*10 */ RES_CHRATR_ROTATE, RES_CHRATR_ROTATE,
|
|
|
|
/*12 */ RES_CHRATR_SCALEW, RES_CHRATR_RELIEF,
|
|
|
|
// insert position for CJK/CTL attributes!
|
|
|
|
/*14 */ RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
|
|
|
|
/*16 */ RES_PARATR_REGISTER, RES_PARATR_REGISTER,
|
|
|
|
/*18 */ RES_PARATR_VERTALIGN, RES_PARATR_VERTALIGN,
|
|
|
|
/*20 */ RES_LR_SPACE, RES_UL_SPACE,
|
|
|
|
/*22 */ SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
|
|
|
|
/*24 */ 0
|
2000-09-18 16:15:01 +00:00
|
|
|
};
|
|
|
|
|
2001-10-31 14:55:46 +00:00
|
|
|
static const USHORT aCJKAttr[] =
|
|
|
|
{
|
|
|
|
RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_WEIGHT,
|
|
|
|
RES_CHRATR_EMPHASIS_MARK, RES_CHRATR_TWO_LINES,
|
|
|
|
RES_PARATR_SCRIPTSPACE, RES_PARATR_FORBIDDEN_RULES
|
|
|
|
};
|
|
|
|
static const USHORT aCTLAttr[] =
|
|
|
|
{
|
|
|
|
RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_WEIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
SvUShorts aArr( 0, 16 );
|
|
|
|
aArr.Insert( aNormalAttr,
|
|
|
|
sizeof( aNormalAttr ) / sizeof( aNormalAttr[0] ),
|
|
|
|
0 );
|
2003-05-22 07:49:31 +00:00
|
|
|
if( SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
|
2001-10-31 14:55:46 +00:00
|
|
|
aArr.Insert( aCTLAttr,
|
|
|
|
sizeof( aCTLAttr ) / sizeof( aCTLAttr[0] ),
|
|
|
|
14 );
|
|
|
|
SvtCJKOptions aCJKOpt;
|
|
|
|
if( aCJKOpt.IsAnyEnabled() )
|
|
|
|
aArr.Insert( aCJKAttr,
|
|
|
|
sizeof( aCJKAttr ) / sizeof( aCJKAttr[0] ),
|
|
|
|
14 );
|
|
|
|
|
|
|
|
SfxItemSet aSet( pWrtShell->GetAttrPool(), aArr.GetData() );
|
2000-09-18 16:15:01 +00:00
|
|
|
USHORT nWhich = SID_SEARCH_SEARCHSET;
|
|
|
|
|
|
|
|
if ( FID_SEARCH_REPLACESET == nSlot )
|
|
|
|
{
|
|
|
|
nWhich = SID_SEARCH_REPLACESET;
|
|
|
|
|
|
|
|
if ( pReplList )
|
|
|
|
{
|
|
|
|
pReplList->Get( aSet );
|
|
|
|
DELETEZ( pReplList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( pSrchList )
|
|
|
|
{
|
|
|
|
pSrchList->Get( aSet );
|
|
|
|
DELETEZ( pSrchList );
|
|
|
|
}
|
|
|
|
rReq.SetReturnValue( SvxSetItem( nWhich, aSet ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef PRODUCT
|
|
|
|
if(nSlot)
|
|
|
|
{
|
|
|
|
ByteString sStr( "nSlot: " );
|
|
|
|
sStr += ByteString::CreateFromInt32( nSlot );
|
|
|
|
sStr += " falscher Dispatcher (viewsrch.cxx)";
|
|
|
|
DBG_ERROR( sStr.GetBuffer() );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL SwView::SearchAndWrap(BOOL bApi)
|
|
|
|
{
|
|
|
|
SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
|
|
|
|
|
|
|
|
// Startposition der Suche fuer WrapAround merken
|
|
|
|
// Start- / EndAction wegen vielleicht bestehender Selektionen
|
|
|
|
// aus 'Suche alle'
|
|
|
|
pWrtShell->StartAllAction();
|
|
|
|
pWrtShell->Push();
|
|
|
|
// falls in selektierten Bereichen gesucht werden soll, duerfen sie
|
|
|
|
// nicht aufgehoben werden
|
|
|
|
if (!pSrchItem->GetSelection())
|
|
|
|
(pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
|
|
|
|
|
|
|
|
SwWait *pWait = new SwWait( *GetDocShell(), TRUE );
|
|
|
|
if( FUNC_Search( aOpts ) )
|
|
|
|
{
|
|
|
|
bFound = TRUE;
|
|
|
|
if(pWrtShell->IsSelFrmMode())
|
|
|
|
{
|
|
|
|
pWrtShell->UnSelectFrm();
|
|
|
|
pWrtShell->LeaveSelFrmMode();
|
|
|
|
}
|
|
|
|
pWrtShell->Pop();
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
delete pWait;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
delete pWait, pWait = 0;
|
|
|
|
|
|
|
|
// Suchen in den Sonderbereichen, wenn keine
|
|
|
|
// Suche in Selektionen vorliegt. Bei Suche in Selektionen
|
|
|
|
// wird ohnehin in diesen Sonderbereichen gesucht
|
|
|
|
BOOL bHasSrchInOther = bExtra;
|
|
|
|
if (!pSrchItem->GetSelection() && !bExtra )
|
|
|
|
{
|
|
|
|
bExtra = TRUE;
|
|
|
|
if( FUNC_Search( aOpts ) )
|
|
|
|
{
|
|
|
|
bFound = TRUE;
|
|
|
|
pWrtShell->Pop();
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
bExtra = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bExtra = !bExtra;
|
|
|
|
|
|
|
|
const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
|
|
|
|
SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)GetViewFrame()->GetChildWindow(nId);
|
|
|
|
pSrchDlg = pWrp ? (SvxSearchDialog*)(pWrp->GetWindow()) : 0;
|
|
|
|
|
|
|
|
// falls Startposition am Dokumentende / -anfang
|
|
|
|
if (aOpts.bDontWrap)
|
|
|
|
{
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
if( !bApi )
|
|
|
|
{
|
|
|
|
Window* pParentWindow = GetParentWindow( pSrchDlg );
|
|
|
|
InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
|
|
|
|
}
|
|
|
|
bFound = FALSE;
|
|
|
|
pWrtShell->Pop();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
// noch mal mit WrapAround versuchen?
|
|
|
|
|
|
|
|
if( bApi || RET_NO == QueryBox( GetParentWindow( pSrchDlg ),
|
|
|
|
SW_RES( DOCPOS_START == aOpts.eEnd
|
|
|
|
? MSG_SEARCH_START
|
|
|
|
: MSG_SEARCH_END )
|
|
|
|
).Execute() )
|
|
|
|
{
|
|
|
|
bFound = FALSE;
|
|
|
|
pWrtShell->Pop();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pWrtShell->StartAllAction();
|
|
|
|
pWrtShell->Pop(FALSE);
|
|
|
|
pWait = new SwWait( *GetDocShell(), TRUE );
|
|
|
|
|
|
|
|
BOOL bSrchBkwrd = DOCPOS_START == aOpts.eEnd;
|
|
|
|
|
|
|
|
aOpts.eEnd = bSrchBkwrd ? DOCPOS_START : DOCPOS_END;
|
|
|
|
aOpts.eStart = bSrchBkwrd ? DOCPOS_END : DOCPOS_START;
|
|
|
|
|
|
|
|
if (bHasSrchInOther)
|
|
|
|
{
|
|
|
|
pWrtShell->ClearMark();
|
|
|
|
if (bSrchBkwrd)
|
|
|
|
pWrtShell->EndDoc();
|
|
|
|
else
|
|
|
|
pWrtShell->SttDoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
bFound = 0 != FUNC_Search( aOpts );
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
delete pWait;
|
|
|
|
if ( bFound )
|
|
|
|
return bFound;
|
|
|
|
if(!bApi)
|
|
|
|
{
|
|
|
|
Window* pParentWindow = GetParentWindow( pSrchDlg );
|
|
|
|
InfoBox( pParentWindow, SW_RES(MSG_NOT_FOUND)).Execute();
|
|
|
|
}
|
|
|
|
return bFound = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL SwView::SearchAll(USHORT* pFound)
|
|
|
|
{
|
|
|
|
SwWait aWait( *GetDocShell(), TRUE );
|
|
|
|
pWrtShell->StartAllAction();
|
|
|
|
|
|
|
|
SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
|
|
|
|
|
|
|
|
if (!pSrchItem->GetSelection())
|
|
|
|
{
|
|
|
|
// bestehende Selektionen aufheben,
|
|
|
|
// wenn nicht in selektierten Bereichen gesucht werden soll
|
|
|
|
(pWrtShell->*pWrtShell->fnKillSel)(0, FALSE);
|
|
|
|
|
|
|
|
if( DOCPOS_START == aOpts.eEnd )
|
|
|
|
pWrtShell->EndDoc();
|
|
|
|
else
|
|
|
|
pWrtShell->SttDoc();
|
|
|
|
}
|
|
|
|
bExtra = FALSE;
|
2003-03-27 14:45:43 +00:00
|
|
|
USHORT nFound = (USHORT)FUNC_Search( aOpts );
|
2000-09-18 16:15:01 +00:00
|
|
|
if(pFound)
|
|
|
|
*pFound = nFound;
|
|
|
|
bFound = 0 != nFound;
|
|
|
|
|
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SwView::Replace()
|
|
|
|
{
|
|
|
|
SwWait aWait( *GetDocShell(), TRUE );
|
|
|
|
|
|
|
|
pWrtShell->StartAllAction();
|
|
|
|
|
|
|
|
if( pSrchItem->GetPattern() ) // Vorlagen?
|
2004-05-18 13:13:00 +00:00
|
|
|
{
|
2004-09-08 14:04:41 +00:00
|
|
|
SwRewriter aRewriter;
|
|
|
|
aRewriter.AddRule(UNDO_ARG1, pSrchItem->GetSearchString());
|
|
|
|
aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
|
|
|
|
aRewriter.AddRule(UNDO_ARG3, pSrchItem->GetReplaceString());
|
|
|
|
|
2007-09-27 11:38:59 +00:00
|
|
|
pWrtShell->StartUndo(UNDO_UI_REPLACE_STYLE, &aRewriter); // #111827#
|
2004-05-18 13:13:00 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
pWrtShell->SetTxtFmtColl( pWrtShell->GetParaStyle(
|
|
|
|
pSrchItem->GetReplaceString(),
|
|
|
|
SwWrtShell::GETSTYLE_CREATESOME ));
|
2004-05-18 13:13:00 +00:00
|
|
|
|
2007-09-27 11:38:59 +00:00
|
|
|
pWrtShell->EndUndo(UNDO_UI_REPLACE_STYLE); // #111827#
|
2004-05-18 13:13:00 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
|
|
|
|
pSrchItem->GetRegExp());
|
|
|
|
|
|
|
|
if( pReplList && pReplList->Count() && pWrtShell->HasSelection() )
|
|
|
|
{
|
|
|
|
SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
|
|
|
|
aTxtFmtCollSetRange );
|
|
|
|
if( pReplList->Get( aReplSet ).Count() )
|
|
|
|
{
|
|
|
|
::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
|
|
|
|
pWrtShell->SwEditShell::SetAttr( aReplSet );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 13:13:00 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
pWrtShell->EndAllAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SwSearchOptions::SwSearchOptions( SwWrtShell* pSh, BOOL bBackward )
|
|
|
|
{
|
|
|
|
eStart = DOCPOS_CURR;
|
|
|
|
if( bBackward )
|
|
|
|
{
|
|
|
|
eEnd = DOCPOS_START;
|
|
|
|
bDontWrap = pSh->IsEndOfDoc();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eEnd = DOCPOS_END;
|
|
|
|
bDontWrap = pSh->IsStartOfDoc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG SwView::FUNC_Search( const SwSearchOptions& rOptions )
|
|
|
|
{
|
|
|
|
BOOL bDoReplace = pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE ||
|
|
|
|
pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL;
|
|
|
|
|
|
|
|
int eRanges = pSrchItem->GetSelection() ?
|
|
|
|
FND_IN_SEL : bExtra ? FND_IN_OTHER : FND_IN_BODY;
|
|
|
|
if (pSrchItem->GetCommand() == SVX_SEARCHCMD_FIND_ALL ||
|
|
|
|
pSrchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
|
|
|
|
eRanges |= FND_IN_SELALL;
|
|
|
|
|
|
|
|
pWrtShell->SttSelect();
|
|
|
|
|
|
|
|
static USHORT __READONLY_DATA aSearchAttrRange[] = {
|
|
|
|
RES_FRMATR_BEGIN, RES_FRMATR_END-1,
|
|
|
|
RES_CHRATR_BEGIN, RES_CHRATR_END-1,
|
|
|
|
RES_PARATR_BEGIN, RES_PARATR_END-1,
|
|
|
|
SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
|
|
|
|
0 };
|
|
|
|
|
|
|
|
SfxItemSet aSrchSet( pWrtShell->GetAttrPool(), aSearchAttrRange);
|
|
|
|
if( pSrchList && pSrchList->Count() )
|
|
|
|
{
|
|
|
|
pSrchList->Get( aSrchSet );
|
|
|
|
|
|
|
|
/* -- Seitenumbruch mit Seitenvorlage */
|
|
|
|
::SfxToSwPageDescAttr( *pWrtShell, aSrchSet );
|
|
|
|
}
|
|
|
|
|
|
|
|
SfxItemSet* pReplSet = 0;
|
|
|
|
if( bDoReplace && pReplList && pReplList->Count() )
|
|
|
|
{
|
|
|
|
pReplSet = new SfxItemSet( pWrtShell->GetAttrPool(),
|
|
|
|
aSearchAttrRange );
|
|
|
|
pReplList->Get( *pReplSet );
|
|
|
|
|
|
|
|
/* -- Seitenumbruch mit Seitenvorlage */
|
|
|
|
::SfxToSwPageDescAttr( *pWrtShell, *pReplSet );
|
|
|
|
|
|
|
|
if( !pReplSet->Count() ) // schade, die Attribute
|
|
|
|
DELETEZ( pReplSet ); // kennen wir nicht
|
|
|
|
}
|
|
|
|
|
2001-03-12 07:18:49 +00:00
|
|
|
//
|
|
|
|
// build SearchOptions to be used
|
|
|
|
//
|
2001-03-27 20:47:24 +00:00
|
|
|
SearchOptions aSearchOpt( pSrchItem->GetSearchOptions() );
|
2004-08-23 08:11:21 +00:00
|
|
|
aSearchOpt.Locale = SvxCreateLocale( (USHORT)GetAppLanguage() );
|
2001-10-08 13:18:33 +00:00
|
|
|
if( !bDoReplace )
|
|
|
|
aSearchOpt.replaceString = aEmptyStr;
|
2001-03-12 07:18:49 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
ULONG nFound;
|
|
|
|
if( aSrchSet.Count() || ( pReplSet && pReplSet->Count() ))
|
|
|
|
{
|
|
|
|
nFound = pWrtShell->SearchAttr(
|
|
|
|
aSrchSet,
|
|
|
|
!pSrchItem->GetPattern(),
|
|
|
|
rOptions.eStart,
|
|
|
|
rOptions.eEnd,
|
|
|
|
FindRanges(eRanges),
|
2001-03-12 07:18:49 +00:00
|
|
|
pSrchItem->GetSearchString().Len() ? &aSearchOpt : 0,
|
2000-09-18 16:15:01 +00:00
|
|
|
pReplSet );
|
|
|
|
}
|
|
|
|
else if( pSrchItem->GetPattern() )
|
|
|
|
{
|
|
|
|
// Suchen (und ersetzen) von Vorlagen
|
2001-09-13 14:27:15 +00:00
|
|
|
const String sRplStr( pSrchItem->GetReplaceString() );
|
2000-09-18 16:15:01 +00:00
|
|
|
nFound = pWrtShell->SearchTempl( pSrchItem->GetSearchString(),
|
|
|
|
rOptions.eStart,
|
|
|
|
rOptions.eEnd,
|
|
|
|
FindRanges(eRanges),
|
2001-09-13 14:27:15 +00:00
|
|
|
bDoReplace ? &sRplStr : 0 );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normale Suche
|
2001-03-12 07:18:49 +00:00
|
|
|
nFound = pWrtShell->SearchPattern(aSearchOpt,
|
2000-09-18 16:15:01 +00:00
|
|
|
rOptions.eStart,
|
|
|
|
rOptions.eEnd,
|
|
|
|
FindRanges(eRanges),
|
|
|
|
bDoReplace );
|
|
|
|
}
|
|
|
|
pWrtShell->EndSelect();
|
|
|
|
return nFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog* SwView::GetSearchDialog()
|
|
|
|
{
|
|
|
|
const USHORT nId = SvxSearchDialogWrapper::GetChildWindowId();
|
|
|
|
SvxSearchDialogWrapper *pWrp = (SvxSearchDialogWrapper*)SfxViewFrame::Current()->GetChildWindow(nId);
|
|
|
|
if ( pWrp )
|
|
|
|
pSrchDlg = (SvxSearchDialog*)(pWrp->GetWindow());
|
|
|
|
else
|
|
|
|
pSrchDlg = 0;
|
|
|
|
return pSrchDlg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SwView::StateSearch(SfxItemSet &rSet)
|
|
|
|
{
|
|
|
|
SfxWhichIter aIter(rSet);
|
|
|
|
USHORT nWhich = aIter.FirstWhich();
|
|
|
|
|
|
|
|
while(nWhich)
|
|
|
|
{
|
|
|
|
switch(nWhich)
|
|
|
|
{
|
|
|
|
case SID_SEARCH_OPTIONS:
|
|
|
|
{
|
|
|
|
UINT16 nOpt = 0xFFFF;
|
|
|
|
if( GetDocShell()->IsReadOnly() )
|
|
|
|
nOpt &= ~( SEARCH_OPTIONS_REPLACE |
|
|
|
|
SEARCH_OPTIONS_REPLACE_ALL );
|
|
|
|
rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SID_SEARCH_ITEM:
|
|
|
|
{
|
|
|
|
if ( !pSrchItem )
|
|
|
|
{
|
|
|
|
pSrchItem = new SvxSearchItem( SID_SEARCH_ITEM );
|
|
|
|
pSrchItem->SetFamily(SFX_STYLE_FAMILY_PARA);
|
|
|
|
pSrchItem->SetSearchString( pWrtShell->GetSelTxt() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bJustOpened && pWrtShell->IsSelection() )
|
|
|
|
{
|
|
|
|
String aTxt;
|
|
|
|
if( 1 == pWrtShell->GetCrsrCnt() &&
|
|
|
|
( aTxt = pWrtShell->SwCrsrShell::GetSelTxt() ).Len() )
|
|
|
|
{
|
|
|
|
pSrchItem->SetSearchString( aTxt );
|
|
|
|
pSrchItem->SetSelection( FALSE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pSrchItem->SetSelection( TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
bJustOpened = FALSE;
|
|
|
|
rSet.Put( *pSrchItem );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* case SID_SEARCH_REPLACESET:
|
|
|
|
case SID_SEARCH_SEARCHSET:
|
|
|
|
{
|
|
|
|
static USHORT __READONLY_DATA aSearchAttrRange[] =
|
|
|
|
{
|
|
|
|
RES_CHRATR_CASEMAP, RES_CHRATR_POSTURE,
|
|
|
|
RES_CHRATR_SHADOWED, RES_CHRATR_WORDLINEMODE,
|
|
|
|
RES_PARATR_LINESPACING, RES_PARATR_HYPHENZONE,
|
|
|
|
RES_LR_SPACE, RES_UL_SPACE,
|
|
|
|
SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
SfxItemSet aSet(pWrtShell->GetAttrPool(), aSearchAttrRange );
|
|
|
|
if( SID_SEARCH_REPLACESET==nWhich )
|
|
|
|
{
|
|
|
|
if( pReplList )
|
|
|
|
{
|
|
|
|
pReplList->Get( aSet );
|
|
|
|
DELETEZ( pReplList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( pSrchList )
|
|
|
|
{
|
|
|
|
pSrchList->Get( aSet );
|
|
|
|
DELETEZ( pSrchList );
|
|
|
|
}
|
|
|
|
rSet.Put( SvxSetItem( nWhich, aSet ));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
nWhich = aIter.NextWhich();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|