Flu_Combo_Tree.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. }
  27. Flu_Combo_Tree :: ~Flu_Combo_Tree()
  28. {
  29. }
  30. void Flu_Combo_Tree :: cb()
  31. {
  32. if( tree.callback_reason() == FLU_SELECTED )
  33. selected( tree.callback_node()->find_path() );
  34. }
  35. void Flu_Combo_Tree :: _hilight( int x, int y )
  36. {
  37. if( tree.inside_entry_area( x, y ) )
  38. tree.handle( FL_PUSH );
  39. }
  40. bool Flu_Combo_Tree :: _value( const char *v )
  41. {
  42. // see if 'v' is in the tree, and if so, make it the current selection
  43. Flu_Tree_Browser::Node *n = tree.find( v );
  44. if( n )
  45. {
  46. tree.unselect_all();
  47. tree.set_hilighted( n );
  48. n->select( true );
  49. return true;
  50. }
  51. return false;
  52. }
  53. const char* Flu_Combo_Tree :: _next()
  54. {
  55. Flu_Tree_Browser::Node *n = tree.get_selected( 1 );
  56. if( n )
  57. {
  58. Flu_Tree_Browser::Node *n2 = n->next();
  59. if( n2 )
  60. {
  61. n->select( false );
  62. n2->select( true );
  63. tree.set_hilighted( n2 );
  64. const char *path = n2->find_path();
  65. return( strlen(path) ? path : NULL );
  66. }
  67. }
  68. return NULL;
  69. }
  70. const char* Flu_Combo_Tree :: _previous()
  71. {
  72. Flu_Tree_Browser::Node *n = tree.get_selected( 1 );
  73. if( n )
  74. {
  75. Flu_Tree_Browser::Node *n2 = n->previous();
  76. if( n2 )
  77. {
  78. if( n2->is_root() && !tree.show_root() )
  79. return NULL;
  80. n->select( false );
  81. n2->select( true );
  82. tree.set_hilighted( n2 );
  83. const char *path = n2->find_path();
  84. return( strlen(path) ? path : NULL );
  85. }
  86. }
  87. return NULL;
  88. }