Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXTextField.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * T e x t F i e l d W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXTextField.h,v 1.62 2006/01/22 17:58:11 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXTEXTFIELD_H
25 #define FXTEXTFIELD_H
26 
27 #ifndef FXFRAME_H
28 #include "FXFrame.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Textfield styles
35 enum {
36  TEXTFIELD_PASSWD = 0x00080000, /// Password mode
37  TEXTFIELD_INTEGER = 0x00100000, /// Integer mode
38  TEXTFIELD_REAL = 0x00200000, /// Real mode
39  TEXTFIELD_READONLY = 0x00400000, /// NOT editable
40  TEXTFIELD_ENTER_ONLY = 0x00800000, /// Only callback when enter hit
41  TEXTFIELD_LIMITED = 0x01000000, /// Limit entry to given number of columns
42  TEXTFIELD_OVERSTRIKE = 0x02000000, /// Overstrike mode
43  TEXTFIELD_AUTOGRAY = 0x04000000, /// Automatically gray out text field when not updated
44  TEXTFIELD_AUTOHIDE = 0x08000000, /// Automatically hide text field when not updated
46  };
47 
48 
49 /**
50 * A text field is a single-line text entry widget.
51 * The text field widget supports clipboard for cut-and-paste
52 * operations.
53 * Text input may be constrained to a certain format; the built-in
54 * capabilities support integer and real number entry constraints;
55 * additional constraints on the input may be implemented by intercepting
56 * the SEL_VERIFY message; a custom handler should examine the tentative
57 * input string passed as type const FXchar* in the message data, and return
58 * a value of "0" if the new input is accepted.
59 * During text entry, the text field sends a SEL_CHANGED message to its target,
60 * with the message data set to the current text value of type const FXchar*.
61 * When the text is accepted by hitting ENTER, the SEL_COMMAND message is sent.
62 * The text field also sends SEL_COMMAND when the focus moves to another control.
63 * TEXTFIELD_ENTER_ONLY can be passed to suppress this feature. Typically, this
64 * flag is used in dialogs that close when ENTER is hit in a text field.
65 */
66 class FXAPI FXTextField : public FXFrame {
68 protected:
69  FXString contents; // Edited text
70  const FXchar *delimiters; // Set of delimiters
71  FXFont *font; // Text font
72  FXColor textColor; // Text color
73  FXColor selbackColor; // Selected background color
74  FXColor seltextColor; // Selected text color
75  FXColor cursorColor; // Color of the Cursor
76  FXint cursor; // Cursor position
77  FXint anchor; // Anchor position
78  FXint columns; // Number of columns visible
79  FXint shift; // Shift amount
80  FXString clipped; // Clipped text
81  FXString help; // Help string
82  FXString tip; // Tooltip
83 protected:
84  FXTextField();
85  FXint index(FXint x) const;
86  FXint coord(FXint i) const;
87  void drawCursor(FXuint state);
88  void drawTextRange(FXDCWindow& dc,FXint fm,FXint to);
89  void drawTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
90  void drawPWDTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to);
91  FXint rightWord(FXint pos) const;
92  FXint leftWord(FXint pos) const;
93  FXint wordStart(FXint pos) const;
94  FXint wordEnd(FXint pos) const;
95 private:
96  FXTextField(const FXTextField&);
97  FXTextField& operator=(const FXTextField&);
98 public:
99  long onPaint(FXObject*,FXSelector,void*);
100  long onUpdate(FXObject*,FXSelector,void*);
101  long onKeyPress(FXObject*,FXSelector,void*);
102  long onKeyRelease(FXObject*,FXSelector,void*);
103  long onLeftBtnPress(FXObject*,FXSelector,void*);
104  long onLeftBtnRelease(FXObject*,FXSelector,void*);
105  long onMiddleBtnPress(FXObject*,FXSelector,void*);
106  long onMiddleBtnRelease(FXObject*,FXSelector,void*);
107  long onVerify(FXObject*,FXSelector,void*);
108  long onMotion(FXObject*,FXSelector,void*);
109  long onSelectionLost(FXObject*,FXSelector,void*);
110  long onSelectionGained(FXObject*,FXSelector,void*);
111  long onSelectionRequest(FXObject*,FXSelector,void* ptr);
112  long onClipboardLost(FXObject*,FXSelector,void*);
113  long onClipboardGained(FXObject*,FXSelector,void*);
114  long onClipboardRequest(FXObject*,FXSelector,void*);
115  long onFocusSelf(FXObject*,FXSelector,void*);
116  long onFocusIn(FXObject*,FXSelector,void*);
117  long onFocusOut(FXObject*,FXSelector,void*);
118  long onBlink(FXObject*,FXSelector,void*);
119  long onAutoScroll(FXObject*,FXSelector,void*);
120  long onCmdSetValue(FXObject*,FXSelector,void*);
121  long onCmdSetIntValue(FXObject*,FXSelector,void*);
122  long onCmdSetRealValue(FXObject*,FXSelector,void*);
123  long onCmdSetStringValue(FXObject*,FXSelector,void*);
124  long onCmdGetIntValue(FXObject*,FXSelector,void*);
125  long onCmdGetRealValue(FXObject*,FXSelector,void*);
126  long onCmdGetStringValue(FXObject*,FXSelector,void*);
127  long onCmdCursorHome(FXObject*,FXSelector,void*);
128  long onCmdCursorEnd(FXObject*,FXSelector,void*);
129  long onCmdCursorRight(FXObject*,FXSelector,void*);
130  long onCmdCursorLeft(FXObject*,FXSelector,void*);
131  long onCmdCursorWordLeft(FXObject*,FXSelector,void*);
132  long onCmdCursorWordRight(FXObject*,FXSelector,void*);
133  long onCmdCursorWordStart(FXObject*,FXSelector,void*);
134  long onCmdCursorWordEnd(FXObject*,FXSelector,void*);
135  long onCmdMark(FXObject*,FXSelector,void*);
136  long onCmdExtend(FXObject*,FXSelector,void*);
137  long onCmdSelectAll(FXObject*,FXSelector,void*);
138  long onCmdDeselectAll(FXObject*,FXSelector,void*);
139  long onCmdCutSel(FXObject*,FXSelector,void*);
140  long onCmdCopySel(FXObject*,FXSelector,void*);
141  long onCmdPasteSel(FXObject*,FXSelector,void*);
142  long onCmdPasteMiddle(FXObject*,FXSelector,void*);
143  long onCmdDeleteSel(FXObject*,FXSelector,void*);
144  long onCmdDeleteAll(FXObject*,FXSelector,void*);
145  long onCmdOverstString(FXObject*,FXSelector,void*);
146  long onCmdInsertString(FXObject*,FXSelector,void*);
147  long onCmdBackspace(FXObject*,FXSelector,void*);
148  long onCmdDelete(FXObject*,FXSelector,void*);
149  long onCmdToggleEditable(FXObject*,FXSelector,void*);
150  long onUpdToggleEditable(FXObject*,FXSelector,void*);
151  long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
152  long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
153  long onUpdHaveSelection(FXObject*,FXSelector,void*);
154  long onUpdSelectAll(FXObject*,FXSelector,void*);
155  long onCmdSetHelp(FXObject*,FXSelector,void*);
156  long onCmdGetHelp(FXObject*,FXSelector,void*);
157  long onCmdSetTip(FXObject*,FXSelector,void*);
158  long onCmdGetTip(FXObject*,FXSelector,void*);
159  long onQueryHelp(FXObject*,FXSelector,void*);
160  long onQueryTip(FXObject*,FXSelector,void*);
161 public:
163  /// Default text delimiters
164  static const FXchar textDelimiters[];
166 public:
168  enum{
169  ID_CURSOR_HOME=FXFrame::ID_LAST,
170  ID_CURSOR_END,
171  ID_CURSOR_RIGHT,
172  ID_CURSOR_LEFT,
173  ID_CURSOR_WORD_LEFT,
174  ID_CURSOR_WORD_RIGHT,
175  ID_CURSOR_WORD_START,
176  ID_CURSOR_WORD_END,
177  ID_MARK,
178  ID_EXTEND,
179  ID_SELECT_ALL,
180  ID_DESELECT_ALL,
181  ID_CUT_SEL,
182  ID_COPY_SEL,
183  ID_PASTE_SEL,
184  ID_PASTE_MIDDLE,
185  ID_DELETE_SEL,
186  ID_DELETE_ALL,
187  ID_OVERST_STRING,
188  ID_INSERT_STRING,
189  ID_BACKSPACE,
190  ID_DELETE,
191  ID_TOGGLE_EDITABLE,
192  ID_TOGGLE_OVERSTRIKE,
193  ID_BLINK,
194  ID_LAST
195  };
196 
197 public:
198 
199  /// Construct text field wide enough to display ncols columns
201 
202  /// Create server-side resources
203  virtual void create();
204 
205  /// Perform layout
206  virtual void layout();
207 
208  /// Enable text field
209  virtual void enable();
210 
211  /// Disable text field
212  virtual void disable();
213 
214  /// Return default width
215  virtual FXint getDefaultWidth();
216 
217  /// Return default height
218  virtual FXint getDefaultHeight();
219 
220  /// Yes, text field may receive focus
221  virtual bool canFocus() const;
223  /// Move the focus to this window
224  virtual void setFocus();
225 
226  /// Remove the focus from this window
227  virtual void killFocus();
229  /// Set editable mode
230  void setEditable(FXbool edit=TRUE);
231 
232  /// Return TRUE if text field may be edited
233  FXbool isEditable() const;
235  /// Set overstrike mode
236  void setOverstrike(FXbool over=TRUE);
237 
238  /// Return TRUE if overstrike mode in effect
239  FXbool isOverstrike() const;
241  /// Set cursor position
242  void setCursorPos(FXint pos);
243 
244  /// Return cursor position
245  FXint getCursorPos() const { return cursor; }
247  /// Change anchor position
248  void setAnchorPos(FXint pos);
249 
250  /// Return anchor position
251  FXint getAnchorPos() const { return anchor; }
253  /// Change the text and move cursor to end
254  void setText(const FXString& text,FXbool notify=FALSE);
255 
256  /// Get the text for this label
257  FXString getText() const { return contents; }
259  /// Set the text font
260  void setFont(FXFont* fnt);
261 
262  /// Get the text font
263  FXFont* getFont() const { return font; }
265  /// Change text color
266  void setTextColor(FXColor clr);
267 
268  /// Return text color
269  FXColor getTextColor() const { return textColor; }
270 
271  /// Change selected background color
272  void setSelBackColor(FXColor clr);
274  /// Return selected background color
275  FXColor getSelBackColor() const { return selbackColor; }
276 
277  /// Change selected text color
278  void setSelTextColor(FXColor clr);
279 
280  /// Return selected text color
281  FXColor getSelTextColor() const { return seltextColor; }
282 
283  /// Changes the cursor color
284  void setCursorColor(FXColor clr);
285 
286  /// Return the cursor color
287  FXColor getCursorColor() const { return cursorColor; }
289  /**
290  * Change the default width of the text field in terms of a number
291  * of columns times the width of the numeral '8'.
292  */
293  void setNumColumns(FXint cols);
295  /// Return number of columns
296  FXint getNumColumns() const { return columns; }
298  /**
299  * Change text justification mode. The justify mode is a combination of
300  * horizontal justification (JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER_X),
301  * and vertical justification (JUSTIFY_TOP, JUSTIFY_BOTTOM, JUSTIFY_CENTER_Y).
302  * Note that JUSTIFY_CENTER_X can not be set from the constructor since by
303  * default text fields are left-justified.
304  */
305  void setJustify(FXuint mode);
306 
307  /// Return text justification mode
308  FXuint getJustify() const;
309 
310  /// Change word delimiters
311  void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; }
312 
313  /// Return word delimiters
314  const FXchar* getDelimiters() const { return delimiters; }
315 
316  /// Set the status line help text for this label
317  void setHelpText(const FXString& text){ help=text; }
318 
319  /// Get the status line help text for this label
320  const FXString& getHelpText() const { return help; }
321 
322  /// Set the tool tip message for this text field
323  void setTipText(const FXString& text){ tip=text; }
324 
325  /// Get the tool tip message for this text field
326  const FXString& getTipText() const { return tip; }
327 
328  /// Change text style
329  void setTextStyle(FXuint style);
330 
331  /// Return text style
332  FXuint getTextStyle() const;
333 
334  /// Select all text
335  FXbool selectAll();
336 
337  /// Select len characters starting at given position pos
338  FXbool setSelection(FXint pos,FXint len);
339 
340  /// Extend the selection from the anchor to the given position
341  FXbool extendSelection(FXint pos);
342 
343  /// Unselect the text
344  FXbool killSelection();
345 
346  /// Return TRUE if position pos is selected
347  FXbool isPosSelected(FXint pos) const;
348 
349  /// Return TRUE if position is fully visible
350  FXbool isPosVisible(FXint pos) const;
351 
352  /// Scroll text to make the given position visible
353  void makePositionVisible(FXint pos);
354 
355  /// Save text field to a stream
356  virtual void save(FXStream& store) const;
357 
358  /// Load text field from a stream
359  virtual void load(FXStream& store);
360 
361  /// Destructor
362  virtual ~FXTextField();
363  };
364 
365 }
366 
367 #endif
Overstrike mode.
Definition: FXTextField.h:45
char FXchar
Definition: fxdefs.h:380
Real mode.
Definition: FXTextField.h:41
#define TRUE
Definition: fxdefs.h:32
The Frame widget provides borders around some contents.
Definition: FXFrame.h:73
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:389
Automatically hide text field when not updated.
Definition: FXTextField.h:47
Password mode.
Definition: FXTextField.h:39
Definition: FXFrame.h:56
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:386
Sunken border.
Definition: FXWindow.h:76
Base composite.
Definition: FXComposite.h:35
#define NULL
Definition: fxdefs.h:41
NOT editable.
Definition: FXTextField.h:42
FXuint FXColor
Definition: fxdefs.h:447
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
A text field is a single-line text entry widget.
Definition: FXTextField.h:73
Automatically gray out text field when not updated.
Definition: FXTextField.h:46
#define FALSE
Definition: fxdefs.h:35
Definition: FXTextField.h:48
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
Window Device Context.
Definition: FXDCWindow.h:52
Integer mode.
Definition: FXTextField.h:40
Thick border.
Definition: FXWindow.h:78
Only callback when enter hit.
Definition: FXTextField.h:43
Font class.
Definition: FXFont.h:142
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Limit entry to given number of columns.
Definition: FXTextField.h:44
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp