ROOT logo
// @(#)root/base:$Id: TQCommand.h 25128 2008-08-12 17:59:19Z pcanal $
// Author: Valeriy Onuchin   04/27/2004

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TQCommand
#define ROOT_TQCommand

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TQCommand, TQUndoManager - support for multiple Undo/Redo operations //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TList
#include "TList.h"
#endif

#ifndef ROOT_TQObject
#include "TQObject.h"
#endif

class TQCommand : public TList, public TQObject {

friend class TQUndoManager;

protected:
   TQConnection  *fRedo;      // do/redo action
   TQConnection  *fUndo;      // undo action
   Long_t        *fRedoArgs;  // redo values
   Long_t        *fUndoArgs;  // undo values
   Int_t          fNRargs;    // number of redo arguments
   Int_t          fNUargs;    // number of undo arguments
   Int_t          fState;     // -1 undoing on, 1 redoing on, 0 nothing in progress
   Int_t          fStatus;    // fStatus++ after Redo(), fStatus-- after Undo()
   Bool_t         fNewDelete; // kTRUE if Redo/Undo methods are new/delete
   TString        fName;      // command name. Default is "ClassName::RedoName(args)"
   TString        fTitle;     // command description
   void          *fObject;    // object to which undo/redo actions applied

   virtual void Init(const char *cl, void *object,
                     const char *redo, const char *undo);
   virtual void PrintCollectionHeader(Option_t* option) const;

public:
   TQCommand(const char *cl = 0, void *object = 0,
             const char *redo = 0, const char *undo = 0);
   TQCommand(TObject *obj, const char *redo = 0, const char *undo = 0);
   TQCommand(const TQCommand &com);
   virtual ~TQCommand();

   virtual void   Redo(Option_t *option="");  //*SIGNAL*
   virtual void   Undo(Option_t *option="");  //*SIGNAL*
   virtual void   SetArgs(Int_t nargs, ...);
   virtual void   SetUndoArgs(Int_t nargs, ...);
   virtual void   SetRedoArgs(Int_t nargs, ...);
   virtual Bool_t CanMerge(TQCommand *c) const;
   virtual void   Merge(TQCommand *c);
   virtual Bool_t CanCompress(TQCommand *c) const;
   virtual void   Compress(TQCommand *c);
   virtual Bool_t IsEqual(const TObject* obj) const;
   virtual Bool_t IsSetter() const;
   virtual Bool_t CanRedo() const;
   virtual Bool_t CanUndo() const;
   const char    *GetRedoName() const;
   const char    *GetUndoName() const;
   TQConnection  *GetRedo() const { return fRedo; }
   TQConnection  *GetUndo() const { return fUndo; }
   Long_t        *GetRedoArgs() const;
   Long_t        *GetUndoArgs() const;
   Int_t          GetNRargs() const;
   Int_t          GetNUargs() const;
   void          *GetObject() const;
   Int_t          GetStatus() const;
   Bool_t         IsMacro() const;
   Bool_t         IsUndoing() const;
   Bool_t         IsRedoing() const;
   Bool_t         IsExecuting() const;
   virtual void   SetName(const char *name);
   virtual void   SetTitle(const char *title);
   virtual void   ls(Option_t *option="") const;
   virtual void   Add(TObject *obj, Option_t *opt);
   virtual void   Add(TObject *obj) { Add(obj, 0); }
   virtual void   Delete(Option_t *option="");
   virtual const char *GetName() const;
   virtual const char *GetTitle() const;

   static TQCommand *GetCommand();

   ClassDef(TQCommand,0) // encapsulates the information for undo/redo a single action.
};


//////////////////////////////////////////////////////////////////////////
class TQUndoManager : public TQCommand {

protected:
   TObjLink   *fCursor;  // current position in history stack
   TQCommand  *fCurrent; // the latest executed command
   UInt_t      fLimit;   // maximum number of commands can be located in stack
   TList      *fLogBook; // listing of all actions during execution
   Bool_t      fLogging; // kTRUE if logging is ON

   virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;

public:
   TQUndoManager();
   virtual ~TQUndoManager();

