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 : : #include "doc.hxx"
30 : : #include "swundo.hxx"
31 : : #include "pam.hxx"
32 : : #include "ndtxt.hxx"
33 : : #include <UndoCore.hxx>
34 : : #include "rolbck.hxx"
35 : : #include "docary.hxx"
36 : :
37 : : //--------------------------------------------------
38 : :
39 : 8 : SwUndoFmtColl::SwUndoFmtColl( const SwPaM& rRange,
40 : : SwFmtColl* pColl,
41 : : const bool bReset,
42 : : const bool bResetListAttrs )
43 : : : SwUndo( UNDO_SETFMTCOLL ),
44 : : SwUndRng( rRange ),
45 [ + - ]: 8 : pHistory( new SwHistory ),
46 : : pFmtColl( pColl ),
47 : : mbReset( bReset ),
48 [ + - ][ + - ]: 8 : mbResetListAttrs( bResetListAttrs )
[ + - ]
49 : : {
50 : : // #i31191#
51 [ + - ]: 8 : if ( pColl )
52 [ + - ]: 8 : aFmtName = pColl->GetName();
53 : 8 : }
54 : :
55 [ + - ]: 8 : SwUndoFmtColl::~SwUndoFmtColl()
56 : : {
57 [ + - ][ + - ]: 8 : delete pHistory;
58 [ - + ]: 16 : }
59 : :
60 : 0 : void SwUndoFmtColl::UndoImpl(::sw::UndoRedoContext & rContext)
61 : : {
62 : : // restore old values
63 : 0 : pHistory->TmpRollback(& rContext.GetDoc(), 0);
64 : 0 : pHistory->SetTmpEnd( pHistory->Count() );
65 : :
66 : : // create cursor for undo range
67 : 0 : AddUndoRedoPaM(rContext);
68 : 0 : }
69 : :
70 : 0 : void SwUndoFmtColl::RedoImpl(::sw::UndoRedoContext & rContext)
71 : : {
72 : 0 : SwPaM & rPam = AddUndoRedoPaM(rContext);
73 : :
74 : 0 : DoSetFmtColl(rContext.GetDoc(), rPam);
75 : 0 : }
76 : :
77 : 0 : void SwUndoFmtColl::RepeatImpl(::sw::RepeatContext & rContext)
78 : : {
79 : 0 : DoSetFmtColl(rContext.GetDoc(), rContext.GetRepeatPaM());
80 : 0 : }
81 : :
82 : 0 : void SwUndoFmtColl::DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM)
83 : : {
84 : : // Only one TextFrmColl can be applied to a section, thus request only in
85 : : // this array.
86 : : sal_uInt16 const nPos = rDoc.GetTxtFmtColls()->GetPos(
87 : 0 : (SwTxtFmtColl*)pFmtColl );
88 : : // does the format still exist?
89 [ # # ]: 0 : if( USHRT_MAX != nPos )
90 : : {
91 : : rDoc.SetTxtFmtColl(rPaM,
92 : : (SwTxtFmtColl*)pFmtColl,
93 : : mbReset,
94 : 0 : mbResetListAttrs );
95 : : }
96 : 0 : }
97 : :
98 : 8 : SwRewriter SwUndoFmtColl::GetRewriter() const
99 : : {
100 : 8 : SwRewriter aResult;
101 : :
102 : : // #i31191# Use stored format name instead of
103 : : // pFmtColl->GetName(), because pFmtColl does not have to be available
104 : : // anymore.
105 [ + - ]: 8 : aResult.AddRule(UndoArg1, aFmtName );
106 : :
107 : 8 : return aResult;
108 : : }
109 : :
110 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|