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

Generated by: LCOV version 1.10