summaryrefslogtreecommitdiffstats
path: root/sw/inc/IDocumentUndoRedo.hxx
blob: b533a7e647c221dc6e8fbc9058c69e95a159d33c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX
#define INCLUDED_SW_INC_IDOCUMENTUNDOREDO_HXX

#include <sal/types.h>

#include "swundo.hxx"
#include <memory>

class SwRewriter;
class SwNodes;
class SwUndo;
class SwView;

namespace sw {
    class RepeatContext;
}

class IDocumentUndoRedo
{
public:

    /** Enable/Disable Undo.
    */
    virtual void DoUndo(bool const bDoUndo) = 0;

    /** Is Undo enabled?
    */
    virtual bool DoesUndo() const = 0;

    /** Enable/Disable Group Undo.
        This determines whether successive Insert/Delete/Overwrite
        actions are combined.
    */
    virtual void DoGroupUndo(bool const bDoUndo) = 0;

    /** Is Group Undo enabled?
    */
    virtual bool DoesGroupUndo() const = 0;

    /** Enable/Disable Undo for Drawing objects.
     */
    virtual void DoDrawUndo(bool const bDoUndo) = 0;

    /** Is Undo for Drawing objects enabled?
        for Draw-Undo: writer wants to handle actions on Flys on its own.
     */
    virtual bool DoesDrawUndo() const = 0;

    /// Enable repair mode.
    virtual void DoRepair(bool bRepair) = 0;
    /// Is repair mode active?
    virtual bool DoesRepair() const = 0;

    /** Set the position at which the document is in the "unmodified" state
        to the current position in the Undo stack.
    */
    virtual void SetUndoNoModifiedPosition() = 0;

    /** Prevent updates to the "unmodified" state position
        via SetUndoNoResetModified().
    */
    virtual void LockUndoNoModifiedPosition() = 0;

    /** Allow updates to the "unmodified" state position
        via SetUndoNoResetModified().
    */
    virtual void UnLockUndoNoModifiedPosition() = 0;

    /** Disable (re)setting the document modified flag on Undo/Redo.
    */
    virtual void SetUndoNoResetModified() = 0;

    /** Is setting the document modified flag on Undo/Redo disabled?
    */
    virtual bool IsUndoNoResetModified() const = 0;

    /** Execute Undo.

        @return     true if executing the last Undo action was successful.
    */
    virtual bool Undo() = 0;

    /** Opens undo block.

        @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().

        @param nUndoId        undo ID for the list action
        @param pRewriter      rewriter for comments @see SwUndo::GetComment

        If the given nUndoId is equal to zero an undo object with ID
        SwUndoId::START will be generated.

        @return the undo ID of the created object
    */
    virtual SwUndoId StartUndo(SwUndoId const eUndoId,
                SwRewriter const*const  pRewriter) = 0;

    /**
       Closes undo block.

       @remark     StartUndo() and EndUndo() do nothing if !DoesUndo().

       @param nUndoId         undo ID for the list action
       @param pRewriter       rewriter for comments @see SwUndo::GetComment

       If the given nUndoId is not SwUndoId::EMPTY or SwUndoId::END, the comment of
       the resulting list action will be set via the nUndoId, applying the
       given pRewriter (if not 0).  Otherwise the comment of the resulting
       list action is unchanged if it has an UndoId that is not SwUndoId::START
       set by StartUndo, and in case the UndoId is SwUndoId::START the comment
       of the list action defaults to the comment of the last action
       contained in the list action.
    */
    virtual SwUndoId EndUndo(SwUndoId const eUndoId,
                SwRewriter const*const  pRewriter) = 0;

    /**
        Delete all Undo actions.
        Of course Undo will be disabled during deletion.
    */
    virtual void DelAllUndoObj() = 0;

    /** Get Id and comment of last Undo action.
        @param o_pStr       if not 0, receives comment of last Undo action.
        @param o_pId        if not 0, receives Id of last Undo action.
        @param pView        if not nullptr, get the info for this view
        @return     true if there is a Undo action, false if none
    */
    virtual bool GetLastUndoInfo(OUString *const o_pStr,
                SwUndoId *const o_pId,
                const SwView* pView = nullptr) const = 0;

