TQCommand.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TQCommand.h 25128 2008-08-12 17:59:19Z pcanal $
00002 // Author: Valeriy Onuchin   04/27/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TQCommand
00013 #define ROOT_TQCommand
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TQCommand, TQUndoManager - support for multiple Undo/Redo operations //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #ifndef ROOT_TList
00022 #include "TList.h"
00023 #endif
00024 
00025 #ifndef ROOT_TQObject
00026 #include "TQObject.h"
00027 #endif
00028 
00029 class TQCommand : public TList, public TQObject {
00030 
00031 friend class TQUndoManager;
00032 
00033 protected:
00034    TQConnection  *fRedo;      // do/redo action
00035    TQConnection  *fUndo;      // undo action
00036    Long_t        *fRedoArgs;  // redo values
00037    Long_t        *fUndoArgs;  // undo values
00038    Int_t          fNRargs;    // number of redo arguments
00039    Int_t          fNUargs;    // number of undo arguments
00040    Int_t          fState;     // -1 undoing on, 1 redoing on, 0 nothing in progress
00041    Int_t          fStatus;    // fStatus++ after Redo(), fStatus-- after Undo()
00042    Bool_t         fNewDelete; // kTRUE if Redo/Undo methods are new/delete
00043    TString        fName;      // command name. Default is "ClassName::RedoName(args)"
00044    TString        fTitle;     // command description
00045    void          *fObject;    // object to which undo/redo actions applied
00046 
00047    virtual void Init(const char *cl, void *object,
00048                      const char *redo, const char *undo);
00049    virtual void PrintCollectionHeader(Option_t* option) const;
00050 
00051 public:
00052    TQCommand(const char *cl = 0, void *object = 0,
00053              const char *redo = 0, const char *undo = 0);
00054    TQCommand(TObject *obj, const char *redo = 0, const char *undo = 0);
00055    TQCommand(const TQCommand &com);
00056    virtual ~TQCommand();
00057 
00058    virtual void   Redo(Option_t *option="");  //*SIGNAL*
00059    virtual void   Undo(Option_t *option="");  //*SIGNAL*
00060    virtual void   SetArgs(Int_t nargs, ...);
00061    virtual void   SetUndoArgs(Int_t nargs, ...);
00062    virtual void   SetRedoArgs(Int_t nargs, ...);
00063    virtual Bool_t CanMerge(TQCommand *c) const;
00064    virtual void   Merge(TQCommand *c);
00065    virtual Bool_t CanCompress(TQCommand *c) const;
00066    virtual void   Compress(TQCommand *c);
00067    virtual Bool_t IsEqual(const TObject* obj) const;
00068    virtual Bool_t IsSetter() const;
00069    virtual Bool_t CanRedo() const;
00070    virtual Bool_t CanUndo() const;
00071    const char    *GetRedoName() const;
00072    const char    *GetUndoName() const;
00073    TQConnection  *GetRedo() const { return fRedo; }
00074    TQConnection  *GetUndo() const { return fUndo; }
00075    Long_t        *GetRedoArgs() const;
00076    Long_t        *GetUndoArgs() const;
00077    Int_t          GetNRargs() const;
00078    Int_t          GetNUargs() const;
00079    void          *GetObject() const;
00080    Int_t          GetStatus() const;
00081    Bool_t         IsMacro() const;
00082    Bool_t         IsUndoing() const;
00083    Bool_t         IsRedoing() const;
00084    Bool_t         IsExecuting() const;
00085    virtual void   SetName(const char *name);
00086    virtual void   SetTitle(const char *title);
00087    virtual void   ls(Option_t *option="") const;
00088    virtual void   Add(TObject *obj, Option_t *opt);
00089    virtual void   Add(TObject *obj) { Add(obj, 0); }
00090    virtual void   Delete(Option_t *option="");
00091    virtual const char *GetName() const;
00092    virtual const char *GetTitle() const;
00093 
00094    static TQCommand *GetCommand();
00095 
00096    ClassDef(TQCommand,0) // encapsulates the information for undo/redo a single action.
00097 };
00098 
00099 
00100 //////////////////////////////////////////////////////////////////////////
00101 class TQUndoManager : public TQCommand {
00102 
00103 protected:
00104    TObjLink   *fCursor;  // current position in history stack
00105    TQCommand  *fCurrent; // the latest executed command
00106    UInt_t      fLimit;   // maximum number of commands can be located in stack
00107    TList      *fLogBook; // listing of all actions during execution
00108    Bool_t      fLogging; // kTRUE if logging is ON
00109 
00110    virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
00111 
00112 public:
00113    TQUndoManager();
00114    virtual ~TQUndoManager();
00115 
00116    virtual void   Add(TObject *obj, Option_t *opt);
00117    virtual void   Add(TObject *obj) { Add(obj, 0); }
00118    virtual void   Redo(Option_t *option="");
00119    virtual void   Undo(Option_t *option="");
00120    virtual Bool_t CanRedo() const;
00121    virtual Bool_t CanUndo() const;
00122    virtual void   SetLogging(Bool_t on = kTRUE);
00123    Bool_t         IsLogging() const;
00124    TQCommand     *GetCurrent() const;
00125    TQCommand     *GetCursor() const;
00126    UInt_t         GetLimit() const;
00127    virtual void   SetLimit(UInt_t limit);
00128    virtual void   CurrentChanged(TQCommand *c); //*SIGNAL*
00129    virtual void   ls(Option_t *option="") const;
00130 
00131    ClassDef(TQUndoManager,0) // recorder of operations for undo and redo
00132 };
00133 
00134 #endif

Generated on Tue Jul 5 14:10:29 2011 for ROOT_528-00b_version by  doxygen 1.5.1