Flu_Combo_List.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. editable(0);
  26. pop_height(200);
  27. }
  28. void Flu_Combo_List::cb()
  29. {
  30. if( list.value() )
  31. selected( list.text( list.value() ) );
  32. else
  33. _value( value() );
  34. }
  35. void Flu_Combo_List::_hilight( int x, int y )
  36. {
  37. if( list.scrollbar.visible() )
  38. {
  39. if( x > list.x() && y > list.y() &&
  40. x < (list.x()+list.w()-list.scrollbar.w()) &&
  41. y < (list.y()+list.h()) )
  42. list.handle( FL_DRAG );
  43. }
  44. else
  45. {
  46. if( x > list.x() && y > list.y() &&
  47. x < (list.x()+list.w()) &&
  48. y < (list.y()+list.h()) )
  49. list.handle( FL_DRAG );
  50. }
  51. }
  52. bool Flu_Combo_List::_value( const char *v )
  53. {
  54. // see if 'v' is in the list, and if so, make it the current selection
  55. for( int i = 1; i <= list.size(); i++ )
  56. {
  57. if( strcmp( list.text(i), v ) == 0 )
  58. {
  59. list.value( i );
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. const char* Flu_Combo_List::_next()
  66. {
  67. int v = list.value();
  68. if( v < list.size() )
  69. list.value( v+1 );
  70. list.middleline( list.value() );
  71. return list.text(list.value());
  72. }
  73. const char* Flu_Combo_List::_previous()
  74. {
  75. int v = list.value();
  76. if( v > 1 )
  77. list.value( v-1 );
  78. list.middleline( list.value() );
  79. return list.text(list.value());
  80. }
  81. void Flu_Combo_List::textsize(Fl_Fontsize pix)
  82. {
  83. Flu_Combo_Box::textsize(pix);
  84. list.labelsize(pix);
  85. list.textsize(pix);
  86. input.textsize(pix);
  87. }
  88. void Flu_Combo_List::textfont(Fl_Font f)
  89. {
  90. Flu_Combo_Box::textfont(f);
  91. list.labelfont(f);
  92. list.textfont(f);
  93. input.textfont(f);
  94. }
  95. void *Flu_Combo_List::get_data_at(int pos)
  96. {
  97. if(pos == -1) pos = list.value();
  98. if(pos == 0) return 0;
  99. return list.data(pos);
  100. }
  101. void Flu_Combo_List::select_by_data (void *adata)
  102. {
  103. int line = list.lineno_for_data(adata);
  104. list.value(line);
  105. value(list.text(line));
  106. }