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-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
32public:
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
76protected:
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
85public:
87 Double_t val, GContext_t norm,
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,
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
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
164private:
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
171protected:
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
177public:
178 TGNumberEntry(const TGWindow *parent = 0, Double_t val = 0,
179 Int_t digitwidth = 5, Int_t id = -1,
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)
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)
201 virtual void SetText(const char* text) {
202 // Set the value (text format)
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
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
289protected:
290 TGNumberEntry *fBox; // pointer to numeric control box
291
292private:
293 TGNumberEntryLayout(const TGNumberEntryLayout&); // not implemented
295
296public:
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
@ kSunkenFrame
Definition: GuiTypes.h:383
@ kDoubleBorder
Definition: GuiTypes.h:385
Handle_t GContext_t
Definition: GuiTypes.h:37
Handle_t FontStruct_t
Definition: GuiTypes.h:38
ULong_t Pixel_t
Definition: GuiTypes.h:39
const Bool_t kFALSE
Definition: RtypesCore.h:90
unsigned long ULong_t
Definition: RtypesCore.h:53
long Long_t
Definition: RtypesCore.h:52
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassDef(name, id)
Definition: Rtypes.h:322
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:693
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
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
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 SetTime(Int_t hour, Int_t min, Int_t sec)
Set the numeric value (time format).
virtual Bool_t IsEditable() const
virtual Long_t GetIntNumber() const
Get the numeric value (integer representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void ReturnPressed()
Return was pressed.
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 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 void SetDate(Int_t year, Int_t month, Int_t day)
Set the numeric value (date format).
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
Definition: TGNumberEntry.h:79
virtual void SetIntNumber(Long_t val)
Set the numeric value (integer representation).
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual Int_t GetCharWidth(const char *text="0") const
Get the text width in pixels.
virtual void Layout()
Layout.
virtual ELimit GetNumLimits() const
virtual void SetHexNumber(ULong_t val)
Set the numeric value (hex format).
TGNumberEntry * fBox
TGNumberEntryLayout(TGNumberEntry *box)
virtual TGDimension GetDefaultSize() const
Return the default size of the numeric control box.
TGNumberEntryLayout & operator=(const TGNumberEntryLayout &)
TGNumberEntryLayout(const TGNumberEntryLayout &)
virtual void Layout()
Layout the internal GUI elements in use.
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
TGButton * fButtonDown
virtual Double_t GetNumMax() const
virtual Bool_t IsLogStep() const
virtual EStyle GetNumStyle() const
virtual void SetTime(Int_t hour, Int_t min, Int_t sec)
Bool_t fButtonToNum
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 SetNumber(Double_t val)
virtual void SetIntNumber(Long_t val)
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
TGNumberEntry(const TGNumberEntry &)
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
virtual void SetHexNumber(ULong_t val)
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
virtual ELimit GetNumLimits() const
virtual void SetLogStep(Bool_t on=kTRUE)
Set log steps.
const TGPicture * fPicDown
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
TGNumberEntry & operator=(const TGNumberEntry &)
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 void SetDate(Int_t year, Int_t month, Int_t day)
virtual Double_t GetNumMin() const
TGNumberEntryField * fNumericEntry
virtual Double_t GetNumber() const
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a number entry widget as a C++ statement(s) on output stream out.
TGButton * fButtonUp
TGButton * GetButtonUp() const
virtual void SetText(const char *text)
virtual TGLayoutManager * GetLayoutManager() const
Return layout manager.
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
void SetNumStyle(EStyle style)
virtual ~TGNumberFormat()
Definition: TGNumberEntry.h:69
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
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
TCanvas * style()
Definition: style.C:1