// @(#)root/treeviewer:$Id$
//Author : Andrei Gheata   16/08/00

/*************************************************************************
 * 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_TTreeViewer
#define ROOT_TTreeViewer

////////////////////////////////////////////////////
//                                                //
// TTreeViewer - A GUI oriented tree viewer       //
//                                                //
////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif

class TTreeViewer;
class TTVLVContainer;
class TTVLVEntry;
class TTVSession;
class TGSelectBox;
class TTree;
class TBranch;
class TContextMenu;
class TList;
class TGPicture;
class TTimer;
class TGLayoutHints;
class TGMenuBar;
class TGPopupMenu;
class TGToolBar;
class TGLabel;
class TGCheckButton;
class TGComboBox;
class TGTextButton;
class TGTextEntry;
class TGDoubleVSlider;
class TGPictureButton;
class TGStatusBar;
class TGCanvas;
class TGListTree;
class TGListTreeItem;
class TGListView;
class TGHProgressBar;
class TGButton;


class TTreeViewer : public TGMainFrame {

friend class TGClient;
friend class TGButton;

public:
   //---- item types used as user data
   enum EListItemType {
      kLTNoType            = 0,
      kLTPackType          = BIT(0),
      kLTTreeType          = BIT(1),
      kLTBranchType        = BIT(2),
      kLTLeafType          = BIT(3),
      kLTActionType        = BIT(4),
      kLTDragType          = BIT(5),
      kLTExpressionType    = BIT(6),
      kLTCutType           = BIT(7)
   };

private:
   TTree                *fTree;                 // selected tree
   TTVSession           *fSession;              // current tree-viewer session
   const char           *fFilename;             // name of the file containing the tree
   const char           *fSourceFile;           // name of the C++ source file - default treeviewer.C
   TString              fLastOption;            // last graphic option
   TTree                *fMappedTree;           // listed tree
   TBranch              *fMappedBranch;         // listed branch
   Int_t                fDimension;             // histogram dimension
   Bool_t               fVarDraw;               // true if an item is double-clicked
   Bool_t               fScanMode;              // flag activated when Scan Box is double-clicked
   TContextMenu         *fContextMenu;          // context menu for tree viewer
   TGSelectBox          *fDialogBox;            // expression editor
   TList                *fTreeList;             // list of mapped trees
   Int_t                fTreeIndex;             // index of current tree in list
   const TGPicture      *fPicX, *fPicY, *fPicZ; // pictures for X, Y and Z expressions
   const TGPicture      *fPicDraw, *fPicStop;   // pictures for Draw/Stop buttons
   const TGPicture      *fPicRefr;              // pictures for Refresh buttons //ia
   Cursor_t             fDefaultCursor;         // default cursor
   Cursor_t             fWatchCursor;           // watch cursor
   TTimer               *fTimer;                // tree viewer timer
   Bool_t               fCounting;              // true if timer is counting
   Bool_t               fStopMapping;           // true if branch don't need remapping
   Bool_t               fEnableCut;             // true if cuts are enabled
   Int_t                fNexpressions;          // number of expression widgets
// menu bar, menu bar entries and layouts
   TGLayoutHints        *fMenuBarLayout;
   TGLayoutHints        *fMenuBarItemLayout;
   TGLayoutHints        *fMenuBarHelpLayout;
   TGMenuBar            *fMenuBar;
   TGPopupMenu          *fFileMenu;
   TGPopupMenu          *fEditMenu;
   TGPopupMenu          *fRunMenu;
   TGPopupMenu          *fOptionsMenu;
   TGPopupMenu          *fOptionsGen;
   TGPopupMenu          *fOptions1D;
   TGPopupMenu          *fOptions2D;
   TGPopupMenu          *fHelpMenu;
// toolbar and hints
   TGToolBar            *fToolBar;
   TGLayoutHints        *fBarLayout;
// widgets on the toolbar
   TGLabel              *fBarLbl1;      // label of command text entry
   TGLabel              *fBarLbl2;      // label of option text entry
   TGLabel              *fBarLbl3;      // label of histogram name text entry
   TGCheckButton        *fBarH;         // checked for drawing current histogram with different graphic option
   TGCheckButton        *fBarScan;      // checked for tree scan
   TGCheckButton        *fBarRec;       // command recording toggle
   TGTextEntry          *fBarCommand;   // user command entry
   TGTextEntry          *fBarOption;    // histogram drawing option entry
   TGTextEntry          *fBarHist;      // histogram name entry
// frames
   TGHorizontalFrame    *fHf;           // main horizontal frame
   TGDoubleVSlider      *fSlider;       // vertical slider to select processed tree entries;
   TGVerticalFrame      *fV1;           // list tree mother
   TGVerticalFrame      *fV2;           // list view mother
   TGCompositeFrame     *fTreeHdr;      // header for list tree
   TGCompositeFrame     *fListHdr;      // header for list view
   TGLabel              *fLbl1;         // label for list tree
   TGLabel              *fLbl2;         // label for list view
   TGHorizontalFrame    *fBFrame;       // button frame
   TGHorizontalFrame    *fHpb;          // progress bar frame
   TGHProgressBar       *fProgressBar;  // progress bar
   TGLabel              *fBLbl4;        // label for input list entry
   TGLabel              *fBLbl5;        // label for output list entry
   TGTextEntry          *fBarListIn;    // tree input event list name entry
   TGTextEntry          *fBarListOut;   // tree output event list name entry
   TGPictureButton      *fDRAW;         // DRAW button
   TGTextButton         *fSPIDER;       // SPIDER button
   TGPictureButton      *fSTOP;         // interrupt current command (not yet)
   TGPictureButton      *fREFR;         // REFRESH button  //ia
   TGStatusBar          *fStatusBar;    // status bar
   TGComboBox           *fCombo;        // combo box with session records
   TGPictureButton      *fBGFirst;
   TGPictureButton      *fBGPrevious;
   TGPictureButton      *fBGRecord;
   TGPictureButton      *fBGNext;
   TGPictureButton      *fBGLast;
   TGTextButton         *fReset;        // clear expression's entries
// ListTree
   TGCanvas             *fTreeView;     // ListTree canvas container
   TGListTree           *fLt;           // ListTree with file and tree items
// ListView
   TGListView           *fListView;     // ListView with branches and leaves
   TTVLVContainer       *fLVContainer;  // container for listview

   TList                *fWidgets;      // list of widgets to be deleted

private:
// private methods
   void          BuildInterface();
   const char   *Cut();
   Int_t         Dimension();
   const char   *EmptyBrackets(const char* name);
   const char   *Ex();
   const char   *Ey();
   const char   *Ez();
   const char   *En(Int_t n);
   void          MapBranch(TBranch *branch, const char *prefix="", TGListTreeItem *parent = 0, Bool_t listIt = kTRUE);
   void          MapOptions(Long_t parm1);
   void          MapTree(TTree *tree, TGListTreeItem *parent = 0, Bool_t listIt = kTRUE);
   void          SetFile();
   const char   *ScanList();
   void          SetParentTree(TGListTreeItem *item);
   void          DoError(int level, const char *location, const char *fmt, va_list va) const;

public:
   TTreeViewer(const char* treeName = 0);
   TTreeViewer(const TTree *tree);
   virtual       ~TTreeViewer();
// public methods
   void          AppendTree(TTree *tree);
   void          ActivateButtons(Bool_t first, Bool_t previous,
                                 Bool_t next , Bool_t last);
   virtual void  CloseWindow();
   virtual void  Delete(Option_t *) { }                          // *MENU*
   void          DoRefresh();
   void          EditExpression();
   void          Empty();
   void          EmptyAll();                                     // *MENU*
   void          ExecuteCommand(const char* command, Bool_t fast = kFALSE); // *MENU*
   void          ExecuteDraw();
   void          ExecuteSpider();
   TTVLVEntry   *ExpressionItem(Int_t index);
   TList        *ExpressionList();
   const char   *GetGrOpt();
   TTree        *GetTree() {return fTree;}
   Bool_t        HandleTimer(TTimer *timer);
   Bool_t        IsCutEnabled() {return fEnableCut;}
   Bool_t        IsScanRedirected();
   Int_t         MakeSelector(const char* selector = 0);         // *MENU*
   void          Message(const char* msg);
   void          NewExpression();                                // *MENU*
   void          PrintEntries();
   Long64_t      Process(const char* filename, Option_t *option="", Long64_t nentries=1000000000, Long64_t firstentry=0); // *MENU*
   Bool_t        ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
   void          RemoveItem();
   void          RemoveLastRecord();                             // *MENU*
   void          SaveSource(const char* filename="", Option_t *option="");            // *MENU*
   void          SetHistogramTitle(const char *title);
   void          SetCutMode(Bool_t enabled = kTRUE) {fEnableCut = enabled;}
   void          SetCurrentRecord(Long64_t entry);
   void          SetGrOpt(const char *option);
   void          SetNexpressions(Int_t expr);
   void          SetRecordName(const char *name);                // *MENU*
   void          SetScanFileName(const char *name="");           // *MENU*
   void          SetScanMode(Bool_t mode=kTRUE) {fScanMode = mode;}
   void          SetScanRedirect(Bool_t mode);
   void          SetSession(TTVSession *session);
   void          SetUserCode(const char *code, Bool_t autoexec=kTRUE); // *MENU*
   void          SetTree(TTree* tree);
   void          SetTreeName(const char* treeName);              // *MENU*
   Bool_t        SwitchTree(Int_t index);
   void          UpdateCombo();
   void          UpdateRecord(const char *name="new name");      // *MENU*

   ClassDef(TTreeViewer,0)  // A GUI oriented tree viewer
};

#endif
 TTreeViewer.h:1
 TTreeViewer.h:2
 TTreeViewer.h:3
 TTreeViewer.h:4
 TTreeViewer.h:5
 TTreeViewer.h:6
 TTreeViewer.h:7
 TTreeViewer.h:8
 TTreeViewer.h:9
 TTreeViewer.h:10
 TTreeViewer.h:11
 TTreeViewer.h:12
 TTreeViewer.h:13
 TTreeViewer.h:14
 TTreeViewer.h:15
 TTreeViewer.h:16
 TTreeViewer.h:17
 TTreeViewer.h:18
 TTreeViewer.h:19
 TTreeViewer.h:20
 TTreeViewer.h:21
 TTreeViewer.h:22
 TTreeViewer.h:23
 TTreeViewer.h:24
 TTreeViewer.h:25
 TTreeViewer.h:26
 TTreeViewer.h:27
 TTreeViewer.h:28
 TTreeViewer.h:29
 TTreeViewer.h:30
 TTreeViewer.h:31
 TTreeViewer.h:32
 TTreeViewer.h:33
 TTreeViewer.h:34
 TTreeViewer.h:35
 TTreeViewer.h:36
 TTreeViewer.h:37
 TTreeViewer.h:38
 TTreeViewer.h:39
 TTreeViewer.h:40
 TTreeViewer.h:41
 TTreeViewer.h:42
 TTreeViewer.h:43
 TTreeViewer.h:44
 TTreeViewer.h:45
 TTreeViewer.h:46
 TTreeViewer.h:47
 TTreeViewer.h:48
 TTreeViewer.h:49
 TTreeViewer.h:50
 TTreeViewer.h:51
 TTreeViewer.h:52
 TTreeViewer.h:53
 TTreeViewer.h:54
 TTreeViewer.h:55
 TTreeViewer.h:56
 TTreeViewer.h:57
 TTreeViewer.h:58
 TTreeViewer.h:59
 TTreeViewer.h:60
 TTreeViewer.h:61
 TTreeViewer.h:62
 TTreeViewer.h:63
 TTreeViewer.h:64
 TTreeViewer.h:65
 TTreeViewer.h:66
 TTreeViewer.h:67
 TTreeViewer.h:68
 TTreeViewer.h:69
 TTreeViewer.h:70
 TTreeViewer.h:71
 TTreeViewer.h:72
 TTreeViewer.h:73
 TTreeViewer.h:74
 TTreeViewer.h:75
 TTreeViewer.h:76
 TTreeViewer.h:77
 TTreeViewer.h:78
 TTreeViewer.h:79
 TTreeViewer.h:80
 TTreeViewer.h:81
 TTreeViewer.h:82
 TTreeViewer.h:83
 TTreeViewer.h:84
 TTreeViewer.h:85
 TTreeViewer.h:86
 TTreeViewer.h:87
 TTreeViewer.h:88
 TTreeViewer.h:89
 TTreeViewer.h:90
 TTreeViewer.h:91
 TTreeViewer.h:92
 TTreeViewer.h:93
 TTreeViewer.h:94
 TTreeViewer.h:95
 TTreeViewer.h:96
 TTreeViewer.h:97
 TTreeViewer.h:98
 TTreeViewer.h:99
 TTreeViewer.h:100
 TTreeViewer.h:101
 TTreeViewer.h:102
 TTreeViewer.h:103
 TTreeViewer.h:104
 TTreeViewer.h:105
 TTreeViewer.h:106
 TTreeViewer.h:107
 TTreeViewer.h:108
 TTreeViewer.h:109
 TTreeViewer.h:110
 TTreeViewer.h:111
 TTreeViewer.h:112
 TTreeViewer.h:113
 TTreeViewer.h:114
 TTreeViewer.h:115
 TTreeViewer.h:116
 TTreeViewer.h:117
 TTreeViewer.h:118
 TTreeViewer.h:119
 TTreeViewer.h:120
 TTreeViewer.h:121
 TTreeViewer.h:122
 TTreeViewer.h:123
 TTreeViewer.h:124
 TTreeViewer.h:125
 TTreeViewer.h:126
 TTreeViewer.h:127
 TTreeViewer.h:128
 TTreeViewer.h:129
 TTreeViewer.h:130
 TTreeViewer.h:131
 TTreeViewer.h:132
 TTreeViewer.h:133
 TTreeViewer.h:134
 TTreeViewer.h:135
 TTreeViewer.h:136
 TTreeViewer.h:137
 TTreeViewer.h:138
 TTreeViewer.h:139
 TTreeViewer.h:140
 TTreeViewer.h:141
 TTreeViewer.h:142
 TTreeViewer.h:143
 TTreeViewer.h:144
 TTreeViewer.h:145
 TTreeViewer.h:146
 TTreeViewer.h:147
 TTreeViewer.h:148
 TTreeViewer.h:149
 TTreeViewer.h:150
 TTreeViewer.h:151
 TTreeViewer.h:152
 TTreeViewer.h:153
 TTreeViewer.h:154
 TTreeViewer.h:155
 TTreeViewer.h:156
 TTreeViewer.h:157
 TTreeViewer.h:158
 TTreeViewer.h:159
 TTreeViewer.h:160
 TTreeViewer.h:161
 TTreeViewer.h:162
 TTreeViewer.h:163
 TTreeViewer.h:164
 TTreeViewer.h:165
 TTreeViewer.h:166
 TTreeViewer.h:167
 TTreeViewer.h:168
 TTreeViewer.h:169
 TTreeViewer.h:170
 TTreeViewer.h:171
 TTreeViewer.h:172
 TTreeViewer.h:173
 TTreeViewer.h:174
 TTreeViewer.h:175
 TTreeViewer.h:176
 TTreeViewer.h:177
 TTreeViewer.h:178
 TTreeViewer.h:179
 TTreeViewer.h:180
 TTreeViewer.h:181
 TTreeViewer.h:182
 TTreeViewer.h:183
 TTreeViewer.h:184
 TTreeViewer.h:185
 TTreeViewer.h:186
 TTreeViewer.h:187
 TTreeViewer.h:188
 TTreeViewer.h:189
 TTreeViewer.h:190
 TTreeViewer.h:191
 TTreeViewer.h:192
 TTreeViewer.h:193
 TTreeViewer.h:194
 TTreeViewer.h:195
 TTreeViewer.h:196
 TTreeViewer.h:197
 TTreeViewer.h:198
 TTreeViewer.h:199
 TTreeViewer.h:200
 TTreeViewer.h:201
 TTreeViewer.h:202
 TTreeViewer.h:203
 TTreeViewer.h:204
 TTreeViewer.h:205
 TTreeViewer.h:206
 TTreeViewer.h:207
 TTreeViewer.h:208
 TTreeViewer.h:209
 TTreeViewer.h:210
 TTreeViewer.h:211
 TTreeViewer.h:212
 TTreeViewer.h:213
 TTreeViewer.h:214
 TTreeViewer.h:215
 TTreeViewer.h:216
 TTreeViewer.h:217
 TTreeViewer.h:218
 TTreeViewer.h:219
 TTreeViewer.h:220
 TTreeViewer.h:221
 TTreeViewer.h:222
 TTreeViewer.h:223
 TTreeViewer.h:224
 TTreeViewer.h:225
 TTreeViewer.h:226
 TTreeViewer.h:227
 TTreeViewer.h:228
 TTreeViewer.h:229
 TTreeViewer.h:230
 TTreeViewer.h:231
 TTreeViewer.h:232
 TTreeViewer.h:233
 TTreeViewer.h:234