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