FLTK 1.3.9
Loading...
Searching...
No Matches
Fl_Input_.H
1//
2// "$Id$"
3//
4// Input base class header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2015 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
94class 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
172protected:
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
211public:
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
277 void maximum_size(int m) {maximum_size_ = m;}
278
283 int position() const {return position_;}
284
287 int mark() const {return mark_;}
288
289 /* Sets the index for the cursor and mark. */
290 int position(int p, int m);
291
298 int position(int p) {return position(p, p);}
299
305 int mark(int m) {return position(position(), m);}
306
307 /* Deletes text from \p b to \p e and inserts the new string \p text. */
308 int replace(int b, int e, const char *text, int ilen=0);
309
320 int cut() {return replace(position(), mark(), 0);}
321
334 int cut(int n) {return replace(position(), position()+n, 0);}
335
347 int cut(int a, int b) {return replace(a, b, 0);}
348
360 int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
361
362 /* Put the current selection into the clipboard. */
363 int copy(int clipboard);
364
365 /* Undo previous changes to the text buffer. */
366 int undo();
367
368 /* Copy the yank buffer to the clipboard. */
369 int copy_cuts();
370
374 int shortcut() const {return shortcut_;}
375
382 void shortcut(int s) {shortcut_ = s;}
383
386 Fl_Font textfont() const {return textfont_;}
387
391 void textfont(Fl_Font s) {textfont_ = s;}
392
395 Fl_Fontsize textsize() const {return textsize_;}
396
400 void textsize(Fl_Fontsize s) {textsize_ = s;}
401
405 Fl_Color textcolor() const {return textcolor_;}
406
411 void textcolor(Fl_Color n) {textcolor_ = n;}
412
415 Fl_Color cursor_color() const {return cursor_color_;}
416
420 void cursor_color(Fl_Color n) {cursor_color_ = n;}
421
424 int input_type() const {return type() & FL_INPUT_TYPE; }
425
429 void input_type(int t) { type((uchar)(t | readonly())); }
430
433 int readonly() const { return type() & FL_INPUT_READONLY; }
434
437 void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
438 else type((uchar)(type() & ~FL_INPUT_READONLY)); }
439
444 int wrap() const { return type() & FL_INPUT_WRAP; }
445
450 void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
451 else type((uchar)(type() & ~FL_INPUT_WRAP)); }
452
476 void tab_nav(int val) {
477 tab_nav_ = val;
478 }
479
490 int tab_nav() const {
491 return tab_nav_;
492 }
493};
494
495#endif
496
497//
498// End of "$Id$".
499//
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:875
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:932
@ FL_DAMAGE_EXPOSE
The window was exposed.
Definition Enumerations.H:1105
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:904
Fl_Widget, Fl_Label classes .
This class provides a low-overhead text input field.
Definition Fl_Input_.H:94
int cut(int n)
Deletes the next n bytes rounded to characters before or after the cursor.
Definition Fl_Input_.H:334
int position(int p)
Sets the cursor position and mark.
Definition Fl_Input_.H:298
void textsize(Fl_Fontsize s)
Sets the size of the text in the input field.
Definition Fl_Input_.H:400
int tab_nav() const
Gets whether the Tab key causes focus navigation in multiline input fields or not.
Definition Fl_Input_.H:490
int mark() const
Gets the current selection mark.
Definition Fl_Input_.H:287
void readonly(int b)
Sets the read-only state of the input field.
Definition Fl_Input_.H:437
void shortcut(int s)
Sets the shortcut key associated with this widget.
Definition Fl_Input_.H:382
int position() const
Gets the position of the text cursor.
Definition Fl_Input_.H:283
int maximum_size() const
Gets the maximum length of the input field in characters.
Definition Fl_Input_.H:266
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition Fl_Input_.H:386
void wrap(int b)
Sets the word wrapping state of the input field.
Definition Fl_Input_.H:450
void input_type(int t)
Sets the input field type.
Definition Fl_Input_.H:429
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition Fl_Input_.H:405
int wrap() const
Gets the word wrapping state of the input field.
Definition Fl_Input_.H:444
void maximum_size(int m)
Sets the maximum length of the input field in characters.
Definition Fl_Input_.H:277
int cut(int a, int b)
Deletes all characters between index a and b.
Definition Fl_Input_.H:347
int shortcut() const
Return the shortcut key associated with this widget.
Definition Fl_Input_.H:374
int mark(int m)
Sets the current selection mark.
Definition Fl_Input_.H:305
int input_type() const
Gets the input field type.
Definition Fl_Input_.H:424
void cursor_color(Fl_Color n)
Sets the color of the cursor.
Definition Fl_Input_.H:420
void textcolor(Fl_Color n)
Sets the color of the text in the input field.
Definition Fl_Input_.H:411
int insert(const char *t, int l=0)
Inserts text at the cursor position.
Definition Fl_Input_.H:360
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition Fl_Input_.H:395
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:476
Fl_Color cursor_color() const
Gets the color of the cursor.
Definition Fl_Input_.H:415
int size() const
Returns the number of bytes in value().
Definition Fl_Input_.H:257
void size(int W, int H)
Sets the width and height of this widget.
Definition Fl_Input_.H:262
int readonly() const
Gets the read-only state of the input field.
Definition Fl_Input_.H:433
const char * value() const
Returns the text displayed in the widget.
Definition Fl_Input_.H:244
void textfont(Fl_Font s)
Sets the font of the text in the input field.
Definition Fl_Input_.H:391
int cut()
Deletes the current selection.
Definition Fl_Input_.H:320
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:101
void position(int X, int Y)
Repositions the window or widget.
Definition Fl_Widget.H:332
virtual void resize(int x, int y, int w, int h)
Changes the size or position of the widget.
Definition Fl_Widget.cxx:150
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition Fl_Widget.H:917
uchar type() const
Gets the widget type.
Definition Fl_Widget.H:274
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:341
unsigned int Fl_Char
24-bit Unicode character - upper 8 bits are unused
Definition fl_types.h:49
unsigned char uchar
unsigned char
Definition fl_types.h:30