Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
48 enum ESliderSize {
49  kSliderWidth = 24,
50  kSliderHeight = kSliderWidth
51 };
52 
53 
54 enum ESliderType {
55  //--- slider types (type of slider picture)
56  kSlider1 = BIT(0),
57  kSlider2 = BIT(1),
58 
59  //--- scaling of slider
60  kScaleNo = BIT(2),
61  kScaleDownRight = BIT(3),
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,
90  Pixel_t back = GetDefaultFrameBackground());
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; }
113  virtual void MapSubwindows() { TGWindow::MapSubwindows(); }
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,
138  Pixel_t back = GetDefaultFrameBackground());
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,
165  Pixel_t back = GetDefaultFrameBackground());
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