Flu_Combo_List.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // $Id: Flu_Combo_List.cpp,v 1.5 2004/03/24 02:49:13 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_List.h"
  19. Flu_Combo_List :: Flu_Combo_List( int X, int Y, int W, int H, const char* l )
  20. : Flu_Combo_Box( X, Y, W, H, l ), list(0,0,0,0)
  21. {
  22. list.box( FL_FLAT_BOX );
  23. list.callback( _cb, this );
  24. set_combo_widget( &list );
  25. }
  26. Flu_Combo_List :: ~Flu_Combo_List()
  27. {
  28. }
  29. void Flu_Combo_List :: cb()
  30. {
  31. if( list.value() )
  32. selected( list.text( list.value() ) );
  33. else
  34. _value( value() );
  35. }
  36. void Flu_Combo_List :: _hilight( int x, int y )
  37. {
  38. if( list.scrollbar.visible() )
  39. {
  40. if( x > list.x() && y > list.y() &&
  41. x < (list.x()+list.w()-list.scrollbar.w()) &&
  42. y < (list.y()+list.h()) )
  43. list.handle( FL_DRAG );
  44. }
  45. else
  46. {
  47. if( x > list.x() && y > list.y() &&
  48. x < (list.x()+list.w()) &&
  49. y < (list.y()+list.h()) )
  50. list.handle( FL_DRAG );
  51. }
  52. }
  53. bool Flu_Combo_List :: _value( const char *v )
  54. {
  55. // see if 'v' is in the list, and if so, make it the current selection
  56. for( int i = 1; i <= list.size(); i++ )
  57. {
  58. if( strcmp( list.text(i), v ) == 0 )
  59. {
  60. list.value( i );
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. const char* Flu_Combo_List :: _next()
  67. {
  68. int v = list.value();
  69. if( v < list.size() )
  70. list.value( v+1 );
  71. list.middleline( list.value() );
  72. return list.text(list.value());
  73. }
  74. const char* Flu_Combo_List :: _previous()
  75. {
  76. int v = list.value();
  77. if( v > 1 )
  78. list.value( v-1 );
  79. list.middleline( list.value() );
  80. return list.text(list.value());
  81. }