Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXUndoList.h
1 /********************************************************************************
2 * *
3 * U n d o / R e d o - a b l e C o m m a n d *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2000,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXUNDOLIST_H
22 #define FXUNDOLIST_H
23 
24 #ifndef FXOBJECT_H
25 #include "FXObject.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 class FXUndoList;
32 class FXCommandGroup;
33 
34 
41 class FXAPI FXCommand : public FXObject {
42  FXDECLARE_ABSTRACT(FXCommand)
43  friend class FXUndoList;
44  friend class FXCommandGroup;
45 private:
46  FXCommand *next;
47 private:
48  FXCommand(const FXCommand&);
49  FXCommand &operator=(const FXCommand&);
50 protected:
51  FXCommand():next(NULL){}
52 public:
53 
58  virtual void undo() = 0;
59 
64  virtual void redo() = 0;
65 
73  virtual FXuint size() const;
74 
79  virtual FXString undoName() const;
80 
85  virtual FXString redoName() const;
86 
93  virtual FXbool canMerge() const;
94 
100  virtual FXbool mergeWith(FXCommand* command);
101 
103  virtual ~FXCommand(){}
104  };
105 
106 
107 
114 class FXAPI FXCommandGroup : public FXCommand {
115  FXDECLARE(FXCommandGroup)
116  friend class FXUndoList;
117 private:
118  FXCommand *undolist;
119  FXCommand *redolist;
120  FXCommandGroup *group;
121 private:
123  FXCommandGroup &operator=(const FXCommandGroup&);
124 public:
125 
127  FXCommandGroup():undolist(NULL),redolist(NULL),group(NULL){}
128 
130  FXbool empty(){ return !undolist; }
131 
133  virtual void undo();
134 
136  virtual void redo();
137 
139  virtual FXuint size() const;
140 
142  virtual ~FXCommandGroup();
143  };
144 
145 
146 
150 class FXAPI FXUndoList : public FXCommandGroup {
151  FXDECLARE(FXUndoList)
152 private:
153  FXint undocount; // Number of undo records
154  FXint redocount; // Number of redo records
155  FXint marker; // Marker value
156  FXuint space; // Space taken up by all the undo records
157  FXbool working; // Currently busy with undo or redo
158 private:
159  FXUndoList(const FXUndoList&);
160  FXUndoList &operator=(const FXUndoList&);
161 public:
162  long onCmdUndo(FXObject*,FXSelector,void*);
163  long onUpdUndo(FXObject*,FXSelector,void*);
164  long onCmdRedo(FXObject*,FXSelector,void*);
165  long onUpdRedo(FXObject*,FXSelector,void*);
166  long onCmdClear(FXObject*,FXSelector,void*);
167  long onUpdClear(FXObject*,FXSelector,void*);
168  long onCmdRevert(FXObject*,FXSelector,void*);
169  long onUpdRevert(FXObject*,FXSelector,void*);
170  long onCmdUndoAll(FXObject*,FXSelector,void*);
171  long onCmdRedoAll(FXObject*,FXSelector,void*);
172  long onUpdUndoCount(FXObject*,FXSelector,void*);
173  long onUpdRedoCount(FXObject*,FXSelector,void*);
174 public:
175  enum{
176  ID_CLEAR=FXWindow::ID_LAST,
177  ID_REVERT,
178  ID_UNDO,
179  ID_REDO,
180  ID_UNDO_ALL,
181  ID_REDO_ALL,
182  ID_UNDO_COUNT,
183  ID_REDO_COUNT,
184  ID_LAST
185  };
186 public:
187 
191  FXUndoList();
192 
197  void cut();
198 
208  void add(FXCommand* command,FXbool doit=false,FXbool merge=true);
209 
216  void begin(FXCommandGroup *command);
217 
224  void end();
225 
231  void abort();
232 
236  virtual void undo();
237 
241  virtual void redo();
242 
244  void undoAll();
245 
247  void redoAll();
248 
250  void revert();
251 
253  FXbool canUndo() const;
254 
256  FXbool canRedo() const;
257 
259  FXbool canRevert() const;
260 
266  FXbool busy() const { return working; }
267 
269  FXCommand* current() const { return undolist; }
270 
275  virtual FXString undoName() const;
276 
281  virtual FXString redoName() const;
282 
284  FXint undoCount() const { return undocount; }
285 
287  FXint redoCount() const { return redocount; }
288 
290  virtual FXuint size() const;
291 
296  void clear();
297 
303  void trimCount(FXint nc);
304 
310  void trimSize(FXuint sz);
311 
318  void mark();
319 
323  void unmark();
324 
329  FXbool marked() const;
330  };
331 
332 
333 }
334 
335 #endif

Copyright © 1997-2016 Jeroen van der Zijp