1 | // |
---|
2 | // "$Id: Browser.h 4368 2005-05-24 04:35:49Z spitzak $" |
---|
3 | // |
---|
4 | // Copyright 2002 by Bill Spitzak and others. |
---|
5 | // |
---|
6 | // This library is free software; you can redistribute it and/or |
---|
7 | // modify it under the terms of the GNU Library General Public |
---|
8 | // License as published by the Free Software Foundation; either |
---|
9 | // version 2 of the License, or (at your option) any later version. |
---|
10 | // |
---|
11 | // This library is distributed in the hope that it will be useful, |
---|
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | // Library General Public License for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU Library General Public |
---|
17 | // License along with this library; if not, write to the Free Software |
---|
18 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
19 | // USA. |
---|
20 | // |
---|
21 | // Please report all bugs and problems to "fltk-bugs@fltk.org". |
---|
22 | // |
---|
23 | |
---|
24 | #ifndef fltk_Browser_h |
---|
25 | #define fltk_Browser_h |
---|
26 | |
---|
27 | #include "Menu.h" |
---|
28 | #include "Scrollbar.h" |
---|
29 | |
---|
30 | namespace fltk { |
---|
31 | |
---|
32 | class FL_API Browser : public Menu { |
---|
33 | public: |
---|
34 | |
---|
35 | int handle(int); |
---|
36 | void layout(); |
---|
37 | void draw(); |
---|
38 | |
---|
39 | Browser(int X,int Y,int W,int H,const char*l=0); |
---|
40 | static NamedStyle* default_style; |
---|
41 | ~Browser(); |
---|
42 | |
---|
43 | enum { // values for type() |
---|
44 | NORMAL = 0, |
---|
45 | MULTI = 1 |
---|
46 | }; |
---|
47 | |
---|
48 | int width() const {return width_;} |
---|
49 | int height() const {return height_;} |
---|
50 | int box_width() const {return interior.w();} |
---|
51 | int box_height() const {return interior.h();} |
---|
52 | int xposition() const {return xposition_;} |
---|
53 | void xposition(int); |
---|
54 | int yposition() const {return yposition_;} |
---|
55 | void yposition(int); |
---|
56 | bool indented() const {return indented_;} |
---|
57 | void indented(bool v) {indented_ = v;} |
---|
58 | |
---|
59 | Scrollbar scrollbar; |
---|
60 | Scrollbar hscrollbar; |
---|
61 | |
---|
62 | Widget* goto_top(); |
---|
63 | Widget* goto_focus() {return goto_mark(FOCUS);} |
---|
64 | Widget* goto_position(int y); |
---|
65 | Widget* goto_index(const int* indexes, int level); |
---|
66 | Widget* goto_index(int); |
---|
67 | Widget* goto_index(int,int,int=-1,int=-1,int=-1); |
---|
68 | Widget* next(); |
---|
69 | Widget* next_visible(); |
---|
70 | Widget* previous_visible(); |
---|
71 | bool item_is_visible() const; |
---|
72 | bool item_is_parent() const; |
---|
73 | bool item_is_open() const; |
---|
74 | int item_h() const; |
---|
75 | |
---|
76 | bool set_focus(); |
---|
77 | bool set_item_selected(bool value = true, int do_callback = 0); |
---|
78 | bool select_only_this(int do_callback = 0); |
---|
79 | bool deselect(int do_callback = 0); |
---|
80 | enum linepos { NOSCROLL, TOP, MIDDLE, BOTTOM }; |
---|
81 | bool make_item_visible(linepos = NOSCROLL); |
---|
82 | void damage_item() {damage_item(HERE);} |
---|
83 | bool set_item_opened(bool); |
---|
84 | bool set_item_visible(bool); |
---|
85 | |
---|
86 | int current_level() const {return item_level[HERE];} |
---|
87 | const int* current_index() const {return item_index[HERE];} |
---|
88 | int current_position() const {return item_position[HERE];} |
---|
89 | |
---|
90 | int focus_level() const {return item_level[FOCUS];} |
---|
91 | const int* focus_index() const {return item_index[FOCUS];} |
---|
92 | int focus_position() const {return item_position[FOCUS];} |
---|
93 | void value(int v) {goto_index(v); set_focus();} |
---|
94 | int value() const {return focus_index()[0];} |
---|
95 | |
---|
96 | // Maybe these should be moved to base Menu class: |
---|
97 | const int *column_widths() const { return column_widths_p; } |
---|
98 | void column_widths(const int *pWidths); |
---|
99 | const char **column_labels() const { return column_labels_; } |
---|
100 | void column_labels(const char **pLabels); |
---|
101 | int selected_column() { return selected_column_; } |
---|
102 | int set_column_start(int column, int x); |
---|
103 | |
---|
104 | // Convienence functions for flat browsers: |
---|
105 | bool select(int line, bool value = true); |
---|
106 | bool selected(int line); |
---|
107 | int topline() const {return item_index[FIRST_VISIBLE][0];} |
---|
108 | void topline(int line) {goto_index(line); make_item_visible(TOP);} |
---|
109 | void bottomline(int line) {goto_index(line); make_item_visible(BOTTOM);} |
---|
110 | void middleline(int line) {goto_index(line); make_item_visible();} |
---|
111 | bool displayed(int line); |
---|
112 | bool display(int line, bool value = true); |
---|
113 | |
---|
114 | Widget *header(int col) { if(col<0 || col>=nHeader) return 0; return header_[col]; } |
---|
115 | int nheader() const { return nHeader; } |
---|
116 | |
---|
117 | int load(const char *filename); |
---|
118 | |
---|
119 | private: |
---|
120 | |
---|
121 | bool indented_; |
---|
122 | const int *column_widths_; // original column widths |
---|
123 | int *column_widths_i; // original column widths after user interaction |
---|
124 | int *column_widths_p; // actual column widths |
---|
125 | const char **column_labels_; |
---|
126 | int xposition_, yposition_; |
---|
127 | int width_, height_; |
---|
128 | int scrolldx, scrolldy; |
---|
129 | static void hscrollbar_cb(Widget*, void*); |
---|
130 | static void scrollbar_cb(Widget*, void*); |
---|
131 | void draw_item(int); |
---|
132 | void draw_clip(const Rectangle&); |
---|
133 | static void draw_clip_cb(void*,const Rectangle&); |
---|
134 | Rectangle interior; // inside box edges and scrollbars |
---|
135 | |
---|
136 | Widget **header_; |
---|
137 | int nHeader, nColumn, selected_column_; |
---|
138 | |
---|
139 | int multi() const {return type()&MULTI;} |
---|
140 | |
---|
141 | // Marks serve as "indexes" into the hierarchial browser. We probably |
---|
142 | // need to make some sort of public interface but I have not figured |
---|
143 | // it out completely. |
---|
144 | enum { // predefined marks |
---|
145 | HERE = 0, // current item, the one moved by all the calls |
---|
146 | FOCUS, // what the user thinks is the curren item |
---|
147 | FIRST_VISIBLE, // item at top of scroll region |
---|
148 | REDRAW_0, // item that needs to be redrawn |
---|
149 | REDRAW_1, // a second item that needs to be redrawn |
---|
150 | OPEN, // this and all parents are open |
---|
151 | TEMP, // scratch space |
---|
152 | TEMP2, // scratch space, currently unused |
---|
153 | NUMMARKS |
---|
154 | }; |
---|
155 | Widget* goto_mark(int mark); // set HERE to mark |
---|
156 | Widget* goto_visible_focus(); // set HERE to focus if visible |
---|
157 | void set_mark(int dest, int mark); // set dest to mark |
---|
158 | int compare_marks(int mark1, int mark2); // returns >0 if mark1 after mark2 |
---|
159 | bool at_mark(int mark) { return !compare_marks(HERE,mark); } |
---|
160 | void unset_mark(int mark); // makes mark have illegal value |
---|
161 | bool is_set(int mark); // false if unset_mark was called |
---|
162 | void damage_item(int mark); // make this item redraw |
---|
163 | int siblings; // # of children of parent of HERE item |
---|
164 | |
---|
165 | // For each mark: |
---|
166 | unsigned char item_level[NUMMARKS]; // depth in hierarchy of the item |
---|
167 | unsigned char open_level[NUMMARKS]; // depth of highest closed parent |
---|
168 | int item_position[NUMMARKS]; // distance in pixels from top of browser |
---|
169 | int* item_index[NUMMARKS]; // indexes at each level of hierarchy |
---|
170 | int levels; // maximum depth of all items encountered so far |
---|
171 | void set_level(int); // increases levels by reallocating the arrays |
---|
172 | |
---|
173 | static void column_click_cb_(Widget*, void*); |
---|
174 | }; |
---|
175 | |
---|
176 | } |
---|
177 | |
---|
178 | #endif |
---|
179 | |
---|
180 | // |
---|
181 | // End of "$Id: Browser.h 4368 2005-05-24 04:35:49Z spitzak $". |
---|
182 | // |
---|