Tweak themes for more color consistency.
[ntk.git] / examples / tree-simple.cxx
blobf3b9192ba66d8d809431e99737a8a929204136d2
1 //
2 // "$Id: tree-simple.cxx 8635 2011-05-06 04:27:49Z greg.ercolano $"
3 //
4 // Simple Fl_Tree widget example. - erco 06/05/2010
5 //
6 // Copyright 2010 Greg Ercolano.
7 // Copyright 1998-2010 by Bill Spitzak and others.
8 //
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
22 // USA.
24 // Please report all bugs and problems on the following page:
26 // http://www.fltk.org/str.php
28 #include <stdio.h>
29 #include <FL/Fl.H>
30 #include <FL/Fl_Double_Window.H>
31 #include <FL/Fl_Tree.H>
33 // Tree's callback
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();
39 if ( ! item ) return;
40 switch ( tree->callback_reason() ) {
41 case FL_TREE_REASON_SELECTED: {
42 char pathname[256];
43 tree->item_pathname(pathname, sizeof(pathname), item);
44 fprintf(stderr, "TreeCallback: Item selected='%s', Full pathname='%s'\n", item->label(), pathname);
45 break;
47 case FL_TREE_REASON_DESELECTED:
48 // fprintf(stderr, "TreeCallback: Item '%s' deselected\n", item->label());
49 break;
50 case FL_TREE_REASON_OPENED:
51 // fprintf(stderr, "TreeCallback: Item '%s' opened\n", item->label());
52 break;
53 case FL_TREE_REASON_CLOSED:
54 // fprintf(stderr, "TreeCallback: Item '%s' closed\n", item->label());
55 default:
56 break;
60 int main(int argc, char *argv[]) {
61 Fl::scheme("gtk+");
62 Fl_Double_Window *win = new Fl_Double_Window(250, 400, "Simple Tree");
63 win->begin();
65 // Create the 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
70 // Add some items
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");
87 win->end();
88 win->resizable(win);
89 win->show(argc, argv);
90 return(Fl::run());
94 // End of "$Id: tree-simple.cxx 8635 2011-05-06 04:27:49Z greg.ercolano $".