![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * U n d o / R e d o - a b l e C o m m a n d * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2000,2002 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXUndoList.h,v 1.18 2002/03/12 07:11:31 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXUNDOLIST_H 00025 #define FXUNDOLIST_H 00026 00027 #ifndef FXOBJECT_H 00028 #include "FXObject.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 class FXUndoList; 00035 00036 00037 /// Base class for undoable commands 00038 class FXAPI FXCommand { 00039 friend class FXUndoList; 00040 private: 00041 FXCommand *next; 00042 private: 00043 FXCommand(const FXCommand&); 00044 FXCommand &operator=(const FXCommand&); 00045 protected: 00046 FXCommand():next(NULL){} 00047 public: 00048 00049 /** 00050 * Undo this command; this should save the 00051 * information for a subsequent redo. 00052 */ 00053 virtual void undo() = 0; 00054 00055 /** 00056 * Redo this command; this should save the 00057 * information for a subsequent undo. 00058 */ 00059 virtual void redo() = 0; 00060 00061 /** 00062 * Return the size of the information in the undo record. 00063 * The undo list may be trimmed to limit memory usage to 00064 * a certain limit. 00065 */ 00066 virtual FXuint size() const = 0; 00067 00068 /** 00069 * Name of the undo command to be shown on a button; 00070 * for example, "Undo Delete". 00071 */ 00072 virtual FXString undoName() const = 0; 00073 00074 /** 00075 * Name of the redo command to be shown on a button; 00076 * for example, "Redo Delete". 00077 */ 00078 virtual FXString redoName() const = 0; 00079 00080 /// Delete undo command 00081 virtual ~FXCommand(){} 00082 }; 00083 00084 00085 /** 00086 * The Undo List class manages a list of undoable commands. 00087 */ 00088 class FXAPI FXUndoList : public FXObject { 00089 FXDECLARE(FXUndoList) 00090 private: 00091 FXCommand *redolist; // List yet to be done from this point 00092 FXCommand *undolist; // List which has been done from this point 00093 FXint marker; // Marker value 00094 FXint count; // Number of undo records 00095 FXuint size; // Size of undo records 00096 public: 00097 long onCmdUndo(FXObject*,FXSelector,void*); 00098 long onUpdUndo(FXObject*,FXSelector,void*); 00099 long onCmdRedo(FXObject*,FXSelector,void*); 00100 long onUpdRedo(FXObject*,FXSelector,void*); 00101 long onCmdClear(FXObject*,FXSelector,void*); 00102 long onUpdClear(FXObject*,FXSelector,void*); 00103 long onCmdRevert(FXObject*,FXSelector,void*); 00104 long onUpdRevert(FXObject*,FXSelector,void*); 00105 long onCmdUndoAll(FXObject*,FXSelector,void*); 00106 long onCmdRedoAll(FXObject*,FXSelector,void*); 00107 public: 00108 enum{ 00109 ID_CLEAR=FXWindow::ID_LAST, 00110 ID_REVERT, 00111 ID_UNDO, 00112 ID_REDO, 00113 ID_UNDO_ALL, 00114 ID_REDO_ALL, 00115 ID_LAST 00116 }; 00117 public: 00118 00119 /// Make new empty undo list, initially unmarked. 00120 FXUndoList(); 00121 00122 /// Cut the redo list 00123 void cut(); 00124 00125 /// Add new command, executing if desired 00126 FXbool add(FXCommand* command,FXbool doit=FALSE); 00127 00128 /// Undo last command 00129 FXbool undo(); 00130 00131 /// Redo next command 00132 FXbool redo(); 00133 00134 /// Undo all commands 00135 FXbool undoAll(); 00136 00137 /// Redo all commands 00138 FXbool redoAll(); 00139 00140 /// Revert to marked 00141 FXbool revert(); 00142 00143 /// Can we undo more commands 00144 FXbool canUndo() const; 00145 00146 /// Can we redo more commands 00147 FXbool canRedo() const; 00148 00149 /// Can revert to marked 00150 FXbool canRevert() const; 00151 00152 /// Current undo command 00153 FXCommand* current() const { return undolist; } 00154 00155 /// Number of undo records 00156 FXint undoCount() const { return count; } 00157 00158 /// Size of undo information 00159 FXuint undoSize() const { return size; } 00160 00161 /// Clear list, and unmark all states. 00162 void clear(); 00163 00164 /// Trim undo list down to at most nc commands 00165 void trimCount(FXint nc); 00166 00167 /// Trim undo list down to at most size sz 00168 void trimSize(FXuint sz); 00169 00170 /** 00171 * Mark the current state of the undo list, which is initially unmarked. 00172 * There can be only one active mark at any time. 00173 */ 00174 void mark(); 00175 00176 /** 00177 * Unmark all states in the undo list. 00178 */ 00179 void unmark(); 00180 00181 /** 00182 * Check if the current state was marked, if the application has returned 00183 * to the previously marked state. 00184 */ 00185 FXbool marked() const; 00186 00187 /// Clean up 00188 ~FXUndoList(); 00189 }; 00190 00191 } 00192 00193 #endif