2 // "$Id: tree-simple.cxx 8635 2011-05-06 04:27:49Z greg.ercolano $"
4 // Simple Fl_Tree widget example. - erco 06/05/2010
6 // Copyright 2010 Greg Ercolano.
7 // Copyright 1998-2010 by Bill Spitzak and others.
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Library General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Library General Public License for more details.
19 // You should have received a copy of the GNU Library General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 // Please report all bugs and problems on the following page:
26 // http://www.fltk.org/str.php
30 #include <FL/Fl_Double_Window.H>
31 #include <FL/Fl_Tree.H>
34 // Invoked whenever an item's state changes.
36 void TreeCallback(Fl_Widget
*w
, void *data
) {
37 Fl_Tree
*tree
= (Fl_Tree
*)w
;
38 Fl_Tree_Item
*item
= (Fl_Tree_Item
*)tree
->callback_item();
40 switch ( tree
->callback_reason() ) {
41 case FL_TREE_REASON_SELECTED
: {
43 tree
->item_pathname(pathname
, sizeof(pathname
), item
);
44 fprintf(stderr
, "TreeCallback: Item selected='%s', Full pathname='%s'\n", item
->label(), pathname
);
47 case FL_TREE_REASON_DESELECTED
:
48 // fprintf(stderr, "TreeCallback: Item '%s' deselected\n", item->label());
50 case FL_TREE_REASON_OPENED
:
51 // fprintf(stderr, "TreeCallback: Item '%s' opened\n", item->label());
53 case FL_TREE_REASON_CLOSED
:
54 // fprintf(stderr, "TreeCallback: Item '%s' closed\n", item->label());
60 int main(int argc
, char *argv
[]) {
62 Fl_Double_Window
*win
= new Fl_Double_Window(250, 400, "Simple Tree");
66 Fl_Tree
*tree
= new Fl_Tree(10, 10, win
->w()-20, win
->h()-20);
67 tree
->showroot(0); // don't show root of tree
68 tree
->callback(TreeCallback
); // setup a callback for the tree
71 tree
->add("Flintstones/Fred");
72 tree
->add("Flintstones/Wilma");
73 tree
->add("Flintstones/Pebbles");
74 tree
->add("Simpsons/Homer");
75 tree
->add("Simpsons/Marge");
76 tree
->add("Simpsons/Bart");
77 tree
->add("Simpsons/Lisa");
78 tree
->add("Pathnames/\\/bin"); // front slashes
79 tree
->add("Pathnames/\\/usr\\/sbin");
80 tree
->add("Pathnames/C:\\\\Program Files"); // backslashes
81 tree
->add("Pathnames/C:\\\\Documents and Settings");
83 // Start with some items closed
84 tree
->close("Simpsons");
85 tree
->close("Pathnames");
89 win
->show(argc
, argv
);
94 // End of "$Id: tree-simple.cxx 8635 2011-05-06 04:27:49Z greg.ercolano $".