File indexing completed on 2025-01-18 10:12:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_TGNumberEntry
0014 #define ROOT_TGNumberEntry
0015
0016
0017 #include "TGFrame.h"
0018 #include "TGTextEntry.h"
0019 #include "TGButton.h"
0020
0021
0022 class TGNumberFormat {
0023 public:
0024 enum EStyle {
0025 kNESInteger = 0,
0026 kNESRealOne = 1,
0027 kNESRealTwo = 2,
0028 kNESRealThree = 3,
0029 kNESRealFour = 4,
0030 kNESReal = 5,
0031 kNESDegree = 6,
0032 kNESMinSec = 7,
0033 kNESHourMin = 8,
0034 kNESHourMinSec = 9,
0035 kNESDayMYear = 10,
0036 kNESMDayYear = 11,
0037 kNESHex = 12,
0038 kNESMinSecCent = 13
0039 };
0040
0041 enum EAttribute {
0042 kNEAAnyNumber = 0,
0043 kNEANonNegative = 1,
0044 kNEAPositive = 2
0045 };
0046
0047 enum ELimit {
0048 kNELNoLimits = 0,
0049 kNELLimitMin = 1,
0050 kNELLimitMax = 2,
0051 kNELLimitMinMax = 3
0052 };
0053
0054 enum EStepSize {
0055 kNSSSmall = 0,
0056 kNSSMedium = 1,
0057 kNSSLarge = 2,
0058 kNSSHuge = 3
0059 };
0060
0061 virtual ~TGNumberFormat() {}
0062 ClassDef(TGNumberFormat,0)
0063 };
0064
0065
0066 class TGNumberEntryField : public TGTextEntry, public TGNumberFormat {
0067
0068 protected:
0069 Bool_t fNeedsVerification;
0070 EStyle fNumStyle;
0071 EAttribute fNumAttr;
0072 ELimit fNumLimits;
0073 Double_t fNumMin;
0074 Double_t fNumMax;
0075 Bool_t fStepLog;
0076
0077 public:
0078 TGNumberEntryField(const TGWindow *p, Int_t id,
0079 Double_t val, GContext_t norm,
0080 FontStruct_t font = GetDefaultFontStruct(),
0081 UInt_t option = kSunkenFrame | kDoubleBorder,
0082 Pixel_t back = GetWhitePixel());
0083 TGNumberEntryField(const TGWindow *parent = nullptr,
0084 Int_t id = -1, Double_t val = 0,
0085 EStyle style = kNESReal,
0086 EAttribute attr = kNEAAnyNumber,
0087 ELimit limits = kNELNoLimits,
0088 Double_t min = 0, Double_t max = 1);
0089
0090 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE);
0091 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE);
0092 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE);
0093 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE);
0094 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE);
0095 void SetText(const char* text, Bool_t emit = kTRUE) override;
0096
0097 virtual Double_t GetNumber() const;
0098 virtual Long_t GetIntNumber() const;
0099 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
0100 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const;
0101 virtual ULong_t GetHexNumber() const;
0102
0103 virtual Int_t GetCharWidth(const char* text = "0") const;
0104 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
0105 Int_t sign = 1, Bool_t logstep = kFALSE);
0106 virtual void SetFormat(EStyle style,
0107 EAttribute attr = kNEAAnyNumber);
0108 virtual void SetLimits(ELimit limits = kNELNoLimits,
0109 Double_t min = 0, Double_t max = 1);
0110 void SetState(Bool_t state) override;
0111
0112
0113 virtual void SetLogStep(Bool_t on = kTRUE) { fStepLog = on; }
0114
0115
0116 virtual EStyle GetNumStyle() const { return fNumStyle; }
0117
0118
0119 virtual EAttribute GetNumAttr() const { return fNumAttr; }
0120
0121
0122 virtual ELimit GetNumLimits() const { return fNumLimits; }
0123
0124
0125 virtual Double_t GetNumMin() const { return fNumMin; }
0126
0127
0128 virtual Double_t GetNumMax() const { return fNumMax; }
0129
0130
0131 virtual Bool_t IsLogStep() const { return fStepLog; }
0132
0133 Bool_t HandleKey(Event_t* event) override;
0134 Bool_t HandleFocusChange (Event_t* event) override;
0135 void TextChanged(const char *text = nullptr) override;
0136 void ReturnPressed() override;
0137 void Layout() override;
0138 Bool_t IsEditable() const override { return kFALSE; }
0139 virtual void InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); }
0140 void SavePrimitive(std::ostream &out, Option_t * = "") override;
0141
0142 ClassDefOverride(TGNumberEntryField,0)
0143 };
0144
0145
0146
0147 class TGNumberEntry : public TGCompositeFrame, public TGWidget,
0148 public TGNumberFormat {
0149
0150
0151 EStyle fNumStyle;
0152 EAttribute fNumAttr;
0153 ELimit fNumLimits;
0154
0155 private:
0156 const TGPicture *fPicUp;
0157 const TGPicture *fPicDown;
0158
0159 TGNumberEntry(const TGNumberEntry&) = delete;
0160 TGNumberEntry& operator=(const TGNumberEntry&) = delete;
0161
0162 protected:
0163 TGNumberEntryField *fNumericEntry;
0164 TGButton *fButtonUp;
0165 TGButton *fButtonDown;
0166 Bool_t fButtonToNum;
0167
0168 public:
0169 TGNumberEntry(const TGWindow *parent = nullptr, Double_t val = 0,
0170 Int_t digitwidth = 5, Int_t id = -1,
0171 EStyle style = kNESReal,
0172 EAttribute attr = kNEAAnyNumber,
0173 ELimit limits = kNELNoLimits,
0174 Double_t min = 0, Double_t max = 1);
0175 ~TGNumberEntry() override;
0176
0177 virtual void SetNumber(Double_t val, Bool_t emit = kTRUE) {
0178
0179 fNumericEntry->SetNumber(val, emit); }
0180 virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE) {
0181
0182 fNumericEntry->SetIntNumber(val, emit); }
0183 virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE) {
0184
0185 fNumericEntry->SetTime(hour, min, sec, emit); }
0186 virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit = kTRUE) {
0187
0188 fNumericEntry->SetDate(year, month, day, emit); }
0189 virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE) {
0190
0191 fNumericEntry->SetHexNumber(val, emit); }
0192 virtual void SetText(const char* text, Bool_t emit = kTRUE) {
0193
0194 fNumericEntry->SetText(text, emit); }
0195 virtual void SetState(Bool_t enable = kTRUE);
0196
0197 virtual Double_t GetNumber() const {
0198
0199 return fNumericEntry->GetNumber(); }
0200 virtual Long_t GetIntNumber() const {
0201
0202 return fNumericEntry->GetIntNumber (); }
0203 virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
0204
0205 fNumericEntry->GetTime(hour, min, sec); }
0206 virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
0207
0208 fNumericEntry->GetDate(year, month, day); }
0209 virtual ULong_t GetHexNumber() const {
0210
0211 return fNumericEntry->GetHexNumber(); }
0212 virtual void IncreaseNumber(EStepSize step = kNSSSmall,
0213 Int_t sign = 1, Bool_t logstep = kFALSE) {
0214
0215 fNumericEntry->IncreaseNumber(step, sign, logstep); }
0216 virtual void SetFormat(EStyle style, EAttribute attr = TGNumberFormat::kNEAAnyNumber) {
0217
0218 fNumericEntry->SetFormat(style, attr); }
0219 virtual void SetLimits(ELimit limits = TGNumberFormat::kNELNoLimits,
0220 Double_t min = 0, Double_t max = 1) {
0221
0222 fNumericEntry->SetLimits(limits, min, max); }
0223
0224 virtual EStyle GetNumStyle() const {
0225
0226 return fNumericEntry->GetNumStyle(); }
0227 virtual EAttribute GetNumAttr() const {
0228
0229 return fNumericEntry->GetNumAttr(); }
0230 virtual ELimit GetNumLimits() const {
0231
0232 return fNumericEntry->GetNumLimits(); }
0233 virtual Double_t GetNumMin() const {
0234
0235 return fNumericEntry->GetNumMin(); }
0236 virtual Double_t GetNumMax() const {
0237
0238 return fNumericEntry->GetNumMax(); }
0239 virtual Bool_t IsLogStep() const {
0240
0241 return fNumericEntry->IsLogStep(); }
0242 virtual void SetButtonToNum(Bool_t state);
0243
0244 void SetNumStyle(EStyle style) {
0245 SetFormat(style, GetNumAttr()); }
0246 void SetNumAttr(EAttribute attr = kNEAAnyNumber) {
0247 SetFormat(GetNumStyle(), attr); }
0248 void SetNumLimits(ELimit limits = kNELNoLimits) {
0249 SetLimits(limits, GetNumMin(), GetNumMax()); }
0250 void SetLimitValues(Double_t min = 0, Double_t max = 1) {
0251 SetLimits(GetNumLimits(), min, max); }
0252 virtual void SetLogStep(Bool_t on = kTRUE);
0253
0254 void Associate(const TGWindow *w) override;
0255 Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
0256 virtual void ValueChanged(Long_t val);
0257 virtual void ValueSet(Long_t val);
0258 virtual void Modified();
0259
0260
0261 TGNumberEntryField *GetNumberEntry() const { return fNumericEntry; }
0262
0263 TGButton *GetButtonUp() const { return fButtonUp; }
0264
0265 TGButton *GetButtonDown() const { return fButtonDown; }
0266
0267 Bool_t IsEditable() const override { return kFALSE; }
0268
0269 UInt_t GetDefaultHeight() const override { return fNumericEntry->GetDefaultHeight(); }
0270 void SavePrimitive(std::ostream &out, Option_t * = "") override;
0271 TGLayoutManager *GetLayoutManager() const override;
0272
0273 ClassDefOverride(TGNumberEntry,0)
0274 };
0275
0276
0277 class TGNumberEntryLayout : public TGLayoutManager {
0278 protected:
0279 TGNumberEntry *fBox;
0280
0281 private:
0282 TGNumberEntryLayout(const TGNumberEntryLayout&) = delete;
0283 TGNumberEntryLayout& operator=(const TGNumberEntryLayout&) = delete;
0284
0285 public:
0286 TGNumberEntryLayout(TGNumberEntry *box): fBox(box) { }
0287 void Layout() override;
0288 TGDimension GetDefaultSize() const override;
0289
0290 ClassDefOverride(TGNumberEntryLayout,0)
0291 };
0292
0293
0294 #endif