Added method RGValuator::SetEnabled().
[u/mrichter/AliRoot.git] / EVE / Reve / RGValuators.cxx
CommitLineData
5987168b 1// $Header$
2
3#include "RGValuators.h"
4
5#include <TGLabel.h>
6#include <TGSlider.h>
7#include <TGDoubleSlider.h>
8
9using namespace Reve;
10
11/**************************************************************************/
12// RGValuatorBase
13/**************************************************************************/
14
15ClassImp(RGValuatorBase)
16
17RGValuatorBase::RGValuatorBase(const TGWindow *p, const char* name,
18 UInt_t w, UInt_t h) :
19 TGCompositeFrame(p, w, h),
20
21 fLabelWidth (0),
22 fAlignRight (kFALSE),
23 fShowSlider (kTRUE),
24
25 fNELength (5),
26 fNEHeight (20),
27
28 fLabel (0)
29{
30 SetName(name);
31}
32
33/**************************************************************************/
34// RGValuator
35/**************************************************************************/
36
37ClassImp(RGValuator)
38
39RGValuator::RGValuator(const TGWindow *p, const char* title,
40 UInt_t w, UInt_t h) :
41 RGValuatorBase(p, title, w, h),
42
43 fValue (0),
44 fMin (0),
45 fMax (0),
46
47 fSliderNewLine (kFALSE),
48 fSliderSteps (-1),
49 fEntry (0),
50 fSlider (0)
51{}
52
53void RGValuator::Build()
54{
55 TGCompositeFrame *hf1, *hfs;
56 if(fShowSlider && fSliderNewLine) {
57 SetLayoutManager(new TGVerticalLayout(this));
58 hf1 = new TGHorizontalFrame(this);
59 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
60 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
61 hfs = new TGHorizontalFrame(this);
62 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
63 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
64 } else {
65 hf1 = this;
66 hfs = this;
67 SetLayoutManager(new TGHorizontalLayout(this));
68 }
69
70 // label
71 TGLayoutHints* lh;
72 if(fAlignRight)
73 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
74 else
75 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
76
77 if (fLabelWidth > 0) {
78 // printf("fLabelWidth > 0 \n");
79 TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize);
80 fLabel = new TGLabel(lf, GetName());
81 lf->AddFrame(fLabel, lh);
82 // add label frame to top horizontal frame
83 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
84 hf1->AddFrame(lf, lfh);
85 } else {
86 fLabel = new TGLabel(hf1, GetName());
87 hf1->AddFrame(fLabel, lh);
88 }
89
90 // entry
78cd2dc1 91 TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
5987168b 92 fEntry = new TGNumberEntry(hf1, 0, fNELength);
93 fEntry->SetHeight(fNEHeight);
94 fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
95 hf1->AddFrame(fEntry, elh);
96
97 fEntry->Associate(this);
98 fEntry->Connect("ValueSet(Long_t)",
99 "Reve::RGValuator", this, "EntryCallback()");
100
101
102 // slider
103 if(fShowSlider) {
104 fSlider = new TGHSlider(hfs, GetWidth(), kSlider1 | kScaleBoth);
105 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsLeft, 1,1,0,0));
106
107 fSlider->Associate(this);
108 fSlider->Connect("PositionChanged(Int_t)",
109 "Reve::RGValuator", this, "SliderCallback()");
110 }
111}
112
113void RGValuator::SetLimits(Float_t min, Float_t max, Int_t ndiv,
114 TGNumberFormat::EStyle nef)
115{
116 fMin = Float_t(min);
117 fMax = Float_t(max);
118 fSliderSteps = ndiv;
119 fEntry->SetFormat(nef);
120 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
121}
122
123void RGValuator::SetLimits(Int_t min, Int_t max)
124{
125 fMin = Float_t(min);
126 fMax = Float_t(max);
127 fEntry->SetFormat(TGNumberFormat::kNESInteger);
128 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
129
130 if(fSlider){
131 fSlider->SetRange(min, max);
132 fSliderSteps = max - min;
133 }
134}
135
136void RGValuator::EntryCallback()
137{
138 fValue = fEntry->GetNumber();
139 if(fSlider) {
140 Int_t pos;
141 if (fSliderSteps != -1) {
142 pos = Int_t( fSliderSteps*(fValue - fMin)/(fMax - fMin));
143 } else {
144 pos = Int_t(fValue - fMin);
145 }
146 pos += Int_t(fMin);
147 fSlider->SetPosition(pos);
148 // printf( "RGValuator::EntryCallback() slider pos %d n", pos);
149 }
150 ValueSet(fValue);
151}
152
153void RGValuator::SliderCallback()
154{
155 Double_t val;
156 if(fSliderSteps != -1)
157 val = fMin + fSlider->GetPosition()*Double_t((fMax-fMin))/fSliderSteps;
158 else
159 val = Double_t(fSlider->GetPosition());
160
161 fValue = val;
162 fEntry->SetNumber(fValue);
163 ValueSet(fValue);
164}
165
166
167void RGValuator::ValueSet(Double_t val)
168{
169 Emit("ValueSet(Double_t)", val);
170}
171
172void RGValuator::SetValue(Float_t val, Bool_t emit)
173{
174 fValue = val;
175 fEntry->SetNumber(fValue);
176
177 if(fSlider){
178 fSlider->SetPosition(Int_t((val-fMin)*fSliderSteps/(fMax-fMin)));
179 // printf("RGValuator::ValueSet slider pos %d\n",fSlider->GetPosition() );
180 }
181 if(emit)
182 ValueSet(val);
183}
184
185void RGValuator::SetToolTip(const Text_t* tip)
186{
187 fEntry->GetNumberEntry()->SetToolTipText(tip);
188}
189
78cd2dc1 190void RGValuator::SetEnabled(Bool_t state)
191{
192 fEntry->GetNumberEntry()->SetEnabled(state);
193 fEntry->GetButtonUp()->SetEnabled(state);
194 fEntry->GetButtonDown()->SetEnabled(state);
195 if(fSlider) {
196 if(state) fSlider->MapWindow();
197 else fSlider->UnmapWindow();
198 }
199}
200
5987168b 201/**************************************************************************/
202// RGDoubleValuator
203/**************************************************************************/
204
205ClassImp(RGDoubleValuator)
206
207RGDoubleValuator::RGDoubleValuator(const TGWindow *p, const char* title,
208 UInt_t w, UInt_t h) :
209 RGValuatorBase(p, title, w, h),
210
211 fMinEntry(0),
212 fMaxEntry(0),
213 fSlider(0)
214{}
215
216void RGDoubleValuator::Build()
217{
218 TGCompositeFrame *hf1, *hfs;
219 if(fShowSlider) {
220 SetLayoutManager(new TGVerticalLayout(this));
221 hf1 = new TGHorizontalFrame(this);
222 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
223 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
224 hfs = new TGHorizontalFrame(this);
225 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
226 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
227 } else {
228 hf1 = this;
229 hfs = this;
230 SetLayoutManager(new TGHorizontalLayout(this));
231 }
232
233 // label
234 TGLayoutHints* lh;
235 if(fAlignRight)
236 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,2,0,0);
237 else
238 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,2,0,0);
239
240 if(fLabelWidth > 0) {
241 TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize);
242 fLabel = new TGLabel(lf, GetName());
243 lf->AddFrame(fLabel, lh);
244 // add label frame to top horizontal frame
245 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
246 hf1->AddFrame(lf, lfh);
247 } else {
248 fLabel = new TGLabel(hf1, GetName());
249 hf1->AddFrame(fLabel);
250 }
251
252 // entries
253 fMinEntry = new TGNumberEntry(this, 0, fNELength);
254 fMinEntry->SetHeight(fNEHeight);
255 fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
78cd2dc1 256 hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
5987168b 257 fMinEntry->Connect("ValueSet(Long_t)",
258 "Reve::RGDoubleValuator", this, "MinEntryCallback()");
259 fMinEntry->Associate(this);
260
261 fMaxEntry = new TGNumberEntry(this, 0, fNELength);
262 fMaxEntry->SetHeight(fNEHeight);
263 fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
264 hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
265 fMaxEntry->Connect("ValueSet(Long_t)",
266 "Reve::RGDoubleValuator", this, "MaxEntryCallback()");
267 fMaxEntry->Associate(this);
268
269 // slider
270 if(fShowSlider) {
271 fSlider = new TGDoubleHSlider(hfs, GetWidth(), kDoubleScaleBoth);
272 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0,0,1,0));
273 fSlider->Associate(this);
274 fSlider->Connect("PositionChanged()",
275 "Reve::RGDoubleValuator", this, "SliderCallback()");
276 }
277}
278
279void RGDoubleValuator::SetLimits(Float_t min, Float_t max,
280 TGNumberFormat::EStyle nef)
281{
282 // printf("RGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n");
283 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
284 fMinEntry->SetFormat(nef);
285 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
286 fMaxEntry->SetFormat(nef);
287
288 if(fSlider) fSlider->SetRange(min, max);
289}
290
291void RGDoubleValuator::MinEntryCallback()
292{
293 if(GetMin() > GetMax())
294 fMaxEntry->SetNumber(GetMin());
295 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
296 ValueSet();
297}
298
299void RGDoubleValuator::MaxEntryCallback()
300{
301 if(GetMax() < GetMin())
302 fMinEntry->SetNumber(GetMax());
303 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
304 ValueSet();
305}
306
307void RGDoubleValuator::SliderCallback()
308{
309 Float_t minp, maxp;
310 fSlider->GetPosition(minp, maxp);
311 //printf("RGDoubleValuator::SliderCallback %f %f\n", minp, maxp);
312 fMinEntry->SetNumber(minp);
313 fMaxEntry->SetNumber(maxp);
314 ValueSet();
315}
316
317void RGDoubleValuator::SetValues(Float_t min, Float_t max, Bool_t emit)
318{
319 fMinEntry->SetNumber(min);
320 fMaxEntry->SetNumber(max);
321
322 if(fSlider) fSlider->SetPosition(min, max);
323 if(emit) ValueSet();
324}
325
326void RGDoubleValuator::ValueSet()
327{
328 Emit("ValueSet()");
329}