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-2011 by Bill Spitzak and others. 00007 // 00008 // This library is free software. Distribution and use rights are outlined in 00009 // the file "COPYING" which should have been included with this file. If this 00010 // file is missing or damaged, see the license at: 00011 // 00012 // http://www.fltk.org/COPYING.php 00013 // 00014 // Please report all bugs and problems on the following page: 00015 // 00016 // http://www.fltk.org/str.php 00017 // 00018 00019 /* \file 00020 Fl_Input_ widget . */ 00021 00022 #ifndef Fl_Input__H 00023 #define Fl_Input__H 00024 00025 #ifndef Fl_Widget_H 00026 #include "Fl_Widget.H" 00027 #endif 00028 00029 #define FL_NORMAL_INPUT 0 00030 #define FL_FLOAT_INPUT 1 00031 #define FL_INT_INPUT 2 00032 #define FL_HIDDEN_INPUT 3 00033 #define FL_MULTILINE_INPUT 4 00034 #define FL_SECRET_INPUT 5 00035 #define FL_INPUT_TYPE 7 00036 #define FL_INPUT_READONLY 8 00037 #define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY) 00038 #define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY) 00039 #define FL_INPUT_WRAP 16 00040 #define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP) 00041 #define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP) 00042 00094 class FL_EXPORT Fl_Input_ : public Fl_Widget { 00095 00097 const char* value_; 00098 00100 char* buffer; 00101 00103 int size_; 00104 00106 int bufsize; 00107 00109 int position_; 00110 00113 int mark_; 00114 00118 int tab_nav_; 00119 00121 int xscroll_, yscroll_; 00122 00125 int mu_p; 00126 00128 int maximum_size_; 00129 00131 int shortcut_; 00132 00134 uchar erase_cursor_only; 00135 00137 Fl_Font textfont_; 00138 00140 Fl_Fontsize textsize_; 00141 00143 Fl_Color textcolor_; 00144 00146 Fl_Color cursor_color_; 00147 00149 static double up_down_pos; 00150 00152 static int was_up_down; 00153 00154 /* Convert a given text segment into the text that will be rendered on screen. */ 00155 const char* expand(const char*, char*) const; 00156 00157 /* Calculates the width in pixels of part of a text buffer. */ 00158 double expandpos(const char*, const char*, const char*, int*) const; 00159 00160 /* Mark a range of characters for update. */ 00161 void minimal_update(int, int); 00162 00163 /* Mark a range of characters for update. */ 00164 void minimal_update(int p); 00165 00166 /* Copy the value from a possibly static entry into the internal buffer. */ 00167 void put_in_buffer(int newsize); 00168 00169 /* Set the current font and font size. */ 00170 void setfont() const; 00171 00172 protected: 00173 00174 /* Find the start of a word. */ 00175 int word_start(int i) const; 00176 00177 /* Find the end of a word. */ 00178 int word_end(int i) const; 00179 00180 /* Find the start of a line. */ 00181 int line_start(int i) const; 00182 00183 /* Find the end of a line. */ 00184 int line_end(int i) const; 00185 00186 /* Draw the text in the passed bounding box. */ 00187 void drawtext(int, int, int, int); 00188 00189 /* Move the cursor to the column given by up_down_pos. */ 00190 int up_down_position(int, int keepmark=0); 00191 00192 /* Handle mouse clicks and mouse moves. */ 00193 void handle_mouse(int, int, int, int, int keepmark=0); 00194 00195 /* Handle all kinds of text field related events. */ 00196 int handletext(int e, int, int, int, int); 00197 00198 /* Check the when() field and do a callback if indicated. */ 00199 void maybe_do_callback(); 00200 00202 int xscroll() const {return xscroll_;} 00203 00205 int yscroll() const {return yscroll_;} 00206 void yscroll(int yOffset) { yscroll_ = yOffset; damage(FL_DAMAGE_EXPOSE);} 00207 00208 /* Return the number of lines displayed on a single page. */ 00209 int linesPerPage(); 00210 00211 public: 00212 00213 /* Change the size of the widget. */ 00214 void resize(int, int, int, int); 00215 00216 /* Constructor */ 00217 Fl_Input_(int, int, int, int, const char* = 0); 00218 00219 /* Destructor */ 00220 ~Fl_Input_(); 00221 00222 /* Changes the widget text. */ 00223 int value(const char*); 00224 00225 /* Changes the widget text. */ 00226 int value(const char*, int); 00227 00228 /* Changes the widget text. */ 00229 int static_value(const char*); 00230 00231 /* Changes the widget text. */ 00232 int static_value(const char*, int); 00233 00244 const char* value() const {return value_;} 00245 00246 /* Returns the character at index \p i. */ 00247 Fl_Char index(int i) const; 00248 00257 int size() const {return size_;} 00258 00262 void size(int W, int H) { Fl_Widget::size(W, H); } 00263 00266 int maximum_size() const {return maximum_size_;} 00267 00275 void maximum_size(int m) {maximum_size_ = m;} 00276 00281 int position() const {return position_;} 00282 00285 int mark() const {return mark_;} 00286 00287 /* Sets the index for the cursor and mark. */ 00288 int position(int p, int m); 00289 00296 int position(int p) {return position(p, p);} 00297 00303 int mark(int m) {return position(position(), m);} 00304 00305 /* Deletes text from \p b to \p e and inserts the new string \p text. */ 00306 int replace(int b, int e, const char *text, int ilen=0); 00307 00318 int cut() {return replace(position(), mark(), 0);} 00319 00332 int cut(int n) {return replace(position(), position()+n, 0);} 00333 00345 int cut(int a, int b) {return replace(a, b, 0);} 00346 00358 int insert(const char* t, int l=0){return replace(position_, mark_, t, l);} 00359 00360 /* Put the current selection into the clipboard. */ 00361 int copy(int clipboard); 00362 00363 /* Undo previous changes to the text buffer. */ 00364 int undo(); 00365 00366 /* Copy the yank buffer to the clipboard. */ 00367 int copy_cuts(); 00368 00372 int shortcut() const {return shortcut_;} 00373 00380 void shortcut(int s) {shortcut_ = s;} 00381 00384 Fl_Font textfont() const {return textfont_;} 00385 00389 void textfont(Fl_Font s) {textfont_ = s;} 00390 00393 Fl_Fontsize textsize() const {return textsize_;} 00394 00398 void textsize(Fl_Fontsize s) {textsize_ = s;} 00399 00403 Fl_Color textcolor() const {return textcolor_;} 00404 00409 void textcolor(Fl_Color n) {textcolor_ = n;} 00410 00413 Fl_Color cursor_color() const {return cursor_color_;} 00414 00418 void cursor_color(Fl_Color n) {cursor_color_ = n;} 00419 00422 int input_type() const {return type() & FL_INPUT_TYPE; } 00423 00427 void input_type(int t) { type((uchar)(t | readonly())); } 00428 00431 int readonly() const { return type() & FL_INPUT_READONLY; } 00432 00435 void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY)); 00436 else type((uchar)(type() & ~FL_INPUT_READONLY)); } 00437 00442 int wrap() const { return type() & FL_INPUT_WRAP; } 00443 00448 void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP)); 00449 else type((uchar)(type() & ~FL_INPUT_WRAP)); } 00450 00472 void tab_nav(int val) { 00473 tab_nav_ = val; 00474 } 00475 00485 int tab_nav() const { 00486 return tab_nav_; 00487 } 00488 }; 00489 00490 #endif 00491 00492 // 00493 // End of "$Id$". 00494 //