FLTK 1.3.0
Fl_Browser_.H
00001 //
00002 // "$Id$"
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. 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_Browser_ widget . */
00021 
00022 // Yes, I know this should be a template...
00023 
00024 #ifndef Fl_Browser__H
00025 #define Fl_Browser__H
00026 
00027 #ifndef Fl_Group_H
00028 #include "Fl_Group.H"
00029 #endif
00030 #include "Fl_Scrollbar.H"
00031 #include <FL/Fl.H>              // Fl::scrollbar_size()
00032 
00033 #define FL_NORMAL_BROWSER       0       
00034 #define FL_SELECT_BROWSER       1       
00035 #define FL_HOLD_BROWSER         2       
00036 #define FL_MULTI_BROWSER        3       
00038 #define FL_SORT_ASCENDING       0       
00039 #define FL_SORT_DESCENDING      1       
00058 class FL_EXPORT Fl_Browser_ : public Fl_Group {
00059   int position_;        // where user wants it scrolled to
00060   int real_position_;   // the current vertical scrolling position
00061   int hposition_;       // where user wants it panned to
00062   int real_hposition_;  // the current horizontal scrolling position
00063   int offset_;          // how far down top_ item the real_position is
00064   int max_width;        // widest object seen so far
00065   uchar has_scrollbar_; // which scrollbars are enabled
00066   Fl_Font textfont_;
00067   Fl_Fontsize textsize_;
00068   Fl_Color textcolor_;
00069   void* top_;           // which item scrolling position is in
00070   void* selection_;     // which is selected (except for FL_MULTI_BROWSER)
00071   void *redraw1,*redraw2; // minimal update pointers
00072   void* max_width_item; // which item has max_width_
00073   int scrollbar_size_;  // size of scrollbar trough
00074 
00075   void update_top();
00076 
00077 protected:
00078 
00079   // All of the following must be supplied by the subclass:
00085   virtual void *item_first() const = 0;
00091   virtual void *item_next(void *item) const = 0;
00097   virtual void *item_prev(void *item) const = 0;
00103   virtual void *item_last() const { return 0L; }
00112   virtual int item_height(void *item) const = 0;
00120   virtual int item_width(void *item) const = 0;
00121   virtual int item_quick_height(void *item) const ;
00126   virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0;
00132   virtual const char *item_text(void *item) const { (void)item; return 0L; }
00138   virtual void item_swap(void *a,void *b) { (void)a; (void)b; }
00145   virtual void *item_at(int index) const { (void)index; return 0L; }
00146   // you don't have to provide these but it may help speed it up:
00147   virtual int full_width() const ;      // current width of all items
00148   virtual int full_height() const ;     // current height of all items
00149   virtual int incr_height() const ;     // average height of an item
00150   // These only need to be done by subclass if you want a multi-browser:
00151   virtual void item_select(void *item,int val=1);
00152   virtual int item_selected(void *item) const ;
00153 
00154   // things the subclass may want to call:
00158   void *top() const { return top_; }
00166   void *selection() const { return selection_; }
00167   void new_list(); // completely clobber all data, as though list replaced
00168   void deleting(void *item); // get rid of any pointers to item
00169   void replacing(void *a,void *b); // change a pointers to b
00170   void swapping(void *a,void *b); // exchange pointers a and b
00171   void inserting(void *a,void *b); // insert b near a
00172   int displayed(void *item) const ; // true if this item is visible
00173   void redraw_line(void *item); // minimal update, no change in size
00178   void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them
00179   void bbox(int &X,int &Y,int &W,int &H) const;
00180   int leftedge() const; // x position after scrollbar & border
00181   void *find_item(int ypos); // item under mouse
00182   
00183   void draw();
00184   Fl_Browser_(int X,int Y,int W,int H,const char *L=0);
00185 
00186 public:
00187 
00191   Fl_Scrollbar scrollbar;
00195   Fl_Scrollbar hscrollbar;
00196 
00197   int handle(int event);
00198   void resize(int X,int Y,int W,int H);
00199 
00200   int select(void *item,int val=1,int docallbacks=0);
00201   int select_only(void *item,int docallbacks=0);
00202   int deselect(int docallbacks=0);
00210   int position() const { return position_; }
00211   void position(int pos); // scroll to here
00219   int hposition() const { return hposition_; }
00220   void hposition(int); // pan to here
00221   void display(void *item); // scroll so this item is shown
00222 
00232   enum { // values for has_scrollbar()
00233     HORIZONTAL = 1,             
00234     VERTICAL = 2,               
00235     BOTH = 3,                   
00236     ALWAYS_ON = 4,              
00237     HORIZONTAL_ALWAYS = 5,      
00238     VERTICAL_ALWAYS = 6,        
00239     BOTH_ALWAYS = 7             
00240   };
00244   uchar has_scrollbar() const { return has_scrollbar_; }
00267   void has_scrollbar(uchar mode) { has_scrollbar_ = mode; }
00268 
00273   Fl_Font textfont() const { return textfont_; }
00277   void textfont(Fl_Font font) { textfont_ = font; }
00278 
00282   Fl_Fontsize textsize() const { return textsize_; }
00286   void textsize(Fl_Fontsize newSize) { textsize_ = newSize; }
00287 
00291   Fl_Color textcolor() const { return textcolor_; }
00295   void textcolor(Fl_Color col) { textcolor_ = col; }
00296 
00306   int scrollbar_size() const {
00307       return(scrollbar_size_);
00308   }
00328   void scrollbar_size(int newSize) {
00329       scrollbar_size_ = newSize;
00330   }   
00338   int scrollbar_width() const {
00339       return(Fl::scrollbar_size());
00340   }
00348   void scrollbar_width(int width) {
00349       Fl::scrollbar_size(width);
00350       scrollbar_size_ = 0;
00351   }
00356   void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); }
00361   void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
00362   void sort(int flags=0);
00363 };
00364 
00365 #endif
00366 
00367 //
00368 // End of "$Id$".
00369 //