ROOT logo
// @(#)root/gui:$Id: TGNumberEntry.h 25233 2008-08-25 16:48:47Z bellenot $
// Author: Daniel Sigg   03/09/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


#ifndef ROOT_TGNumberEntry
#define ROOT_TGNumberEntry

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGNumberEntry, TGNumberEntryField and TGNumberFormat                 //
//                                                                      //
// TGNumberEntry is a number entry input widget with up/down buttons.   //
// TGNumberEntryField is a number entry input widget.                   //
// TGNumberFormat contains enum types to specify the numeric format .   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif
#ifndef ROOT_TGTextEntry
#include "TGTextEntry.h"
#endif
#ifndef ROOT_TGButton
#include "TGButton.h"
#endif


class TGNumberFormat {
public:
   enum EStyle {             // Style of number entry field
      kNESInteger = 0,       // Integer
      kNESRealOne = 1,       // Fixed fraction real, one digit
      kNESRealTwo = 2,       // Fixed fraction real, two digit
      kNESRealThree = 3,     // Fixed fraction real, three digit
      kNESRealFour = 4,      // Fixed fraction real, four digit
      kNESReal = 5,          // Real number
      kNESDegree = 6,        // Degree
      kNESMinSec = 7,        // Minute:seconds
      kNESHourMin = 8,       // Hour:minutes
      kNESHourMinSec = 9,    // Hour:minute:seconds
      kNESDayMYear = 10,     // Day/month/year
      kNESMDayYear = 11,     // Month/day/year
      kNESHex = 12           // Hex
   };

   enum EAttribute {         // Attributes of number entry field
      kNEAAnyNumber = 0,     // Any number
      kNEANonNegative = 1,   // Non-negative number
      kNEAPositive = 2       // Positive number
   };

   enum ELimit {             // Limit selection of number entry field
      kNELNoLimits = 0,      // No limits
      kNELLimitMin = 1,      // Lower limit only
      kNELLimitMax = 2,      // Upper limit only
      kNELLimitMinMax = 3    // Both lower and upper limits
   };

   enum EStepSize {          // Step for number entry field increase
      kNSSSmall = 0,         // Small step
      kNSSMedium = 1,        // Medium step
      kNSSLarge = 2,         // Large step
      kNSSHuge = 3           // Huge step
   };

   virtual ~TGNumberFormat() { }
   ClassDef(TGNumberFormat,0)  // Class defining namespace for several enums used by TGNumberEntry
};


