slider.h 12 KB

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