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,2017 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 onCmdReplaceSel(FXObject*,FXSelector,void*);
169  long onCmdPasteMiddle(FXObject*,FXSelector,void*);
170  long onCmdSelectAll(FXObject*,FXSelector,void*);
171  long onCmdDeselectAll(FXObject*,FXSelector,void*);
172 
173  // Deletion
174  long onCmdBackspace(FXObject*,FXSelector,void*);
175  long onCmdBackspaceWord(FXObject*,FXSelector,void*);
176  long onCmdBackspaceBol(FXObject*,FXSelector,void*);
177  long onCmdDeleteChar(FXObject*,FXSelector,void*);
178  long onCmdDeleteWord(FXObject*,FXSelector,void*);
179  long onCmdDeleteEol(FXObject*,FXSelector,void*);
180  long onCmdDeleteAll(FXObject*,FXSelector,void*);
181 
182  // Control commands
183  long onCmdToggleEditable(FXObject*,FXSelector,void*);
184  long onUpdToggleEditable(FXObject*,FXSelector,void*);
185  long onCmdToggleOverstrike(FXObject*,FXSelector,void*);
186  long onUpdToggleOverstrike(FXObject*,FXSelector,void*);
187 public:
188 
190  static const FXchar textDelimiters[];
191 
192 public:
193 
194  enum{
195  ID_CURSOR_HOME=FXFrame::ID_LAST,
196  ID_CURSOR_END,
197  ID_CURSOR_RIGHT,
198  ID_CURSOR_LEFT,
199  ID_CURSOR_WORD_LEFT,
200  ID_CURSOR_WORD_RIGHT,
201  ID_CURSOR_SHIFT_HOME,
202  ID_CURSOR_SHIFT_END,
203  ID_CURSOR_SHIFT_LEFT,
204  ID_CURSOR_SHIFT_RIGHT,
205  ID_CURSOR_SHIFT_WORD_LEFT,
206  ID_CURSOR_SHIFT_WORD_RIGHT,
207  ID_SELECT_ALL,
208  ID_DESELECT_ALL,
209  ID_CUT_SEL,
210  ID_COPY_SEL,
211  ID_DELETE_SEL,
212  ID_REPLACE_SEL,
213  ID_PASTE_SEL,
214  ID_PASTE_MIDDLE,
215  ID_INSERT_STRING,
216  ID_BACKSPACE,
217  ID_BACKSPACE_WORD,
218  ID_BACKSPACE_BOL,
219  ID_DELETE_CHAR,
220  ID_DELETE_WORD,
221  ID_DELETE_EOL,
222  ID_DELETE_ALL,
223  ID_TOGGLE_EDITABLE,
224  ID_TOGGLE_OVERSTRIKE,
225  ID_BLINK,
226  ID_AUTOSCROLL,
227  ID_LAST
228  };
229 
230 public:
231 
233  FXTextField(FXComposite* p,FXint ncols,FXObject* tgt=NULL,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);
234 
236  virtual void create();
237 
239  virtual void layout();
240 
242  virtual void enable();
243 
245  virtual void disable();
246 
248  virtual FXint getDefaultWidth();
249 
251  virtual FXint getDefaultHeight();
252 
254  virtual FXbool canFocus() const;
255 
257  virtual void setFocus();
258 
260  virtual void killFocus();
261 
263  void setNumColumns(FXint cols);
264 
266  FXint getNumColumns() const { return columns; }
267 
269  FXString getText() const { return contents; }
270 
272  FXString getSelectedText() const;
273 
275  void setText(const FXString& text,FXbool notify=false);
276 
278  void replaceText(FXint pos,FXint m,const FXString& text,FXbool notify=false);
279 
281  void appendText(const FXString& text,FXbool notify=false);
282 
284  void insertText(FXint pos,const FXString& text,FXbool notify=false);
285 
287  void removeText(FXint pos,FXint m,FXbool notify=false);
288 
290  void clearText(FXbool notify=false);
291 
293  FXbool selectAll();
294 
296  FXbool setSelection(FXint pos,FXint len);
297 
299  FXbool extendSelection(FXint pos);
300 
302  FXbool copySelection();
303 
305  FXbool cutSelection(FXbool notify=false);
306 
308  FXbool deleteSelection(FXbool notify=false);
309 
311  FXbool replaceSelection(const FXString& text,FXbool notify=false);
312 
314  FXbool pasteSelection(FXbool notify=false);
315 
317  FXbool pasteClipboard(FXbool notify=false);
318 
320  FXbool killSelection();
321 
323  FXbool isPosSelected(FXint pos) const;
324 
326  FXbool isPosVisible(FXint pos) const;
327 
329  void makePositionVisible(FXint pos);
330 
332  void setCursorPos(FXint pos);
333 
335  FXint getCursorPos() const { return cursor; }
336 
338  void moveCursor(FXint pos);
339 
341  void moveCursorAndSelect(FXint pos);
342 
344  void setAnchorPos(FXint pos);
345 
347  FXint getAnchorPos() const { return anchor; }
348 
350  void setEditable(FXbool edit=true);
351 
353  FXbool isEditable() const;
354 
356  void setOverstrike(FXbool over=true);
357 
359  FXbool isOverstrike() const;
360 
368  void setJustify(FXuint mode);
369 
371  FXuint getJustify() const;
372 
374  void setDelimiters(const FXchar* delims=textDelimiters){ delimiters=delims; }
375 
377  const FXchar* getDelimiters() const { return delimiters; }
378 
380  void setTextStyle(FXuint style);
381 
383  FXuint getTextStyle() const;
384 
386  void setFont(FXFont* fnt);
387 
389  FXFont* getFont() const { return font; }
390 
392  void setTextColor(FXColor clr);
393 
395  FXColor getTextColor() const { return textColor; }
396 
398  void setSelBackColor(FXColor clr);
399 
401  FXColor getSelBackColor() const { return selbackColor; }
402 
404  void setSelTextColor(FXColor clr);
405 
407  FXColor getSelTextColor() const { return seltextColor; }
408 
410  void setCursorColor(FXColor clr);
411 
413  FXColor getCursorColor() const { return cursorColor; }
414 
416  void setHelpText(const FXString& text){ help=text; }
417 
419  const FXString& getHelpText() const { return help; }
420 
422  void setTipText(const FXString& text){ tip=text; }
423 
425  const FXString& getTipText() const { return tip; }
426 
428  virtual void save(FXStream& store) const;
429 
431  virtual void load(FXStream& store);
432 
434  virtual ~FXTextField();
435  };
436 
437 }
438 
439 #endif

Copyright © 1997-2016 Jeroen van der Zijp