Logo ROOT  
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),
62  kScaleBoth = BIT(4)
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) {
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
TGVSlider::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in vertical slider.
Definition: TGSlider.cxx:210
TGVSlider::DoRedraw
virtual void DoRedraw()
Redraw vertical slider widget.
Definition: TGSlider.cxx:167
TGVSlider::fYp
Int_t fYp
Definition: TGSlider.h:130
TGSlider::fType
Int_t fType
Definition: TGSlider.h:73
TGWindow
Definition: TGWindow.h:31
TGSlider::SetState
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Definition: TGSlider.cxx:114
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGSlider::operator=
TGSlider & operator=(const TGSlider &)
TGSlider::fVmin
Int_t fVmin
Definition: TGSlider.h:71
TGHSlider::fXp
Int_t fXp
Definition: TGSlider.h:157
TGVSlider::HandleConfigureNotify
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
Definition: TGSlider.cxx:312
TGSlider::HandleButton
virtual Bool_t HandleButton(Event_t *event)=0
TGPicture
Definition: TGPicture.h:36
TGDimension
Definition: TGDimension.h:27
Option_t
const char Option_t
Definition: RtypesCore.h:66
TGSlider::GetPosition
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
TGSlider::GetMaxPosition
virtual Int_t GetMaxPosition() const
Definition: TGSlider.h:111
TGSlider::CreateDisabledPicture
virtual void CreateDisabledPicture()
Creates disabled picture.
Definition: TGSlider.cxx:85
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGSlider::fSliderPic
const TGPicture * fSliderPic
Definition: TGSlider.h:76
TGSlider::PositionChanged
virtual void PositionChanged(Int_t pos)
Definition: TGSlider.h:119
TGFrame::fWidth
UInt_t fWidth
Definition: TGFrame.h:112
kScaleDownRight
@ kScaleDownRight
Definition: TGSlider.h:61
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
TGSlider::~TGSlider
virtual ~TGSlider()
Definition: TGSlider.h:92
TGVSlider::Resize
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:147
TGSlider::ChangeSliderPic
virtual void ChangeSliderPic(const char *name)
Definition: TGSlider.h:114
kSliderHeight
@ kSliderHeight
Definition: TGSlider.h:50
TGSlider::SetRange
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
TGHSlider
Definition: TGSlider.h:154
TGSlider::GetMinPosition
virtual Int_t GetMinPosition() const
Definition: TGSlider.h:110
TGSlider::fPos
Int_t fPos
Definition: TGSlider.h:69
TGHSlider::TGHSlider
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())
Create horizontal slider widget.
Definition: TGSlider.cxx:322
TGWidget
Definition: TGWidget.h:55
TGSlider::Pressed
virtual void Pressed()
Definition: TGSlider.h:120
TGVSlider::~TGVSlider
virtual ~TGVSlider()
Delete vertical slider widget.
Definition: TGSlider.cxx:158
kSlider2
@ kSlider2
Definition: TGSlider.h:57
TGVSlider
Definition: TGSlider.h:127
TGFrame::GetDefaultFrameBackground
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:668
TGClient::FreePicture
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:309
TGSlider::Released
virtual void Released()
Definition: TGSlider.h:121
TGSlider::MapSubwindows
virtual void MapSubwindows()
map sub windows
Definition: TGSlider.h:113
TString
Basic string class.
Definition: TString.h:136
TGFrame
Definition: TGFrame.h:105
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGSlider::SetPosition
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
TGHSlider::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in horizontal slider widget.
Definition: TGSlider.cxx:404
bool
TGSlider::SetScale
virtual void SetScale(Int_t scale)
Definition: TGSlider.h:100
TGHSlider::HandleConfigureNotify
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
Definition: TGSlider.cxx:502
ESliderSize
ESliderSize
Definition: TGSlider.h:48
TGHSlider::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in horizontal slide widget.
Definition: TGSlider.cxx:478
ESliderType
ESliderType
Definition: TGSlider.h:54
kScaleNo
@ kScaleNo
Definition: TGSlider.h:60
TGSlider::fVmax
Int_t fVmax
Definition: TGSlider.h:72
TGSlider::HandleConfigureNotify
virtual Bool_t HandleConfigureNotify(Event_t *event)=0
This event is generated when the frame is resized.
TGDimension::fHeight
UInt_t fHeight
Definition: TGDimension.h:30
TGVSlider::Resize
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:146
h
#define h(i)
Definition: RSha256.hxx:106
TGSlider::fScale
Int_t fScale
Definition: TGSlider.h:74
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGVSlider::TGVSlider
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())
Create a vertical slider widget.
Definition: TGSlider.cxx:127
TGFrame.h
TGDimension::fWidth
UInt_t fWidth
Definition: TGDimension.h:29
TGVSlider::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an horizontal slider as a C++ statement(s) on output stream out.
Definition: TGSlider.cxx:581
TGSlider::GetScale
virtual Int_t GetScale() const
Definition: TGSlider.h:112
TGClient::GetPicture
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:290
BIT
#define BIT(n)
Definition: Rtypes.h:85
TGSlider::GetTypeString
TString GetTypeString() const
Returns the slider type as a string - used in SavePrimitive().
Definition: TGSlider.cxx:512
TGWindow::MapSubwindows
virtual void MapSubwindows()
map sub windows
Definition: TGWindow.cxx:149
TGSlider
Definition: TGSlider.h:66
TGVSlider::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in vertical slider.
Definition: TGSlider.cxx:288
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TGWidget.h
unsigned int
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGHSlider::DoRedraw
virtual void DoRedraw()
Redraw horizontal slider widget.
Definition: TGSlider.cxx:362
TGClient::NeedRedraw
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:373
kSliderWidth
@ kSliderWidth
Definition: TGSlider.h:49
TGVSlider::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:144
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
Event_t
Definition: GuiTypes.h:173
TGHSlider::~TGHSlider
virtual ~TGHSlider()
Delete a horizontal slider widget.
Definition: TGSlider.cxx:353
name
char name[80]
Definition: TGX11.cxx:110
TGSlider::fRelPos
Int_t fRelPos
Definition: TGSlider.h:70
TGHSlider::Resize
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:173
kSlider1
@ kSlider1
Definition: TGSlider.h:56
TGHSlider::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:171
TGHSlider::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an horizontal slider as a C++ statement(s) on output stream out.
Definition: TGSlider.cxx:544
TGHSlider::Resize
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:174
TGFrame::fHeight
UInt_t fHeight
Definition: TGFrame.h:113
type
int type
Definition: TGX11.cxx:121
TGSlider::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)=0
kScaleBoth
@ kScaleBoth
Definition: TGSlider.h:62
TGSlider::TGSlider
TGSlider(const TGSlider &)
TGSlider::fDisabledPic
const TGPicture * fDisabledPic
Definition: TGSlider.h:77
TGSlider::SetEnabled
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
TGSlider::fDragging
Bool_t fDragging
Definition: TGSlider.h:75
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
kChildFrame
@ kChildFrame
Definition: GuiTypes.h:379
int