    /** Get comments of Undo actions.
        @return     comments of all top-level Undo actions.
    */
    virtual SwUndoComments_t GetUndoComments() const = 0;

    /** Execute Redo.

        @return     true if executing the first Redo action was successful.
    */
    virtual bool Redo() = 0;

    /** Get Id and comment of first Redo action.
        @param o_pStr       if not 0, receives comment of first Redo action.
        @param o_pId        if not 0, receives Id of first Redo action.
        @param pView        if not nullptr, get the info for this view
        @return     true if there is a Redo action, false if none
    */
    virtual bool GetFirstRedoInfo(OUString *const o_pStr,
                                  SwUndoId *const o_pId,
                                  const SwView* pView = nullptr) const = 0;

    /** Get comments of Redo actions.
        @return     comments of all top-level Redo actions.
    */
    virtual SwUndoComments_t GetRedoComments() const = 0;

    /** Repeat the last Undo action.
        @return     true if repeating the last Undo Redo action was attempted.
    */
    virtual bool Repeat(::sw::RepeatContext & rContext,
                sal_uInt16 const nRepeatCnt) = 0;

    /** Get Id and comment of last Undo action, if it is Repeat capable.
        @param o_pStr       if not 0, receives comment of last Undo action
                            if it is Repeat capable.
        @return     Id of last Undo action if it is Repeat capable,
                    or SwUndoId::EMPTY if there is none or it is not Repeat capable.
    */
    virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const = 0;

    /** Add new Undo action.
        Takes over ownership of pUndo.
        @remark     calls ClearRedo(), except for SwUndoId::START/SwUndoId::END.
        @remark     does nothing if !DoesUndo().
    */
    virtual void AppendUndo(std::unique_ptr<SwUndo> pUndo) = 0;

    /** Delete all Redo actions.
    */
    virtual void ClearRedo() = 0;

    /* Is the given nodes array the Undo nodes array?
    */
    virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0;

    /** Get the number of Undo actions.
    */
    virtual size_t GetUndoActionCount(const bool bCurrentLevel = true) const = 0;

    /** Return undo/redo info for this view.
     */
    virtual void SetView(SwView* pView) = 0;

protected:
    virtual ~IDocumentUndoRedo() {};
};

namespace sw {

class UndoGuard
{
public:

    UndoGuard(IDocumentUndoRedo & rUndoRedo)
        :   m_rUndoRedo(rUndoRedo)
        ,   m_bUndoWasEnabled(rUndoRedo.DoesUndo())
    {
        m_rUndoRedo.DoUndo(false);
    }
    ~UndoGuard()
    {
        m_rUndoRedo.DoUndo(m_bUndoWasEnabled);
    }

    bool UndoWasEnabled() const
    {
        return m_bUndoWasEnabled;
    }

private:
    IDocumentUndoRedo & m_rUndoRedo;
    bool const m_bUndoWasEnabled;
};

class GroupUndoGuard
{
public:

    GroupUndoGuard(IDocumentUndoRedo & rUndoRedo)
        :   m_rUndoRedo(rUndoRedo)
        ,   m_bGroupUndoWasEnabled(rUndoRedo.DoesGroupUndo())
    {
        m_rUndoRedo.DoGroupUndo(false);
    }
    ~GroupUndoGuard()
    {
        m_rUndoRedo.DoGroupUndo(m_bGroupUndoWasEnabled);
    }

private:
    IDocumentUndoRedo & m_rUndoRedo;
    bool const m_bGroupUndoWasEnabled;
};

class DrawUndoGuard
{
public:

    DrawUndoGuard(IDocumentUndoRedo & rUndoRedo)
        :   m_rUndoRedo(rUndoRedo)
        ,   m_bDrawUndoWasEnabled(rUndoRedo.DoesDrawUndo())
    {
        m_rUndoRedo.DoDrawUndo(false);
    }
    ~DrawUndoGuard()
    {
        m_rUndoRedo.DoDrawUndo(m_bDrawUndoWasEnabled);
    }

private:
    IDocumentUndoRedo & m_rUndoRedo;
    bool const m_bDrawUndoWasEnabled;
};

} // namespace sw

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */