FLTK 1.4.4: Fl_Tree.H Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Tree.H
Go to the documentation of this file.
1//
2
3#ifndef FL_TREE_H
4#define FL_TREE_H
5
6#include <FL/Fl.H>
7#include <FL/Fl_Group.H>
8#include <FL/Fl_Scrollbar.H>
9#include <FL/fl_draw.H>
10
11#include <FL/Fl_Tree_Item.H>
12#include <FL/Fl_Tree_Prefs.H>
13
15// FL/Fl_Tree.H
17//
18// Fl_Tree -- This file is part of the Fl_Tree widget for FLTK
19// Copyright (C) 2009-2010 by Greg Ercolano.
20//
21// This library is free software. Distribution and use rights are outlined in
22// the file "COPYING" which should have been included with this file. If this
23// file is missing or damaged, see the license at:
24//
25// https://www.fltk.org/COPYING.php
26//
27// Please see the following page on how to report bugs and issues:
28//
29// https://www.fltk.org/bugs.php
30//
31
36
271
275 enum Fl_Tree_Reason {
276 FL_TREE_REASON_NONE = FL_REASON_UNKNOWN,
277 FL_TREE_REASON_SELECTED = FL_REASON_SELECTED,
278 FL_TREE_REASON_DESELECTED = FL_REASON_DESELECTED,
279 FL_TREE_REASON_RESELECTED = FL_REASON_RESELECTED,
281 FL_TREE_REASON_OPENED = FL_REASON_OPENED,
282 FL_TREE_REASON_CLOSED = FL_REASON_CLOSED,
283 FL_TREE_REASON_DRAGGED = FL_REASON_DRAGGED
284};
285
286 class FL_EXPORT Fl_Tree : public Fl_Group {
287 friend class Fl_Tree_Item;
288 Fl_Tree_Item *_root; // can be null!
289 Fl_Tree_Item *_item_focus; // item that has focus box
290 Fl_Tree_Item *_callback_item; // item invoked during callback (can be NULL)
291 Fl_Tree_Reason _callback_reason; // reason for the callback
292 Fl_Tree_Prefs _prefs; // all the tree's settings
293 int _scrollbar_size; // size of scrollbar trough
294 Fl_Tree_Item *_lastselect; // last selected item
295 char _lastpushed; // FL_PUSH occurred on: 0=nothing, 1=open/close, 2=usericon, 3=label
296 void fix_scrollbar_order();
297
298protected:
299 Fl_Scrollbar *_vscroll;
300 Fl_Scrollbar *_hscroll;
301 int _tox,_toy,_tow,_toh;
302 int _tix,_tiy,_tiw,_tih;
303
305 int _tree_w;
307 int _tree_h;
308 void item_clicked(Fl_Tree_Item* val);
309 void do_callback_for_item(Fl_Tree_Item* item, Fl_Tree_Reason reason);
310
311 // next_visible_item() and extend_selection() moved to 'public' in ABI 1.3.3
312 // undocmented draw_tree() dropped -- draw() does all the work now
313
314 // draw() has to be protected per FLTK convention (was public in 1.3.x)
315 void draw() FL_OVERRIDE;
316
317public:
318 Fl_Tree(int X, int Y, int W, int H, const char *L=0);
319 ~Fl_Tree();
320 int handle(int e) FL_OVERRIDE;
321 void show_self();
322 void resize(int,int,int,int) FL_OVERRIDE;
323
325 // root methods
327 void root_label(const char *new_label);
328 Fl_Tree_Item* root();
329 void root(Fl_Tree_Item *newitem);
330 const Fl_Tree_Prefs& prefs() const { return _prefs; }
331
333 // Item creation/removal methods
335 Fl_Tree_Item *add(const char *path, Fl_Tree_Item *newitem=0);
336 Fl_Tree_Item* add(Fl_Tree_Item *parent_item, const char *name);
337 Fl_Tree_Item *insert_above(Fl_Tree_Item *above, const char *name);
338 Fl_Tree_Item* insert(Fl_Tree_Item *item, const char *name, int pos);
339 int remove(Fl_Tree_Item *item);
340 void clear();
341 void clear_children(Fl_Tree_Item *item);
342
344 // Item lookup methods
346 Fl_Tree_Item *find_item(const char *path);
347 const Fl_Tree_Item *find_item(const char *path) const;
348 int item_pathname(char *pathname, int pathnamelen, const Fl_Tree_Item *item) const;
349 const Fl_Tree_Item* find_clicked(int yonly=0) const;
350 Fl_Tree_Item* find_clicked(int yonly=0);
351 Fl_Tree_Item *item_clicked();
352 Fl_Tree_Item *first();
353 Fl_Tree_Item *first_visible(); // deprecated in ABI 10303
354 Fl_Tree_Item *first_visible_item();
355 Fl_Tree_Item *next(Fl_Tree_Item *item=0);
356 Fl_Tree_Item *prev(Fl_Tree_Item *item=0);
357 Fl_Tree_Item *last();
358 Fl_Tree_Item *last_visible(); // deprecated in ABI 10303
359 Fl_Tree_Item *last_visible_item();
360 Fl_Tree_Item *next_visible_item(Fl_Tree_Item *start, int dir); // made public in 1.3.3 ABI
361 Fl_Tree_Item *first_selected_item();
362 Fl_Tree_Item *last_selected_item();
363 Fl_Tree_Item *next_item(Fl_Tree_Item *item, int dir=FL_Down, bool visible=false);
364 Fl_Tree_Item *next_selected_item(Fl_Tree_Item *item=0, int dir=FL_Down);
365 int get_selected_items(Fl_Tree_Item_Array &items);
366
368 // Item open/close methods
370 int open(Fl_Tree_Item *item, int docallback=1);
371 int open(const char *path, int docallback=1);
372 void open_toggle(Fl_Tree_Item *item, int docallback=1);
373 int close(Fl_Tree_Item *item, int docallback=1);
374 int close(const char *path, int docallback=1);
375 int is_open(Fl_Tree_Item *item) const;
376 int is_open(const char *path) const;
377 int is_close(Fl_Tree_Item *item) const;
378 int is_close(const char *path) const;
379
381 // Item selection methods
383 int select(Fl_Tree_Item *item, int docallback=1);
384 int select(const char *path, int docallback=1);
385 void select_toggle(Fl_Tree_Item *item, int docallback=1);
386 int deselect(Fl_Tree_Item *item, int docallback=1);
387 int deselect(const char *path, int docallback=1);
388 int deselect_all(Fl_Tree_Item *item=0, int docallback=1);
389 int select_only(Fl_Tree_Item *selitem, int docallback=1);
390 int select_all(Fl_Tree_Item *item=0, int docallback=1);
391 int extend_selection_dir(Fl_Tree_Item *from,
392 Fl_Tree_Item *to,
393 int dir,
394 int val,
395 bool visible);
396 int extend_selection(Fl_Tree_Item *from,
397 Fl_Tree_Item *to,
398 int val=1,
399 bool visible=false);
400 void set_item_focus(Fl_Tree_Item *item);
401 Fl_Tree_Item *get_item_focus() const;
402 int is_selected(Fl_Tree_Item *item) const;
403 int is_selected(const char *path);
404
406 // Item attribute related methods
408 Fl_Font item_labelfont() const;
409 void item_labelfont(Fl_Font val);
410 Fl_Fontsize item_labelsize() const;
411 void item_labelsize(Fl_Fontsize val);
412 Fl_Color item_labelfgcolor(void) const;
413 void item_labelfgcolor(Fl_Color val);
414 Fl_Color item_labelbgcolor(void) const;
415 void item_labelbgcolor(Fl_Color val);
416 Fl_Color connectorcolor() const;
417 void connectorcolor(Fl_Color val);
418 int marginleft() const;
419 void marginleft(int val);
420 int margintop() const;
421 void margintop(int val);
422 int marginbottom() const;
423 void marginbottom(int val);
424 int linespacing() const;
425 void linespacing(int val);
426 int openchild_marginbottom() const;
427 void openchild_marginbottom(int val);
428 int usericonmarginleft() const;
429 void usericonmarginleft(int val);
430 int labelmarginleft() const;
431 void labelmarginleft(int val);
432 int widgetmarginleft() const;
433 void widgetmarginleft(int val);
434 int connectorwidth() const;
435 void connectorwidth(int val);
436 Fl_Image* usericon() const;
437 void usericon(Fl_Image *val);
438 Fl_Image* openicon() const;
439 void openicon(Fl_Image *val);
440 Fl_Image* closeicon() const;
441 void closeicon(Fl_Image *val);
442 int showcollapse() const;
443 void showcollapse(int val);
444 int showroot() const;
445 void showroot(int val);
446 Fl_Tree_Connector connectorstyle() const;
447 void connectorstyle(Fl_Tree_Connector val);
448 Fl_Tree_Sort sortorder() const;
449 void sortorder(Fl_Tree_Sort val);
450 Fl_Boxtype selectbox() const;
451 void selectbox(Fl_Boxtype val);
452 Fl_Tree_Select selectmode() const;
453 void selectmode(Fl_Tree_Select val);
454 Fl_Tree_Item_Reselect_Mode item_reselect_mode() const;
455 void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode);
456 Fl_Tree_Item_Draw_Mode item_draw_mode() const;
457 void item_draw_mode(Fl_Tree_Item_Draw_Mode mode);
458 void item_draw_mode(int mode);
459 void calc_dimensions();
460 void calc_tree();
461 void recalc_tree();
462 int displayed(Fl_Tree_Item *item);
463 void show_item(Fl_Tree_Item *item, int yoff);
464 void show_item(Fl_Tree_Item *item);
465 void show_item_top(Fl_Tree_Item *item);
466 void show_item_middle(Fl_Tree_Item *item);
467 void show_item_bottom(Fl_Tree_Item *item);
468 void display(Fl_Tree_Item *item);
469 int vposition() const;
470 void vposition(int pos);
471 int hposition() const;
472 void hposition(int pos);
473
474 int is_scrollbar(Fl_Widget *w);
475 int scrollbar_size() const;
476 void scrollbar_size(int size);
477 int is_vscroll_visible() const;
478 int is_hscroll_visible() const;
479
481 // callback related
483 void callback_item(Fl_Tree_Item* item);
484 Fl_Tree_Item* callback_item();
485 void callback_reason(Fl_Tree_Reason reason);
486 Fl_Tree_Reason callback_reason() const;
487
489 void load(class Fl_Preferences&);
490};
491
492#endif /*FL_TREE_H*/
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1063
FL_Down
#define FL_Down
The down arrow key.
Definition Enumerations.H:502
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1092
Fl_Boxtype
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:644
FL_REASON_DESELECTED
@ FL_REASON_DESELECTED
an item was de-selected
Definition Enumerations.H:458
FL_REASON_CLOSED
@ FL_REASON_CLOSED
an item was closed
Definition Enumerations.H:461
FL_REASON_OPENED
@ FL_REASON_OPENED
an item was opened
Definition Enumerations.H:460
FL_REASON_UNKNOWN
@ FL_REASON_UNKNOWN
unknown or unset reason
Definition Enumerations.H:456
FL_REASON_SELECTED
@ FL_REASON_SELECTED
an item was selected
Definition Enumerations.H:457
FL_REASON_DRAGGED
@ FL_REASON_DRAGGED
an item was dragged into a new place
Definition Enumerations.H:462
FL_REASON_RESELECTED
@ FL_REASON_RESELECTED
an item was re-selected (double-clicked).
Definition Enumerations.H:459
Fl.H
Fl static class.
Fl_Group.H
Fl_Group and Fl_End classes.
Fl_Tree_Reason
Fl_Tree_Reason
The reason the callback was invoked.
Definition Fl_Tree.H:275
FL_TREE_REASON_RESELECTED
@ FL_TREE_REASON_RESELECTED
an item was re-selected (double-clicked).
Definition Fl_Tree.H:279
FL_TREE_REASON_CLOSED
@ FL_TREE_REASON_CLOSED
an item was closed
Definition Fl_Tree.H:282
FL_TREE_REASON_NONE
@ FL_TREE_REASON_NONE
unknown reason
Definition Fl_Tree.H:276
FL_TREE_REASON_OPENED
@ FL_TREE_REASON_OPENED
an item was opened
Definition Fl_Tree.H:281
FL_TREE_REASON_SELECTED
@ FL_TREE_REASON_SELECTED
an item was selected
Definition Fl_Tree.H:277
FL_TREE_REASON_DRAGGED
@ FL_TREE_REASON_DRAGGED
an item was dragged into a new place
Definition Fl_Tree.H:283
FL_TREE_REASON_DESELECTED
@ FL_TREE_REASON_DESELECTED
an item was de-selected
Definition Fl_Tree.H:278
Fl_Tree_Item.H
This file contains the definitions for Fl_Tree_Item.
Fl_Tree_Prefs.H
This file contains the definitions for Fl_Tree's preferences.
Fl_Tree_Connector
Fl_Tree_Connector
Defines the style of connection lines between items.
Definition Fl_Tree_Prefs.H:56
Fl_Tree_Sort
Fl_Tree_Sort
Sort order options for items added to the tree.
Definition Fl_Tree_Prefs.H:47
Fl_Tree_Item_Reselect_Mode
Fl_Tree_Item_Reselect_Mode
Defines the ways an item can be (re) selected via item_reselect_mode().
Definition Fl_Tree_Prefs.H:78
Fl_Tree_Item_Draw_Mode
Fl_Tree_Item_Draw_Mode
Bit flags that control how item's labels and widget()s are drawn in the tree via item_draw_mode().
Definition Fl_Tree_Prefs.H:87
Fl_Tree_Select
Fl_Tree_Select
Tree selection style.
Definition Fl_Tree_Prefs.H:65
Fl_Group::add
void add(Fl_Widget &)
The widget is removed from its current group (if any) and then added to the end of this group.
Definition Fl_Group.cxx:560
Fl_Group::draw
void draw() FL_OVERRIDE
Draws the widget.
Definition Fl_Group.cxx:943
Fl_Group::insert
void insert(Fl_Widget &, int i)
The widget is removed from its current group (if any) and then inserted into this group.
Definition Fl_Group.cxx:511
Fl_Group::clear
void clear()
Deletes all child widgets from memory recursively.
Definition Fl_Group.cxx:381
Fl_Group::remove
void remove(int index)
Removes the widget at index from the group but does not delete it.
Definition Fl_Group.cxx:585
Fl_Image
Base class for image caching, scaling and drawing.
Definition Fl_Image.H:60
Fl_Preferences
Fl_Preferences store user settings between application starts.
Definition Fl_Preferences.H:125
Fl_Scrollbar
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition Fl_Scrollbar.H:41
Fl_Tree_Item_Array
Manages an array of Fl_Tree_Item pointers.
Definition Fl_Tree_Item_Array.H:45
Fl_Tree_Item
Tree widget item.
Definition Fl_Tree_Item.H:65
Fl_Tree_Prefs
Tree widget's preferences.
Definition Fl_Tree_Prefs.H:105
Fl_Tree::root_label
void root_label(const char *new_label)
Set the label for the root item to 'new_label'.
Definition Fl_Tree.cxx:779
Fl_Tree::show_self
void show_self()
Print the tree as 'ascii art' to stdout.
Definition Fl_Tree.cxx:770
Fl_Tree::resize
void resize(int, int, int, int) FL_OVERRIDE
Resizes the Fl_Group widget and all of its children.
Definition Fl_Tree.cxx:692
Fl_Tree::_toh
int _toh
Tree widget outer xywh dimension: outside scrollbars, inside widget border.
Definition Fl_Tree.H:301
Fl_Tree::root
Fl_Tree_Item * root()
Returns the root item.
Definition Fl_Tree.cxx:785
Fl_Tree::item_clicked
void item_clicked(Fl_Tree_Item *val)
Set the item that was last clicked.
Definition Fl_Tree.cxx:1076
Fl_Tree::_tree_h
int _tree_h
the calculated height of the entire tree hierarchy. See calc_tree()
Definition Fl_Tree.H:307
Fl_Tree::_tree_w
int _tree_w
the calculated width of the entire tree hierarchy. See calc_tree()
Definition Fl_Tree.H:305
Fl_Tree::_hscroll
Fl_Scrollbar * _hscroll
Horizontal scrollbar.
Definition Fl_Tree.H:300
Fl_Tree::_tih
int _tih
Tree widget inner xywh dimension: inside borders + scrollbars.
Definition Fl_Tree.H:302
Fl_Tree::do_callback_for_item
void do_callback_for_item(Fl_Tree_Item *item, Fl_Tree_Reason reason)
Do the callback for the specified 'item' using 'reason', setting the callback_item() and callback_rea...
Definition Fl_Tree.cxx:2571
Fl_Tree::handle
int handle(int e) FL_OVERRIDE
Standard FLTK event handler for this widget.
Definition Fl_Tree.cxx:224
Fl_Tree::Fl_Tree
Fl_Tree(int X, int Y, int W, int H, const char *L=0)
Constructor.
Definition Fl_Tree.cxx:78
Fl_Tree::_vscroll
Fl_Scrollbar * _vscroll
Vertical scrollbar.
Definition Fl_Tree.H:299
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
fl_draw.H
utility header to pull drawing functions together