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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svx.hxx" 24 #include <svx/sdrundomanager.hxx> 25 26 ////////////////////////////////////////////////////////////////////////////// 27 28 SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount) 29 : EditUndoManager(nMaxUndoActionCount), 30 maEndTextEditHdl(), 31 mpLastUndoActionBeforeTextEdit(0) 32 { 33 } 34 35 SdrUndoManager::~SdrUndoManager() 36 { 37 } 38 39 sal_Bool SdrUndoManager::Undo() 40 { 41 sal_Bool bRetval(sal_False); 42 43 if(maEndTextEditHdl.IsSet()) 44 { 45 // we are in text edit mode 46 if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0)) 47 { 48 // there is an undo action for text edit, trigger it 49 bRetval = EditUndoManager::Undo(); 50 } 51 else 52 { 53 // no more text edit undo, end text edit 54 maEndTextEditHdl.Call(this); 55 } 56 } 57 58 if(!bRetval && GetUndoActionCount()) 59 { 60 // no undo triggered up to now, trigger local one 61 bRetval = SfxUndoManager::Undo(); 62 } 63 64 return bRetval; 65 } 66 67 sal_Bool SdrUndoManager::Redo() 68 { 69 sal_Bool bRetval(sal_False); 70 71 if(maEndTextEditHdl.IsSet()) 72 { 73 // we are in text edit mode 74 bRetval = EditUndoManager::Redo(); 75 } 76 77 if(!bRetval) 78 { 79 // no redo triggered up to now, trigger local one 80 bRetval = SfxUndoManager::Redo(); 81 } 82 83 return bRetval; 84 } 85 86 void SdrUndoManager::SetEndTextEditHdl(const Link& rLink) 87 { 88 maEndTextEditHdl = rLink; 89 90 if(maEndTextEditHdl.IsSet()) 91 { 92 // text edit start, remember last non-textedit action for later cleanup 93 mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0; 94 } 95 else 96 { 97 // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start 98 // to set back the UndoManager to the state before text edit started. If that action is already gone 99 // (due to being removed from the undo stack in the meantime), all need to be removed anyways 100 while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0)) 101 { 102 RemoveLastUndoAction(); 103 } 104 105 // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!) 106 ClearRedo(); 107 108 // forget marker again 109 mpLastUndoActionBeforeTextEdit = 0; 110 } 111 } 112 113 ////////////////////////////////////////////////////////////////////////////// 114 // eof 115