00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXUNDOLIST_H
00022 #define FXUNDOLIST_H
00023
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027
00028 namespace FX {
00029
00030
00031 class FXUndoList;
00032 class FXCommandGroup;
00033
00034
00041 class FXAPI FXCommand : public FXObject {
00042 FXDECLARE_ABSTRACT(FXCommand)
00043 friend class FXUndoList;
00044 friend class FXCommandGroup;
00045 private:
00046 FXCommand *next;
00047 private:
00048 FXCommand(const FXCommand&);
00049 FXCommand &operator=(const FXCommand&);
00050 protected:
00051 FXCommand():next(NULL){}
00052 public:
00053
00058 virtual void undo() = 0;
00059
00064 virtual void redo() = 0;
00065
00073 virtual FXuint size() const;
00074
00079 virtual FXString undoName() const;
00080
00085 virtual FXString redoName() const;
00086
00093 virtual FXbool canMerge() const;
00094
00100 virtual FXbool mergeWith(FXCommand* command);
00101
00103 virtual ~FXCommand(){}
00104 };
00105
00106
00107
00114 class FXAPI FXCommandGroup : public FXCommand {
00115 FXDECLARE(FXCommandGroup)
00116 friend class FXUndoList;
00117 private:
00118 FXCommand *undolist;
00119 FXCommand *redolist;
00120 FXCommandGroup *group;
00121 private:
00122 FXCommandGroup(const FXCommandGroup&);
00123 FXCommandGroup &operator=(const FXCommandGroup&);
00124 public:
00125
00127 FXCommandGroup():undolist(NULL),redolist(NULL),group(NULL){}
00128
00130 FXbool empty(){ return !undolist; }
00131
00133 virtual void undo();
00134
00136 virtual void redo();
00137
00139 virtual FXuint size() const;
00140
00142 virtual ~FXCommandGroup();
00143 };
00144
00145
00146
00150 class FXAPI FXUndoList : public FXCommandGroup {
00151 FXDECLARE(FXUndoList)
00152 private:
00153 FXint undocount;
00154 FXint redocount;
00155 FXint marker;
00156 FXuint space;
00157 FXbool working;
00158 private:
00159 FXUndoList(const FXUndoList&);
00160 FXUndoList &operator=(const FXUndoList&);
00161 public:
00162 long onCmdUndo(FXObject*,FXSelector,void*);
00163 long onUpdUndo(FXObject*,FXSelector,void*);
00164 long onCmdRedo(FXObject*,FXSelector,void*);
00165 long onUpdRedo(FXObject*,FXSelector,void*);
00166 long onCmdClear(FXObject*,FXSelector,void*);
00167 long onUpdClear(FXObject*,FXSelector,void*);
00168 long onCmdRevert(FXObject*,FXSelector,void*);
00169 long onUpdRevert(FXObject*,FXSelector,void*);
00170 long onCmdUndoAll(FXObject*,FXSelector,void*);
00171 long onCmdRedoAll(FXObject*,FXSelector,void*);
00172 long onUpdUndoCount(FXObject*,FXSelector,void*);
00173 long onUpdRedoCount(FXObject*,FXSelector,void*);
00174 public:
00175 enum{
00176 ID_CLEAR=FXWindow::ID_LAST,
00177 ID_REVERT,
00178 ID_UNDO,
00179 ID_REDO,
00180 ID_UNDO_ALL,
00181 ID_REDO_ALL,
00182 ID_UNDO_COUNT,
00183 ID_REDO_COUNT,
00184 ID_LAST
00185 };
00186 public:
00187
00191 FXUndoList();
00192
00197 void cut();
00198
00208 void add(FXCommand* command,FXbool doit=false,FXbool merge=true);
00209
00216 void begin(FXCommandGroup *command);
00217
00224 void end();
00225
00231 void abort();
00232
00236 virtual void undo();
00237
00241 virtual void redo();
00242
00244 void undoAll();
00245
00247 void redoAll();
00248
00250 void revert();
00251
00253 FXbool canUndo() const;
00254
00256 FXbool canRedo() const;
00257
00259 FXbool canRevert() const;
00260
00266 FXbool busy() const { return working; }
00267
00269 FXCommand* current() const { return undolist; }
00270
00275 virtual FXString undoName() const;
00276
00281 virtual FXString redoName() const;
00282
00284 FXint undoCount() const { return undocount; }
00285
00287 FXint redoCount() const { return redocount; }
00288
00290 virtual FXuint size() const;
00291
00296 void clear();
00297
00303 void trimCount(FXint nc);
00304
00310 void trimSize(FXuint sz);
00311
00318 void mark();
00319
00323 void unmark();
00324
00329 FXbool marked() const;
00330 };
00331
00332
00333 }
00334
00335 #endif