class TGNumberEntryField : public TGTextEntry, public TGNumberFormat {

protected:
   Bool_t        fNeedsVerification; // Needs verification of input
   EStyle        fNumStyle;          // Number style
   EAttribute    fNumAttr;           // Number attribute
   ELimit        fNumLimits;         // Limit attributes
   Double_t      fNumMin;            // Lower limit
   Double_t      fNumMax;            // Upper limit
   Bool_t        fStepLog;           // Logarithmic steps for increase?

public:
   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());
   TGNumberEntryField(const TGWindow *parent = 0,
                      Int_t id = -1, Double_t val = 0,
                      EStyle style = kNESReal,
                      EAttribute attr = kNEAAnyNumber,
                      ELimit limits = kNELNoLimits,
                      Double_t min = 0, Double_t max = 1);

   virtual void SetNumber(Double_t val);
   virtual void SetIntNumber(Long_t val);
   virtual void SetTime(Int_t hour, Int_t min, Int_t sec);
   virtual void SetDate(Int_t year, Int_t month, Int_t day);
   virtual void SetHexNumber(ULong_t val);
   virtual void SetText(const char* text, Bool_t emit = kTRUE);

   virtual Double_t GetNumber() const;
   virtual Long_t   GetIntNumber() const;
   virtual void     GetTime(Int_t& hour, Int_t& min, Int_t& sec) const;
   virtual void     GetDate(Int_t& year, Int_t& month, Int_t& day) const;
   virtual ULong_t  GetHexNumber() const;

   virtual Int_t GetCharWidth(const char* text = "0") const;
   virtual void  IncreaseNumber(EStepSize step = kNSSSmall,
                                Int_t sign = 1, Bool_t logstep = kFALSE);
   virtual void  SetFormat(EStyle style,
                           EAttribute attr = kNEAAnyNumber);
   virtual void  SetLimits(ELimit limits = kNELNoLimits,
                           Double_t min = 0, Double_t max = 1);
   virtual void  SetState(Bool_t state);
   virtual void  SetLogStep(Bool_t on = kTRUE) {
      // Set logarithmic steps
      fStepLog = on; }

   virtual EStyle GetNumStyle() const {
      // Get the numerical style
      return fNumStyle; }
   virtual EAttribute GetNumAttr() const {
      // Get the numerical attribute
      return fNumAttr; }
   virtual ELimit GetNumLimits() const {
      // Get the numerialc limit attribute
      return fNumLimits; }
   virtual Double_t GetNumMin() const {
      // Get the lower limit
      return fNumMin; }
   virtual Double_t GetNumMax() const {
      // Get the upper limit
      return fNumMax; }
   virtual Bool_t IsLogStep() const {
      // Is log step enabled?
      return fStepLog; }

   virtual Bool_t HandleKey(Event_t* event);
   virtual Bool_t HandleFocusChange (Event_t* event);
   virtual void   TextChanged(const char *text = 0);
   virtual void   ReturnPressed();
   virtual void   Layout();
   virtual Bool_t IsEditable() const { return kFALSE; }
   virtual void   InvalidInput(const char *instr) { Emit("InvalidInput(char*)", instr); }   //*SIGNAL*
   virtual void   SavePrimitive(ostream &out, Option_t * = "");

   ClassDef(TGNumberEntryField,0)  // A text entry field used by a TGNumberEntry
};



