TGScrollBar.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGScrollBar.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Fons Rademakers   10/01/98
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_TGScrollBar
00013 #define ROOT_TGScrollBar
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGScrollBar and TGScrollBarElement                                   //
00019 //                                                                      //
00020 // The classes in this file implement scrollbars. Scrollbars can be     //
00021 // either placed horizontal or vertical. A scrollbar contains three     //
00022 // TGScrollBarElements: The "head", "tail" and "slider". The head and   //
00023 // tail are fixed at either end and have the typical arrows in them.    //
00024 //                                                                      //
00025 // The TGHScrollBar will generate the following event messages:         //
00026 // kC_HSCROLL, kSB_SLIDERPOS, position, 0                               //
00027 // kC_HSCROLL, kSB_SLIDERTRACK, position, 0                             //
00028 //                                                                      //
00029 // The TGVScrollBar will generate the following event messages:         //
00030 // kC_VSCROLL, kSB_SLIDERPOS, position, 0                               //
00031 // kC_VSCROLL, kSB_SLIDERTRACK, position, 0                             //
00032 //                                                                      //
00033 //////////////////////////////////////////////////////////////////////////
00034 
00035 #ifndef ROOT_TGButton
00036 #include "TGButton.h"
00037 #endif
00038 
00039 
00040 //--- scrollbar types
00041 
00042 enum EScrollBarMode {
00043    kSBHorizontal,
00044    kSBVertical
00045 };
00046 
00047 class TTimer;
00048 
00049 
00050 class TGScrollBarElement : public TGFrame {
00051 
00052 private:
00053    TGScrollBarElement(const TGScrollBarElement&); // Not implemented
00054    TGScrollBarElement& operator=(const TGScrollBarElement&); // Not implemented
00055 
00056 protected:
00057    Int_t            fState;  // state of scrollbar element (button up or down)
00058    const TGPicture *fPic;    // picture in scrollbar element
00059    const TGPicture *fPicN;   // picture for normal state of scrollbar element
00060    const TGPicture *fPicD;   // picture for disabled state of scrollbar element
00061 
00062 public:
00063    TGScrollBarElement(const TGWindow *p = 0, const TGPicture *pic = 0,
00064                       UInt_t w = 1, UInt_t h = 1,
00065                       UInt_t options = kRaisedFrame | kDoubleBorder,
00066                       Pixel_t back = GetDefaultFrameBackground());
00067    virtual ~TGScrollBarElement();
00068 
00069    virtual void SetState(Int_t state);
00070    virtual void DrawBorder();
00071    virtual void SetEnabled(Bool_t on = kTRUE);
00072    virtual Bool_t IsEnabled() const { return !(fState & kButtonDisabled); }
00073 
00074    ClassDef(TGScrollBarElement,0)  // Scrollbar element (head, tail, slider)
00075 };
00076 
00077 
00078 class TGScrollBar : public TGFrame, public TGWidget {
00079 
00080 private:
00081    TGScrollBar(const TGScrollBar&); // Not implemented
00082    TGScrollBar& operator=(const TGScrollBar&); // Not implemented
00083 
00084 protected:
00085    Int_t                fX0, fY0;      // current slider position in pixels
00086    Int_t                fXp, fYp;      // previous slider position in pixels
00087    Bool_t               fDragging;     // in dragging mode?
00088    Bool_t               fGrabPointer;  // grab pointer when dragging
00089    Int_t                fRange;        // logical upper range of scrollbar
00090    Int_t                fPsize;        // logical page size of scrollbar
00091    Int_t                fPos;          // logical current position
00092    Int_t                fSliderSize;   // logical slider size
00093    Int_t                fSliderRange;  // logical slider range
00094    Int_t                fSmallInc;     // Small Increment in the sliding algorithm
00095    TGScrollBarElement  *fHead;         // head button of scrollbar
00096    TGScrollBarElement  *fTail;         // tail button of scrollbar
00097    TGScrollBarElement  *fSlider;       // slider
00098    const TGPicture     *fHeadPic;      // picture in head (up or left arrow)
00099    const TGPicture     *fTailPic;      // picture in tail (down or right arrow)
00100    TTimer              *fRepeat;       // repeat rate timer (when mouse stays pressed)
00101    Window_t             fSubw;         // sub window in which mouse is pressed
00102    Bool_t               fAccelerated;  // kFALSE - normal, kTRUE - accelerated
00103 
00104    static Pixmap_t    fgBckgndPixmap;
00105    static Int_t       fgScrollBarWidth;
00106 
00107 public:
00108    static Pixmap_t  GetBckgndPixmap();
00109    static Int_t     GetScrollBarWidth();
00110 
00111    TGScrollBar(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
00112                UInt_t options = kChildFrame,
00113                Pixel_t back = GetDefaultFrameBackground());
00114    virtual ~TGScrollBar();
00115 
00116    void           GrabPointer(Bool_t grab) { fGrabPointer = grab; }
00117 
00118    virtual void   DrawBorder() { }
00119    virtual Bool_t HandleButton(Event_t *event) = 0;
00120    virtual Bool_t HandleMotion(Event_t *event) = 0;
00121    virtual Bool_t HandleTimer(TTimer *t);
00122    virtual void   Layout() = 0;
00123 
00124    virtual void  SetRange(Int_t range, Int_t page_size) = 0;
00125    virtual void  SetPosition(Int_t pos) = 0;
00126    virtual Int_t GetPosition() const { return fPos; }
00127    virtual Int_t GetPageSize() const { return fPsize; }
00128    virtual Int_t GetRange() const { return fRange; }
00129    virtual void  Resize(UInt_t w = 0, UInt_t h = 0) { TGFrame::Resize(w, h); SetRange(fRange, fPsize); }
00130    virtual void  MoveResize(Int_t x, Int_t y, UInt_t w = 0, UInt_t h = 0)
00131                   { TGFrame::MoveResize(x, y, w, h); SetRange(fRange, fPsize); }
00132    virtual void  Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
00133    virtual void  ChangeBackground(Pixel_t back);
00134    virtual void  SetAccelerated(Bool_t m = kTRUE) { fAccelerated = m; }
00135          Bool_t  IsAccelerated() const { return fAccelerated; }
00136  
00137    virtual void MapSubwindows() { TGWindow::MapSubwindows(); }
00138    TGScrollBarElement *GetHead() const { return fHead; }
00139    TGScrollBarElement *GetTail() const { return fTail; }
00140    TGScrollBarElement *GetSlider() const { return fSlider; }
00141 
00142    virtual void  PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } //*SIGNAL*
00143    virtual void  RangeChanged(Int_t range) { Emit("RangeChanged(Int_t)", range); } //*SIGNAL*
00144    virtual void  PageSizeChanged(Int_t range) { Emit("PageSizeChanged(Int_t)", range); } //*SIGNAL*
00145 
00146    virtual Int_t GetSmallIncrement() { return fSmallInc; }
00147    virtual void  SetSmallIncrement(Int_t increment) { fSmallInc = increment; }
00148 
00149    ClassDef(TGScrollBar,0)  // Scrollbar widget
00150 };
00151 
00152 
00153 
00154 class TGHScrollBar : public TGScrollBar {
00155 
00156 public:
00157    TGHScrollBar(const TGWindow *p = 0, UInt_t w = 4, UInt_t h = 2,
00158                 UInt_t options = kHorizontalFrame,
00159                 Pixel_t back = GetDefaultFrameBackground());
00160    virtual ~TGHScrollBar() { }
00161 
00162    virtual Bool_t HandleButton(Event_t *event);
00163    virtual Bool_t HandleMotion(Event_t *event);
00164    virtual TGDimension GetDefaultSize() const
00165                         { return TGDimension(fWidth, GetScrollBarWidth()); }
00166    virtual void Layout();
00167 
00168    virtual void SetRange(Int_t range, Int_t page_size);  //*MENU*
00169    virtual void SetPosition(Int_t pos);                  //*MENU* *GETTER=GetPosition
00170    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00171 
00172    ClassDef(TGHScrollBar,0)  // Horizontal scrollbar widget
00173 };
00174 
00175 
00176 
00177 class TGVScrollBar : public TGScrollBar {
00178 
00179 public:
00180    TGVScrollBar(const TGWindow *p = 0, UInt_t w = 2, UInt_t h = 4,
00181                 UInt_t options = kVerticalFrame,
00182                 Pixel_t back = GetDefaultFrameBackground());
00183    virtual ~TGVScrollBar() { }
00184 
00185    virtual Bool_t HandleButton(Event_t *event);
00186    virtual Bool_t HandleMotion(Event_t *event);
00187    virtual TGDimension GetDefaultSize() const
00188                         { return TGDimension(GetScrollBarWidth(), fHeight); }
00189    virtual void Layout();
00190 
00191    virtual void SetRange(Int_t range, Int_t page_size);  //*MENU*
00192    virtual void SetPosition(Int_t pos);                  //*MENU*  *GETTER=GetPosition
00193    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00194 
00195    ClassDef(TGVScrollBar,0)  // Vertical scrollbar widget
00196 };
00197 
00198 #endif

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