Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGTextEntry.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 08/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TGTextEntry
13 #define ROOT_TGTextEntry
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGTextEntry //
19 // //
20 // A TGTextEntry is a one line text input widget. //
21 // //
22 // Changing text in the text entry widget will generate the event: //
23 // kC_TEXTENTRY, kTE_TEXTCHANGED, widget id, 0. //
24 // Hitting the enter key will generate: //
25 // kC_TEXTENTRY, kTE_ENTER, widget id, 0. //
26 // Hitting the tab key will generate: //
27 // kC_TEXTENTRY, kTE_TAB, widget id, 0. //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 #include "TGFrame.h"
32 #include "TGWidget.h"
33 #include "TGTextBuffer.h"
34 
35 class TBlinkTimer;
36 class TGToolTip;
37 class TColor;
38 
39 class TGTextEntry : public TGFrame, public TGWidget {
40 
41 public:
42  enum EEchoMode { kNormal, kNoEcho, kPassword };
43  enum EInsertMode { kInsert, kReplace };
44 
45 protected:
46  TGTextBuffer *fText; // text buffer
47  Int_t fStartX; // selection begin in pixels
48  Int_t fEndX; // selection end in pixels
49  Int_t fStartIX; // selection begin in characters
50  Int_t fEndIX; // selection end in characters
51  Bool_t fSelectionOn; // selection status (on/off)
52  Int_t fOffset; // start position of text (in pixels)
53  Int_t fCursorX; // cursor position in pixels
54  Int_t fCursorIX; // cursor position in characters
55  Bool_t fCursorOn; // cursor status (on/off)
56  FontStruct_t fFontStruct; // text font
57  TGGC fNormGC; // normal drawing context
58  TGGC fSelGC; // selected text drawing context
59  GContext_t fSelbackGC; // selected background drawing context
60  Atom_t fClipboard; // clipboard property
61  TBlinkTimer *fCurBlink; // cursor blink timer
62  TGToolTip *fTip; // associated tooltip
63  Int_t fMaxLen; // maximum length of text
64  Bool_t fEdited; // kFALSE, if the line edit's contents have not been changed since the construction
65  Bool_t fFrameDrawn; // kTRUE draw itself inside a two-pixel frame, kFALSE draw without any frame
66  EEchoMode fEchoMode; // *OPTION={GetMethod="GetEchoMode";SetMethod="SetEchoMode";Items=(kNormal="Normal",kNoEcho="No Echo",kPassword="Password")}*
67  EInsertMode fInsertMode; // *OPTION={GetMethod="GetInsertMode";SetMethod="SetInsertMode";Items=(kInsert="Insert",kReplace="Replace")}*
68  ETextJustification fAlignment; // *OPTION={GetMethod="GetAlignment";SetMethod="SetAlignment";Items=(kTextLeft="Left",kTextCenterX="Center",kTextRight="Right")}*
69  Bool_t fHasOwnFont; // kTRUE - font defined locally, kFALSE - globally
70  UInt_t fDefWidth; // default width
71  UInt_t fDefHeight; // default height
72 
73  void CopyText() const;
74  virtual void DoRedraw();
75  Int_t GetCharacterIndex(Int_t xcoord);
76  virtual void Init();
77  virtual Bool_t IsCursorOutOfFrame();
78  void Paste();
79  virtual void PastePrimary(Window_t wid, Atom_t property, Bool_t del);
80  virtual void ScrollByChar();
81  virtual void UpdateOffset();
82 
83  static TString *fgClipboardText; // application clipboard text
84  static const TGFont *fgDefaultFont;
85  static const TGGC *fgDefaultSelectedGC;
86  static const TGGC *fgDefaultSelectedBackgroundGC;
87  static const TGGC *fgDefaultGC;
88 
89  static const TGGC &GetDefaultSelectedGC();
90  static const TGGC &GetDefaultSelectedBackgroundGC();
91 
92 private:
93  TGTextEntry(const TGTextEntry&); // not implemented
94  TGTextEntry& operator=(const TGTextEntry&); // not implemented
95 
96 public:
97  static FontStruct_t GetDefaultFontStruct();
98  static const TGGC &GetDefaultGC();
99 
100  TGTextEntry(const TGWindow *p, TGTextBuffer *text, Int_t id = -1,
101  GContext_t norm = GetDefaultGC()(),
102  FontStruct_t font = GetDefaultFontStruct(),
103  UInt_t option = kSunkenFrame | kDoubleBorder,
104  Pixel_t back = GetWhitePixel());
105 
106  TGTextEntry(const TGWindow *parent = 0, const char *text = 0, Int_t id = -1);
107  TGTextEntry(const TString &contents, const TGWindow *parent, Int_t id = -1);
108 
109  virtual ~TGTextEntry();
110 
111  virtual TGDimension GetDefaultSize() const;
112  virtual void SetDefaultSize(UInt_t w, UInt_t h);
113 
114  virtual void AppendText(const char *text);
115  void Backspace();
116  void Clear(Option_t *option="");
117  void CursorLeft(Bool_t mark = kFALSE , Int_t steps = 1);
118  void CursorRight(Bool_t mark = kFALSE , Int_t steps = 1);
119  void CursorWordForward(Bool_t mark = kFALSE);
120  void CursorWordBackward(Bool_t mark = kFALSE);
121  void Cut();
122  void Del();
123  void Deselect();
124  virtual void DrawBorder();
125  void End(Bool_t mark = kFALSE);
126  ETextJustification GetAlignment() const { return fAlignment; }
127  TGTextBuffer *GetBuffer() const { return fText; }
128  Int_t GetCursorPosition() const { return fCursorIX; }
129  TString GetDisplayText() const;
130  EEchoMode GetEchoMode() const { return fEchoMode; }
131  EInsertMode GetInsertMode() const { return fInsertMode; }
132  TString GetMarkedText() const;
133  Int_t GetMaxLength() const { return fMaxLen; }
134  const char *GetText() const { return fText->GetString(); }
135  virtual TGToolTip *GetToolTip() const { return fTip; }
136  virtual const char *GetTitle() const { return GetText(); }
137  Bool_t HasMarkedText() const { return fSelectionOn && (fStartIX != fEndIX); }
138  Pixel_t GetTextColor() const { return fNormGC.GetForeground(); }
139  FontStruct_t GetFontStruct() const { return fFontStruct; }
140  void Home(Bool_t mark = kFALSE);
141  virtual void Insert(const char *);
142  virtual void InsertText(const char *text, Int_t pos);
143  Bool_t IsFrameDrawn() const { return fFrameDrawn; }
144  Bool_t IsEdited() const { return fEdited; }
145  virtual void Layout() { UpdateOffset(); }
146  void MarkWord(Int_t pos);
147  Int_t MaxMark() const { return fStartIX > fEndIX ? fStartIX : fEndIX; }
148  Int_t MinMark() const { return fStartIX < fEndIX ? fStartIX : fEndIX; }
149  void NewMark(Int_t pos);
150  void Remove();
151  virtual void RemoveText(Int_t start, Int_t end);
152  virtual void SetFont(TGFont *font, Bool_t local = kTRUE);
153  virtual void SetFont(FontStruct_t font, Bool_t local = kTRUE);
154  virtual void SetFont(const char *fontName, Bool_t local = kTRUE);
155  virtual void SetTextColor(Pixel_t color, Bool_t local = kTRUE);
156  virtual void SetTextColor(TColor *color, Bool_t local = kTRUE);
157  virtual void SetText(const char *text, Bool_t emit = kTRUE); //*MENU*
158  virtual void SetToolTipText(const char *text, Long_t delayms = 500); //*MENU*
159  virtual void SetMaxLength(Int_t maxlen); //*MENU*
160  virtual void SelectAll();
161  virtual void SetAlignment(ETextJustification mode = kTextLeft); //*SUBMENU*
162  virtual void SetInsertMode(EInsertMode mode = kInsert); //*SUBMENU*
163  virtual void SetEchoMode(EEchoMode mode = kNormal); //*SUBMENU*
164  void SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); } //*TOGGLE* *GETTER=IsEnabled
165  virtual void SetCursorPosition(Int_t pos);
166  void SetEdited(Bool_t flag = kTRUE) { fEdited = flag; }
167  virtual void SetFocus();
168  virtual void SetFrameDrawn(Bool_t flag = kTRUE);
169  virtual void SetState(Bool_t state);
170  virtual void SetTitle(const char *label) { SetText(label); }
171  virtual void SetForegroundColor(Pixel_t fore) { SetTextColor(fore, kFALSE); }
172  Pixel_t GetForeground() const { return fNormGC.GetForeground(); }
173  Bool_t HasOwnFont() const { return fHasOwnFont; }
174 
175  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
176 
177  virtual Bool_t HandleButton(Event_t *event);
178  virtual Bool_t HandleDoubleClick(Event_t *event);
179  virtual Bool_t HandleCrossing(Event_t *event);
180  virtual Bool_t HandleMotion(Event_t *event);
181  virtual Bool_t HandleKey(Event_t *event);
182  virtual Bool_t HandleFocusChange(Event_t *event);
183  virtual Bool_t HandleSelection(Event_t *event);
184  virtual Bool_t HandleSelectionClear(Event_t *event);
185  virtual Bool_t HandleSelectionRequest(Event_t *event);
186  virtual Bool_t HandleTimer(TTimer *t);
187  virtual Bool_t HandleConfigureNotify(Event_t *event);
188 
189  virtual void TextChanged(const char *text = 0); //*SIGNAL*
190  virtual void ReturnPressed(); //*SIGNAL*
191  virtual void TabPressed(); //*SIGNAL*
192  virtual void ShiftTabPressed(); //*SIGNAL*
193  virtual void CursorOutLeft(); //*SIGNAL*
194  virtual void CursorOutRight(); //*SIGNAL*
195  virtual void CursorOutUp(); //*SIGNAL*
196  virtual void CursorOutDown(); //*SIGNAL*
197  virtual void DoubleClicked(); //*SIGNAL*
198 
199  ClassDef(TGTextEntry,0) // The TGTextEntry widget is a simple line editor for inputting text
200 };
201 
202 #endif