Flu_Combo_Tree.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // $Id: Flu_Combo_Tree.cpp,v 1.5 2004/08/02 14:18:16 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #include <stdio.h>
  13. #include <FL/Fl.H>
  14. #include <FL/fl_draw.H>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <FL/math.h>
  18. #include "FLU/Flu_Combo_Tree.H"
  19. Flu_Combo_Tree::Flu_Combo_Tree( int X, int Y, int W, int H, const char* l )
  20. : Flu_Combo_Box( X, Y, W, H, l ), tree(0,0,0,0)
  21. {
  22. tree.callback( _cb, this );
  23. tree.selection_mode( FLU_SINGLE_SELECT );
  24. tree.when( FL_WHEN_RELEASE );
  25. set_combo_widget( &tree );
  26. editable(0);
  27. pop_height(200);
  28. }
  29. void Flu_Combo_Tree::cb()
  30. {
  31. if( tree.callback_reason() == FLU_SELECTED )
  32. selected( tree.callback_node()->find_path() );
  33. }
  34. void Flu_Combo_Tree::_hilight( int x, int y )
  35. {
  36. if( tree.inside_entry_area( x, y ) )
  37. tree.handle( FL_PUSH );
  38. }
  39. bool Flu_Combo_Tree::_value( const char *v )
  40. {
  41. // see if 'v' is in the tree, and if so, make it the current selection
  42. Flu_Tree_Browser::Node *n = tree.find( v );
  43. if( n )
  44. {
  45. tree.unselect_all();
  46. tree.set_hilighted( n );
  47. n->select( true );
  48. return true;
  49. }
  50. return false;
  51. }
  52. const char* Flu_Combo_Tree::_next()
  53. {
  54. Flu_Tree_Browser::Node *n = tree.get_selected( 1 );
  55. if( n )
  56. {
  57. Flu_Tree_Browser::Node *n2 = n->next();
  58. if( n2 )
  59. {
  60. n->select( false );
  61. n2->select( true );
  62. tree.set_hilighted( n2 );
  63. const char *path = n2->find_path();
  64. return( strlen(path) ? path : NULL );
  65. }
  66. }
  67. return NULL;
  68. }
  69. const char* Flu_Combo_Tree::_previous()
  70. {
  71. Flu_Tree_Browser::Node *n = tree.get_selected( 1 );
  72. if( n )
  73. {
  74. Flu_Tree_Browser::Node *n2 = n->previous();
  75. if( n2 )
  76. {
  77. if( n2->is_root() && !tree.show_root() )
  78. return NULL;
  79. n->select( false );
  80. n2->select( true );
  81. tree.set_hilighted( n2 );
  82. const char *path = n2->find_path();
  83. return( strlen(path) ? path : NULL );
  84. }
  85. }
  86. return NULL;
  87. }
  88. void Flu_Combo_Tree::textsize(Fl_Fontsize pix)
  89. {
  90. Flu_Combo_Box::textsize(pix);
  91. tree.labelsize(pix);
  92. input.textsize(pix);
  93. }
  94. void Flu_Combo_Tree::textfont(Fl_Font f)
  95. {
  96. Flu_Combo_Box::textfont(f);
  97. tree.labelfont(f);
  98. input.textfont(f);
  99. }
  100. void *Flu_Combo_Tree::get_data_at (int pos)
  101. {
  102. Flu_Tree_Browser::Node *node = tree.get_hilighted();
  103. if(node)
  104. {
  105. return node->user_data();
  106. }
  107. else
  108. {
  109. return 0;
  110. }
  111. }
  112. void Flu_Combo_Tree::select_by_data (void *adata)
  113. {
  114. tree.unselect_all();
  115. Flu_Tree_Browser::Node *item = tree.find_by_user_data(adata);
  116. if(item) tree.set_hilighted(item);
  117. }