slider.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: slider.h
  3. // Purpose: interface of wxSlider
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxSL_HORIZONTAL wxHORIZONTAL /* 0x0004 */
  8. #define wxSL_VERTICAL wxVERTICAL /* 0x0008 */
  9. #define wxSL_TICKS 0x0010
  10. #define wxSL_AUTOTICKS wxSL_TICKS // we don't support manual ticks
  11. #define wxSL_LEFT 0x0040
  12. #define wxSL_TOP 0x0080
  13. #define wxSL_RIGHT 0x0100
  14. #define wxSL_BOTTOM 0x0200
  15. #define wxSL_BOTH 0x0400
  16. #define wxSL_SELRANGE 0x0800
  17. #define wxSL_INVERSE 0x1000
  18. #define wxSL_MIN_MAX_LABELS 0x2000
  19. #define wxSL_VALUE_LABEL 0x4000
  20. #define wxSL_LABELS (wxSL_MIN_MAX_LABELS|wxSL_VALUE_LABEL)
  21. /**
  22. @class wxSlider
  23. A slider is a control with a handle which can be pulled back and forth to
  24. change the value.
  25. On Windows, the track bar control is used.
  26. Slider generates the same events as wxScrollBar but in practice the most
  27. convenient way to process wxSlider updates is by handling the
  28. slider-specific @c wxEVT_SLIDER event which carries wxCommandEvent
  29. containing just the latest slider position.
  30. @beginStyleTable
  31. @style{wxSL_HORIZONTAL}
  32. Displays the slider horizontally (this is the default).
  33. @style{wxSL_VERTICAL}
  34. Displays the slider vertically.
  35. @style{wxSL_AUTOTICKS}
  36. Displays tick marks. Windows only.
  37. @style{wxSL_MIN_MAX_LABELS}
  38. Displays minimum, maximum labels (new since wxWidgets 2.9.1).
  39. @style{wxSL_VALUE_LABEL}
  40. Displays value label (new since wxWidgets 2.9.1).
  41. @style{wxSL_LABELS}
  42. Displays minimum, maximum and value labels (same as wxSL_VALUE_LABEL
  43. and wxSL_MIN_MAX_LABELS together).
  44. @style{wxSL_LEFT}
  45. Displays ticks on the left and forces the slider to be vertical.
  46. @style{wxSL_RIGHT}
  47. Displays ticks on the right and forces the slider to be vertical.
  48. @style{wxSL_TOP}
  49. Displays ticks on the top.
  50. @style{wxSL_BOTTOM}
  51. Displays ticks on the bottom (this is the default).
  52. @style{wxSL_SELRANGE}
  53. Allows the user to select a range on the slider. Windows only.
  54. @style{wxSL_INVERSE}
  55. Inverses the minimum and maximum endpoints on the slider. Not
  56. compatible with wxSL_SELRANGE.
  57. @endStyleTable
  58. Notice that @c wxSL_LEFT, @c wxSL_TOP, @c wxSL_RIGHT and @c wxSL_BOTTOM
  59. specify the position of the slider ticks in MSW implementation and that the
  60. slider labels, if any, are positioned on the opposite side. So, to have a
  61. label on the left side of a vertical slider, @b wxSL_RIGHT must be used (or
  62. none of these styles at all should be specified as left and top are default
  63. positions for the vertical and horizontal sliders respectively).
  64. @beginEventEmissionTable{wxScrollEvent}
  65. You can use EVT_COMMAND_SCROLL... macros with window IDs for when intercepting
  66. scroll events from controls, or EVT_SCROLL... macros without window IDs for
  67. intercepting scroll events from the receiving window -- except for this,
  68. the macros behave exactly the same.
  69. @event{EVT_SCROLL(func)}
  70. Process all scroll events.
  71. @event{EVT_SCROLL_TOP(func)}
  72. Process @c wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
  73. @event{EVT_SCROLL_BOTTOM(func)}
  74. Process @c wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
  75. @event{EVT_SCROLL_LINEUP(func)}
  76. Process @c wxEVT_SCROLL_LINEUP line up events.
  77. @event{EVT_SCROLL_LINEDOWN(func)}
  78. Process @c wxEVT_SCROLL_LINEDOWN line down events.
  79. @event{EVT_SCROLL_PAGEUP(func)}
  80. Process @c wxEVT_SCROLL_PAGEUP page up events.
  81. @event{EVT_SCROLL_PAGEDOWN(func)}
  82. Process @c wxEVT_SCROLL_PAGEDOWN page down events.
  83. @event{EVT_SCROLL_THUMBTRACK(func)}
  84. Process @c wxEVT_SCROLL_THUMBTRACK thumbtrack events
  85. (frequent events sent as the user drags the thumbtrack).
  86. @event{EVT_SCROLL_THUMBRELEASE(func)}
  87. Process @c wxEVT_SCROLL_THUMBRELEASE thumb release events.
  88. @event{EVT_SCROLL_CHANGED(func)}
  89. Process @c wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
  90. @event{EVT_COMMAND_SCROLL(id, func)}
  91. Process all scroll events.
  92. @event{EVT_COMMAND_SCROLL_TOP(id, func)}
  93. Process @c wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
  94. @event{EVT_COMMAND_SCROLL_BOTTOM(id, func)}
  95. Process @c wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
  96. @event{EVT_COMMAND_SCROLL_LINEUP(id, func)}
  97. Process @c wxEVT_SCROLL_LINEUP line up events.
  98. @event{EVT_COMMAND_SCROLL_LINEDOWN(id, func)}
  99. Process @c wxEVT_SCROLL_LINEDOWN line down events.
  100. @event{EVT_COMMAND_SCROLL_PAGEUP(id, func)}
  101. Process @c wxEVT_SCROLL_PAGEUP page up events.
  102. @event{EVT_COMMAND_SCROLL_PAGEDOWN(id, func)}
  103. Process @c wxEVT_SCROLL_PAGEDOWN page down events.
  104. @event{EVT_COMMAND_SCROLL_THUMBTRACK(id, func)}
  105. Process @c wxEVT_SCROLL_THUMBTRACK thumbtrack events
  106. (frequent events sent as the user drags the thumbtrack).
  107. @event{EVT_COMMAND_SCROLL_THUMBRELEASE(func)}
  108. Process @c wxEVT_SCROLL_THUMBRELEASE thumb release events.
  109. @event{EVT_COMMAND_SCROLL_CHANGED(func)}
  110. Process @c wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
  111. @event{EVT_SLIDER(id, func)}
  112. Process @c wxEVT_SLIDER which is generated after any
  113. change of wxSlider position in addition to one of the events above.
  114. Notice that the handler of this event receives a wxCommandEvent as
  115. argument and not wxScrollEvent, as all the other handlers.
  116. @endEventTable
  117. @section slider_diff The difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED
  118. The EVT_SCROLL_THUMBRELEASE event is only emitted when actually dragging the
  119. thumb using the mouse and releasing it (This EVT_SCROLL_THUMBRELEASE event
  120. is also followed by an EVT_SCROLL_CHANGED event).
  121. The EVT_SCROLL_CHANGED event also occurs when using the keyboard to change
  122. the thumb position, and when clicking next to the thumb
  123. (In all these cases the EVT_SCROLL_THUMBRELEASE event does not happen).
  124. In short, the EVT_SCROLL_CHANGED event is triggered when scrolling/ moving
  125. has finished independently of the way it had started.
  126. Please see the widgets sample ("Slider" page) to see the difference between
  127. EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED in action.
  128. @library{wxcore}
  129. @category{ctrl}
  130. @appearance{slider}
  131. @see @ref overview_events, wxScrollBar
  132. */
  133. class wxSlider : public wxControl
  134. {
  135. public:
  136. /**
  137. Default constructor
  138. */
  139. wxSlider();
  140. /**
  141. Constructor, creating and showing a slider.
  142. @param parent
  143. Parent window. Must not be @NULL.
  144. @param id
  145. Window identifier. The value wxID_ANY indicates a default value.
  146. @param value
  147. Initial position for the slider.
  148. @param minValue
  149. Minimum slider position.
  150. @param maxValue
  151. Maximum slider position.
  152. @param pos
  153. Window position.
  154. If ::wxDefaultPosition is specified then a default position is chosen.
  155. @param size
  156. Window size.
  157. If ::wxDefaultSize is specified then a default size is chosen.
  158. @param style
  159. Window style. See wxSlider.
  160. @param validator
  161. Window validator.
  162. @param name
  163. Window name.
  164. @see Create(), wxValidator
  165. */
  166. wxSlider(wxWindow* parent, wxWindowID id, int value,
  167. int minValue, int maxValue,
  168. const wxPoint& pos = wxDefaultPosition,
  169. const wxSize& size = wxDefaultSize,
  170. long style = wxSL_HORIZONTAL,
  171. const wxValidator& validator = wxDefaultValidator,
  172. const wxString& name = wxSliderNameStr);
  173. /**
  174. Destructor, destroying the slider.
  175. */
  176. virtual ~wxSlider();
  177. /**
  178. Clears the selection, for a slider with the @b wxSL_SELRANGE style.
  179. @onlyfor{wxmsw}
  180. */
  181. virtual void ClearSel();
  182. /**
  183. Clears the ticks.
  184. @onlyfor{wxmsw}
  185. */
  186. virtual void ClearTicks();
  187. /**
  188. Used for two-step slider construction.
  189. See wxSlider() for further details.
  190. */
  191. bool Create(wxWindow* parent, wxWindowID id, int value, int minValue,
  192. int maxValue, const wxPoint& point = wxDefaultPosition,
  193. const wxSize& size = wxDefaultSize, long style = wxSL_HORIZONTAL,
  194. const wxValidator& validator = wxDefaultValidator,
  195. const wxString& name = wxSliderNameStr);
  196. /**
  197. Returns the line size.
  198. @see SetLineSize()
  199. */
  200. virtual int GetLineSize() const;
  201. /**
  202. Gets the maximum slider value.
  203. @see GetMin(), SetRange()
  204. */
  205. virtual int GetMax() const;
  206. /**
  207. Gets the minimum slider value.
  208. @see GetMin(), SetRange()
  209. */
  210. virtual int GetMin() const;
  211. /**
  212. Returns the page size.
  213. @see SetPageSize()
  214. */
  215. virtual int GetPageSize() const;
  216. /**
  217. Returns the selection end point.
  218. @onlyfor{wxmsw}
  219. @see GetSelStart(), SetSelection()
  220. */
  221. virtual int GetSelEnd() const;
  222. /**
  223. Returns the selection start point.
  224. @onlyfor{wxmsw}
  225. @see GetSelEnd(), SetSelection()
  226. */
  227. virtual int GetSelStart() const;
  228. /**
  229. Returns the thumb length.
  230. @onlyfor{wxmsw}
  231. @see SetThumbLength()
  232. */
  233. virtual int GetThumbLength() const;
  234. /**
  235. Returns the tick frequency.
  236. @onlyfor{wxmsw}
  237. @see SetTickFreq()
  238. */
  239. virtual int GetTickFreq() const;
  240. /**
  241. Gets the current slider value.
  242. @see GetMin(), GetMax(), SetValue()
  243. */
  244. virtual int GetValue() const;
  245. /**
  246. Sets the line size for the slider.
  247. @param lineSize
  248. The number of steps the slider moves when the user moves it up
  249. or down a line.
  250. @see GetLineSize()
  251. */
  252. virtual void SetLineSize(int lineSize);
  253. /**
  254. Sets the minimum slider value.
  255. @param minValue
  256. The new bottom end of the slider range.
  257. @see GetMin(), SetRange()
  258. */
  259. void SetMin( int minValue );
  260. /**
  261. Sets the maximum slider value.
  262. @param maxValue
  263. The new top end of the slider range.
  264. @see GetMax(), SetRange()
  265. */
  266. void SetMax( int maxValue );
  267. /**
  268. Sets the page size for the slider.
  269. @param pageSize
  270. The number of steps the slider moves when the user pages up or down.
  271. @see GetPageSize()
  272. */
  273. virtual void SetPageSize(int pageSize);
  274. /**
  275. Sets the minimum and maximum slider values.
  276. @see GetMin(), GetMax()
  277. */
  278. virtual void SetRange(int minValue, int maxValue);
  279. /**
  280. Sets the selection.
  281. @param startPos
  282. The selection start position.
  283. @param endPos
  284. The selection end position.
  285. @onlyfor{wxmsw}
  286. @see GetSelStart(), GetSelEnd()
  287. */
  288. virtual void SetSelection(int startPos, int endPos);
  289. /**
  290. Sets the slider thumb length.
  291. @param len
  292. The thumb length.
  293. @onlyfor{wxmsw}
  294. @see GetThumbLength()
  295. */
  296. virtual void SetThumbLength(int len);
  297. /**
  298. Sets a tick position.
  299. @param tickPos
  300. The tick position.
  301. @onlyfor{wxmsw}
  302. @see SetTickFreq()
  303. */
  304. virtual void SetTick(int tickPos);
  305. /**
  306. Sets the tick mark frequency and position.
  307. @param n
  308. Frequency. For example, if the frequency is set to two, a tick mark is
  309. displayed for every other increment in the slider's range.
  310. @onlyfor{wxmsw}
  311. @see GetTickFreq()
  312. */
  313. virtual void SetTickFreq(int n);
  314. /**
  315. Sets the slider position.
  316. @param value
  317. The slider position.
  318. */
  319. virtual void SetValue(int value);
  320. };