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