You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.9KB

  1. //
  2. // "$Id: Fl_Button.H 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Button 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; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Button widget . */
  29. #ifndef Fl_Button_H
  30. #define Fl_Button_H
  31. #ifndef Fl_Widget_H
  32. #include "Fl_Widget.H"
  33. #endif
  34. // values for type()
  35. #define FL_NORMAL_BUTTON 0 /**< value() will be set to 1 during the press of the button and
  36. reverts back to 0 when the button is released */
  37. #define FL_TOGGLE_BUTTON 1 ///< value() toggles between 0 and 1 at every click of the button
  38. #define FL_RADIO_BUTTON (FL_RESERVED_TYPE+2) /**< is set to 1 at button press, and all other
  39. buttons in the same group with <tt>type() == FL_RADIO_BUTTON</tt>
  40. are set to zero.*/
  41. #define FL_HIDDEN_BUTTON 3 ///< for Forms compatibility
  42. extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
  43. class Fl_Widget_Tracker;
  44. /**
  45. \class Fl_Button
  46. \brief Buttons generate callbacks when they are clicked by the user.
  47. You control exactly when and how by changing the values for type() and
  48. when(). Buttons can also generate callbacks in response to \c FL_SHORTCUT
  49. events. The button can either have an explicit shortcut(int s) value or a
  50. letter shortcut can be indicated in the label() with an '\&' character
  51. before it. For the label shortcut it does not matter if \e Alt is held
  52. down, but if you have an input field in the same window, the user will have
  53. to hold down the \e Alt key so that the input field does not eat the event
  54. first as an \c FL_KEYBOARD event.
  55. \todo Refactor the doxygen comments for Fl_Button type() documentation.
  56. For an Fl_Button object, the type() call returns one of:
  57. \li \c FL_NORMAL_BUTTON (0): value() remains unchanged after button press.
  58. \li \c FL_TOGGLE_BUTTON: value() is inverted after button press.
  59. \li \c FL_RADIO_BUTTON: value() is set to 1 after button press, and all other
  60. buttons in the current group with <tt>type() == FL_RADIO_BUTTON</tt>
  61. are set to zero.
  62. \todo Refactor the doxygen comments for Fl_Button when() documentation.
  63. For an Fl_Button object, the following when() values are useful, the default
  64. being \c FL_WHEN_RELEASE:
  65. \li \c 0: The callback is not done, instead changed() is turned on.
  66. \li \c FL_WHEN_RELEASE: The callback is done after the user successfully
  67. clicks the button, or when a shortcut is typed.
  68. \li \c FL_WHEN_CHANGED: The callback is done each time the value() changes
  69. (when the user pushes and releases the button, and as the mouse is
  70. dragged around in and out of the button).
  71. */
  72. class FL_EXPORT Fl_Button : public Fl_Widget {
  73. int shortcut_;
  74. char value_;
  75. char oldval;
  76. uchar down_box_;
  77. protected:
  78. static Fl_Widget_Tracker *key_release_tracker;
  79. static void key_release_timeout(void*);
  80. void simulate_key_action();
  81. virtual void draw();
  82. public:
  83. virtual int handle(int);
  84. Fl_Button(int X, int Y, int W, int H, const char *L = 0);
  85. int value(int v);
  86. /**
  87. Returns the current value of the button (0 or 1).
  88. */
  89. char value() const {return value_;}
  90. /**
  91. Same as \c value(1).
  92. \see value(int v)
  93. */
  94. int set() {return value(1);}
  95. /**
  96. Same as \c value(0).
  97. \see value(int v)
  98. */
  99. int clear() {return value(0);}
  100. void setonly(); // this should only be called on FL_RADIO_BUTTONs
  101. /**
  102. Returns the current shortcut key for the button.
  103. \retval int
  104. */
  105. int shortcut() const {return shortcut_;}
  106. /**
  107. Sets the shortcut key to \c s.
  108. Setting this overrides the use of '\&' in the label().
  109. The value is a bitwise OR of a key and a set of shift flags, for example:
  110. <tt>FL_ALT | 'a'</tt>, or
  111. <tt>FL_ALT | (FL_F + 10)</tt>, or just
  112. <tt>'a'</tt>.
  113. A value of 0 disables the shortcut.
  114. The key can be any value returned by Fl::event_key(), but will usually be
  115. an ASCII letter. Use a lower-case letter unless you require the shift key
  116. to be held down.
  117. The shift flags can be any set of values accepted by Fl::event_state().
  118. If the bit is on, that shift key must be pushed. Meta, Alt, Ctrl, and
  119. Shift must be off if they are not in the shift flags (zero for the other
  120. bits indicates a "don't care" setting).
  121. \param[in] s bitwise OR of key and shift flags
  122. */
  123. void shortcut(int s) {shortcut_ = s;}
  124. /**
  125. Returns the current down box type, which is drawn when value() is non-zero.
  126. \retval Fl_Boxtype
  127. */
  128. Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
  129. /**
  130. Sets the down box type. The default value of 0 causes FLTK to figure out
  131. the correct matching down version of box().
  132. \param[in] b down box type
  133. */
  134. void down_box(Fl_Boxtype b) {down_box_ = b;}
  135. /// (for backwards compatibility)
  136. void shortcut(const char *s) {shortcut(fl_old_shortcut(s));}
  137. /// (for backwards compatibility)
  138. Fl_Color down_color() const {return selection_color();}
  139. /// (for backwards compatibility)
  140. void down_color(unsigned c) {selection_color(c);}
  141. };
  142. #endif
  143. //
  144. // End of "$Id: Fl_Button.H 7903 2010-11-28 21:06:39Z matt $".
  145. //