LCOV - code coverage report
Current view: top level - sw/inc - IDocumentUndoRedo.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 25 100.0 %
Date: 2015-06-13 12:38:46 Functions: 9 10 90.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             : #ifndef INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
      21             : #define INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : 
      25             : #include <swundo.hxx>
      26             : 
      27             : class SwRewriter;
      28             : class SwNodes;
      29             : class SwUndo;
      30             : 
      31             : namespace sw {
      32             :     class RepeatContext;
      33             : }
      34             : 
      35        2958 : class IDocumentUndoRedo
      36             : {
      37             : public:
      38             : 
      39             :     /** Enable/Disable Undo.
      40             :     */
      41             :     virtual void DoUndo(bool const bDoUndo) = 0;
      42             : 
      43             :     /** Is Undo enabled?
      44             :     */
      45             :     virtual bool DoesUndo() const = 0;
      46             : 
      47             :     /** Enable/Disable Group Undo.
      48             :         This determines whether successive Insert/Delete/Overwrite
      49             :         actions are combined.
      50             :     */
      51             :     virtual void DoGroupUndo(bool const bDoUndo) = 0;
      52             : 
      53             :     /** Is Group Undo enabled?
      54             :     */
      55             :     virtual bool DoesGroupUndo() const = 0;
      56             : 
      57             :     /** Enable/Disable Undo for Drawing objects.
      58             :      */
      59             :     virtual void DoDrawUndo(bool const bDoUndo) = 0;
      60             : 
      61             :     /** Is Undo for Drawing objects enabled?
      62             :         for Draw-Undo: writer wants to handle actions on Flys on its own.
      63             :      */
      64             :     virtual bool DoesDrawUndo() const = 0;
      65             : 
      66             :     /** Set the position at which the document is in the "unmodified" state
      67             :         to the current position in the Undo stack.
      68             :     */
      69             :     virtual void SetUndoNoModifiedPosition() = 0;
      70             : 
      71             :     /** Prevent updates to the "unmodified" state position
      72             :         via SetUndoNoResetModified().
      73             :     */
      74             :     virtual void LockUndoNoModifiedPosition() = 0;
      75             : 
      76             :     /** Allow updates to the "unmodified" state position
      77             :         via SetUndoNoResetModified().
      78             :     */
      79             :     virtual void UnLockUndoNoModifiedPosition() = 0;
      80             : 
      81             :     /** Disable (re)setting the document modified flag on Undo/Redo.
      82             :     */
      83             :     virtual void SetUndoNoResetModified() = 0;
      84             : 
      85             :     /** Is setting the document modified flag on Undo/Redo disabled?
      86             :     */
      87             :     virtual bool IsUndoNoResetModified() const = 0;
      88             : 
      89             :     /** Execute Undo.
      90             : 
      91             :         @return     true if executing the last Undo action was successful.
      92             :     */
      93             :     virtual bool Undo() = 0;
      94             : 
      95             :     /** Opens undo block.
      96             : 
      97             :         @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().
      98             : 
      99             :         @param nUndoId        undo ID for the list action
     100             :         @param pRewriter      rewriter for comments @see SwUndo::GetComment
     101             : 
     102             :         If the given nUndoId is equal to zero an undo object with ID
     103             :         UNDO_START will be generated.
     104             : 
     105             :         @return the undo ID of the created object
     106             :     */
     107             :     virtual SwUndoId StartUndo(SwUndoId const eUndoId,
     108             :                 SwRewriter const*const  pRewriter) = 0;
     109             : 
     110             :     /**
     111             :        Closes undo block.
     112             : 
     113             :        @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().
     114             : 
     115             :        @param nUndoId         undo ID for the list action
     116             :        @param pRewriter       rewriter for comments @see SwUndo::GetComment
     117             : 
     118             :        If the given nUndoId is not UNDO_EMPTY or UNDO_END, the comment of
     119             :        the resulting list action will be set via the nUndoId, applying the
     120             :        given pRewriter (if not 0).  Otherwise the comment of the resulting
     121             :        list action is unchanged if it has an UndoId that is not UNDO_START
     122             :        set by StartUndo, and in case the UndoId is UNDO_START the comment
     123             :        of the list action defaults to the comment of the last action
     124             :        contained in the list action.
     125             :     */
     126             :     virtual SwUndoId EndUndo(SwUndoId const eUndoId,
     127             :                 SwRewriter const*const  pRewriter) = 0;
     128             : 
     129             :     /**
     130             :         Delete all Undo actions.
     131             :         Of course Undo will be disabled during deletion.
     132             :     */
     133             :     virtual void DelAllUndoObj() = 0;
     134             : 
     135             :     /** Get Id and comment of last Undo action.
     136             :         @param o_pStr       if not 0, receives comment of last Undo action.
     137             :         @param o_pId        if not 0, receives Id of last Undo action.
     138             :         @return     true if there is a Undo action, false if none
     139             :     */
     140             :     virtual bool GetLastUndoInfo(OUString *const o_pStr,
     141             :                 SwUndoId *const o_pId) const = 0;
     142             : 
     143             :     /** Get comments of Undo actions.
     144             :         @return     comments of all top-level Undo actions.
     145             :     */
     146             :     virtual SwUndoComments_t GetUndoComments() const = 0;
     147             : 
     148             :     /** Execute Redo.
     149             : 
     150             :         @return     true if executing the first Redo action was successful.
     151             :     */
     152             :     virtual bool Redo() = 0;
     153             : 
     154             :     /** Get Id and comment of first Redo action.
     155             :         @param o_pStr       if not 0, receives comment of first Redo action.
     156             :         @param o_pId        if not 0, receives Id of first Redo action.
     157             :         @return     true if there is a Redo action, false if none
     158             :     */
     159             :     virtual bool GetFirstRedoInfo(OUString *const o_pStr,
     160             :                                   SwUndoId *const o_pId = 0) const = 0;
     161             : 
     162             :     /** Get comments of Redo actions.
     163             :         @return     comments of all top-level Redo actions.
     164             :     */
     165             :     virtual SwUndoComments_t GetRedoComments() const = 0;
     166             : 
     167             :     /** Repeat the last Undo action.
     168             :         @return     true if repeating the last Undo Redo action was attempted.
     169             :     */
     170             :     virtual bool Repeat(::sw::RepeatContext & rContext,
     171             :                 sal_uInt16 const nRepeatCnt) = 0;
     172             : 
     173             :     /** Get Id and comment of last Undo action, if it is Repeat capable.
     174             :         @param o_pStr       if not 0, receives comment of last Undo action
     175             :                             if it is Repeat capable.
     176             :         @return     Id of last Undo action if it is Repeat capable,
     177             :                     or UNDO_EMPTY if there is none or it is not Repeat capable.
     178             :     */
     179             :     virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const = 0;
     180             : 
     181             :     /** Add new Undo action.
     182             :         Takes over ownership of pUndo.
     183             :         @remark     calls ClearRedo(), except for UNDO_START/UNDO_END.
     184             :         @remark     does nothing if !DoesUndo().
     185             :     */
     186             :     virtual void AppendUndo(SwUndo *const pUndo) = 0;
     187             : 
     188             :     /** Delete all Redo actions.
     189             :     */
     190             :     virtual void ClearRedo() = 0;
     191             : 
     192             :     /* Is the given nodes array the Undo nodes array?
     193             :     */
     194             :     virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
     195             : 
     196             : protected:
     197        2949 :     virtual ~IDocumentUndoRedo() {};
     198             : };
     199             : 
     200             : namespace sw {
     201             : 
     202             : class UndoGuard
     203             : {
     204             : public:
     205             : 
     206       40683 :     UndoGuard(IDocumentUndoRedo & rUndoRedo)
     207             :         :   m_rUndoRedo(rUndoRedo)
     208       40683 :         ,   m_bUndoWasEnabled(rUndoRedo.DoesUndo())
     209             :     {
     210       40683 :         m_rUndoRedo.DoUndo(false);
     211       40683 :     }
     212       40683 :     ~UndoGuard()
     213             :     {
     214       40683 :         m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
     215       40683 :     }
     216             : 
     217       23669 :     bool UndoWasEnabled() const
     218             :     {
     219       23669 :         return m_bUndoWasEnabled;
     220             :     }
     221             : 
     222             : private:
     223             :     IDocumentUndoRedo & m_rUndoRedo;
     224             :     bool const m_bUndoWasEnabled;
     225             : };
     226             : 
     227             : class GroupUndoGuard
     228             : {
     229             : public:
     230             : 
     231      118602 :     GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
     232             :         :   m_rUndoRedo(rUndoRedo)
     233      118602 :         ,   m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
     234             :     {
     235      118602 :         m_rUndoRedo.DoGroupUndo(false);
     236      118602 :     }
     237      118602 :     ~GroupUndoGuard()
     238             :     {
     239      118602 :         m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
     240      118602 :     }
     241             : 
     242             : private:
     243             :     IDocumentUndoRedo & m_rUndoRedo;
     244             :     bool const m_bGroupUndoWasEnabled;
     245             : };
     246             : 
     247             : class DrawUndoGuard
     248             : {
     249             : public:
     250             : 
     251         544 :     DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
     252             :         :   m_rUndoRedo(rUndoRedo)
     253         544 :         ,   m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
     254             :     {
     255         544 :         m_rUndoRedo.DoDrawUndo(false);
     256         544 :     }
     257         544 :     ~DrawUndoGuard()
     258             :     {
     259         544 :         m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
     260         544 :     }
     261             : 
     262             : private:
     263             :     IDocumentUndoRedo & m_rUndoRedo;
     264             :     bool const m_bDrawUndoWasEnabled;
     265             : };
     266             : 
     267             : } // namespace sw
     268             : 
     269             : #endif
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11