Logo ROOT   6.12/07
Reference Guide
TGSlider.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 14/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGSlider
13 #define ROOT_TGSlider
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGSlider, TGVSlider and TGHSlider //
19 // //
20 // Slider widgets allow easy selection of a range. //
21 // Sliders can be either horizontal or vertical oriented and there is //
22 // a choice of two different slider types and three different types //
23 // of tick marks. //
24 // //
25 // TGSlider is an abstract base class. Use the concrete TGVSlider and //
26 // TGHSlider. //
27 // //
28 // Dragging the slider will generate the event: //
29 // kC_VSLIDER, kSL_POS, slider id, position (for vertical slider) //
30 // kC_HSLIDER, kSL_POS, slider id, position (for horizontal slider) //
31 // //
32 // Pressing the mouse will generate the event: //
33 // kC_VSLIDER, kSL_PRESS, slider id, 0 (for vertical slider) //
34 // kC_HSLIDER, kSL_PRESS, slider id, 0 (for horizontal slider) //
35 // //
36 // Releasing the mouse will generate the event: //
37 // kC_VSLIDER, kSL_RELEASE, slider id, 0 (for vertical slider) //
38 // kC_HSLIDER, kSL_RELEASE, slider id, 0 (for horizontal slider) //
39 // //
40 //////////////////////////////////////////////////////////////////////////
41 
42 #include "TGFrame.h"
43 #include "TGWidget.h"
44 
45 
46 //--- sizes for vert. and horz. sliders
47 
51 };
52 
53 
55  //--- slider types (type of slider picture)
56  kSlider1 = BIT(0),
57  kSlider2 = BIT(1),
58 
59  //--- scaling of slider
60  kScaleNo = BIT(2),
63 };
64 
65 
66 class TGSlider : public TGFrame, public TGWidget {
67 
68 protected:
69  Int_t fPos; // logical position between fVmin and fVmax
70  Int_t fRelPos; // slider position in pixel coordinates
71  Int_t fVmin; // logical lower limit of slider
72  Int_t fVmax; // logical upper limit of slider
73  Int_t fType; // slider type bits
74  Int_t fScale; // tick mark scale
75  Bool_t fDragging; // true if in dragging mode
76  const TGPicture *fSliderPic; // picture to draw slider
77  const TGPicture *fDisabledPic; // picture to draw disabled slider
78 
79  TString GetTypeString() const; // used in SavePrimitive
80  virtual void CreateDisabledPicture();
81 
82 private:
83  TGSlider(const TGSlider&); // not implemented
84  TGSlider& operator=(const TGSlider&); // not implemented
85 
86 public:
87  TGSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
88  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
89  UInt_t options = kChildFrame,
91 
92  virtual ~TGSlider() { }
93 
94  virtual Bool_t HandleButton(Event_t *event) = 0;
95  virtual Bool_t HandleConfigureNotify(Event_t* event) = 0;
96  virtual Bool_t HandleMotion(Event_t *event) = 0;
97 
98  virtual void SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); } //*TOGGLE* *GETTER=IsEnabled
99  virtual void SetState(Bool_t state);
100  virtual void SetScale(Int_t scale) { fScale = scale; } //*MENU*
101  virtual void SetRange(Int_t min, Int_t max) {
102  if (max > min) { fVmin = min; fVmax = max; }
103  else Warning("SetRange", "Incorrect range boundaries [%d,%d]", min, max);
104  } //*MENU*
105  virtual void SetPosition(Int_t pos) {
106  if ((pos >= fVmin) && (pos <= fVmax)) { fPos = pos; fClient->NeedRedraw(this); }
107  else Warning("SetPosition", "The position (%d) is out of range [%d,%d]", pos, fVmin, fVmax);
108  } //*MENU*
109  virtual Int_t GetPosition() const { return fPos; }
110  virtual Int_t GetMinPosition() const { return fVmin; }
111  virtual Int_t GetMaxPosition() const { return fVmax; }
112  virtual Int_t GetScale() const { return fScale; }
114  virtual void ChangeSliderPic(const char *name) {
115  if (fSliderPic) fClient->FreePicture(fSliderPic);
116  fSliderPic = fClient->GetPicture(name);
117  }
118 
119  virtual void PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } // *SIGNAL*
120  virtual void Pressed() { Emit("Pressed()"); } // *SIGNAL*
121  virtual void Released() { Emit("Released()"); } // *SIGNAL*
122 
123  ClassDef(TGSlider,0) // Slider widget abstract base class
124 };
125 
126 
127 class TGVSlider : public TGSlider {
128 
129 protected:
130  Int_t fYp; // vertical slider y position in pixel coordinates
131 
132  virtual void DoRedraw();
133 
134 public:
135  TGVSlider(const TGWindow *p = 0, UInt_t h = 40,
136  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
137  UInt_t options = kVerticalFrame,
139  virtual ~TGVSlider();
140 
141  virtual Bool_t HandleButton(Event_t *event);
142  virtual Bool_t HandleConfigureNotify(Event_t* event);
143  virtual Bool_t HandleMotion(Event_t *event);
144  virtual TGDimension GetDefaultSize() const
145  { return TGDimension(kSliderWidth, fHeight); }
146  virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w, h ? h+16 : fHeight + 16); }
147  virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
148  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
149 
150  ClassDef(TGVSlider,0) // Vertical slider widget
151 };
152 
153 
154 class TGHSlider : public TGSlider {
155 
156 protected:
157  Int_t fXp; // horizontal slider x position in pixel coordinates
158 
159  virtual void DoRedraw();
160 
161 public:
162  TGHSlider(const TGWindow *p = 0, UInt_t w = 40,
163  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
164  UInt_t options = kHorizontalFrame,
166  virtual ~TGHSlider();
167 
168  virtual Bool_t HandleButton(Event_t *event);
169  virtual Bool_t HandleConfigureNotify(Event_t* event);
170  virtual Bool_t HandleMotion(Event_t *event);
171  virtual TGDimension GetDefaultSize() const
172  { return TGDimension(fWidth, kSliderHeight); }
173  virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w ? w+16 : fWidth + 16, h); }
174  virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
175  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
176 
177  ClassDef(TGHSlider,0) // Horizontal slider widget
178 };
179 
180 #endif
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:144
virtual void Pressed()
Definition: TGSlider.h:120
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
const char Option_t
Definition: RtypesCore.h:62
TGSlider & operator=(const TGSlider &)
#define BIT(n)
Definition: Rtypes.h:78
TH1 * h
Definition: legend2.C:5
virtual void MapSubwindows()
Definition: TGWindow.h:89
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Definition: TGSlider.cxx:112
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:174
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
TGSlider(const TGSlider &)
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t HandleConfigureNotify(Event_t *event)=0
This event is generated when the frame is resized.
Int_t fYp
Definition: TGSlider.h:130
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:412
const TGPicture * fDisabledPic
Definition: TGSlider.h:77
#define ClassDef(name, id)
Definition: Rtypes.h:320
ULong_t Pixel_t
Definition: GuiTypes.h:39
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
TString GetTypeString() const
Returns the slider type as a string - used in SavePrimitive().
Definition: TGSlider.cxx:510
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
virtual Bool_t HandleButton(Event_t *event)=0
UInt_t fHeight
Definition: TGDimension.h:30
virtual void ChangeSliderPic(const char *name)
Definition: TGSlider.h:114
UInt_t fWidth
Definition: TGDimension.h:29
Int_t fPos
Definition: TGSlider.h:69
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:147
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a frame widget as a C++ statement(s) on output stream out.
Definition: TGFrame.cxx:3187
Int_t fXp
Definition: TGSlider.h:157
virtual void Released()
Definition: TGSlider.h:121
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:171
virtual Int_t GetMaxPosition() const
Definition: TGSlider.h:111
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual ~TGSlider()
Definition: TGSlider.h:92
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
Int_t fType
Definition: TGSlider.h:73
UInt_t fWidth
Definition: TGFrame.h:134
virtual void SetScale(Int_t scale)
Definition: TGSlider.h:100
Int_t fRelPos
Definition: TGSlider.h:70
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:173
virtual void PositionChanged(Int_t pos)
Definition: TGSlider.h:119
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:287
int type
Definition: TGX11.cxx:120
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
virtual Int_t GetMinPosition() const
Definition: TGSlider.h:110
UInt_t fHeight
Definition: TGFrame.h:135
virtual Bool_t HandleMotion(Event_t *event)=0
Int_t fVmin
Definition: TGSlider.h:71
Bool_t fDragging
Definition: TGSlider.h:75
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:146
TGClient * fClient
Definition: TGObject.h:37
virtual void CreateDisabledPicture()
Creates disabled picture.
Definition: TGSlider.cxx:83
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
ESliderType
Definition: TGSlider.h:54
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:165
virtual Int_t GetScale() const
Definition: TGSlider.h:112
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t fVmax
Definition: TGSlider.h:72
ESliderSize
Definition: TGSlider.h:48
virtual void MapSubwindows()
Definition: TGSlider.h:113
char name[80]
Definition: TGX11.cxx:109
Int_t fScale
Definition: TGSlider.h:74
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
const TGPicture * fSliderPic
Definition: TGSlider.h:76