LibreOffice Module svl (master) 1
undo.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_SVL_UNDO_HXX
20#define INCLUDED_SVL_UNDO_HXX
21
22#include <svl/svldllapi.h>
23#include <rtl/ustring.hxx>
24#include <tools/datetime.hxx>
25#include <o3tl/strong_int.hxx>
26
27#include <memory>
28#include <vector>
29
32
33typedef struct _xmlTextWriter* xmlTextWriterPtr;
34
35class SVL_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") SfxRepeatTarget
36{
37public:
38 virtual ~SfxRepeatTarget() = 0;
39};
40
41
43{
44public:
49 virtual size_t GetUndoOffset() { return 0; }
50
51 virtual ~SfxUndoContext() = 0;
52};
53
54
56{
57public:
59 virtual ~SfxUndoAction() COVERITY_NOEXCEPT_FALSE;
60
61 virtual void Undo();
62 virtual void UndoWithContext( SfxUndoContext& i_context );
63 virtual void Redo();
64 virtual void RedoWithContext( SfxUndoContext& i_context );
65 virtual void Repeat(SfxRepeatTarget&);
66 virtual bool CanRepeat(SfxRepeatTarget&) const;
67
68 virtual bool Merge( SfxUndoAction *pNextAction );
69
70 virtual OUString GetComment() const;
71 virtual OUString GetRepeatComment(SfxRepeatTarget&) const;
73 virtual ViewShellId GetViewShellId() const;
75 const DateTime& GetDateTime() const;
76 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
77
78private:
79 SfxUndoAction( const SfxUndoAction& ) = delete;
81
83};
84
85
87typedef sal_Int32 UndoStackMark;
88#define MARK_INVALID ::std::numeric_limits< UndoStackMark >::max()
89
91{
92 std::unique_ptr<SfxUndoAction> pAction;
93 ::std::vector< UndoStackMark > aMarks;
94
95 MarkedUndoAction(std::unique_ptr<SfxUndoAction> p) : pAction(std::move(p)) {}
96};
97
101{
102 std::vector<MarkedUndoAction> maUndoActions;
106
107 SfxUndoArray(size_t nMax=0) :
108 nMaxUndoActions(nMax), nCurUndoAction(0), pFatherUndoArray(nullptr) {}
109 virtual ~SfxUndoArray();
110
111 SfxUndoArray& operator=( SfxUndoArray const & ) = delete; // MSVC2017 workaround
112 SfxUndoArray( SfxUndoArray const & ) = delete; // MSVC2017 workaround
113
114 SfxUndoAction* GetUndoAction(size_t idx) { return maUndoActions[idx].pAction.get(); }
115 std::unique_ptr<SfxUndoAction> Remove(int idx);
116 void Remove( size_t i_pos, size_t i_count );
117 void Insert( std::unique_ptr<SfxUndoAction> i_action, size_t i_pos );
118};
119
120
124
125/* [Explanation]
126
127 UndoAction to composite multiple Undos in one UndoAction.
128 These actions are used by SfxUndomanager. With < SfxUndoManager::EnterListAction >
129 you can go one composite level down and with < SfxUndoManager::LeaveListAction > up again.
130 Redo and Undo work element wise on SfxListUndoActions.
131*/
132{
133 struct Impl;
134 std::unique_ptr<Impl> mpImpl;
135
136public:
137
139 const OUString &rComment, const OUString& rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId, SfxUndoArray *pFather );
140 virtual ~SfxListUndoAction() override;
141
142 virtual void Undo() override;
143 virtual void UndoWithContext( SfxUndoContext& i_context ) override;
144 virtual void Redo() override;
145 virtual void RedoWithContext( SfxUndoContext& i_context ) override;
146 virtual void Repeat(SfxRepeatTarget&) override;
147 virtual bool CanRepeat(SfxRepeatTarget&) const override;
148
149 virtual bool Merge( SfxUndoAction *pNextAction ) override;
150
151 virtual OUString GetComment() const override;
153 ViewShellId GetViewShellId() const override;
154 virtual OUString GetRepeatComment(SfxRepeatTarget&) const override;
155 sal_uInt16 GetId() const;
156
157 void SetComment(const OUString& rComment);
158 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
159};
160
161
165{
166public:
167 virtual void actionUndone( const OUString& i_actionComment ) = 0;
168 virtual void actionRedone( const OUString& i_actionComment ) = 0;
169 virtual void undoActionAdded( const OUString& i_actionComment ) = 0;
170 virtual void cleared() = 0;
171 virtual void clearedRedo() = 0;
172 virtual void resetAll() = 0;
173 virtual void listActionEntered( const OUString& i_comment ) = 0;
174 virtual void listActionLeft( const OUString& i_comment ) = 0;
175 virtual void listActionCancelled() = 0;
176
177protected:
179};
180
181
182namespace svl::undo::impl
183{
184 class UndoManagerGuard;
185 class LockGuard;
186}
187
190{
191 std::unique_ptr< SfxUndoManager_Data >
193public:
194 static bool const CurrentLevel = true;
195 static bool const TopLevel = false;
196
197 SfxUndoManager( size_t nMaxUndoActionCount = 20 );
198 virtual ~SfxUndoManager();
199
200 void SetMaxUndoActionCount( size_t nMaxUndoActionCount );
201 size_t GetMaxUndoActionCount() const;
202 virtual void AddUndoAction( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerg=false );
203 virtual size_t GetUndoActionCount( bool const i_currentLevel = CurrentLevel ) const;
204 OUString GetUndoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const;
205 SfxUndoAction* GetUndoAction( size_t nNo=0 ) const;
207 OUString GetUndoActionsInfo() const;
208 virtual size_t GetRedoActionCount( bool const i_currentLevel = CurrentLevel ) const;
209 OUString GetRedoActionComment( size_t nNo=0, bool const i_currentLevel = CurrentLevel ) const;
210 SfxUndoAction* GetRedoAction(size_t nNo = 0) const;
212 OUString GetRedoActionsInfo() const;
213 virtual bool Undo();
214 virtual bool Redo();
218 virtual void Clear();
222 virtual void ClearRedo();
230 void Reset();
233 bool IsDoing() const;
234 size_t GetRepeatActionCount() const;
235 OUString GetRepeatActionComment( SfxRepeatTarget &rTarget) const;
236 bool Repeat( SfxRepeatTarget &rTarget );
237 bool CanRepeat( SfxRepeatTarget &rTarget ) const;
238 virtual void EnterListAction(const OUString &rComment, const OUString& rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId);
243 size_t LeaveListAction();
244
260 size_t LeaveAndMergeListAction();
262 bool IsInListAction() const;
264 size_t GetListActionDepth() const;
266 void RemoveLastUndoAction();
275 void EnableUndo( bool bEnable );
279 bool IsUndoEnabled() const;
281 void AddUndoListener( SfxUndoListener& i_listener );
282 void RemoveUndoListener( SfxUndoListener& i_listener );
283 bool IsEmptyActions() const;
284
285
288 UndoStackMark MarkTopUndoAction();
289
293 void RemoveMark( UndoStackMark const i_mark );
294
297 bool HasTopUndoActionMark( UndoStackMark const i_mark );
298
301 void RemoveOldestUndoAction();
302
303 void dumpAsXml(xmlTextWriterPtr pWriter) const;
304
305protected:
306 bool UndoWithContext( SfxUndoContext& i_context );
307 bool RedoWithContext( SfxUndoContext& i_context );
308
309 void ImplClearRedo_NoLock( bool const i_currentLevel );
310
320 void ClearAllLevels();
321 virtual void EmptyActionsChanged();
322
323private:
324 size_t ImplLeaveListAction( const bool i_merge, ::svl::undo::impl::UndoManagerGuard& i_guard );
325 bool ImplAddUndoAction_NoNotify( std::unique_ptr<SfxUndoAction> pAction, bool bTryMerge, bool bClearRedo, ::svl::undo::impl::UndoManagerGuard& i_guard );
326 void ImplClearRedo( ::svl::undo::impl::UndoManagerGuard& i_guard, bool const i_currentLevel );
327 void ImplClearUndo( ::svl::undo::impl::UndoManagerGuard& i_guard );
328 void ImplClearCurrentLevel_NoNotify( ::svl::undo::impl::UndoManagerGuard& i_guard );
329 size_t ImplGetRedoActionCount_Lock( bool const i_currentLevel = CurrentLevel ) const;
330 bool ImplIsUndoEnabled_Lock() const;
331 bool ImplIsInListAction_Lock() const;
332 void ImplEnableUndo_Lock( bool const i_enable );
333
334 bool ImplUndo( SfxUndoContext* i_contextOrNull );
335 bool ImplRedo( SfxUndoContext* i_contextOrNull );
336 void ImplCheckEmptyActions();
337 inline bool ImplIsEmptyActions() const;
338
339 friend class ::svl::undo::impl::LockGuard;
340};
341
342#endif
343
344/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
do not make use of these implementation details, unless you really really have to!
Definition: undo.hxx:132
std::unique_ptr< Impl > mpImpl
Definition: undo.hxx:133
SfxUndoAction(const SfxUndoAction &)=delete
SfxUndoAction & operator=(const SfxUndoAction &)=delete
DateTime m_aDateTime
Definition: undo.hxx:82
virtual size_t GetUndoOffset()
Don't undo the top undo action, but an earlier one.
Definition: undo.hxx:49
is a callback interface for notifications about state changes of an SfxUndoManager
Definition: undo.hxx:165
virtual void listActionEntered(const OUString &i_comment)=0
~SfxUndoListener()
Definition: undo.hxx:178
virtual void cleared()=0
virtual void actionUndone(const OUString &i_actionComment)=0
virtual void actionRedone(const OUString &i_actionComment)=0
virtual void listActionLeft(const OUString &i_comment)=0
virtual void clearedRedo()=0
virtual void resetAll()=0
virtual void listActionCancelled()=0
virtual void undoActionAdded(const OUString &i_actionComment)=0
std::unique_ptr< SfxUndoManager_Data > m_xData
Definition: undo.hxx:192
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
virtual sal_uInt32 GetId() const override
struct _xmlTextWriter * xmlTextWriterPtr
const sal_uInt16 idx[]
void * p
void Clear(EHistoryType eHistory)
DateTime GetDateTime(const css::util::DateTime &_rDT)
::std::vector< UndoStackMark > aMarks
Definition: undo.hxx:93
MarkedUndoAction(std::unique_ptr< SfxUndoAction > p)
Definition: undo.hxx:95
std::unique_ptr< SfxUndoAction > pAction
Definition: undo.hxx:92
do not make use of these implementation details, unless you really really have to!
Definition: undo.hxx:101
std::vector< MarkedUndoAction > maUndoActions
Definition: undo.hxx:102
SfxUndoArray & operator=(SfxUndoArray const &)=delete
size_t nMaxUndoActions
Definition: undo.hxx:103
SfxUndoArray(SfxUndoArray const &)=delete
SfxUndoAction * GetUndoAction(size_t idx)
Definition: undo.hxx:114
SfxUndoArray(size_t nMax=0)
Definition: undo.hxx:107
size_t nCurUndoAction
Definition: undo.hxx:104
SfxUndoArray * pFatherUndoArray
Definition: undo.hxx:105
#define SVL_DLLPUBLIC
Definition: svldllapi.h:28
#define SAL_NO_VTABLE
o3tl::strong_int< sal_Int32, struct ViewShellIdTag > ViewShellId
Definition: undo.hxx:30
struct _xmlTextWriter * xmlTextWriterPtr
Definition: undo.hxx:33
sal_Int32 UndoStackMark
is a mark on the Undo stack
Definition: undo.hxx:87
o3tl::strong_int< int, struct ViewShellDocIdTag > ViewShellDocId
Definition: undo.hxx:31
class SVL_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") SfxRepeatTarget
Definition: undo.hxx:35