LCOV - code coverage report
Current view: top level - sw/inc - IDocumentUndoRedo.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 25 100.0 %
Date: 2012-08-25 Functions: 9 10 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           Branch data     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                 :       1549 : 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 sal_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(::rtl::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 sal_Bool Redo() = 0;
     158                 :            : 
     159                 :            :     /** Get comment of first Redo action.
     160                 :            :         @param o_pStr       if not 0, receives comment of first Redo action.
     161                 :            :         @return     true if there is a Redo action, false if none
     162                 :            :     */
     163                 :            :     virtual bool GetFirstRedoInfo(::rtl::OUString *const o_pStr) const = 0;
     164                 :            : 
     165                 :            :     /** Get comments of Redo actions.
     166                 :            :         @return     comments of all top-level Redo actions.
     167                 :            :     */
     168                 :            :     virtual SwUndoComments_t GetRedoComments() const = 0;
     169                 :            : 
     170                 :            :     /** Repeat the last Undo action.
     171                 :            :         @return     true if repeating the last Undo Redo action was attempted.
     172                 :            :     */
     173                 :            :     virtual bool Repeat(::sw::RepeatContext & rContext,
     174                 :            :                 sal_uInt16 const nRepeatCnt) = 0;
     175                 :            : 
     176                 :            :     /** Get Id and comment of last Undo action, if it is Repeat capable.
     177                 :            :         @param o_pStr       if not 0, receives comment of last Undo action
     178                 :            :                             if it is Repeat capable.
     179                 :            :         @return     Id of last Undo action if it is Repeat capable,
     180                 :            :                     or UNDO_EMPTY if there is none or it is not Repeat capable.
     181                 :            :     */
     182                 :            :     virtual SwUndoId GetRepeatInfo(::rtl::OUString *const o_pStr) const = 0;
     183                 :            : 
     184                 :            :     /** Add new Undo action.
     185                 :            :         Takes over ownership of pUndo.
     186                 :            :         @remark     calls ClearRedo(), except for UNDO_START/UNDO_END.
     187                 :            :         @remark     does nothing if !DoesUndo().
     188                 :            :     */
     189                 :            :     virtual void AppendUndo(SwUndo *const pUndo) = 0;
     190                 :            : 
     191                 :            :     /** Delete all Redo actions.
     192                 :            :     */
     193                 :            :     virtual void ClearRedo() = 0;
     194                 :            : 
     195                 :            :     /* Is the given nodes array the Undo nodes array?
     196                 :            :     */
     197                 :            :     virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;
     198                 :            : 
     199                 :            : protected:
     200         [ -  + ]:       1458 :     virtual ~IDocumentUndoRedo() {};
     201                 :            : };
     202                 :            : 
     203                 :            : 
     204                 :            : namespace sw {
     205                 :            : 
     206                 :            : class UndoGuard
     207                 :            : {
     208                 :            : public:
     209                 :            : 
     210                 :      10070 :     UndoGuard(IDocumentUndoRedo & rUndoRedo)
     211                 :            :         :   m_rUndoRedo(rUndoRedo)
     212                 :      10070 :         ,   m_bUndoWasEnabled(rUndoRedo.DoesUndo())
     213                 :            :     {
     214                 :      10070 :         m_rUndoRedo.DoUndo(false);
     215                 :      10070 :     }
     216                 :      10070 :     ~UndoGuard()
     217                 :            :     {
     218                 :      10070 :         m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
     219                 :      10070 :     }
     220                 :            : 
     221                 :       3559 :     bool UndoWasEnabled() const
     222                 :            :     {
     223                 :       3559 :         return m_bUndoWasEnabled;
     224                 :            :     }
     225                 :            : 
     226                 :            : private:
     227                 :            :     IDocumentUndoRedo & m_rUndoRedo;
     228                 :            :     bool const m_bUndoWasEnabled;
     229                 :            : };
     230                 :            : 
     231                 :            : class GroupUndoGuard
     232                 :            : {
     233                 :            : public:
     234                 :            : 
     235                 :      18739 :     GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
     236                 :            :         :   m_rUndoRedo(rUndoRedo)
     237                 :      18739 :         ,   m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
     238                 :            :     {
     239                 :      18739 :         m_rUndoRedo.DoGroupUndo(false);
     240                 :      18739 :     }
     241                 :      18739 :     ~GroupUndoGuard()
     242                 :            :     {
     243                 :      18739 :         m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
     244                 :      18739 :     }
     245                 :            : 
     246                 :            : private:
     247                 :            :     IDocumentUndoRedo & m_rUndoRedo;
     248                 :            :     bool const m_bGroupUndoWasEnabled;
     249                 :            : };
     250                 :            : 
     251                 :            : class DrawUndoGuard
     252                 :            : {
     253                 :            : public:
     254                 :            : 
     255                 :         15 :     DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
     256                 :            :         :   m_rUndoRedo(rUndoRedo)
     257                 :         15 :         ,   m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
     258                 :            :     {
     259                 :         15 :         m_rUndoRedo.DoDrawUndo(false);
     260                 :         15 :     }
     261                 :         15 :     ~DrawUndoGuard()
     262                 :            :     {
     263                 :         15 :         m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
     264                 :         15 :     }
     265                 :            : 
     266                 :            : private:
     267                 :            :     IDocumentUndoRedo & m_rUndoRedo;
     268                 :            :     bool const m_bDrawUndoWasEnabled;
     269                 :            : };
     270                 :            : 
     271                 :            : 
     272                 :            : } // namespace sw
     273                 :            : 
     274                 :            : #endif
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10