// @(#)root/gui:$Id$
// Author: Fons Rademakers   11/01/98

/*************************************************************************
 * 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_TGCanvas
#define ROOT_TGCanvas


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGCanvas and TGViewPort and TGContainer                              //
//                                                                      //
// A TGCanvas is a frame containing two scrollbars (horizontal and      //
// vertical) and a viewport. The viewport acts as the window through    //
// which we look at the contents of the container frame.                //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

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

class TGHScrollBar;
class TGVScrollBar;
class TGClient;
class TGViewPort;
class TGCanvas;
class TGFrameElement;
class TGContainerTimer;
class TGContainerKeyboardTimer;
class TGContainerScrollTimer;
class TGListView;
class TGPicture;
class TGRectangle;

class TGContainer : public TGCompositeFrame {

friend class TGViewPort;
friend class TGCanvas;
friend class TGContainerKeyboardTimer;
friend class TGContainerScrollTimer;
friend class TGListView;

protected:
   TGViewPort        *fViewPort;      // container viewport
   TGCanvas          *fCanvas;        // pointer to canvas
   const TGWindow    *fMsgWindow;     // window handling container messages
   TGFrameElement    *fLastActiveEl;  // last active item
   Int_t              fXp, fYp;       // previous pointer position
   Int_t              fX0, fY0;       // corner of rubber band box
   Int_t              fXf, fYf;       // other corner of rubber band box
   Bool_t             fDragging;      // true if in dragging mode
   Int_t              fTotal;         // total items
   Int_t              fSelected;      // number of selected items
   TTimer            *fScrollTimer;   // autoscroll timer
   Bool_t             fOnMouseOver;   // kTRUE when mouse pointer is over entry
   Bool_t             fLastDir;       // direction of last search
   Bool_t             fLastCase;      // case sensetivity of last search
   Bool_t             fLastSubstring; // substring search option of last search
   TString            fLastName;      // the name of object of last search
   TTimer            *fKeyTimer;      // keyboard timer
   TString            fKeyInput;      // keyboard input (buffer)
   Bool_t             fKeyTimerActive;// kTRUE - keyboard timer is active
   Bool_t             fScrolling;     // kTRUE - when scrolling is ON
   Int_t              fXDND, fYDND;
   Bool_t             fBdown;
   TGRectangle        fExposedRegion; // exposed area

   static TGGC       *fgLineGC;
   static const TGGC &GetLineGC();

   virtual void DoRedraw();
   virtual void ActivateItem(TGFrameElement* el);
   virtual void DeActivateItem(TGFrameElement* el);
   virtual void SearchPattern();
   virtual void OnAutoScroll();
   virtual void RepeatSearch();

private:
   TGContainer(const TGContainer&);               // not implemented
   TGContainer& operator=(const TGContainer&);    // not implemented

public:
   TGContainer(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
               UInt_t options = kSunkenFrame,
               Pixel_t back = GetDefaultFrameBackground());
   TGContainer(TGCanvas *p,UInt_t options = kSunkenFrame,
               Pixel_t back = GetDefaultFrameBackground());

   virtual ~TGContainer();

   virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
   virtual void ClearViewPort();
   virtual void Associate(const TGWindow *w) { fMsgWindow = w; }
   virtual void AdjustPosition();
   virtual void SetPagePosition(const TGPosition& pos);
   virtual void SetPagePosition(Int_t x, Int_t y);
   virtual void SetPageDimension(const TGDimension& dim);
   virtual void SetPageDimension(UInt_t w, UInt_t h);
   virtual void RemoveAll();
   virtual void RemoveItem(TGFrame *item);
   virtual void Layout();

   TGCanvas         *GetCanvas() const { return fCanvas; }
   const TGWindow   *GetMessageWindow() const { return fMsgWindow; }
   virtual TGPosition   GetPagePosition() const;
   virtual TGDimension  GetPageDimension() const;

   virtual Int_t  NumSelected() const { return fSelected; }
   virtual Int_t  NumItems() const { return fTotal; }
   virtual TGFrameElement *FindFrame(Int_t x,Int_t y,Bool_t exclude=kTRUE);
   virtual TGFrame        *FindFrameByName(const char *name);
   virtual TGHScrollBar *GetHScrollbar() const;
   virtual TGVScrollBar *GetVScrollbar() const;
   virtual void SetHsbPosition(Int_t newPos);
   virtual void SetVsbPosition(Int_t newPos);
   virtual void LineUp(Bool_t select = kFALSE);
   virtual void LineDown(Bool_t select = kFALSE);
   virtual void LineLeft(Bool_t select = kFALSE);
   virtual void LineRight(Bool_t select = kFALSE);
   virtual void PageUp(Bool_t select = kFALSE);
   virtual void PageDown(Bool_t select = kFALSE);
   virtual void Home(Bool_t select = kFALSE);
   virtual void End(Bool_t select = kFALSE);
   virtual void Search(Bool_t close = kTRUE);
   virtual void *FindItem(const TString& name,
                          Bool_t direction = kTRUE,
                          Bool_t caseSensitive = kTRUE,
                          Bool_t subString = kFALSE);

   virtual const TGFrame *GetNextSelected(void **current);
   virtual TGFrame *GetLastActive() const { return fLastActiveEl ? fLastActiveEl->fFrame : 0; }
   virtual void SavePrimitive(std::ostream &out, Option_t *option = "");

   virtual Bool_t HandleDNDFinished() { fBdown = kFALSE; return kTRUE; }
   virtual Bool_t HandleExpose(Event_t *event);
   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleDoubleClick(Event_t *event);
   virtual Bool_t HandleMotion(Event_t *event);
   virtual Bool_t HandleKey(Event_t *event);

   const TGPicture *GetObjPicture(TGFrame *f);
   virtual void SetDragPixmap(const TGPicture *pic);

   virtual void SelectAll();                    //*SIGNAL*
   virtual void UnSelectAll();                  //*SIGNAL*
   virtual void InvertSelection();              //*SIGNAL*
   virtual void ReturnPressed(TGFrame*);        //*SIGNAL*
   virtual void SpacePressed(TGFrame*);         //*SIGNAL*
   virtual void KeyPressed(TGFrame*, UInt_t keysym, UInt_t mask); //*SIGNAL*
   virtual void OnMouseOver(TGFrame*);          //*SIGNAL*
   virtual void CurrentChanged(Int_t x,Int_t y);//*SIGNAL*
   virtual void CurrentChanged(TGFrame* f);     //*SIGNAL*
   virtual void Clicked(TGFrame *f, Int_t btn); //*SIGNAL*
   virtual void DoubleClicked(TGFrame *f, Int_t btn);  //*SIGNAL*
   virtual void DoubleClicked(TGFrame *f, Int_t btn, Int_t x, Int_t y); //*SIGNAL*
   virtual void Clicked(TGFrame *f, Int_t btn, Int_t x, Int_t y);       //*SIGNAL*

   ClassDef(TGContainer,0)  // Canvas container
};


class TGViewPort : public TGCompositeFrame {

protected:
   Int_t       fX0, fY0;     // position of container frame in viewport
   TGFrame    *fContainer;   // container frame

private:
   TGViewPort(const TGViewPort&);             // not implemented
   TGViewPort& operator=(const TGViewPort&);  // not implemented

public:
   TGViewPort(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
              UInt_t options = kChildFrame,
              Pixel_t back = GetDefaultFrameBackground());

   TGFrame *GetContainer() const { return fContainer; }
   void SetContainer(TGFrame *f);

   virtual void DrawBorder() { };
   virtual void Layout() { }
   virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }

   virtual void SetHPos(Int_t xpos);
   virtual void SetVPos(Int_t ypos);
   void SetPos(Int_t xpos, Int_t ypos);

   Int_t GetHPos() const { return fX0; }
   Int_t GetVPos() const { return fY0; }
   virtual Bool_t HandleConfigureNotify(Event_t *event);

   ClassDef(TGViewPort,0)  // Viewport through which to look at a container frame
};


class TGCanvas : public TGFrame {

protected:
   TGViewPort      *fVport;        // viewport through which we look at contents
   TGHScrollBar    *fHScrollbar;   // horizontal scrollbar
   TGVScrollBar    *fVScrollbar;   // vertical scrollbar
   Int_t            fScrolling;    // flag which scrolling modes are allowed

private:
   TGCanvas(const TGCanvas&);              // not implemented
   TGCanvas& operator=(const TGCanvas&);   // not implemented

public:
   enum { kCanvasNoScroll         = 0,
          kCanvasScrollHorizontal = BIT(0),
          kCanvasScrollVertical   = BIT(1),
          kCanvasScrollBoth       = (kCanvasScrollHorizontal | kCanvasScrollVertical)
   };

   TGCanvas(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
            UInt_t options = kSunkenFrame | kDoubleBorder,
            Pixel_t back = GetDefaultFrameBackground());
   virtual ~TGCanvas();

   TGFrame      *GetContainer() const { return fVport->GetContainer(); }
   TGViewPort   *GetViewPort() const { return fVport; }
   TGHScrollBar *GetHScrollbar() const { return fHScrollbar; }
   TGVScrollBar *GetVScrollbar() const { return fVScrollbar; }

   virtual void  AddFrame(TGFrame *f, TGLayoutHints *l = 0);
   virtual void  SetContainer(TGFrame *f) { fVport->SetContainer(f); }
   virtual void  MapSubwindows();
   virtual void  DrawBorder();
   virtual void  Layout();
   virtual void  ClearViewPort();
   virtual Int_t GetHsbPosition() const;
   virtual Int_t GetVsbPosition() const;
   virtual void  SetHsbPosition(Int_t newPos);
   virtual void  SetVsbPosition(Int_t newPos);
   void          SetScrolling(Int_t scrolling);
   Int_t         GetScrolling() const { return fScrolling; }

   virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

   virtual void SavePrimitive(std::ostream &out, Option_t *option = "");

   ClassDef(TGCanvas,0)  // A canvas with two scrollbars and a viewport
};


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