xref: /AOO41X/main/sw/source/core/crsr/findcoll.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #include <tools/resid.hxx>
32 
33 #include <swcrsr.hxx>
34 #include <doc.hxx>
35 #include <IDocumentUndoRedo.hxx>
36 #include <pamtyp.hxx>
37 #include <swundo.hxx>
38 #include <SwRewriter.hxx>
39 #include <comcore.hrc>
40 
41 //------------------ Methoden der CrsrShell ---------------------------
42 
43 // Parameter fuer das Suchen vom FormatCollections
44 struct SwFindParaFmtColl : public SwFindParas
45 {
46 	const SwTxtFmtColl *pFmtColl, *pReplColl;
47 	SwCursor& rCursor;
48 	SwFindParaFmtColl( const SwTxtFmtColl& rFmtColl,
49 						const SwTxtFmtColl* pRpColl, SwCursor& rCrsr )
50 		: pFmtColl( &rFmtColl ), pReplColl( pRpColl ), rCursor( rCrsr )
51 	{}
52 	virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, sal_Bool bInReadOnly );
53 	virtual int IsReplaceMode() const;
54 };
55 
56 
57 int SwFindParaFmtColl::Find( SwPaM* pCrsr, SwMoveFn fnMove, const SwPaM* pRegion,
58 							sal_Bool bInReadOnly )
59 {
60 	int nRet = FIND_FOUND;
61 	if( bInReadOnly && pReplColl )
62 		bInReadOnly = sal_False;
63 
64 	if( !pCrsr->Find( *pFmtColl, fnMove, pRegion, bInReadOnly ) )
65 		nRet = FIND_NOT_FOUND;
66 	else if( pReplColl )
67 	{
68 		pCrsr->GetDoc()->SetTxtFmtColl( *pCrsr, (SwTxtFmtColl*)pReplColl );
69 		nRet = FIND_NO_RING;
70 	}
71 	return nRet;
72 }
73 
74 
75 int SwFindParaFmtColl::IsReplaceMode() const
76 {
77 	return 0 != pReplColl;
78 }
79 
80 
81 // Suchen nach Format-Collections
82 
83 
84 sal_uLong SwCursor::Find( const SwTxtFmtColl& rFmtColl,
85                     SwDocPositions nStart, SwDocPositions nEnde, sal_Bool& bCancel,
86 					FindRanges eFndRngs, const SwTxtFmtColl* pReplFmtColl )
87 {
88 	// OLE-Benachrichtigung abschalten !!
89 	SwDoc* pDoc = GetDoc();
90 	Link aLnk( pDoc->GetOle2Link() );
91 	pDoc->SetOle2Link( Link() );
92 
93     bool const bStartUndo =
94         pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFmtColl;
95     if (bStartUndo)
96     {
97         SwRewriter aRewriter;
98         aRewriter.AddRule(UNDO_ARG1, rFmtColl.GetName());
99         aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
100         aRewriter.AddRule(UNDO_ARG3, pReplFmtColl->GetName());
101 
102         pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
103                 &aRewriter );
104     }
105 
106 	SwFindParaFmtColl aSwFindParaFmtColl( rFmtColl, pReplFmtColl, *this );
107 
108     sal_uLong nRet = FindAll( aSwFindParaFmtColl, nStart, nEnde, eFndRngs, bCancel );
109 	pDoc->SetOle2Link( aLnk );
110 
111 	if( nRet && pReplFmtColl )
112 		pDoc->SetModified();
113 
114     if (bStartUndo)
115     {
116         pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
117     }
118     return nRet;
119 }
120 
121 
122 
123