Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 kNESMinSecCent = 13 ///< Minute:seconds.centiseconds
39 };
40
41 enum EAttribute { ///< Attributes of number entry field
42 kNEAAnyNumber = 0, ///< Any number
43 kNEANonNegative = 1, ///< Non-negative number
44 kNEAPositive = 2 ///< Positive number
45 };
46
47 enum ELimit { ///< Limit selection of number entry field
48 kNELNoLimits = 0, ///< No limits
49 kNELLimitMin = 1, ///< Lower limit only
50 kNELLimitMax = 2, ///< Upper limit only
51 kNELLimitMinMax = 3 ///< Both lower and upper limits
52 };
53
54 enum EStepSize { ///< Step for number entry field increase
55 kNSSSmall = 0, ///< Small step
56 kNSSMedium = 1, ///< Medium step
57 kNSSLarge = 2, ///< Large step
58 kNSSHuge = 3 ///< Huge step
59 };
60
61 virtual ~TGNumberFormat() {}
62 ClassDef(TGNumberFormat,0) // Class defining namespace for several enums used by TGNumberEntry
63};
64
65
67
68protected:
69 Bool_t fNeedsVerification; ///< Needs verification of input
70 EStyle fNumStyle; ///< Number style
71 EAttribute fNumAttr; ///< Number attribute
72 ELimit fNumLimits; ///< Limit attributes
73 Double_t fNumMin; ///< Lower limit
74 Double_t fNumMax; ///< Upper limit
75 Bool_t fStepLog; ///< Logarithmic steps for increase?
76
77public:
79 Double_t val, GContext_t norm,
82 Pixel_t back = GetWhitePixel());
83 TGNumberEntryField(const TGWindow *parent = nullptr,
84 Int_t id = -1, Double_t val = 0,
87 ELimit limits = kNELNoLimits,
88 Double_t min = 0, Double_t max = 1);
89
90 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE);
91 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE);
92 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE);
93 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE);
94 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE);
95 void SetText(const char* text, Bool_t emit = kTRUE) override;
96
97 virtual Double_t GetNumber() const;
98 virtual Long_t GetIntNumber() const;
99 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
100 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const;
101 virtual ULong_t GetHexNumber() const;
102
103 virtual Int_t GetCharWidth(const char* text = "0") const;
104 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
105 Int_t sign = 1, Bool_t logstep = kFALSE);
106 virtual void SetFormat(EStyle style,
108 virtual void SetLimits(ELimit limits = kNELNoLimits,
109 Double_t min = 0, Double_t max = 1);
110 void SetState(Bool_t state) override;
111
112 /** Set logarithmic steps */
113 virtual void SetLogStep(Bool_t on = kTRUE) { fStepLog = on; }
114
115 /** Get the numerical style */
116 virtual EStyle GetNumStyle() const { return fNumStyle; }
117
118 /** Get the numerical attribute */
119 virtual EAttribute GetNumAttr() const { return fNumAttr; }
120
121 /** Get the numerical limit attribute */
122 virtual ELimit GetNumLimits() const { return fNumLimits; }
123
124 /** Get the lower limit */
125 virtual Double_t GetNumMin() const { return fNumMin; }
126
127 /** Get the upper limit */
128 virtual Double_t GetNumMax() const { return fNumMax; }
129
130 /** Is log step enabled? */
131 virtual Bool_t IsLogStep() const { return fStepLog; }
132
133 Bool_t HandleKey(Event_t* event) override;
134 Bool_t HandleFocusChange (Event_t* event) override;
135 void TextChanged(const char *text = nullptr) override;
136 void ReturnPressed() override;
137 void Layout() override;
138 Bool_t IsEditable() const override { return kFALSE; }
139 virtual void InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); } //*SIGNAL*
140 void SavePrimitive(std::ostream &out, Option_t * = "") override;
141
142 ClassDefOverride(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",13="Min:Sec.Centisec")}*
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 ~TGNumberEntry() override;
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
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 void Associate(const TGWindow *w) override;
255 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
256 virtual void ValueChanged(Long_t val); //*SIGNAL*
257 virtual void ValueSet(Long_t val); //*SIGNAL*
258 virtual void Modified(); //*SIGNAL*
259
260 /** Get the number entry field */
262 /** Get the up button */
263 TGButton *GetButtonUp() const { return fButtonUp; }
264 /** Get the down button */
265 TGButton *GetButtonDown() const { return fButtonDown; }
266
267 Bool_t IsEditable() const override { return kFALSE; }
268
270 void SavePrimitive(std::ostream &out, Option_t * = "") override;
271 TGLayoutManager *GetLayoutManager() const override;
272
273 ClassDefOverride(TGNumberEntry,0) // Entry field widget for several numeric formats
274};
275
276
278protected:
279 TGNumberEntry *fBox; // pointer to numeric control box
280
281private:
284
285public:
287 void Layout() override;
288 TGDimension GetDefaultSize() const override;
289
290 ClassDefOverride(TGNumberEntryLayout,0) // Layout manager for number entry widget
291};
292
293
294#endif
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
@ kSunkenFrame
Definition GuiTypes.h:383
@ kDoubleBorder
Definition GuiTypes.h:385
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
bool Bool_t
Definition RtypesCore.h:63
long Longptr_t
Definition RtypesCore.h:82
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:337
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t style
Option_t Option_t TPoint TPoint const char text
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.
virtual void InvalidInput(const char *instr)
virtual Double_t GetNumMin() const
Get the lower limit.
Bool_t fNeedsVerification
Needs verification of input.
virtual void SetFormat(EStyle style, EAttribute attr=kNEAAnyNumber)
Set the numerical format.
virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit=kTRUE)
Set the numeric value (date format).
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).
EStyle fNumStyle
Number style.
virtual Bool_t IsLogStep() const
Is log step enabled?
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change.
void SetState(Bool_t state) override
Set the active state.
virtual EStyle GetNumStyle() const
Get the numerical style.
Bool_t IsEditable() const override
void ReturnPressed() override
Return was pressed.
virtual Double_t GetNumMax() const
Get the upper limit.
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
Get the numeric value (date format).
void TextChanged(const char *text=nullptr) override
Text has changed message.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a number entry widget as a C++ statement(s) on output stream out.
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
Increase the number value.
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).
Bool_t HandleKey(Event_t *event) override
Handle keys.
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 SetLogStep(Bool_t on=kTRUE)
Set logarithmic steps.
virtual EAttribute GetNumAttr() const
Get the numerical attribute.
void SetText(const char *text, Bool_t emit=kTRUE) override
Set the value (text format).
EAttribute fNumAttr
Number attribute.
Double_t fNumMin
Lower limit.
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).
Bool_t fStepLog
Logarithmic steps for increase?
Double_t fNumMax
Upper limit.
void Layout() override
Layout.
virtual ELimit GetNumLimits() const
Get the numerical limit attribute.
TGNumberEntry * fBox
TGNumberEntryLayout(TGNumberEntry *box)
TGDimension GetDefaultSize() const override
Return the default size of the numeric control box.
TGNumberEntryLayout(const TGNumberEntryLayout &)=delete
TGNumberEntryLayout & operator=(const TGNumberEntryLayout &)=delete
void Layout() override
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 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.
TGNumberEntryField * GetNumberEntry() const
Get the number entry field.
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)
~TGNumberEntry() override
Destructs a numeric entry widget.
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)
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process the up/down button messages.
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 SavePrimitive(std::ostream &out, Option_t *="") override
Save a number entry widget as a C++ statement(s) on output stream out.
void SetNumLimits(ELimit limits=kNELNoLimits)
virtual void ValueChanged(Long_t val)
Emit ValueChanged(Long_t) signal.
TGLayoutManager * GetLayoutManager() const override
Return layout manager.
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
void Associate(const TGWindow *w) override
Make w the window that will receive the generated messages.
TGButton * GetButtonDown() const
Get the down button.
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)
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)
Bool_t IsEditable() const override
Return kTRUE if frame is being edited.
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
TGButton * fButtonUp
Button for increasing value.
TGButton * GetButtonUp() const
Get the up button.
UInt_t GetDefaultHeight() const override
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
void SetNumStyle(EStyle style)
@ kNEAPositive
Positive number.
@ kNEANonNegative
Non-negative number.
@ kNEAAnyNumber
Attributes of number entry field.
@ kNESRealOne
Fixed fraction real, one digit.
@ kNESHourMin
Hour:minutes.
@ kNESDegree
Degree.
@ kNESMDayYear
Month/day/year.
@ kNESReal
Real number.
@ kNESRealThree
Fixed fraction real, three digit.
@ kNESInteger
Style of number entry field.
@ kNESRealFour
Fixed fraction real, four digit.
@ kNESDayMYear
Day/month/year.
@ kNESMinSecCent
Minute:seconds.centiseconds.
@ kNESRealTwo
Fixed fraction real, two digit.
@ kNESHourMinSec
Hour:minute:seconds.
@ kNESMinSec
Minute:seconds.
virtual ~TGNumberFormat()
@ kNSSHuge
Huge step.
@ kNSSMedium
Medium step.
@ kNSSLarge
Large step.
@ kNSSSmall
Step for number entry field increase.
@ kNELNoLimits
Limit selection of number entry field.
@ kNELLimitMax
Upper limit only.
@ kNELLimitMin
Lower limit only.
@ kNELLimitMinMax
Both lower and upper limits.
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
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