class TGNumberEntry : public TGCompositeFrame, public TGWidget,
   public TGNumberFormat {

   // dummy data members - just to say about options for context menu
   EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
   EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
   ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*

private:
   const TGPicture  *fPicUp;      // Up arrow
   const TGPicture  *fPicDown;    // Down arrow

   TGNumberEntry(const TGNumberEntry&);             // not implemented
   TGNumberEntry& operator=(const TGNumberEntry&);  // not implemented

protected:
   TGNumberEntryField *fNumericEntry;  // Number text entry field
   TGButton           *fButtonUp;      // Button for increasing value
   TGButton           *fButtonDown;    // Button for decreasing value
   Bool_t              fButtonToNum;   // Send button messages to parent rather than number entry field

public:
   TGNumberEntry(const TGWindow *parent = 0, Double_t val = 0,
                 Int_t digitwidth = 5, Int_t id = -1,
                 EStyle style = kNESReal,
                 EAttribute attr = kNEAAnyNumber,
                 ELimit limits = kNELNoLimits,
                 Double_t min = 0, Double_t max = 1);
   virtual ~TGNumberEntry();

   virtual void SetNumber(Double_t val) {
      // Set the numeric value (floating point representation)
      fNumericEntry->SetNumber(val); }
   virtual void SetIntNumber(Long_t val) {
      // Set the numeric value (integer representation)
      fNumericEntry->SetIntNumber(val); }
   virtual void SetTime(Int_t hour, Int_t min, Int_t sec) {
      // Set the numeric value (time format)
      fNumericEntry->SetTime(hour, min, sec); }
   virtual void SetDate(Int_t year, Int_t month, Int_t day) {
      // Set the numeric value (date format)
      fNumericEntry->SetDate(year, month, day); }
   virtual void SetHexNumber(ULong_t val) {
      // Set the numeric value (hex format)
      fNumericEntry->SetHexNumber(val); }
   virtual void SetText(const char* text) {
      // Set the value (text format)
      fNumericEntry->SetText(text); }
   virtual void SetState(Bool_t enable = kTRUE);

   virtual Double_t GetNumber() const {
      // Get the numeric value (floating point representation)
      return fNumericEntry->GetNumber(); }
   virtual Long_t GetIntNumber() const {
      // Get the numeric value (integer representation)
      return fNumericEntry->GetIntNumber (); }
   virtual void GetTime(Int_t& hour, Int_t& min, Int_t& sec) const {
      // Get the numeric value (time format)
      fNumericEntry->GetTime(hour, min, sec); }
   virtual void GetDate(Int_t& year, Int_t& month, Int_t& day) const {
      // Get the numeric value (date format)
      fNumericEntry->GetDate(year, month, day); }
   virtual ULong_t GetHexNumber() const {
      // Get the numeric value (hex format)
      return fNumericEntry->GetHexNumber(); }
   virtual void IncreaseNumber(EStepSize step = kNSSSmall,
                               Int_t sign = 1, Bool_t logstep = kFALSE) {
      // Increase the number value
      fNumericEntry->IncreaseNumber(step, sign, logstep); }
   virtual void SetFormat(EStyle style, EAttribute attr = TGNumberFormat::kNEAAnyNumber) {
      // Set the numerical format
      fNumericEntry->SetFormat(style, attr); }
   virtual void SetLimits(ELimit limits = TGNumberFormat::kNELNoLimits,
                          Double_t min = 0, Double_t max = 1) {
      // Set the numerical limits.
      fNumericEntry->SetLimits(limits, min, max); }

   virtual EStyle GetNumStyle() const {
      // Get the numerical style
      return fNumericEntry->GetNumStyle(); }
   virtual EAttribute GetNumAttr() const {
      // Get the numerical attribute
      return fNumericEntry->GetNumAttr(); }
   virtual ELimit GetNumLimits() const {
      // Get the numerical limit attribute
      return fNumericEntry->GetNumLimits(); }
   virtual Double_t GetNumMin() const {
      // Get the lower limit
      return fNumericEntry->GetNumMin(); }
   virtual Double_t GetNumMax() const {
      // Get the upper limit
      return fNumericEntry->GetNumMax(); }
   virtual Bool_t IsLogStep() const {
      // Is log step enabled?
      return fNumericEntry->IsLogStep(); }
   virtual void   SetButtonToNum(Bool_t state);

   void SetNumStyle(EStyle style) {
         SetFormat(style, GetNumAttr()); }                  //*SUBMENU*
   void SetNumAttr(EAttribute attr = kNEAAnyNumber) {
         SetFormat(GetNumStyle(), attr); }                  //*SUBMENU*
   void SetNumLimits(ELimit limits = kNELNoLimits) {
         SetLimits(limits, GetNumMin(), GetNumMax());  }    //*SUBMENU*
   void SetLimitValues(Double_t min = 0, Double_t max = 1) {
         SetLimits(GetNumLimits(), min, max);  }            //*MENU*
   virtual void SetLogStep(Bool_t on = kTRUE);              //*TOGGLE* *GETTER=IsLogStep

   virtual void   Associate(const TGWindow *w);
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
   virtual void   ValueChanged(Long_t val);     //*SIGNAL*
   virtual void   ValueSet(Long_t val);         //*SIGNAL*

   TGNumberEntryField *GetNumberEntry() const {
      // Get the number entry field
      return fNumericEntry; }
   TGButton *GetButtonUp() const {
      // Get the up button
      return fButtonUp; }
   TGButton *GetButtonDown() const {
      // Get the down button
      return fButtonDown; }

   virtual Bool_t IsEditable() const { return kFALSE; }

   UInt_t GetDefaultHeight() const { return fNumericEntry->GetDefaultHeight(); }
   virtual void SavePrimitive(ostream &out, Option_t * = "");
   virtual TGLayoutManager *GetLayoutManager() const;

   ClassDef(TGNumberEntry,0)  // Entry field widget for several numeric formats
};


