Flu_Combo_Box.H 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // $Id: Flu_Combo_Box.h,v 1.12 2004/03/24 02:49:00 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. #ifndef _FLU_COMBO_BOX_H
  13. #define _FLU_COMBO_BOX_H
  14. #include <FL/Fl_Double_Window.H>
  15. #include <FL/Fl_Input.H>
  16. #include <FL/Fl_Group.H>
  17. #include "FLU/Flu_Enumerations.H"
  18. //! This is a generic base class for implementing widgets with combo-box-like behavior (i.e. a pulldown menu where the "input" area is editable
  19. class FLU_EXPORT Flu_Combo_Box : public Fl_Group
  20. {
  21. public:
  22. //! Normal FLTK widget constructor
  23. Flu_Combo_Box( int x, int y, int w, int h, const char *l = 0 );
  24. //! Get whether the input field can be edited. Default is \c true
  25. inline bool editable() const
  26. { return (int)(!input.readonly()); }
  27. //! Set whether the input field can be edited.
  28. inline void editable( bool b )
  29. { input.readonly( (int)(!b) ); }
  30. //! Get the string in the input field
  31. inline const char* value() const
  32. { return input.value(); }
  33. //! Set the string in the input field and the value of the popup box.
  34. void value( const char *v );
  35. //! Set the height of the popup box
  36. inline void pop_height( int h )
  37. { popHeight = h; }
  38. //! Get the height of the popup box
  39. inline int pop_height()
  40. { return popHeight; }
  41. //! Override of Fl_Group::handle()
  42. int handle( int );
  43. //! Override of Fl_Group::resize()
  44. void resize( int X, int Y, int W, int H );
  45. //! Set the function that will be called when the input area is interacted with
  46. inline void input_callback( void (*cb)(Fl_Widget*,void*), void* cbd = 0 )
  47. { _inputCB = cb; _inputCBD = cbd; }
  48. //! Publicly exposed input widget
  49. Fl_Input input;
  50. virtual void add_item (void *adata, char const * avalue) = 0;
  51. virtual void *get_data_at(int pos=-1) = 0;
  52. virtual void select_by_data (void *adata) = 0;
  53. virtual void clear_items () = 0;
  54. virtual bool hasItems() = 0;
  55. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Combo_Box, Fl_Group)
  56. protected:
  57. void (*_inputCB)(Fl_Widget*,void*);
  58. void* _inputCBD;
  59. virtual bool _value( const char *v ) = 0;
  60. virtual const char* _next() = 0;
  61. virtual const char* _previous() = 0;
  62. virtual void _hilight( int x, int y ) = 0;
  63. void draw();
  64. void selected( const char *v );
  65. void set_combo_widget( Fl_Widget *w );
  66. uchar _valbox;
  67. bool _pushed, _popped;
  68. Fl_Widget *_cbox;
  69. int popHeight;
  70. static void input_cb( Fl_Widget*, void* v );
  71. class FLU_EXPORT Popup : public Fl_Double_Window
  72. {
  73. public:
  74. Popup( Flu_Combo_Box *b, Fl_Widget *c, int H );
  75. ~Popup();
  76. int handle( int event );
  77. protected:
  78. Flu_Combo_Box *combo;
  79. bool dragging;
  80. const char* selected;
  81. };
  82. friend class Popup;
  83. };
  84. #endif