]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: scrolwin.h | |
f09b5681 | 3 | // Purpose: interface of wxScrolled template |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
6362d82b VZ |
9 | /** |
10 | Possible values for the second argument of wxScrolled::ShowScrollbars(). | |
11 | */ | |
12 | enum wxScrollbarVisibility | |
13 | { | |
14 | wxSHOW_SB_NEVER = -1, ///< Never show the scrollbar at all. | |
15 | wxSHOW_SB_DEFAULT, ///< Show scrollbar only if it is needed. | |
16 | wxSHOW_SB_ALWAYS ///< Always show scrollbar, even if not needed. | |
17 | }; | |
18 | ||
23324ae1 | 19 | /** |
7c913512 | 20 | |
f09b5681 | 21 | The wxScrolled class manages scrolling for its client area, transforming |
23324ae1 FM |
22 | the coordinates according to the scrollbar positions, and setting the |
23 | scroll positions, thumb sizes and ranges according to the area in view. | |
7c913512 | 24 | |
16361ec9 VS |
25 | There are two commonly used (but not the only possible!) specializations of |
26 | this class: | |
27 | ||
28 | - ::wxScrolledWindow, aka wxScrolled<wxPanel>, is equivalent to | |
29 | ::wxScrolledWindow from earlier versions. Derived from wxPanel, it shares | |
30 | wxPanel's behaviour with regard to TAB traversal and focus handling. Use | |
d2ddc77d | 31 | this if the scrolled window will have child controls. |
16361ec9 VS |
32 | |
33 | - ::wxScrolledCanvas, aka wxScrolled<wxWindow>, derives from wxWindow and | |
34 | so doesn't handle children specially. This is suitable e.g. for | |
d13b34d3 | 35 | implementing scrollable controls such as tree or list controls. |
16361ec9 | 36 | |
23324ae1 | 37 | Starting from version 2.4 of wxWidgets, there are several ways to use a |
d2ddc77d RR |
38 | ::wxScrolledWindow (and now wxScrolled). In particular, there are |
39 | three ways to set the size of the scrolling area: | |
7c913512 | 40 | |
16361ec9 VS |
41 | One way is to set the scrollbars directly using a call to SetScrollbars(). |
42 | This is the way it used to be in any previous version of wxWidgets and it | |
43 | will be kept for backwards compatibility. | |
7c913512 | 44 | |
23324ae1 FM |
45 | An additional method of manual control, which requires a little less |
46 | computation of your own, is to set the total size of the scrolling area by | |
16361ec9 VS |
47 | calling either wxWindow::SetVirtualSize(), or wxWindow::FitInside(), and |
48 | setting the scrolling increments for it by calling SetScrollRate(). | |
23324ae1 FM |
49 | Scrolling in some orientation is enabled by setting a non-zero increment |
50 | for it. | |
7c913512 | 51 | |
23324ae1 | 52 | The most automatic and newest way is to simply let sizers determine the |
16361ec9 | 53 | scrolling area. This is now the default when you set an interior sizer into |
f09b5681 | 54 | a wxScrolled with wxWindow::SetSizer(). The scrolling area will be |
16361ec9 VS |
55 | set to the size requested by the sizer and the scrollbars will be assigned |
56 | for each orientation according to the need for them and the scrolling | |
57 | increment set by SetScrollRate(). As above, scrolling is only enabled in | |
58 | orientations with a non-zero increment. You can influence the minimum size | |
59 | of the scrolled area controlled by a sizer by calling | |
60 | wxWindow::SetVirtualSizeHints(). (Calling SetScrollbars() has analogous | |
61 | effects in wxWidgets 2.4 -- in later versions it may not continue to | |
62 | override the sizer.) | |
63 | ||
64 | Note that if maximum size hints are still supported by | |
65 | wxWindow::SetVirtualSizeHints(), use them at your own dire risk. They may | |
66 | or may not have been removed for 2.4, but it really only makes sense to set | |
67 | minimum size hints here. We should probably replace | |
68 | wxWindow::SetVirtualSizeHints() with wxWindow::SetMinVirtualSize() or | |
69 | similar and remove it entirely in future. | |
70 | ||
3e0e3895 FM |
71 | @todo review docs for this class replacing SetVirtualSizeHints() with |
72 | SetMinClientSize(). | |
73 | ||
f09b5681 BP |
74 | As with all windows, an application can draw onto a wxScrolled using a |
75 | @ref overview_dc "device context". | |
7c913512 | 76 | |
16361ec9 | 77 | You have the option of handling the OnPaint handler or overriding the |
f09b5681 BP |
78 | wxScrolled::OnDraw() function, which is passed a pre-scrolled device |
79 | context (prepared by wxScrolled::DoPrepareDC()). | |
16361ec9 VS |
80 | |
81 | If you don't wish to calculate your own scrolling, you must call | |
82 | DoPrepareDC() when not drawing from within OnDraw(), to set the device | |
83 | origin for the device context according to the current scroll position. | |
84 | ||
f09b5681 | 85 | A wxScrolled will normally scroll itself and therefore its child windows |
16361ec9 VS |
86 | as well. It might however be desired to scroll a different window than |
87 | itself: e.g. when designing a spreadsheet, you will normally only have to | |
88 | scroll the (usually white) cell area, whereas the (usually grey) label area | |
89 | will scroll very differently. For this special purpose, you can call | |
90 | SetTargetWindow() which means that pressing the scrollbars will scroll a | |
91 | different window. | |
92 | ||
93 | Note that the underlying system knows nothing about scrolling coordinates, | |
94 | so that all system functions (mouse events, expose events, refresh calls | |
95 | etc) as well as the position of subwindows are relative to the "physical" | |
96 | origin of the scrolled window. If the user insert a child window at | |
23324ae1 | 97 | position (10,10) and scrolls the window down 100 pixels (moving the child |
16361ec9 VS |
98 | window out of the visible area), the child window will report a position |
99 | of (10,-90). | |
7c913512 | 100 | |
23324ae1 | 101 | @beginStyleTable |
8c6791e4 | 102 | @style{wxRETAINED} |
23324ae1 FM |
103 | Uses a backing pixmap to speed refreshes. Motif only. |
104 | @endStyleTable | |
7c913512 | 105 | |
2e8c12bc VZ |
106 | |
107 | @beginEventEmissionTable{wxScrollWinEvent} | |
108 | @event{EVT_SCROLLWIN(func)} | |
109 | Process all scroll events. | |
110 | @event{EVT_SCROLLWIN_TOP(func)} | |
111 | Process @c wxEVT_SCROLLWIN_TOP scroll-to-top events. | |
112 | @event{EVT_SCROLLWIN_BOTTOM(func)} | |
113 | Process @c wxEVT_SCROLLWIN_BOTTOM scroll-to-bottom events. | |
114 | @event{EVT_SCROLLWIN_LINEUP(func)} | |
115 | Process @c wxEVT_SCROLLWIN_LINEUP line up events. | |
116 | @event{EVT_SCROLLWIN_LINEDOWN(func)} | |
117 | Process @c wxEVT_SCROLLWIN_LINEDOWN line down events. | |
118 | @event{EVT_SCROLLWIN_PAGEUP(func)} | |
119 | Process @c wxEVT_SCROLLWIN_PAGEUP page up events. | |
120 | @event{EVT_SCROLLWIN_PAGEDOWN(func)} | |
121 | Process @c wxEVT_SCROLLWIN_PAGEDOWN page down events. | |
122 | @event{EVT_SCROLLWIN_THUMBTRACK(func)} | |
123 | Process @c wxEVT_SCROLLWIN_THUMBTRACK thumbtrack events | |
124 | (frequent events sent as the user drags the thumbtrack). | |
125 | @event{EVT_SCROLLWIN_THUMBRELEASE(func)} | |
126 | Process @c wxEVT_SCROLLWIN_THUMBRELEASE thumb release events. | |
127 | @endEventTable | |
128 | ||
129 | @note | |
130 | Don't confuse wxScrollWinEvents generated by this class with | |
131 | wxScrollEvent objects generated by wxScrollBar and wxSlider. | |
132 | ||
133 | ||
16361ec9 | 134 | @remarks |
f09b5681 BP |
135 | Use wxScrolled for applications where the user scrolls by a fixed amount, |
136 | and where a 'page' can be interpreted to be the current visible portion of | |
137 | the window. For more sophisticated applications, use the wxScrolled | |
138 | implementation as a guide to build your own scroll behaviour or use | |
139 | wxVScrolledWindow or its variants. | |
16361ec9 | 140 | |
d2ddc77d | 141 | @since The wxScrolled template exists since version 2.9.0. In older versions, |
f09b5681 BP |
142 | only ::wxScrolledWindow (equivalent of wxScrolled<wxPanel>) was |
143 | available. | |
16361ec9 | 144 | |
23324ae1 FM |
145 | @library{wxcore} |
146 | @category{miscwnd} | |
7c913512 | 147 | |
16361ec9 VS |
148 | @see wxScrollBar, wxClientDC, wxPaintDC, |
149 | wxVScrolledWindow, wxHScrolledWindow, wxHVScrolledWindow, | |
23324ae1 | 150 | */ |
16361ec9 VS |
151 | template<class T> |
152 | class wxScrolled : public T | |
23324ae1 FM |
153 | { |
154 | public: | |
16361ec9 VS |
155 | /// Default constructor. |
156 | wxScrolled(); | |
157 | ||
23324ae1 FM |
158 | /** |
159 | Constructor. | |
3c4f71cc | 160 | |
7c913512 | 161 | @param parent |
4cc4bfaf | 162 | Parent window. |
7c913512 | 163 | @param id |
16361ec9 | 164 | Window identifier. The value @c wxID_ANY indicates a default value. |
7c913512 | 165 | @param pos |
76e2b570 | 166 | Window position. If a position of ::wxDefaultPosition is specified |
16361ec9 | 167 | then a default position is chosen. |
7c913512 | 168 | @param size |
76e2b570 | 169 | Window size. If a size of ::wxDefaultSize is specified then the |
16361ec9 | 170 | window is sized appropriately. |
7c913512 | 171 | @param style |
f09b5681 | 172 | Window style. See wxScrolled. |
7c913512 | 173 | @param name |
4cc4bfaf | 174 | Window name. |
3c4f71cc | 175 | |
16361ec9 VS |
176 | @remarks The window is initially created without visible scrollbars. |
177 | Call SetScrollbars() to specify how big the virtual window | |
178 | size should be. | |
23324ae1 | 179 | */ |
16361ec9 VS |
180 | wxScrolled(wxWindow* parent, wxWindowID id = -1, |
181 | const wxPoint& pos = wxDefaultPosition, | |
182 | const wxSize& size = wxDefaultSize, | |
183 | long style = wxHSCROLL | wxVSCROLL, | |
184 | const wxString& name = "scrolledWindow"); | |
23324ae1 | 185 | |
23324ae1 FM |
186 | |
187 | /** | |
16361ec9 VS |
188 | Translates the logical coordinates to the device ones. For example, if |
189 | a window is scrolled 10 pixels to the bottom, the device coordinates of | |
190 | the origin are (0, 0) (as always), but the logical coordinates are (0, | |
191 | 10) and so the call to CalcScrolledPosition(0, 10, xx, yy) will return | |
192 | 0 in yy. | |
3c4f71cc | 193 | |
1058f652 MB |
194 | @beginWxPerlOnly |
195 | In wxPerl this method takes two parameters and returns a | |
196 | 2-element list (xx, yy). | |
197 | @endWxPerlOnly | |
198 | ||
4cc4bfaf | 199 | @see CalcUnscrolledPosition() |
23324ae1 | 200 | */ |
328f5751 | 201 | void CalcScrolledPosition(int x, int y, int* xx, int* yy) const; |
23324ae1 FM |
202 | |
203 | /** | |
16361ec9 VS |
204 | Translates the device coordinates to the logical ones. For example, if |
205 | a window is scrolled 10 pixels to the bottom, the device coordinates of | |
206 | the origin are (0, 0) (as always), but the logical coordinates are (0, | |
207 | 10) and so the call to CalcUnscrolledPosition(0, 0, xx, yy) will return | |
208 | 10 in yy. | |
3c4f71cc | 209 | |
1058f652 MB |
210 | @beginWxPerlOnly |
211 | In wxPerl this method takes two parameters and returns a | |
212 | 2-element list (xx, yy). | |
213 | @endWxPerlOnly | |
214 | ||
4cc4bfaf | 215 | @see CalcScrolledPosition() |
23324ae1 | 216 | */ |
328f5751 | 217 | void CalcUnscrolledPosition(int x, int y, int* xx, int* yy) const; |
23324ae1 FM |
218 | |
219 | /** | |
220 | Creates the window for two-step construction. Derived classes | |
f09b5681 | 221 | should call or replace this function. See wxScrolled::wxScrolled() |
23324ae1 FM |
222 | for details. |
223 | */ | |
224 | bool Create(wxWindow* parent, wxWindowID id = -1, | |
225 | const wxPoint& pos = wxDefaultPosition, | |
226 | const wxSize& size = wxDefaultSize, | |
4cc4bfaf | 227 | long style = wxHSCROLL | wxVSCROLL, |
23324ae1 FM |
228 | const wxString& name = "scrolledWindow"); |
229 | ||
d6a658ff VZ |
230 | /** |
231 | Disable use of keyboard keys for scrolling. | |
232 | ||
233 | By default cursor movement keys (including Home, End, Page Up and Down) | |
234 | are used to scroll the window appropriately. If the derived class uses | |
235 | these keys for something else, e.g. changing the currently selected | |
236 | item, this function can be used to disable this behaviour as it's not | |
237 | only not necessary then but can actually be actively harmful if another | |
238 | object forwards a keyboard event corresponding to one of the above keys | |
239 | to us using ProcessWindowEvent() because the event will always be | |
240 | processed which can be undesirable. | |
241 | ||
242 | @since 2.9.1 | |
243 | */ | |
244 | void DisableKeyboardScrolling(); | |
245 | ||
23324ae1 | 246 | /** |
16361ec9 VS |
247 | Call this function to prepare the device context for drawing a scrolled |
248 | image. | |
249 | ||
250 | It sets the device origin according to the current scroll position. | |
60a14f1b VZ |
251 | DoPrepareDC() is called automatically within the default @c wxEVT_PAINT |
252 | event handler, so your OnDraw() override will be passed an already | |
16361ec9 | 253 | 'pre-scrolled' device context. However, if you wish to draw from |
60a14f1b VZ |
254 | outside of OnDraw() (e.g. from your own @c wxEVT_PAINT handler), you |
255 | must call this function yourself. | |
16361ec9 VS |
256 | |
257 | For example: | |
258 | @code | |
259 | void MyWindow::OnEvent(wxMouseEvent& event) | |
260 | { | |
261 | wxClientDC dc(this); | |
262 | DoPrepareDC(dc); | |
263 | ||
264 | dc.SetPen(*wxBLACK_PEN); | |
265 | float x, y; | |
266 | event.Position(&x, &y); | |
267 | if (xpos > -1 && ypos > -1 && event.Dragging()) | |
268 | { | |
269 | dc.DrawLine(xpos, ypos, x, y); | |
270 | } | |
271 | xpos = x; | |
272 | ypos = y; | |
273 | } | |
274 | @endcode | |
275 | ||
60a14f1b VZ |
276 | Notice that the function sets the origin by moving it relatively to the |
277 | current origin position, so you shouldn't change the origin before | |
278 | calling DoPrepareDC() or, if you do, reset it to (0, 0) later. If you | |
279 | call DoPrepareDC() immediately after device context creation, as in the | |
280 | example above, this problem doesn't arise, of course, so it is | |
281 | customary to do it like this. | |
23324ae1 FM |
282 | */ |
283 | void DoPrepareDC(wxDC& dc); | |
284 | ||
285 | /** | |
286 | Enable or disable physical scrolling in the given direction. Physical | |
287 | scrolling is the physical transfer of bits up or down the | |
288 | screen when a scroll event occurs. If the application scrolls by a | |
289 | variable amount (e.g. if there are different font sizes) then physical | |
290 | scrolling will not work, and you should switch it off. Note that you | |
291 | will have to reposition child windows yourself, if physical scrolling | |
292 | is disabled. | |
3c4f71cc | 293 | |
7c913512 | 294 | @param xScrolling |
4cc4bfaf | 295 | If @true, enables physical scrolling in the x direction. |
7c913512 | 296 | @param yScrolling |
4cc4bfaf | 297 | If @true, enables physical scrolling in the y direction. |
3c4f71cc | 298 | |
23324ae1 | 299 | @remarks Physical scrolling may not be available on all platforms. Where |
4cc4bfaf | 300 | it is available, it is enabled by default. |
23324ae1 FM |
301 | */ |
302 | void EnableScrolling(bool xScrolling, bool yScrolling); | |
303 | ||
6362d82b VZ |
304 | /** |
305 | Set the scrollbar visibility. | |
306 | ||
307 | By default the scrollbar in the corresponding direction is only shown | |
308 | if it is needed, i.e. if the virtual size of the scrolled window in | |
309 | this direction is greater than the current physical window size. Using | |
310 | this function the scrollbar visibility can be changed to be: | |
311 | - wxSHOW_SB_ALWAYS: To always show the scrollbar, even if it is | |
312 | not needed currently (wxALWAYS_SHOW_SB style can be used during | |
313 | the window creation to achieve the same effect but it applies | |
314 | in both directions). | |
315 | - wxSHOW_SB_NEVER: To never show the scrollbar at all. In this case | |
316 | the program should presumably provide some other way for the | |
317 | user to scroll the window. | |
318 | - wxSHOW_SB_DEFAULT: To restore the default behaviour described | |
319 | above. | |
320 | ||
321 | @param horz | |
322 | The desired visibility for the horizontal scrollbar. | |
323 | @param vert | |
324 | The desired visibility for the vertical scrollbar. | |
325 | ||
326 | @since 2.9.0 | |
327 | */ | |
328 | void ShowScrollbars(wxScrollbarVisibility horz, wxScrollbarVisibility vert); | |
329 | ||
23324ae1 | 330 | /** |
16361ec9 VS |
331 | Get the number of pixels per scroll unit (line), in each direction, as |
332 | set by SetScrollbars(). A value of zero indicates no scrolling in that | |
333 | direction. | |
3c4f71cc | 334 | |
7c913512 | 335 | @param xUnit |
4cc4bfaf | 336 | Receives the number of pixels per horizontal unit. |
7c913512 | 337 | @param yUnit |
4cc4bfaf | 338 | Receives the number of pixels per vertical unit. |
3c4f71cc | 339 | |
1058f652 MB |
340 | @beginWxPerlOnly |
341 | In wxPerl this method takes no parameters and returns a | |
342 | 2-element list (xUnit, yUnit). | |
343 | @endWxPerlOnly | |
344 | ||
4cc4bfaf | 345 | @see SetScrollbars(), GetVirtualSize() |
23324ae1 | 346 | */ |
328f5751 | 347 | void GetScrollPixelsPerUnit(int* xUnit, int* yUnit) const; |
23324ae1 FM |
348 | |
349 | /** | |
350 | Get the position at which the visible portion of the window starts. | |
3c4f71cc | 351 | |
7c913512 | 352 | @param x |
4cc4bfaf | 353 | Receives the first visible x position in scroll units. |
7c913512 | 354 | @param y |
4cc4bfaf | 355 | Receives the first visible y position in scroll units. |
3c4f71cc | 356 | |
f8f31de6 FM |
357 | @remarks |
358 | If either of the scrollbars is not at the home position, @a x | |
359 | and/or @a y will be greater than zero. | |
360 | Combined with wxWindow::GetClientSize(), the application can use this | |
361 | function to efficiently redraw only the visible portion of the window. | |
362 | The positions are in logical scroll units, not pixels, so to convert | |
363 | to pixels you will have to multiply by the number of pixels per scroll | |
364 | increment. | |
3c4f71cc | 365 | |
1058f652 MB |
366 | @beginWxPerlOnly |
367 | In wxPerl this method takes no parameters and returns a | |
368 | 2-element list (x, y). | |
369 | @endWxPerlOnly | |
370 | ||
0b0f6f87 | 371 | @see SetScrollbars(), Scroll() |
23324ae1 | 372 | */ |
328f5751 | 373 | void GetViewStart(int* x, int* y) const; |
f8f31de6 FM |
374 | |
375 | /** | |
376 | This is a simple overload of GetViewStart(int*,int*); see that function | |
377 | for more info. | |
378 | */ | |
0b0f6f87 | 379 | wxPoint GetViewStart() const; |
23324ae1 FM |
380 | |
381 | /** | |
382 | Gets the size in device units of the scrollable window area (as | |
383 | opposed to the client size, which is the area of the window currently | |
384 | visible). | |
3c4f71cc | 385 | |
7c913512 | 386 | @param x |
4cc4bfaf | 387 | Receives the length of the scrollable window, in pixels. |
7c913512 | 388 | @param y |
4cc4bfaf | 389 | Receives the height of the scrollable window, in pixels. |
3c4f71cc | 390 | |
16361ec9 | 391 | @remarks Use wxDC::DeviceToLogicalX() and wxDC::DeviceToLogicalY() to |
4cc4bfaf | 392 | translate these units to logical units. |
3c4f71cc | 393 | |
1058f652 MB |
394 | @beginWxPerlOnly |
395 | In wxPerl this method takes no parameters and returns a | |
396 | 2-element list (xUnit, yUnit). | |
397 | @endWxPerlOnly | |
398 | ||
4cc4bfaf | 399 | @see SetScrollbars(), GetScrollPixelsPerUnit() |
23324ae1 | 400 | */ |
328f5751 | 401 | void GetVirtualSize(int* x, int* y) const; |
23324ae1 FM |
402 | |
403 | /** | |
404 | Motif only: @true if the window has a backing bitmap. | |
405 | */ | |
328f5751 | 406 | bool IsRetained() const; |
23324ae1 FM |
407 | |
408 | /** | |
16361ec9 VS |
409 | Called by the default paint event handler to allow the application to |
410 | define painting behaviour without having to worry about calling | |
23324ae1 | 411 | DoPrepareDC(). |
16361ec9 VS |
412 | |
413 | Instead of overriding this function you may also just process the paint | |
414 | event in the derived class as usual, but then you will have to call | |
415 | DoPrepareDC() yourself. | |
23324ae1 FM |
416 | */ |
417 | virtual void OnDraw(wxDC& dc); | |
418 | ||
419 | /** | |
7c913512 | 420 | This function is for backwards compatibility only and simply calls |
16361ec9 VS |
421 | DoPrepareDC() now. Notice that it is not called by the default paint |
422 | event handle (DoPrepareDC() is), so overriding this method in your | |
423 | derived class is useless. | |
23324ae1 FM |
424 | */ |
425 | void PrepareDC(wxDC& dc); | |
426 | ||
427 | /** | |
428 | Scrolls a window so the view start is at the given point. | |
3c4f71cc | 429 | |
7c913512 | 430 | @param x |
4cc4bfaf | 431 | The x position to scroll to, in scroll units. |
7c913512 | 432 | @param y |
4cc4bfaf | 433 | The y position to scroll to, in scroll units. |
3c4f71cc | 434 | |
23324ae1 | 435 | @remarks The positions are in scroll units, not pixels, so to convert to |
4cc4bfaf | 436 | pixels you will have to multiply by the number of |
0b0f6f87 | 437 | pixels per scroll increment. If either parameter is |
f8f31de6 | 438 | ::wxDefaultCoord (-1), that position will be ignored (no change |
0b0f6f87 | 439 | in that direction). |
3c4f71cc | 440 | |
4cc4bfaf | 441 | @see SetScrollbars(), GetScrollPixelsPerUnit() |
23324ae1 FM |
442 | */ |
443 | void Scroll(int x, int y); | |
f8f31de6 FM |
444 | |
445 | /** | |
446 | This is an overload of Scroll(int,int); see that function for more info. | |
447 | */ | |
0b0f6f87 | 448 | void Scroll(const wxPoint& pt); |
23324ae1 FM |
449 | |
450 | /** | |
16361ec9 VS |
451 | Set the horizontal and vertical scrolling increment only. See the |
452 | pixelsPerUnit parameter in SetScrollbars(). | |
23324ae1 FM |
453 | */ |
454 | void SetScrollRate(int xstep, int ystep); | |
455 | ||
456 | /** | |
457 | Sets up vertical and/or horizontal scrollbars. | |
3c4f71cc | 458 | |
16361ec9 VS |
459 | The first pair of parameters give the number of pixels per 'scroll |
460 | step', i.e. amount moved when the up or down scroll arrows are pressed. | |
461 | The second pair gives the length of scrollbar in scroll steps, which | |
462 | sets the size of the virtual window. | |
463 | ||
464 | @a xPos and @a yPos optionally specify a position to scroll to | |
465 | immediately. | |
466 | ||
467 | For example, the following gives a window horizontal and vertical | |
468 | scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 | |
469 | pixels) in each direction: | |
470 | @code | |
471 | window->SetScrollbars(20, 20, 50, 50); | |
472 | @endcode | |
473 | ||
f09b5681 | 474 | wxScrolled manages the page size itself, using the current client |
16361ec9 VS |
475 | window size as the page size. |
476 | ||
477 | Note that for more sophisticated scrolling applications, for example | |
478 | where scroll steps may be variable according to the position in the | |
479 | document, it will be necessary to derive a new class from wxWindow, | |
480 | overriding OnSize() and adjusting the scrollbars appropriately. | |
481 | ||
7c913512 | 482 | @param pixelsPerUnitX |
4cc4bfaf | 483 | Pixels per scroll unit in the horizontal direction. |
7c913512 | 484 | @param pixelsPerUnitY |
4cc4bfaf | 485 | Pixels per scroll unit in the vertical direction. |
7c913512 | 486 | @param noUnitsX |
4cc4bfaf | 487 | Number of units in the horizontal direction. |
7c913512 | 488 | @param noUnitsY |
4cc4bfaf | 489 | Number of units in the vertical direction. |
7c913512 | 490 | @param xPos |
16361ec9 VS |
491 | Position to initialize the scrollbars in the horizontal direction, |
492 | in scroll units. | |
7c913512 | 493 | @param yPos |
16361ec9 VS |
494 | Position to initialize the scrollbars in the vertical direction, in |
495 | scroll units. | |
7c913512 | 496 | @param noRefresh |
4cc4bfaf | 497 | Will not refresh window if @true. |
3c4f71cc | 498 | |
16361ec9 | 499 | @see wxWindow::SetVirtualSize() |
23324ae1 FM |
500 | */ |
501 | void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, | |
502 | int noUnitsX, | |
503 | int noUnitsY, | |
504 | int xPos = 0, | |
505 | int yPos = 0, | |
4cc4bfaf | 506 | bool noRefresh = false); |
23324ae1 FM |
507 | |
508 | /** | |
1d7b600d VZ |
509 | Call this function to tell wxScrolled to perform the actual scrolling |
510 | on a different window (and not on itself). | |
511 | ||
512 | This method is useful when only a part of the window should be | |
513 | scrolled. A typical example is a control consisting of a fixed header | |
514 | and the scrollable contents window: the scrollbars are attached to the | |
515 | main window itself, hence it, and not the contents window must be | |
516 | derived from wxScrolled, but only the contents window scrolls when the | |
517 | scrollbars are used. To implement such setup, you need to call this | |
518 | method with the contents window as argument. | |
519 | ||
520 | Notice that if this method is used, GetSizeAvailableForScrollTarget() | |
521 | method must be overridden. | |
23324ae1 | 522 | */ |
1d7b600d | 523 | void SetTargetWindow(wxWindow *window); |
7cab9c41 RD |
524 | wxWindow *GetTargetWindow() const; |
525 | ||
526 | ||
527 | void SetTargetRect(const wxRect& rect); | |
528 | wxRect GetTargetRect() const; | |
529 | ||
530 | int GetScrollPageSize(int orient) const; | |
531 | void SetScrollPageSize(int orient, int pageSize); | |
532 | int GetScrollLines( int orient ) const; | |
533 | void SetScale(double xs, double ys); | |
534 | double GetScaleX() const; | |
535 | double GetScaleY() const; | |
536 | ||
537 | virtual void AdjustScrollbars(); | |
538 | bool IsAutoScrolling() const; | |
539 | void StopAutoScrolling(); | |
1d7b600d VZ |
540 | |
541 | protected: | |
542 | /** | |
543 | Function which must be overridden to implement the size available for | |
544 | the scroll target for the given size of the main window. | |
545 | ||
546 | This method must be overridden if SetTargetWindow() is used (it is | |
547 | never called otherwise). The implementation should decrease the @a size | |
548 | to account for the size of the non-scrollable parts of the main window | |
549 | and return only the size available for the scrollable window itself. | |
550 | E.g. in the example given in SetTargetWindow() documentation the | |
551 | function would subtract the height of the header window from the | |
552 | vertical component of @a size. | |
553 | */ | |
554 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); | |
23324ae1 | 555 | }; |
e54c96f1 | 556 | |
16361ec9 VS |
557 | |
558 | /** | |
559 | Scrolled window derived from wxPanel. | |
560 | ||
f09b5681 | 561 | See wxScrolled for detailed description. |
16361ec9 VS |
562 | |
563 | @note Note that because this class derives from wxPanel, it shares its | |
4c51a665 | 564 | behaviour with regard to TAB traversal and focus handling (in |
16361ec9 VS |
565 | particular, it forwards focus to its children). If you don't want |
566 | this behaviour, use ::wxScrolledCanvas instead. | |
567 | ||
f09b5681 | 568 | @note ::wxScrolledWindow is an alias for wxScrolled<wxPanel> since version |
16361ec9 VS |
569 | 2.9.0. In older versions, it was a standalone class. |
570 | ||
571 | @library{wxcore} | |
572 | @category{miscwnd} | |
573 | ||
f09b5681 | 574 | @see wxScrolled, ::wxScrolledCanvas |
16361ec9 VS |
575 | */ |
576 | typedef wxScrolled<wxPanel> wxScrolledWindow; | |
577 | ||
578 | /** | |
579 | Alias for wxScrolled<wxWindow>. Scrolled window that doesn't have children | |
580 | and so doesn't need or want special handling of TAB traversal. | |
581 | ||
582 | @since 2.9.0 | |
583 | ||
584 | @library{wxcore} | |
585 | @category{miscwnd} | |
586 | ||
587 | @see wxScrolled, ::wxScrolledWindow | |
588 | */ | |
589 | typedef wxScrolled<wxWindow> wxScrolledCanvas; |