FLTK 1.4.0
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 
93 class FL_EXPORT Fl_Input_ : public Fl_Widget {
94 
96  const char* value_;
97 
99  char* buffer;
100 
102  int size_;
103 
105  int bufsize;
106 
108  int position_;
109 
112  int mark_;
113 
117  int tab_nav_;
118 
120  int xscroll_, yscroll_;
121 
124  int mu_p;
125 
127  int maximum_size_;
128 
130  int shortcut_;
131 
133  uchar erase_cursor_only;
134 
136  Fl_Font textfont_;
137 
139  Fl_Fontsize textsize_;
140 
142  Fl_Color textcolor_;
143 
145  Fl_Color cursor_color_;
146 
148  static double up_down_pos;
149 
151  static int was_up_down;
152 
153  /* Convert a given text segment into the text that will be rendered on screen. */
154  const char* expand(const char*, char*) const;
155 
156  /* Calculates the width in pixels of part of a text buffer. */
157  double expandpos(const char*, const char*, const char*, int*) const;
158 
159  /* Mark a range of characters for update. */
160  void minimal_update(int, int);
161 
162  /* Mark a range of characters for update. */
163  void minimal_update(int p);
164 
165  /* Copy the value from a possibly static entry into the internal buffer. */
166  void put_in_buffer(int newsize);
167 
168  /* Set the current font and font size. */
169  void setfont() const;
170 
171 protected:
172 
173  /* Find the start of a word. */
174  int word_start(int i) const;
175 
176  /* Find the end of a word. */
177  int word_end(int i) const;
178 
179  /* Find the start of a line. */
180  int line_start(int i) const;
181 
182  /* Find the end of a line. */
183  int line_end(int i) const;
184 
185  /* Draw the text in the passed bounding box. */
186  void drawtext(int, int, int, int);
187 
188  /* Move the cursor to the column given by up_down_pos. */
189  int up_down_position(int, int keepmark=0);
190 
191  /* Handle mouse clicks and mouse moves. */
192  void handle_mouse(int, int, int, int, int keepmark=0);
193 
194  /* Handle all kinds of text field related events. */
195  int handletext(int e, int, int, int, int);
196 
197  /* Check the when() field and do a callback if indicated. */
198  void maybe_do_callback();
199 
201  int xscroll() const {return xscroll_;}
202 
204  int yscroll() const {return yscroll_;}
205  void yscroll(int yOffset) { yscroll_ = yOffset; damage(FL_DAMAGE_EXPOSE);}
206 
207  /* Return the number of lines displayed on a single page. */
208  int linesPerPage();
209 
210 public:
211 
212  /* Change the size of the widget. */
213  void resize(int, int, int, int);
214 
215  /* Constructor */
216  Fl_Input_(int, int, int, int, const char* = 0);
217 
218  /* Destructor */
219  ~Fl_Input_();
220 
221  /* Changes the widget text. */
222  int value(const char*);
223 
224  /* Changes the widget text. */
225  int value(const char*, int);
226 
227  /* Changes the widget text. */
228  int static_value(const char*);
229 
230  /* Changes the widget text. */
231  int static_value(const char*, int);
232 
243  const char* value() const {return value_;}
244 
245  /* Returns the Unicode character at index \p i. */
246  unsigned int index(int i) const;
247 
256  int size() const {return size_;}
257 
261  void size(int W, int H) { Fl_Widget::size(W, H); }
262 
265  int maximum_size() const {return maximum_size_;}
266 
276  void maximum_size(int m) {maximum_size_ = m;}
277 
282  int position() const {return position_;}
283 
286  int mark() const {return mark_;}
287 
288  /* Sets the index for the cursor and mark. */
289  int position(int p, int m);
290 
297  int position(int p) {return position(p, p);}
298 
304  int mark(int m) {return position(position(), m);}
305 
306  /* Deletes text from \p b to \p e and inserts the new string \p text. */
307  int replace(int b, int e, const char *text, int ilen=0);
308 
319  int cut() {return replace(position(), mark(), 0);}
320 
333  int cut(int n) {return replace(position(), position()+n, 0);}
334 
346  int cut(int a, int b) {return replace(a, b, 0);}
347 
359  int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
360 
361  /* Append text at the end. */
362  int append(const char* t, int l=0, char keep_selection=0);
363 
364  /* Put the current selection into the clipboard. */
365  int copy(int clipboard);
366 
367  /* Undo previous changes to the text buffer. */
368  int undo();
369 
370  /* Copy the yank buffer to the clipboard. */
371  int copy_cuts();
372 
376  int shortcut() const {return shortcut_;}
377 
384  void shortcut(int s) {shortcut_ = s;}
385 
388  Fl_Font textfont() const {return textfont_;}
389 
393  void textfont(Fl_Font s) {textfont_ = s;}
394 
397  Fl_Fontsize textsize() const {return textsize_;}
398 
402  void textsize(Fl_Fontsize s) {textsize_ = s;}
403 
407  Fl_Color textcolor() const {return textcolor_;}
408 
413  void textcolor(Fl_Color n) {textcolor_ = n;}
414 
417  Fl_Color cursor_color() const {return cursor_color_;}
418 
422  void cursor_color(Fl_Color n) {cursor_color_ = n;}
423 
426  int input_type() const {return type() & FL_INPUT_TYPE; }
427 
431  void input_type(int t) { type((uchar)(t | readonly())); }
432 
435  int readonly() const { return type() & FL_INPUT_READONLY; }
436 
439  void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
440  else type((uchar)(type() & ~FL_INPUT_READONLY)); }
441 
446  int wrap() const { return type() & FL_INPUT_WRAP; }
447 
452  void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
453  else type((uchar)(type() & ~FL_INPUT_WRAP)); }
454 
478  void tab_nav(int val) {
479  tab_nav_ = val;
480  }
481 
492  int tab_nav() const {
493  return tab_nav_;
494  }
495 };
496 
497 #endif
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition: Enumerations.H:1042
@ FL_DAMAGE_EXPOSE
The window was exposed.
Definition: Enumerations.H:1215
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
Fl_Widget, Fl_Label classes .
This class provides a low-overhead text input field.
Definition: Fl_Input_.H:93
int cut(int n)
Deletes the next n bytes rounded to characters before or after the cursor.
Definition: Fl_Input_.H:333
int position(int p)
Sets the cursor position and mark.
Definition: Fl_Input_.H:297
void textsize(Fl_Fontsize s)
Sets the size of the text in the input field.
Definition: Fl_Input_.H:402
int tab_nav() const
Gets whether the Tab key causes focus navigation in multiline input fields or not.
Definition: Fl_Input_.H:492
int mark() const
Gets the current selection mark.
Definition: Fl_Input_.H:286
void readonly(int b)
Sets the read-only state of the input field.
Definition: Fl_Input_.H:439
void shortcut(int s)
Sets the shortcut key associated with this widget.
Definition: Fl_Input_.H:384
int position() const
Gets the position of the text cursor.
Definition: Fl_Input_.H:282
int maximum_size() const
Gets the maximum length of the input field in characters.
Definition: Fl_Input_.H:265
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition: Fl_Input_.H:388
void wrap(int b)
Sets the word wrapping state of the input field.
Definition: Fl_Input_.H:452
void input_type(int t)
Sets the input field type.
Definition: Fl_Input_.H:431
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition: Fl_Input_.H:407
int wrap() const
Gets the word wrapping state of the input field.
Definition: Fl_Input_.H:446
void maximum_size(int m)
Sets the maximum length of the input field in characters.
Definition: Fl_Input_.H:276
const char * value() const
Returns the text displayed in the widget.
Definition: Fl_Input_.H:243
int cut(int a, int b)
Deletes all characters between index a and b.
Definition: Fl_Input_.H:346
int shortcut() const
Return the shortcut key associated with this widget.
Definition: Fl_Input_.H:376
int mark(int m)
Sets the current selection mark.
Definition: Fl_Input_.H:304
int input_type() const
Gets the input field type.
Definition: Fl_Input_.H:426
void cursor_color(Fl_Color n)
Sets the color of the cursor.
Definition: Fl_Input_.H:422
void textcolor(Fl_Color n)
Sets the color of the text in the input field.
Definition: Fl_Input_.H:413
int insert(const char *t, int l=0)
Inserts text at the cursor position.
Definition: Fl_Input_.H:359
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition: Fl_Input_.H:397
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:478
Fl_Color cursor_color() const
Gets the color of the cursor.
Definition: Fl_Input_.H:417
int size() const
Returns the number of bytes in value().
Definition: Fl_Input_.H:256
void size(int W, int H)
Sets the width and height of this widget.
Definition: Fl_Input_.H:261
int readonly() const
Gets the read-only state of the input field.
Definition: Fl_Input_.H:435
void textfont(Fl_Font s)
Sets the font of the text in the input field.
Definition: Fl_Input_.H:393
int cut()
Deletes the current selection.
Definition: Fl_Input_.H:319
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
void position(int X, int Y)
Repositions the window or widget.
Definition: Fl_Widget.H:338
virtual void resize(int x, int y, int w, int h)
Changes the size or position of the widget.
Definition: Fl_Widget.cxx:140
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition: Fl_Widget.H:958
uchar type() const
Gets the widget type.
Definition: Fl_Widget.H:280
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:347
unsigned char uchar
unsigned char
Definition: fl_types.h:28