LCOV - code coverage report
Current view: top level - svx/source/svdraw - sdrundomanager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 40 77.5 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11