Fl_Value_Input.H 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // "$Id: Fl_Value_Input.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Value input 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_Value_Input widget . */
  20. #ifndef Fl_Value_Input_H
  21. #define Fl_Value_Input_H
  22. #include "Fl_Valuator.H"
  23. #include "Fl_Input.H"
  24. /**
  25. The Fl_Value_Input widget displays a numeric value.
  26. The user can click in the text field and edit it - there is in
  27. fact a hidden Fl_Input widget with
  28. type(FL_FLOAT_INPUT) or type(FL_INT_INPUT) in
  29. there - and when they hit return or tab the value updates to
  30. what they typed and the callback is done.
  31. <P>If step() is non-zero and integral, then the range of numbers
  32. is limited to integers instead of floating point numbers. As
  33. well as displaying the value as an integer, typed input is also
  34. limited to integer values, even if the hidden Fl_Input widget
  35. is of type(FL_FLOAT_INPUT).</P>
  36. <P>If step() is non-zero, the user can also drag the
  37. mouse across the object and thus slide the value. The left
  38. button moves one step() per pixel, the middle by 10
  39. * step(), and the right button by 100 * step(). It
  40. is therefore impossible to select text by dragging across it,
  41. although clicking can still move the insertion cursor.</P>
  42. <P>If step() is non-zero and integral, then the range
  43. of numbers are limited to integers instead of floating point
  44. values.
  45. <P ALIGN="CENTER">\image html Fl_Value_Input.png
  46. \image latex Fl_Value_Input.png "Fl_Value_Input" width=4cm
  47. */
  48. class FL_EXPORT Fl_Value_Input : public Fl_Valuator {
  49. public:
  50. /* This is the encapsulated Fl_input attribute to which
  51. this class delegates the value font, color and shortcut */
  52. Fl_Input input;
  53. private:
  54. char soft_;
  55. static void input_cb(Fl_Widget*,void*);
  56. virtual void value_damage(); // cause damage() due to value() changing
  57. public:
  58. int handle(int);
  59. protected:
  60. void draw();
  61. public:
  62. void resize(int,int,int,int);
  63. Fl_Value_Input(int x,int y,int w,int h,const char *l=0);
  64. ~Fl_Value_Input();
  65. /** See void Fl_Value_Input::soft(char s) */
  66. void soft(char s) {soft_ = s;}
  67. /**
  68. If "soft" is turned on, the user is allowed to drag
  69. the value outside the range. If they drag the value to one of
  70. the ends, let go, then grab again and continue to drag, they can
  71. get to any value. The default is true.
  72. */
  73. char soft() const {return soft_;}
  74. /**
  75. Returns the current shortcut key for the Input.
  76. \see Fl_Value_Input::shortcut(int)
  77. */
  78. int shortcut() const {return input.shortcut();}
  79. /**
  80. Sets the shortcut key to \p s. Setting this
  81. overrides the use of '&' in the label(). The value is a bitwise
  82. OR of a key and a set of shift flags, for example FL_ALT | 'a'
  83. , FL_ALT | (FL_F + 10), or just 'a'. A value
  84. of 0 disables the shortcut.
  85. The key can be any value returned by
  86. Fl::event_key(), but will usually be an ASCII letter. Use
  87. a lower-case letter unless you require the shift key to be held down.
  88. The shift flags can be any set of values accepted by
  89. Fl::event_state(). If the bit is on that shift key must
  90. be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in
  91. the shift flags (zero for the other bits indicates a "don't care"
  92. setting).
  93. */
  94. void shortcut(int s) {input.shortcut(s);}
  95. /** Gets the typeface of the text in the value box. */
  96. Fl_Font textfont() const {return input.textfont();}
  97. /** Sets the typeface of the text in the value box. */
  98. void textfont(Fl_Font s) {input.textfont(s);}
  99. /** Gets the size of the text in the value box. */
  100. Fl_Fontsize textsize() const {return input.textsize();}
  101. /** Sets the size of the text in the value box. */
  102. void textsize(Fl_Fontsize s) {input.textsize(s);}
  103. /** Gets the color of the text in the value box. */
  104. Fl_Color textcolor() const {return input.textcolor();}
  105. /** Sets the color of the text in the value box.*/
  106. void textcolor(Fl_Color n) {input.textcolor(n);}
  107. /** Gets the color of the text cursor. The text cursor is black by default. */
  108. Fl_Color cursor_color() const {return input.cursor_color();}
  109. /** Sets the color of the text cursor. The text cursor is black by default. */
  110. void cursor_color(Fl_Color n) {input.cursor_color(n);}
  111. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Value_Input, Fl_Valuator)
  112. };
  113. #endif
  114. //
  115. // End of "$Id: Fl_Value_Input.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
  116. //