You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1KB

  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.
  13. //
  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.
  18. //
  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.
  23. //
  24. // Please report all bugs and problems on the following page:
  25. //
  26. // http://www.fltk.org/str.php
  27. //
  28. #include <stdio.h>
  29. #include <FL/Fl.H>
  30. #include <FL/Fl_Double_Window.H>
  31. #include <FL/Fl_Tree.H>
  32. // Tree's callback
  33. // Invoked whenever an item's state changes.
  34. //
  35. void TreeCallback(Fl_Widget *w, void *data) {
  36. Fl_Tree *tree = (Fl_Tree*)w;
  37. Fl_Tree_Item *item = (Fl_Tree_Item*)tree->callback_item();
  38. if ( ! item ) return;
  39. switch ( tree->callback_reason() ) {
  40. case FL_TREE_REASON_SELECTED: {
  41. char pathname[256];
  42. tree->item_pathname(pathname, sizeof(pathname), item);
  43. fprintf(stderr, "TreeCallback: Item selected='%s', Full pathname='%s'\n", item->label(), pathname);
  44. break;
  45. }
  46. case FL_TREE_REASON_DESELECTED:
  47. // fprintf(stderr, "TreeCallback: Item '%s' deselected\n", item->label());
  48. break;
  49. case FL_TREE_REASON_OPENED:
  50. // fprintf(stderr, "TreeCallback: Item '%s' opened\n", item->label());
  51. break;
  52. case FL_TREE_REASON_CLOSED:
  53. // fprintf(stderr, "TreeCallback: Item '%s' closed\n", item->label());
  54. default:
  55. break;
  56. }
  57. }
  58. int main(int argc, char *argv[]) {
  59. Fl::scheme("gtk+");
  60. Fl_Double_Window *win = new Fl_Double_Window(250, 400, "Simple Tree");
  61. win->begin();
  62. {
  63. // Create the tree
  64. Fl_Tree *tree = new Fl_Tree(10, 10, win->w()-20, win->h()-20);
  65. tree->showroot(0); // don't show root of tree
  66. tree->callback(TreeCallback); // setup a callback for the tree
  67. // Add some items
  68. tree->add("Flintstones/Fred");
  69. tree->add("Flintstones/Wilma");
  70. tree->add("Flintstones/Pebbles");
  71. tree->add("Simpsons/Homer");
  72. tree->add("Simpsons/Marge");
  73. tree->add("Simpsons/Bart");
  74. tree->add("Simpsons/Lisa");
  75. tree->add("Pathnames/\\/bin"); // front slashes
  76. tree->add("Pathnames/\\/usr\\/sbin");
  77. tree->add("Pathnames/C:\\\\Program Files"); // backslashes
  78. tree->add("Pathnames/C:\\\\Documents and Settings");
  79. // Start with some items closed
  80. tree->close("Simpsons");
  81. tree->close("Pathnames");
  82. }
  83. win->end();
  84. win->resizable(win);
  85. win->show(argc, argv);
  86. return(Fl::run());
  87. }
  88. //
  89. // End of "$Id: tree-simple.cxx 8635 2011-05-06 04:27:49Z greg.ercolano $".
  90. //