Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:03

0001 // @(#)root/gui:$Id$
0002 // Author: Daniel Sigg   03/09/2001
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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 {             ///< Style of number entry field
0025       kNESInteger = 0,       ///< Integer
0026       kNESRealOne = 1,       ///< Fixed fraction real, one digit
0027       kNESRealTwo = 2,       ///< Fixed fraction real, two digit
0028       kNESRealThree = 3,     ///< Fixed fraction real, three digit
0029       kNESRealFour = 4,      ///< Fixed fraction real, four digit
0030       kNESReal = 5,          ///< Real number
0031       kNESDegree = 6,        ///< Degree
0032       kNESMinSec = 7,        ///< Minute:seconds
0033       kNESHourMin = 8,       ///< Hour:minutes
0034       kNESHourMinSec = 9,    ///< Hour:minute:seconds
0035       kNESDayMYear = 10,     ///< Day/month/year
0036       kNESMDayYear = 11,     ///< Month/day/year
0037       kNESHex = 12,          ///< Hex
0038       kNESMinSecCent = 13    ///< Minute:seconds.centiseconds
0039    };
0040 
0041    enum EAttribute {         ///< Attributes of number entry field
0042       kNEAAnyNumber = 0,     ///< Any number
0043       kNEANonNegative = 1,   ///< Non-negative number
0044       kNEAPositive = 2       ///< Positive number
0045    };
0046 
0047    enum ELimit {             ///< Limit selection of number entry field
0048       kNELNoLimits = 0,      ///< No limits
0049       kNELLimitMin = 1,      ///< Lower limit only
0050       kNELLimitMax = 2,      ///< Upper limit only
0051       kNELLimitMinMax = 3    ///< Both lower and upper limits
0052    };
0053 
0054    enum EStepSize {          ///< Step for number entry field increase
0055       kNSSSmall = 0,         ///< Small step
0056       kNSSMedium = 1,        ///< Medium step
0057       kNSSLarge = 2,         ///< Large step
0058       kNSSHuge = 3           ///< Huge step
0059    };
0060 
0061    virtual ~TGNumberFormat() {}
0062    ClassDef(TGNumberFormat,0)  // Class defining namespace for several enums used by TGNumberEntry
0063 };
0064 
0065 
0066 class TGNumberEntryField : public TGTextEntry, public TGNumberFormat {
0067 
0068 protected:
0069    Bool_t        fNeedsVerification; ///< Needs verification of input
0070    EStyle        fNumStyle;          ///< Number style
0071    EAttribute    fNumAttr;           ///< Number attribute
0072    ELimit        fNumLimits;         ///< Limit attributes
0073    Double_t      fNumMin;            ///< Lower limit
0074    Double_t      fNumMax;            ///< Upper limit
0075    Bool_t        fStepLog;           ///< Logarithmic steps for increase?
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    /** Set logarithmic steps */
0113    virtual void  SetLogStep(Bool_t on = kTRUE) { fStepLog = on; }
0114 
0115    /** Get the numerical style */
0116    virtual EStyle GetNumStyle() const { return fNumStyle; }
0117 
0118    /** Get the numerical attribute */
0119    virtual EAttribute GetNumAttr() const { return fNumAttr; }
0120 
0121    /** Get the numerical limit attribute */
0122    virtual ELimit GetNumLimits() const { return fNumLimits; }
0123 
0124    /** Get the lower limit */
0125    virtual Double_t GetNumMin() const { return fNumMin; }
0126 
0127    /** Get the upper limit */
0128    virtual Double_t GetNumMax() const { return fNumMax; }
0129 
0130    /** Is log step enabled? */
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); }   //*SIGNAL*
0140    void           SavePrimitive(std::ostream &out, Option_t * = "") override;
0141 
0142    ClassDefOverride(TGNumberEntryField,0)  // A text entry field used by a TGNumberEntry
0143 };
0144 
0145 
0146 
0147 class TGNumberEntry : public TGCompositeFrame, public TGWidget,
0148    public TGNumberFormat {
0149 
0150    // dummy data members - just to say about options for context menu
0151    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")}*
0152    EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
0153    ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
0154 
0155 private:
0156    const TGPicture  *fPicUp;      ///< Up arrow
0157    const TGPicture  *fPicDown;    ///< Down arrow
0158 
0159    TGNumberEntry(const TGNumberEntry&) = delete;
0160    TGNumberEntry& operator=(const TGNumberEntry&) = delete;
0161 
0162 protected:
0163    TGNumberEntryField *fNumericEntry;  ///< Number text entry field
0164    TGButton           *fButtonUp;      ///< Button for increasing value
0165    TGButton           *fButtonDown;    ///< Button for decreasing value
0166    Bool_t              fButtonToNum;   ///< Send button messages to parent rather than number entry field
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       // Set the numeric value (floating point representation)
0179       fNumericEntry->SetNumber(val, emit); }
0180    virtual void SetIntNumber(Long_t val, Bool_t emit = kTRUE) {
0181       // Set the numeric value (integer representation)
0182       fNumericEntry->SetIntNumber(val, emit); }
0183    virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit = kTRUE) {
0184       // Set the numeric value (time format)
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       // Set the numeric value (date format)
0188       fNumericEntry->SetDate(year, month, day, emit); }
0189    virtual void SetHexNumber(ULong_t val, Bool_t emit = kTRUE) {
0190       // Set the numeric value (hex format)
0191       fNumericEntry->SetHexNumber(val, emit); }
0192    virtual void SetText(const char* text, Bool_t emit = kTRUE) {
0193       // Set the value (text format)
0194       fNumericEntry->SetText(text, emit); }
0195    virtual void SetState(Bool_t enable = kTRUE);
0196 
0197    virtual Double_t GetNumber() const {
0198       // Get the numeric value (floating point representation)
0199       return fNumericEntry->GetNumber(); }
0200    virtual Long_t GetIntNumber() const {
0201       // Get the numeric value (integer representation)
0202       return fNumericEntry->GetIntNumber (); }
0203    virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
0204       // Get the numeric value (time format)
0205       fNumericEntry->GetTime(hour, min, sec); }
0206    virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
0207       // Get the numeric value (date format)
0208       fNumericEntry->GetDate(year, month, day); }
0209    virtual ULong_t GetHexNumber() const {
0210       // Get the numeric value (hex format)
0211       return fNumericEntry->GetHexNumber(); }
0212    virtual void IncreaseNumber(EStepSize step = kNSSSmall,
0213                                Int_t sign = 1, Bool_t logstep = kFALSE) {
0214       // Increase the number value
0215       fNumericEntry->IncreaseNumber(step, sign, logstep); }
0216    virtual void SetFormat(EStyle style, EAttribute attr = TGNumberFormat::kNEAAnyNumber) {
0217       // Set the numerical format
0218       fNumericEntry->SetFormat(style, attr); }
0219    virtual void SetLimits(ELimit limits = TGNumberFormat::kNELNoLimits,
0220                           Double_t min = 0, Double_t max = 1) {
0221       // Set the numerical limits.
0222       fNumericEntry->SetLimits(limits, min, max); }
0223 
0224    virtual EStyle GetNumStyle() const {
0225       // Get the numerical style
0226       return fNumericEntry->GetNumStyle(); }
0227    virtual EAttribute GetNumAttr() const {
0228       // Get the numerical attribute
0229       return fNumericEntry->GetNumAttr(); }
0230    virtual ELimit GetNumLimits() const {
0231       // Get the numerical limit attribute
0232       return fNumericEntry->GetNumLimits(); }
0233    virtual Double_t GetNumMin() const {
0234       // Get the lower limit
0235       return fNumericEntry->GetNumMin(); }
0236    virtual Double_t GetNumMax() const {
0237       // Get the upper limit
0238       return fNumericEntry->GetNumMax(); }
0239    virtual Bool_t IsLogStep() const {
0240       // Is log step enabled?
0241       return fNumericEntry->IsLogStep(); }
0242    virtual void   SetButtonToNum(Bool_t state);
0243 
0244    void SetNumStyle(EStyle style) {
0245          SetFormat(style, GetNumAttr()); }                  //*SUBMENU*
0246    void SetNumAttr(EAttribute attr = kNEAAnyNumber) {
0247          SetFormat(GetNumStyle(), attr); }                  //*SUBMENU*
0248    void SetNumLimits(ELimit limits = kNELNoLimits) {
0249          SetLimits(limits, GetNumMin(), GetNumMax());  }    //*SUBMENU*
0250    void SetLimitValues(Double_t min = 0, Double_t max = 1) {
0251          SetLimits(GetNumLimits(), min, max);  }            //*MENU*
0252    virtual void SetLogStep(Bool_t on = kTRUE);              //*TOGGLE* *GETTER=IsLogStep
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);     //*SIGNAL*
0257    virtual void   ValueSet(Long_t val);         //*SIGNAL*
0258    virtual void   Modified();                   //*SIGNAL*
0259 
0260    /** Get the number entry field */
0261    TGNumberEntryField *GetNumberEntry() const { return fNumericEntry; }
0262    /** Get the up button */
0263    TGButton *GetButtonUp() const { return fButtonUp; }
0264    /** Get the down button */
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)  // Entry field widget for several numeric formats
0274 };
0275 
0276 
0277 class TGNumberEntryLayout : public TGLayoutManager {
0278 protected:
0279    TGNumberEntry *fBox;        // pointer to numeric control box
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)  // Layout manager for number entry widget
0291 };
0292 
0293 
0294 #endif