Logo ROOT   6.08/07
Reference Guide
TGNumberEntry.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Daniel Sigg 03/09/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, 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 
13 #ifndef ROOT_TGNumberEntry
14 #define ROOT_TGNumberEntry
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGNumberEntry, TGNumberEntryField and TGNumberFormat //
19 // //
20 // TGNumberEntry is a number entry input widget with up/down buttons. //
21 // TGNumberEntryField is a number entry input widget. //
22 // TGNumberFormat contains enum types to specify the numeric format . //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TGFrame
27 #include "TGFrame.h"
28 #endif
29 #ifndef ROOT_TGTextEntry
30 #include "TGTextEntry.h"
31 #endif
32 #ifndef ROOT_TGButton
33 #include "TGButton.h"
34 #endif
35 
36 
38 public:
39  enum EStyle { // Style of number entry field
40  kNESInteger = 0, // Integer
41  kNESRealOne = 1, // Fixed fraction real, one digit
42  kNESRealTwo = 2, // Fixed fraction real, two digit
43  kNESRealThree = 3, // Fixed fraction real, three digit
44  kNESRealFour = 4, // Fixed fraction real, four digit
45  kNESReal = 5, // Real number
46  kNESDegree = 6, // Degree
47  kNESMinSec = 7, // Minute:seconds
48  kNESHourMin = 8, // Hour:minutes
49  kNESHourMinSec = 9, // Hour:minute:seconds
50  kNESDayMYear = 10, // Day/month/year
51  kNESMDayYear = 11, // Month/day/year
52  kNESHex = 12 // Hex
53  };
54 
55  enum EAttribute { // Attributes of number entry field
56  kNEAAnyNumber = 0, // Any number
57  kNEANonNegative = 1, // Non-negative number
58  kNEAPositive = 2 // Positive number
59  };
60 
61  enum ELimit { // Limit selection of number entry field
62  kNELNoLimits = 0, // No limits
63  kNELLimitMin = 1, // Lower limit only
64  kNELLimitMax = 2, // Upper limit only
65  kNELLimitMinMax = 3 // Both lower and upper limits
66  };
67 
68  enum EStepSize { // Step for number entry field increase
69  kNSSSmall = 0, // Small step
70  kNSSMedium = 1, // Medium step
71  kNSSLarge = 2, // Large step
72  kNSSHuge = 3 // Huge step
73  };
74 
75  virtual ~TGNumberFormat() { }
76  ClassDef(TGNumberFormat,0) // Class defining namespace for several enums used by TGNumberEntry
77 };
78 
79 
81 
82 protected:
83  Bool_t fNeedsVerification; // Needs verification of input
84  EStyle fNumStyle; // Number style
85  EAttribute fNumAttr; // Number attribute
86  ELimit fNumLimits; // Limit attributes
87  Double_t fNumMin; // Lower limit
88  Double_t fNumMax; // Upper limit
89  Bool_t fStepLog; // Logarithmic steps for increase?
90 
91 public:
92  TGNumberEntryField(const TGWindow *p, Int_t id,
94  FontStruct_t font = GetDefaultFontStruct(),
96  Pixel_t back = GetWhitePixel());
97  TGNumberEntryField(const TGWindow *parent = 0,
98  Int_t id = -1, Double_t val = 0,
100  EAttribute attr = kNEAAnyNumber,
101  ELimit limits = kNELNoLimits,
102  Double_t min = 0, Double_t max = 1);
103 
104  virtual void SetNumber(Double_t val);
105  virtual void SetIntNumber(Long_t val);
106  virtual void SetTime(Int_t hour, Int_t min, Int_t sec);
107  virtual void SetDate(Int_t year, Int_t month, Int_t day);
108  virtual void SetHexNumber(ULong_t val);
109  virtual void SetText(const char* text, Bool_t emit = kTRUE);
110 
111  virtual Double_t GetNumber() const;
112  virtual Long_t GetIntNumber() const;
113  virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
114  virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const;
115  virtual ULong_t GetHexNumber() const;
116 
117  virtual Int_t GetCharWidth(const char* text = "0") const;
118  virtual void IncreaseNumber(EStepSize step = kNSSSmall,
119  Int_t sign = 1, Bool_t logstep = kFALSE);
120  virtual void SetFormat(EStyle style,
121  EAttribute attr = kNEAAnyNumber);
122  virtual void SetLimits(ELimit limits = kNELNoLimits,
123  Double_t min = 0, Double_t max = 1);
124  virtual void SetState(Bool_t state);
125  virtual void SetLogStep(Bool_t on = kTRUE) {
126  // Set logarithmic steps
127  fStepLog = on; }
128 
129  virtual EStyle GetNumStyle() const {
130  // Get the numerical style
131  return fNumStyle; }
132  virtual EAttribute GetNumAttr() const {
133  // Get the numerical attribute
134  return fNumAttr; }
135  virtual ELimit GetNumLimits() const {
136  // Get the numerialc limit attribute
137  return fNumLimits; }
138  virtual Double_t GetNumMin() const {
139  // Get the lower limit
140  return fNumMin; }
141  virtual Double_t GetNumMax() const {
142  // Get the upper limit
143  return fNumMax; }
144  virtual Bool_t IsLogStep() const {
145  // Is log step enabled?
146  return fStepLog; }
147 
148  virtual Bool_t HandleKey(Event_t* event);
149  virtual Bool_t HandleFocusChange (Event_t* event);
150  virtual void TextChanged(const char *text = 0);
151  virtual void ReturnPressed();
152  virtual void Layout();
153  virtual Bool_t IsEditable() const { return kFALSE; }
154  virtual void InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); } //*SIGNAL*
155  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
156 
157  ClassDef(TGNumberEntryField,0) // A text entry field used by a TGNumberEntry
158 };
159 
160 
161 
162 class TGNumberEntry : public TGCompositeFrame, public TGWidget,
163  public TGNumberFormat {
164 
165  // dummy data members - just to say about options for context menu
166  EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
167  EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
168  ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
169 
170 private:
171  const TGPicture *fPicUp; // Up arrow
172  const TGPicture *fPicDown; // Down arrow
173 
174  TGNumberEntry(const TGNumberEntry&); // not implemented
175  TGNumberEntry& operator=(const TGNumberEntry&); // not implemented
176 
177 protected:
178  TGNumberEntryField *fNumericEntry; // Number text entry field
179  TGButton *fButtonUp; // Button for increasing value
180  TGButton *fButtonDown; // Button for decreasing value
181  Bool_t fButtonToNum; // Send button messages to parent rather than number entry field
182 
183 public:
184  TGNumberEntry(const TGWindow *parent = 0, Double_t val = 0,
185  Int_t digitwidth = 5, Int_t id = -1,
187  EAttribute attr = kNEAAnyNumber,
188  ELimit limits = kNELNoLimits,
189  Double_t min = 0, Double_t max = 1);
190  virtual ~TGNumberEntry();
191 
192  virtual void SetNumber(Double_t val) {
193  // Set the numeric value (floating point representation)
194  fNumericEntry->SetNumber(val); }
195  virtual void SetIntNumber(Long_t val) {
196  // Set the numeric value (integer representation)
197  fNumericEntry->SetIntNumber(val); }
198  virtual void SetTime(Int_t hour, Int_t min, Int_t sec) {
199  // Set the numeric value (time format)
200  fNumericEntry->SetTime(hour, min, sec); }
201  virtual void SetDate(Int_t year, Int_t month, Int_t day) {
202  // Set the numeric value (date format)
203  fNumericEntry->SetDate(year, month, day); }
204  virtual void SetHexNumber(ULong_t val) {
205  // Set the numeric value (hex format)
206  fNumericEntry->SetHexNumber(val); }
207  virtual void SetText(const char* text) {
208  // Set the value (text format)
209  fNumericEntry->SetText(text); }
210  virtual void SetState(Bool_t enable = kTRUE);
211 
212  virtual Double_t GetNumber() const {
213  // Get the numeric value (floating point representation)
214  return fNumericEntry->GetNumber(); }
215  virtual Long_t GetIntNumber() const {
216  // Get the numeric value (integer representation)
217  return fNumericEntry->GetIntNumber (); }
218  virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
219  // Get the numeric value (time format)
220  fNumericEntry->GetTime(hour, min, sec); }
221  virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
222  // Get the numeric value (date format)
223  fNumericEntry->GetDate(year, month, day); }
224  virtual ULong_t GetHexNumber() const {
225  // Get the numeric value (hex format)
226  return fNumericEntry->GetHexNumber(); }
227  virtual void IncreaseNumber(EStepSize step = kNSSSmall,
228  Int_t sign = 1, Bool_t logstep = kFALSE) {
229  // Increase the number value
230  fNumericEntry->IncreaseNumber(step, sign, logstep); }
232  // Set the numerical format
233  fNumericEntry->SetFormat(style, attr); }
235  Double_t min = 0, Double_t max = 1) {
236  // Set the numerical limits.
237  fNumericEntry->SetLimits(limits, min, max); }
238 
239  virtual EStyle GetNumStyle() const {
240  // Get the numerical style
241  return fNumericEntry->GetNumStyle(); }
242  virtual EAttribute GetNumAttr() const {
243  // Get the numerical attribute
244  return fNumericEntry->GetNumAttr(); }
245  virtual ELimit GetNumLimits() const {
246  // Get the numerical limit attribute
247  return fNumericEntry->GetNumLimits(); }
248  virtual Double_t GetNumMin() const {
249  // Get the lower limit
250  return fNumericEntry->GetNumMin(); }
251  virtual Double_t GetNumMax() const {
252  // Get the upper limit
253  return fNumericEntry->GetNumMax(); }
254  virtual Bool_t IsLogStep() const {
255  // Is log step enabled?
256  return fNumericEntry->IsLogStep(); }
257  virtual void SetButtonToNum(Bool_t state);
258 
260  SetFormat(style, GetNumAttr()); } //*SUBMENU*
262  SetFormat(GetNumStyle(), attr); } //*SUBMENU*
264  SetLimits(limits, GetNumMin(), GetNumMax()); } //*SUBMENU*
265  void SetLimitValues(Double_t min = 0, Double_t max = 1) {
266  SetLimits(GetNumLimits(), min, max); } //*MENU*
267  virtual void SetLogStep(Bool_t on = kTRUE); //*TOGGLE* *GETTER=IsLogStep
268 
269  virtual void Associate(const TGWindow *w);
270  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
271  virtual void ValueChanged(Long_t val); //*SIGNAL*
272  virtual void ValueSet(Long_t val); //*SIGNAL*
273 
275  // Get the number entry field
276  return fNumericEntry; }
278  // Get the up button
279  return fButtonUp; }
281  // Get the down button
282  return fButtonDown; }
283 
284  virtual Bool_t IsEditable() const { return kFALSE; }
285 
286  UInt_t GetDefaultHeight() const { return fNumericEntry->GetDefaultHeight(); }
287  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
288  virtual TGLayoutManager *GetLayoutManager() const;
289 
290  ClassDef(TGNumberEntry,0) // Entry field widget for several numeric formats
291 };
292 
293 
295 protected:
296  TGNumberEntry *fBox; // pointer to numeric control box
297 
298 private:
299  TGNumberEntryLayout(const TGNumberEntryLayout&); // not implemented
300  TGNumberEntryLayout& operator=(const TGNumberEntryLayout&); // not implemented
301 
302 public:
304  virtual void Layout();
305  virtual TGDimension GetDefaultSize() const;
306 
307  ClassDef(TGNumberEntryLayout,0) // Layout manager for number entry widget
308 };
309 
310 
311 #endif
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
virtual ULong_t GetHexNumber() const
const TGPicture * fPicDown
Handle_t FontStruct_t
Definition: GuiTypes.h:40
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
Get the numeric value (time format).
virtual void SetTime(Int_t hour, Int_t min, Int_t sec)
Set the numeric value (time format).
virtual void SetDate(Int_t year, Int_t month, Int_t day)
Set the numeric value (date format).
virtual void SetLogStep(Bool_t on=kTRUE)
virtual void SetHexNumber(ULong_t val)
virtual void InvalidInput(const char *instr)
Bool_t fButtonToNum
virtual ELimit GetNumLimits() const
const char Option_t
Definition: RtypesCore.h:62
virtual Bool_t IsEditable() const
virtual void SetIntNumber(Long_t val)
Set the numeric value (integer representation).
virtual void SetNumber(Double_t val)
Handle_t GContext_t
Definition: GuiTypes.h:39
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
EAttribute fNumAttr
void SetNumLimits(ELimit limits=kNELNoLimits)
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
Get the numeric value (date format).
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
Increase the number value.
TGButton * GetButtonDown() const
TGButton * fButtonDown
virtual EAttribute GetNumAttr() const
virtual Double_t GetNumMin() const
virtual void SetFormat(EStyle style, EAttribute attr=kNEAAnyNumber)
Set the numerical format.
virtual Long_t GetIntNumber() const
Get the numeric value (integer representation).
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual Long_t GetIntNumber() const
TGNumberEntry * fBox
TGNumberEntryField * fNumericEntry
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual ELimit GetNumLimits() const
virtual Double_t GetNumMin() const
virtual void SetLimits(ELimit limits=kNELNoLimits, Double_t min=0, Double_t max=1)
Set the numerical limits.
virtual EStyle GetNumStyle() const
void SetLimitValues(Double_t min=0, Double_t max=1)
virtual Bool_t IsEditable() const
Return kTRUE if frame is being edited.
void SetNumStyle(EStyle style)
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetHexNumber(ULong_t val)
Set the numeric value (hex format).
TGButton * GetButtonUp() const
virtual void SetIntNumber(Long_t val)
virtual void SetTime(Int_t hour, Int_t min, Int_t sec)
TGNumberEntryLayout(TGNumberEntry *box)
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual void SetDate(Int_t year, Int_t month, Int_t day)
EAttribute fNumAttr
Definition: TGNumberEntry.h:85
long Long_t
Definition: RtypesCore.h:50
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
virtual Bool_t IsLogStep() const
double Double_t
Definition: RtypesCore.h:55
TText * text
virtual Double_t GetNumber() const
unsigned long ULong_t
Definition: RtypesCore.h:51
TCanvas * style()
Definition: style.C:1
TGButton * fButtonUp
virtual ~TGNumberFormat()
Definition: TGNumberEntry.h:75
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
TGNumberEntryField * GetNumberEntry() const
virtual Double_t GetNumMax() const
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
virtual Bool_t IsLogStep() const
virtual EAttribute GetNumAttr() const
virtual void SetText(const char *text)
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual EStyle GetNumStyle() const
virtual ULong_t GetHexNumber() const
Get the numeric value (hex format).
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
const TGPicture * fPicUp
virtual Double_t GetNumMax() const
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Set the value (text format).
UInt_t GetDefaultHeight() const
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const