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