LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/svdraw - sdrundomanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 33 48.5 %
Date: 2013-07-09 Functions: 6 7 85.7 %
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        1295 : SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount)
      24             :     : EditUndoManager(nMaxUndoActionCount)
      25             :     , maEndTextEditHdl()
      26             :     , mpLastUndoActionBeforeTextEdit(0)
      27        1295 :     , mbEndTextEditTriggeredFromUndo(false)
      28             : {
      29        1295 : }
      30             : 
      31        1577 : SdrUndoManager::~SdrUndoManager()
      32             : {
      33        1577 : }
      34             : 
      35         146 : bool SdrUndoManager::Undo()
      36             : {
      37         146 :     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         146 :         return SfxUndoManager::Undo();
      61             :     }
      62             : }
      63             : 
      64           6 : bool SdrUndoManager::Redo()
      65             : {
      66           6 :     bool bRetval(false);
      67             : 
      68           6 :     if(isTextEditActive())
      69             :     {
      70             :         // we are in text edit mode
      71           0 :         bRetval = EditUndoManager::Redo();
      72             :     }
      73             : 
      74           6 :     if(!bRetval)
      75             :     {
      76             :         // no redo triggered up to now, trigger local one
      77           6 :         bRetval = SfxUndoManager::Redo();
      78             :     }
      79             : 
      80           2 :     return bRetval;
      81             : }
      82             : 
      83           0 : void SdrUndoManager::SetEndTextEditHdl(const Link& rLink)
      84             : {
      85           0 :     maEndTextEditHdl = rLink;
      86             : 
      87           0 :     if(isTextEditActive())
      88             :     {
      89             :         // text edit start, remember last non-textedit action for later cleanup
      90           0 :         mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0;
      91             :     }
      92             :     else
      93             :     {
      94             :         // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
      95             :         // to set back the UndoManager to the state before text edit started. If that action is already gone
      96             :         // (due to being removed from the undo stack in the meantime), all need to be removed anyways
      97           0 :         while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0))
      98             :         {
      99           0 :             RemoveLastUndoAction();
     100             :         }
     101             : 
     102             :         // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
     103           0 :         ClearRedo();
     104             : 
     105             :         // forget marker again
     106           0 :         mpLastUndoActionBeforeTextEdit = 0;
     107             :     }
     108           0 : }
     109             : 
     110      204082 : bool SdrUndoManager::isTextEditActive() const
     111             : {
     112      204082 :     return maEndTextEditHdl.IsSet();
     113             : }
     114             : 
     115             : //////////////////////////////////////////////////////////////////////////////
     116             : // eof

Generated by: LCOV version 1.10