ROOT logo
// @(#)root/gui:$Id: TGSlider.h 27642 2009-02-27 16:11:02Z bellenot $
// Author: Fons Rademakers   14/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_TGSlider
#define ROOT_TGSlider


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGSlider, TGVSlider and TGHSlider                                    //
//                                                                      //
// Slider widgets allow easy selection of a range.                      //
// Sliders can be either horizontal or vertical oriented and there is   //
// a choice of two different slider types and three different types     //
// of tick marks.                                                       //
//                                                                      //
// TGSlider is an abstract base class. Use the concrete TGVSlider and   //
// TGHSlider.                                                           //
//                                                                      //
// Dragging the slider will generate the event:                         //
// kC_VSLIDER, kSL_POS, slider id, position  (for vertical slider)      //
// kC_HSLIDER, kSL_POS, slider id, position  (for horizontal slider)    //
//                                                                      //
// Pressing the mouse will generate the event:                          //
// kC_VSLIDER, kSL_PRESS, slider id, 0  (for vertical slider)           //
// kC_HSLIDER, kSL_PRESS, slider id, 0  (for horizontal slider)         //
//                                                                      //
// Releasing the mouse will generate the event:                         //
// kC_VSLIDER, kSL_RELEASE, slider id, 0  (for vertical slider)         //
// kC_HSLIDER, kSL_RELEASE, slider id, 0  (for horizontal slider)       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

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


//--- sizes for vert. and horz. sliders

enum ESliderSize {
   kSliderWidth  = 24,
   kSliderHeight = kSliderWidth
};


enum ESliderType {
   //--- slider types (type of slider picture)
   kSlider1        = BIT(0),
   kSlider2        = BIT(1),

   //--- scaling of slider
   kScaleNo        = BIT(2),
   kScaleDownRight = BIT(3),
   kScaleBoth      = BIT(4)
};


class TGSlider : public TGFrame, public TGWidget {

protected:
   Int_t            fPos;           // logical position between fVmin and fVmax
   Int_t            fRelPos;        // slider position in pixel coordinates
   Int_t            fVmin;          // logical lower limit of slider
   Int_t            fVmax;          // logical upper limit of slider
   Int_t            fType;          // slider type bits
   Int_t            fScale;         // tick mark scale
   Bool_t           fDragging;      // true if in dragging mode
   const TGPicture *fSliderPic;     // picture to draw slider

   TString GetTypeString() const;   // used in SavePrimitive

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

public:
   TGSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
            UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
            UInt_t options = kChildFrame,
            Pixel_t back = GetDefaultFrameBackground());

   virtual ~TGSlider() { }

   virtual Bool_t HandleButton(Event_t *event) = 0;
   virtual Bool_t HandleConfigureNotify(Event_t* event) = 0;
   virtual Bool_t HandleMotion(Event_t *event) = 0;

   virtual void  SetScale(Int_t scale) { fScale = scale; }                          //*MENU*
   virtual void  SetRange(Int_t min, Int_t max) { fVmin = min; fVmax = max; }       //*MENU*
   virtual void  SetPosition(Int_t pos) { fPos = pos; fClient->NeedRedraw(this); }  //*MENU*
   virtual Int_t GetPosition() const { return fPos; }
   virtual Int_t GetMinPosition() const { return fVmin; }
   virtual Int_t GetMaxPosition() const { return fVmax; }
   virtual Int_t GetScale() const { return fScale; }
   virtual void  MapSubwindows() { TGWindow::MapSubwindows(); }
   virtual void  ChangeSliderPic(const char *name) {
                    if (fSliderPic) fClient->FreePicture(fSliderPic);
                    fSliderPic = fClient->GetPicture(name);
                 }

   virtual void  PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } // *SIGNAL*
   virtual void  Pressed() { Emit("Pressed()"); }    // *SIGNAL*
   virtual void  Released() { Emit("Released()"); }  // *SIGNAL*

   ClassDef(TGSlider,0)  // Slider widget abstract base class
};


class TGVSlider : public TGSlider {

protected:
   Int_t   fYp;      // vertical slider y position in pixel coordinates

   virtual void DoRedraw();

public:
   TGVSlider(const TGWindow *p = 0, UInt_t h = 40,
             UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
             UInt_t options = kVerticalFrame,
             Pixel_t back = GetDefaultFrameBackground());
   virtual ~TGVSlider();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleConfigureNotify(Event_t* event);
   virtual Bool_t HandleMotion(Event_t *event);
   virtual TGDimension GetDefaultSize() const
                     { return TGDimension(kSliderWidth, fHeight); }
   virtual void   Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w, h ? h+16 : fHeight + 16); }
   virtual void   Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
   virtual void   SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGVSlider,0)  // Vertical slider widget
};


class TGHSlider : public TGSlider {

protected:
   Int_t       fXp;     // horizontal slider x position in pixel coordinates

