169ffbee1SArmin Le Grand /**************************************************************
269ffbee1SArmin Le Grand  *
369ffbee1SArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
469ffbee1SArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
569ffbee1SArmin Le Grand  * distributed with this work for additional information
669ffbee1SArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
769ffbee1SArmin Le Grand  * to you under the Apache License, Version 2.0 (the
869ffbee1SArmin Le Grand  * "License"); you may not use this file except in compliance
969ffbee1SArmin Le Grand  * with the License.  You may obtain a copy of the License at
1069ffbee1SArmin Le Grand  *
1169ffbee1SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
1269ffbee1SArmin Le Grand  *
1369ffbee1SArmin Le Grand  * Unless required by applicable law or agreed to in writing,
1469ffbee1SArmin Le Grand  * software distributed under the License is distributed on an
1569ffbee1SArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1669ffbee1SArmin Le Grand  * KIND, either express or implied.  See the License for the
1769ffbee1SArmin Le Grand  * specific language governing permissions and limitations
1869ffbee1SArmin Le Grand  * under the License.
1969ffbee1SArmin Le Grand  *
2069ffbee1SArmin Le Grand  *************************************************************/
2169ffbee1SArmin Le Grand 
2269ffbee1SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
2369ffbee1SArmin Le Grand #include "precompiled_svx.hxx"
2469ffbee1SArmin Le Grand #include <svx/sdrundomanager.hxx>
2569ffbee1SArmin Le Grand 
2669ffbee1SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
2769ffbee1SArmin Le Grand 
2869ffbee1SArmin Le Grand SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount)
2969ffbee1SArmin Le Grand :   EditUndoManager(nMaxUndoActionCount),
3069ffbee1SArmin Le Grand     maEndTextEditHdl(),
31*3d9b0034SArmin Le Grand     mpLastUndoActionBeforeTextEdit(0),
32*3d9b0034SArmin Le Grand     mbEndTextEditTriggeredFromUndo(false)
3369ffbee1SArmin Le Grand {
3469ffbee1SArmin Le Grand }
3569ffbee1SArmin Le Grand 
3669ffbee1SArmin Le Grand SdrUndoManager::~SdrUndoManager()
3769ffbee1SArmin Le Grand {
3869ffbee1SArmin Le Grand }
3969ffbee1SArmin Le Grand 
4069ffbee1SArmin Le Grand sal_Bool SdrUndoManager::Undo()
4169ffbee1SArmin Le Grand {
42*3d9b0034SArmin Le Grand     if(isTextEditActive())
4369ffbee1SArmin Le Grand     {
44*3d9b0034SArmin Le Grand         sal_Bool bRetval(sal_False);
45*3d9b0034SArmin Le Grand 
4669ffbee1SArmin Le Grand         // we are in text edit mode
4769ffbee1SArmin Le Grand         if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
4869ffbee1SArmin Le Grand         {
4969ffbee1SArmin Le Grand             // there is an undo action for text edit, trigger it
5069ffbee1SArmin Le Grand             bRetval = EditUndoManager::Undo();
5169ffbee1SArmin Le Grand         }
5269ffbee1SArmin Le Grand         else
5369ffbee1SArmin Le Grand         {
5469ffbee1SArmin Le Grand             // no more text edit undo, end text edit
55*3d9b0034SArmin Le Grand             mbEndTextEditTriggeredFromUndo = true;
5669ffbee1SArmin Le Grand             maEndTextEditHdl.Call(this);
57*3d9b0034SArmin Le Grand             mbEndTextEditTriggeredFromUndo = false;
5869ffbee1SArmin Le Grand         }
5969ffbee1SArmin Le Grand 
60*3d9b0034SArmin Le Grand         return bRetval;
61*3d9b0034SArmin Le Grand     }
62*3d9b0034SArmin Le Grand     else
6369ffbee1SArmin Le Grand     {
6469ffbee1SArmin Le Grand         // no undo triggered up to now, trigger local one
65*3d9b0034SArmin Le Grand         return SfxUndoManager::Undo();
6669ffbee1SArmin Le Grand     }
6769ffbee1SArmin Le Grand }
6869ffbee1SArmin Le Grand 
6969ffbee1SArmin Le Grand sal_Bool SdrUndoManager::Redo()
7069ffbee1SArmin Le Grand {
7169ffbee1SArmin Le Grand     sal_Bool bRetval(sal_False);
7269ffbee1SArmin Le Grand 
73*3d9b0034SArmin Le Grand     if(isTextEditActive())
7469ffbee1SArmin Le Grand     {
7569ffbee1SArmin Le Grand         // we are in text edit mode
7669ffbee1SArmin Le Grand         bRetval = EditUndoManager::Redo();
7769ffbee1SArmin Le Grand     }
7869ffbee1SArmin Le Grand 
7969ffbee1SArmin Le Grand     if(!bRetval)
8069ffbee1SArmin Le Grand     {
8169ffbee1SArmin Le Grand         // no redo triggered up to now, trigger local one
8269ffbee1SArmin Le Grand         bRetval = SfxUndoManager::Redo();
8369ffbee1SArmin Le Grand     }
8469ffbee1SArmin Le Grand 
8569ffbee1SArmin Le Grand     return bRetval;
8669ffbee1SArmin Le Grand }
8769ffbee1SArmin Le Grand 
8869ffbee1SArmin Le Grand void SdrUndoManager::SetEndTextEditHdl(const Link& rLink)
8969ffbee1SArmin Le Grand {
9069ffbee1SArmin Le Grand     maEndTextEditHdl = rLink;
9169ffbee1SArmin Le Grand 
92*3d9b0034SArmin Le Grand     if(isTextEditActive())
9369ffbee1SArmin Le Grand     {
9469ffbee1SArmin Le Grand         // text edit start, remember last non-textedit action for later cleanup
9569ffbee1SArmin Le Grand         mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0;
9669ffbee1SArmin Le Grand     }
9769ffbee1SArmin Le Grand     else
9869ffbee1SArmin Le Grand     {
9969ffbee1SArmin Le Grand         // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
10069ffbee1SArmin Le Grand         // to set back the UndoManager to the state before text edit started. If that action is already gone
10169ffbee1SArmin Le Grand         // (due to being removed from the undo stack in the meantime), all need to be removed anyways
10269ffbee1SArmin Le Grand         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
10369ffbee1SArmin Le Grand         {
10469ffbee1SArmin Le Grand             RemoveLastUndoAction();
10569ffbee1SArmin Le Grand         }
10669ffbee1SArmin Le Grand 
10769ffbee1SArmin Le Grand         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
10869ffbee1SArmin Le Grand         ClearRedo();
10969ffbee1SArmin Le Grand 
11069ffbee1SArmin Le Grand         // forget marker again
11169ffbee1SArmin Le Grand         mpLastUndoActionBeforeTextEdit = 0;
11269ffbee1SArmin Le Grand     }
11369ffbee1SArmin Le Grand }
11469ffbee1SArmin Le Grand 
115*3d9b0034SArmin Le Grand bool SdrUndoManager::isTextEditActive() const
116*3d9b0034SArmin Le Grand {
117*3d9b0034SArmin Le Grand     return maEndTextEditHdl.IsSet();
118*3d9b0034SArmin Le Grand }
119*3d9b0034SArmin Le Grand 
12069ffbee1SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
12169ffbee1SArmin Le Grand // eof
122