TGSlider.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGSlider.h 33776 2010-06-08 12:16:54Z bellenot $
00002 // Author: Fons Rademakers   14/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_TGSlider
00013 #define ROOT_TGSlider
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGSlider, TGVSlider and TGHSlider                                    //
00019 //                                                                      //
00020 // Slider widgets allow easy selection of a range.                      //
00021 // Sliders can be either horizontal or vertical oriented and there is   //
00022 // a choice of two different slider types and three different types     //
00023 // of tick marks.                                                       //
00024 //                                                                      //
00025 // TGSlider is an abstract base class. Use the concrete TGVSlider and   //
00026 // TGHSlider.                                                           //
00027 //                                                                      //
00028 // Dragging the slider will generate the event:                         //
00029 // kC_VSLIDER, kSL_POS, slider id, position  (for vertical slider)      //
00030 // kC_HSLIDER, kSL_POS, slider id, position  (for horizontal slider)    //
00031 //                                                                      //
00032 // Pressing the mouse will generate the event:                          //
00033 // kC_VSLIDER, kSL_PRESS, slider id, 0  (for vertical slider)           //
00034 // kC_HSLIDER, kSL_PRESS, slider id, 0  (for horizontal slider)         //
00035 //                                                                      //
00036 // Releasing the mouse will generate the event:                         //
00037 // kC_VSLIDER, kSL_RELEASE, slider id, 0  (for vertical slider)         //
00038 // kC_HSLIDER, kSL_RELEASE, slider id, 0  (for horizontal slider)       //
00039 //                                                                      //
00040 //////////////////////////////////////////////////////////////////////////
00041 
00042 #ifndef ROOT_TGFrame
00043 #include "TGFrame.h"
00044 #endif
00045 #ifndef ROOT_TGWidget
00046 #include "TGWidget.h"
00047 #endif
00048 
00049 
00050 //--- sizes for vert. and horz. sliders
00051 
00052 enum ESliderSize {
00053    kSliderWidth  = 24,
00054    kSliderHeight = kSliderWidth
00055 };
00056 
00057 
00058 enum ESliderType {
00059    //--- slider types (type of slider picture)
00060    kSlider1        = BIT(0),
00061    kSlider2        = BIT(1),
00062 
00063    //--- scaling of slider
00064    kScaleNo        = BIT(2),
00065    kScaleDownRight = BIT(3),
00066    kScaleBoth      = BIT(4)
00067 };
00068 
00069 
00070 class TGSlider : public TGFrame, public TGWidget {
00071 
00072 protected:
00073    Int_t            fPos;           // logical position between fVmin and fVmax
00074    Int_t            fRelPos;        // slider position in pixel coordinates
00075    Int_t            fVmin;          // logical lower limit of slider
00076    Int_t            fVmax;          // logical upper limit of slider
00077    Int_t            fType;          // slider type bits
00078    Int_t            fScale;         // tick mark scale
00079    Bool_t           fDragging;      // true if in dragging mode
00080    const TGPicture *fSliderPic;     // picture to draw slider
00081    const TGPicture *fDisabledPic;   // picture to draw disabled slider
00082 
00083    TString GetTypeString() const;   // used in SavePrimitive
00084    virtual void CreateDisabledPicture();
00085 
00086 private:
00087    TGSlider(const TGSlider&);             // not implemented
00088    TGSlider& operator=(const TGSlider&);  // not implemented
00089 
00090 public:
00091    TGSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
00092             UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
00093             UInt_t options = kChildFrame,
00094             Pixel_t back = GetDefaultFrameBackground());
00095 
00096    virtual ~TGSlider() { }
00097 
00098    virtual Bool_t HandleButton(Event_t *event) = 0;
00099    virtual Bool_t HandleConfigureNotify(Event_t* event) = 0;
00100    virtual Bool_t HandleMotion(Event_t *event) = 0;
00101 
00102    virtual void  SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); }              //*TOGGLE* *GETTER=IsEnabled
00103    virtual void  SetState(Bool_t state);
00104    virtual void  SetScale(Int_t scale) { fScale = scale; }                          //*MENU*
00105    virtual void  SetRange(Int_t min, Int_t max) { fVmin = min; fVmax = max; }       //*MENU*
00106    virtual void  SetPosition(Int_t pos) { fPos = pos; fClient->NeedRedraw(this); }  //*MENU*
00107    virtual Int_t GetPosition() const { return fPos; }
00108    virtual Int_t GetMinPosition() const { return fVmin; }
00109    virtual Int_t GetMaxPosition() const { return fVmax; }
00110    virtual Int_t GetScale() const { return fScale; }
00111    virtual void  MapSubwindows() { TGWindow::MapSubwindows(); }
00112    virtual void  ChangeSliderPic(const char *name) {
00113                     if (fSliderPic) fClient->FreePicture(fSliderPic);
00114                     fSliderPic = fClient->GetPicture(name);
00115                  }
00116 
00117    virtual void  PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } // *SIGNAL*
00118    virtual void  Pressed() { Emit("Pressed()"); }    // *SIGNAL*
00119    virtual void  Released() { Emit("Released()"); }  // *SIGNAL*
00120 
00121    ClassDef(TGSlider,0)  // Slider widget abstract base class
00122 };
00123 
00124 
00125 class TGVSlider : public TGSlider {
00126 
00127 protected:
00128    Int_t   fYp;      // vertical slider y position in pixel coordinates
00129 
00130    virtual void DoRedraw();
00131 
00132 public:
00133    TGVSlider(const TGWindow *p = 0, UInt_t h = 40,
00134              UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
00135              UInt_t options = kVerticalFrame,
00136              Pixel_t back = GetDefaultFrameBackground());
00137    virtual ~TGVSlider();
00138 
00139    virtual Bool_t HandleButton(Event_t *event);
00140    virtual Bool_t HandleConfigureNotify(Event_t* event);
00141    virtual Bool_t HandleMotion(Event_t *event);
00142    virtual TGDimension GetDefaultSize() const
00143                      { return TGDimension(kSliderWidth, fHeight); }
00144    virtual void   Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w, h ? h+16 : fHeight + 16); }
00145    virtual void   Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
00146    virtual void   SavePrimitive(ostream &out, Option_t *option = "");
00147 
00148    ClassDef(TGVSlider,0)  // Vertical slider widget
00149 };
00150 
00151 
00152 class TGHSlider : public TGSlider {
00153 
00154 protected:
00155    Int_t       fXp;     // horizontal slider x position in pixel coordinates
00156 
00157    virtual void DoRedraw();
00158 
00159 public:
00160    TGHSlider(const TGWindow *p = 0, UInt_t w = 40,
00161              UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
00162              UInt_t options = kHorizontalFrame,
00163              Pixel_t back = GetDefaultFrameBackground());
00164    virtual ~TGHSlider();
00165 
00166    virtual Bool_t HandleButton(Event_t *event);
00167    virtual Bool_t HandleConfigureNotify(Event_t* event);
00168    virtual Bool_t HandleMotion(Event_t *event);
00169    virtual TGDimension GetDefaultSize() const
00170                      { return TGDimension(fWidth, kSliderHeight); }
00171    virtual void   Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w ? w+16 : fWidth + 16, h); }
00172    virtual void   Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
00173    virtual void   SavePrimitive(ostream &out, Option_t *option = "");
00174 
00175    ClassDef(TGHSlider,0)  // Horizontal slider widget
00176 };
00177 
00178 #endif

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