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

Fl_Browser_.H

00001 //
00002 // "$Id$"
00003 //
00004 // Common browser header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2016 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       
00077 class FL_EXPORT Fl_Browser_ : public Fl_Group {
00078   int position_;        // where user wants it scrolled to
00079   int real_position_;   // the current vertical scrolling position
00080   int hposition_;       // where user wants it panned to
00081   int real_hposition_;  // the current horizontal scrolling position
00082   int offset_;          // how far down top_ item the real_position is
00083   int max_width;        // widest object seen so far
00084   uchar has_scrollbar_; // which scrollbars are enabled
00085   Fl_Font textfont_;
00086   Fl_Fontsize textsize_;
00087   Fl_Color textcolor_;
00088   void* top_;           // which item scrolling position is in
00089   void* selection_;     // which is selected (except for FL_MULTI_BROWSER)
00090   void *redraw1,*redraw2; // minimal update pointers
00091   void* max_width_item; // which item has max_width_
00092   int scrollbar_size_;  // size of scrollbar trough
00093 
00094   void update_top();
00095 
00096 protected:
00097 
00098   // All of the following must be supplied by the subclass:
00104   virtual void *item_first() const = 0;
00110   virtual void *item_next(void *item) const = 0;
00116   virtual void *item_prev(void *item) const = 0;
00122   virtual void *item_last() const { return 0L; }
00131   virtual int item_height(void *item) const = 0;
00139   virtual int item_width(void *item) const = 0;
00140   virtual int item_quick_height(void *item) const ;
00145   virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0;
00151   virtual const char *item_text(void *item) const { (void)item; return 0L; }
00157   virtual void item_swap(void *a,void *b) { (void)a; (void)b; }
00164   virtual void *item_at(int index) const { (void)index; return 0L; }
00165   // you don't have to provide these but it may help speed it up:
00166   virtual int full_width() const ;      // current width of all items
00167   virtual int full_height() const ;     // current height of all items
00168   virtual int incr_height() const ;     // average height of an item
00169   // These only need to be done by subclass if you want a multi-browser:
00170   virtual void item_select(void *item,int val=1);
00171   virtual int item_selected(void *item) const ;
00172 
00173   // things the subclass may want to call:
00177   void *top() const { return top_; }
00185   void *selection() const { return selection_; }
00186   void new_list(); // completely clobber all data, as though list replaced
00187   void deleting(void *item); // get rid of any pointers to item
00188   void replacing(void *a,void *b); // change a pointers to b
00189   void swapping(void *a,void *b); // exchange pointers a and b
00190   void inserting(void *a,void *b); // insert b near a
00191   int displayed(void *item) const ; // true if this item is visible
00192   void redraw_line(void *item); // minimal update, no change in size
00197   void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them
00198   void bbox(int &X,int &Y,int &W,int &H) const;
00199   int leftedge() const; // x position after scrollbar & border
00200   void *find_item(int ypos); // item under mouse
00201   
00202   void draw();
00203   Fl_Browser_(int X,int Y,int W,int H,const char *L=0);
00204 
00205 public:
00206 
00210   Fl_Scrollbar scrollbar;
00214   Fl_Scrollbar hscrollbar;
00215 
00216   int handle(int event);
00217   void resize(int X,int Y,int W,int H);
00218 
00219   int select(void *item,int val=1,int docallbacks=0);
00220   int select_only(void *item,int docallbacks=0);
00221   int deselect(int docallbacks=0);
00229   int position() const { return position_; }
00230   void position(int pos); // scroll to here
00238   int hposition() const { return hposition_; }
00239   void hposition(int); // pan to here
00240   void display(void *item); // scroll so this item is shown
00241 
00251   enum { // values for has_scrollbar()
00252     HORIZONTAL = 1,             
00253     VERTICAL = 2,               
00254     BOTH = 3,                   
00255     ALWAYS_ON = 4,              
00256     HORIZONTAL_ALWAYS = 5,      
00257     VERTICAL_ALWAYS = 6,        
00258     BOTH_ALWAYS = 7             
00259   };
00263   uchar has_scrollbar() const { return has_scrollbar_; }
00286   void has_scrollbar(uchar mode) { has_scrollbar_ = mode; }
00287 
00292   Fl_Font textfont() const { return textfont_; }
00296   void textfont(Fl_Font font) { textfont_ = font; }
00297 
00301   Fl_Fontsize textsize() const { return textsize_; }
00305   void textsize(Fl_Fontsize newSize) { textsize_ = newSize; }
00306 
00310   Fl_Color textcolor() const { return textcolor_; }
00314   void textcolor(Fl_Color col) { textcolor_ = col; }
00315 
00325   int scrollbar_size() const {
00326       return(scrollbar_size_);
00327   }
00347   void scrollbar_size(int newSize) {
00348       scrollbar_size_ = newSize;
00349   }   
00357   int scrollbar_width() const {
00358       return(Fl::scrollbar_size());
00359   }
00367   void scrollbar_width(int width) {
00368       Fl::scrollbar_size(width);
00369       scrollbar_size_ = 0;
00370   }
00375   void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); }
00380   void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
00381   void sort(int flags=0);
00382 };
00383 
00384 #endif
00385 
00386 //
00387 // End of "$Id$".
00388 //
  • © 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.