spinctrl.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: spinctrl.h
  3. // Purpose: interface of wxSpinCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxSpinCtrl
  9. wxSpinCtrl combines wxTextCtrl and wxSpinButton in one control.
  10. @beginStyleTable
  11. @style{wxSP_ARROW_KEYS}
  12. The user can use arrow keys to change the value.
  13. @style{wxSP_WRAP}
  14. The value wraps at the minimum and maximum.
  15. @style{wxTE_PROCESS_ENTER}
  16. Indicates that the control should generate @c wxEVT_TEXT_ENTER
  17. events. Using this style will prevent the user from using the Enter key
  18. for dialog navigation (e.g. activating the default button in the
  19. dialog) under MSW.
  20. @style{wxALIGN_LEFT}
  21. Same as wxTE_LEFT for wxTextCtrl: the text is left aligned.
  22. @style{wxALIGN_CENTRE_HORIZONTAL}
  23. Same as wxTE_CENTRE for wxTextCtrl: the text is centered.
  24. @style{wxALIGN_RIGHT}
  25. Same as wxTE_RIGHT for wxTextCtrl: the text is right aligned (this is
  26. the default).
  27. @endStyleTable
  28. @beginEventEmissionTable{wxSpinEvent}
  29. @event{EVT_SPINCTRL(id, func)}
  30. Process a wxEVT_SPINCTRL event, which is generated
  31. whenever the numeric value of the spin control is updated.
  32. @endEventTable
  33. You may also use the wxSpinButton event macros, however the corresponding events
  34. will not be generated under all platforms. Finally, if the user modifies the
  35. text in the edit part of the spin control directly, the EVT_TEXT is generated,
  36. like for the wxTextCtrl. When the use enters text into the text area, the text
  37. is not validated until the control loses focus (e.g. by using the TAB key).
  38. The value is then adjusted to the range and a wxSpinEvent sent then if the value
  39. is different from the last value sent.
  40. @library{wxcore}
  41. @category{ctrl}
  42. @appearance{spinctrl}
  43. @see wxSpinButton, wxSpinCtrlDouble, wxControl
  44. */
  45. class wxSpinCtrl : public wxControl
  46. {
  47. public:
  48. /**
  49. Default constructor.
  50. */
  51. wxSpinCtrl();
  52. /**
  53. Constructor, creating and showing a spin control.
  54. If @a value is non-empty, it will be shown in the text entry part of
  55. the control and if it has numeric value, the initial numeric value of
  56. the control, as returned by GetValue() will also be determined by it
  57. instead of by @a initial. Hence, it only makes sense to specify @a
  58. initial if @a value is an empty string or is not convertible to a
  59. number, otherwise @a initial is simply ignored and the number specified
  60. by @a value is used.
  61. @param parent
  62. Parent window. Must not be @NULL.
  63. @param value
  64. Default value (as text).
  65. @param id
  66. Window identifier. The value wxID_ANY indicates a default value.
  67. @param pos
  68. Window position.
  69. If ::wxDefaultPosition is specified then a default position is chosen.
  70. @param size
  71. Window size.
  72. If ::wxDefaultSize is specified then a default size is chosen.
  73. @param style
  74. Window style. See wxSpinButton.
  75. @param min
  76. Minimal value.
  77. @param max
  78. Maximal value.
  79. @param initial
  80. Initial value.
  81. @param name
  82. Window name.
  83. @see Create()
  84. */
  85. wxSpinCtrl(wxWindow* parent, wxWindowID id = wxID_ANY,
  86. const wxString& value = wxEmptyString,
  87. const wxPoint& pos = wxDefaultPosition,
  88. const wxSize& size = wxDefaultSize,
  89. long style = wxSP_ARROW_KEYS,
  90. int min = 0, int max = 100,
  91. int initial = 0, const wxString& name = "wxSpinCtrl");
  92. /**
  93. Creation function called by the spin control constructor.
  94. See wxSpinCtrl() for details.
  95. */
  96. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  97. const wxString& value = wxEmptyString,
  98. const wxPoint& pos = wxDefaultPosition,
  99. const wxSize& size = wxDefaultSize,
  100. long style = wxSP_ARROW_KEYS, int min = 0, int max = 100,
  101. int initial = 0, const wxString& name = "wxSpinCtrl");
  102. /**
  103. Returns the numerical base being currently used, 10 by default.
  104. @see SetBase()
  105. @since 2.9.5
  106. */
  107. int GetBase() const;
  108. /**
  109. Gets maximal allowable value.
  110. */
  111. int GetMax() const;
  112. /**
  113. Gets minimal allowable value.
  114. */
  115. int GetMin() const;
  116. /**
  117. Gets the value of the spin control.
  118. */
  119. int GetValue() const;
  120. /**
  121. Sets the base to use for the numbers in this control.
  122. Currently the only supported values are 10 (which is the default) and
  123. 16.
  124. Changing the base allows the user to enter the numbers in the specified
  125. base, e.g. with "0x" prefix for hexadecimal numbers, and also displays
  126. the numbers in the specified base when they are changed using the spin
  127. control arrows.
  128. @param base
  129. Numeric base, currently only 10 and 16 are supported.
  130. @return
  131. @true if the base was successfully changed or @false if it failed,
  132. usually meaning that either the base is not 10 or 16.
  133. @since 2.9.5
  134. */
  135. bool SetBase(int base);
  136. /**
  137. Sets range of allowable values.
  138. Notice that calling this method may change the value of the control if
  139. it's not inside the new valid range, e.g. it will become @a minVal if
  140. it is less than it now. However no @c wxEVT_SPINCTRL
  141. event is generated, even if it the value does change.
  142. */
  143. void SetRange(int minVal, int maxVal);
  144. /**
  145. Select the text in the text part of the control between positions
  146. @a from (inclusive) and @a to (exclusive).
  147. This is similar to wxTextCtrl::SetSelection().
  148. @note this is currently only implemented for Windows and generic versions
  149. of the control.
  150. */
  151. virtual void SetSelection(long from, long to);
  152. /**
  153. Sets the value of the spin control.
  154. It is recommended to use the overload taking an integer value instead.
  155. Notice that, unlike wxTextCtrl::SetValue(), but like most of the other
  156. setter methods in wxWidgets, calling this method does not generate any
  157. events as events are only generated for the user actions.
  158. */
  159. virtual void SetValue(const wxString& text);
  160. /**
  161. Sets the value of the spin control.
  162. Calling this method doesn't generate any @c wxEVT_SPINCTRL events.
  163. */
  164. void SetValue(int value);
  165. };
  166. /**
  167. @class wxSpinCtrlDouble
  168. wxSpinCtrlDouble combines wxTextCtrl and wxSpinButton in one control and
  169. displays a real number. (wxSpinCtrl displays an integer.)
  170. @beginStyleTable
  171. @style{wxSP_ARROW_KEYS}
  172. The user can use arrow keys to change the value.
  173. @style{wxSP_WRAP}
  174. The value wraps at the minimum and maximum.
  175. @endStyleTable
  176. @beginEventEmissionTable{wxSpinDoubleEvent}
  177. @event{EVT_SPINCTRLDOUBLE(id, func)}
  178. Generated whenever the numeric value of the spin control is changed,
  179. that is, when the up/down spin button is clicked, when ENTER is pressed,
  180. or the control loses focus and the new value is different from the last.
  181. See wxSpinDoubleEvent.
  182. @endEventTable
  183. @library{wxcore}
  184. @category{ctrl}
  185. @appearance{spinctrldouble}
  186. @see wxSpinButton, wxSpinCtrl, wxControl
  187. */
  188. class wxSpinCtrlDouble : public wxControl
  189. {
  190. public:
  191. /**
  192. Default constructor.
  193. */
  194. wxSpinCtrlDouble();
  195. /**
  196. Constructor, creating and showing a spin control.
  197. @param parent
  198. Parent window. Must not be @NULL.
  199. @param value
  200. Default value (as text).
  201. @param id
  202. Window identifier. The value wxID_ANY indicates a default value.
  203. @param pos
  204. Window position.
  205. If ::wxDefaultPosition is specified then a default position is chosen.
  206. @param size
  207. Window size.
  208. If ::wxDefaultSize is specified then a default size is chosen.
  209. @param style
  210. Window style. See wxSpinButton.
  211. @param min
  212. Minimal value.
  213. @param max
  214. Maximal value.
  215. @param initial
  216. Initial value.
  217. @param inc
  218. Increment value.
  219. @param name
  220. Window name.
  221. @see Create()
  222. */
  223. wxSpinCtrlDouble(wxWindow* parent, wxWindowID id = -1,
  224. const wxString& value = wxEmptyString,
  225. const wxPoint& pos = wxDefaultPosition,
  226. const wxSize& size = wxDefaultSize,
  227. long style = wxSP_ARROW_KEYS,
  228. double min = 0, double max = 100,
  229. double initial = 0, double inc = 1,
  230. const wxString& name = wxT("wxSpinCtrlDouble"));
  231. /**
  232. Creation function called by the spin control constructor.
  233. See wxSpinCtrlDouble() for details.
  234. */
  235. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  236. const wxString& value = wxEmptyString,
  237. const wxPoint& pos = wxDefaultPosition,
  238. const wxSize& size = wxDefaultSize,
  239. long style = wxSP_ARROW_KEYS, double min = 0, double max = 100,
  240. double initial = 0, double inc = 1,
  241. const wxString& name = "wxSpinCtrlDouble");
  242. /**
  243. Gets the number of digits in the display.
  244. */
  245. unsigned int GetDigits() const;
  246. /**
  247. Gets the increment value.
  248. */
  249. double GetIncrement() const;
  250. /**
  251. Gets maximal allowable value.
  252. */
  253. double GetMax() const;
  254. /**
  255. Gets minimal allowable value.
  256. */
  257. double GetMin() const;
  258. /**
  259. Gets the value of the spin control.
  260. */
  261. double GetValue() const;
  262. /**
  263. Sets the number of digits in the display.
  264. */
  265. void SetDigits(unsigned int digits);
  266. /**
  267. Sets the increment value.
  268. @note You may also need to increase the number of visible digits
  269. using SetDigits
  270. */
  271. void SetIncrement(double inc);
  272. /**
  273. Sets range of allowable values.
  274. */
  275. void SetRange(double minVal, double maxVal);
  276. /**
  277. Sets the value of the spin control.
  278. It is recommended to use the overload taking a double value instead.
  279. Notice that, unlike wxTextCtrl::SetValue(), but like most of the other
  280. setter methods in wxWidgets, calling this method does not generate any
  281. events as events are only generated for the user actions.
  282. */
  283. virtual void SetValue(const wxString& text);
  284. /**
  285. Sets the value of the spin control.
  286. Calling this method doesn't generate any @c wxEVT_SPINCTRLDOUBLE events.
  287. */
  288. void SetValue(double value);
  289. };
  290. /**
  291. @class wxSpinDoubleEvent
  292. This event class is used for the events generated by wxSpinCtrlDouble.
  293. @beginEventTable{wxSpinDoubleEvent}
  294. @event{EVT_SPINCTRLDOUBLE(id, func)}
  295. Generated whenever the numeric value of the spin control is changed,
  296. that is, when the up/down spin button is clicked, when ENTER is pressed,
  297. or the control loses focus and the new value is different from the last.
  298. See wxSpinDoubleEvent.
  299. @endEventTable
  300. @library{wxcore}
  301. @category{events}
  302. @see wxSpinCtrlDouble
  303. */
  304. class wxSpinDoubleEvent : public wxNotifyEvent
  305. {
  306. public:
  307. /**
  308. The constructor. Not normally used by the user code.
  309. */
  310. wxSpinDoubleEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
  311. double value = 0);
  312. /**
  313. The copy constructor.
  314. */
  315. wxSpinDoubleEvent(const wxSpinDoubleEvent& event);
  316. /**
  317. Returns the value associated with this spin control event.
  318. */
  319. double GetValue() const;
  320. /**
  321. Set the value associated with the event.
  322. (Not normally used by user code.)
  323. */
  324. void SetValue(double value);
  325. };
  326. wxEventType wxEVT_SPINCTRL;
  327. wxEventType wxEVT_SPINCTRLDOUBLE;