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 };
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 = nullptr,
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 void SetText(const char* text, Bool_t emit = kTRUE) override;
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 void SetState(Bool_t state) override;
110
111 /** Set logarithmic steps */
112 virtual void SetLogStep(Bool_t on = kTRUE) { fStepLog = on; }
113
114 /** Get the numerical style */
115 virtual EStyle GetNumStyle() const { return fNumStyle; }
116
117 /** Get the numerical attribute */
118 virtual EAttribute GetNumAttr() const { return fNumAttr; }
119
120 /** Get the numerical limit attribute */
121 virtual ELimit GetNumLimits() const { return fNumLimits; }
122
123 /** Get the lower limit */
124 virtual Double_t GetNumMin() const { return fNumMin; }
125
126 /** Get the upper limit */
127 virtual Double_t GetNumMax() const { return fNumMax; }
128
129 /** Is log step enabled? */
130 virtual Bool_t IsLogStep() const { return fStepLog; }
131
132 Bool_t HandleKey(Event_t* event) override;
134 void TextChanged(const char *text = nullptr) override;
135 void ReturnPressed() override;
136 void Layout() override;
137 Bool_t IsEditable() const override { return kFALSE; }
138 virtual void InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); } //*SIGNAL*
139 void SavePrimitive(std::ostream &out, Option_t * = "") override;
140
141 ClassDefOverride(TGNumberEntryField,0) // A text entry field used by a TGNumberEntry
142};
143
144
145
147 public TGNumberFormat {
148
149 // dummy data members - just to say about options for context menu
150 EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
151 EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
152 ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
153
154private:
155 const TGPicture *fPicUp; ///< Up arrow
156 const TGPicture *fPicDown; ///< Down arrow
157
158 TGNumberEntry(const TGNumberEntry&) = delete;
160
161protected:
162 TGNumberEntryField *fNumericEntry; ///< Number text entry field
163 TGButton *fButtonUp; ///< Button for increasing value
164 TGButton *fButtonDown; ///< Button for decreasing value
165 Bool_t fButtonToNum; ///< Send button messages to parent rather than number entry field
166
167public:
168 TGNumberEntry(const TGWindow *parent = nullptr, Double_t val = 0,
169 Int_t digitwidth = 5, Int_t id = -1,
172 ELimit limits = kNELNoLimits,
173 Double_t min = 0, Double_t max = 1);
174 virtual ~TGNumberEntry();
175
176 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE) {
177 // Set the numeric value (floating point representation)
178 fNumericEntry->SetNumber(val, emit); }
179 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE) {
180 // Set the numeric value (integer representation)
181 fNumericEntry->SetIntNumber(val, emit); }
182 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE) {
183 // Set the numeric value (time format)
184 fNumericEntry->SetTime(hour, min, sec, emit); }
185 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE) {
186 // Set the numeric value (date format)
187 fNumericEntry->SetDate(year, month, day, emit); }
188 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE) {
189 // Set the numeric value (hex format)
190 fNumericEntry->SetHexNumber(val, emit); }
191 virtual void SetText(const char* text, Bool_t emit = kTRUE) {
192 // Set the value (text format)
193 fNumericEntry->SetText(text, emit); }
194 virtual void SetState(Bool_t enable = kTRUE);
195
196 virtual Double_t GetNumber() const {
197 // Get the numeric value (floating point representation)
198 return fNumericEntry->GetNumber(); }
199 virtual Long_t GetIntNumber() const {
200 // Get the numeric value (integer representation)
201 return fNumericEntry->GetIntNumber (); }
202 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
203 // Get the numeric value (time format)
204 fNumericEntry->GetTime(hour, min, sec); }
205 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
206 // Get the numeric value (date format)
207 fNumericEntry->GetDate(year, month, day); }
208 virtual ULong_t GetHexNumber() const {
209 // Get the numeric value (hex format)
210 return fNumericEntry->GetHexNumber(); }
211 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
212 Int_t sign = 1, Bool_t logstep = kFALSE) {
213 // Increase the number value
214 fNumericEntry->IncreaseNumber(step, sign, logstep); }
216 // Set the numerical format
219 Double_t min = 0, Double_t max = 1) {
220 // Set the numerical limits.
221 fNumericEntry->SetLimits(limits, min, max); }
222
223 virtual EStyle GetNumStyle() const {
224 // Get the numerical style
225 return fNumericEntry->GetNumStyle(); }
226 virtual EAttribute GetNumAttr() const {
227 // Get the numerical attribute
228 return fNumericEntry->GetNumAttr(); }
229 virtual ELimit GetNumLimits() const {
230 // Get the numerical limit attribute
231 return fNumericEntry->GetNumLimits(); }
232 virtual Double_t GetNumMin() const {
233 // Get the lower limit
234 return fNumericEntry->GetNumMin(); }
235 virtual Double_t GetNumMax() const {
236 // Get the upper limit
237 return fNumericEntry->GetNumMax(); }
238 virtual Bool_t IsLogStep() const {
239 // Is log step enabled?
240 return fNumericEntry->IsLogStep(); }
241 virtual void SetButtonToNum(Bool_t state);
242
244 SetFormat(style, GetNumAttr()); } //*SUBMENU*
246 SetFormat(GetNumStyle(), attr); } //*SUBMENU*
248 SetLimits(limits, GetNumMin(), GetNumMax()); } //*SUBMENU*
249 void SetLimitValues(Double_t min = 0, Double_t max = 1) {
250 SetLimits(GetNumLimits(), min, max); } //*MENU*
251 virtual void SetLogStep(Bool_t on = kTRUE); //*TOGGLE* *GETTER=IsLogStep
252
253 void Associate(const TGWindow *w) override;
254 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
255 virtual void ValueChanged(Long_t val); //*SIGNAL*
256 virtual void ValueSet(Long_t val); //*SIGNAL*
257 virtual void Modified(); //*SIGNAL*
258
259 /** Get the number entry field */
261 /** Get the up button */
262 TGButton *GetButtonUp() const { return fButtonUp; }
263 /** Get the down button */
264 TGButton *GetButtonDown() const { return fButtonDown; }
265
266 Bool_t IsEditable() const override { return kFALSE; }
267
269 void SavePrimitive(std::ostream &out, Option_t * = "") override;
270 TGLayoutManager *GetLayoutManager() const override;
271
272 ClassDefOverride(TGNumberEntry,0) // Entry field widget for several numeric formats
273};
274
275
277protected:
278 TGNumberEntry *fBox; // pointer to numeric control box
279
280private:
283
284public:
286 void Layout() override;
287 TGDimension GetDefaultSize() const override;
288
289 ClassDefOverride(TGNumberEntryLayout,0) // Layout manager for number entry widget
290};
291
292
293#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
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
unsigned long ULong_t
Definition RtypesCore.h:55
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 ~TGNumberEntry()
Destructs a numeric entry widget.
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)
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.
@ 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