summaryrefslogtreecommitdiff
path: root/FL/Fl_Browser_.H
blob: f8ee3ca1cd5cf1e73fc9d484b79b563299572792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//
// "$Id$"
//
// Common browser header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2005 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//

// This is the base class for browsers.  To be useful it must
// be subclassed and several virtual functions defined.  The
// Forms-compatable browser and the file chooser's browser are
// subclassed off of this.

// Yes, I know this should be a template...

#ifndef Fl_Browser__H
#define Fl_Browser__H

#ifndef Fl_Group_H
#include "Fl_Group.H"
#endif
#include "Fl_Scrollbar.H"

#define FL_NORMAL_BROWSER	0
#define FL_SELECT_BROWSER	1
#define FL_HOLD_BROWSER		2
#define FL_MULTI_BROWSER	3

/**
  This is the base for browsers.  To be useful it must be
  subclassed and several virtual functions defined.  The Forms-compatible
  browser and the file chooser's browser are subclassed off of this.
  <P>This has been designed so that the subhas complete control
  over the storage of the data, although because next() and 
  prev() functions are used to index, it works best as a linked list
  or as a large block of characters in which the line breaks must be
  searched for. </P>
  <P>A great deal of work has been done so that the &quot;height&quot; of a data
  object does not need to be determined until it is drawn.  This is
  useful if actually figuring out the size of an object requires
  accessing image data or doing stat() on a file or doing some
  other slow operation.
*/
class FL_EXPORT Fl_Browser_ : public Fl_Group {
  int position_;	// where user wants it scrolled to
  int real_position_;	// the current vertical scrolling position
  int hposition_;	// where user wants it panned to
  int real_hposition_;	// the current horizontal scrolling position
  int offset_;		// how far down top_ item the real_position is
  int max_width;	// widest object seen so far
  uchar has_scrollbar_;	// which scrollbars are enabled
  Fl_Font textfont_;
  Fl_Fontsize textsize_;
  unsigned textcolor_;
  void* top_;		// which item scrolling position is in
  void* selection_;	// which is selected (except for FL_MULTI_BROWSER)
  void *redraw1,*redraw2; // minimal update pointers
  void* max_width_item;	// which item has max_width_

  static int scrollbar_width_;

  void update_top();

protected:

  // All of the following must be supplied by the subclass:
  /** This method must be provided by the subclass to return the first item in  the list. */
    virtual void *item_first() const = 0;
  /** This method must be provided by the subclass to return the item in the list after p. */
    virtual void *item_next(void *) const = 0;
  /** This method must be provided by the subclass to return the item in the list before p. */
    virtual void *item_prev(void *) const = 0;
  /** 
    This method must be provided by the subclass to return the height of the
    item p in pixels.  Allow for two additional pixels for the list
    selection box.
  */
  virtual int item_height(void *) const = 0;
  /**
    This method must be provided by the subclass to return the width of the
    item p in pixels.  Allow for two additional pixels for the list
    selection box.
  */
  virtual int item_width(void *) const = 0;
  virtual int item_quick_height(void *) const ;
  /**
    This method must be provided by the subclass to draw the item
    p in the area indicated by x, y, w,
    and h.
  */
  virtual void item_draw(void *,int,int,int,int) const = 0;
  // you don't have to provide these but it may help speed it up:
  virtual int full_width() const ;	// current width of all items
  virtual int full_height() const ;	// current height of all items
  virtual int incr_height() const ;	// average height of an item
  // These only need to be done by subclass if you want a multi-browser:
  virtual void item_select(void *,int=1);
  virtual int item_selected(void *) const ;

  // things the subclass may want to call:
  /**  Returns the item the appears at the top of the list.  */
  void *top() const {return top_;}
  /**
    Returns the item currently selected, or NULL if there is no selection.
    
    <P>For multiple selection browsers this call returns the currently focused item,
    even if it is not selected. To find all selected items, call 
    
    Fl_Multi_Browser::selected() for every item in question.
  */
  void *selection() const {return selection_;}
  void new_list(); // completely clobber all data, as though list replaced
  void deleting(void *a); // get rid of any pointers to a
  void replacing(void *a,void *b); // change a pointers to b
  void swapping(void *a,void *b); // exchange pointers a and b
  void inserting(void *a,void *b); // insert b near a
  int displayed(void *) const ; // true if this line is visible
  void redraw_line(void *); // minimal update, no change in size
  /**    This method will cause the entire list to be redrawn.  */
  void redraw_lines() {damage(FL_DAMAGE_SCROLL);} // redraw all of them
  void bbox(int&,int&,int&,int&) const;
  int leftedge() const;	// x position after scrollbar & border
  void *find_item(int my); // item under mouse
  /**
    The first form draws the list within the normal widget bounding box.
    
    <P>The second form draws the contents of the browser within the
    specified bounding box.
  */
  void draw(int,int,int,int);
  int handle(int,int,int,int,int);

