FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Tree_Item.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Tree_Item.H 9706 2012-11-06 20:46:14Z matt $"
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
13 #include <FL/Fl_Tree_Item_Array.H>
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. Distribution and use rights are outlined in
24 // the file "COPYING" which should have been included with this file. If this
25 // file is missing or damaged, see the license at:
26 //
27 // http://www.fltk.org/COPYING.php
28 //
29 // Please report all bugs and problems on the following page:
30 //
31 // http://www.fltk.org/str.php
32 //
33
38
54 class FL_EXPORT Fl_Tree_Item {
55 const char *_label; // label (memory managed)
56 Fl_Font _labelfont; // label's font face
57 Fl_Fontsize _labelsize; // label's font size
58 Fl_Color _labelfgcolor; // label's fg color
59 Fl_Color _labelbgcolor; // label's bg color (0xffffffff is 'transparent')
60 enum {
61 OPEN = 1<<0,
62 VISIBLE = 1<<1,
63 ACTIVE = 1<<2,
64 SELECTED = 1<<3,
65 };
66 #if FLTK_ABI_VERSION >= 10301
67 // NEW
68 unsigned short _flags; // misc flags
69 #else /*FLTK_ABI_VERSION*/
70 // OLD: this will go away after 1.3.x
71 char _open; // item is open?
72 char _visible; // item is visible?
73 char _active; // item activated?
74 char _selected; // item selected?
75 #endif /*FLTK_ABI_VERSION*/
76 int _xywh[4]; // xywh of this widget (if visible)
77 int _collapse_xywh[4]; // xywh of collapse icon (if visible)
78 int _label_xywh[4]; // xywh of label
79 Fl_Widget *_widget; // item's label widget (optional)
80 Fl_Image *_usericon; // item's user-specific icon (optional)
81 Fl_Tree_Item_Array _children; // array of child items
82 Fl_Tree_Item *_parent; // parent item (=0 if root)
83 void *_userdata; // user data that can be associated with an item
84 #if FLTK_ABI_VERSION >= 10301
85 Fl_Tree_Item *_prev_sibling; // previous sibling (same level)
86 Fl_Tree_Item *_next_sibling; // next sibling (same level)
87 #endif /*FLTK_ABI_VERSION*/
88 protected:
89 void show_widgets();
90 void hide_widgets();
91 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
92 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
93 public:
94 Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR
95 ~Fl_Tree_Item(); // DTOR
96 Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR
97 int x() const { return(_xywh[0]); }
98 int y() const { return(_xywh[1]); }
99 int w() const { return(_xywh[2]); }
100 int h() const { return(_xywh[3]); }
101 int calc_item_height(const Fl_Tree_Prefs &prefs) const;
102 void draw(int X, int &Y, int W, Fl_Widget *tree, Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1);
103 void show_self(const char *indent = "") const;
104 void label(const char *val);
105 const char *label() const;
106
108 inline void user_data( void* data ) { _userdata = data; }
109
111 inline void* user_data() const { return _userdata; }
112
114 void labelfont(Fl_Font val) {
115 _labelfont = val;
116 }
118 Fl_Font labelfont() const {
119 return(_labelfont);
120 }
122 void labelsize(Fl_Fontsize val) {
123 _labelsize = val;
124 }
126 Fl_Fontsize labelsize() const {
127 return(_labelsize);
128 }
130 void labelfgcolor(Fl_Color val) {
131 _labelfgcolor = val;
132 }
134 void labelcolor(Fl_Color val) {
135 _labelfgcolor = val;
136 }
138 Fl_Color labelcolor() const {
139 return(_labelfgcolor);
140 }
142 Fl_Color labelfgcolor() const {
143 return(_labelfgcolor);
144 }
147 void labelbgcolor(Fl_Color val) {
148 _labelbgcolor = val;
149 }
152 Fl_Color labelbgcolor() const {
153 return(_labelbgcolor);
154 }
156 void widget(Fl_Widget *val) {
157 _widget = val;
158 }
160 Fl_Widget *widget() const {
161 return(_widget);
162 }
164 int children() const {
165 return(_children.total());
166 }
168 Fl_Tree_Item *child(int index) {
169 return(_children[index]);
170 }
172 const Fl_Tree_Item *child(int t) const;
174 int has_children() const {
175 return(children());
176 }
177 int find_child(const char *name);
178 int find_child(Fl_Tree_Item *item);
179 int remove_child(Fl_Tree_Item *item);
180 int remove_child(const char *new_label);
181 void clear_children();
182 void swap_children(int ax, int bx);
183 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
184 const Fl_Tree_Item *find_child_item(char **arr) const; // const
185 Fl_Tree_Item *find_child_item(char **arr); // non-const
186 const Fl_Tree_Item *find_item(char **arr) const; // const
187 Fl_Tree_Item *find_item(char **arr); // non-const
189 // Adding items
191 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, const char *new_label);
192 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs, char **arr);
193 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
194 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
195 int depth() const;
196 Fl_Tree_Item *prev();
197 Fl_Tree_Item *next();
198 Fl_Tree_Item *next_sibling();
199 Fl_Tree_Item *prev_sibling();
200 void update_prev_next(int index);
201 Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs);
202 Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs);
203
205 Fl_Tree_Item *parent() {
206 return(_parent);
207 }
209 const Fl_Tree_Item *parent() const {
210 return(_parent);
211 }
215 void parent(Fl_Tree_Item *val) {
216 _parent = val;
217 }
219 // State
221 void open();
222 void close();
224 int is_open() const {
225 return(is_flag(OPEN));
226 }
228 int is_close() const {
229 return(is_flag(OPEN)?0:1);
230 }
232 void open_toggle() {
233 is_open()?close():open();
234 }
238 void select(int val=1) {
239 set_flag(SELECTED, val);
240 }
242 void select_toggle() {
243 if ( is_selected() ) {
244 deselect(); // deselect if selected
245 } else {
246 select(); // select if deselected
247 }
248 }
253 int select_all() {
254 int count = 0;
255 if ( ! is_selected() ) {
256 select();
257 ++count;
258 }
259 for ( int t=0; t<children(); t++ ) {
260 count += child(t)->select_all();
261 }
262 return(count);
263 }
265 void deselect() {
266 set_flag(SELECTED, 0);
267 }
272 int deselect_all() {
273 int count = 0;
274 if ( is_selected() ) {
275 deselect();
276 ++count;
277 }
278 for ( int t=0; t<children(); t++ ) {
279 count += child(t)->deselect_all();
280 }
281 return(count);
282 }
284 char is_selected() const {
285 return(is_flag(SELECTED));
286 }
296 void activate(int val=1) {
297 set_flag(ACTIVE,val);
298 if ( _widget && val != (int)_widget->active() ) {
299 if ( val ) {
300 _widget->activate();
301 } else {
302 _widget->deactivate();
303 }
304 _widget->redraw();
305 }
306 }
310 void deactivate() {
311 activate(0);
312 }
314 char is_activated() const {
315 return(is_flag(ACTIVE));
316 }
318 char is_active() const {
319 return(is_activated());
320 }
322 int visible() const {
323 return(is_visible());
324 }
326 int is_visible() const {
327 return(is_flag(VISIBLE));
328 }
329 int visible_r() const;
330
332 void usericon(Fl_Image *val) {
333 _usericon = val;
334 }
336 Fl_Image *usericon() const {
337 return(_usericon);
338 }
340 // Events
342 const Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs) const;
343 Fl_Tree_Item *find_clicked(const Fl_Tree_Prefs &prefs);
344 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
345 int event_on_label(const Fl_Tree_Prefs &prefs) const;
347 int is_root() const {
348 return(_parent==0?1:0);
349 }
350
351 // Protected methods
352 protected:
353 #if FLTK_ABI_VERSION >= 10301
354 inline void set_flag(unsigned short flag,int val) {
356 if ( val ) _flags |= flag; else _flags &= ~flag;
357 }
359 inline int is_flag(unsigned short val) const {
360 return(_flags & val ? 1 : 0);
361 }
362 #else /*FLTK_ABI_VERSION*/
363 void set_flag(unsigned short flag,int val) {
365 switch (flag) {
366 case OPEN: _open = val; break;
367 case VISIBLE: _visible = val; break;
368 case ACTIVE: _active = val; break;
369 case SELECTED: _selected = val; break;
370 }
371 }
373 int is_flag(unsigned short flag) const {
374 switch (flag) {
375 case OPEN: return(_open ? 1 : 0);
376 case VISIBLE: return(_visible ? 1 : 0);
377 case ACTIVE: return(_active ? 1 : 0);
378 case SELECTED: return(_selected ? 1 : 0);
379 default: return(0);
380 }
381 }
382 #endif /*FLTK_ABI_VERSION*/
383
384 };
385
386 #endif /*FL_TREE_ITEM_H*/
387
388 //
389 // End of "$Id: Fl_Tree_Item.H 9706 2012-11-06 20:46:14Z matt $".
390 //
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
Fl_Tree_Item::is_root
int is_root() const
Is this item the root of the tree?
Definition: Fl_Tree_Item.H:347
Fl_Tree_Item::select
void select(int val=1)
Change the item&#39;s selection state to the optionally specified &#39;val&#39;.
Definition: Fl_Tree_Item.H:238
Fl_Tree_Item::visible
int visible() const
See if the item is visible. Alias for is_visible().
Definition: Fl_Tree_Item.H:322
Fl_Tree_Item::deselect_all
int deselect_all()
Deselect item and all its children.
Definition: Fl_Tree_Item.H:272
Fl.H
Fl static class.
Fl_Tree_Item::parent
void parent(Fl_Tree_Item *val)
Set the parent for this item.
Definition: Fl_Tree_Item.H:215
Fl_Tree_Item::labelcolor
Fl_Color labelcolor() const
Return item&#39;s label text color.
Definition: Fl_Tree_Item.H:138
Fl_Tree_Item::deselect
void deselect()
Disable the item&#39;s selection state.
Definition: Fl_Tree_Item.H:265
Fl_Image
Fl_Image is the base class used for caching and drawing all kinds of images in FLTK.
Definition: Fl_Image.H:44
Fl_Tree_Item::user_data
void user_data(void *data)
Set a user-data value for the item.
Definition: Fl_Tree_Item.H:108
Fl_Tree_Item::labelfont
void labelfont(Fl_Font val)
Set item&#39;s label font face.
Definition: Fl_Tree_Item.H:114
Fl_Tree_Item::select_all
int select_all()
Select item and all its children.
Definition: Fl_Tree_Item.H:253
Fl_Tree_Item::widget
Fl_Widget * widget() const
Return FLTK widget assigned to this item.
Definition: Fl_Tree_Item.H:160
Fl_Tree_Item::labelsize
void labelsize(Fl_Fontsize val)
Set item&#39;s label font size.
Definition: Fl_Tree_Item.H:122
Fl_Tree_Item::labelbgcolor
void labelbgcolor(Fl_Color val)
Set item&#39;s label background color.
Definition: Fl_Tree_Item.H:147
Fl_Tree_Item::usericon
void usericon(Fl_Image *val)
Set the item&#39;s user icon to an Fl_Image. &#39;0&#39; will disable.
Definition: Fl_Tree_Item.H:332
Fl_Tree_Item::activate
void activate(int val=1)
Change the item&#39;s activation state to the optionally specified &#39;val&#39;.
Definition: Fl_Tree_Item.H:296
Fl_Tree_Item::labelfont
Fl_Font labelfont() const
Get item&#39;s label font face.
Definition: Fl_Tree_Item.H:118
Fl_Tree_Item::select_toggle
void select_toggle()
Toggle the item&#39;s selection state.
Definition: Fl_Tree_Item.H:242
Fl_Tree_Item::is_active
char is_active() const
See if the item is activated.
Definition: Fl_Tree_Item.H:318
Fl_Tree_Item::labelbgcolor
Fl_Color labelbgcolor() const
Return item&#39;s background text color.
Definition: Fl_Tree_Item.H:152
Fl_Widget.H
Fl_Widget, Fl_Label classes .
Fl_Tree_Item::has_children
int has_children() const
See if this item has children.
Definition: Fl_Tree_Item.H:174
Fl_Tree_Item::labelcolor
void labelcolor(Fl_Color val)
Set item&#39;s label text color.
Definition: Fl_Tree_Item.H:134
Fl_Tree_Item::is_close
int is_close() const
See if the item is &#39;closed&#39;.
Definition: Fl_Tree_Item.H:228
Fl_Tree_Item::usericon
Fl_Image * usericon() const
Get the item&#39;s user icon as an Fl_Image. Returns &#39;0&#39; if disabled.
Definition: Fl_Tree_Item.H:336
Fl_Tree_Item::open_toggle
void open_toggle()
Toggle the item&#39;s open/closed state.
Definition: Fl_Tree_Item.H:232
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
Fl_Tree_Item::child
Fl_Tree_Item * child(int index)
Return the child item for the given &#39;index&#39;.
Definition: Fl_Tree_Item.H:168
Fl_Tree_Item::parent
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:209
Fl_Tree_Item::is_flag
int is_flag(unsigned short flag) const
See if flag set. Returns 0 or 1.
Definition: Fl_Tree_Item.H:373
fl_draw.H
utility header to pull drawing functions together
Fl_Color
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
Fl_Tree_Item
Tree item.
Definition: Fl_Tree_Item.H:54
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
Fl_Tree_Item_Array.H
This file defines a class that manages an array of Fl_Tree_Item pointers.
Fl_Tree_Prefs.H
This file contains the definitions for Fl_Tree&#39;s preferences.
Fl_Tree_Item::children
int children() const
Return the number of children this item has.
Definition: Fl_Tree_Item.H:164
Fl_Tree_Item_Array
Manages an array of Fl_Tree_Item pointers.
Definition: Fl_Tree_Item_Array.H:47
Fl_Tree_Item::parent
Fl_Tree_Item * parent()
Return the parent for this item. Returns NULL if we are the root.
Definition: Fl_Tree_Item.H:205
Fl_Tree_Item::labelsize
Fl_Fontsize labelsize() const
Get item&#39;s label font size.
Definition: Fl_Tree_Item.H:126
Fl_Tree_Item::is_visible
int is_visible() const
See if the item is visible.
Definition: Fl_Tree_Item.H:326
Fl_Tree_Prefs
Tree widget&#39;s preferences.
Definition: Fl_Tree_Prefs.H:104
Fl_Tree_Item::widget
void widget(Fl_Widget *val)
Assign an FLTK widget to this item.
Definition: Fl_Tree_Item.H:156
Fl_Tree_Item::labelfgcolor
Fl_Color labelfgcolor() const
Return item&#39;s label foreground text color.
Definition: Fl_Tree_Item.H:142
Fl_Tree_Item::user_data
void * user_data() const
Retrieve the user-data value that has been assigned to the item.
Definition: Fl_Tree_Item.H:111
Fl_Tree_Item::is_selected
char is_selected() const
See if the item is selected.
Definition: Fl_Tree_Item.H:284
Fl_Tree_Item::labelfgcolor
void labelfgcolor(Fl_Color val)
Set item&#39;s label foreground text color.
Definition: Fl_Tree_Item.H:130
Fl_Tree_Item::is_activated
char is_activated() const
See if the item is activated.
Definition: Fl_Tree_Item.H:314
Fl_Tree_Item::is_open
int is_open() const
See if the item is &#39;open&#39;.
Definition: Fl_Tree_Item.H:224
Fl_Tree_Item::deactivate
void deactivate()
Deactivate the item; the callback() won&#39;t be invoked when clicked.
Definition: Fl_Tree_Item.H:310
- © 1998-2012 by Bill Spitzak and others.