FLTK 1.3.0
Fl_Input_.H
1 //
2 // "$Id: Fl_Input_.H 8068 2010-12-20 07:48:59Z greg.ercolano $"
3 //
4 // Input base class header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (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 GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27 
28 /* \file
29  Fl_Input_ widget . */
30 
31 #ifndef Fl_Input__H
32 #define Fl_Input__H
33 
34 #ifndef Fl_Widget_H
35 #include "Fl_Widget.H"
36 #endif
37 
38 #define FL_NORMAL_INPUT 0
39 #define FL_FLOAT_INPUT 1
40 #define FL_INT_INPUT 2
41 #define FL_HIDDEN_INPUT 3
42 #define FL_MULTILINE_INPUT 4
43 #define FL_SECRET_INPUT 5
44 #define FL_INPUT_TYPE 7
45 #define FL_INPUT_READONLY 8
46 #define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY)
47 #define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY)
48 #define FL_INPUT_WRAP 16
49 #define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP)
50 #define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
51 
102 class FL_EXPORT Fl_Input_ : public Fl_Widget {
103 
105  const char* value_;
106 
108  char* buffer;
109 
111  int size_;
112 
114  int bufsize;
115 
117  int position_;
118 
121  int mark_;
122 
126  int tab_nav_;
127 
129  int xscroll_, yscroll_;
130 
133  int mu_p;
134 
136  int maximum_size_;
137 
139  int shortcut_;
140 
142  uchar erase_cursor_only;
143 
145  Fl_Font textfont_;
146 
148  Fl_Fontsize textsize_;
149 
151  Fl_Color textcolor_;
152 
154  Fl_Color cursor_color_;
155 
157  static double up_down_pos;
158 
160  static int was_up_down;
161 
162  /* Convert a given text segment into the text that will be rendered on screen. */
163  const char* expand(const char*, char*) const;
164 
165  /* Calculates the width in pixels of part of a text buffer. */
166  double expandpos(const char*, const char*, const char*, int*) const;
167 
168  /* Mark a range of characters for update. */
169  void minimal_update(int, int);
170 
171  /* Mark a range of characters for update. */
172  void minimal_update(int p);
173 
174  /* Copy the value from a possibly static entry into the internal buffer. */
175  void put_in_buffer(int newsize);
176 
177  /* Set the current font and font size. */
178  void setfont() const;
179 
180 protected:
181 
182  /* Find the start of a word. */
183  int word_start(int i) const;
184 
185  /* Find the end of a word. */
186  int word_end(int i) const;
187 
188  /* Find the start of a line. */
189  int line_start(int i) const;
190 
191  /* Find the end of a line. */
192  int line_end(int i) const;
193 
194  /* Draw the text in the passed bounding box. */
195  void drawtext(int, int, int, int);
196 
197  /* Move the cursor to the column given by up_down_pos. */
198  int up_down_position(int, int keepmark=0);
199 
200  /* Handle mouse clicks and mouse moves. */
201  void handle_mouse(int, int, int, int, int keepmark=0);
202 
203  /* Handle all kinds of text field related events. */
204  int handletext(int e, int, int, int, int);
205 
206  /* Check the when() field and do a callback if indicated. */
207  void maybe_do_callback();
208 
210  int xscroll() const {return xscroll_;}
211 
213  int yscroll() const {return yscroll_;}
214  void yscroll(int y) { yscroll_ = y; damage(FL_DAMAGE_EXPOSE);}
215 
216  /* Return the number of lines displayed on a single page. */
217  int linesPerPage();
218 
219 public:
220 
221  /* Change the size of the widget. */
222  void resize(int, int, int, int);
223 
224  /* Constructor */
225  Fl_Input_(int, int, int, int, const char* = 0);
226 
227  /* Destructor */
228  ~Fl_Input_();
229 
230  /* Changes the widget text. */
231  int value(const char*);
232 
233  /* Changes the widget text. */
234  int value(const char*, int);
235 
236  /* Changes the widget text. */
237  int static_value(const char*);
238 
239  /* Changes the widget text. */
240  int static_value(const char*, int);
241 
252  const char* value() const {return value_;}
253 
254  /* Returns the character at index \p i. */
255  Fl_Char index(int i) const;
256 
265  int size() const {return size_;}
266 
270  void size(int W, int H) { Fl_Widget::size(W, H); }
271 
274  int maximum_size() const {return maximum_size_;}
275 
278  void maximum_size(int m) {maximum_size_ = m;}
279 
284  int position() const {return position_;}
285 
288  int mark() const {return mark_;}
289 
290  /* Sets the index for the cursor and mark. */
291  int position(int p, int m);
292 
299  int position(int p) {return position(p, p);}
300 
306  int mark(int m) {return position(position(), m);}
307 
308  /* Deletes text from b to e and inserts the new string text. */
309  int replace(int, int, const char*, int=0);
310 
321  int cut() {return replace(position(), mark(), 0);}
322 
335  int cut(int n) {return replace(position(), position()+n, 0);}
336 
348  int cut(int a, int b) {return replace(a, b, 0);}
349 
361  int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
362 
363  /* Put the current selection into the clipboard. */
364  int copy(int clipboard);
365 
366  /* Undo previous changes to the text buffer. */
367  int undo();
368 
369  /* Copy the yank buffer to the clipboard. */
370  int copy_cuts();
371 
375  int shortcut() const {return shortcut_;}
376 
383  void shortcut(int s) {shortcut_ = s;}
384 
387  Fl_Font textfont() const {return textfont_;}
388 
392  void textfont(Fl_Font s) {textfont_ = s;}
393 
396  Fl_Fontsize textsize() const {return textsize_;}
397 
401  void textsize(Fl_Fontsize s) {textsize_ = s;}
402 
406  Fl_Color textcolor() const {return textcolor_;}
407 
412  void textcolor(Fl_Color n) {textcolor_ = n;}
413 
416  Fl_Color cursor_color() const {return cursor_color_;}
417 
421  void cursor_color(Fl_Color n) {cursor_color_ = n;}
422 
425  int input_type() const {return type() & FL_INPUT_TYPE; }
426 
430  void input_type(int t) { type((uchar)(t | readonly())); }
431 
434  int readonly() const { return type() & FL_INPUT_READONLY; }
435 
438  void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
439  else type((uchar)(type() & ~FL_INPUT_READONLY)); }
440 
445  int wrap() const { return type() & FL_INPUT_WRAP; }
446 
451  void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
452  else type((uchar)(type() & ~FL_INPUT_WRAP)); }
453 
475  void tab_nav(int val) {
476  tab_nav_ = val;
477  }
478 
488  int tab_nav() const {
489  return tab_nav_;
490  }
491 };
492 
493 #endif
494 
495 //
496 // End of "$Id: Fl_Input_.H 8068 2010-12-20 07:48:59Z greg.ercolano $".
497 //