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