xref: /trunk/main/sw/source/core/undo/unfmco.cxx (revision 28f5a95a)
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 
28 
29 #include "doc.hxx"
30 #include "swundo.hxx"			// fuer die UndoIds
31 #include "pam.hxx"
32 #include "ndtxt.hxx"
33 
34 #include <UndoCore.hxx>
35 #include "rolbck.hxx"
36 
37 
38 //--------------------------------------------------
39 
40 
41 // --> OD 2008-04-15 #refactorlists#
SwUndoFmtColl(const SwPaM & rRange,SwFmtColl * pColl,const bool bReset,const bool bResetListAttrs)42 SwUndoFmtColl::SwUndoFmtColl( const SwPaM& rRange,
43                               SwFmtColl* pColl,
44                               const bool bReset,
45                               const bool bResetListAttrs )
46     : SwUndo( UNDO_SETFMTCOLL ),
47       SwUndRng( rRange ),
48       pHistory( new SwHistory ),
49       pFmtColl( pColl ),
50       mbReset( bReset ),
51       mbResetListAttrs( bResetListAttrs )
52 // <--
53 {
54     // --> FME 2004-08-06 #i31191#
55     if ( pColl )
56         aFmtName = pColl->GetName();
57     // <--
58 }
59 
60 
~SwUndoFmtColl()61 SwUndoFmtColl::~SwUndoFmtColl()
62 {
63 	delete pHistory;
64 }
65 
66 
UndoImpl(::sw::UndoRedoContext & rContext)67 void SwUndoFmtColl::UndoImpl(::sw::UndoRedoContext & rContext)
68 {
69     // restore old values
70     pHistory->TmpRollback(& rContext.GetDoc(), 0);
71 	pHistory->SetTmpEnd( pHistory->Count() );
72 
73 	// create cursor for undo range
74     AddUndoRedoPaM(rContext);
75 }
76 
77 
RedoImpl(::sw::UndoRedoContext & rContext)78 void SwUndoFmtColl::RedoImpl(::sw::UndoRedoContext & rContext)
79 {
80     SwPaM & rPam = AddUndoRedoPaM(rContext);
81 
82     DoSetFmtColl(rContext.GetDoc(), rPam);
83 }
84 
RepeatImpl(::sw::RepeatContext & rContext)85 void SwUndoFmtColl::RepeatImpl(::sw::RepeatContext & rContext)
86 {
87     DoSetFmtColl(rContext.GetDoc(), rContext.GetRepeatPaM());
88 }
89 
DoSetFmtColl(SwDoc & rDoc,SwPaM & rPaM)90 void SwUndoFmtColl::DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM)
91 {
92 	// es kann nur eine TextFmtColl auf einen Bereich angewendet werden,
93 	// also erfrage auch nur in dem Array
94     sal_uInt16 const nPos = rDoc.GetTxtFmtColls()->GetPos(
95 													 (SwTxtFmtColl*)pFmtColl );
96     // does the format still exist?
97     if ( USHRT_MAX != nPos )
98     {
99         rDoc.SetTxtFmtColl(
100             rPaM,
101             (SwTxtFmtColl*) pFmtColl,
102             mbReset,
103             mbResetListAttrs );
104     }
105 }
106 
GetRewriter() const107 SwRewriter SwUndoFmtColl::GetRewriter() const
108 {
109     SwRewriter aResult;
110 
111     // --> FME 2004-08-06 #i31191# Use stored format name instead of
112     // pFmtColl->GetName(), because pFmtColl does not have to be available
113     // anymore.
114     aResult.AddRule(UNDO_ARG1, aFmtName );
115     // <--
116 
117     return aResult;
118 }
119 
120