FLTK 1.3.0
Fl_Browser.H
1 //
2 // "$Id: Fl_Browser.H 8623 2011-04-24 17:09:41Z AlbrechtS $"
3 //
4 // Browser header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2011 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 // Forms-compatible browser. Probably useful for other
32 // lists of textual data. Notice that the line numbers
33 // start from 1, and 0 means "no line".
34 
35 #ifndef Fl_Browser_H
36 #define Fl_Browser_H
37 
38 #include "Fl_Browser_.H"
39 #include "Fl_Image.H"
40 
41 struct FL_BLINE;
42 
89 class FL_EXPORT Fl_Browser : public Fl_Browser_ {
90 
91  FL_BLINE *first; // the array of lines
92  FL_BLINE *last;
93  FL_BLINE *cache;
94  int cacheline; // line number of cache
95  int lines; // Number of lines
96  int full_height_;
97  const int* column_widths_;
98  char format_char_; // alternative to @-sign
99  char column_char_; // alternative to tab
100 
101 protected:
102 
103  // required routines for Fl_Browser_ subclass:
104  void* item_first() const ;
105  void* item_next(void* item) const ;
106  void* item_prev(void* item) const ;
107  void* item_last()const ;
108  int item_selected(void* item) const ;
109  void item_select(void* item, int val);
110  int item_height(void* item) const ;
111  int item_width(void* item) const ;
112  void item_draw(void* item, int X, int Y, int W, int H) const ;
113  int full_height() const ;
114  int incr_height() const ;
115  const char *item_text(void *item) const;
121  void item_swap(void *a, void *b) { swap((FL_BLINE*)a, (FL_BLINE*)b); }
127  void *item_at(int line) const { return (void*)find_line(line); }
128 
129  FL_BLINE* find_line(int line) const ;
130  FL_BLINE* _remove(int line) ;
131  void insert(int line, FL_BLINE* item);
132  int lineno(void *item) const ;
133  void swap(FL_BLINE *a, FL_BLINE *b);
134 
135 public:
136 
137  void remove(int line);
138  void add(const char* newtext, void* d = 0);
139  void insert(int line, const char* newtext, void* d = 0);
140  void move(int to, int from);
141  int load(const char* filename);
142  void swap(int a, int b);
143  void clear();
144 
150  int size() const { return lines; }
151  void size(int W, int H) { Fl_Widget::size(W, H); }
152 
153  int topline() const ;
155  enum Fl_Line_Position { TOP, BOTTOM, MIDDLE };
156  void lineposition(int line, Fl_Line_Position pos);
163  void topline(int line) { lineposition(line, TOP); }
170  void bottomline(int line) { lineposition(line, BOTTOM); }
177  void middleline(int line) { lineposition(line, MIDDLE); }
178 
179  int select(int line, int val=1);
180  int selected(int line) const ;
181  void show(int line);
183  void show() { Fl_Widget::show(); }
184  void hide(int line);
186  void hide() { Fl_Widget::hide(); }
187  int visible(int line) const ;
188 
189  int value() const ;
195  void value(int line) { select(line); }
196  const char* text(int line) const ;
197  void text(int line, const char* newtext);
198  void* data(int line) const ;
199  void data(int line, void* d);
200 
201  Fl_Browser(int X, int Y, int W, int H, const char *L = 0);
206 
236  char format_char() const { return format_char_; }
242  void format_char(char c) { format_char_ = c; }
248  char column_char() const { return column_char_; }
255  void column_char(char c) { column_char_ = c; }
279  const int* column_widths() const { return column_widths_; }
284  void column_widths(const int* arr) { column_widths_ = arr; }
285 
295  int displayed(int line) const { return Fl_Browser_::displayed(find_line(line)); }
296 
304  void make_visible(int line) {
305  if (line < 1) Fl_Browser_::display(find_line(1));
306  else if (line > lines) Fl_Browser_::display(find_line(lines));
307  else Fl_Browser_::display(find_line(line));
308  }
309 
310  // icon support
311  void icon(int line, Fl_Image* icon);
312  Fl_Image* icon(int line) const;
313  void remove_icon(int line);
314 
316  void replace(int a, const char* b) { text(a, b); }
317  void display(int line, int val=1);
318 };
319 
320 #endif
321 
322 //
323 // End of "$Id: Fl_Browser.H 8623 2011-04-24 17:09:41Z AlbrechtS $".
324 //