Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_TGFrame
32 #include "TGFrame.h"
33 #endif
34 #ifndef ROOT_TGWidget
35 #include "TGWidget.h"
36 #endif
37 #ifndef ROOT_TGTextBuffer
38 #include "TGTextBuffer.h"
39 #endif
40 
41 class TBlinkTimer;
42 class TGToolTip;
43 class TColor;
44 
45 class TGTextEntry : public TGFrame, public TGWidget {
46 
47 public:
50 
51 protected:
52  TGTextBuffer *fText; // text buffer
53  Int_t fStartX; // selection begin in pixels
54  Int_t fEndX; // selection end in pixels
55  Int_t fStartIX; // selection begin in characters
56  Int_t fEndIX; // selection end in characters
57  Bool_t fSelectionOn; // selection status (on/off)
58  Int_t fOffset; // start position of text (in pixels)
59  Int_t fCursorX; // cursor position in pixels
60  Int_t fCursorIX; // cursor position in characters
61  Bool_t fCursorOn; // cursor status (on/off)
62  FontStruct_t fFontStruct; // text font
63  TGGC fNormGC; // normal drawing context
64  TGGC fSelGC; // selected text drawing context
65  GContext_t fSelbackGC; // selected background drawing context
66  Atom_t fClipboard; // clipboard property
67  TBlinkTimer *fCurBlink; // cursor blink timer
68  TGToolTip *fTip; // associated tooltip
69  Int_t fMaxLen; // maximum length of text
70  Bool_t fEdited; // kFALSE, if the line edit's contents have not been changed since the construction
71  Bool_t fFrameDrawn; // kTRUE draw itself inside a two-pixel frame, kFALSE draw without any frame
72  EEchoMode fEchoMode; // *OPTION={GetMethod="GetEchoMode";SetMethod="SetEchoMode";Items=(kNormal="Normal",kNoEcho="No Echo",kPassword="Password")}*
73  EInsertMode fInsertMode; // *OPTION={GetMethod="GetInsertMode";SetMethod="SetInsertMode";Items=(kInsert="Insert",kReplace="Replace")}*
74  ETextJustification fAlignment; // *OPTION={GetMethod="GetAlignment";SetMethod="SetAlignment";Items=(kTextLeft="Left",kTextCenterX="Center",kTextRight="Right")}*
75  Bool_t fHasOwnFont; // kTRUE - font defined locally, kFALSE - globally
76  UInt_t fDefWidth; // default width
77  UInt_t fDefHeight; // default height
78 
79  void CopyText() const;
80  virtual void DoRedraw();
82  virtual void Init();
83  virtual Bool_t IsCursorOutOfFrame();
84  void Paste();
85  virtual void PastePrimary(Window_t wid, Atom_t property, Bool_t del);
86  virtual void ScrollByChar();
87  virtual void UpdateOffset();
88 
89  static TString *fgClipboardText; // application clipboard text
90  static const TGFont *fgDefaultFont;
91  static const TGGC *fgDefaultSelectedGC;
93  static const TGGC *fgDefaultGC;
94 
95  static const TGGC &GetDefaultSelectedGC();
96  static const TGGC &GetDefaultSelectedBackgroundGC();
97 
98 private:
99  TGTextEntry(const TGTextEntry&); // not implemented
100  TGTextEntry& operator=(const TGTextEntry&); // not implemented
101 
102 public:
104  static const TGGC &GetDefaultGC();
105 
106  TGTextEntry(const TGWindow *p, TGTextBuffer *text, Int_t id = -1,
109  UInt_t option = kSunkenFrame | kDoubleBorder,
110  Pixel_t back = GetWhitePixel());
111 
112  TGTextEntry(const TGWindow *parent = 0, const char *text = 0, Int_t id = -1);
113  TGTextEntry(const TString &contents, const TGWindow *parent, Int_t id = -1);
114 
115  virtual ~TGTextEntry();
116 
117  virtual TGDimension GetDefaultSize() const;
118  virtual void SetDefaultSize(UInt_t w, UInt_t h);
119 
120  virtual void AppendText(const char *text);
121  void Backspace();
122  void Clear(Option_t *option="");
123  void CursorLeft(Bool_t mark = kFALSE , Int_t steps = 1);
124  void CursorRight(Bool_t mark = kFALSE , Int_t steps = 1);
127  void Cut();
128  void Del();
129  void Deselect();
130  virtual void DrawBorder();
131  void End(Bool_t mark = kFALSE);
133  TGTextBuffer *GetBuffer() const { return fText; }
134  Int_t GetCursorPosition() const { return fCursorIX; }
135  TString GetDisplayText() const;
136  EEchoMode GetEchoMode() const { return fEchoMode; }
138  TString GetMarkedText() const;
139  Int_t GetMaxLength() const { return fMaxLen; }
140  const char *GetText() const { return fText->GetString(); }
141  virtual TGToolTip *GetToolTip() const { return fTip; }
142  virtual const char *GetTitle() const { return GetText(); }
143  Bool_t HasMarkedText() const { return fSelectionOn && (fStartIX != fEndIX); }
144  Pixel_t GetTextColor() const { return fNormGC.GetForeground(); }
146  void Home(Bool_t mark = kFALSE);
147  virtual void Insert(const char *);
148  virtual void InsertText(const char *text, Int_t pos);
149  Bool_t IsFrameDrawn() const { return fFrameDrawn; }
150  Bool_t IsEdited() const { return fEdited; }
151  virtual void Layout() { UpdateOffset(); }
152  void MarkWord(Int_t pos);
153  Int_t MaxMark() const { return fStartIX > fEndIX ? fStartIX : fEndIX; }
154  Int_t MinMark() const { return fStartIX < fEndIX ? fStartIX : fEndIX; }
155  void NewMark(Int_t pos);
156  void Remove();
157  virtual void RemoveText(Int_t start, Int_t end);
158  virtual void SetFont(TGFont *font, Bool_t local = kTRUE);
159  virtual void SetFont(FontStruct_t font, Bool_t local = kTRUE);
160  virtual void SetFont(const char *fontName, Bool_t local = kTRUE);
161  virtual void SetTextColor(Pixel_t color, Bool_t local = kTRUE);
162  virtual void SetTextColor(TColor *color, Bool_t local = kTRUE);
163  virtual void SetText(const char *text, Bool_t emit = kTRUE); //*MENU*
164  virtual void SetToolTipText(const char *text, Long_t delayms = 500); //*MENU*
165  virtual void SetMaxLength(Int_t maxlen); //*MENU*
166  virtual void SelectAll();
167  virtual void SetAlignment(ETextJustification mode = kTextLeft); //*SUBMENU*
168  virtual void SetInsertMode(EInsertMode mode = kInsert); //*SUBMENU*
169  virtual void SetEchoMode(EEchoMode mode = kNormal); //*SUBMENU*
170  void SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); } //*TOGGLE* *GETTER=IsEnabled
171  virtual void SetCursorPosition(Int_t pos);
172  void SetEdited(Bool_t flag = kTRUE) { fEdited = flag; }
173  virtual void SetFocus();
174  virtual void SetFrameDrawn(Bool_t flag = kTRUE);
175  virtual void SetState(Bool_t state);
176  virtual void SetTitle(const char *label) { SetText(label); }
177  virtual void SetForegroundColor(Pixel_t fore) { SetTextColor(fore, kFALSE); }
178  Pixel_t GetForeground() const { return fNormGC.GetForeground(); }
179  Bool_t HasOwnFont() const { return fHasOwnFont; }
180 
181  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
182 
183  virtual Bool_t HandleButton(Event_t *event);
184  virtual Bool_t HandleDoubleClick(Event_t *event);
185  virtual Bool_t HandleCrossing(Event_t *event);
186  virtual Bool_t HandleMotion(Event_t *event);
187  virtual Bool_t HandleKey(Event_t *event);
188  virtual Bool_t HandleFocusChange(Event_t *event);
189  virtual Bool_t HandleSelection(Event_t *event);
190  virtual Bool_t HandleSelectionClear(Event_t *event);
191  virtual Bool_t HandleSelectionRequest(Event_t *event);
192  virtual Bool_t HandleTimer(TTimer *t);
193  virtual Bool_t HandleConfigureNotify(Event_t *event);
194 
195  virtual void TextChanged(const char *text = 0); //*SIGNAL*
196  virtual void ReturnPressed(); //*SIGNAL*
197  virtual void TabPressed(); //*SIGNAL*
198  virtual void ShiftTabPressed(); //*SIGNAL*
199  virtual void CursorOutLeft(); //*SIGNAL*
200  virtual void CursorOutRight(); //*SIGNAL*
201  virtual void CursorOutUp(); //*SIGNAL*
202  virtual void CursorOutDown(); //*SIGNAL*
203  virtual void DoubleClicked(); //*SIGNAL*
204 
205  ClassDef(TGTextEntry,0) // The TGTextEntry widget is a simple line editor for inputting text
206 };
207 
208 #endif
void CursorRight(Bool_t mark=kFALSE, Int_t steps=1)
Moves the cursor rightwards one or more characters.
Bool_t IsEdited() const
Definition: TGTextEntry.h:150
static const TGGC & GetDefaultGC()
Return default graphics context.
Int_t fEndIX
Definition: TGTextEntry.h:56
static const TGGC * fgDefaultSelectedBackgroundGC
Definition: TGTextEntry.h:92
Handle_t FontStruct_t
Definition: GuiTypes.h:40
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle request to send current clipboard contents to requestor window.
Int_t GetCursorPosition() const
Definition: TGTextEntry.h:134
Bool_t HasMarkedText() const
Definition: TGTextEntry.h:143
Int_t GetMaxLength() const
Definition: TGTextEntry.h:139
Bool_t fCursorOn
Definition: TGTextEntry.h:61
virtual void DrawBorder()
Draw the border of the text entry widget.
static const TGGC & GetDefaultSelectedBackgroundGC()
Return graphics context for highlighted frame background.
virtual void Init()
Do default initialization.
virtual void ShiftTabPressed()
This signal is emitted when <SHIFT> and <TAB> keys are pressed.
virtual void SetAlignment(ETextJustification mode=kTextLeft)
Sets the alignment of the text entry.
Bool_t HasOwnFont() const
Definition: TGTextEntry.h:179
virtual void TabPressed()
This signal is emitted when the <TAB> key is pressed.
virtual Bool_t HandleSelectionClear(Event_t *event)
Handle selection clear event.
const char Option_t
Definition: RtypesCore.h:62
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
#define mark(osub)
Definition: triangle.c:1206
virtual Bool_t HandleSelection(Event_t *event)
Handle text selection event.
TH1 * h
Definition: legend2.C:5
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
Pixel_t GetTextColor() const
Definition: TGTextEntry.h:144
Atom_t fClipboard
Definition: TGTextEntry.h:66
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
Int_t fMaxLen
Definition: TGTextEntry.h:69
virtual void SetTextColor(Pixel_t color, Bool_t local=kTRUE)
Changes text color.
Bool_t fEdited
Definition: TGTextEntry.h:70
Handle_t GContext_t
Definition: GuiTypes.h:39
virtual void SetTitle(const char *label)
Definition: TGTextEntry.h:176
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TGGC fNormGC
Definition: TGTextEntry.h:63
virtual void RemoveText(Int_t start, Int_t end)
Removes text at the range, clears the selection and moves the cursor to the end of the line...
virtual void UpdateOffset()
Updates start text offset according GetAlignment() mode, if cursor is out of frame => scroll the text...
virtual void SetInsertMode(EInsertMode mode=kInsert)
Sets the mode how characters are entered to the text entry.
ETextJustification
Definition: TGWidget.h:39
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context.
FontStruct_t fFontStruct
Definition: TGTextEntry.h:62
void CursorWordBackward(Bool_t mark=kFALSE)
Moves the cursor one word to the left.
virtual void Layout()
Definition: TGTextEntry.h:151
EInsertMode GetInsertMode() const
Definition: TGTextEntry.h:137
TString GetMarkedText() const
Returns the text marked by the user (e.g.
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Int_t fStartIX
Definition: TGTextEntry.h:55
virtual void SelectAll()
Selects all text (i.e.
Int_t fOffset
Definition: TGTextEntry.h:58
void Deselect()
Deselects all text (i.e.
EEchoMode fEchoMode
Definition: TGTextEntry.h:72
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
void MarkWord(Int_t pos)
Marks the word nearest to cursor position.
TBlinkTimer * fCurBlink
Definition: TGTextEntry.h:67
virtual void ReturnPressed()
This signal is emitted when the return or enter key is pressed.
UInt_t fDefHeight
Definition: TGTextEntry.h:77
GContext_t fSelbackGC
Definition: TGTextEntry.h:65
ETextJustification fAlignment
Definition: TGTextEntry.h:74
Handle_t Atom_t
Definition: GuiTypes.h:38
void Cut()
Copies the marked text to the clipboard and deletes it, if there is any.
virtual void SetFocus()
Set focus to this text entry.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text entry widget.
const char * GetString() const
Definition: TGTextBuffer.h:49
virtual Bool_t HandleTimer(TTimer *t)
Handle cursor blink timer.
void Del()
Deletes the character on the right side of the text cursor.
EInsertMode fInsertMode
Definition: TGTextEntry.h:73
static const TGGC * fgDefaultSelectedGC
Definition: TGTextEntry.h:91
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text entry widget.
void NewMark(Int_t pos)
New character mark at position pos.
ETextJustification GetAlignment() const
Definition: TGTextEntry.h:132
void End(Bool_t mark=kFALSE)
Moves the text cursor to the right end of the line.
virtual void SetMaxLength(Int_t maxlen)
Set the maximum length of the text in the editor.
virtual void SetDefaultSize(UInt_t w, UInt_t h)
Set the default / minimal size of the widget.
Int_t fEndX
Definition: TGTextEntry.h:54
TGTextBuffer * GetBuffer() const
Definition: TGTextEntry.h:133
TGToolTip * fTip
Definition: TGTextEntry.h:68
virtual void SetFrameDrawn(Bool_t flag=kTRUE)
Sets the text entry to draw itself inside a two-pixel frame if enable is kTRUE, and to draw itself wi...
virtual void InsertText(const char *text, Int_t pos)
Inserts text at position pos, clears the selection and moves the cursor to the end of the line...
Bool_t fFrameDrawn
Definition: TGTextEntry.h:71
Pixel_t GetForeground() const
Definition: TGGC.h:86
EEchoMode GetEchoMode() const
Definition: TGTextEntry.h:136
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a text entry widget as a C++ statement(s) on output stream out.
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t fStartX
Definition: TGTextEntry.h:53
virtual void PastePrimary(Window_t wid, Atom_t property, Bool_t del)
Paste text from selection (either primary or cut buffer) into text entry widget.
void CopyText() const
Copies the marked text to the clipboard, if there is any and GetEchoMode() is kNormal.
void SetEdited(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:172
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Int_t GetCharacterIndex(Int_t xcoord)
Returns the index of the character to whose left edge xcoord is closest.
Int_t MaxMark() const
Definition: TGTextEntry.h:153
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle mouse double click event in the text entry widget.
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual void TextChanged(const char *text=0)
This signal is emitted every time the text has changed.
void Remove()
Deletes all characters on the right side of the cursor.
Pixel_t GetForeground() const
Return frame foreground color.
Definition: TGTextEntry.h:178
static const TGGC * fgDefaultGC
Definition: TGTextEntry.h:93
virtual void CursorOutRight()
This signal is emitted when cursor is going out of right side.
static const TGFont * fgDefaultFont
Definition: TGTextEntry.h:90
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event in text entry widget.
virtual TGDimension GetDefaultSize() const
Return the default / minimal size of the widget.
TGTextBuffer * fText
Definition: TGTextEntry.h:52
UInt_t fDefWidth
Definition: TGTextEntry.h:76
virtual TGToolTip * GetToolTip() const
Definition: TGTextEntry.h:141
const char * GetText() const
Definition: TGTextEntry.h:140
virtual void CursorOutUp()
This signal is emitted when cursor is going out of upper side.
long Long_t
Definition: RtypesCore.h:50
virtual void SetForegroundColor(Pixel_t fore)
Definition: TGTextEntry.h:177
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:170
void CursorLeft(Bool_t mark=kFALSE, Int_t steps=1)
Moves the cursor leftwards one or more characters.
virtual Bool_t IsCursorOutOfFrame()
Returns kTRUE if cursor is out of frame.
Int_t fCursorIX
Definition: TGTextEntry.h:60
virtual void Insert(const char *)
Removes any currently selected text, inserts newText, sets it as the new contents of the text entry...
FontStruct_t GetFontStruct() const
Definition: TGTextEntry.h:145
virtual void SetCursorPosition(Int_t pos)
Set the cursor position to newPos.
TText * text
virtual void CursorOutDown()
This signal is emitted when cursor is going out of bottom side.
virtual void DoRedraw()
Draw the text entry widget.
Definition: TGFont.h:155
virtual void DoubleClicked()
This signal is emitted when widget is double clicked.
virtual void CursorOutLeft()
This signal is emitted when cursor is going out of left side.
The color creation and management class.
Definition: TColor.h:23
Bool_t fSelectionOn
Definition: TGTextEntry.h:57
virtual const char * GetTitle() const
Returns title of object.
Definition: TGTextEntry.h:142
TGTextEntry & operator=(const TGTextEntry &)
Int_t fCursorX
Definition: TGTextEntry.h:59
Int_t MinMark() const
Definition: TGTextEntry.h:154
Bool_t IsFrameDrawn() const
Definition: TGTextEntry.h:149
Handle_t Window_t
Definition: GuiTypes.h:30
virtual void SetFont(TGFont *font, Bool_t local=kTRUE)
Changes text font specified by pointer to TGFont object.
virtual void ScrollByChar()
Shift position of cursor by one character.
TGTextEntry(const TGTextEntry &)
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
void Backspace()
Deletes the character on the left side of the text cursor and moves the cursor one position to the le...
void CursorWordForward(Bool_t mark=kFALSE)
Moves the cursor one word to the right.
void Paste()
Inserts text at the cursor position, deleting any previous marked text.
virtual ~TGTextEntry()
Delete a text entry widget.
void Home(Bool_t mark=kFALSE)
Moves the text cursor to the left end of the line.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line...
virtual void AppendText(const char *text)
Appends text to the end of text entry, clears the selection and moves the cursor to the end of the li...
void Clear(Option_t *option="")
Clears up the text entry.
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetEchoMode(EEchoMode mode=kNormal)
The echo modes available are:
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
Definition: TGGC.h:35
static TString * fgClipboardText
Definition: TGTextEntry.h:89
Bool_t fHasOwnFont
Definition: TGTextEntry.h:75
TString GetDisplayText() const
Returns the text that&#39;s currently displayed.