FLTK 1.3.3: Fl_Tree_Item.H Source File

FLTK 1.3.3

- 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 10271 2014-09-04 18:56:52Z 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
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
66 class Fl_Tree;
67 class FL_EXPORT Fl_Tree_Item {
68 #if FLTK_ABI_VERSION >= 10303
69 Fl_Tree *_tree; // parent tree
70 #endif
71 const char *_label; // label (memory managed)
72 Fl_Font _labelfont; // label's font face
73 Fl_Fontsize _labelsize; // label's font size
74 Fl_Color _labelfgcolor; // label's fg color
75 Fl_Color _labelbgcolor; // label's bg color (0xffffffff is 'transparent')
76 #if FLTK_ABI_VERSION >= 10303
77 enum Fl_Tree_Item_Flags {
79 #else
80 enum {
82 #endif
83 OPEN = 1<<0,
84 VISIBLE = 1<<1,
85 ACTIVE = 1<<2,
86 SELECTED = 1<<3
87 };
88 #if FLTK_ABI_VERSION >= 10301
89 // NEW
90 unsigned short _flags; // misc flags
91 #else /*FLTK_ABI_VERSION*/
92 // OLD: this will go away after 1.3.x
93 char _open; // item is open?
94 char _visible; // item is visible?
95 char _active; // item activated?
96 char _selected; // item selected?
97 #endif /*FLTK_ABI_VERSION*/
98 int _xywh[4]; // xywh of this widget (if visible)
99 int _collapse_xywh[4]; // xywh of collapse icon (if visible)
100 int _label_xywh[4]; // xywh of label
101 Fl_Widget *_widget; // item's label widget (optional)
102 Fl_Image *_usericon; // item's user-specific icon (optional)
103 Fl_Tree_Item_Array _children; // array of child items
104 Fl_Tree_Item *_parent; // parent item (=0 if root)
105 void *_userdata; // user data that can be associated with an item
106 #if FLTK_ABI_VERSION >= 10301
107 Fl_Tree_Item *_prev_sibling; // previous sibling (same level)
108 Fl_Tree_Item *_next_sibling; // next sibling (same level)
109 #endif /*FLTK_ABI_VERSION*/
110 // Protected methods
111 protected:
112 void _Init(const Fl_Tree_Prefs &prefs, Fl_Tree *tree);
113 void show_widgets();
114 void hide_widgets();
115 void draw_vertical_connector(int x, int y1, int y2, const Fl_Tree_Prefs &prefs);
116 void draw_horizontal_connector(int x1, int x2, int y, const Fl_Tree_Prefs &prefs);
117 void recalc_tree();
118 int calc_item_height(const Fl_Tree_Prefs &prefs) const;
119 #if FLTK_ABI_VERSION >= 10303
120 Fl_Color drawfgcolor() const;
121 Fl_Color drawbgcolor() const;
122 #endif
123
124 public:
125 Fl_Tree_Item(const Fl_Tree_Prefs &prefs); // CTOR -- backwards compatible
126 #if FLTK_ABI_VERSION >= 10303
127 Fl_Tree_Item(Fl_Tree *tree); // CTOR -- ABI 1.3.3+
128 virtual ~Fl_Tree_Item(); // DTOR -- ABI 1.3.3+
129 #else
130 ~Fl_Tree_Item(); // DTOR -- backwards compatible
131 #endif
132 Fl_Tree_Item(const Fl_Tree_Item *o); // COPY CTOR
134 int x() const { return(_xywh[0]); }
136 int y() const { return(_xywh[1]); }
139 int w() const { return(_xywh[2]); }
141 int h() const { return(_xywh[3]); }
144 int label_x() const { return(_label_xywh[0]); }
147 int label_y() const { return(_label_xywh[1]); }
151 int label_w() const { return(_label_xywh[2]); }
154 int label_h() const { return(_label_xywh[3]); }
155 #if FLTK_ABI_VERSION >= 10303
156 virtual int draw_item_content(int render);
157 void draw(int X, int &Y, int W, Fl_Tree_Item *itemfocus,
158 int &tree_item_xmax, int lastchild=1, int render=1);
159 #else
160 void draw(int X, int &Y, int W, Fl_Widget *tree,
161 Fl_Tree_Item *itemfocus, const Fl_Tree_Prefs &prefs, int lastchild=1);
162 #endif
163 void show_self(const char *indent = "") const;
164 void label(const char *val);
165 const char *label() const;
166
168 inline void user_data( void* data ) { _userdata = data; }
169
171 inline void* user_data() const { return _userdata; }
172
174 void labelfont(Fl_Font val) {
175 _labelfont = val;
176 recalc_tree(); // may change tree geometry
177 }
179 Fl_Font labelfont() const {
180 return(_labelfont);
181 }
183 void labelsize(Fl_Fontsize val) {
184 _labelsize = val;
185 recalc_tree(); // may change tree geometry
186 }
188 Fl_Fontsize labelsize() const {
189 return(_labelsize);
190 }
192 void labelfgcolor(Fl_Color val) {
193 _labelfgcolor = val;
194 }
196 Fl_Color labelfgcolor() const {
197 return(_labelfgcolor);
198 }
200 void labelcolor(Fl_Color val) {
201 labelfgcolor(val);
202 }
204 Fl_Color labelcolor() const {
205 return labelfgcolor();
206 }
209 void labelbgcolor(Fl_Color val) {
210 _labelbgcolor = val;
211 }
216 Fl_Color labelbgcolor() const {
217 return(_labelbgcolor);
218 }
220 void widget(Fl_Widget *val) {
221 _widget = val;
222 recalc_tree(); // may change tree geometry
223 }
225 Fl_Widget *widget() const {
226 return(_widget);
227 }
229 int children() const {
230 return(_children.total());
231 }
233 Fl_Tree_Item *child(int index) {
234 return(_children[index]);
235 }
237 const Fl_Tree_Item *child(int t) const;
239 int has_children() const {
240 return(children());
241 }
242 int find_child(const char *name);
243 int find_child(Fl_Tree_Item *item);
244 int remove_child(Fl_Tree_Item *item);
245 int remove_child(const char *new_label);
246 void clear_children();
247 void swap_children(int ax, int bx);
248 int swap_children(Fl_Tree_Item *a, Fl_Tree_Item *b);
249 const Fl_Tree_Item *find_child_item(const char *name) const;
250 Fl_Tree_Item *find_child_item(const char *name);
251 const Fl_Tree_Item *find_child_item(char **arr) const;
252 Fl_Tree_Item *find_child_item(char **arr);
253 const Fl_Tree_Item *find_item(char **arr) const;
254 Fl_Tree_Item *find_item(char **arr);
256 // Adding items
258 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs,
259 const char *new_label,
260 Fl_Tree_Item *newitem);
261 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs,
262 const char *new_label);
263 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs,
264 char **arr,
265 Fl_Tree_Item *newitem);
266 Fl_Tree_Item *add(const Fl_Tree_Prefs &prefs,
267 char **arr);
268 #if FLTK_ABI_VERSION >= 10303
269 Fl_Tree_Item *replace(Fl_Tree_Item *new_item);
270 Fl_Tree_Item *replace_child(Fl_Tree_Item *olditem, Fl_Tree_Item *newitem);
271 #endif
272 Fl_Tree_Item *insert(const Fl_Tree_Prefs &prefs, const char *new_label, int pos=0);
273 Fl_Tree_Item *insert_above(const Fl_Tree_Prefs &prefs, const char *new_label);
274 Fl_Tree_Item* deparent(int index);
275 int reparent(Fl_Tree_Item *newchild, int index);
276 int move(int to, int from);
277 int move(Fl_Tree_Item *item, int op=0, int pos=0);
278 int move_above(Fl_Tree_Item *item);
279 int move_below(Fl_Tree_Item *item);
280 int move_into(Fl_Tree_Item *item, int pos=0);
281 int depth() const;
282 Fl_Tree_Item *prev();
283 Fl_Tree_Item *next();
284 Fl_Tree_Item *next_sibling();
285 Fl_Tree_Item *prev_sibling();
286 void update_prev_next(int index);
287 Fl_Tree_Item *next_displayed(Fl_Tree_Prefs &prefs); // deprecated
288 Fl_Tree_Item *prev_displayed(Fl_Tree_Prefs &prefs); // deprecated
289 Fl_Tree_Item *next_visible(Fl_Tree_Prefs &prefs);
290 Fl_Tree_Item *prev_visible(Fl_Tree_Prefs &prefs);
291
293 Fl_Tree_Item *parent() {
294 return(_parent);
295 }
297 const Fl_Tree_Item *parent() const {
298 return(_parent);
299 }
303 void parent(Fl_Tree_Item *val) {
304 _parent = val;
305 }
306 #if FLTK_ABI_VERSION >= 10303
307 const Fl_Tree_Prefs& prefs() const;
309 const Fl_Tree *tree() const {
310 return(_tree);
311 }
312 #endif
313 // State
316 void open();
317 void close();
319 int is_open() const {
320 return(is_flag(OPEN));
321 }
323 int is_close() const {
324 return(is_flag(OPEN)?0:1);
325 }
327 void open_toggle() {
328 is_open()?close():open(); // handles calling recalc_tree()
329 }
333 void select(int val=1) {
334 set_flag(SELECTED, val);
335 }
337 void select_toggle() {
338 if ( is_selected() ) {
339 deselect(); // deselect if selected
340 } else {
341 select(); // select if deselected
342 }
343 }
348 int select_all() {
349 int count = 0;
350 if ( ! is_selected() ) {
351 select();
352 ++count;
353 }
354 for ( int t=0; t<children(); t++ ) {
355 count += child(t)->select_all();
356 }
357 return(count);
358 }
360 void deselect() {
361 set_flag(SELECTED, 0);
362 }
367 int deselect_all() {
368 int count = 0;
369 if ( is_selected() ) {
370 deselect();
371 ++count;
372 }
373 for ( int t=0; t<children(); t++ ) {
374 count += child(t)->deselect_all();
375 }
376 return(count);
377 }
379 char is_selected() const {
380 return(is_flag(SELECTED));
381 }
390 void activate(int val=1) {
391 set_flag(ACTIVE,val);
392 if ( _widget && val != (int)_widget->active() ) {
393 if ( val ) {
394 _widget->activate();
395 } else {
396 _widget->deactivate();
397 }
398 _widget->redraw();
399 }
400 }
404 void deactivate() {
405 activate(0);
406 }
408 char is_activated() const {
409 return(is_flag(ACTIVE));
410 }
412 char is_active() const {
413 return(is_activated());
414 }
416 int visible() const {
417 return(is_visible());
418 }
420 int is_visible() const {
421 return(is_flag(VISIBLE));
422 }
423 int visible_r() const;
424
426 void usericon(Fl_Image *val) {
427 _usericon = val;
428 recalc_tree(); // may change tree geometry
429 }
431 Fl_Image *usericon() const {
432 return(_usericon);
433 }
435 // Events
437 #if FLTK_ABI_VERSION >= 10303
438 const Fl_Tree_Item* find_clicked(const Fl_Tree_Prefs &prefs, int yonly=0) const;
439 Fl_Tree_Item* find_clicked(const Fl_Tree_Prefs &prefs, int yonly=0);
440 #else
441 const Fl_Tree_Item* find_clicked(const Fl_Tree_Prefs &prefs) const;
442 Fl_Tree_Item* find_clicked(const Fl_Tree_Prefs &prefs);
443 #endif
444 int event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const;
445 int event_on_label(const Fl_Tree_Prefs &prefs) const;
447 int is_root() const {
448 return(_parent==0?1:0);
449 }
450
451 // Protected methods
452 // TODO: move these to top 'protected:' section
453 protected:
454 #if FLTK_ABI_VERSION >= 10301
455 inline void set_flag(unsigned short flag,int val) {
457 if ( flag==OPEN || flag==VISIBLE ) {
458 recalc_tree(); // may change tree geometry
459 }
460 if ( val ) _flags |= flag; else _flags &= ~flag;
461 }
463 inline int is_flag(unsigned short val) const {
464 return(_flags & val ? 1 : 0);
465 }
466 #else /*FLTK_ABI_VERSION*/
467 void set_flag(unsigned short flag,int val) {
469 switch (flag) {
470 case OPEN: _open = val; break;
471 case VISIBLE: _visible = val; break;
472 case ACTIVE: _active = val; break;
473 case SELECTED: _selected = val; break;
474 }
475 }
477 int is_flag(unsigned short flag) const {
478 switch (flag) {
479 case OPEN: return(_open ? 1 : 0);
480 case VISIBLE: return(_visible ? 1 : 0);
481 case ACTIVE: return(_active ? 1 : 0);
482 case SELECTED: return(_selected ? 1 : 0);
483 default: return(0);
484 }
485 }
486 #endif /*FLTK_ABI_VERSION*/
487
488 };
489
490 #endif /*FL_TREE_ITEM_H*/
491
492 //
493 // End of "$Id: Fl_Tree_Item.H 10271 2014-09-04 18:56:52Z greg.ercolano $".
494 //
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:447
Fl_Widget::deactivate
void deactivate()
Deactivates the widget.
Definition: Fl_Widget.cxx:234
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:333
Fl_Tree_Item::label_h
int label_h() const
The item&#39;s label height.
Definition: Fl_Tree_Item.H:154
Fl_Tree_Item::visible
int visible() const
See if the item is visible. Alias for is_visible().
Definition: Fl_Tree_Item.H:416
Fl_Widget::redraw
void redraw()
Schedules the drawing of the widget.
Definition: Fl.cxx:1710
Fl_Tree
Tree widget.
Definition: Fl_Tree.H:324
Fl_Tree_Item::deselect_all
int deselect_all()
Deselect item and all its children.
Definition: Fl_Tree_Item.H:367
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:303
Fl_Tree_Item::labelcolor
Fl_Color labelcolor() const
Return item&#39;s label text color. Alias for labelfgcolor() const).
Definition: Fl_Tree_Item.H:204
Fl_Tree_Item::deselect
void deselect()
Disable the item&#39;s selection state.
Definition: Fl_Tree_Item.H:360
Fl_Image
Fl_Image is the base class used for caching and drawing all kinds of images in FLTK.
Definition: Fl_Image.H:52
Fl_Image.H
Fl_Image, Fl_RGB_Image classes.
Fl_Tree_Item::user_data
void user_data(void *data)
Set a user-data value for the item.
Definition: Fl_Tree_Item.H:168
Fl_Tree_Item::x
int x() const
The item&#39;s x position relative to the window.
Definition: Fl_Tree_Item.H:134
Fl_Tree_Item::labelfont
void labelfont(Fl_Font val)
Set item&#39;s label font face.
Definition: Fl_Tree_Item.H:174
Fl_Tree_Item::select_all
int select_all()
Select item and all its children.
Definition: Fl_Tree_Item.H:348
Fl_Tree_Item::widget
Fl_Widget * widget() const
Return FLTK widget assigned to this item.
Definition: Fl_Tree_Item.H:225
Fl_Tree_Item::labelsize
void labelsize(Fl_Fontsize val)
Set item&#39;s label font size.
Definition: Fl_Tree_Item.H:183
Fl_Tree_Item::labelbgcolor
void labelbgcolor(Fl_Color val)
Set item&#39;s label background color.
Definition: Fl_Tree_Item.H:209
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:426
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:390
Fl_Tree_Item::labelfont
Fl_Font labelfont() const
Get item&#39;s label font face.
Definition: Fl_Tree_Item.H:179
Fl_Tree_Item::select_toggle
void select_toggle()
Toggle the item&#39;s selection state.
Definition: Fl_Tree_Item.H:337
Fl_Tree_Item::is_active
char is_active() const
See if the item is activated. Alias for is_activated().
Definition: Fl_Tree_Item.H:412
Fl_Tree_Item::labelbgcolor
Fl_Color labelbgcolor() const
Return item&#39;s label background text color.
Definition: Fl_Tree_Item.H:216
Fl_Widget::activate
void activate()
Activates the widget.
Definition: Fl_Widget.cxx:222
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:239
Fl_Widget::active
unsigned int active() const
Returns whether the widget is active.
Definition: Fl_Widget.H:696
Fl_Tree_Item::labelcolor
void labelcolor(Fl_Color val)
Set item&#39;s label text color. Alias for labelfgcolor(Fl_Color)).
Definition: Fl_Tree_Item.H:200
Fl_Tree_Item::w
int w() const
The entire item&#39;s width to right edge of Fl_Tree&#39;s inner width within scrollbars. ...
Definition: Fl_Tree_Item.H:139
Fl_Tree_Item::y
int y() const
The item&#39;s y position relative to the window.
Definition: Fl_Tree_Item.H:136
Fl_Tree_Item::label_x
int label_x() const
The item&#39;s label x position relative to the window.
Definition: Fl_Tree_Item.H:144
Fl_Tree_Item::is_close
int is_close() const
See if the item is &#39;closed&#39;.
Definition: Fl_Tree_Item.H:323
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:431
Fl_Tree_Item::open_toggle
void open_toggle()
Toggle the item&#39;s open/closed state.
Definition: Fl_Tree_Item.H:327
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:768
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:233
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:297
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:477
fl_draw.H
utility header to pull drawing functions together
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:796
Fl_Tree_Item
Tree widget item.
Definition: Fl_Tree_Item.H:67
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:739
Fl_Tree_Item_Array.H
This file defines a class that manages an array of Fl_Tree_Item pointers.
Fl_Tree_Item_Array::total
int total() const
Return the total items in the array, or 0 if empty.
Definition: Fl_Tree_Item_Array.H:72
Fl_Tree_Prefs.H
This file contains the definitions for Fl_Tree&#39;s preferences.
Fl_Tree_Item::label_y
int label_y() const
The item&#39;s label y position relative to the window.
Definition: Fl_Tree_Item.H:147
Fl_Tree_Item::children
int children() const
Return the number of children this item has.
Definition: Fl_Tree_Item.H:229
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:293
Fl_Tree_Item::h
int h() const
The item&#39;s height.
Definition: Fl_Tree_Item.H:141
Fl_Tree_Item::labelsize
Fl_Fontsize labelsize() const
Get item&#39;s label font size.
Definition: Fl_Tree_Item.H:188
Fl_Tree_Item::is_visible
int is_visible() const
See if the item is visible.
Definition: Fl_Tree_Item.H:420
Fl_Tree_Prefs
Tree widget&#39;s preferences.
Definition: Fl_Tree_Prefs.H:111
Fl_Tree_Item::widget
void widget(Fl_Widget *val)
Assign an FLTK widget to this item.
Definition: Fl_Tree_Item.H:220
Fl_Tree_Item::labelfgcolor
Fl_Color labelfgcolor() const
Return item&#39;s label foreground text color.
Definition: Fl_Tree_Item.H:196
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:171
Fl_Tree_Item::is_selected
char is_selected() const
See if the item is selected.
Definition: Fl_Tree_Item.H:379
Fl_Tree_Item::labelfgcolor
void labelfgcolor(Fl_Color val)
Set item&#39;s label foreground text color.
Definition: Fl_Tree_Item.H:192
Fl_Tree_Item::label_w
int label_w() const
The item&#39;s maximum label width to right edge of Fl_Tree&#39;s inner width within scrollbars.
Definition: Fl_Tree_Item.H:151
Fl_Tree_Item::is_activated
char is_activated() const
See if the item is activated.
Definition: Fl_Tree_Item.H:408
Fl_Tree_Item::is_open
int is_open() const
See if the item is &#39;open&#39;.
Definition: Fl_Tree_Item.H:319
Fl_Tree_Item::deactivate
void deactivate()
Deactivate the item; the callback() won&#39;t be invoked when clicked.
Definition: Fl_Tree_Item.H:404
- © 1998-2014 by Bill Spitzak and others.