FLTK 1.3.5
Fl_Browser.H
1 //
2 // "$Id$"
3 //
4 // Browser header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2016 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 /* \file
20  Fl_Browser widget . */
21 
22 // Forms-compatible browser. Probably useful for other
23 // lists of textual data. Notice that the line numbers
24 // start from 1, and 0 means "no line".
25 
26 #ifndef Fl_Browser_H
27 #define Fl_Browser_H
28 
29 #include "Fl_Browser_.H"
30 #include "Fl_Image.H"
31 
32 struct FL_BLINE;
33 
80 class FL_EXPORT Fl_Browser : public Fl_Browser_ {
81 
82  FL_BLINE *first; // the array of lines
83  FL_BLINE *last;
84  FL_BLINE *cache;
85  int cacheline; // line number of cache
86  int lines; // Number of lines
87  int full_height_;
88  const int* column_widths_;
89  char format_char_; // alternative to @-sign
90  char column_char_; // alternative to tab
91 
92 protected:
93 
94  // required routines for Fl_Browser_ subclass:
95  void* item_first() const ;
96  void* item_next(void* item) const ;
97  void* item_prev(void* item) const ;
98  void* item_last()const ;
99  int item_selected(void* item) const ;
100  void item_select(void* item, int val);
101  int item_height(void* item) const ;
102  int item_width(void* item) const ;
103  void item_draw(void* item, int X, int Y, int W, int H) const ;
104  int full_height() const ;
105  int incr_height() const ;
106  const char *item_text(void *item) const;
112  void item_swap(void *a, void *b) { swap((FL_BLINE*)a, (FL_BLINE*)b); }
118  void *item_at(int line) const { return (void*)find_line(line); }
119 
120  FL_BLINE* find_line(int line) const ;
121  FL_BLINE* _remove(int line) ;
122  void insert(int line, FL_BLINE* item);
123  int lineno(void *item) const ;
124  void swap(FL_BLINE *a, FL_BLINE *b);
125 
126 public:
127 
128  void remove(int line);
129  void add(const char* newtext, void* d = 0);
130  void insert(int line, const char* newtext, void* d = 0);
131  void move(int to, int from);
132  int load(const char* filename);
133  void swap(int a, int b);
134  void clear();
135 
141  int size() const { return lines; }
142  void size(int W, int H) { Fl_Widget::size(W, H); }
143 
148 
149  /*
150  Sets the default text size for the lines in the browser to newSize.
151  Defined and documented in Fl_Browser.cxx
152  */
153  void textsize(Fl_Fontsize newSize);
154 
155  int topline() const ;
157  enum Fl_Line_Position { TOP, BOTTOM, MIDDLE };
158  void lineposition(int line, Fl_Line_Position pos);
165  void topline(int line) { lineposition(line, TOP); }
172  void bottomline(int line) { lineposition(line, BOTTOM); }
179  void middleline(int line) { lineposition(line, MIDDLE); }
180 
181  int select(int line, int val=1);
182  int selected(int line) const ;
183  void show(int line);
185  void show() { Fl_Widget::show(); }
186  void hide(int line);
188  void hide() { Fl_Widget::hide(); }
189  int visible(int line) const ;
190 
191  int value() const ;
197  void value(int line) { select(line); }
198  const char* text(int line) const ;
199  void text(int line, const char* newtext);
200  void* data(int line) const ;
201  void data(int line, void* d);
202 
203  Fl_Browser(int X, int Y, int W, int H, const char *L = 0);
208 
238  char format_char() const { return format_char_; }
244  void format_char(char c) { format_char_ = c; }
250  char column_char() const { return column_char_; }
257  void column_char(char c) { column_char_ = c; }
281  const int* column_widths() const { return column_widths_; }
286  void column_widths(const int* arr) { column_widths_ = arr; }
287 
297  int displayed(int line) const { return Fl_Browser_::displayed(find_line(line)); }
298 
306  void make_visible(int line) {
307  if (line < 1) Fl_Browser_::display(find_line(1));
308  else if (line > lines) Fl_Browser_::display(find_line(lines));
309  else Fl_Browser_::display(find_line(line));
310  }
311 
312  // icon support
313  void icon(int line, Fl_Image* icon);
314  Fl_Image* icon(int line) const;
315  void remove_icon(int line);
316 
318  void replace(int a, const char* b) { text(a, b); }
319  void display(int line, int val=1);
320 };
321 
322 #endif
323 
324 //
325 // End of "$Id$".
326 //