Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/resid.hxx>
21 : #include <swcrsr.hxx>
22 : #include <doc.hxx>
23 : #include <IDocumentUndoRedo.hxx>
24 : #include <pamtyp.hxx>
25 : #include <swundo.hxx>
26 : #include <SwRewriter.hxx>
27 : #include <comcore.hrc>
28 :
29 : /// parameters for a search for FormatCollections
30 : struct SwFindParaFmtColl : public SwFindParas
31 : {
32 : const SwTxtFmtColl *pFmtColl, *pReplColl;
33 : SwCursor& rCursor;
34 0 : SwFindParaFmtColl( const SwTxtFmtColl& rFmtColl,
35 : const SwTxtFmtColl* pRpColl, SwCursor& rCrsr )
36 0 : : pFmtColl( &rFmtColl ), pReplColl( pRpColl ), rCursor( rCrsr )
37 0 : {}
38 0 : virtual ~SwFindParaFmtColl() {}
39 : virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, sal_Bool bInReadOnly ) SAL_OVERRIDE;
40 : virtual bool IsReplaceMode() const SAL_OVERRIDE;
41 : };
42 :
43 0 : int SwFindParaFmtColl::Find( SwPaM* pCrsr, SwMoveFn fnMove, const SwPaM* pRegion,
44 : sal_Bool bInReadOnly )
45 : {
46 0 : int nRet = FIND_FOUND;
47 0 : if( bInReadOnly && pReplColl )
48 0 : bInReadOnly = sal_False;
49 :
50 0 : if( !pCrsr->Find( *pFmtColl, fnMove, pRegion, bInReadOnly ) )
51 0 : nRet = FIND_NOT_FOUND;
52 0 : else if( pReplColl )
53 : {
54 0 : pCrsr->GetDoc()->SetTxtFmtColl( *pCrsr, (SwTxtFmtColl*)pReplColl );
55 0 : nRet = FIND_NO_RING;
56 : }
57 0 : return nRet;
58 : }
59 :
60 0 : bool SwFindParaFmtColl::IsReplaceMode() const
61 : {
62 0 : return 0 != pReplColl;
63 : }
64 :
65 : /// search for Format-Collections
66 0 : sal_uLong SwCursor::Find( const SwTxtFmtColl& rFmtColl, SwDocPositions nStart,
67 : SwDocPositions nEnd, sal_Bool& bCancel,
68 : FindRanges eFndRngs, const SwTxtFmtColl* pReplFmtColl )
69 : {
70 : // switch off OLE-notifications
71 0 : SwDoc* pDoc = GetDoc();
72 0 : Link aLnk( pDoc->GetOle2Link() );
73 0 : pDoc->SetOle2Link( Link() );
74 :
75 : bool const bStartUndo =
76 0 : pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFmtColl;
77 0 : if (bStartUndo)
78 : {
79 0 : SwRewriter aRewriter;
80 0 : aRewriter.AddRule(UndoArg1, rFmtColl.GetName());
81 0 : aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
82 0 : aRewriter.AddRule(UndoArg3, pReplFmtColl->GetName());
83 :
84 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
85 0 : &aRewriter );
86 : }
87 :
88 0 : SwFindParaFmtColl aSwFindParaFmtColl( rFmtColl, pReplFmtColl, *this );
89 :
90 0 : sal_uLong nRet = FindAll( aSwFindParaFmtColl, nStart, nEnd, eFndRngs, bCancel );
91 0 : pDoc->SetOle2Link( aLnk );
92 :
93 0 : if( nRet && pReplFmtColl )
94 0 : pDoc->SetModified();
95 :
96 0 : if (bStartUndo)
97 : {
98 0 : pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
99 : }
100 0 : return nRet;
101 : }
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|