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

FXTextField.h
1 /********************************************************************************
2 * *
3 * T e x t F i e l d W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXTEXTFIELD_H
22 #define FXTEXTFIELD_H
23 
24 #ifndef FXFRAME_H
25 #include "FXFrame.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 enum {
33  TEXTFIELD_PASSWD = 0x00080000,
34  TEXTFIELD_INTEGER = 0x00100000,
35  TEXTFIELD_REAL = 0x00200000,
36  TEXTFIELD_READONLY = 0x00400000,
37  TEXTFIELD_ENTER_ONLY = 0x00800000,
38  TEXTFIELD_LIMITED = 0x01000000,
39  TEXTFIELD_OVERSTRIKE = 0x02000000,
40  TEXTFIELD_AUTOGRAY = 0x04000000,
41  TEXTFIELD_AUTOHIDE = 0x08000000,
42  TEXTFIELD_NORMAL = FRAME_SUNKEN|FRAME_THICK
43  };
44 
45 
63 class FXAPI FXTextField : public FXFrame {
64  FXDECLARE(FXTextField)
65 protected:
66  FXString contents; // Edited text
67  FXFont *font; // Text font
68  const FXchar *delimiters; // Set of delimiters
69  FXString clipped; // Clipped text
70  FXString help; // Help string
71  FXString tip; // Tooltip
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  FXuint blink; // Next cursor blink state
77  FXint cursor; // Cursor position
78  FXint anchor; // Anchor position
79  FXint columns; // Number of columns visible
80  FXint shift; // Shift amount
81 protected:
82  FXTextField();
83  FXint index(FXint x) const;
84  FXint coord(FXint i) const;
85  FXint leftWord(FXint pos) const;
86  FXint rightWord(FXint pos) const;
87  FXint wordStart(FXint pos) const;
88  FXint wordEnd(FXint pos) const;
89  void drawCursor(FXuint state);
90  void paintCursor(FXDCWindow& dc) const;
91  void eraseCursor(FXDCWindow& dc) const;
92  void drawTextRange(FXDCWindow& dc,FXint fm,FXint to) const;
93  void drawTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to) const;
94  void drawPWDTextFragment(FXDCWindow& dc,FXint x,FXint y,FXint fm,FXint to) const;
95  void enterText(const FXString& text,FXbool notify);
96  FXbool deletePendingSelection(FXbool notify);
97 private:
98  FXTextField(const FXTextField&);
99  FXTextField& operator=(const FXTextField&);
100 public:
101  long onPaint(FXObject*,FXSelector,void*);
102  long onUpdate(FXObject*,FXSelector,void*);
103  long onBlink(FXObject*,FXSelector,void*);
104  long onFocusIn(FXObject*,FXSelector,void*);
105  long onFocusOut(FXObject*,FXSelector,void*);
106  long onFocusSelf(FXObject*,FXSelector,void*);
107  long onMotion(FXObject*,FXSelector,void*);
108  long onAutoScroll(FXObject*,FXSelector,void*);
109  long onLeftBtnPress(FXObject*,FXSelector,void*);
110  long onLeftBtnRelease(FXObject*,FXSelector,void*);
111  long onMiddleBtnPress(FXObject*,FXSelector,void*);
112  long onMiddleBtnRelease(FXObject*,FXSelector,void*);
113  long onKeyPress(FXObject*,FXSelector,void*);
114  long onKeyRelease(FXObject*,FXSelector,void*);
115  long onVerify(FXObject*,FXSelector,void*);
116  long onSelectionLost(FXObject*,FXSelector,void*);
117  long onSelectionGained(FXObject*,FXSelector,void*);
118  long onSelectionRequest(FXObject*,FXSelector,void* ptr);
119  long onClipboardLost(FXObject*,FXSelector,void*);
120  long onClipboardGained(FXObject*,FXSelector,void*);
121  long onClipboardRequest(FXObject*,FXSelector,void*);
122  long onCmdSetTip(FXObject*,FXSelector,void*);
123  long onCmdGetTip(FXObject*,FXSelector,void*);
124  long onCmdSetHelp(FXObject*,FXSelector,void*);
125  long onCmdGetHelp(FXObject*,FXSelector,void*);
126  long onQueryTip(FXObject*,FXSelector,void*);
127  long onQueryHelp(FXObject*,FXSelector,void*);
128  long onUpdIsEditable(FXObject*,FXSelector,void*);
129  long onUpdHaveSelection(FXObject*,FXSelector,void*);
130  long onUpdHaveEditableSelection(FXObject*,FXSelector,void*);
131 
132  // Value access
133  long onCmdSetValue(FXObject*,FXSelector,void*);
134  long onCmdSetIntValue(FXObject*,FXSelector,void*);
135  long onCmdSetLongValue(FXObject*,FXSelector,void*);
136  long onCmdSetRealValue(FXObject*,FXSelector,void*);
137  long onCmdSetStringValue(FXObject*,FXSelector,void*);
138  long onCmdGetIntValue(FXObject*,FXSelector,void*);
139  long onCmdGetLongValue(FXObject*,FXSelector,void*);
140  long onCmdGetRealValue(FXObject*,FXSelector,void*);
141  long onCmdGetStringValue(FXObject*,FXSelector,void*);
142 
143  // Cursor movement
144  long onCmdCursorHome(FXObject*,FXSelector,void*);
145  long onCmdCursorEnd(FXObject*,FXSelector,void*);
146  long onCmdCursorRight(FXObject*,FXSelector,void*);
147  long onCmdCursorLeft(FXObject*,FXSelector,void*);
148  long onCmdCursorWordLeft(FXObject*,FXSelector,void*);
149  long onCmdCursorWordRight(FXObject*,FXSelector,void*);
150 
151  // Cursor drag movement
152  long onCmdCursorShiftHome(FXObject*,FXSelector,void*);
153  long onCmdCursorShiftEnd(FXObject*,FXSelector,void*);
154  long onCmdCursorShiftRight(FXObject*,FXSelector,void*);
155  long onCmdCursorShiftLeft(FXObject*,FXSelector,void*);
156  long onCmdCursorShiftWordLeft(FXObject*,FXSelector,void*);
157  long onCmdCursorShiftWordRight(FXObject*,FXSelector,void*);
158 
159  // Inserting
160  long onCmdInsertString(FXObject*,FXSelector,void*);
161  long onIMEStart(FXObject*,FXSelector,void*);
162 
163  // Manipulation Selection
164  long onCmdCutSel(FXObject*,FXSelector,void*);
165  long onCmdCopySel(FXObject*,FXSelector,void*);
166  long onCmdPasteSel(FXObject*,FXSelector,void*);
167  long onCmdDeleteSel(FXObject*,FXSelector,void*);
168  long onCmdPasteMiddle(FXObject*,FXSelector,void*);
169  long onCmdSelectAll(FXObject*,FXSelector,void*);
170  long onCmdDeselectAll(FXObject*,FXSelector,void*);
171 
172  // Deletion
173  long onCmdBackspace(FXObject*,FXSelector,void*);
174  long onCmdBackspaceWord(FXObject*,FXSelector,void*);
175  long onCmdBackspaceBol(FXObject*,FXSelector,void*);
176  long onCmdDeleteChar(FXObject*,FXSelector,void*);
177  long onCmdDeleteWord(FXObject*,FXSelector,void*);
178  long onCmdDeleteEol(FXObject*,FXSelector,void*);
179  long onCmdDeleteAll(FXObject*,FXSelector,void*);
180 
181  // Control commands
182  long onCmdToggleEditable(FXObject*,FXSelector,void*);
183  long onUpdToggleEditable(FXObject*,FXSelector,void*);
184  long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
185  long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
186 public:
187 
189  static const FXchar textDelimiters[];
190 
191 public:
192  enum{
193  ID_CURSOR_HOME=FXFrame::ID_LAST,
194  ID_CURSOR_END,
195  ID_CURSOR_RIGHT,
196  ID_CURSOR_LEFT,
197  ID_CURSOR_WORD_LEFT,
198  ID_CURSOR_WORD_RIGHT,
199  ID_CURSOR_SHIFT_HOME,
200  ID_CURSOR_SHIFT_END,
201  ID_CURSOR_SHIFT_LEFT,
202  ID_CURSOR_SHIFT_RIGHT,
203  ID_CURSOR_SHIFT_WORD_LEFT,
204  ID_CURSOR_SHIFT_WORD_RIGHT,
205  ID_SELECT_ALL,
206  ID_DESELECT_ALL,
207  ID_CUT_SEL,
208  ID_COPY_SEL,
209  ID_DELETE_SEL,
210  ID_PASTE_SEL,
211  ID_PASTE_MIDDLE,
212  ID_INSERT_STRING,
213  ID_BACKSPACE,
214  ID_BACKSPACE_WORD,
215  ID_BACKSPACE_BOL,
216  ID_DELETE_CHAR,
217  ID_DELETE_WORD,
218  ID_DELETE_EOL,
219  ID_DELETE_ALL,
220  ID_TOGGLE_EDITABLE,
221  ID_TOGGLE_OVERSTRIKE,
222  ID_BLINK,
223  ID_AUTOSCROLL,
224  ID_LAST
225  };
226 public:
227 
229  FXTextField(FXComposite* p,FXint ncols,FXObject* tgt=nullptr,FXSelector sel=0,FXuint opts=TEXTFIELD_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
230 
232  virtual void create();
233 
235  virtual void layout();
236 
238  virtual void enable();
239 
241  virtual void disable();
242 
244  virtual FXint getDefaultWidth();
245 
247  virtual FXint getDefaultHeight();
248 
250  virtual FXbool canFocus() const;
251 
253  virtual void setFocus();
254 
256  virtual void killFocus();
257 
259  void setEditable(FXbool edit=true);
260 
262  FXbool isEditable() const;
263 
265  void setOverstrike(FXbool over=true);
266 
268  FXbool isOverstrike() const;
269 
271  void setText(const FXString& text,FXbool notify=false);
272 
274  void replaceText(FXint pos,FXint m,const FXString& text,FXbool notify=false);
275 
277  void appendText(const FXString& text,FXbool notify=false);
278 
280  void insertText(FXint pos,const FXString& text,FXbool notify=false);
281 
283  void removeText(FXint pos,FXint m,FXbool notify=false);
284 
286  void clearText(FXbool notify=false);
287 
289  FXString getText() const { return contents; }
290 
292  FXbool selectAll();
293 
295  FXbool setSelection(FXint pos,FXint len);
296 
298  FXbool extendSelection(FXint pos);
299 
301  FXbool killSelection();
302 
304  FXString getSelectedText() const;
305 
307  FXbool copySelection();
308 
310  FXbool cutSelection(FXbool notify=false);
311 
313  FXbool deleteSelection(FXbool notify=false);
314 
316  FXbool pasteSelection(FXbool notify=false);
317 
319  FXbool pasteClipboard(FXbool notify=false);
320 
322  FXbool isPosSelected(FXint pos) const;
323 
325  FXbool isPosVisible(FXint pos) const;
326 
328  void makePositionVisible(FXint pos);
329 
331  void setCursorPos(FXint pos);
332 
334  FXint getCursorPos() const { return cursor; }
335 
337  void moveCursor(FXint pos);
338 
340  void moveCursorAndSelect(FXint pos);
341 
343  void setAnchorPos(FXint pos);
344 
346  FXint getAnchorPos() const { return anchor; }
347 
349  void setTextStyle(FXuint style);
350 
352  FXuint getTextStyle() const;
353 
355  void setFont(FXFont* fnt);
356 
358  FXFont* getFont() const { return font; }
359 
361  void setNumColumns(FXint cols);
362 
364  FXint getNumColumns() const { return columns; }
365 
367  void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; }
368 
370  const FXchar* getDelimiters() const { return delimiters; }
371 
379  void setJustify(FXuint mode);
380 
382  FXuint getJustify() const;
383 
385  void setTextColor(FXColor clr);
386 
388  FXColor getTextColor() const { return textColor; }
389 
391  void setSelBackColor(FXColor clr);
392 
394  FXColor getSelBackColor() const { return selbackColor; }
395 
397  void setSelTextColor(FXColor clr);
398 
400  FXColor getSelTextColor() const { return seltextColor; }
401 
403  void setCursorColor(FXColor clr);
404 
406  FXColor getCursorColor() const { return cursorColor; }
407 
409  void setHelpText(const FXString& text){ help=text; }
410 
412  const FXString& getHelpText() const { return help; }
413 
415  void setTipText(const FXString& text){ tip=text; }
416 
418  const FXString& getTipText() const { return tip; }
419 
421  virtual void save(FXStream& store) const;
422 
424  virtual void load(FXStream& store);
425 
427  virtual ~FXTextField();
428  };
429 
430 }
431 
432 #endif
const FXString & getTipText() const
Get the tool tip message for this text field.
Definition: FXTextField.h:418
FXColor getTextColor() const
Return text color.
Definition: FXTextField.h:388
FXint getAnchorPos() const
Return anchor position.
Definition: FXTextField.h:346
FXColor getSelBackColor() const
Return selected background color.
Definition: FXTextField.h:394
The Frame widget provides borders around some contents.
Definition: FXFrame.h:58
const FXString & getHelpText() const
Get the status line help text for this label.
Definition: FXTextField.h:412
void setDelimiters(const FXchar *delims=textDelimiters)
Change word delimiters.
Definition: FXTextField.h:367
Base composite.
Definition: FXComposite.h:32
FXint getCursorPos() const
Return cursor position.
Definition: FXTextField.h:334
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
FXFont * getFont() const
Get the text font.
Definition: FXTextField.h:358
FXColor getSelTextColor() const
Return selected text color.
Definition: FXTextField.h:400
const FXchar * getDelimiters() const
Return word delimiters.
Definition: FXTextField.h:370
FXString getText() const
Get entire text.
Definition: FXTextField.h:289
Definition: FX4Splitter.h:28
FXint getNumColumns() const
Return number of visible columns.
Definition: FXTextField.h:364
void setTipText(const FXString &text)
Set the tool tip message for this text field.
Definition: FXTextField.h:415
void setHelpText(const FXString &text)
Set the status line help text for this label.
Definition: FXTextField.h:409
A text field is a single-line text entry widget.
Definition: FXTextField.h:63
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
Window Device Context.
Definition: FXDCWindow.h:48
Font class.
Definition: FXFont.h:137
FXColor getCursorColor() const
Return the cursor color.
Definition: FXTextField.h:406
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp