LCOV - code coverage report
Current view: top level - svx/source/svdraw - sdrundomanager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 20 40 50.0 %
Date: 2014-11-03 Functions: 7 8 87.5 %
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        6510 : SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount)
      25             :     : EditUndoManager(nMaxUndoActionCount)
      26             :     , maEndTextEditHdl()
      27             :     , mpLastUndoActionBeforeTextEdit(0)
      28        6510 :     , mbEndTextEditTriggeredFromUndo(false)
      29             : {
      30        6510 : }
      31             : 
      32        7523 : SdrUndoManager::~SdrUndoManager()
      33             : {
      34        7523 : }
      35             : 
      36         392 : bool SdrUndoManager::Undo()
      37             : {
      38         392 :     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         392 :         return SfxUndoManager::Undo();
      62             :     }
      63             : }
      64             : 
      65          50 : bool SdrUndoManager::Redo()
      66             : {
      67          50 :     bool bRetval(false);
      68             : 
      69          50 :     if(isTextEditActive())
      70             :     {
      71             :         // we are in text edit mode
      72           0 :         bRetval = EditUndoManager::Redo();
      73             :     }
      74             : 
      75          50 :     if(!bRetval)
      76             :     {
      77             :         // no redo triggered up to now, trigger local one
      78          50 :         bRetval = SfxUndoManager::Redo();
      79             :     }
      80             : 
      81          42 :     return bRetval;
      82             : }
      83             : 
      84         478 : void SdrUndoManager::Clear()
      85             : {
      86         478 :     if(isTextEditActive())
      87             :     {
      88           0 :         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
      89             :         {
      90           0 :             RemoveLastUndoAction();
      91             :         }
      92             : 
      93             :         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
      94           0 :         ClearRedo();
      95             :     }
      96             :     else
      97             :     {
      98             :         // call parent
      99         478 :         EditUndoManager::Clear();
     100             :     }
     101         478 : }
     102             : 
     103           0 : void SdrUndoManager::SetEndTextEditHdl(const Link& rLink)
     104             : {
     105           0 :     maEndTextEditHdl = rLink;
     106             : 
     107           0 :     if(isTextEditActive())
     108             :     {
     109             :         // text edit start, remember last non-textedit action for later cleanup
     110           0 :         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           0 :         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
     118             :         {
     119           0 :             RemoveLastUndoAction();
     120             :         }
     121             : 
     122             :         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
     123           0 :         ClearRedo();
     124             : 
     125             :         // forget marker again
     126           0 :         mpLastUndoActionBeforeTextEdit = 0;
     127             :     }
     128           0 : }
     129             : 
     130     3702336 : bool SdrUndoManager::isTextEditActive() const
     131             : {
     132     3702336 :     return maEndTextEditHdl.IsSet();
     133             : }
     134             : 
     135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10