1*69ffbee1SArmin Le Grand /**************************************************************
2*69ffbee1SArmin Le Grand  *
3*69ffbee1SArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4*69ffbee1SArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5*69ffbee1SArmin Le Grand  * distributed with this work for additional information
6*69ffbee1SArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7*69ffbee1SArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8*69ffbee1SArmin Le Grand  * "License"); you may not use this file except in compliance
9*69ffbee1SArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*69ffbee1SArmin Le Grand  *
11*69ffbee1SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*69ffbee1SArmin Le Grand  *
13*69ffbee1SArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14*69ffbee1SArmin Le Grand  * software distributed under the License is distributed on an
15*69ffbee1SArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*69ffbee1SArmin Le Grand  * KIND, either express or implied.  See the License for the
17*69ffbee1SArmin Le Grand  * specific language governing permissions and limitations
18*69ffbee1SArmin Le Grand  * under the License.
19*69ffbee1SArmin Le Grand  *
20*69ffbee1SArmin Le Grand  *************************************************************/
21*69ffbee1SArmin Le Grand 
22*69ffbee1SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23*69ffbee1SArmin Le Grand #include "precompiled_svx.hxx"
24*69ffbee1SArmin Le Grand #include <svx/sdrundomanager.hxx>
25*69ffbee1SArmin Le Grand 
26*69ffbee1SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
27*69ffbee1SArmin Le Grand 
28*69ffbee1SArmin Le Grand SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount)
29*69ffbee1SArmin Le Grand :   EditUndoManager(nMaxUndoActionCount),
30*69ffbee1SArmin Le Grand     maEndTextEditHdl(),
31*69ffbee1SArmin Le Grand     mpLastUndoActionBeforeTextEdit(0)
32*69ffbee1SArmin Le Grand {
33*69ffbee1SArmin Le Grand }
34*69ffbee1SArmin Le Grand 
35*69ffbee1SArmin Le Grand SdrUndoManager::~SdrUndoManager()
36*69ffbee1SArmin Le Grand {
37*69ffbee1SArmin Le Grand }
38*69ffbee1SArmin Le Grand 
39*69ffbee1SArmin Le Grand sal_Bool SdrUndoManager::Undo()
40*69ffbee1SArmin Le Grand {
41*69ffbee1SArmin Le Grand     sal_Bool bRetval(sal_False);
42*69ffbee1SArmin Le Grand 
43*69ffbee1SArmin Le Grand     if(maEndTextEditHdl.IsSet())
44*69ffbee1SArmin Le Grand     {
45*69ffbee1SArmin Le Grand         // we are in text edit mode
46*69ffbee1SArmin Le Grand         if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
47*69ffbee1SArmin Le Grand         {
48*69ffbee1SArmin Le Grand             // there is an undo action for text edit, trigger it
49*69ffbee1SArmin Le Grand             bRetval = EditUndoManager::Undo();
50*69ffbee1SArmin Le Grand         }
51*69ffbee1SArmin Le Grand         else
52*69ffbee1SArmin Le Grand         {
53*69ffbee1SArmin Le Grand             // no more text edit undo, end text edit
54*69ffbee1SArmin Le Grand             maEndTextEditHdl.Call(this);
55*69ffbee1SArmin Le Grand         }
56*69ffbee1SArmin Le Grand     }
57*69ffbee1SArmin Le Grand 
58*69ffbee1SArmin Le Grand     if(!bRetval && GetUndoActionCount())
59*69ffbee1SArmin Le Grand     {
60*69ffbee1SArmin Le Grand         // no undo triggered up to now, trigger local one
61*69ffbee1SArmin Le Grand         bRetval = SfxUndoManager::Undo();
62*69ffbee1SArmin Le Grand     }
63*69ffbee1SArmin Le Grand 
64*69ffbee1SArmin Le Grand     return bRetval;
65*69ffbee1SArmin Le Grand }
66*69ffbee1SArmin Le Grand 
67*69ffbee1SArmin Le Grand sal_Bool SdrUndoManager::Redo()
68*69ffbee1SArmin Le Grand {
69*69ffbee1SArmin Le Grand     sal_Bool bRetval(sal_False);
70*69ffbee1SArmin Le Grand 
71*69ffbee1SArmin Le Grand     if(maEndTextEditHdl.IsSet())
72*69ffbee1SArmin Le Grand     {
73*69ffbee1SArmin Le Grand         // we are in text edit mode
74*69ffbee1SArmin Le Grand         bRetval = EditUndoManager::Redo();
75*69ffbee1SArmin Le Grand     }
76*69ffbee1SArmin Le Grand 
77*69ffbee1SArmin Le Grand     if(!bRetval)
78*69ffbee1SArmin Le Grand     {
79*69ffbee1SArmin Le Grand         // no redo triggered up to now, trigger local one
80*69ffbee1SArmin Le Grand         bRetval = SfxUndoManager::Redo();
81*69ffbee1SArmin Le Grand     }
82*69ffbee1SArmin Le Grand 
83*69ffbee1SArmin Le Grand     return bRetval;
84*69ffbee1SArmin Le Grand }
85*69ffbee1SArmin Le Grand 
86*69ffbee1SArmin Le Grand void SdrUndoManager::SetEndTextEditHdl(const Link& rLink)
87*69ffbee1SArmin Le Grand {
88*69ffbee1SArmin Le Grand     maEndTextEditHdl = rLink;
89*69ffbee1SArmin Le Grand 
90*69ffbee1SArmin Le Grand     if(maEndTextEditHdl.IsSet())
91*69ffbee1SArmin Le Grand     {
92*69ffbee1SArmin Le Grand         // text edit start, remember last non-textedit action for later cleanup
93*69ffbee1SArmin Le Grand         mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0;
94*69ffbee1SArmin Le Grand     }
95*69ffbee1SArmin Le Grand     else
96*69ffbee1SArmin Le Grand     {
97*69ffbee1SArmin Le Grand         // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
98*69ffbee1SArmin Le Grand         // to set back the UndoManager to the state before text edit started. If that action is already gone
99*69ffbee1SArmin Le Grand         // (due to being removed from the undo stack in the meantime), all need to be removed anyways
100*69ffbee1SArmin Le Grand         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
101*69ffbee1SArmin Le Grand         {
102*69ffbee1SArmin Le Grand             RemoveLastUndoAction();
103*69ffbee1SArmin Le Grand         }
104*69ffbee1SArmin Le Grand 
105*69ffbee1SArmin Le Grand         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
106*69ffbee1SArmin Le Grand         ClearRedo();
107*69ffbee1SArmin Le Grand 
108*69ffbee1SArmin Le Grand         // forget marker again
109*69ffbee1SArmin Le Grand         mpLastUndoActionBeforeTextEdit = 0;
110*69ffbee1SArmin Le Grand     }
111*69ffbee1SArmin Le Grand }
112*69ffbee1SArmin Le Grand 
113*69ffbee1SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
114*69ffbee1SArmin Le Grand // eof
115