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# 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 61 SwUndoFmtColl::~SwUndoFmtColl() 62 { 63 delete pHistory; 64 } 65 66 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 78 void SwUndoFmtColl::RedoImpl(::sw::UndoRedoContext & rContext) 79 { 80 SwPaM & rPam = AddUndoRedoPaM(rContext); 81 82 DoSetFmtColl(rContext.GetDoc(), rPam); 83 } 84 85 void SwUndoFmtColl::RepeatImpl(::sw::RepeatContext & rContext) 86 { 87 DoSetFmtColl(rContext.GetDoc(), rContext.GetRepeatPaM()); 88 } 89 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 // --> OD 2008-04-15 #refactorlists# 100 rDoc.SetTxtFmtColl(rPaM, 101 (SwTxtFmtColl*)pFmtColl, 102 mbReset, 103 mbResetListAttrs ); 104 // <-- 105 } 106 } 107 108 SwRewriter SwUndoFmtColl::GetRewriter() const 109 { 110 SwRewriter aResult; 111 112 // --> FME 2004-08-06 #i31191# Use stored format name instead of 113 // pFmtColl->GetName(), because pFmtColl does not have to be available 114 // anymore. 115 aResult.AddRule(UNDO_ARG1, aFmtName ); 116 // <-- 117 118 return aResult; 119 } 120 121