FLTK 1.3.3
Fl_Input_.H
1 //
2 // "$Id: Fl_Input_.H 10134 2014-04-29 02:56:34Z greg.ercolano $"
3 //
4 // Input base class header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2011 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 /* \file
20  Fl_Input_ widget . */
21 
22 #ifndef Fl_Input__H
23 #define Fl_Input__H
24 
25 #ifndef Fl_Widget_H
26 #include "Fl_Widget.H"
27 #endif
28 
29 #define FL_NORMAL_INPUT 0
30 #define FL_FLOAT_INPUT 1
31 #define FL_INT_INPUT 2
32 #define FL_HIDDEN_INPUT 3
33 #define FL_MULTILINE_INPUT 4
34 #define FL_SECRET_INPUT 5
35 #define FL_INPUT_TYPE 7
36 #define FL_INPUT_READONLY 8
37 #define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY)
38 #define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY)
39 #define FL_INPUT_WRAP 16
40 #define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP)
41 #define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
42 
94 class FL_EXPORT Fl_Input_ : public Fl_Widget {
95 
97  const char* value_;
98 
100  char* buffer;
101 
103  int size_;
104 
106  int bufsize;
107 
109  int position_;
110 
113  int mark_;
114 
118  int tab_nav_;
119 
121  int xscroll_, yscroll_;
122 
125  int mu_p;
126 
128  int maximum_size_;
129 
131  int shortcut_;
132 
134  uchar erase_cursor_only;
135 
137  Fl_Font textfont_;
138 
140  Fl_Fontsize textsize_;
141 
143  Fl_Color textcolor_;
144 
146  Fl_Color cursor_color_;
147 
149  static double up_down_pos;
150 
152  static int was_up_down;
153 
154  /* Convert a given text segment into the text that will be rendered on screen. */
155  const char* expand(const char*, char*) const;
156 
157  /* Calculates the width in pixels of part of a text buffer. */
158  double expandpos(const char*, const char*, const char*, int*) const;
159 
160  /* Mark a range of characters for update. */
161  void minimal_update(int, int);
162 
163  /* Mark a range of characters for update. */
164  void minimal_update(int p);
165 
166  /* Copy the value from a possibly static entry into the internal buffer. */
167  void put_in_buffer(int newsize);
168 
169  /* Set the current font and font size. */
170  void setfont() const;
171 
172 protected:
173 
174  /* Find the start of a word. */
175  int word_start(int i) const;
176 
177  /* Find the end of a word. */
178  int word_end(int i) const;
179 
180  /* Find the start of a line. */
181  int line_start(int i) const;
182 
183  /* Find the end of a line. */
184  int line_end(int i) const;
185 
186  /* Draw the text in the passed bounding box. */
187  void drawtext(int, int, int, int);
188 
189  /* Move the cursor to the column given by up_down_pos. */
190  int up_down_position(int, int keepmark=0);
191 
192  /* Handle mouse clicks and mouse moves. */
193  void handle_mouse(int, int, int, int, int keepmark=0);
194 
195  /* Handle all kinds of text field related events. */
196  int handletext(int e, int, int, int, int);
197 
198  /* Check the when() field and do a callback if indicated. */
199  void maybe_do_callback();
200 
202  int xscroll() const {return xscroll_;}
203 
205  int yscroll() const {return yscroll_;}
206  void yscroll(int yOffset) { yscroll_ = yOffset; damage(FL_DAMAGE_EXPOSE);}
207 
208  /* Return the number of lines displayed on a single page. */
209  int linesPerPage();
210 
211 public:
212 
213  /* Change the size of the widget. */
214  void resize(int, int, int, int);
215 
216  /* Constructor */
217  Fl_Input_(int, int, int, int, const char* = 0);
218 
219  /* Destructor */
220  ~Fl_Input_();
221 
222  /* Changes the widget text. */
223  int value(const char*);
224 
225  /* Changes the widget text. */
226  int value(const char*, int);
227 
228  /* Changes the widget text. */
229  int static_value(const char*);
230 
231  /* Changes the widget text. */
232  int static_value(const char*, int);
233 
244  const char* value() const {return value_;}
245 
246  /* Returns the character at index \p i. */
247  Fl_Char index(int i) const;
248 
257  int size() const {return size_;}
258 
262  void size(int W, int H) { Fl_Widget::size(W, H); }
263 
266  int maximum_size() const {return maximum_size_;}
267 
275  void maximum_size(int m) {maximum_size_ = m;}
276 
281  int position() const {return position_;}
282 
285  int mark() const {return mark_;}
286 
287  /* Sets the index for the cursor and mark. */
288  int position(int p, int m);
289 
296  int position(int p) {return position(p, p);}
297 
303  int mark(int m) {return position(position(), m);}
304 
305  /* Deletes text from \p b to \p e and inserts the new string \p text. */
306  int replace(int b, int e, const char *text, int ilen=0);
307 
318  int cut() {return replace(position(), mark(), 0);}
319 
332  int cut(int n) {return replace(position(), position()+n, 0);}
333 
345  int cut(int a, int b) {return replace(a, b, 0);}
346 
358  int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
359 
360  /* Put the current selection into the clipboard. */
361  int copy(int clipboard);
362 
363  /* Undo previous changes to the text buffer. */
364  int undo();
365 
366  /* Copy the yank buffer to the clipboard. */
367  int copy_cuts();
368 
372  int shortcut() const {return shortcut_;}
373 
380  void shortcut(int s) {shortcut_ = s;}
381 
384  Fl_Font textfont() const {return textfont_;}
385 
389  void textfont(Fl_Font s) {textfont_ = s;}
390 
393  Fl_Fontsize textsize() const {return textsize_;}
394 
398  void textsize(Fl_Fontsize s) {textsize_ = s;}
399 
403  Fl_Color textcolor() const {return textcolor_;}
404 
409  void textcolor(Fl_Color n) {textcolor_ = n;}
410 
413  Fl_Color cursor_color() const {return cursor_color_;}
414 
418  void cursor_color(Fl_Color n) {cursor_color_ = n;}
419 
422  int input_type() const {return type() & FL_INPUT_TYPE; }
423 
427  void input_type(int t) { type((uchar)(t | readonly())); }
428 
431  int readonly() const { return type() & FL_INPUT_READONLY; }
432 
435  void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
436  else type((uchar)(type() & ~FL_INPUT_READONLY)); }
437 
442  int wrap() const { return type() & FL_INPUT_WRAP; }
443 
448  void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
449  else type((uchar)(type() & ~FL_INPUT_WRAP)); }
450 
474  void tab_nav(int val) {
475  tab_nav_ = val;
476  }
477 
488  int tab_nav() const {
489  return tab_nav_;
490  }
491 };
492 
493 #endif
494 
495 //
496 // End of "$Id: Fl_Input_.H 10134 2014-04-29 02:56:34Z greg.ercolano $".
497 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
int maximum_size() const
Gets the maximum length of the input field in characters.
Definition: Fl_Input_.H:266
void readonly(int b)
Sets the read-only state of the input field.
Definition: Fl_Input_.H:435
void input_type(int t)
Sets the input field type.
Definition: Fl_Input_.H:427
int position() const
Gets the position of the text cursor.
Definition: Fl_Input_.H:281
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:330
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition: Fl_Input_.H:403
void textsize(Fl_Fontsize s)
Sets the size of the text in the input field.
Definition: Fl_Input_.H:398
void textcolor(Fl_Color n)
Sets the color of the text in the input field.
Definition: Fl_Input_.H:409
int tab_nav() const
Gets whether the Tab key causes focus navigation in multiline input fields or not.
Definition: Fl_Input_.H:488
int cut(int a, int b)
Deletes all characters between index a and b.
Definition: Fl_Input_.H:345
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition: Fl_Widget.H:896
virtual void resize(int x, int y, int w, int h)
Changes the size or position of the widget.
Definition: Fl_Widget.cxx:131
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:474
Fl_Color cursor_color() const
Gets the color of the cursor.
Definition: Fl_Input_.H:413
int mark(int m)
Sets the current selection mark.
Definition: Fl_Input_.H:303
const char * value() const
Returns the text displayed in the widget.
Definition: Fl_Input_.H:244
int size() const
Returns the number of bytes in value().
Definition: Fl_Input_.H:257
int wrap() const
Gets the word wrapping state of the input field.
Definition: Fl_Input_.H:442
Fl_Widget, Fl_Label classes .
int mark() const
Gets the current selection mark.
Definition: Fl_Input_.H:285
unsigned int Fl_Char
24-bit Unicode character - upper 8-bits are unused
Definition: fl_types.h:49
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:768
int shortcut() const
Return the shortcut key associated with this widget.
Definition: Fl_Input_.H:372
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:796
This class provides a low-overhead text input field.
Definition: Fl_Input_.H:94
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:739
int input_type() const
Gets the input field type.
Definition: Fl_Input_.H:422
int cut()
Deletes the current selection.
Definition: Fl_Input_.H:318
The window was exposed.
Definition: Enumerations.H:968
int cut(int n)
Deletes the next n bytes rounded to characters before or after the cursor.
Definition: Fl_Input_.H:332
int insert(const char *t, int l=0)
Inserts text at the cursor position.
Definition: Fl_Input_.H:358
int readonly() const
Gets the read-only state of the input field.
Definition: Fl_Input_.H:431
int position(int p)
Sets the cursor position and mark.
Definition: Fl_Input_.H:296
void textfont(Fl_Font s)
Sets the font of the text in the input field.
Definition: Fl_Input_.H:389
void size(int W, int H)
Sets the width and height of this widget.
Definition: Fl_Input_.H:262
void position(int X, int Y)
Repositions the window or widget.
Definition: Fl_Widget.H:321
void cursor_color(Fl_Color n)
Sets the color of the cursor.
Definition: Fl_Input_.H:418
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition: Fl_Input_.H:393
void maximum_size(int m)
Sets the maximum length of the input field in characters.
Definition: Fl_Input_.H:275
void shortcut(int s)
Sets the shortcut key associated with this widget.
Definition: Fl_Input_.H:380
unsigned char uchar
unsigned char
Definition: fl_types.h:30
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition: Fl_Input_.H:384
void wrap(int b)
Sets the word wrapping state of the input field.
Definition: Fl_Input_.H:448
uchar type() const
Gets the widget type.
Definition: Fl_Widget.H:263