   virtual void DoRedraw();

public:
   TGHSlider(const TGWindow *p = 0, UInt_t w = 40,
             UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
             UInt_t options = kHorizontalFrame,
             Pixel_t back = GetDefaultFrameBackground());
   virtual ~TGHSlider();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleConfigureNotify(Event_t* event);
   virtual Bool_t HandleMotion(Event_t *event);
   virtual TGDimension GetDefaultSize() const
                     { return TGDimension(fWidth, kSliderHeight); }
   virtual void   Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w ? w+16 : fWidth + 16, h); }
   virtual void   Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
   virtual void   SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGHSlider,0)  // Horizontal slider widget
};

#endif
 TGSlider.h:1
 TGSlider.h:2
 TGSlider.h:3
 TGSlider.h:4
 TGSlider.h:5
 TGSlider.h:6
 TGSlider.h:7
 TGSlider.h:8
 TGSlider.h:9
 TGSlider.h:10
 TGSlider.h:11
 TGSlider.h:12
 TGSlider.h:13
 TGSlider.h:14
 TGSlider.h:15
 TGSlider.h:16
 TGSlider.h:17
 TGSlider.h:18
 TGSlider.h:19
 TGSlider.h:20
 TGSlider.h:21
 TGSlider.h:22
 TGSlider.h:23
 TGSlider.h:24
 TGSlider.h:25
 TGSlider.h:26
 TGSlider.h:27
 TGSlider.h:28
 TGSlider.h:29
 TGSlider.h:30
 TGSlider.h:31
 TGSlider.h:32
 TGSlider.h:33
 TGSlider.h:34
 TGSlider.h:35
 TGSlider.h:36
 TGSlider.h:37
 TGSlider.h:38
 TGSlider.h:39
 TGSlider.h:40
 TGSlider.h:41
 TGSlider.h:42
 TGSlider.h:43
 TGSlider.h:44
 TGSlider.h:45
 TGSlider.h:46
 TGSlider.h:47
 TGSlider.h:48
 TGSlider.h:49
 TGSlider.h:50
 TGSlider.h:51
 TGSlider.h:52
 TGSlider.h:53
 TGSlider.h:54
 TGSlider.h:55
 TGSlider.h:56
 TGSlider.h:57
 TGSlider.h:58
 TGSlider.h:59
 TGSlider.h:60
 TGSlider.h:61
 TGSlider.h:62
 TGSlider.h:63
 TGSlider.h:64
 TGSlider.h:65
 TGSlider.h:66
 TGSlider.h:67
 TGSlider.h:68
 TGSlider.h:69
 TGSlider.h:70
 TGSlider.h:71
 TGSlider.h:72
 TGSlider.h:73
 TGSlider.h:74
 TGSlider.h:75
 TGSlider.h:76
 TGSlider.h:77
 TGSlider.h:78
 TGSlider.h:79
 TGSlider.h:80
 TGSlider.h:81
 TGSlider.h:82
 TGSlider.h:83
 TGSlider.h:84
 TGSlider.h:85
 TGSlider.h:86
 TGSlider.h:87
 TGSlider.h:88
 TGSlider.h:89
 TGSlider.h:90
 TGSlider.h:91
 TGSlider.h:92
 TGSlider.h:93
 TGSlider.h:94
 TGSlider.h:95
 TGSlider.h:96
 TGSlider.h:97
 TGSlider.h:98
 TGSlider.h:99
 TGSlider.h:100
 TGSlider.h:101
 TGSlider.h:102
 TGSlider.h:103
 TGSlider.h:104
 TGSlider.h:105
 TGSlider.h:106
 TGSlider.h:107
 TGSlider.h:108
 TGSlider.h:109
 TGSlider.h:110
 TGSlider.h:111
 TGSlider.h:112
 TGSlider.h:113
 TGSlider.h:114
 TGSlider.h:115
 TGSlider.h:116
 TGSlider.h:117
 TGSlider.h:118
 TGSlider.h:119
 TGSlider.h:120
 TGSlider.h:121
 TGSlider.h:122
 TGSlider.h:123
 TGSlider.h:124
 TGSlider.h:125
 TGSlider.h:126
 TGSlider.h:127
 TGSlider.h:128
 TGSlider.h:129
 TGSlider.h:130
 TGSlider.h:131
 TGSlider.h:132
 TGSlider.h:133
 TGSlider.h:134
 TGSlider.h:135
 TGSlider.h:136
 TGSlider.h:137
 TGSlider.h:138
 TGSlider.h:139
 TGSlider.h:140
 TGSlider.h:141
 TGSlider.h:142
 TGSlider.h:143
 TGSlider.h:144
 TGSlider.h:145
 TGSlider.h:146
 TGSlider.h:147
 TGSlider.h:148
 TGSlider.h:149
 TGSlider.h:150
 TGSlider.h:151
 TGSlider.h:152
 TGSlider.h:153
 TGSlider.h:154
 TGSlider.h:155
 TGSlider.h:156
 TGSlider.h:157
 TGSlider.h:158
 TGSlider.h:159
 TGSlider.h:160
 TGSlider.h:161
 TGSlider.h:162
 TGSlider.h:163
 TGSlider.h:164
 TGSlider.h:165
 TGSlider.h:166
 TGSlider.h:167
 TGSlider.h:168
 TGSlider.h:169
 TGSlider.h:170
 TGSlider.h:171
 TGSlider.h:172
 TGSlider.h:173
 TGSlider.h:174