FLTK 1.3.0
|
00001 // 00002 // "$Id$" 00003 // 00004 // Browser 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_Browser widget . */ 00030 00031 // Forms-compatable browser. Probably useful for other 00032 // lists of textual data. Notice that the line numbers 00033 // start from 1, and 0 means "no line". 00034 00035 #ifndef Fl_Browser_H 00036 #define Fl_Browser_H 00037 00038 #include "Fl_Browser_.H" 00039 #include "Fl_Image.H" 00040 00041 struct FL_BLINE; 00042 00089 class FL_EXPORT Fl_Browser : public Fl_Browser_ { 00090 00091 FL_BLINE *first; // the array of lines 00092 FL_BLINE *last; 00093 FL_BLINE *cache; 00094 int cacheline; // line number of cache 00095 int lines; // Number of lines 00096 int full_height_; 00097 const int* column_widths_; 00098 char format_char_; // alternative to @-sign 00099 char column_char_; // alternative to tab 00100 00101 protected: 00102 00103 // required routines for Fl_Browser_ subclass: 00104 void* item_first() const ; 00105 void* item_next(void* item) const ; 00106 void* item_prev(void* item) const ; 00107 void* item_last()const ; 00108 int item_selected(void* item) const ; 00109 void item_select(void* item, int val); 00110 int item_height(void* item) const ; 00111 int item_width(void* item) const ; 00112 void item_draw(void* item, int X, int Y, int W, int H) const ; 00113 int full_height() const ; 00114 int incr_height() const ; 00115 const char *item_text(void *item) const; 00121 void item_swap(void *a, void *b) { swap((FL_BLINE*)a, (FL_BLINE*)b); } 00127 void *item_at(int line) const { return (void*)find_line(line); } 00128 00129 FL_BLINE* find_line(int line) const ; 00130 FL_BLINE* _remove(int line) ; 00131 void insert(int line, FL_BLINE* item); 00132 int lineno(void *item) const ; 00133 void swap(FL_BLINE *a, FL_BLINE *b); 00134 00135 public: 00136 00137 void remove(int line); 00138 void add(const char* newtext, void* d = 0); 00139 void insert(int line, const char* newtext, void* d = 0); 00140 void move(int to, int from); 00141 int load(const char* filename); 00142 void swap(int a, int b); 00143 void clear(); 00144 00150 int size() const { return lines; } 00151 void size(int W, int H) { Fl_Widget::size(W, H); } 00152 00153 int topline() const ; 00155 enum Fl_Line_Position { TOP, BOTTOM, MIDDLE }; 00156 void lineposition(int line, Fl_Line_Position pos); 00163 void topline(int line) { lineposition(line, TOP); } 00170 void bottomline(int line) { lineposition(line, BOTTOM); } 00177 void middleline(int line) { lineposition(line, MIDDLE); } 00178 00179 int select(int line, int val=1); 00180 int selected(int line) const ; 00181 void show(int line); 00183 void show() { Fl_Widget::show(); } 00184 void hide(int line); 00186 void hide() { Fl_Widget::hide(); } 00187 int visible(int line) const ; 00188 00189 int value() const ; 00195 void value(int line) { select(line); } 00196 const char* text(int line) const ; 00197 void text(int line, const char* newtext); 00198 void* data(int line) const ; 00199 void data(int line, void* d); 00200 00201 Fl_Browser(int X, int Y, int W, int H, const char *L = 0); 00205 ~Fl_Browser() { clear(); } 00206 00236 char format_char() const { return format_char_; } 00242 void format_char(char c) { format_char_ = c; } 00248 char column_char() const { return column_char_; } 00255 void column_char(char c) { column_char_ = c; } 00279 const int* column_widths() const { return column_widths_; } 00284 void column_widths(const int* arr) { column_widths_ = arr; } 00285 00295 int displayed(int line) const { return Fl_Browser_::displayed(find_line(line)); } 00296 00304 void make_visible(int line) { 00305 if (line < 1) Fl_Browser_::display(find_line(1)); 00306 else if (line > lines) Fl_Browser_::display(find_line(lines)); 00307 else Fl_Browser_::display(find_line(line)); 00308 } 00309 00310 // icon support 00311 void icon(int line, Fl_Image* icon); 00312 Fl_Image* icon(int line) const; 00313 void remove_icon(int line); 00314 00316 void replace(int a, const char* b) { text(a, b); } 00317 void display(int line, int val=1); 00318 }; 00319 00320 #endif 00321 00322 // 00323 // End of "$Id$". 00324 //