  void draw();
  Fl_Browser_(int,int,int,int,const char * = 0);

public:

  Fl_Scrollbar scrollbar;		// Vertical scrollbar
  Fl_Scrollbar hscrollbar;		// Horizontal scrollbar

  int handle(int);
  void resize(int,int,int,int);

  int select(void *,int=1,int docallbacks=0);
  int select_only(void *,int docallbacks=0);
  int deselect(int docallbacks=0);
  /**
    Gets or sets the vertical scrolling position of the list,
    which is the pixel offset of the list items within the list
    area.
  */
  int position() const {return position_;}
  /**
    Gets or sets the horizontal scrolling position of the list,
    which is the pixel offset of the list items within the list
    area.
  */
  int hposition() const {return hposition_;}
  void position(int); // scroll to here
  void hposition(int); // pan to here
  void display(void*); // scroll so this item is shown
  /** See Fl_Browser_::has_scrollbar(uchar) */
  uchar has_scrollbar() const {return has_scrollbar_;}
  /**
    By default you can scroll in both directions, and the scrollbars
    disappear if the data will fit in the widget.  has_scrollbar() changes
    this based on the value of h:
  
    <UL>
  
  	<LI>0 - No scrollbars.
  
  	<LI>Fl_Browser_::HORIZONTAL - Only a horizontal
  	scrollbar.
  
  	<LI>Fl_Browser_::VERTICAL - Only a vertical
  	scrollbar.
  
  	<LI>Fl_Browser_::BOTH - The default is both
  	scrollbars.
  
  	<LI>Fl_Browser_::HORIZONTAL_ALWAYS - Horizontal
  	scrollbar always on, vertical always off.
  
  	<LI>Fl_Browser_::VERTICAL_ALWAYS - Vertical
  	scrollbar always on, horizontal always off.
  
  	<LI>Fl_Browser_::BOTH_ALWAYS - Both always on.
  
    </UL>
  */
  void has_scrollbar(uchar i) {has_scrollbar_ = i;}
  enum { // values for has_scrollbar()
    HORIZONTAL = 1,
    VERTICAL = 2,
    BOTH = 3,
    ALWAYS_ON = 4,
    HORIZONTAL_ALWAYS = 5,
    VERTICAL_ALWAYS = 6,
    BOTH_ALWAYS = 7
  };

  /**
    The first form gets the default text font for the lines in the
    browser.
    
    <P>The second form sets the default text font to font
  */
  Fl_Font textfont() const {return textfont_;}
  /**
    The first form gets the default text font for the lines in the
    browser.
    
    <P>The second form sets the default text font to font
  */
  void textfont(Fl_Font s) {textfont_ = s;}
  /**
    The first form gets the default text size for the lines in the
    browser.
    
    <P>The second form sets the default text size to size
  */
  Fl_Fontsize textsize() const {return textsize_;}
  void textsize(Fl_Fontsize s) {textsize_ = s;}
  /**
    The first form gets the default text color for the lines in the
    browser.
    
    <P>The second form sets the default text color to color
  */
  Fl_Color textcolor() const {return (Fl_Color)textcolor_;}
  void textcolor(unsigned n) {textcolor_ = n;}

  /**    Sets or gets the width of any scrollbars that are used.  */
  static void scrollbar_width(int b) {scrollbar_width_ = b;}
  /**    Sets or gets the width of any scrollbars that are used.  */
  static int scrollbar_width() {return scrollbar_width_;}

  // for back compatability:
  /**    This method moves the vertical scrollbar to the righthand side of the list.  */
  void scrollbar_right() {scrollbar.align(FL_ALIGN_RIGHT);}
  /**    This method moves the vertical scrollbar to the lefthand side of the list.  */
  void scrollbar_left() {scrollbar.align(FL_ALIGN_LEFT);}

};

#endif

//
// End of "$Id$".
//