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