Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/resid.hxx>
31 : :
32 : : #include <swcrsr.hxx>
33 : : #include <doc.hxx>
34 : : #include <IDocumentUndoRedo.hxx>
35 : : #include <pamtyp.hxx>
36 : : #include <swundo.hxx>
37 : : #include <SwRewriter.hxx>
38 : : #include <comcore.hrc>
39 : :
40 : : /// parameters for a search for FormatCollections
41 : : struct SwFindParaFmtColl : public SwFindParas
42 : : {
43 : : const SwTxtFmtColl *pFmtColl, *pReplColl;
44 : : SwCursor& rCursor;
45 : 0 : SwFindParaFmtColl( const SwTxtFmtColl& rFmtColl,
46 : : const SwTxtFmtColl* pRpColl, SwCursor& rCrsr )
47 : 0 : : pFmtColl( &rFmtColl ), pReplColl( pRpColl ), rCursor( rCrsr )
48 : 0 : {}
49 [ # # ]: 0 : virtual ~SwFindParaFmtColl() {}
50 : : virtual int Find( SwPaM* , SwMoveFn , const SwPaM*, sal_Bool bInReadOnly );
51 : : virtual int IsReplaceMode() const;
52 : : };
53 : :
54 : :
55 : 0 : int SwFindParaFmtColl::Find( SwPaM* pCrsr, SwMoveFn fnMove, const SwPaM* pRegion,
56 : : sal_Bool bInReadOnly )
57 : : {
58 : 0 : int nRet = FIND_FOUND;
59 [ # # ][ # # ]: 0 : if( bInReadOnly && pReplColl )
60 : 0 : bInReadOnly = sal_False;
61 : :
62 [ # # ]: 0 : if( !pCrsr->Find( *pFmtColl, fnMove, pRegion, bInReadOnly ) )
63 : 0 : nRet = FIND_NOT_FOUND;
64 [ # # ]: 0 : else if( pReplColl )
65 : : {
66 : 0 : pCrsr->GetDoc()->SetTxtFmtColl( *pCrsr, (SwTxtFmtColl*)pReplColl );
67 : 0 : nRet = FIND_NO_RING;
68 : : }
69 : 0 : return nRet;
70 : : }
71 : :
72 : :
73 : 0 : int SwFindParaFmtColl::IsReplaceMode() const
74 : : {
75 : 0 : return 0 != pReplColl;
76 : : }
77 : :
78 : : /// search for Format-Collections
79 : 0 : sal_uLong SwCursor::Find( const SwTxtFmtColl& rFmtColl, SwDocPositions nStart,
80 : : SwDocPositions nEnd, sal_Bool& bCancel,
81 : : FindRanges eFndRngs, const SwTxtFmtColl* pReplFmtColl )
82 : : {
83 : : // switch off OLE-notifications
84 : 0 : SwDoc* pDoc = GetDoc();
85 : 0 : Link aLnk( pDoc->GetOle2Link() );
86 [ # # ]: 0 : pDoc->SetOle2Link( Link() );
87 : :
88 : : bool const bStartUndo =
89 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().DoesUndo() && pReplFmtColl;
[ # # ][ # # ]
90 [ # # ]: 0 : if (bStartUndo)
91 : : {
92 [ # # ]: 0 : SwRewriter aRewriter;
93 [ # # ]: 0 : aRewriter.AddRule(UndoArg1, rFmtColl.GetName());
94 [ # # ][ # # ]: 0 : aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
[ # # ]
95 [ # # ]: 0 : aRewriter.AddRule(UndoArg3, pReplFmtColl->GetName());
96 : :
97 [ # # ]: 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE_STYLE,
98 [ # # ][ # # ]: 0 : &aRewriter );
99 : : }
100 : :
101 : 0 : SwFindParaFmtColl aSwFindParaFmtColl( rFmtColl, pReplFmtColl, *this );
102 : :
103 [ # # ]: 0 : sal_uLong nRet = FindAll( aSwFindParaFmtColl, nStart, nEnd, eFndRngs, bCancel );
104 : 0 : pDoc->SetOle2Link( aLnk );
105 : :
106 [ # # ][ # # ]: 0 : if( nRet && pReplFmtColl )
107 [ # # ]: 0 : pDoc->SetModified();
108 : :
109 [ # # ]: 0 : if (bStartUndo)
110 : : {
111 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
112 : : }
113 : 0 : return nRet;
114 : : }
115 : :
116 : :
117 : :
118 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|