LCOV - code coverage report
Current view: top level - svx/source/svdraw - sdrundomanager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 40 0.0 %
Date: 2014-04-14 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include <svx/sdrundomanager.hxx>
      20             : 
      21             : 
      22             : 
      23           0 : SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount)
      24             :     : EditUndoManager(nMaxUndoActionCount)
      25             :     , maEndTextEditHdl()
      26             :     , mpLastUndoActionBeforeTextEdit(0)
      27           0 :     , mbEndTextEditTriggeredFromUndo(false)
      28             : {
      29           0 : }
      30             : 
      31           0 : SdrUndoManager::~SdrUndoManager()
      32             : {
      33           0 : }
      34             : 
      35           0 : bool SdrUndoManager::Undo()
      36             : {
      37           0 :     if(isTextEditActive())
      38             :     {
      39           0 :         bool bRetval(false);
      40             : 
      41             :         // we are in text edit mode
      42           0 :         if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
      43             :         {
      44             :             // there is an undo action for text edit, trigger it
      45           0 :             bRetval = EditUndoManager::Undo();
      46             :         }
      47             :         else
      48             :         {
      49             :             // no more text edit undo, end text edit
      50           0 :             mbEndTextEditTriggeredFromUndo = true;
      51           0 :             maEndTextEditHdl.Call(this);
      52           0 :             mbEndTextEditTriggeredFromUndo = false;
      53             :         }
      54             : 
      55           0 :         return bRetval;
      56             :     }
      57             :     else
      58             :     {
      59             :         // no undo triggered up to now, trigger local one
      60           0 :         return SfxUndoManager::Undo();
      61             :     }
      62             : }
      63             : 
      64           0 : bool SdrUndoManager::Redo()
      65             : {
      66           0 :     bool bRetval(false);
      67             : 
      68           0 :     if(isTextEditActive())
      69             :     {
      70             :         // we are in text edit mode
      71           0 :         bRetval = EditUndoManager::Redo();
      72             :     }
      73             : 
      74           0 :     if(!bRetval)
      75             :     {
      76             :         // no redo triggered up to now, trigger local one
      77           0 :         bRetval = SfxUndoManager::Redo();
      78             :     }
      79             : 
      80           0 :     return bRetval;
      81             : }
      82             : 
      83           0 : void SdrUndoManager::Clear()
      84             : {
      85           0 :     if(isTextEditActive())
      86             :     {
      87           0 :         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
      88             :         {
      89           0 :             RemoveLastUndoAction();
      90             :         }
      91             : 
      92             :         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
      93           0 :         ClearRedo();
      94             :     }
      95             :     else
      96             :     {
      97             :         // call parent
      98           0 :         EditUndoManager::Clear();
      99             :     }
     100           0 : }
     101             : 
     102           0 : void SdrUndoManager::SetEndTextEditHdl(const Link& rLink)
     103             : {
     104           0 :     maEndTextEditHdl = rLink;
     105             : 
     106           0 :     if(isTextEditActive())
     107             :     {
     108             :         // text edit start, remember last non-textedit action for later cleanup
     109           0 :         mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0;
     110             :     }
     111             :     else
     112             :     {
     113             :         // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
     114             :         // to set back the UndoManager to the state before text edit started. If that action is already gone
     115             :         // (due to being removed from the undo stack in the meantime), all need to be removed anyways
     116           0 :         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
     117             :         {
     118           0 :             RemoveLastUndoAction();
     119             :         }
     120             : 
     121             :         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
     122           0 :         ClearRedo();
     123             : 
     124             :         // forget marker again
     125           0 :         mpLastUndoActionBeforeTextEdit = 0;
     126             :     }
     127           0 : }
     128             : 
     129           0 : bool SdrUndoManager::isTextEditActive() const
     130             : {
     131           0 :     return maEndTextEditHdl.IsSet();
     132             : }
     133             : 
     134             : 
     135             : // eof

Generated by: LCOV version 1.10