1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <tools/resid.hxx>
28
29 #include <swcrsr.hxx>
30 #include <doc.hxx>
31 #include <IDocumentUndoRedo.hxx>
32 #include <pamtyp.hxx>
33 #include <swundo.hxx>
34 #include <SwRewriter.hxx>
35 #include <comcore.hrc>
36
37 //------------------ Methoden der CrsrShell ---------------------------
38
39 // Parameter fuer das Suchen vom FormatCollections
40 struct SwFindParaFmtColl : public SwFindParas
41 {
42 const SwTxtFmtColl *pFmtColl, *pReplColl;
43 SwCursor& rCursor;
SwFindParaFmtCollSwFindParaFmtColl44 SwFindParaFmtColl( const SwTxtFmtColl& rFmtColl,
45 const SwTxtFmtColl* pRpColl, SwCursor& rCrsr )
46 : pFmtColl( &rFmtColl ), pReplColl( pRpColl ), rCursor( rCrsr )
47 {}
48 virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, sal_Bool bInReadOnly );
49 virtual int IsReplaceMode() const;
50 };
51
52
Find(SwPaM * pCrsr,SwMoveFn fnMove,const SwPaM * pRegion,sal_Bool bInReadOnly)53 int SwFindParaFmtColl::Find( SwPaM* pCrsr, SwMoveFn fnMove, const SwPaM* pRegion,
54 sal_Bool bInReadOnly )
55 {
56 int nRet = FIND_FOUND;
57 if( bInReadOnly && pReplColl )
58 bInReadOnly = sal_False;
59
60 if( !pCrsr->Find( *pFmtColl, fnMove, pRegion, bInReadOnly ) )
61 nRet = FIND_NOT_FOUND;
62 else if( pReplColl )
63 {
64 pCrsr->GetDoc()->SetTxtFmtColl( *pCrsr, (SwTxtFmtColl*)pReplColl );
65 nRet = FIND_NO_RING;
66 }
67 return nRet;
68 }
69
70
IsReplaceMode() const71 int SwFindParaFmtColl::IsReplaceMode() const
72 {
73 return 0 != pReplColl;
74 }
75
76
77 // Suchen nach Format-Collections
78
79
Find(const SwTxtFmtColl & rFmtColl,SwDocPositions nStart,SwDocPositions nEnde,sal_Bool & bCancel,FindRanges eFndRngs,const SwTxtFmtColl * pReplFmtColl)80 sal_uLong SwCursor::Find( const SwTxtFmtColl& rFmtColl,
81 SwDocPositions nStart, SwDocPositions nEnde, sal_Bool& bCancel,
82 FindRanges eFndRngs, const SwTxtFmtColl* pReplFmtColl )
83 {
84 // OLE-Benachrichtigung abschalten !!
85 SwDoc* pDoc = GetDoc();
86 Link aLnk( pDoc->GetOle2Link() );
87 pDoc->SetOle2Link( Link() );
88
89 bool const bStartUndo =
90 pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFmtColl;
91 if (bStartUndo)
92 {
93 SwRewriter aRewriter;
94 aRewriter.AddRule(UNDO_ARG1, rFmtColl.GetName());
95 aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
96 aRewriter.AddRule(UNDO_ARG3, pReplFmtColl->GetName());
97
98 pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
99 &aRewriter );
100 }
101
102 SwFindParaFmtColl aSwFindParaFmtColl( rFmtColl, pReplFmtColl, *this );
103
104 sal_uLong nRet = FindAll( aSwFindParaFmtColl, nStart, nEnde, eFndRngs, bCancel );
105 pDoc->SetOle2Link( aLnk );
106
107 if( nRet && pReplFmtColl )
108 pDoc->SetModified();
109
110 if (bStartUndo)
111 {
112 pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
113 }
114 return nRet;
115 }
116
117
118
119