   virtual void   Add(TObject *obj, Option_t *opt);
   virtual void   Add(TObject *obj) { Add(obj, 0); }
   virtual void   Redo(Option_t *option="");
   virtual void   Undo(Option_t *option="");
   virtual Bool_t CanRedo() const;
   virtual Bool_t CanUndo() const;
   virtual void   SetLogging(Bool_t on = kTRUE);
   Bool_t         IsLogging() const;
   TQCommand     *GetCurrent() const;
   TQCommand     *GetCursor() const;
   UInt_t         GetLimit() const;
   virtual void   SetLimit(UInt_t limit);
   virtual void   CurrentChanged(TQCommand *c); //*SIGNAL*
   virtual void   ls(Option_t *option="") const;

   ClassDef(TQUndoManager,0) // recorder of operations for undo and redo
};

#endif
 TQCommand.h:1
 TQCommand.h:2
 TQCommand.h:3
 TQCommand.h:4
 TQCommand.h:5
 TQCommand.h:6
 TQCommand.h:7
 TQCommand.h:8
 TQCommand.h:9
 TQCommand.h:10
 TQCommand.h:11
 TQCommand.h:12
 TQCommand.h:13
 TQCommand.h:14
 TQCommand.h:15
 TQCommand.h:16
 TQCommand.h:17
 TQCommand.h:18
 TQCommand.h:19
 TQCommand.h:20
 TQCommand.h:21
 TQCommand.h:22
 TQCommand.h:23
 TQCommand.h:24
 TQCommand.h:25
 TQCommand.h:26
 TQCommand.h:27
 TQCommand.h:28
 TQCommand.h:29
 TQCommand.h:30
 TQCommand.h:31
 TQCommand.h:32
 TQCommand.h:33
 TQCommand.h:34
 TQCommand.h:35
 TQCommand.h:36
 TQCommand.h:37
 TQCommand.h:38
 TQCommand.h:39
 TQCommand.h:40
 TQCommand.h:41
 TQCommand.h:42
 TQCommand.h:43
 TQCommand.h:44
 TQCommand.h:45
 TQCommand.h:46
 TQCommand.h:47
 TQCommand.h:48
 TQCommand.h:49
 TQCommand.h:50
 TQCommand.h:51
 TQCommand.h:52
 TQCommand.h:53
 TQCommand.h:54
 TQCommand.h:55
 TQCommand.h:56
 TQCommand.h:57
 TQCommand.h:58
 TQCommand.h:59
 TQCommand.h:60
 TQCommand.h:61
 TQCommand.h:62
 TQCommand.h:63
 TQCommand.h:64
 TQCommand.h:65
 TQCommand.h:66
 TQCommand.h:67
 TQCommand.h:68
 TQCommand.h:69
 TQCommand.h:70
 TQCommand.h:71
 TQCommand.h:72
 TQCommand.h:73
 TQCommand.h:74
 TQCommand.h:75
 TQCommand.h:76
 TQCommand.h:77
 TQCommand.h:78
 TQCommand.h:79
 TQCommand.h:80
 TQCommand.h:81
 TQCommand.h:82
 TQCommand.h:83
 TQCommand.h:84
 TQCommand.h:85
 TQCommand.h:86
 TQCommand.h:87
 TQCommand.h:88
 TQCommand.h:89
 TQCommand.h:90
 TQCommand.h:91
 TQCommand.h:92
 TQCommand.h:93
 TQCommand.h:94
 TQCommand.h:95
 TQCommand.h:96
 TQCommand.h:97
 TQCommand.h:98
 TQCommand.h:99
 TQCommand.h:100
 TQCommand.h:101
 TQCommand.h:102
 TQCommand.h:103
 TQCommand.h:104
 TQCommand.h:105
 TQCommand.h:106
 TQCommand.h:107
 TQCommand.h:108
 TQCommand.h:109
 TQCommand.h:110
 TQCommand.h:111
 TQCommand.h:112
 TQCommand.h:113
 TQCommand.h:114
 TQCommand.h:115
 TQCommand.h:116
 TQCommand.h:117
 TQCommand.h:118
 TQCommand.h:119
 TQCommand.h:120
 TQCommand.h:121
 TQCommand.h:122
 TQCommand.h:123
 TQCommand.h:124
 TQCommand.h:125
 TQCommand.h:126
 TQCommand.h:127
 TQCommand.h:128
 TQCommand.h:129
 TQCommand.h:130
 TQCommand.h:131
 TQCommand.h:132
 TQCommand.h:133
 TQCommand.h:134