Fl_Spinner.H 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // "$Id: Fl_Spinner.H 12313 2017-07-12 21:51:42Z AlbrechtS $"
  3. //
  4. // Spinner widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 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_Spinner widget . */
  20. #ifndef Fl_Spinner_H
  21. #define Fl_Spinner_H
  22. #include <FL/Enumerations.H>
  23. #include <FL/Fl_Group.H>
  24. #include <FL/Fl_Input.H>
  25. #include <FL/Fl_Repeat_Button.H>
  26. /**
  27. This widget is a combination of a numerical input widget and repeat buttons.
  28. The user can either type into the input area or use the buttons to
  29. change the value.
  30. \image html Fl_Spinner.png "Fl_Spinner widget"
  31. \image latex Fl_Spinner.png "Fl_Spinner widget" width=6cm
  32. */
  33. class FL_EXPORT Fl_Spinner : public Fl_Group {
  34. double value_; // Current value
  35. double minimum_; // Minimum value
  36. double maximum_; // Maximum value
  37. double step_; // Amount to add/subtract for up/down
  38. const char *format_; // Format string for input field
  39. int wrap_; // wrap around at bounds (1/0)
  40. private:
  41. static void sb_cb(Fl_Widget *w, Fl_Spinner *sb); // internal callback
  42. void update(); // update input field
  43. protected:
  44. // This class works like Fl_Input but ignores FL_Up and FL_Down key
  45. // presses so they are handled by its parent, the Fl_Spinner widget.
  46. // See STR #2989.
  47. class FL_EXPORT Fl_Spinner_Input : public Fl_Input {
  48. public:
  49. Fl_Spinner_Input(int X, int Y, int W, int H)
  50. : Fl_Input(X, Y, W, H) {}
  51. int handle(int event); // implemented in src/Fl_Spinner.cxx
  52. };
  53. Fl_Spinner_Input input_; // Input field for the value
  54. Fl_Repeat_Button
  55. up_button_, // Up button
  56. down_button_; // Down button
  57. public:
  58. // Constructor
  59. Fl_Spinner(int X, int Y, int W, int H, const char *L = 0);
  60. // Event handling
  61. int handle(int event);
  62. // Resize group and subwidgets
  63. void resize(int X, int Y, int W, int H);
  64. /** Returns the format string for the value. */
  65. const char *format() const { return (format_); }
  66. /** Sets the format string for the value. */
  67. void format(const char *f) { format_ = f; update(); }
  68. /** Gets the maximum value of the widget. */
  69. double maximum() const { return (maximum_); }
  70. /** Sets the maximum value of the widget. */
  71. void maximum(double m) { maximum_ = m; }
  72. /** Gets the minimum value of the widget. */
  73. double minimum() const { return (minimum_); }
  74. /** Sets the minimum value of the widget. */
  75. void minimum(double m) { minimum_ = m; }
  76. /** Sets the minimum and maximum values for the widget. */
  77. void range(double a, double b) { minimum_ = a; maximum_ = b; }
  78. // Sets the amount to change the value when the user clicks a button.
  79. // Docs in src/Fl_Spinner.cxx
  80. void step(double s);
  81. /**
  82. Gets the amount to change the value when the user clicks a button.
  83. \see Fl_Spinner::step(double)
  84. */
  85. double step() const { return (step_); }
  86. /** Sets whether the spinner wraps around at upper and lower bounds.
  87. If wrap mode is on the spinner value is set to the minimum() or
  88. maximum() if the value exceeds the upper or lower bounds, resp., if
  89. it was changed by one of the buttons or the FL_Up or FL_Down keys.
  90. The spinner stops at the upper and lower bounds if wrap mode is off.
  91. The default wrap mode is on for backwards compatibility with
  92. FLTK 1.3.x and older versions.
  93. \note Wrap mode does not apply to the input field if the input value
  94. is edited directly as a number. The input value is always
  95. clipped to the allowed range as if wrap mode was off when the
  96. input field is left (i.e. loses focus).
  97. \see minimum(), maximum()
  98. \param[in] set non-zero sets wrap mode, zero resets wrap mode
  99. \since 1.4.0
  100. */
  101. void wrap(int set) { wrap_ = set ? 1 : 0; }
  102. /** Gets the wrap mode of the Fl_Spinner widget.
  103. \see void wrap(int)
  104. \since 1.4.0
  105. */
  106. int wrap() const { return wrap_; }
  107. /** Gets the color of the text in the input field. */
  108. Fl_Color textcolor() const { return (input_.textcolor()); }
  109. /** Sets the color of the text in the input field. */
  110. void textcolor(Fl_Color c) { input_.textcolor(c); }
  111. /** Gets the font of the text in the input field. */
  112. Fl_Font textfont() const { return (input_.textfont()); }
  113. /** Sets the font of the text in the input field. */
  114. void textfont(Fl_Font f) { input_.textfont(f); }
  115. /** Gets the size of the text in the input field. */
  116. Fl_Fontsize textsize() const { return (input_.textsize()); }
  117. /** Sets the size of the text in the input field. */
  118. void textsize(Fl_Fontsize s) { input_.textsize(s); }
  119. // Sets the numeric representation in the input field.
  120. // Docs see src/Fl_Spinner.cxx
  121. void type(uchar v);
  122. /** Gets the numeric representation in the input field.
  123. \see Fl_Spinner::type(uchar)
  124. */
  125. uchar type() const { return (input_.type()); }
  126. /** Gets the current value of the widget. */
  127. double value() const { return (value_); }
  128. /**
  129. Sets the current value of the input widget.
  130. Before setting value to a non-integer value, the spinner
  131. type() should be changed to floating point.
  132. */
  133. void value(double v) { value_ = v; update(); }
  134. /**
  135. Sets the background color of the spinner widget's input field.
  136. */
  137. void color(Fl_Color v) { input_.color(v); }
  138. /**
  139. Returns the background color of the spinner widget's input field.
  140. */
  141. Fl_Color color() const { return(input_.color()); }
  142. /**
  143. Sets the selection color of the spinner widget's input field.
  144. */
  145. void selection_color(Fl_Color val) { input_.selection_color(val); }
  146. /**
  147. Returns the selection color of the spinner widget's input field.
  148. */
  149. Fl_Color selection_color() const { return input_.selection_color(); }
  150. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Spinner, Fl_Group)
  151. };
  152. #endif // !Fl_Spinner_H
  153. //
  154. // End of "$Id: Fl_Spinner.H 12313 2017-07-12 21:51:42Z AlbrechtS $".
  155. //