Logo ROOT  
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-2021, 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#include "TGFrame.h"
18#include "TGTextEntry.h"
19#include "TGButton.h"
20
21
23public:
24 enum EStyle { ///< Style of number entry field
25 kNESInteger = 0, ///< Integer
26 kNESRealOne = 1, ///< Fixed fraction real, one digit
27 kNESRealTwo = 2, ///< Fixed fraction real, two digit
28 kNESRealThree = 3, ///< Fixed fraction real, three digit
29 kNESRealFour = 4, ///< Fixed fraction real, four digit
30 kNESReal = 5, ///< Real number
31 kNESDegree = 6, ///< Degree
32 kNESMinSec = 7, ///< Minute:seconds
33 kNESHourMin = 8, ///< Hour:minutes
34 kNESHourMinSec = 9, ///< Hour:minute:seconds
35 kNESDayMYear = 10, ///< Day/month/year
36 kNESMDayYear = 11, ///< Month/day/year
37 kNESHex = 12 ///< Hex
38 };
39
40 enum EAttribute { ///< Attributes of number entry field
41 kNEAAnyNumber = 0, ///< Any number
42 kNEANonNegative = 1, ///< Non-negative number
43 kNEAPositive = 2 ///< Positive number
44 };
45
46 enum ELimit { ///< Limit selection of number entry field
47 kNELNoLimits = 0, ///< No limits
48 kNELLimitMin = 1, ///< Lower limit only
49 kNELLimitMax = 2, ///< Upper limit only
50 kNELLimitMinMax = 3 ///< Both lower and upper limits
51 };
52
53 enum EStepSize { ///< Step for number entry field increase
54 kNSSSmall = 0, ///< Small step
55 kNSSMedium = 1, ///< Medium step
56 kNSSLarge = 2, ///< Large step
57 kNSSHuge = 3 ///< Huge step
58 };
59
60 virtual ~TGNumberFormat() { }
61 ClassDef(TGNumberFormat,0) // Class defining namespace for several enums used by TGNumberEntry
62};
63
64
66
67protected:
68 Bool_t fNeedsVerification; ///< Needs verification of input
69 EStyle fNumStyle; ///< Number style
70 EAttribute fNumAttr; ///< Number attribute
71 ELimit fNumLimits; ///< Limit attributes
72 Double_t fNumMin; ///< Lower limit
73 Double_t fNumMax; ///< Upper limit
74 Bool_t fStepLog; ///< Logarithmic steps for increase?
75
76public:
78 Double_t val, GContext_t norm,
81 Pixel_t back = GetWhitePixel());
82 TGNumberEntryField(const TGWindow *parent = 0,
83 Int_t id = -1, Double_t val = 0,
86 ELimit limits = kNELNoLimits,
87 Double_t min = 0, Double_t max = 1);
88
89 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE);
90 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE);
91 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE);
92 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE);
93 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE);
94 virtual void SetText(const char* text, Bool_t emit = kTRUE);
95
96 virtual Double_t GetNumber() const;
97 virtual Long_t GetIntNumber() const;
98 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
99 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const;
100 virtual ULong_t GetHexNumber() const;
101
102 virtual Int_t GetCharWidth(const char* text = "0") const;
103 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
104 Int_t sign = 1, Bool_t logstep = kFALSE);
105 virtual void SetFormat(EStyle style,
107 virtual void SetLimits(ELimit limits = kNELNoLimits,
108 Double_t min = 0, Double_t max = 1);
109 virtual void SetState(Bool_t state);
110 virtual void SetLogStep(Bool_t on = kTRUE) {
111 // Set logarithmic steps
112 fStepLog = on; }
113
114 virtual EStyle GetNumStyle() const {
115 // Get the numerical style
116 return fNumStyle; }
117 virtual EAttribute GetNumAttr() const {
118 // Get the numerical attribute
119 return fNumAttr; }
120 virtual ELimit GetNumLimits() const {
121 // Get the numerical limit attribute
122 return fNumLimits; }
123 virtual Double_t GetNumMin() const {
124 // Get the lower limit
125 return fNumMin; }
126 virtual Double_t GetNumMax() const {
127 // Get the upper limit
128 return fNumMax; }
129 virtual Bool_t IsLogStep() const {
130 // Is log step enabled?
131 return fStepLog; }
132
133 virtual Bool_t HandleKey(Event_t* event);
135 virtual void TextChanged(const char *text = 0);
136 virtual void ReturnPressed();
137 virtual void Layout();
138 virtual Bool_t IsEditable() const { return kFALSE; }
139 virtual void InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); } //*SIGNAL*
140 virtual void SavePrimitive(std::ostream &out, Option_t * = "");
141
142 ClassDef(TGNumberEntryField,0) // A text entry field used by a TGNumberEntry
143};
144
145
146
148 public TGNumberFormat {
149
150 // dummy data members - just to say about options for context menu
151 EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
152 EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
153 ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
154
155private:
156 const TGPicture *fPicUp; ///< Up arrow
157 const TGPicture *fPicDown; ///< Down arrow
158
159 TGNumberEntry(const TGNumberEntry&) = delete;
161
162protected:
163 TGNumberEntryField *fNumericEntry; ///< Number text entry field
164 TGButton *fButtonUp; ///< Button for increasing value
165 TGButton *fButtonDown; ///< Button for decreasing value
166 Bool_t fButtonToNum; ///< Send button messages to parent rather than number entry field
167
168public:
169 TGNumberEntry(const TGWindow *parent = nullptr, Double_t val = 0,
170 Int_t digitwidth = 5, Int_t id = -1,
173 ELimit limits = kNELNoLimits,
174 Double_t min = 0, Double_t max = 1);
175 virtual ~TGNumberEntry();
176
177 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE) {
178 // Set the numeric value (floating point representation)
179 fNumericEntry->SetNumber(val, emit); }
180 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE) {
181 // Set the numeric value (integer representation)
182 fNumericEntry->SetIntNumber(val, emit); }
183 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE) {
184 // Set the numeric value (time format)
185 fNumericEntry->SetTime(hour, min, sec, emit); }
186 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE) {
187 // Set the numeric value (date format)
188 fNumericEntry->SetDate(year, month, day, emit); }
189 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE) {
190 // Set the numeric value (hex format)
191 fNumericEntry->SetHexNumber(val, emit); }
192 virtual void SetText(const char* text, Bool_t emit = kTRUE) {
193 // Set the value (text format)
194 fNumericEntry->SetText(text, emit); }
195 virtual void SetState(Bool_t enable = kTRUE);
196
197 virtual Double_t GetNumber() const {
198 // Get the numeric value (floating point representation)
199 return fNumericEntry->GetNumber(); }
200 virtual Long_t GetIntNumber() const {
201 // Get the numeric value (integer representation)
202 return fNumericEntry->GetIntNumber (); }
203 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
204 // Get the numeric value (time format)
205 fNumericEntry->GetTime(hour, min, sec); }
206 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
207 // Get the numeric value (date format)
208 fNumericEntry->GetDate(year, month, day); }
209 virtual ULong_t GetHexNumber() const {
210 // Get the numeric value (hex format)
211 return fNumericEntry->GetHexNumber(); }
212 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
213 Int_t sign = 1, Bool_t logstep = kFALSE) {
214 // Increase the number value
215 fNumericEntry->IncreaseNumber(step, sign, logstep); }
217 // Set the numerical format
218 fNumericEntry->SetFormat(style, attr); }
220 Double_t min = 0, Double_t max = 1) {
221 // Set the numerical limits.
222 fNumericEntry->SetLimits(limits, min, max); }
223
224 virtual EStyle GetNumStyle() const {
225 // Get the numerical style
226 return fNumericEntry->GetNumStyle(); }
227 virtual EAttribute GetNumAttr() const {
228 // Get the numerical attribute
229 return fNumericEntry->GetNumAttr(); }
230 virtual ELimit GetNumLimits() const {
231 // Get the numerical limit attribute
232 return fNumericEntry->GetNumLimits(); }
233 virtual Double_t GetNumMin() const {
234 // Get the lower limit
235 return fNumericEntry->GetNumMin(); }
236 virtual Double_t GetNumMax() const {
237 // Get the upper limit
238 return fNumericEntry->GetNumMax(); }
239 virtual Bool_t IsLogStep() const {
240 // Is log step enabled?
241 return fNumericEntry->IsLogStep(); }
242 virtual void SetButtonToNum(Bool_t state);
243
245 SetFormat(style, GetNumAttr()); } //*SUBMENU*
247 SetFormat(GetNumStyle(), attr); } //*SUBMENU*
249 SetLimits(limits, GetNumMin(), GetNumMax()); } //*SUBMENU*
250 void SetLimitValues(Double_t min = 0, Double_t max = 1) {
251 SetLimits(GetNumLimits(), min, max); } //*MENU*
252 virtual void SetLogStep(Bool_t on = kTRUE); //*TOGGLE* *GETTER=IsLogStep
253
254 virtual void Associate(const TGWindow *w);
255 virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
256 virtual void ValueChanged(Long_t val); //*SIGNAL*
257 virtual void ValueSet(Long_t val); //*SIGNAL*
258 virtual void Modified(); //*SIGNAL*
259
261 // Get the number entry field
262 return fNumericEntry; }
264 // Get the up button
265 return fButtonUp; }
267 // Get the down button
268 return fButtonDown; }
269
270 virtual Bool_t IsEditable() const { return kFALSE; }
271
273 virtual void SavePrimitive(std::ostream &out, Option_t * = "");
274 virtual TGLayoutManager *GetLayoutManager() const;
275
276 ClassDef(TGNumberEntry,0) // Entry field widget for several numeric formats
277};
278
279
281protected:
282 TGNumberEntry *fBox; // pointer to numeric control box
283
284private:
287
288public:
290 virtual void Layout();
291 virtual TGDimension GetDefaultSize() const;
292
293 ClassDef(TGNumberEntryLayout,0) // Layout manager for number entry widget
294};
295
296
297#endif
@ kSunkenFrame
Definition: GuiTypes.h:383
@ kDoubleBorder
Definition: GuiTypes.h:385
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned long ULong_t
Definition: RtypesCore.h:55
long Long_t
Definition: RtypesCore.h:54
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
A button abstract base class.
Definition: TGButton.h:68
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:709
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:191
Frame layout manager.
Definition: TGLayout.h:135
virtual void SetHexNumber(ULong_t val, Bool_t emit=kTRUE)
Set the numeric value (hex format).
ELimit fNumLimits
Limit attributes.
Definition: TGNumberEntry.h:71
virtual void InvalidInput(const char *instr)
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Set the value (text format).
virtual Double_t GetNumMin() const
Bool_t fNeedsVerification
Needs verification of input.
Definition: TGNumberEntry.h:68
virtual void SetFormat(EStyle style, EAttribute attr=kNEAAnyNumber)
Set the numerical format.
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a number entry widget as a C++ statement(s) on output stream out.
virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit=kTRUE)
Set the numeric value (date format).
virtual Bool_t IsEditable() const
virtual Long_t GetIntNumber() const
Get the numeric value (integer representation).
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
Set the numeric value (floating point representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void ReturnPressed()
Return was pressed.
EStyle fNumStyle
Number style.
Definition: TGNumberEntry.h:69
virtual Bool_t IsLogStep() const
virtual Bool_t HandleKey(Event_t *event)
Handle keys.
virtual EStyle GetNumStyle() const
virtual Double_t GetNumMax() const
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
Get the numeric value (date format).
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change.
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
Increase the number value.
virtual void SetState(Bool_t state)
Set the active state.
virtual ULong_t GetHexNumber() const
Get the numeric value (hex format).
virtual void SetIntNumber(Long_t val, Bool_t emit=kTRUE)
Set the numeric value (integer representation).
virtual void SetLimits(ELimit limits=kNELNoLimits, Double_t min=0, Double_t max=1)
Set the numerical limits.
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
Get the numeric value (time format).
virtual void TextChanged(const char *text=0)
Text has changed message.
virtual void SetLogStep(Bool_t on=kTRUE)
virtual EAttribute GetNumAttr() const
TGNumberEntryField(const TGWindow *p, Int_t id, Double_t val, GContext_t norm, FontStruct_t font=GetDefaultFontStruct(), UInt_t option=kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Constructs a number entry field.
EAttribute fNumAttr
Number attribute.
Definition: TGNumberEntry.h:70
Double_t fNumMin
Lower limit.
Definition: TGNumberEntry.h:72
virtual Int_t GetCharWidth(const char *text="0") const
Get the text width in pixels.
virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit=kTRUE)
Set the numeric value (time format).
virtual void Layout()
Layout.
Bool_t fStepLog
Logarithmic steps for increase?
Definition: TGNumberEntry.h:74
Double_t fNumMax
Upper limit.
Definition: TGNumberEntry.h:73
virtual ELimit GetNumLimits() const
TGNumberEntry * fBox
TGNumberEntryLayout(TGNumberEntry *box)
virtual TGDimension GetDefaultSize() const
Return the default size of the numeric control box.
TGNumberEntryLayout(const TGNumberEntryLayout &)=delete
TGNumberEntryLayout & operator=(const TGNumberEntryLayout &)=delete
virtual void Layout()
Layout the internal GUI elements in use.
TGNumberEntry is a number entry input widget with up/down buttons.
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
TGButton * fButtonDown
Button for decreasing value.
virtual Double_t GetNumMax() const
virtual Bool_t IsLogStep() const
virtual EStyle GetNumStyle() const
Bool_t fButtonToNum
Send button messages to parent rather than number entry field.
EAttribute fNumAttr
virtual ULong_t GetHexNumber() const
virtual ~TGNumberEntry()
Destructs a numeric entry widget.
virtual Bool_t IsEditable() const
Return kTRUE if frame is being edited.
virtual void SetButtonToNum(Bool_t state)
Send button messages to the number field (true) or parent widget (false).
virtual void ValueSet(Long_t val)
Emit ValueSet(Long_t) signal.
UInt_t GetDefaultHeight() const
TGNumberEntryField * GetNumberEntry() const
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
const TGPicture * fPicUp
Up arrow.
virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit=kTRUE)
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
TGNumberEntry(const TGNumberEntry &)=delete
virtual ELimit GetNumLimits() const
virtual void SetText(const char *text, Bool_t emit=kTRUE)
virtual void SetIntNumber(Long_t val, Bool_t emit=kTRUE)
virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit=kTRUE)
virtual void SetLogStep(Bool_t on=kTRUE)
Set log steps.
const TGPicture * fPicDown
Down arrow.
void SetNumLimits(ELimit limits=kNELNoLimits)
virtual void ValueChanged(Long_t val)
Emit ValueChanged(Long_t) signal.
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
TGButton * GetButtonDown() const
virtual Long_t GetIntNumber() const
virtual EAttribute GetNumAttr() const
virtual void Modified()
Emit Modified() signal.
TGNumberEntry & operator=(const TGNumberEntry &)=delete
void SetLimitValues(Double_t min=0, Double_t max=1)
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process the up/down button messages.
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
virtual Double_t GetNumMin() const
TGNumberEntryField * fNumericEntry
Number text entry field.
virtual void SetHexNumber(ULong_t val, Bool_t emit=kTRUE)
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a number entry widget as a C++ statement(s) on output stream out.
TGButton * fButtonUp
Button for increasing value.
TGButton * GetButtonUp() const
virtual TGLayoutManager * GetLayoutManager() const
Return layout manager.
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
void SetNumStyle(EStyle style)
@ kNEAPositive
Positive number.
Definition: TGNumberEntry.h:43
@ kNEANonNegative
Non-negative number.
Definition: TGNumberEntry.h:42
@ kNEAAnyNumber
Attributes of number entry field.
Definition: TGNumberEntry.h:41
@ kNESRealOne
Fixed fraction real, one digit.
Definition: TGNumberEntry.h:26
@ kNESHourMin
Hour:minutes.
Definition: TGNumberEntry.h:33
@ kNESDegree
Degree.
Definition: TGNumberEntry.h:31
@ kNESMDayYear
Month/day/year.
Definition: TGNumberEntry.h:36
@ kNESReal
Real number.
Definition: TGNumberEntry.h:30
@ kNESRealThree
Fixed fraction real, three digit.
Definition: TGNumberEntry.h:28
@ kNESInteger
Style of number entry field.
Definition: TGNumberEntry.h:25
@ kNESRealFour
Fixed fraction real, four digit.
Definition: TGNumberEntry.h:29
@ kNESDayMYear
Day/month/year.
Definition: TGNumberEntry.h:35
@ kNESRealTwo
Fixed fraction real, two digit.
Definition: TGNumberEntry.h:27
@ kNESHourMinSec
Hour:minute:seconds.
Definition: TGNumberEntry.h:34
@ kNESMinSec
Minute:seconds.
Definition: TGNumberEntry.h:32
virtual ~TGNumberFormat()
Definition: TGNumberEntry.h:60
@ kNSSHuge
Huge step.
Definition: TGNumberEntry.h:57
@ kNSSMedium
Medium step.
Definition: TGNumberEntry.h:55
@ kNSSLarge
Large step.
Definition: TGNumberEntry.h:56
@ kNSSSmall
Step for number entry field increase.
Definition: TGNumberEntry.h:54
@ kNELNoLimits
Limit selection of number entry field.
Definition: TGNumberEntry.h:47
@ kNELLimitMax
Upper limit only.
Definition: TGNumberEntry.h:49
@ kNELLimitMin
Lower limit only.
Definition: TGNumberEntry.h:48
@ kNELLimitMinMax
Both lower and upper limits.
Definition: TGNumberEntry.h:50
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition: TGPicture.h:25
A TGTextEntry is a one line text input widget.
Definition: TGTextEntry.h:24
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
The widget base class.
Definition: TGWidget.h:43
ROOT GUI Window base class.
Definition: TGWindow.h:23
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TText * text
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
Event structure.
Definition: GuiTypes.h:174
TCanvas * style()
Definition: style.C:1