NTK 1.3.0
Fl_Browser_.H
1//
2// "$Id: Fl_Browser_.H 8275 2011-01-13 22:07:31Z manolo $"
3//
4// Common browser header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28/* \file
29 Fl_Browser_ widget . */
30
31// Yes, I know this should be a template...
32
33#ifndef Fl_Browser__H
34#define Fl_Browser__H
35
36#ifndef Fl_Group_H
37#include "Fl_Group.H"
38#endif
39#include "Fl_Scrollbar.H"
40#include <FL/Fl.H> // Fl::scrollbar_size()
41
42#define FL_NORMAL_BROWSER 0
43#define FL_SELECT_BROWSER 1
44#define FL_HOLD_BROWSER 2
45#define FL_MULTI_BROWSER 3
47#define FL_SORT_ASCENDING 0
48#define FL_SORT_DESCENDING 1
67class FL_EXPORT Fl_Browser_ : public Fl_Group {
68 int position_; // where user wants it scrolled to
69 int real_position_; // the current vertical scrolling position
70 int hposition_; // where user wants it panned to
71 int real_hposition_; // the current horizontal scrolling position
72 int offset_; // how far down top_ item the real_position is
73 int max_width; // widest object seen so far
74 uchar has_scrollbar_; // which scrollbars are enabled
75 Fl_Font textfont_;
76 Fl_Fontsize textsize_;
77 Fl_Color textcolor_;
78 void* top_; // which item scrolling position is in
79 void* selection_; // which is selected (except for FL_MULTI_BROWSER)
80 void *redraw1,*redraw2; // minimal update pointers
81 void* max_width_item; // which item has max_width_
82 int scrollbar_size_; // size of scrollbar trough
83
84 void update_top();
85
86protected:
87
88 // All of the following must be supplied by the subclass:
94 virtual void *item_first() const = 0;
100 virtual void *item_next(void *item) const = 0;
106 virtual void *item_prev(void *item) const = 0;
112 virtual void *item_last() const { return 0L; }
121 virtual int item_height(void *item) const = 0;
129 virtual int item_width(void *item) const = 0;
130 virtual int item_quick_height(void *item) const ;
135 virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0;
141 virtual const char *item_text(void *item) const { (void)item; return 0L; }
147 virtual void item_swap(void *a,void *b) { (void)a; (void)b; }
154 virtual void *item_at(int index) const { (void)index; return 0L; }
155 // you don't have to provide these but it may help speed it up:
156 // These only need to be done by subclass if you want a multi-browser:
157 virtual void item_select(void *item,int val=1);
158 virtual int item_selected(void *item) const ;
159
160 // things the subclass may want to call:
164 void *top() const { return top_; }
172 void *selection() const { return selection_; }
173 void new_list(); // completely clobber all data, as though list replaced
174 void deleting(void *item); // get rid of any pointers to item
175 void replacing(void *a,void *b); // change a pointers to b
176 void swapping(void *a,void *b); // exchange pointers a and b
177 void inserting(void *a,void *b); // insert b near a
178 int displayed(void *item) const ; // true if this item is visible
179 void redraw_line(void *item); // minimal update, no change in size
184 void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them
185 void bbox(int &X,int &Y,int &W,int &H) const;
186 int leftedge() const; // x position after scrollbar & border
187 void *find_item(int ypos); // item under mouse
188
189 void draw();
190 Fl_Browser_(int X,int Y,int W,int H,const char *L=0);
191
192public:
193
194 virtual int full_width() const ; // current width of all items
195 virtual int full_height() const ; // current height of all items
196 virtual int incr_height() const ; // average height of an item
197
206
207 int handle(int event);
208 void resize(int X,int Y,int W,int H);
209
210 int select(void *item,int val=1,int docallbacks=0);
211 int select_only(void *item,int docallbacks=0);
212 int deselect(int docallbacks=0);
220 int position() const { return position_; }
221 void position(int pos); // scroll to here
229 int hposition() const { return hposition_; }
230 void hposition(int); // pan to here
231 void display(void *item); // scroll so this item is shown
232
242 enum { // values for has_scrollbar()
243 HORIZONTAL = 1,
244 VERTICAL = 2,
245 BOTH = 3,
246 ALWAYS_ON = 4,
247 HORIZONTAL_ALWAYS = 5,
248 VERTICAL_ALWAYS = 6,
249 BOTH_ALWAYS = 7
250 };
254 uchar has_scrollbar() const { return has_scrollbar_; }
277 void has_scrollbar(uchar mode) { has_scrollbar_ = mode; }
278
283 Fl_Font textfont() const { return textfont_; }
287 void textfont(Fl_Font font) { textfont_ = font; }
288
292 Fl_Fontsize textsize() const { return textsize_; }
296 void textsize(Fl_Fontsize size) { textsize_ = size; }
297
301 Fl_Color textcolor() const { return textcolor_; }
305 void textcolor(Fl_Color col) { textcolor_ = col; }
306
316 int scrollbar_size() const {
317 return(scrollbar_size_);
318 }
338 void scrollbar_size(int size) {
339 scrollbar_size_ = size;
340 }
348 int scrollbar_width() const {
349 return(Fl::scrollbar_size());
350 }
358 void scrollbar_width(int width) {
359 Fl::scrollbar_size(width);
360 scrollbar_size_ = 0;
361 }
366 void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); }
371 void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
372 void sort(int flags=0);
373};
374
375#endif
376
377//
378// End of "$Id: Fl_Browser_.H 8275 2011-01-13 22:07:31Z manolo $".
379//
const Fl_Align FL_ALIGN_RIGHT
Align the label to the right of the widget.
Definition: Enumerations.H:671
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:707
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:764
@ FL_DAMAGE_SCROLL
The Fl_Scroll widget was scrolled.
Definition: Enumerations.H:937
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:736
const Fl_Align FL_ALIGN_LEFT
Align the label at the left of the widget.
Definition: Enumerations.H:669
Fl static class.
This is the base class for browsers.
Definition: Fl_Browser_.H:67
void * top() const
Returns the item that appears at the top of the list.
Definition: Fl_Browser_.H:164
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.
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:112
Fl_Color textcolor() const
Gets the default text color for the lines in the browser.
Definition: Fl_Browser_.H:301
Fl_Font textfont() const
Gets the default text font for the lines in the browser.
Definition: Fl_Browser_.H:283
int scrollbar_width() const
This method has been deprecated, existing for backwards compatibility only.
Definition: Fl_Browser_.H:348
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.
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:154
Fl_Fontsize textsize() const
Gets the default text size (in pixels) for the lines in the browser.
Definition: Fl_Browser_.H:292
void scrollbar_width(int width)
This method has been deprecated, existing for backwards compatibility only.
Definition: Fl_Browser_.H:358
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:147
virtual int item_height(void *item) const =0
This method must be provided by the subclass to return the height of item in pixels.
uchar has_scrollbar() const
Returns the current scrollbar mode, see Fl_Browser_::has_scrollbar(uchar)
Definition: Fl_Browser_.H:254
void redraw_lines()
This method will cause the entire list to be redrawn.
Definition: Fl_Browser_.H:184
Fl_Scrollbar hscrollbar
Horizontal scrollbar.
Definition: Fl_Browser_.H:205
void * selection() const
Returns the item currently selected, or NULL if there is no selection.
Definition: Fl_Browser_.H:172
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition: Fl_Browser_.H:316
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.
void scrollbar_size(int size)
Sets the pixel size of the scrollbars' troughs to the size, in pixels.
Definition: Fl_Browser_.H:338
void scrollbar_right()
Moves the vertical scrollbar to the righthand side of the list.
Definition: Fl_Browser_.H:366
virtual void * item_first() const =0
This method must be provided by the subclass to return the first item in the list.
void has_scrollbar(uchar mode)
Sets whether the widget should have scrollbars or not (default Fl_Browser_::BOTH).
Definition: Fl_Browser_.H:277
Fl_Scrollbar scrollbar
Vertical scrollbar.
Definition: Fl_Browser_.H:201
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:305
void textsize(Fl_Fontsize size)
Sets the default text size (in pixels) for the lines in the browser to size.
Definition: Fl_Browser_.H:296
int hposition() const
Gets the horizontal scroll position of the list as a pixel position pos.
Definition: Fl_Browser_.H:229
void textfont(Fl_Font font)
Sets the default text font for the lines in the browser to font.
Definition: Fl_Browser_.H:287
int position() const
Gets the vertical scroll position of the list as a pixel position pos.
Definition: Fl_Browser_.H:220
void scrollbar_left()
Moves the vertical scrollbar to the lefthand side of the list.
Definition: Fl_Browser_.H:371
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:141
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:45
int handle(int)
Handles the specified event.
Definition: Fl_Group.cxx:150
void draw()
Draws the widget.
Definition: Fl_Group.cxx:742
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:637
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:52
Fl_Align align() const
Gets the label alignment.
Definition: Fl_Widget.H:346
void position(int X, int Y)
Repositions the window or widget.
Definition: Fl_Widget.H:330
fl_damage_t damage() const
Returns non-zero if draw() needs to be called.
Definition: Fl_Widget.H:890
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:339
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:151
unsigned char uchar
unsigned char
Definition: fl_types.h:39