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