Fl_Choice.H 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // "$Id: Fl_Choice.H 10513 2015-01-10 22:05:15Z greg.ercolano $"
  3. //
  4. // Choice header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Choice widget . */
  20. #ifndef Fl_Choice_H
  21. #define Fl_Choice_H
  22. #include "Fl_Menu_.H"
  23. /**
  24. \class Fl_Choice
  25. \brief A button that is used to pop up a menu.
  26. This is a button that, when pushed, pops up a menu (or hierarchy of menus)
  27. defined by an array of Fl_Menu_Item objects.
  28. Motif calls this an OptionButton.
  29. The only difference between this and a Fl_Menu_Button is that the name of
  30. the most recent chosen menu item is displayed inside the box, while the
  31. label is displayed outside the box. However, since the use of this is most
  32. often to control a single variable rather than do individual callbacks,
  33. some of the Fl_Menu_Button methods are redescribed here in those terms.
  34. When the user clicks a menu item, value() is set to that item
  35. and then:
  36. - The item's callback is done if one has been set; the
  37. Fl_Choice is passed as the Fl_Widget* argument,
  38. along with any userdata configured for the callback.
  39. - If the item does not have a callback, the Fl_Choice widget's
  40. callback is done instead, along with any userdata configured
  41. for it. The callback can determine which item was picked using
  42. value(), mvalue(), item_pathname(), etc.
  43. All three mouse buttons pop up the menu. The Forms behavior of the first
  44. two buttons to increment/decrement the choice is not implemented. This
  45. could be added with a subclass, however.
  46. The menu will also pop up in response to shortcuts indicated by putting
  47. a '\&' character in the label(). See Fl_Button::shortcut(int s) for a
  48. description of this.
  49. Typing the shortcut() of any of the items will do exactly the same as when
  50. you pick the item with the mouse. The '\&' character in item names are
  51. only looked at when the menu is popped up, however.
  52. \image html choice.png
  53. \image latex choice.png "Fl_Choice" width=4cm
  54. \todo Refactor the doxygen comments for Fl_Choice changed() documentation.
  55. \li <tt>int Fl_Widget::changed() const</tt>
  56. This value is true the user picks a different value. <em>It is turned
  57. off by value() and just before doing a callback (the callback can turn
  58. it back on if desired).</em>
  59. \li <tt>void Fl_Widget::set_changed()</tt>
  60. This method sets the changed() flag.
  61. \li <tt>void Fl_Widget::clear_changed()</tt>
  62. This method clears the changed() flag.
  63. \li <tt>Fl_Boxtype Fl_Choice::down_box() const</tt>
  64. Gets the current down box, which is used when the menu is popped up.
  65. The default down box type is \c FL_DOWN_BOX.
  66. \li <tt>void Fl_Choice::down_box(Fl_Boxtype b)</tt>
  67. Sets the current down box type to \p b.
  68. */
  69. class FL_EXPORT Fl_Choice : public Fl_Menu_ {
  70. protected:
  71. void draw();
  72. public:
  73. int handle(int);
  74. Fl_Choice(int X, int Y, int W, int H, const char *L = 0);
  75. /**
  76. Gets the index of the last item chosen by the user.
  77. The index is zero initially.
  78. */
  79. int value() const {return Fl_Menu_::value();}
  80. int value(int v);
  81. int value(const Fl_Menu_Item* v);
  82. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Choice, Fl_Menu_)
  83. };
  84. #endif
  85. //
  86. // End of "$Id: Fl_Choice.H 10513 2015-01-10 22:05:15Z greg.ercolano $".
  87. //