TGNumberEntry.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGNumberEntry.h 25233 2008-08-25 16:48:47Z bellenot $
00002 // Author: Daniel Sigg   03/09/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #ifndef ROOT_TGNumberEntry
00014 #define ROOT_TGNumberEntry
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGNumberEntry, TGNumberEntryField and TGNumberFormat                 //
00019 //                                                                      //
00020 // TGNumberEntry is a number entry input widget with up/down buttons.   //
00021 // TGNumberEntryField is a number entry input widget.                   //
00022 // TGNumberFormat contains enum types to specify the numeric format .   //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 #ifndef ROOT_TGFrame
00027 #include "TGFrame.h"
00028 #endif
00029 #ifndef ROOT_TGTextEntry
00030 #include "TGTextEntry.h"
00031 #endif
00032 #ifndef ROOT_TGButton
00033 #include "TGButton.h"
00034 #endif
00035 
00036 
00037 class TGNumberFormat {
00038 public:
00039    enum EStyle {             // Style of number entry field
00040       kNESInteger = 0,       // Integer
00041       kNESRealOne = 1,       // Fixed fraction real, one digit
00042       kNESRealTwo = 2,       // Fixed fraction real, two digit
00043       kNESRealThree = 3,     // Fixed fraction real, three digit
00044       kNESRealFour = 4,      // Fixed fraction real, four digit
00045       kNESReal = 5,          // Real number
00046       kNESDegree = 6,        // Degree
00047       kNESMinSec = 7,        // Minute:seconds
00048       kNESHourMin = 8,       // Hour:minutes
00049       kNESHourMinSec = 9,    // Hour:minute:seconds
00050       kNESDayMYear = 10,     // Day/month/year
00051       kNESMDayYear = 11,     // Month/day/year
00052       kNESHex = 12           // Hex
00053    };
00054 
00055    enum EAttribute {         // Attributes of number entry field
00056       kNEAAnyNumber = 0,     // Any number
00057       kNEANonNegative = 1,   // Non-negative number
00058       kNEAPositive = 2       // Positive number
00059    };
00060 
00061    enum ELimit {             // Limit selection of number entry field
00062       kNELNoLimits = 0,      // No limits
00063       kNELLimitMin = 1,      // Lower limit only
00064       kNELLimitMax = 2,      // Upper limit only
00065       kNELLimitMinMax = 3    // Both lower and upper limits
00066    };
00067 
00068    enum EStepSize {          // Step for number entry field increase
00069       kNSSSmall = 0,         // Small step
00070       kNSSMedium = 1,        // Medium step
00071       kNSSLarge = 2,         // Large step
00072       kNSSHuge = 3           // Huge step
00073    };
00074 
00075    virtual ~TGNumberFormat() { }
00076    ClassDef(TGNumberFormat,0)  // Class defining namespace for several enums used by TGNumberEntry
00077 };
00078 
00079 
00080 class TGNumberEntryField : public TGTextEntry, public TGNumberFormat {
00081 
00082 protected:
00083    Bool_t        fNeedsVerification; // Needs verification of input
00084    EStyle        fNumStyle;          // Number style
00085    EAttribute    fNumAttr;           // Number attribute
00086    ELimit        fNumLimits;         // Limit attributes
00087    Double_t      fNumMin;            // Lower limit
00088    Double_t      fNumMax;            // Upper limit
00089    Bool_t        fStepLog;           // Logarithmic steps for increase?
00090 
00091 public:
00092    TGNumberEntryField(const TGWindow *p, Int_t id,
00093                       Double_t val, GContext_t norm,
00094                       FontStruct_t font = GetDefaultFontStruct(),
00095                       UInt_t option = kSunkenFrame | kDoubleBorder,
00096                       Pixel_t back = GetWhitePixel());
00097    TGNumberEntryField(const TGWindow *parent = 0,
00098                       Int_t id = -1, Double_t val = 0,
00099                       EStyle style = kNESReal,
00100                       EAttribute attr = kNEAAnyNumber,
00101                       ELimit limits = kNELNoLimits,
00102                       Double_t min = 0, Double_t max = 1);
00103 
00104    virtual void SetNumber(Double_t val);
00105    virtual void SetIntNumber(Long_t val);
00106    virtual void SetTime(Int_t hour, Int_t min, Int_t sec);
00107    virtual void SetDate(Int_t year, Int_t month, Int_t day);
00108    virtual void SetHexNumber(ULong_t val);
00109    virtual void SetText(const char* text, Bool_t emit = kTRUE);
00110 
00111    virtual Double_t GetNumber() const;
00112    virtual Long_t   GetIntNumber() const;
00113    virtual void     GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
00114    virtual void     GetDate(Int_t& year, Int_t& month, Int_t& day) const;
00115    virtual ULong_t  GetHexNumber() const;
00116 
00117    virtual Int_t GetCharWidth(const char* text = "0") const;
00118    virtual void  IncreaseNumber(EStepSize step = kNSSSmall,
00119                                 Int_t sign = 1, Bool_t logstep = kFALSE);
00120    virtual void  SetFormat(EStyle style,
00121                            EAttribute attr = kNEAAnyNumber);
00122    virtual void  SetLimits(ELimit limits = kNELNoLimits,
00123                            Double_t min = 0, Double_t max = 1);
00124    virtual void  SetState(Bool_t state);
00125    virtual void  SetLogStep(Bool_t on = kTRUE) {
00126       // Set logarithmic steps
00127       fStepLog = on; }
00128 
00129    virtual EStyle GetNumStyle() const {
00130       // Get the numerical style
00131       return fNumStyle; }
00132    virtual EAttribute GetNumAttr() const {
00133       // Get the numerical attribute
00134       return fNumAttr; }
00135    virtual ELimit GetNumLimits() const {
00136       // Get the numerialc limit attribute
00137       return fNumLimits; }
00138    virtual Double_t GetNumMin() const {
00139       // Get the lower limit
00140       return fNumMin; }
00141    virtual Double_t GetNumMax() const {
00142       // Get the upper limit
00143       return fNumMax; }
00144    virtual Bool_t IsLogStep() const {
00145       // Is log step enabled?
00146       return fStepLog; }
00147 
00148    virtual Bool_t HandleKey(Event_t* event);
00149    virtual Bool_t HandleFocusChange (Event_t* event);
00150    virtual void   TextChanged(const char *text = 0);
00151    virtual void   ReturnPressed();
00152    virtual void   Layout();
00153    virtual Bool_t IsEditable() const { return kFALSE; }
00154    virtual void   InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); }   //*SIGNAL*
00155    virtual void   SavePrimitive(ostream &out, Option_t * = "");
00156 
00157    ClassDef(TGNumberEntryField,0)  // A text entry field used by a TGNumberEntry
00158 };
00159 
00160 
00161 
00162 class TGNumberEntry : public TGCompositeFrame, public TGWidget,
00163    public TGNumberFormat {
00164 
00165    // dummy data members - just to say about options for context menu
00166    EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
00167    EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
00168    ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
00169 
00170 private:
00171    const TGPicture  *fPicUp;      // Up arrow
00172    const TGPicture  *fPicDown;    // Down arrow
00173 
00174    TGNumberEntry(const TGNumberEntry&);             // not implemented
00175    TGNumberEntry& operator=(const TGNumberEntry&);  // not implemented
00176 
00177 protected:
00178    TGNumberEntryField *fNumericEntry;  // Number text entry field
00179    TGButton           *fButtonUp;      // Button for increasing value
00180    TGButton           *fButtonDown;    // Button for decreasing value
00181    Bool_t              fButtonToNum;   // Send button messages to parent rather than number entry field
00182 
00183 public:
00184    TGNumberEntry(const TGWindow *parent = 0, Double_t val = 0,
00185                  Int_t digitwidth = 5, Int_t id = -1,
00186                  EStyle style = kNESReal,
00187                  EAttribute attr = kNEAAnyNumber,
00188                  ELimit limits = kNELNoLimits,
00189                  Double_t min = 0, Double_t max = 1);
00190    virtual ~TGNumberEntry();
00191 
00192    virtual void SetNumber(Double_t val) {
00193       // Set the numeric value (floating point representation)
00194       fNumericEntry->SetNumber(val); }
00195    virtual void SetIntNumber(Long_t val) {
00196       // Set the numeric value (integer representation)
00197       fNumericEntry->SetIntNumber(val); }
00198    virtual void SetTime(Int_t hour, Int_t min, Int_t sec) {
00199       // Set the numeric value (time format)
00200       fNumericEntry->SetTime(hour, min, sec); }
00201    virtual void SetDate(Int_t year, Int_t month, Int_t day) {
00202       // Set the numeric value (date format)
00203       fNumericEntry->SetDate(year, month, day); }
00204    virtual void SetHexNumber(ULong_t val) {
00205       // Set the numeric value (hex format)
00206       fNumericEntry->SetHexNumber(val); }
00207    virtual void SetText(const char* text) {
00208       // Set the value (text format)
00209       fNumericEntry->SetText(text); }
00210    virtual void SetState(Bool_t enable = kTRUE);
00211 
00212    virtual Double_t GetNumber() const {
00213       // Get the numeric value (floating point representation)
00214       return fNumericEntry->GetNumber(); }
00215    virtual Long_t GetIntNumber() const {
00216       // Get the numeric value (integer representation)
00217       return fNumericEntry->GetIntNumber (); }
00218    virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
00219       // Get the numeric value (time format)
00220       fNumericEntry->GetTime(hour, min, sec); }
00221    virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
00222       // Get the numeric value (date format)
00223       fNumericEntry->GetDate(year, month, day); }
00224    virtual ULong_t GetHexNumber() const {
00225       // Get the numeric value (hex format)
00226       return fNumericEntry->GetHexNumber(); }
00227    virtual void IncreaseNumber(EStepSize step = kNSSSmall,
00228                                Int_t sign = 1, Bool_t logstep = kFALSE) {
00229       // Increase the number value
00230       fNumericEntry->IncreaseNumber(step, sign, logstep); }
00231    virtual void SetFormat(EStyle style, EAttribute attr = TGNumberFormat::kNEAAnyNumber) {
00232       // Set the numerical format
00233       fNumericEntry->SetFormat(style, attr); }
00234    virtual void SetLimits(ELimit limits = TGNumberFormat::kNELNoLimits,
00235                           Double_t min = 0, Double_t max = 1) {
00236       // Set the numerical limits.
00237       fNumericEntry->SetLimits(limits, min, max); }
00238 
00239    virtual EStyle GetNumStyle() const {
00240       // Get the numerical style
00241       return fNumericEntry->GetNumStyle(); }
00242    virtual EAttribute GetNumAttr() const {
00243       // Get the numerical attribute
00244       return fNumericEntry->GetNumAttr(); }
00245    virtual ELimit GetNumLimits() const {
00246       // Get the numerical limit attribute
00247       return fNumericEntry->GetNumLimits(); }
00248    virtual Double_t GetNumMin() const {
00249       // Get the lower limit
00250       return fNumericEntry->GetNumMin(); }
00251    virtual Double_t GetNumMax() const {
00252       // Get the upper limit
00253       return fNumericEntry->GetNumMax(); }
00254    virtual Bool_t IsLogStep() const {
00255       // Is log step enabled?
00256       return fNumericEntry->IsLogStep(); }
00257    virtual void   SetButtonToNum(Bool_t state);
00258 
00259    void SetNumStyle(EStyle style) {
00260          SetFormat(style, GetNumAttr()); }                  //*SUBMENU*
00261    void SetNumAttr(EAttribute attr = kNEAAnyNumber) {
00262          SetFormat(GetNumStyle(), attr); }                  //*SUBMENU*
00263    void SetNumLimits(ELimit limits = kNELNoLimits) {
00264          SetLimits(limits, GetNumMin(), GetNumMax());  }    //*SUBMENU*
00265    void SetLimitValues(Double_t min = 0, Double_t max = 1) {
00266          SetLimits(GetNumLimits(), min, max);  }            //*MENU*
00267    virtual void SetLogStep(Bool_t on = kTRUE);              //*TOGGLE* *GETTER=IsLogStep
00268 
00269    virtual void   Associate(const TGWindow *w);
00270    virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
00271    virtual void   ValueChanged(Long_t val);     //*SIGNAL*
00272    virtual void   ValueSet(Long_t val);         //*SIGNAL*
00273 
00274    TGNumberEntryField *GetNumberEntry() const {
00275       // Get the number entry field
00276       return fNumericEntry; }
00277    TGButton *GetButtonUp() const {
00278       // Get the up button
00279       return fButtonUp; }
00280    TGButton *GetButtonDown() const {
00281       // Get the down button
00282       return fButtonDown; }
00283 
00284    virtual Bool_t IsEditable() const { return kFALSE; }
00285 
00286    UInt_t GetDefaultHeight() const { return fNumericEntry->GetDefaultHeight(); }
00287    virtual void SavePrimitive(ostream &out, Option_t * = "");
00288    virtual TGLayoutManager *GetLayoutManager() const;
00289 
00290    ClassDef(TGNumberEntry,0)  // Entry field widget for several numeric formats
00291 };
00292 
00293 
00294 class TGNumberEntryLayout : public TGLayoutManager {
00295 protected:
00296    TGNumberEntry *fBox;        // pointer to numeric control box
00297 
00298 private:
00299    TGNumberEntryLayout(const TGNumberEntryLayout&);             // not implemented
00300    TGNumberEntryLayout& operator=(const TGNumberEntryLayout&);  // not implemented
00301 
00302 public:
00303    TGNumberEntryLayout(TGNumberEntry *box): fBox(box) { }
00304    virtual void Layout();
00305    virtual TGDimension GetDefaultSize() const;
00306 
00307    ClassDef(TGNumberEntryLayout,0)  // Layout manager for number entry widget
00308 };
00309 
00310 
00311 #endif

Generated on Tue Jul 5 14:20:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1