FLTK 1.3.0
|
00001 // 00002 // "$Id$" 00003 // 00004 // Input base class header file for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 /* \file 00029 Fl_Input_ widget . */ 00030 00031 #ifndef Fl_Input__H 00032 #define Fl_Input__H 00033 00034 #ifndef Fl_Widget_H 00035 #include "Fl_Widget.H" 00036 #endif 00037 00038 #define FL_NORMAL_INPUT 0 00039 #define FL_FLOAT_INPUT 1 00040 #define FL_INT_INPUT 2 00041 #define FL_HIDDEN_INPUT 3 00042 #define FL_MULTILINE_INPUT 4 00043 #define FL_SECRET_INPUT 5 00044 #define FL_INPUT_TYPE 7 00045 #define FL_INPUT_READONLY 8 00046 #define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY) 00047 #define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY) 00048 #define FL_INPUT_WRAP 16 00049 #define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP) 00050 #define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP) 00051 00102 class FL_EXPORT Fl_Input_ : public Fl_Widget { 00103 00105 const char* value_; 00106 00108 char* buffer; 00109 00111 int size_; 00112 00114 int bufsize; 00115 00117 int position_; 00118 00121 int mark_; 00122 00126 int tab_nav_; 00127 00129 int xscroll_, yscroll_; 00130 00133 int mu_p; 00134 00136 int maximum_size_; 00137 00139 int shortcut_; 00140 00142 uchar erase_cursor_only; 00143 00145 Fl_Font textfont_; 00146 00148 Fl_Fontsize textsize_; 00149 00151 Fl_Color textcolor_; 00152 00154 Fl_Color cursor_color_; 00155 00157 static double up_down_pos; 00158 00160 static int was_up_down; 00161 00162 /* Convert a given text segment into the text that will be rendered on screen. */ 00163 const char* expand(const char*, char*) const; 00164 00165 /* Calculates the width in pixels of part of a text buffer. */ 00166 double expandpos(const char*, const char*, const char*, int*) const; 00167 00168 /* Mark a range of characters for update. */ 00169 void minimal_update(int, int); 00170 00171 /* Mark a range of characters for update. */ 00172 void minimal_update(int p); 00173 00174 /* Copy the value from a possibly static entry into the internal buffer. */ 00175 void put_in_buffer(int newsize); 00176 00177 /* Set the current font and font size. */ 00178 void setfont() const; 00179 00180 protected: 00181 00182 /* Find the start of a word. */ 00183 int word_start(int i) const; 00184 00185 /* Find the end of a word. */ 00186 int word_end(int i) const; 00187 00188 /* Find the start of a line. */ 00189 int line_start(int i) const; 00190 00191 /* Find the end of a line. */ 00192 int line_end(int i) const; 00193 00194 /* Draw the text in the passed bounding box. */ 00195 void drawtext(int, int, int, int); 00196 00197 /* Move the cursor to the column given by up_down_pos. */ 00198 int up_down_position(int, int keepmark=0); 00199 00200 /* Handle mouse clicks and mouse moves. */ 00201 void handle_mouse(int, int, int, int, int keepmark=0); 00202 00203 /* Handle all kinds of text field related events. */ 00204 int handletext(int e, int, int, int, int); 00205 00206 /* Check the when() field and do a callback if indicated. */ 00207 void maybe_do_callback(); 00208 00210 int xscroll() const {return xscroll_;} 00211 00213 int yscroll() const {return yscroll_;} 00214 void yscroll(int y) { yscroll_ = y; damage(FL_DAMAGE_EXPOSE);} 00215 00216 /* Return the number of lines displayed on a single page. */ 00217 int linesPerPage(); 00218 00219 public: 00220 00221 /* Change the size of the widget. */ 00222 void resize(int, int, int, int); 00223 00224 /* Constructor */ 00225 Fl_Input_(int, int, int, int, const char* = 0); 00226 00227 /* Destructor */ 00228 ~Fl_Input_(); 00229 00230 /* Changes the widget text. */ 00231 int value(const char*); 00232 00233 /* Changes the widget text. */ 00234 int value(const char*, int); 00235 00236 /* Changes the widget text. */ 00237 int static_value(const char*); 00238 00239 /* Changes the widget text. */ 00240 int static_value(const char*, int); 00241 00252 const char* value() const {return value_;} 00253 00254 /* Returns the character at index \p i. */ 00255 Fl_Char index(int i) const; 00256 00265 int size() const {return size_;} 00266 00270 void size(int W, int H) { Fl_Widget::size(W, H); } 00271 00274 int maximum_size() const {return maximum_size_;} 00275 00278 void maximum_size(int m) {maximum_size_ = m;} 00279 00284 int position() const {return position_;} 00285 00288 int mark() const {return mark_;} 00289 00290 /* Sets the index for the cursor and mark. */ 00291 int position(int p, int m); 00292 00299 int position(int p) {return position(p, p);} 00300 00306 int mark(int m) {return position(position(), m);} 00307 00308 /* Deletes text from b to e and inserts the new string text. */ 00309 int replace(int, int, const char*, int=0); 00310 00321 int cut() {return replace(position(), mark(), 0);} 00322 00335 int cut(int n) {return replace(position(), position()+n, 0);} 00336 00348 int cut(int a, int b) {return replace(a, b, 0);} 00349 00361 int insert(const char* t, int l=0){return replace(position_, mark_, t, l);} 00362 00363 /* Put the current selection into the clipboard. */ 00364 int copy(int clipboard); 00365 00366 /* Undo previous changes to the text buffer. */ 00367 int undo(); 00368 00369 /* Copy the yank buffer to the clipboard. */ 00370 int copy_cuts(); 00371 00375 int shortcut() const {return shortcut_;} 00376 00383 void shortcut(int s) {shortcut_ = s;} 00384 00387 Fl_Font textfont() const {return textfont_;} 00388 00392 void textfont(Fl_Font s) {textfont_ = s;} 00393 00396 Fl_Fontsize textsize() const {return textsize_;} 00397 00401 void textsize(Fl_Fontsize s) {textsize_ = s;} 00402 00406 Fl_Color textcolor() const {return textcolor_;} 00407 00412 void textcolor(Fl_Color n) {textcolor_ = n;} 00413 00416 Fl_Color cursor_color() const {return cursor_color_;} 00417 00421 void cursor_color(Fl_Color n) {cursor_color_ = n;} 00422 00425 int input_type() const {return type() & FL_INPUT_TYPE; } 00426 00430 void input_type(int t) { type((uchar)(t | readonly())); } 00431 00434 int readonly() const { return type() & FL_INPUT_READONLY; } 00435 00438 void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY)); 00439 else type((uchar)(type() & ~FL_INPUT_READONLY)); } 00440 00445 int wrap() const { return type() & FL_INPUT_WRAP; } 00446 00451 void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP)); 00452 else type((uchar)(type() & ~FL_INPUT_WRAP)); } 00453 00475 void tab_nav(int val) { 00476 tab_nav_ = val; 00477 } 00478 00488 int tab_nav() const { 00489 return tab_nav_; 00490 } 00491 }; 00492 00493 #endif 00494 00495 // 00496 // End of "$Id$". 00497 //