• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

Fl_Input_.H

00001 //
00002 // "$Id$"
00003 //
00004 // Input base class header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2015 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 
00277   void maximum_size(int m) {maximum_size_ = m;}
00278 
00283   int position() const {return position_;}
00284 
00287   int mark() const {return mark_;}
00288 
00289   /* Sets the index for the cursor and mark. */
00290   int position(int p, int m);
00291 
00298   int position(int p) {return position(p, p);}
00299 
00305   int mark(int m) {return position(position(), m);}
00306 
00307   /* Deletes text from \p b to \p e and inserts the new string \p text. */
00308   int replace(int b, int e, const char *text, int ilen=0);
00309 
00320   int cut() {return replace(position(), mark(), 0);}
00321 
00334   int cut(int n) {return replace(position(), position()+n, 0);}
00335 
00347   int cut(int a, int b) {return replace(a, b, 0);}
00348 
00360   int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
00361 
00362   /* Put the current selection into the clipboard. */
00363   int copy(int clipboard);
00364 
00365   /* Undo previous changes to the text buffer. */
00366   int undo();
00367 
00368   /* Copy the yank buffer to the clipboard. */
00369   int copy_cuts();
00370 
00374   int shortcut() const {return shortcut_;}
00375 
00382   void shortcut(int s) {shortcut_ = s;}
00383 
00386   Fl_Font textfont() const {return textfont_;}
00387 
00391   void textfont(Fl_Font s) {textfont_ = s;}
00392 
00395   Fl_Fontsize textsize() const {return textsize_;}
00396 
00400   void textsize(Fl_Fontsize s) {textsize_ = s;}
00401 
00405   Fl_Color textcolor() const {return textcolor_;}
00406 
00411   void textcolor(Fl_Color n) {textcolor_ = n;}
00412 
00415   Fl_Color cursor_color() const {return cursor_color_;}
00416 
00420   void cursor_color(Fl_Color n) {cursor_color_ = n;}
00421 
00424   int input_type() const {return type() & FL_INPUT_TYPE; }
00425 
00429   void input_type(int t) { type((uchar)(t | readonly())); }
00430 
00433   int readonly() const { return type() & FL_INPUT_READONLY; }
00434 
00437   void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
00438                          else type((uchar)(type() & ~FL_INPUT_READONLY)); }
00439 
00444   int wrap() const { return type() & FL_INPUT_WRAP; }
00445 
00450   void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
00451                          else type((uchar)(type() & ~FL_INPUT_WRAP)); }
00452 
00476   void tab_nav(int val) {
00477     tab_nav_ = val;
00478   }
00479 
00490   int tab_nav() const {
00491     return tab_nav_;
00492   }
00493 };
00494 
00495 #endif 
00496 
00497 //
00498 // End of "$Id$".
00499 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.