FLTK 1.3.0
|
00001 // 00002 // "$Id: Fl_Browser_.H 8275 2011-01-13 22:07:31Z manolo $" 00003 // 00004 // Common 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 // Yes, I know this should be a template... 00032 00033 #ifndef Fl_Browser__H 00034 #define Fl_Browser__H 00035 00036 #ifndef Fl_Group_H 00037 #include "Fl_Group.H" 00038 #endif 00039 #include "Fl_Scrollbar.H" 00040 #include <FL/Fl.H> // Fl::scrollbar_size() 00041 00042 #define FL_NORMAL_BROWSER 0 00043 #define FL_SELECT_BROWSER 1 00044 #define FL_HOLD_BROWSER 2 00045 #define FL_MULTI_BROWSER 3 00047 #define FL_SORT_ASCENDING 0 00048 #define FL_SORT_DESCENDING 1 00067 class FL_EXPORT Fl_Browser_ : public Fl_Group { 00068 int position_; // where user wants it scrolled to 00069 int real_position_; // the current vertical scrolling position 00070 int hposition_; // where user wants it panned to 00071 int real_hposition_; // the current horizontal scrolling position 00072 int offset_; // how far down top_ item the real_position is 00073 int max_width; // widest object seen so far 00074 uchar has_scrollbar_; // which scrollbars are enabled 00075 Fl_Font textfont_; 00076 Fl_Fontsize textsize_; 00077 Fl_Color textcolor_; 00078 void* top_; // which item scrolling position is in 00079 void* selection_; // which is selected (except for FL_MULTI_BROWSER) 00080 void *redraw1,*redraw2; // minimal update pointers 00081 void* max_width_item; // which item has max_width_ 00082 int scrollbar_size_; // size of scrollbar trough 00083 00084 void update_top(); 00085 00086 protected: 00087 00088 // All of the following must be supplied by the subclass: 00094 virtual void *item_first() const = 0; 00100 virtual void *item_next(void *item) const = 0; 00106 virtual void *item_prev(void *item) const = 0; 00112 virtual void *item_last() const { return 0L; } 00121 virtual int item_height(void *item) const = 0; 00129 virtual int item_width(void *item) const = 0; 00130 virtual int item_quick_height(void *item) const ; 00135 virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0; 00141 virtual const char *item_text(void *item) const { (void)item; return 0L; } 00147 virtual void item_swap(void *a,void *b) { (void)a; (void)b; } 00154 virtual void *item_at(int index) const { (void)index; return 0L; } 00155 // you don't have to provide these but it may help speed it up: 00156 virtual int full_width() const ; // current width of all items 00157 virtual int full_height() const ; // current height of all items 00158 virtual int incr_height() const ; // average height of an item 00159 // These only need to be done by subclass if you want a multi-browser: 00160 virtual void item_select(void *item,int val=1); 00161 virtual int item_selected(void *item) const ; 00162 00163 // things the subclass may want to call: 00167 void *top() const { return top_; } 00175 void *selection() const { return selection_; } 00176 void new_list(); // completely clobber all data, as though list replaced 00177 void deleting(void *item); // get rid of any pointers to item 00178 void replacing(void *a,void *b); // change a pointers to b 00179 void swapping(void *a,void *b); // exchange pointers a and b 00180 void inserting(void *a,void *b); // insert b near a 00181 int displayed(void *item) const ; // true if this item is visible 00182 void redraw_line(void *item); // minimal update, no change in size 00187 void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them 00188 void bbox(int &X,int &Y,int &W,int &H) const; 00189 int leftedge() const; // x position after scrollbar & border 00190 void *find_item(int ypos); // item under mouse 00191 00192 void draw(); 00193 Fl_Browser_(int X,int Y,int W,int H,const char *L=0); 00194 00195 public: 00196 00200 Fl_Scrollbar scrollbar; 00204 Fl_Scrollbar hscrollbar; 00205 00206 int handle(int event); 00207 void resize(int X,int Y,int W,int H); 00208 00209 int select(void *item,int val=1,int docallbacks=0); 00210 int select_only(void *item,int docallbacks=0); 00211 int deselect(int docallbacks=0); 00219 int position() const { return position_; } 00220 void position(int pos); // scroll to here 00228 int hposition() const { return hposition_; } 00229 void hposition(int); // pan to here 00230 void display(void *item); // scroll so this item is shown 00231 00241 enum { // values for has_scrollbar() 00242 HORIZONTAL = 1, 00243 VERTICAL = 2, 00244 BOTH = 3, 00245 ALWAYS_ON = 4, 00246 HORIZONTAL_ALWAYS = 5, 00247 VERTICAL_ALWAYS = 6, 00248 BOTH_ALWAYS = 7 00249 }; 00253 uchar has_scrollbar() const { return has_scrollbar_; } 00276 void has_scrollbar(uchar mode) { has_scrollbar_ = mode; } 00277 00282 Fl_Font textfont() const { return textfont_; } 00286 void textfont(Fl_Font font) { textfont_ = font; } 00287 00291 Fl_Fontsize textsize() const { return textsize_; } 00295 void textsize(Fl_Fontsize size) { textsize_ = size; } 00296 00300 Fl_Color textcolor() const { return textcolor_; } 00304 void textcolor(Fl_Color col) { textcolor_ = col; } 00305 00315 int scrollbar_size() const { 00316 return(scrollbar_size_); 00317 } 00337 void scrollbar_size(int size) { 00338 scrollbar_size_ = size; 00339 } 00347 int scrollbar_width() const { 00348 return(Fl::scrollbar_size()); 00349 } 00357 void scrollbar_width(int width) { 00358 Fl::scrollbar_size(width); 00359 scrollbar_size_ = 0; 00360 } 00365 void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); } 00370 void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); } 00371 void sort(int flags=0); 00372 }; 00373 00374 #endif 00375 00376 // 00377 // End of "$Id: Fl_Browser_.H 8275 2011-01-13 22:07:31Z manolo $". 00378 //