NTK 1.3.0
Fl_Tree_Item.H
Go to the documentation of this file.
1//
2// "$Id: Fl_Tree_Item.H 8340 2011-01-30 20:22:06Z greg.ercolano $"
3//
4
5#ifndef FL_TREE_ITEM_H
6#define FL_TREE_ITEM_H
7
8#include <FL/Fl.H>
9#include <FL/Fl_Widget.H>
10#include <FL/Fl_Image.H>
11#include <FL/fl_draw.H>
12
14#include <FL/Fl_Tree_Prefs.H>
15
17// FL/Fl_Tree_Item.H
19//
20// Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
21// Copyright (C) 2009-2010 by Greg Ercolano.
22//
23// This library is free software; you can redistribute it and/or
24// modify it under the terms of the GNU Library General Public
25// License as published by the Free Software Foundation; either
26// version 2 of the License, or (at your option) any later version.
27//
28// This library is distributed in the hope that it will be useful,
29// but WITHOUT ANY WARRANTY; without even the implied warranty of
30// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31// Library General Public License for more details.
32//
33// You should have received a copy of the GNU Library General Public
34// License along with this library; if not, write to the Free Software
35// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
36// USA.
37//
38
43
59class FL_EXPORT Fl_Tree_Item {
60 const char *_label; // label (memory managed)
61 Fl_Font _labelfont; // label's font face
62 Fl_Fontsize _labelsize; // label's font size
63 Fl_Color _labelfgcolor; // label's fg color
64 Fl_Color _labelbgcolor; // label's bg color
65 char _open; // item is open?
66 char _visible; // item is visible?
67 char _active; // item activated?
68 char _selected; // item selected?
69 int _xywh[4]; // xywh of this widget (if visible)
70 int _collapse_xywh[4]; // xywh of collapse icon (if any)
71 int _label_xywh[4]; // xywh of label
72 Fl_Widget *_widget; // item's label widget (optional)
73 Fl_Image *_usericon; // item's user-specific icon (optional)
74 Fl_Tree_Item_Array _children; // array of child items
75 Fl_Tree_Item *_parent; // parent item (=0 if root)
76 void *_userdata; // user data that can be associated with an item
77protected:
78 void show_widgets();
79 void hide_widgets();
80 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
81 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
82public:
83 Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR
84 ~Fl_Tree_Item(); // DTOR
85 Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR
86 int x() const { return(_xywh[0]); }
87 int y() const { return(_xywh[1]); }
88 int w() const { return(_xywh[2]); }
89 int h() const { return(_xywh[3]); }
90 void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1);
91 void show_self(const char *indent = "") const;
92 void label(const char *val);
93 const char *label() const;
94
96 inline void user_data( void* data ) { _userdata = data; }
97
99 inline void* user_data() const { return _userdata; }
100
102 void labelfont(Fl_Font val) {
103 _labelfont = val;
104 }
105
107 return(_labelfont);
108 }
109
111 _labelsize = val;
112 }
113
115 return(_labelsize);
116 }
117
119 _labelfgcolor = val;
120 }
121
123 _labelfgcolor = val;
124 }
125
127 return(_labelfgcolor);
128 }
129
131 return(_labelfgcolor);
132 }
133
135 _labelbgcolor = val;
136 }
137
139 return(_labelbgcolor);
140 }
141
142 void widget(Fl_Widget *val) {
143 _widget = val;
144 }
145
146 Fl_Widget *widget() const {
147 return(_widget);
148 }
149
150 int children() const {
151 return(_children.total());
152 }
153
154 Fl_Tree_Item *child(int index) {
155 return(_children[index]);
156 }
157
158 const Fl_Tree_Item *child(int t) const;
160 int has_children() const {
161 return(children());
162 }
163 int find_child(const char *name);
164 int find_child(Fl_Tree_Item *item);
165 int remove_child(Fl_Tree_Item *item);
166 int remove_child(const char *new_label);
167 void clear_children();
168 void swap_children(int ax, int bx);
169 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
170 const Fl_Tree_Item *find_child_item(char **arr) const; // const
171 Fl_Tree_Item *find_child_item(char **arr); // non-const
172 const Fl_Tree_Item *find_item(char **arr) const; // const
173 Fl_Tree_Item *find_item(char **arr); // non-const
175 // Adding items
177 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, const char *new_label);
178 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, char **arr);
179 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
180 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
181 int depth() const;
182 Fl_Tree_Item *prev();
183 Fl_Tree_Item *next();
184 Fl_Tree_Item *next_sibling();
185 Fl_Tree_Item *prev_sibling();
186 Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs);
187 Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs);
188
191 return(_parent);
192 }
193
194 const Fl_Tree_Item *parent() const {
195 return(_parent);
196 }
197
200 void parent(Fl_Tree_Item *val) {
201 _parent = val;
202 }
203
204 // State
206 void open();
207 void close();
209 int is_open() const {
210 return(_open?1:0);
211 }
212
213 int is_close() const {
214 return(_open?0:1);
215 }
216
217 void open_toggle() {
218 _open?close():open();
219 }
220
223 void select(int val=1) {
224 _selected = val;
225 }
226
228 if ( is_selected() ) {
229 deselect(); // deselect if selected
230 } else {
231 select(); // select if deselected
232 }
233 }
234
239 int count = 0;
240 if ( ! is_selected() ) {
241 select();
242 ++count;
243 }
244 for ( int t=0; t<children(); t++ ) {
245 count += child(t)->select_all();
246 }
247 return(count);
248 }
249
250 void deselect() {
251 _selected = 0;
252 }
253
258 int count = 0;
259 if ( is_selected() ) {
260 deselect();
261 ++count;
262 }
263 for ( int t=0; t<children(); t++ ) {
264 count += child(t)->deselect_all();
265 }
266 return(count);
267 }
268
269 char is_selected() const {
270 return(_selected);
271 }
272
281 void activate(int val=1) {
282 _active = val;
283 if ( _widget && val != (int)_widget->active() ) {
284 if ( val ) {
285 _widget->activate();
286 } else {
287 _widget->deactivate();
288 }
289 _widget->redraw();
290 }
291 }
292
295 void deactivate() {
296 activate(0);
297 }
298
299 char is_activated() const {
300 return(_active);
301 }
302
303 char is_active() const {
304 return(_active);
305 }
306
307 int visible() const {
308 return(_visible ? 1 : 0);
309 }
310 int visible_r() const;
311
313 void usericon(Fl_Image *val) {
314 _usericon = val;
315 }
316
318 return(_usericon);
319 }
320
321 // Events
323 const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs) const;
324 Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs);
325 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
326 int event_on_label(const Fl_Tree_Prefs &prefs) const;
328 int is_root() const {
329 return(_parent==0?1:0);
330 }
331};
332
333#endif /*FL_TREE_ITEM_H*/
334
335//
336// End of "$Id: Fl_Tree_Item.H 8340 2011-01-30 20:22:06Z greg.ercolano $".
337//
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:707
unsigned int Fl_Color
an FLTK color value
Definition Enumerations.H:764
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:736
Fl static class.
This file defines a class that manages an array of Fl_Tree_Item pointers.
This file contains the definitions for Fl_Tree's preferences.
Fl_Widget, Fl_Label classes .
Fl_Image is the base class used for caching and drawing all kinds of images in FLTK.
Definition Fl_Image.H:51
Manages an array of Fl_Tree_Item pointers.
Definition Fl_Tree_Item_Array.H:51
Tree item.
Definition Fl_Tree_Item.H:59
int has_children() const
See if this item has children.
Definition Fl_Tree_Item.H:160
void usericon(Fl_Image *val)
Set the user icon's image. '0' will disable.
Definition Fl_Tree_Item.H:313
int visible() const
See if the item is visible.
Definition Fl_Tree_Item.H:307
void label(const char *val)
Set the label. Makes a copy of the name.
Definition Fl_Tree_Item.cxx:131
void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1)
Draw this item and its children.
Definition Fl_Tree_Item.cxx:551
void deactivate()
Deactivate the item; the callback() won't be invoked when clicked.
Definition Fl_Tree_Item.H:295
void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs)
Internal: Horizontal connector line based on preference settings.
Definition Fl_Tree_Item.cxx:408
Fl_Widget * widget() const
Return FLTK widget assigned to this item.
Definition Fl_Tree_Item.H:146
void deselect()
Disable the item's selection state.
Definition Fl_Tree_Item.H:250
void open_toggle()
Toggle the item's open/closed state.
Definition Fl_Tree_Item.H:217
void hide_widgets()
Internal: Hide the FLTK widget() for this item and all children.
Definition Fl_Tree_Item.cxx:736
Fl_Tree_Item * parent()
Return the parent for this item. Returns NULL if we are the root.
Definition Fl_Tree_Item.H:190
void open()
Open this item and all its children.
Definition Fl_Tree_Item.cxx:744
Fl_Tree_Item * child(int index)
Return the child item for the given 'index'.
Definition Fl_Tree_Item.H:154
int select_all()
Select self and all children Returns count of how many items were in the 'deselected' state,...
Definition Fl_Tree_Item.H:238
Fl_Color labelfgcolor() const
Return item's label foreground text color.
Definition Fl_Tree_Item.H:130
int is_close() const
See if the item is 'closed'.
Definition Fl_Tree_Item.H:213
void labelsize(Fl_Fontsize val)
Set item's label font size.
Definition Fl_Tree_Item.H:110
void user_data(void *data)
Set a user-data value for the item.
Definition Fl_Tree_Item.H:96
Fl_Tree_Item(const Fl_Tree_Prefs &prefs)
Constructor.
Definition Fl_Tree_Item.cxx:43
void * user_data() const
Retrieve the user-data value that has been assigned to the item.
Definition Fl_Tree_Item.H:99
void select(int val=1)
Change the item's selection state to the optionally specified 'val'.
Definition Fl_Tree_Item.H:223
void show_widgets()
Internal: Show the FLTK widget() for this item and all children.
Definition Fl_Tree_Item.cxx:724
void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs)
Internal: Vertical connector line based on preference settings.
Definition Fl_Tree_Item.cxx:429
const Fl_Tree_Item * parent() const
Return the const parent for this item. Returns NULL if we are the root.
Definition Fl_Tree_Item.H:194
Fl_Color labelbgcolor() const
Return item's background text color.
Definition Fl_Tree_Item.H:138
char is_selected() const
See if the item is selected.
Definition Fl_Tree_Item.H:269
Fl_Color labelcolor() const
Return item's label text color.
Definition Fl_Tree_Item.H:126
void close()
Close this item and all its children.
Definition Fl_Tree_Item.cxx:753
void labelfont(Fl_Font val)
Set item's label font face.
Definition Fl_Tree_Item.H:102
Fl_Font labelfont() const
Get item's label font face.
Definition Fl_Tree_Item.H:106
void select_toggle()
Toggle the item's selection state.
Definition Fl_Tree_Item.H:227
void labelcolor(Fl_Color val)
Set item's label text color.
Definition Fl_Tree_Item.H:122
void activate(int val=1)
Change the item's activation state to the optionally specified 'val'.
Definition Fl_Tree_Item.H:281
int is_open() const
See if the item is 'open'.
Definition Fl_Tree_Item.H:209
int is_root() const
Is this item the root of the tree?
Definition Fl_Tree_Item.H:328
Fl_Fontsize labelsize() const
Get item's label font size.
Definition Fl_Tree_Item.H:114
void widget(Fl_Widget *val)
Assign an FLTK widget to this item.
Definition Fl_Tree_Item.H:142
void parent(Fl_Tree_Item *val)
Set the parent for this item.
Definition Fl_Tree_Item.H:200
char is_active() const
See if the item is activated.
Definition Fl_Tree_Item.H:303
int children() const
Return the number of children this item has.
Definition Fl_Tree_Item.H:150
void labelfgcolor(Fl_Color val)
Set item's label foreground text color.
Definition Fl_Tree_Item.H:118
void show_self(const char *indent="") const
Print the tree as 'ascii art' to stdout.
Definition Fl_Tree_Item.cxx:114
char is_activated() const
See if the item is activated.
Definition Fl_Tree_Item.H:299
void labelbgcolor(Fl_Color val)
Set item's label background color.
Definition Fl_Tree_Item.H:134
int deselect_all()
Deselect self and all children Returns count of how many items were in the 'selected' state,...
Definition Fl_Tree_Item.H:257
Fl_Image * usericon() const
Get the user icon. Returns '0' if disabled.
Definition Fl_Tree_Item.H:317
Tree widget's preferences.
Definition Fl_Tree_Prefs.H:85
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:111
utility header to pull drawing functions together