FLTK 1.4.5: Fl_Browser_.H Source File

FLTK 1.4.5

Loading...
Searching...
No Matches
Fl_Browser_.H
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//
16
17/* \file
18 Fl_Browser_ widget . */
19
20// Yes, I know this should be a template...
21
22#ifndef Fl_Browser__H
23#define Fl_Browser__H
24
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()
30
31#define FL_NORMAL_BROWSER 0
32#define FL_SELECT_BROWSER 1
33#define FL_HOLD_BROWSER 2
34#define FL_MULTI_BROWSER 3
35
36#define FL_SORT_ASCENDING 0
37#define FL_SORT_DESCENDING 1
38#define FL_SORT_CASEINSENSITIVE 0x2
39
83 class FL_EXPORT Fl_Browser_ : public Fl_Group {
84 int position_; // where user wants it scrolled to
85 int real_position_; // the current vertical scrolling position
86 int hposition_; // where user wants it panned to
87 int real_hposition_; // the current horizontal scrolling position
88 int offset_; // how far down top_ item the real_position is
89 int max_width; // widest object seen so far
90 uchar has_scrollbar_; // which scrollbars are enabled
91 Fl_Font textfont_;
92 Fl_Fontsize textsize_;
93 Fl_Color textcolor_;
94 void* top_; // which item scrolling position is in
95 void* selection_; // which is selected (except for FL_MULTI_BROWSER)
96 void *redraw1,*redraw2; // minimal update pointers
97 void* max_width_item; // which item has max_width_
98 int scrollbar_size_; // size of scrollbar trough
99 int linespacing_;
100
101 void update_top();
102
103protected:
104
105 // All of the following must be supplied by the subclass:
111 virtual void *item_first() const = 0;
117 virtual void *item_next(void *item) const = 0;
123 virtual void *item_prev(void *item) const = 0;
129 virtual void *item_last() const { return 0L; }
138 virtual int item_height(void *item) const = 0;
146 virtual int item_width(void *item) const = 0;
147 virtual int item_quick_height(void *item) const ;
152 virtual void item_draw(void *item,int X,int Y,int W,int H) const = 0;
158 virtual const char *item_text(void *item) const { (void)item; return 0L; }
164 virtual void item_swap(void *a,void *b) { (void)a; (void)b; }
171 virtual void *item_at(int index) const { (void)index; return 0L; }
172 // you don't have to provide these but it may help speed it up:
173 virtual int full_width() const ; // current width of all items
174 virtual int full_height() const ; // current height of all items
175 virtual int incr_height() const ; // average height of an item
176 // These only need to be done by subclass if you want a multi-browser:
177 virtual void item_select(void *item,int val=1);
178 virtual int item_selected(void *item) const ;
179
180 // things the subclass may want to call:
184 void *top() const { return top_; }
192 void *selection() const { return selection_; }
193 void new_list(); // completely clobber all data, as though list replaced
194 void deleting(void *item); // get rid of any pointers to item
195 void replacing(void *a,void *b); // change a pointers to b
196 void swapping(void *a,void *b); // exchange pointers a and b
197 void inserting(void *a,void *b); // insert b near a
198 int displayed(void *item) const ; // true if this item is visible
199 void redraw_line(void *item); // minimal update, no change in size
204 void redraw_lines() { damage(FL_DAMAGE_SCROLL); } // redraw all of them
205 void bbox(int &X,int &Y,int &W,int &H) const;
206 int leftedge() const; // x position after scrollbar & border
207 void *find_item(int ypos); // item under mouse
208
209 void draw() FL_OVERRIDE;
210 Fl_Browser_(int X,int Y,int W,int H,const char *L=0);
211
212public:
213
229 Fl_Scrollbar scrollbar;
233 Fl_Scrollbar hscrollbar;
234
235 int handle(int event) FL_OVERRIDE;
236 void resize(int X,int Y,int W,int H) FL_OVERRIDE;
237
238 int select(void *item,int val=1,int docallbacks=0);
239 int select_only(void *item,int docallbacks=0);
240 int deselect(int docallbacks=0);
248 int vposition() const { return position_; }
249 FL_DEPRECATED("since 1.4.0 - use vposition() instead",
250 int position() const) { return vposition(); }
251
252 void vposition(int pos); // scroll to here
253 FL_DEPRECATED("since 1.4.0 - use vposition(pos) instead",
254 void position(int pos)) { return vposition(pos); }
255 void position(int x, int y) { Fl_Group::position(x, y); }
256
264 int hposition() const { return hposition_; }
265 void hposition(int); // pan to here
266 void display(void *item); // scroll so this item is shown
267
277 enum { // values for has_scrollbar()
278 HORIZONTAL = 1,
279 VERTICAL = 2,
280 BOTH = 3,
281 ALWAYS_ON = 4,
282 HORIZONTAL_ALWAYS = 5,
283 VERTICAL_ALWAYS = 6,
284 BOTH_ALWAYS = 7
285 };
289 uchar has_scrollbar() const { return has_scrollbar_; }
312 void has_scrollbar(uchar mode) { has_scrollbar_ = mode; }
313
318 Fl_Font textfont() const { return textfont_; }
322 void textfont(Fl_Font font) { textfont_ = font; }
323
327 Fl_Fontsize textsize() const { return textsize_; }
331 void textsize(Fl_Fontsize newSize) { textsize_ = newSize; }
332
336 Fl_Color textcolor() const { return textcolor_; }
340 void textcolor(Fl_Color col) { textcolor_ = col; }
341
351 int scrollbar_size() const {
352 return(scrollbar_size_);
353 }
354
373 void scrollbar_size(int newSize) {
374 scrollbar_size_ = newSize;
375 }
376
381 int scrollbar_width() const {
382 return(Fl::scrollbar_size());
383 }
384
389 void scrollbar_width(int width) {
390 Fl::scrollbar_size(width);
391 scrollbar_size_ = 0;
392 }
393
397 void scrollbar_right() { scrollbar.align(FL_ALIGN_RIGHT); }
402 void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
403 void sort(int flags=0);
404
409 void linespacing(int pixels) { linespacing_ = pixels; }
410
414 int linespacing() const { return linespacing_; }
415};
416
417#endif
FL_ALIGN_RIGHT
const Fl_Align FL_ALIGN_RIGHT
Align the label to the right of the widget.
Definition Enumerations.H:1004
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1063
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
FL_DAMAGE_SCROLL
@ FL_DAMAGE_SCROLL
The Fl_Scroll widget was scrolled.
Definition Enumerations.H:1343
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1092
FL_ALIGN_LEFT
const Fl_Align FL_ALIGN_LEFT
Align the label at the left of the widget.
Definition Enumerations.H:1001
Fl.H
Fl static class.
Fl_Group.H
Fl_Group and Fl_End classes.
Fl_Browser_
This is the base class for browsers.
Definition Fl_Browser_.H:83
Fl_Browser_::top
void * top() const
Returns the item that appears at the top of the list.
Definition Fl_Browser_.H:184
Fl_Browser_::vposition
int vposition() const
Gets the vertical scroll position of the list as a pixel position pos.
Definition Fl_Browser_.H:248
Fl_Browser_::item_next
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.
Fl_Browser_::item_last
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:129
Fl_Browser_::textcolor
Fl_Color textcolor() const
Gets the default text color for the lines in the browser.
Definition Fl_Browser_.H:336
Fl_Browser_::textfont
Fl_Font textfont() const
Gets the default text font for the lines in the browser.
Definition Fl_Browser_.H:318
Fl_Browser_::linespacing
int linespacing() const
Return the height of additional spacing between browser lines.
Definition Fl_Browser_.H:414
Fl_Browser_::scrollbar_width
int scrollbar_width() const
Returns the global value Fl::scrollbar_size().
Definition Fl_Browser_.H:381
Fl_Browser_::item_width
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_Browser_::item_at
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:171
Fl_Browser_::linespacing
void linespacing(int pixels)
Add some space between browser lines.
Definition Fl_Browser_.H:409
Fl_Browser_::textsize
Fl_Fontsize textsize() const
Gets the default text size (in pixels) for the lines in the browser.
Definition Fl_Browser_.H:327
Fl_Browser_::scrollbar_width
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:389
Fl_Browser_::item_swap
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:164
Fl_Browser_::item_height
virtual int item_height(void *item) const =0
This method must be provided by the subclass to return the height of item in pixels.
Fl_Browser_::scrollbar_size
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition Fl_Browser_.H:373
Fl_Browser_::has_scrollbar
uchar has_scrollbar() const
Returns the current scrollbar mode, see Fl_Browser_::has_scrollbar(uchar).
Definition Fl_Browser_.H:289
Fl_Browser_::select_only
int select_only(void *item, int docallbacks=0)
Selects item and returns 1 if the state changed or 0 if it did not.
Definition Fl_Browser_.cxx:671
Fl_Browser_::redraw_lines
void redraw_lines()
This method will cause the entire list to be redrawn.
Definition Fl_Browser_.H:204
Fl_Browser_::hscrollbar
Fl_Scrollbar hscrollbar
Horizontal scrollbar.
Definition Fl_Browser_.H:233
Fl_Browser_::selection
void * selection() const
Returns the item currently selected, or NULL if there is no selection.
Definition Fl_Browser_.H:192
Fl_Browser_::Fl_Browser_
Fl_Browser_(int X, int Y, int W, int H, const char *L=0)
The constructor makes an empty browser.
Definition Fl_Browser_.cxx:954
Fl_Browser_::scrollbar_size
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition Fl_Browser_.H:351
Fl_Browser_::resize
void resize(int X, int Y, int W, int H) FL_OVERRIDE
Repositions and/or resizes the browser.
Definition Fl_Browser_.cxx:104
Fl_Browser_::item_prev
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.
Fl_Browser_::scrollbar_right
void scrollbar_right()
Moves the vertical scrollbar to the righthand side of the list.
Definition Fl_Browser_.H:397
Fl_Browser_::item_first
virtual void * item_first() const =0
This method must be provided by the subclass to return the first item in the list.
Fl_Browser_::deselect
int deselect(int docallbacks=0)
Deselects all items in the list and returns 1 if the state changed or 0 if it did not.
Definition Fl_Browser_.cxx:649
Fl_Browser_::item_quick_height
virtual int item_quick_height(void *item) const
This method may be provided by the subclass to return the height of the item, in pixels.
Definition Fl_Browser_.cxx:1046
Fl_Browser_::has_scrollbar
void has_scrollbar(uchar mode)
Sets whether the widget should have scrollbars or not (default Fl_Browser_::BOTH).
Definition Fl_Browser_.H:312
Fl_Browser_::scrollbar
Fl_Scrollbar scrollbar
Vertical scrollbar.
Definition Fl_Browser_.H:229
Fl_Browser_::position
void position(int pos)
Definition Fl_Browser_.H:254
Fl_Browser_::item_draw
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,...
Fl_Browser_::textcolor
void textcolor(Fl_Color col)
Sets the default text color for the lines in the browser to color col.
Definition Fl_Browser_.H:340
Fl_Browser_::textsize
void textsize(Fl_Fontsize newSize)
Sets the default text size (in pixels) for the lines in the browser to size.
Definition Fl_Browser_.H:331
Fl_Browser_::handle
int handle(int event) FL_OVERRIDE
Handles the event within the normal widget bounding box.
Definition Fl_Browser_.cxx:692
Fl_Browser_::VERTICAL_ALWAYS
@ VERTICAL_ALWAYS
Vertical scrollbar always on.
Definition Fl_Browser_.H:283
Fl_Browser_::HORIZONTAL
@ HORIZONTAL
Only show horizontal scrollbar.
Definition Fl_Browser_.H:278
Fl_Browser_::ALWAYS_ON
@ ALWAYS_ON
Specified scrollbar(s) should 'always' be shown (to be used with HORIZONTAL/VERTICAL).
Definition Fl_Browser_.H:281
Fl_Browser_::BOTH_ALWAYS
@ BOTH_ALWAYS
Both scrollbars always on.
Definition Fl_Browser_.H:284
Fl_Browser_::HORIZONTAL_ALWAYS
@ HORIZONTAL_ALWAYS
Horizontal scrollbar always on.
Definition Fl_Browser_.H:282
Fl_Browser_::VERTICAL
@ VERTICAL
Only show vertical scrollbar.
Definition Fl_Browser_.H:279
Fl_Browser_::BOTH
@ BOTH
Show both scrollbars. (default).
Definition Fl_Browser_.H:280
Fl_Browser_::hposition
int hposition() const
Gets the horizontal scroll position of the list as a pixel position pos.
Definition Fl_Browser_.H:264
Fl_Browser_::textfont
void textfont(Fl_Font font)
Sets the default text font for the lines in the browser to font.
Definition Fl_Browser_.H:322
Fl_Browser_::position
int position() const
Definition Fl_Browser_.H:250
Fl_Browser_::select
int select(void *item, int val=1, int docallbacks=0)
Sets the selection state of item to val, and returns 1 if the state changed or 0 if it did not.
Definition Fl_Browser_.cxx:607
Fl_Browser_::scrollbar_left
void scrollbar_left()
Moves the vertical scrollbar to the lefthand side of the list.
Definition Fl_Browser_.H:402
Fl_Browser_::item_text
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:158
Fl_Group::draw
void draw() FL_OVERRIDE
Draws the widget.
Definition Fl_Group.cxx:943
Fl_Scrollbar
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition Fl_Scrollbar.H:41
Fl_Widget::position
void position(int X, int Y)
Repositions the window or widget.
Definition Fl_Widget.H:409
Fl_Widget::damage
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition Fl_Widget.H:1146
Fl::scrollbar_size
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:148
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
FL_DEPRECATED
#define FL_DEPRECATED(msg, func)
Enclosing a function or method in FL_DEPRECATED marks it as no longer recommended.
Definition fl_attr.h:57
uchar
unsigned char uchar
unsigned char
Definition fl_types.h:30