FLTK 1.4.0
1 //
2 // Common browser header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2016 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
17 /* \file
18  Fl_Browser_ widget . */
20 // Yes, I know this should be a template...
22 #ifndef Fl_Browser__H
23 #define Fl_Browser__H
25 #ifndef Fl_Group_H
26 #include "Fl_Group.H"
27 #endif
28 #include "Fl_Scrollbar.H"
29 #include <FL/Fl.H> // Fl::scrollbar_size()
31 #define FL_NORMAL_BROWSER 0
32 #define FL_SELECT_BROWSER 1
33 #define FL_HOLD_BROWSER 2
34 #define FL_MULTI_BROWSER 3
36 #define FL_SORT_ASCENDING 0
76 class FL_EXPORT Fl_Browser_ : public Fl_Group {
77  int position_; // where user wants it scrolled to
78  int real_position_; // the current vertical scrolling position
79  int hposition_; // where user wants it panned to
80  int real_hposition_; // the current horizontal scrolling position
81  int offset_; // how far down top_ item the real_position is
82  int max_width; // widest object seen so far
83  uchar has_scrollbar_; // which scrollbars are enabled
84  Fl_Font textfont_;
85  Fl_Fontsize textsize_;
86  Fl_Color textcolor_;
87  void* top_; // which item scrolling position is in
88  void* selection_; // which is selected (except for FL_MULTI_BROWSER)
89  void *redraw1,*redraw2; // minimal update pointers
90  void* max_width_item; // which item has max_width_
91  int scrollbar_size_; // size of scrollbar trough
93  void update_top();
95 protected:
97  // All of the following must be supplied by the subclass:
103  virtual void *item_first() const = 0;
109  virtual void *item_next(void *item) const = 0;
115  virtual void *item_prev(void *item) const = 0;
121  virtual void *item_last() const { return 0L; }
130  virtual int item_height(void *item) const = 0;
138  virtual int item_width(void *item) const = 0;
139  virtual int item_quick_height(void *item) const ;
144  virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0;
150  virtual const char *item_text(void *item) const { (void)item; return 0L; }
156  virtual void item_swap(void *a,void *b) { (void)a; (void)b; }
163  virtual void *item_at(int index) const { (void)index; return 0L; }
164  // you don't have to provide these but it may help speed it up:
165  virtual int full_width() const ; // current width of all items
166  virtual int full_height() const ; // current height of all items
167  virtual int incr_height() const ; // average height of an item
168  // These only need to be done by subclass if you want a multi-browser:
169  virtual void item_select(void *item,int val=1);
170  virtual int item_selected(void *item) const ;
172  // things the subclass may want to call:
176  void *top() const { return top_; }
184  void *selection() const { return selection_; }
185  void new_list(); // completely clobber all data, as though list replaced
186  void deleting(void *item); // get rid of any pointers to item
187  void replacing(void *a,void *b); // change a pointers to b
188  void swapping(void *a,void *b); // exchange pointers a and b
189  void inserting(void *a,void *b); // insert b near a
190  int displayed(void *item) const ; // true if this item is visible
191  void redraw_line(void *item); // minimal update, no change in size
196  void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them
197  void bbox(int &X,int &Y,int &W,int &H) const;
198  int leftedge() const; // x position after scrollbar & border
199  void *find_item(int ypos); // item under mouse
201  void draw();
202  Fl_Browser_(int X,int Y,int W,int H,const char *L=0);
204 public:
227  int handle(int event);
228  void resize(int X,int Y,int W,int H);
230  int select(void *item,int val=1,int docallbacks=0);
231  int select_only(void *item,int docallbacks=0);
232  int deselect(int docallbacks=0);
240  int position() const { return position_; }
241  void position(int pos); // scroll to here
249  int hposition() const { return hposition_; }
250  void hposition(int); // pan to here
251  void display(void *item); // scroll so this item is shown
262  enum { // values for has_scrollbar()
263  HORIZONTAL = 1,
264  VERTICAL = 2,
265  BOTH = 3,
266  ALWAYS_ON = 4,
269  BOTH_ALWAYS = 7
270  };
274  uchar has_scrollbar() const { return has_scrollbar_; }
297  void has_scrollbar(uchar mode) { has_scrollbar_ = mode; }
303  Fl_Font textfont() const { return textfont_; }
307  void textfont(Fl_Font font) { textfont_ = font; }
312  Fl_Fontsize textsize() const { return textsize_; }
316  void textsize(Fl_Fontsize newSize) { textsize_ = newSize; }
321  Fl_Color textcolor() const { return textcolor_; }
325  void textcolor(Fl_Color col) { textcolor_ = col; }
336  int scrollbar_size() const {
337  return(scrollbar_size_);
338  }
358  void scrollbar_size(int newSize) {
359  scrollbar_size_ = newSize;
360  }
366  int scrollbar_width() const {
367  return(Fl::scrollbar_size());
368  }
374  void scrollbar_width(int width) {
375  Fl::scrollbar_size(width);
376  scrollbar_size_ = 0;
377  }
382  void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); }
387  void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
388  void sort(int flags=0);
389 };
391 #endif
const Fl_Align FL_ALIGN_RIGHT
Align the label to the right of the widget.
Definition: Enumerations.H:926
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition: Enumerations.H:1042
The Fl_Scroll widget was scrolled.
Definition: Enumerations.H:1216
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
const Fl_Align FL_ALIGN_LEFT
Align the label at the left of the widget.
Definition: Enumerations.H:923
Fl static class.
This is the base class for browsers.
Definition: Fl_Browser_.H:76
void * selection() const
Returns the item currently selected, or NULL if there is no selection.
Definition: Fl_Browser_.H:184
Fl_Color textcolor() const
Gets the default text color for the lines in the browser.
Definition: Fl_Browser_.H:321
virtual void * item_last() const
This method must be provided by the subclass to return the last item in the list.
Definition: Fl_Browser_.H:121
Fl_Font textfont() const
Gets the default text font for the lines in the browser.
Definition: Fl_Browser_.H:303
int scrollbar_width() const
Returns the global value Fl::scrollbar_size().
Definition: Fl_Browser_.H:366
virtual int item_width(void *item) const =0
This method must be provided by the subclass to return the width of the item in pixels.
Fl_Fontsize textsize() const
Gets the default text size (in pixels) for the lines in the browser.
Definition: Fl_Browser_.H:312
virtual void * item_first() const =0
This method must be provided by the subclass to return the first item in the list.
void scrollbar_width(int width)
Sets the global Fl::scrollbar_size(), and forces this instance of the widget to use it.
Definition: Fl_Browser_.H:374
virtual void item_swap(void *a, void *b)
This optional method should be provided by the subclass to efficiently swap browser items a and b,...
Definition: Fl_Browser_.H:156
virtual int item_height(void *item) const =0
This method must be provided by the subclass to return the height of item in pixels.
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition: Fl_Browser_.H:358
uchar has_scrollbar() const
Returns the current scrollbar mode, see Fl_Browser_::has_scrollbar(uchar)
Definition: Fl_Browser_.H:274
virtual void * item_at(int index) const
This method must be provided by the subclass to return the item for the specified index.
Definition: Fl_Browser_.H:163
void redraw_lines()
This method will cause the entire list to be redrawn.
Definition: Fl_Browser_.H:196
Fl_Scrollbar hscrollbar
Horizontal scrollbar.
Definition: Fl_Browser_.H:225
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition: Fl_Browser_.H:336
void scrollbar_right()
Moves the vertical scrollbar to the righthand side of the list.
Definition: Fl_Browser_.H:382
void has_scrollbar(uchar mode)
Sets whether the widget should have scrollbars or not (default Fl_Browser_::BOTH).
Definition: Fl_Browser_.H:297
Fl_Scrollbar scrollbar
Vertical scrollbar.
Definition: Fl_Browser_.H:221
virtual void * item_next(void *item) const =0
This method must be provided by the subclass to return the item in the list after item.
void * top() const
Returns the item that appears at the top of the list.
Definition: Fl_Browser_.H:176
virtual void item_draw(void *item, int X, int Y, int W, int H) const =0
This method must be provided by the subclass to draw the item in the area indicated by X,...
void textcolor(Fl_Color col)
Sets the default text color for the lines in the browser to color col.
Definition: Fl_Browser_.H:325
void textsize(Fl_Fontsize newSize)
Sets the default text size (in pixels) for the lines in the browser to size.
Definition: Fl_Browser_.H:316
int hposition() const
Gets the horizontal scroll position of the list as a pixel position pos.
Definition: Fl_Browser_.H:249
void textfont(Fl_Font font)
Sets the default text font for the lines in the browser to font.
Definition: Fl_Browser_.H:307
int position() const
Gets the vertical scroll position of the list as a pixel position pos.
Definition: Fl_Browser_.H:240
void scrollbar_left()
Moves the vertical scrollbar to the lefthand side of the list.
Definition: Fl_Browser_.H:387
virtual const char * item_text(void *item) const
This optional method returns a string (label) that may be used for sorting.
Definition: Fl_Browser_.H:150
virtual void * item_prev(void *item) const =0
This method must be provided by the subclass to return the item in the list before item.
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:145
void draw()
Draws the widget.
Definition: Fl_Group.cxx:840
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:737
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:41
Fl_Align align() const
Gets the label alignment.
Definition: Fl_Widget.H:354
void position(int X, int Y)
Repositions the window or widget.
Definition: Fl_Widget.H:338
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition: Fl_Widget.H:958
static int scrollbar_size()
Gets the default scrollbar size used by Fl_Browser_, Fl_Help_View, Fl_Scroll, and Fl_Text_Display wid...
Definition: Fl.cxx:146
unsigned char uchar
unsigned char
Definition: fl_types.h:28