class TGNumberEntryLayout : public TGLayoutManager {
protected:
   TGNumberEntry *fBox;        // pointer to numeric control box

private:
   TGNumberEntryLayout(const TGNumberEntryLayout&);             // not implemented
   TGNumberEntryLayout& operator=(const TGNumberEntryLayout&);  // not implemented

public:
   TGNumberEntryLayout(TGNumberEntry *box): fBox(box) { }
   virtual void Layout();
   virtual TGDimension GetDefaultSize() const;

   ClassDef(TGNumberEntryLayout,0)  // Layout manager for number entry widget
};


#endif
 TGNumberEntry.h:1
 TGNumberEntry.h:2
 TGNumberEntry.h:3
 TGNumberEntry.h:4
 TGNumberEntry.h:5
 TGNumberEntry.h:6
 TGNumberEntry.h:7
 TGNumberEntry.h:8
 TGNumberEntry.h:9
 TGNumberEntry.h:10
 TGNumberEntry.h:11
 TGNumberEntry.h:12
 TGNumberEntry.h:13
 TGNumberEntry.h:14
 TGNumberEntry.h:15
 TGNumberEntry.h:16
 TGNumberEntry.h:17
 TGNumberEntry.h:18
 TGNumberEntry.h:19
 TGNumberEntry.h:20
 TGNumberEntry.h:21
 TGNumberEntry.h:22
 TGNumberEntry.h:23
 TGNumberEntry.h:24
 TGNumberEntry.h:25
 TGNumberEntry.h:26
 TGNumberEntry.h:27
 TGNumberEntry.h:28
 TGNumberEntry.h:29
 TGNumberEntry.h:30
 TGNumberEntry.h:31
 TGNumberEntry.h:32
 TGNumberEntry.h:33
 TGNumberEntry.h:34
 TGNumberEntry.h:35
 TGNumberEntry.h:36
 TGNumberEntry.h:37
 TGNumberEntry.h:38
 TGNumberEntry.h:39
 TGNumberEntry.h:40
 TGNumberEntry.h:41
 TGNumberEntry.h:42
 TGNumberEntry.h:43
 TGNumberEntry.h:44
 TGNumberEntry.h:45
 TGNumberEntry.h:46
 TGNumberEntry.h:47
 TGNumberEntry.h:48
 TGNumberEntry.h:49
 TGNumberEntry.h:50
 TGNumberEntry.h:51
 TGNumberEntry.h:52
 TGNumberEntry.h:53
 TGNumberEntry.h:54
 TGNumberEntry.h:55
 TGNumberEntry.h:56
 TGNumberEntry.h:57
 TGNumberEntry.h:58
 TGNumberEntry.h:59
 TGNumberEntry.h:60
 TGNumberEntry.h:61
 TGNumberEntry.h:62
 TGNumberEntry.h:63
 TGNumberEntry.h:64
 TGNumberEntry.h:65
 TGNumberEntry.h:66
 TGNumberEntry.h:67
 TGNumberEntry.h:68
 TGNumberEntry.h:69
 TGNumberEntry.h:70
 TGNumberEntry.h:71
 TGNumberEntry.h:72
 TGNumberEntry.h:73
 TGNumberEntry.h:74
 TGNumberEntry.h:75
 TGNumberEntry.h:76
 TGNumberEntry.h:77
 TGNumberEntry.h:78
 TGNumberEntry.h:79
 TGNumberEntry.h:80
 TGNumberEntry.h:81
 TGNumberEntry.h:82
 TGNumberEntry.h:83
 TGNumberEntry.h:84
 TGNumberEntry.h:85
 TGNumberEntry.h:86
 TGNumberEntry.h:87
 TGNumberEntry.h:88
 TGNumberEntry.h:89
 TGNumberEntry.h:90
 TGNumberEntry.h:91
 TGNumberEntry.h:92
 TGNumberEntry.h:93
 TGNumberEntry.h:94
 TGNumberEntry.h:95
 TGNumberEntry.h:96
 TGNumberEntry.h:97
 TGNumberEntry.h:98
 TGNumberEntry.h:99
 TGNumberEntry.h:100
 TGNumberEntry.h:101
 TGNumberEntry.h:102
 TGNumberEntry.h:103
 TGNumberEntry.h:104
 TGNumberEntry.h:105
 TGNumberEntry.h:106
 TGNumberEntry.h:107
 TGNumberEntry.h:108
 TGNumberEntry.h:109
 TGNumberEntry.h:110
 TGNumberEntry.h:111
 TGNumberEntry.h:112
 TGNumberEntry.h:113
 TGNumberEntry.h:114
 TGNumberEntry.h:115
 TGNumberEntry.h:116
 TGNumberEntry.h:117
 TGNumberEntry.h:118
 TGNumberEntry.h:119
 TGNumberEntry.h:120
 TGNumberEntry.h:121
 TGNumberEntry.h:122
 TGNumberEntry.h:123
 TGNumberEntry.h:124
 TGNumberEntry.h:125
 TGNumberEntry.h:126
 TGNumberEntry.h:127
 TGNumberEntry.h:128
 TGNumberEntry.h:129
 TGNumberEntry.h:130
 TGNumberEntry.h:131
 TGNumberEntry.h:132
 TGNumberEntry.h:133
 TGNumberEntry.h:134
 TGNumberEntry.h:135
 TGNumberEntry.h:136
 TGNumberEntry.h:137
 TGNumberEntry.h:138
 TGNumberEntry.h:139
 TGNumberEntry.h:140
 TGNumberEntry.h:141
 TGNumberEntry.h:142
 TGNumberEntry.h:143
 TGNumberEntry.h:144
 TGNumberEntry.h:145
 TGNumberEntry.h:146
 TGNumberEntry.h:147
 TGNumberEntry.h:148
 TGNumberEntry.h:149
 TGNumberEntry.h:150
 TGNumberEntry.h:151
 TGNumberEntry.h:152
 TGNumberEntry.h:153
 TGNumberEntry.h:154
 TGNumberEntry.h:155
 TGNumberEntry.h:156
 TGNumberEntry.h:157
 TGNumberEntry.h:158
 TGNumberEntry.h:159
 TGNumberEntry.h:160
 TGNumberEntry.h:161
 TGNumberEntry.h:162
 TGNumberEntry.h:163
 TGNumberEntry.h:164
 TGNumberEntry.h:165
 TGNumberEntry.h:166
 TGNumberEntry.h:167
 TGNumberEntry.h:168
 TGNumberEntry.h:169
 TGNumberEntry.h:170
 TGNumberEntry.h:171
 TGNumberEntry.h:172
 TGNumberEntry.h:173
 TGNumberEntry.h:174
 TGNumberEntry.h:175
 TGNumberEntry.h:176
 TGNumberEntry.h:177
 TGNumberEntry.h:178
 TGNumberEntry.h:179
 TGNumberEntry.h:180
 TGNumberEntry.h:181
 TGNumberEntry.h:182
 TGNumberEntry.h:183
 TGNumberEntry.h:184
 TGNumberEntry.h:185
 TGNumberEntry.h:186
 TGNumberEntry.h:187
 TGNumberEntry.h:188
 TGNumberEntry.h:189
 TGNumberEntry.h:190
 TGNumberEntry.h:191
 TGNumberEntry.h:192
 TGNumberEntry.h:193
 TGNumberEntry.h:194
 TGNumberEntry.h:195
 TGNumberEntry.h:196
 TGNumberEntry.h:197
 TGNumberEntry.h:198
 TGNumberEntry.h:199
 TGNumberEntry.h:200
 TGNumberEntry.h:201
 TGNumberEntry.h:202
 TGNumberEntry.h:203
 TGNumberEntry.h:204
 TGNumberEntry.h:205
 TGNumberEntry.h:206
 TGNumberEntry.h:207
 TGNumberEntry.h:208
 TGNumberEntry.h:209
 TGNumberEntry.h:210
 TGNumberEntry.h:211
 TGNumberEntry.h:212
 TGNumberEntry.h:213
 TGNumberEntry.h:214
 TGNumberEntry.h:215
 TGNumberEntry.h:216
 TGNumberEntry.h:217
 TGNumberEntry.h:218
 TGNumberEntry.h:219
 TGNumberEntry.h:220
 TGNumberEntry.h:221
 TGNumberEntry.h:222
 TGNumberEntry.h:223
 TGNumberEntry.h:224
 TGNumberEntry.h:225
 TGNumberEntry.h:226
 TGNumberEntry.h:227
 TGNumberEntry.h:228
 TGNumberEntry.h:229
 TGNumberEntry.h:230
 TGNumberEntry.h:231
 TGNumberEntry.h:232
 TGNumberEntry.h:233
 TGNumberEntry.h:234
 TGNumberEntry.h:235
 TGNumberEntry.h:236
 TGNumberEntry.h:237
 TGNumberEntry.h:238
 TGNumberEntry.h:239
 TGNumberEntry.h:240
 TGNumberEntry.h:241
 TGNumberEntry.h:242
 TGNumberEntry.h:243
 TGNumberEntry.h:244
 TGNumberEntry.h:245
 TGNumberEntry.h:246
 TGNumberEntry.h:247
 TGNumberEntry.h:248
 TGNumberEntry.h:249
 TGNumberEntry.h:250
 TGNumberEntry.h:251
 TGNumberEntry.h:252
 TGNumberEntry.h:253
 TGNumberEntry.h:254
 TGNumberEntry.h:255
 TGNumberEntry.h:256
 TGNumberEntry.h:257
 TGNumberEntry.h:258
 TGNumberEntry.h:259
 TGNumberEntry.h:260
 TGNumberEntry.h:261
 TGNumberEntry.h:262
 TGNumberEntry.h:263
 TGNumberEntry.h:264
 TGNumberEntry.h:265
 TGNumberEntry.h:266
 TGNumberEntry.h:267
 TGNumberEntry.h:268
 TGNumberEntry.h:269
 TGNumberEntry.h:270
 TGNumberEntry.h:271
 TGNumberEntry.h:272
 TGNumberEntry.h:273
 TGNumberEntry.h:274
 TGNumberEntry.h:275
 TGNumberEntry.h:276
 TGNumberEntry.h:277
 TGNumberEntry.h:278
 TGNumberEntry.h:279
 TGNumberEntry.h:280
 TGNumberEntry.h:281
 TGNumberEntry.h:282
 TGNumberEntry.h:283
 TGNumberEntry.h:284
 TGNumberEntry.h:285
 TGNumberEntry.h:286
 TGNumberEntry.h:287
 TGNumberEntry.h:288
 TGNumberEntry.h:289
 TGNumberEntry.h:290
 TGNumberEntry.h:291
 TGNumberEntry.h:292
 TGNumberEntry.h:293
 TGNumberEntry.h:294
 TGNumberEntry.h:295
 TGNumberEntry.h:296
 TGNumberEntry.h:297
 TGNumberEntry.h:298
 TGNumberEntry.h:299
 TGNumberEntry.h:300
 TGNumberEntry.h:301
 TGNumberEntry.h:302
 TGNumberEntry.h:303
 TGNumberEntry.h:304
 TGNumberEntry.h:305
 TGNumberEntry.h:306
 TGNumberEntry.h:307
 TGNumberEntry.h:308
 TGNumberEntry.h:309
 TGNumberEntry.h:310
 TGNumberEntry.h:311