FLTK 1.4.5: Fl_Input_.H Source File

FLTK 1.4.5

Loading...
Searching...
No Matches
Fl_Input_.H
1//
2// Input base class header file for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 1998-2015 by Bill Spitzak and others.
5//
6// This library is free software. Distribution and use rights are outlined in
7// the file "COPYING" which should have been included with this file. If this
8// file is missing or damaged, see the license at:
9//
10// https://www.fltk.org/COPYING.php
11//
12// Please see the following page on how to report bugs and issues:
13//
14// https://www.fltk.org/bugs.php
15//
16
17/* \file
18 Fl_Input_ widget . */
19
20#ifndef Fl_Input__H
21#define Fl_Input__H
22
23#ifndef Fl_Widget_H
24#include "Fl_Widget.H"
25#endif
26
27#define FL_NORMAL_INPUT 0
28#define FL_FLOAT_INPUT 1
29#define FL_INT_INPUT 2
30#define FL_HIDDEN_INPUT 3
31#define FL_MULTILINE_INPUT 4
32#define FL_SECRET_INPUT 5
33#define FL_INPUT_TYPE 7
34#define FL_INPUT_READONLY 8
35#define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY)
36#define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY)
37#define FL_INPUT_WRAP 16
38#define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP)
39#define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
40
41class Fl_Input_Undo_Action;
42class Fl_Input_Undo_Action_List;
43
96 class FL_EXPORT Fl_Input_ : public Fl_Widget {
97
99 const char* value_;
100
102 char* buffer;
103
105 int size_;
106
108 int bufsize;
109
111 int position_;
112
115 int mark_;
116
120 int tab_nav_;
121
123 int xscroll_, yscroll_;
124
127 int mu_p;
128
130 int maximum_size_;
131
133 int shortcut_;
134
136 uchar erase_cursor_only;
137
139 Fl_Font textfont_;
140
142 Fl_Fontsize textsize_;
143
145 Fl_Color textcolor_;
146
148 Fl_Color cursor_color_;
149
151 Fl_Input_Undo_Action* undo_;
152 Fl_Input_Undo_Action_List* undo_list_;
153 Fl_Input_Undo_Action_List* redo_list_;
154
156 static double up_down_pos;
157
159 static int was_up_down;
160
161 /* Convert a given text segment into the text that will be rendered on screen. */
162 const char* expand(const char*, char*) const;
163
164 /* Calculates the width in pixels of part of a text buffer. */
165 double expandpos(const char*, const char*, const char*, int*) const;
166
167 /* Mark a range of characters for update. */
168 void minimal_update(int, int);
169
170 /* Mark a range of characters for update. */
171 void minimal_update(int p);
172
173 /* Copy the value from a possibly static entry into the internal buffer. */
174 void put_in_buffer(int newsize);
175
176 /* Set the current font and font size. */
177 void setfont() const;
178
179protected:
180
181 /* Find the start of a word. */
182 int word_start(int i) const;
183
184 /* Find the end of a word. */
185 int word_end(int i) const;
186
187 /* Find the start of a line. */
188 int line_start(int i) const;
189
190 /* Find the end of a line. */
191 int line_end(int i) const;
192
193 /* Draw the text in the passed bounding box. */
194 void drawtext(int, int, int, int);
195
196 /* Draw the text in the passed bounding box. */
197 void drawtext(int, int, int, int, bool draw_active);
198
199 /* Move the cursor to the column given by up_down_pos. */
200 int up_down_position(int, int keepmark=0);
201
202 /* Handle mouse clicks and mouse moves. */
203 void handle_mouse(int, int, int, int, int keepmark=0);
204
205 /* Handle all kinds of text field related events. */
206 int handletext(int e, int, int, int, int);
207
208 /* Check the when() field and do a callback if indicated. */
209 void maybe_do_callback(Fl_Callback_Reason reason = FL_REASON_UNKNOWN);
210
212 int xscroll() const {return xscroll_;}
213
215 int yscroll() const {return yscroll_;}
216 void yscroll(int yOffset) { yscroll_ = yOffset; damage(FL_DAMAGE_EXPOSE);}
217
218 /* Return the number of lines displayed on a single page. */
219 int linesPerPage();
220
221 /* Apply the current undo/redo operation, called from undo() or redo() */
222 int apply_undo();
223
224public:
225
226 /* Change the size of the widget. */
227 void resize(int, int, int, int) FL_OVERRIDE;
228
229 /* Constructor */
230 Fl_Input_(int, int, int, int, const char* = 0);
231
232 /* Destructor */
233 ~Fl_Input_();
234
235 /* Changes the widget text. */
236 int value(const char*);
237
238 /* Changes the widget text. */
239 int value(const char*, int);
240
241 /* Changes the widget text. */
242 int value(int value);
243
244 /* Changes the widget text. */
245 int value(double value);
246
247 /* Changes the widget text. */
248 int static_value(const char*);
249
250 /* Changes the widget text. */
251 int static_value(const char*, int);
252
263 const char* value() const {return value_;}
264
265 int ivalue() const;
266
267 double dvalue() const;
268
269 /* Returns the Unicode character at index \p i. */
270 unsigned int index(int i) const;
271
280 int size() const {return size_;}
281
285 void size(int W, int H) { Fl_Widget::size(W, H); }
286
289 int maximum_size() const {return maximum_size_;}
290
300 void maximum_size(int m) {maximum_size_ = m;}
301
306 int insert_position() const { return position_; }
307 FL_DEPRECATED("since 1.4.0 - use insert_position() instead",
308 int position() const ) { return insert_position(); }
309
312 int mark() const {return mark_;}
313
314 /* Sets the index for the cursor and mark. */
315 int insert_position(int p, int m);
316 FL_DEPRECATED("since 1.4.0 - use insert_position(p, m) or Fl_Widget::position(x, y) instead",
317 int position(int p, int m)) { return insert_position(p, m); }
318
325 int insert_position(int p) { return insert_position(p, p); }
326 FL_DEPRECATED("since 1.4.0 - use insert_position(p) instead",
327 int position(int p)) { return insert_position(p); }
328
334 int mark(int m) {return insert_position(insert_position(), m);}
335
336 /* Deletes text from \p b to \p e and inserts the new string \p text. */
337 int replace(int b, int e, const char *text, int ilen=0);
338
349 int cut() {return replace(insert_position(), mark(), 0);}
350
363 int cut(int n) {return replace(insert_position(), insert_position()+n, 0);}
364
376 int cut(int a, int b) {return replace(a, b, 0);}
377
389 int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
390
391 /* Append text at the end. */
392 int append(const char* t, int l=0, char keep_selection=0);
393
394 /* Put the current selection into the clipboard. */
395 int copy(int clipboard);
396
397 /* Undo previous changes to the text buffer. */
398 int undo();
399
400 /* Return true if the last operation can be undone. */
401 bool can_undo() const;
402
403 /* Redo previous undo operations. */
404 int redo();
405
406 /* Return true if there is a redo action in the list. */
407 bool can_redo() const;
408
409 /* Copy the yank buffer to the clipboard. */
410 int copy_cuts();
411
415 int shortcut() const {return shortcut_;}
416
423 void shortcut(int s) {shortcut_ = s;}
424
427 Fl_Font textfont() const {return textfont_;}
428
432 void textfont(Fl_Font s) {textfont_ = s;}
433
436 Fl_Fontsize textsize() const {return textsize_;}
437
441 void textsize(Fl_Fontsize s) {textsize_ = s;}
442
446 Fl_Color textcolor() const {return textcolor_;}
447
452 void textcolor(Fl_Color n) {textcolor_ = n;}
453
456 Fl_Color cursor_color() const {return cursor_color_;}
457
461 void cursor_color(Fl_Color n) {cursor_color_ = n;}
462
465 int input_type() const {return type() & FL_INPUT_TYPE; }
466
470 void input_type(int t) { type((uchar)(t | readonly())); }
471
474 int readonly() const { return type() & FL_INPUT_READONLY; }
475
478 void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
479 else type((uchar)(type() & ~FL_INPUT_READONLY)); }
480
485 int wrap() const { return type() & FL_INPUT_WRAP; }
486
491 void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
492 else type((uchar)(type() & ~FL_INPUT_WRAP)); }
493
517 void tab_nav(int val) {
518 tab_nav_ = val;
519 }
520
531 int tab_nav() const {
532 return tab_nav_;
533 }
534};
535
536#endif
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1063
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
FL_DAMAGE_EXPOSE
@ FL_DAMAGE_EXPOSE
The window was exposed.
Definition Enumerations.H:1342
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1092
Fl_Callback_Reason
Fl_Callback_Reason
These constants describe why a callback is performed.
Definition Enumerations.H:455
FL_REASON_UNKNOWN
@ FL_REASON_UNKNOWN
unknown or unset reason
Definition Enumerations.H:456
Fl_Widget.H
Fl_Widget and Fl_Label classes.
Fl_Input_::word_start
int word_start(int i) const
Finds the start of a word.
Definition Fl_Input_.cxx:559
Fl_Input_::cut
int cut(int n)
Deletes the next n bytes rounded to characters before or after the cursor.
Definition Fl_Input_.H:363
Fl_Input_::Fl_Input_
Fl_Input_(int, int, int, int, const char *=0)
Creates a new Fl_Input_ widget.
Definition Fl_Input_.cxx:1295
Fl_Input_::position
int position(int p)
Definition Fl_Input_.H:327
Fl_Input_::static_value
int static_value(const char *)
Changes the widget text.
Definition Fl_Input_.cxx:1424
Fl_Input_::drawtext
void drawtext(int, int, int, int)
Draws the text in the passed bounding box.
Definition Fl_Input_.cxx:299
Fl_Input_::textsize
void textsize(Fl_Fontsize s)
Sets the size of the text in the input field.
Definition Fl_Input_.H:441
Fl_Input_::tab_nav
int tab_nav() const
Gets whether the Tab key causes focus navigation in multiline input fields or not.
Definition Fl_Input_.H:531
Fl_Input_::mark
int mark() const
Gets the current selection mark.
Definition Fl_Input_.H:312
Fl_Input_::insert_position
int insert_position() const
Gets the position of the text cursor.
Definition Fl_Input_.H:306
Fl_Input_::readonly
void readonly(int b)
Sets the read-only state of the input field.
Definition Fl_Input_.H:478
Fl_Input_::shortcut
void shortcut(int s)
Sets the shortcut key associated with this widget.
Definition Fl_Input_.H:423
Fl_Input_::position
int position() const
Definition Fl_Input_.H:308
Fl_Input_::maximum_size
int maximum_size() const
Gets the maximum length of the input field in characters.
Definition Fl_Input_.H:289
Fl_Input_::textfont
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition Fl_Input_.H:427
Fl_Input_::wrap
void wrap(int b)
Sets the word wrapping state of the input field.
Definition Fl_Input_.H:491
Fl_Input_::input_type
void input_type(int t)
Sets the input field type.
Definition Fl_Input_.H:470
Fl_Input_::textcolor
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition Fl_Input_.H:446
Fl_Input_::wrap
int wrap() const
Gets the word wrapping state of the input field.
Definition Fl_Input_.H:485
Fl_Input_::apply_undo
int apply_undo()
Apply the current undo/redo operation.
Definition Fl_Input_.cxx:1032
Fl_Input_::maximum_size
void maximum_size(int m)
Sets the maximum length of the input field in characters.
Definition Fl_Input_.H:300
Fl_Input_::insert_position
int insert_position(int p)
Sets the cursor position and mark.
Definition Fl_Input_.H:325
Fl_Input_::replace
int replace(int b, int e, const char *text, int ilen=0)
Deletes text from b to e and inserts the new string text.
Definition Fl_Input_.cxx:904
Fl_Input_::cut
int cut(int a, int b)
Deletes all characters between index a and b.
Definition Fl_Input_.H:376
Fl_Input_::shortcut
int shortcut() const
Return the shortcut key associated with this widget.
Definition Fl_Input_.H:415
Fl_Input_::handle_mouse
void handle_mouse(int, int, int, int, int keepmark=0)
Handles mouse clicks and mouse moves.
Definition Fl_Input_.cxx:640
Fl_Input_::mark
int mark(int m)
Sets the current selection mark.
Definition Fl_Input_.H:334
Fl_Input_::input_type
int input_type() const
Gets the input field type.
Definition Fl_Input_.H:465
Fl_Input_::word_end
int word_end(int i) const
Finds the end of a word.
Definition Fl_Input_.cxx:539
Fl_Input_::value
int value(const char *)
Changes the widget text.
Definition Fl_Input_.cxx:1460
Fl_Input_::cursor_color
void cursor_color(Fl_Color n)
Sets the color of the cursor.
Definition Fl_Input_.H:461
Fl_Input_::textcolor
void textcolor(Fl_Color n)
Sets the color of the text in the input field.
Definition Fl_Input_.H:452
Fl_Input_::insert
int insert(const char *t, int l=0)
Inserts text at the cursor position.
Definition Fl_Input_.H:389
Fl_Input_::textsize
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition Fl_Input_.H:436
Fl_Input_::tab_nav
void tab_nav(int val)
Sets whether the Tab key does focus navigation, or inserts tab characters into Fl_Multiline_Input.
Definition Fl_Input_.H:517
Fl_Input_::up_down_position
int up_down_position(int, int keepmark=0)
Moves the cursor to the column given by up_down_pos.
Definition Fl_Input_.cxx:789
Fl_Input_::cursor_color
Fl_Color cursor_color() const
Gets the color of the cursor.
Definition Fl_Input_.H:456
Fl_Input_::size
int size() const
Returns the number of bytes in value().
Definition Fl_Input_.H:280
Fl_Input_::size
void size(int W, int H)
Sets the width and height of this widget.
Definition Fl_Input_.H:285
Fl_Input_::line_end
int line_end(int i) const
Finds the end of a line.
Definition Fl_Input_.cxx:575
Fl_Input_::position
int position(int p, int m)
Definition Fl_Input_.H:317
Fl_Input_::readonly
int readonly() const
Gets the read-only state of the input field.
Definition Fl_Input_.H:474
Fl_Input_::handletext
int handletext(int e, int, int, int, int)
Handles all kinds of text field related events.
Definition Fl_Input_.cxx:1168
Fl_Input_::value
const char * value() const
Returns the text displayed in the widget.
Definition Fl_Input_.H:263
Fl_Input_::textfont
void textfont(Fl_Font s)
Sets the font of the text in the input field.
Definition Fl_Input_.H:432
Fl_Input_::cut
int cut()
Deletes the current selection.
Definition Fl_Input_.H:349
Fl_Input_::line_start
int line_start(int i) const
Finds the start of a line.
Definition Fl_Input_.cxx:606
Fl_Widget::resize
virtual void resize(int x, int y, int w, int h)
Changes the size or position of the widget.
Definition Fl_Widget.cxx:138
Fl_Widget::damage
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition Fl_Widget.H:1146
Fl_Widget::type
uchar type() const
Gets the widget type.
Definition Fl_Widget.H:351
Fl_Widget::size
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:418
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
FL_DEPRECATED
#define FL_DEPRECATED(msg, func)
Enclosing a function or method in FL_DEPRECATED marks it as no longer recommended.
Definition fl_attr.h:57
uchar
unsigned char uchar
unsigned char
Definition fl_types.h:30