Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:57:49

0001 // @(#)root/base:$Id$
0002 // Author: Valeriy Onuchin   04/27/2004
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TQCommand
0013 #define ROOT_TQCommand
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TQCommand, TQUndoManager - support for multiple Undo/Redo operations //
0018 //                                                                      //
0019 //////////////////////////////////////////////////////////////////////////
0020 
0021 #include "TList.h"
0022 
0023 #include "TQObject.h"
0024 
0025 class TQConnection;
0026 
0027 class TQCommand : public TList, public TQObject {
0028 
0029 friend class TQUndoManager;
0030 
0031 protected:
0032    TQConnection  *fRedo;      // do/redo action
0033    TQConnection  *fUndo;      // undo action
0034    Long_t        *fRedoArgs;  // redo values
0035    Long_t        *fUndoArgs;  // undo values
0036    Int_t          fNRargs;    // number of redo arguments
0037    Int_t          fNUargs;    // number of undo arguments
0038    Int_t          fState;     // -1 undoing on, 1 redoing on, 0 nothing in progress
0039    Int_t          fStatus;    // fStatus++ after Redo(), fStatus-- after Undo()
0040    Bool_t         fNewDelete; // kTRUE if Redo/Undo methods are new/delete
0041    TString        fName;      // command name. Default is "ClassName::RedoName(args)"
0042    TString        fTitle;     // command description
0043    void          *fObject;    // object to which undo/redo actions applied
0044 
0045    virtual void Init(const char *cl, void *object,
0046                      const char *redo, const char *undo);
0047    void PrintCollectionHeader(Option_t* option) const override;
0048 
0049 private:
0050    TQCommand &operator=(const TQCommand &); // Not yet implemented.
0051 
0052 public:
0053    TQCommand(const char *cl = nullptr, void *object = nullptr,
0054              const char *redo = nullptr, const char *undo = nullptr);
0055    TQCommand(TObject *obj, const char *redo = nullptr, const char *undo = nullptr);
0056    TQCommand(const TQCommand &com);
0057    virtual ~TQCommand();
0058 
0059    virtual void   Redo(Option_t *option="");  //*SIGNAL*
0060    virtual void   Undo(Option_t *option="");  //*SIGNAL*
0061    virtual void   SetArgs(Int_t nargs, ...);
0062    virtual void   SetUndoArgs(Int_t nargs, ...);
0063    virtual void   SetRedoArgs(Int_t nargs, ...);
0064    virtual Bool_t CanMerge(TQCommand *c) const;
0065    virtual void   Merge(TQCommand *c);
0066    virtual Long64_t Merge(TCollection*,TFileMergeInfo*);
0067    virtual Bool_t CanCompress(TQCommand *c) const;
0068    virtual void   Compress(TQCommand *c);
0069    Bool_t         IsEqual(const TObject* obj) const override;
0070    virtual Bool_t IsSetter() const;
0071    virtual Bool_t CanRedo() const;
0072    virtual Bool_t CanUndo() const;
0073    const char    *GetRedoName() const;
0074    const char    *GetUndoName() const;
0075    TQConnection  *GetRedo() const { return fRedo; }
0076    TQConnection  *GetUndo() const { return fUndo; }
0077    Long_t        *GetRedoArgs() const;
0078    Long_t        *GetUndoArgs() const;
0079    Int_t          GetNRargs() const;
0080    Int_t          GetNUargs() const;
0081    void          *GetObject() const;
0082    Int_t          GetStatus() const;
0083    Bool_t         IsMacro() const;
0084    Bool_t         IsUndoing() const;
0085    Bool_t         IsRedoing() const;
0086    Bool_t         IsExecuting() const;
0087    virtual void   SetName(const char *name);
0088    virtual void   SetTitle(const char *title);
0089    void           ls(Option_t *option="") const override;
0090    void           Add(TObject *obj, Option_t *opt) override;
0091    void           Add(TObject *obj) override { Add(obj, nullptr); }
0092    void           Delete(Option_t *option="") override;
0093    const char    *GetName() const override;
0094    const char    *GetTitle() const override;
0095 
0096    static TQCommand *GetCommand();
0097 
0098    ClassDefOverride(TQCommand,0) // encapsulates the information for undo/redo a single action.
0099 };
0100 
0101 
0102 //////////////////////////////////////////////////////////////////////////
0103 class TQUndoManager : public TQCommand {
0104 
0105 protected:
0106    TObjLink   *fCursor;  // current position in history stack
0107    TQCommand  *fCurrent; // the latest executed command
0108    UInt_t      fLimit;   // maximum number of commands can be located in stack
0109    TList      *fLogBook; // listing of all actions during execution
0110    Bool_t      fLogging; // kTRUE if logging is ON
0111 
0112    void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const override;
0113 
0114 public:
0115    TQUndoManager();
0116    virtual ~TQUndoManager();
0117 
0118    void           Add(TObject *obj, Option_t *opt) override;
0119    void           Add(TObject *obj) override { Add(obj, nullptr); }
0120    void           Redo(Option_t *option="") override;
0121    void           Undo(Option_t *option="") override;
0122    Bool_t         CanRedo() const override;
0123    Bool_t         CanUndo() const override;
0124    virtual void   SetLogging(Bool_t on = kTRUE);
0125    Bool_t         IsLogging() const;
0126    TQCommand     *GetCurrent() const;
0127    TQCommand     *GetCursor() const;
0128    UInt_t         GetLimit() const;
0129    virtual void   SetLimit(UInt_t limit);
0130    virtual void   CurrentChanged(TQCommand *c); //*SIGNAL*
0131    void           ls(Option_t *option="") const override;
0132 
0133    ClassDefOverride(TQUndoManager,0) // recorder of operations for undo and redo
0134 };
0135 
0136 #endif