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,2026 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 // Declarations
32 class FXUndoList;
33 class FXCommandGroup;
34 
35 
56 class FXAPI FXCommand : public FXObject {
57  FXDECLARE_ABSTRACT(FXCommand)
58 private:
59  FXival refs;
60 private:
61  FXCommand(const FXCommand& org);
62  FXCommand &operator=(const FXCommand&);
63 protected:
64  FXCommand():refs(0){}
65 public:
66 
67  // Return reference count
68  FXival nrefs() const { return refs; }
69 
70  // Increment reference count
71  void ref(){ ++refs; }
72 
73  // Decrement reference count
74  void unref(){ if(--refs<=0) delete this; }
75 
79  virtual void undo() = 0;
80 
84  virtual void redo() = 0;
85 
94  virtual FXuval size() const;
95 
100  virtual FXString undoName() const;
101 
106  virtual FXString redoName() const;
107 
114  virtual FXbool canMerge() const;
115 
126  virtual FXuint mergeWith(FXCommand* command);
127  };
128 
129 
130 // A marked pointer to a command
132 
133 // Array of marked command pointers
135 
136 // Stack of command group pointers
138 
139 
157 class FXAPI FXCommandGroup : public FXCommand {
158  FXDECLARE(FXCommandGroup)
159  friend class FXUndoList;
160 private:
161  FXCommandArray command;
162 private:
164  FXCommandGroup &operator=(const FXCommandGroup&);
165 public:
166 
168  FXCommandGroup();
169 
171  FXbool empty() const;
172 
174  virtual FXbool cut();
175 
177  virtual void undo() override;
178 
180  virtual void redo() override;
181 
183  virtual FXuval size() const override;
184 
186  virtual void clear();
187 
189  virtual ~FXCommandGroup();
190  };
191 
192 
243 class FXAPI FXUndoList : public FXCommandGroup {
244  FXDECLARE(FXUndoList)
245 private:
246  FXCommandStack groups; // Command group stack
247  FXuval space; // Total memory in the undo commands
248  FXint undocount; // Number of undo records
249  FXint redocount; // Number of redo records
250  FXint working; // Currently busy with undo or redo
251  FXint marker; // Marker value
252  FXbool markset; // Mark is set
253  FXbool alternate; // Keep alternate history
254 private:
255  FXUndoList(const FXUndoList&);
256  FXUndoList &operator=(const FXUndoList&);
257 public:
258  long onCmdUndo(FXObject*,FXSelector,void*);
259  long onUpdUndo(FXObject*,FXSelector,void*);
260  long onCmdRedo(FXObject*,FXSelector,void*);
261  long onUpdRedo(FXObject*,FXSelector,void*);
262  long onCmdRevert(FXObject*,FXSelector,void*);
263  long onUpdRevert(FXObject*,FXSelector,void*);
264  long onCmdUndoAll(FXObject*,FXSelector,void*);
265  long onCmdRedoAll(FXObject*,FXSelector,void*);
266  long onUpdUndoCount(FXObject*,FXSelector,void*);
267  long onUpdRedoCount(FXObject*,FXSelector,void*);
268  long onCmdAltHistory(FXObject*,FXSelector,void*);
269  long onUpdAltHistory(FXObject*,FXSelector,void*);
270  long onCmdDumpStats(FXObject*,FXSelector,void*);
271  long onCmdTrimMark(FXObject*,FXSelector,void*);
272  long onCmdTrimSize(FXObject*,FXSelector,void*);
273  long onCmdTrimWrinkles(FXObject*,FXSelector,void*);
274  long onCmdTrimCount(FXObject*,FXSelector,void*);
275  long onCmdClear(FXObject*,FXSelector,void*);
276  long onUpdClear(FXObject*,FXSelector,void*);
277  long onUpdSize(FXObject*,FXSelector,void*);
278 public:
279  enum{
280  ID_REVERT=FXWindow::ID_LAST,
281  ID_UNDO,
282  ID_REDO,
283  ID_UNDO_ALL,
284  ID_REDO_ALL,
285  ID_UNDO_COUNT,
286  ID_REDO_COUNT,
287  ID_ALT_HISTORY,
288  ID_SIZE,
289  ID_CLEAR,
290  ID_TRIM_MARK,
291  ID_TRIM_COUNT_1K,
292  ID_TRIM_COUNT_10K,
293  ID_TRIM_COUNT_100K,
294  ID_TRIM_COUNT_1M,
295  ID_TRIM_COUNT_10M,
296  ID_TRIM_COUNT_100M,
297  ID_TRIM_COUNT_1G,
298  ID_TRIM_COUNT=ID_TRIM_COUNT_1K,
299  ID_TRIM_SIZE_1K,
300  ID_TRIM_SIZE_10K,
301  ID_TRIM_SIZE_100K,
302  ID_TRIM_SIZE_1M,
303  ID_TRIM_SIZE_10M,
304  ID_TRIM_SIZE_100M,
305  ID_TRIM_SIZE_1G,
306  ID_TRIM_SIZE=ID_TRIM_SIZE_10M,
307  ID_TRIM_ALT_1K,
308  ID_TRIM_ALT_10K,
309  ID_TRIM_ALT_100K,
310  ID_TRIM_ALT_1M,
311  ID_TRIM_ALT_10M,
312  ID_TRIM_ALT_100M,
313  ID_TRIM_ALT_1G,
314  ID_TRIM_ALT=ID_TRIM_ALT_10M,
315  ID_DUMP_STATS,
316  ID_LAST
317  };
318 public:
319 
323  FXUndoList();
324 
330  FXbool busy() const { return (working!=0); }
331 
340  void mark();
341 
345  void unmark();
346 
351  FXbool marked() const;
352 
360  FXbool add(FXCommand* cmd,FXbool doit=false,FXbool merge=true);
361 
368  FXbool begin(FXCommandGroup *command);
369 
375  FXbool abort();
376 
383  FXbool end();
384 
402  virtual FXbool cut() override;
403 
407  virtual void undo() override;
408 
412  virtual void redo() override;
413 
417  void undoAll();
418 
422  void redoAll();
423 
428  void revert();
429 
433  FXbool canUndo() const;
434 
438  FXbool canRedo() const;
439 
443  FXbool canRevert() const;
444 
448  FXCommand* current() const;
449 
454  virtual FXString undoName() const override;
455 
460  virtual FXString redoName() const override;
461 
463  FXint undoCount() const { return undocount; }
464 
466  FXint redoCount() const { return redocount; }
467 
471  virtual FXuval size() const override;
472 
478  void trimMark();
479 
486  void trimSize(FXuval sz);
487 
503  void trimWrinkles(FXuval sz);
504 
511  void trimCount(FXint nc);
512 
517  virtual void clear() override;
518 
526  void setAlternateHistory(FXbool flag){ alternate=flag; }
527 
531  FXbool getAlternateHistory() const { return alternate; }
532 
534  void dumpStats();
535 
537  virtual ~FXUndoList();
538  };
539 
540 }
541 
542 #endif
FXint redoCount() const
Number of redo records.
Definition: FXUndoList.h:466
FXint undoCount() const
Number of undo records.
Definition: FXUndoList.h:463
FXbool busy() const
Return true if currently inside undo or redo operation; this is useful to avoid generating another un...
Definition: FXUndoList.h:330
void setAlternateHistory(FXbool flag)
Enable or disable alternate history mode.
Definition: FXUndoList.h:526
Base class for undoable commands records.
Definition: FXUndoList.h:56
Marked pointer keeps a flag bit inside of a dynamically allocated pointer; this is possible because m...
Definition: FXMarkedPtr.h:34
Definition: FX4Splitter.h:28
FXbool getAlternateHistory() const
Returns true if alternate history mode is in effect.
Definition: FXUndoList.h:531
The UndoList class manages a list of undoable commands.
Definition: FXUndoList.h:243
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:138
Group of undoable commands.
Definition: FXUndoList.h:157
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2026 Jeroen van der Zijp