FXUndoList.h

Go to the documentation of this file.
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,2006 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.38 2006/01/22 17:58:12 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 class FXCommandGroup;
00036 
00037 
00044 class FXAPI FXCommand : public FXObject {
00045   FXDECLARE_ABSTRACT(FXCommand)
00046   friend class FXUndoList;
00047   friend class FXCommandGroup;
00048 private:
00049   FXCommand *next;
00050 private:
00051   FXCommand(const FXCommand&);
00052   FXCommand &operator=(const FXCommand&);
00053 protected:
00054   FXCommand():next(NULL){}
00055 public:
00056 
00061   virtual void undo() = 0;
00062 
00067   virtual void redo() = 0;
00068 
00076   virtual FXuint size() const;
00077 
00082   virtual FXString undoName() const;
00083 
00088   virtual FXString redoName() const;
00089 
00096   virtual bool canMerge() const;
00097 
00103   virtual bool mergeWith(FXCommand* command);
00104 
00106   virtual ~FXCommand(){}
00107   };
00108 
00109 
00110 
00117 class FXAPI FXCommandGroup : public FXCommand {
00118   FXDECLARE(FXCommandGroup)
00119   friend class FXUndoList;
00120 private:
00121   FXCommand      *undolist;
00122   FXCommand      *redolist;
00123   FXCommandGroup *group;
00124 private:
00125   FXCommandGroup(const FXCommandGroup&);
00126   FXCommandGroup &operator=(const FXCommandGroup&);
00127 public:
00128 
00130   FXCommandGroup():undolist(NULL),redolist(NULL),group(NULL){}
00131 
00133   bool empty(){ return !undolist; }
00134 
00136   virtual void undo();
00137 
00139   virtual void redo();
00140 
00142   virtual FXuint size() const;
00143 
00145   virtual ~FXCommandGroup();
00146   };
00147 
00148 
00149 
00153 class FXAPI FXUndoList : public FXCommandGroup {
00154   FXDECLARE(FXUndoList)
00155 private:
00156   FXint      undocount;     // Number of undo records
00157   FXint      redocount;     // Number of redo records
00158   FXint      marker;        // Marker value
00159   FXuint     space;         // Space taken up by all the undo records
00160   bool       working;       // Currently busy with undo or redo
00161 private:
00162   FXUndoList(const FXUndoList&);
00163   FXUndoList &operator=(const FXUndoList&);
00164 public:
00165   long onCmdUndo(FXObject*,FXSelector,void*);
00166   long onUpdUndo(FXObject*,FXSelector,void*);
00167   long onCmdRedo(FXObject*,FXSelector,void*);
00168   long onUpdRedo(FXObject*,FXSelector,void*);
00169   long onCmdClear(FXObject*,FXSelector,void*);
00170   long onUpdClear(FXObject*,FXSelector,void*);
00171   long onCmdRevert(FXObject*,FXSelector,void*);
00172   long onUpdRevert(FXObject*,FXSelector,void*);
00173   long onCmdUndoAll(FXObject*,FXSelector,void*);
00174   long onCmdRedoAll(FXObject*,FXSelector,void*);
00175   long onUpdUndoCount(FXObject*,FXSelector,void*);
00176   long onUpdRedoCount(FXObject*,FXSelector,void*);
00177 public:
00178   enum{
00179     ID_CLEAR=FXWindow::ID_LAST,
00180     ID_REVERT,
00181     ID_UNDO,
00182     ID_REDO,
00183     ID_UNDO_ALL,
00184     ID_REDO_ALL,
00185     ID_UNDO_COUNT,
00186     ID_REDO_COUNT,
00187     ID_LAST
00188     };
00189 public:
00190 
00194   FXUndoList();
00195 
00200   void cut();
00201 
00211   void add(FXCommand* command,bool doit=false,bool merge=true);
00212 
00219   void begin(FXCommandGroup *command);
00220 
00227   void end();
00228 
00234   void abort();
00235 
00239   virtual void undo();
00240 
00244   virtual void redo();
00245 
00247   void undoAll();
00248 
00250   void redoAll();
00251 
00253   void revert();
00254 
00256   bool canUndo() const;
00257 
00259   bool canRedo() const;
00260 
00262   bool canRevert() const;
00263 
00269   bool busy() const { return working; }
00270 
00272   FXCommand* current() const { return undolist; }
00273 
00278   virtual FXString undoName() const;
00279 
00284   virtual FXString redoName() const;
00285 
00287   FXint undoCount() const { return undocount; }
00288 
00290   FXint redoCount() const { return redocount; }
00291 
00293   virtual FXuint size() const;
00294 
00299   void clear();
00300 
00306   void trimCount(FXint nc);
00307 
00313   void trimSize(FXuint sz);
00314 
00321   void mark();
00322 
00326   void unmark();
00327 
00332   bool marked() const;
00333   };
00334 
00335 
00336 }
00337 
00338 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:25 2009 for TnFOX by doxygen v1.4.7