scrolbar.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: scrolbar.h
  3. // Purpose: interface of wxScrollBar
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxScrollBar
  9. A wxScrollBar is a control that represents a horizontal or vertical scrollbar.
  10. It is distinct from the two scrollbars that some windows provide automatically,
  11. but the two types of scrollbar share the way events are received.
  12. @remarks
  13. A scrollbar has the following main attributes: range, thumb size, page size, and position.
  14. The range is the total number of units associated with the view represented by the scrollbar.
  15. For a table with 15 columns, the range would be 15.
  16. The thumb size is the number of units that are currently visible.
  17. For the table example, the window might be sized so that only 5 columns are
  18. currently visible, in which case the application would set the thumb size to 5.
  19. When the thumb size becomes the same as or greater than the range, the scrollbar
  20. will be automatically hidden on most platforms.
  21. The page size is the number of units that the scrollbar should scroll by,
  22. when 'paging' through the data. This value is normally the same as the thumb
  23. size length, because it is natural to assume that the visible window size defines a page.
  24. The scrollbar position is the current thumb position.
  25. Most applications will find it convenient to provide a function called AdjustScrollbars()
  26. which can be called initially, from an OnSize event handler, and whenever the
  27. application data changes in size. It will adjust the view, object and page
  28. size according to the size of the window and the size of the data.
  29. @beginStyleTable
  30. @style{wxSB_HORIZONTAL}
  31. Specifies a horizontal scrollbar.
  32. @style{wxSB_VERTICAL}
  33. Specifies a vertical scrollbar.
  34. @endStyleTable
  35. @beginEventEmissionTable{wxScrollEvent}
  36. You can use EVT_COMMAND_SCROLL... macros with window IDs for when intercepting
  37. scroll events from controls, or EVT_SCROLL... macros without window IDs for
  38. intercepting scroll events from the receiving window -- except for this,
  39. the macros behave exactly the same.
  40. @event{EVT_SCROLL(func)}
  41. Process all scroll events.
  42. @event{EVT_SCROLL_TOP(func)}
  43. Process @c wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
  44. @event{EVT_SCROLL_BOTTOM(func)}
  45. Process @c wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
  46. @event{EVT_SCROLL_LINEUP(func)}
  47. Process @c wxEVT_SCROLL_LINEUP line up events.
  48. @event{EVT_SCROLL_LINEDOWN(func)}
  49. Process @c wxEVT_SCROLL_LINEDOWN line down events.
  50. @event{EVT_SCROLL_PAGEUP(func)}
  51. Process @c wxEVT_SCROLL_PAGEUP page up events.
  52. @event{EVT_SCROLL_PAGEDOWN(func)}
  53. Process @c wxEVT_SCROLL_PAGEDOWN page down events.
  54. @event{EVT_SCROLL_THUMBTRACK(func)}
  55. Process @c wxEVT_SCROLL_THUMBTRACK thumbtrack events
  56. (frequent events sent as the user drags the thumbtrack).
  57. @event{EVT_SCROLL_THUMBRELEASE(func)}
  58. Process @c wxEVT_SCROLL_THUMBRELEASE thumb release events.
  59. @event{EVT_SCROLL_CHANGED(func)}
  60. Process @c wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
  61. @event{EVT_COMMAND_SCROLL(id, func)}
  62. Process all scroll events.
  63. @event{EVT_COMMAND_SCROLL_TOP(id, func)}
  64. Process @c wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
  65. @event{EVT_COMMAND_SCROLL_BOTTOM(id, func)}
  66. Process @c wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
  67. @event{EVT_COMMAND_SCROLL_LINEUP(id, func)}
  68. Process @c wxEVT_SCROLL_LINEUP line up events.
  69. @event{EVT_COMMAND_SCROLL_LINEDOWN(id, func)}
  70. Process @c wxEVT_SCROLL_LINEDOWN line down events.
  71. @event{EVT_COMMAND_SCROLL_PAGEUP(id, func)}
  72. Process @c wxEVT_SCROLL_PAGEUP page up events.
  73. @event{EVT_COMMAND_SCROLL_PAGEDOWN(id, func)}
  74. Process @c wxEVT_SCROLL_PAGEDOWN page down events.
  75. @event{EVT_COMMAND_SCROLL_THUMBTRACK(id, func)}
  76. Process @c wxEVT_SCROLL_THUMBTRACK thumbtrack events
  77. (frequent events sent as the user drags the thumbtrack).
  78. @event{EVT_COMMAND_SCROLL_THUMBRELEASE(func)}
  79. Process @c wxEVT_SCROLL_THUMBRELEASE thumb release events.
  80. @event{EVT_COMMAND_SCROLL_CHANGED(func)}
  81. Process @c wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
  82. @endEventTable
  83. @section scrollbar_diff The difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED
  84. The EVT_SCROLL_THUMBRELEASE event is only emitted when actually dragging the
  85. thumb using the mouse and releasing it (This EVT_SCROLL_THUMBRELEASE event
  86. is also followed by an EVT_SCROLL_CHANGED event).
  87. The EVT_SCROLL_CHANGED event also occurs when using the keyboard to change
  88. the thumb position, and when clicking next to the thumb
  89. (In all these cases the EVT_SCROLL_THUMBRELEASE event does not happen).
  90. In short, the EVT_SCROLL_CHANGED event is triggered when scrolling/moving has
  91. finished independently of the way it had started. Please see the widgets sample
  92. ("Slider" page) to see the difference between EVT_SCROLL_THUMBRELEASE and
  93. EVT_SCROLL_CHANGED in action.
  94. @library{wxcore}
  95. @category{ctrl}
  96. @appearance{scrollbar}
  97. @see @ref overview_scrolling, @ref overview_events, wxScrolled
  98. */
  99. class wxScrollBar : public wxControl
  100. {
  101. public:
  102. /**
  103. Default constructor
  104. */
  105. wxScrollBar();
  106. /**
  107. Constructor, creating and showing a scrollbar.
  108. @param parent
  109. Parent window. Must be non-@NULL.
  110. @param id
  111. Window identifier. The value wxID_ANY indicates a default value.
  112. @param pos
  113. Window position.
  114. If ::wxDefaultPosition is specified then a default position is chosen.
  115. @param size
  116. Window size.
  117. If ::wxDefaultSize is specified then a default size is chosen.
  118. @param style
  119. Window style. See wxScrollBar.
  120. @param validator
  121. Window validator.
  122. @param name
  123. Window name.
  124. @see Create(), wxValidator
  125. */
  126. wxScrollBar(wxWindow* parent, wxWindowID id,
  127. const wxPoint& pos = wxDefaultPosition,
  128. const wxSize& size = wxDefaultSize,
  129. long style = wxSB_HORIZONTAL,
  130. const wxValidator& validator = wxDefaultValidator,
  131. const wxString& name = wxScrollBarNameStr);
  132. /**
  133. Destructor, destroying the scrollbar.
  134. */
  135. virtual ~wxScrollBar();
  136. /**
  137. Scrollbar creation function called by the scrollbar constructor.
  138. See wxScrollBar() for details.
  139. */
  140. bool Create(wxWindow* parent, wxWindowID id,
  141. const wxPoint& pos = wxDefaultPosition,
  142. const wxSize& size = wxDefaultSize, long style = wxSB_HORIZONTAL,
  143. const wxValidator& validator = wxDefaultValidator,
  144. const wxString& name = wxScrollBarNameStr);
  145. /**
  146. Returns the page size of the scrollbar.
  147. This is the number of scroll units that will be scrolled when the user
  148. pages up or down. Often it is the same as the thumb size.
  149. @see SetScrollbar()
  150. */
  151. virtual int GetPageSize() const;
  152. /**
  153. Returns the length of the scrollbar.
  154. @see SetScrollbar()
  155. */
  156. virtual int GetRange() const;
  157. /**
  158. Returns the current position of the scrollbar thumb.
  159. @see SetThumbPosition()
  160. */
  161. virtual int GetThumbPosition() const;
  162. /**
  163. Returns the thumb or 'view' size.
  164. @see SetScrollbar()
  165. */
  166. virtual int GetThumbSize() const;
  167. /**
  168. Sets the scrollbar properties.
  169. @param position
  170. The position of the scrollbar in scroll units.
  171. @param thumbSize
  172. The size of the thumb, or visible portion of the scrollbar, in scroll units.
  173. @param range
  174. The maximum position of the scrollbar.
  175. @param pageSize
  176. The size of the page size in scroll units. This is the number of units
  177. the scrollbar will scroll when it is paged up or down.
  178. Often it is the same as the thumb size.
  179. @param refresh
  180. @true to redraw the scrollbar, @false otherwise.
  181. @remarks
  182. Let's say you wish to display 50 lines of text, using the same
  183. font. The window is sized so that you can only see 16 lines at a time.
  184. You would use:
  185. @code
  186. scrollbar->SetScrollbar(0, 16, 50, 15);
  187. @endcode
  188. The page size is 1 less than the thumb size so that the last line of
  189. the previous page will be visible on the next page, to help orient the user.
  190. Note that with the window at this size, the thumb position can never
  191. go above 50 minus 16, or 34.
  192. You can determine how many lines are currently visible by dividing
  193. the current view size by the character height in pixels.
  194. When defining your own scrollbar behaviour, you will always need to
  195. recalculate the scrollbar settings when the window size changes.
  196. You could therefore put your scrollbar calculations and SetScrollbar()
  197. call into a function named AdjustScrollbars, which can be called
  198. initially and also from a wxSizeEvent event handler function.
  199. */
  200. virtual void SetScrollbar(int position, int thumbSize, int range,
  201. int pageSize,
  202. bool refresh = true);
  203. /**
  204. Sets the position of the scrollbar.
  205. @param viewStart
  206. The position of the scrollbar thumb.
  207. @see GetThumbPosition()
  208. */
  209. virtual void SetThumbPosition(int viewStart);
  210. /**
  211. Returns @true for scrollbars that have the vertical style set.
  212. */
  213. bool IsVertical() const;
  214. };