]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/scrolwin.tex
moved wxJoystick, wxWave and wxTaskBarIcon to wxAdv
[wxWidgets.git] / docs / latex / wx / scrolwin.tex
CommitLineData
a660d684
KB
1\section{\class{wxScrolledWindow}}\label{wxscrolledwindow}
2
3The wxScrolledWindow class manages scrolling for its client area, transforming
4the coordinates according to the scrollbar positions, and setting the
5scroll positions, thumb sizes and ranges according to the area in view.
6
2b5f62a0
VZ
7Starting from version 2.4 of wxWindows, there are several ways to use a
8wxScrolledWindow. In particular, there are now three ways to set the
9size of the scrolling area:
10
11One way is to set the scrollbars directly using a call to
12\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}.
13This is the way it used to be in any previous version of wxWindows
14and it will be kept for backwards compatibility.
15
16An additional method of manual control, which requires a little less
17computation of your own, is to set the total size of the scrolling area by
18calling either \helpref{wxWindow::SetVirtualSize}{wxwindowsetvirtualsize},
19or \helpref{wxWindow::FitInside}{wxwindowfitinside}, and setting the
52ee2268 20scrolling increments for it by calling
2b5f62a0
VZ
21\helpref{wxScrolledWindow::SetScrollRate}{wxscrolledwindowsetscrollrate}.
22Scrolling in some orientation is enabled by setting a non zero increment
23for it.
24
25The most automatic and newest way is to simply let sizers determine the
26scrolling area. This is now the default when you set an interior sizer
27into a wxScrolledWindow with \helpref{wxWindow::SetSizer}{wxwindowsetsizer}.
28The scrolling area will be set to the size requested by the sizer and
29the scrollbars will be assigned for each orientation according to the need
30for them and the scrolling increment set by
31\helpref{wxScrolledWindow::SetScrollRate}{wxscrolledwindowsetscrollrate}.
32As above, scrolling is only enabled in orientations with a non-zero
33increment. You can influence the minimum size of the scrolled area
34controlled by a sizer by calling
35\helpref{wxWindow::SetVirtualSizeHints}{wxwindowsetvirtualsizehints}.
36(calling \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}
37 has analogous effects in wxWindows 2.4 -- in later versions it may not continue
38 to override the sizer)
39
40Note: if Maximum size hints are still supported by SetVirtualSizeHints, use
41them at your own dire risk. They may or may not have been removed for 2.4,
42but it really only makes sense to set minimum size hints here. We should
43probably replace SetVirtualSizeHints with SetMinVirtualSize or similar
44and remove it entirely in future.
45
46As with all windows, an application can draw onto a wxScrolledWindow using
47a \helpref{device context}{dcoverview}.
a660d684 48
d7cb14ce 49You have the option of handling the OnPaint handler
a660d684
KB
50or overriding the \helpref{OnDraw}{wxscrolledwindowondraw} function, which is passed
51a pre-scrolled device context (prepared by \helpref{PrepareDC}{wxscrolledwindowpreparedc}).
52
53If you don't wish to calculate your own scrolling, you must call PrepareDC when not drawing from
54within OnDraw, to set the device origin for the device context according to the current
55scroll position.
56
30760ce7
RR
57A wxScrolledWindow will normally scroll itself and therefore its child windows as well. It
58might however be desired to scroll a different window than itself: e.g. when designing a
f6bcfd97 59spreadsheet, you will normally only have to scroll the (usually white) cell area, whereas the
30760ce7
RR
60(usually grey) label area will scroll very differently. For this special purpose, you can
61call \helpref{SetTargetWindow}{wxscrolledwindowsettargetwindow} which means that pressing
62the scrollbars will scroll a different window.
63
27d029c7 64Note that the underlying system knows nothing about scrolling coordinates, so that all system
b32c6ff0 65functions (mouse events, expose events, refresh calls etc) as well as the position of subwindows
27d029c7
RR
66are relative to the "physical" origin of the scrolled window. If the user insert a child window at
67position (10,10) and scrolls the window down 100 pixels (moving the child window out of the visible
68area), the child window will report a position of (10,-90).
69
30760ce7 70
a660d684
KB
71\wxheading{Derived from}
72
ad9edf45 73\helpref{wxPanel}{wxpanel}\\
a660d684
KB
74\helpref{wxWindow}{wxwindow}\\
75\helpref{wxEvtHandler}{wxevthandler}\\
76\helpref{wxObject}{wxobject}
77
954b8ae6
JS
78\wxheading{Include files}
79
80<wx/scrolwin.h>
81
a660d684
KB
82\wxheading{Window styles}
83
84\twocolwidtha{5cm}
85\begin{twocollist}\itemsep=0pt
86\twocolitem{\windowstyle{wxRETAINED}}{Uses a backing pixmap to speed refreshes. Motif only.}
87\end{twocollist}
88
89See also \helpref{window styles overview}{windowstyles}.
90
91\wxheading{Remarks}
92
93Use wxScrolledWindow for applications where the user scrolls by a fixed amount, and
94where a `page' can be interpreted to be the current visible portion of the window. For
95more sophisticated applications, use the wxScrolledWindow implementation as a guide
96to build your own scroll behaviour.
97
98\wxheading{See also}
99
cf7d6329
VZ
100\helpref{wxScrollBar}{wxscrollbar}, \helpref{wxClientDC}{wxclientdc},\\
101\helpref{wxPaintDC}{wxpaintdc}, \helpref{wxVScrolledWindow}{wxvscrolledwindow}
a660d684
KB
102
103\latexignore{\rtfignore{\wxheading{Members}}}
104
105\membersection{wxScrolledWindow::wxScrolledWindow}\label{wxscrolledwindowconstr}
106
107\func{}{wxScrolledWindow}{\void}
108
109Default constructor.
110
eaaa6a06 111\func{}{wxScrolledWindow}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp
a660d684 112\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 113\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}
a660d684
KB
114
115Constructor.
116
117\wxheading{Parameters}
118
119\docparam{parent}{Parent window.}
120
121\docparam{id}{Window identifier. A value of -1 indicates a default value.}
122
123\docparam{pos}{Window position. If a position of (-1, -1) is specified then a default position
124is chosen.}
125
126\docparam{size}{Window size. If a size of (-1, -1) is specified then the window is sized
127appropriately.}
128
129\docparam{style}{Window style. See \helpref{wxScrolledWindow}{wxscrolledwindow}.}
130
131\docparam{name}{Window name.}
132
133\wxheading{Remarks}
134
135The window is initially created without visible scrollbars.
136Call \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} to
137specify how big the virtual window size should be.
138
139\membersection{wxScrolledWindow::\destruct{wxScrolledWindow}}
140
141\func{}{\destruct{wxScrolledWindow}}{\void}
142
143Destructor.
144
4092d6f2
VZ
145\membersection{wxScrolledWindow::CalcScrolledPosition}\label{wxscrolledwindowcalcscrolledposition}
146
147\constfunc{void}{CalcScrolledPosition}{
148 \param{int }{x},
149 \param{int }{y},
150 \param{int *}{xx}
151 \param{int *}{yy}}
152
153Translates the logical coordinates to the device ones. For example, if a window is
154scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0)
155(as always), but the logical coordinates are (0, 10) and so the call to
783d4c89 156CalcScrolledPosition(0, 10, \&xx, \&yy) will return 0 in yy.
4092d6f2
VZ
157
158\wxheading{See also}
159
160\helpref{CalcUnscrolledPosition}{wxscrolledwindowcalcunscrolledposition}
161
b32c6ff0
RD
162\pythonnote{The wxPython version of this methods accepts only two
163parameters and returns xx and yy as a tuple of values.}
164
5873607e
VZ
165\perlnote{In wxPerl this method takes two parameters and returns a
1662-element list {\tt ( xx, yy )}.}
167
4092d6f2
VZ
168\membersection{wxScrolledWindow::CalcUnscrolledPosition}\label{wxscrolledwindowcalcunscrolledposition}
169
170\constfunc{void}{CalcUnscrolledPosition}{
171 \param{int }{x},
172 \param{int }{y},
173 \param{int *}{xx}
174 \param{int *}{yy}}
175
176Translates the device coordinates to the logical ones. For example, if a window is
177scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0)
178(as always), but the logical coordinates are (0, 10) and so the call to
783d4c89 179CalcUnscrolledPosition(0, 0, \&xx, \&yy) will return 10 in yy.
4092d6f2
VZ
180
181\wxheading{See also}
182
183\helpref{CalcScrolledPosition}{wxscrolledwindowcalcscrolledposition}
184
b32c6ff0
RD
185\pythonnote{The wxPython version of this methods accepts only two
186parameters and returns xx and yy as a tuple of values.}
187
5873607e
VZ
188\perlnote{In wxPerl this method takes two parameters and returns a
1892-element list {\tt ( xx, yy )}.}
190
a660d684
KB
191\membersection{wxScrolledWindow::Create}\label{wxscrolledwindowcreate}
192
eaaa6a06 193\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp
a660d684 194\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 195\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}
a660d684
KB
196
197Creates the window for two-step construction. Derived classes
198should call or replace this function. See \helpref{wxScrolledWindow::wxScrolledWindow}{wxscrolledwindowconstr}\rtfsp
199for details.
200
201\membersection{wxScrolledWindow::EnableScrolling}\label{wxscrolledwindowenablescrolling}
202
203\func{void}{EnableScrolling}{\param{const bool}{ xScrolling}, \param{const bool}{ yScrolling}}
204
205Enable or disable physical scrolling in the given direction. Physical
206scrolling is the physical transfer of bits up or down the
207screen when a scroll event occurs. If the application scrolls by a
208variable amount (e.g. if there are different font sizes) then physical
27d029c7
RR
209scrolling will not work, and you should switch it off. Note that you
210will have to reposition child windows yourself, if physical scrolling
211is disabled.
a660d684
KB
212
213\wxheading{Parameters}
214
cc81d32f 215\docparam{xScrolling}{If true, enables physical scrolling in the x direction.}
a660d684 216
cc81d32f 217\docparam{yScrolling}{If true, enables physical scrolling in the y direction.}
a660d684
KB
218
219\wxheading{Remarks}
220
221Physical scrolling may not be available on all platforms. Where it is available, it is enabled
222by default.
223
224\membersection{wxScrolledWindow::GetScrollPixelsPerUnit}\label{wxscrolledwindowgetscrollpixelsperunit}
225
226\constfunc{void}{GetScrollPixelsPerUnit}{\param{int* }{xUnit}, \param{int* }{yUnit}}
227
228Get the number of pixels per scroll unit (line), in each direction, as set
229by \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}. A value of zero indicates no
230scrolling in that direction.
231
232\wxheading{Parameters}
233
234\docparam{xUnit}{Receives the number of pixels per horizontal unit.}
235
236\docparam{yUnit}{Receives the number of pixels per vertical unit.}
237
238\wxheading{See also}
239
240\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
bd0df01f 241\helpref{wxScrolledWindow::GetVirtualSize}{wxscrolledwindowgetvirtualsize}
a660d684 242
b32c6ff0
RD
243\pythonnote{The wxPython version of this methods accepts no
244parameters and returns a tuple of values for xUnit and yUnit.}
245
5873607e
VZ
246\perlnote{In wxPerl this method takes no parameters and returns a
2472-element list {\tt ( xUnit, yUnit )}.}
b32c6ff0 248
a9d171bd
JS
249\membersection{wxScrolledWindow::GetViewStart}\label{wxscrolledwindowgetviewstart}
250
251\constfunc{void}{GetViewStart}{\param{int* }{x}, \param{int* }{ y}}
252
253Get the position at which the visible portion of the window starts.
254
255\wxheading{Parameters}
256
257\docparam{x}{Receives the first visible x position in scroll units.}
258
259\docparam{y}{Receives the first visible y position in scroll units.}
260
261\wxheading{Remarks}
262
263If either of the scrollbars is not at the home position, {\it x} and/or
264\rtfsp{\it y} will be greater than zero. Combined with \helpref{wxWindow::GetClientSize}{wxwindowgetclientsize},
265the application can use this function to efficiently redraw only the
266visible portion of the window. The positions are in logical scroll
267units, not pixels, so to convert to pixels you will have to multiply
268by the number of pixels per scroll increment.
269
270\wxheading{See also}
271
272\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}
273
274\pythonnote{The wxPython version of this methods accepts no
275parameters and returns a tuple of values for x and y.}
276
277\perlnote{In wxPerl this method takes no parameters and returns a
2782-element list {\tt ( x, y )}.}
279
a660d684
KB
280\membersection{wxScrolledWindow::GetVirtualSize}\label{wxscrolledwindowgetvirtualsize}
281
282\constfunc{void}{GetVirtualSize}{\param{int* }{x}, \param{int* }{y}}
283
284Gets the size in device units of the scrollable window area (as
285opposed to the client size, which is the area of the window currently
286visible).
287
288\wxheading{Parameters}
289
290\docparam{x}{Receives the length of the scrollable window, in pixels.}
291
292\docparam{y}{Receives the height of the scrollable window, in pixels.}
293
294\wxheading{Remarks}
295
296Use \helpref{wxDC::DeviceToLogicalX}{wxdcdevicetologicalx} and \helpref{wxDC::DeviceToLogicalY}{wxdcdevicetologicaly}\rtfsp
297to translate these units to logical units.
298
299\wxheading{See also}
300
301\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
bd0df01f 302\helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit}
a660d684 303
b32c6ff0
RD
304\pythonnote{The wxPython version of this methods accepts no
305parameters and returns a tuple of values for x and y.}
306
5873607e
VZ
307\perlnote{In wxPerl this method takes no parameters and returns a
3082-element list {\tt ( x, y )}.}
309
a660d684
KB
310\membersection{wxScrolledWindow::IsRetained}\label{wxscrolledwindowisretained}
311
312\constfunc{bool}{IsRetained}{\void}
313
cc81d32f 314Motif only: true if the window has a backing bitmap.
a660d684
KB
315
316\membersection{wxScrolledWindow::PrepareDC}\label{wxscrolledwindowpreparedc}
317
318\func{void}{PrepareDC}{\param{wxDC\& }{dc}}
319
320Call this function to prepare the device context for drawing a scrolled image. It
321sets the device origin according to the current scroll position.
322
d7cb14ce 323PrepareDC is called automatically within the default wxScrolledWindow::OnPaint event
a660d684
KB
324handler, so your \helpref{wxScrolledWindow::OnDraw}{wxscrolledwindowondraw} override
325will be passed a 'pre-scrolled' device context. However, if you wish to draw from
326outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you must
327call this function yourself. For example:
328
329\begin{verbatim}
fe604ccd 330void MyWindow::OnEvent(wxMouseEvent& event)
a660d684
KB
331{
332 wxClientDC dc(this);
333 PrepareDC(dc);
334
335 dc.SetPen(*wxBLACK_PEN);
336 float x, y;
337 event.Position(&x, &y);
338 if (xpos > -1 && ypos > -1 && event.Dragging())
339 {
340 dc.DrawLine(xpos, ypos, x, y);
341 }
342 xpos = x;
343 ypos = y;
344}
345\end{verbatim}
346
347\membersection{wxScrolledWindow::OnDraw}\label{wxscrolledwindowondraw}
348
349\func{virtual void}{OnDraw}{\param{wxDC\& }{dc}}
350
4092d6f2 351Called by the default paint event handler to allow the application to define
b32c6ff0 352painting behaviour without having to worry about calling
4092d6f2 353\helpref{wxScrolledWindow::PrepareDC}{wxscrolledwindowpreparedc}.
a660d684 354
4092d6f2
VZ
355Instead of overriding this function you may also just process the paint event
356in the derived class as usual, but then you will have to call PrepareDC()
357yourself.
a660d684
KB
358
359\membersection{wxScrolledWindow::Scroll}\label{wxscrolledwindowscroll}
360
361\func{void}{Scroll}{\param{int}{ x}, \param{int}{ y}}
362
363Scrolls a window so the view start is at the given point.
364
365\wxheading{Parameters}
366
367\docparam{x}{The x position to scroll to, in scroll units.}
368
369\docparam{y}{The y position to scroll to, in scroll units.}
370
371\wxheading{Remarks}
372
373The positions are in scroll units, not pixels, so to convert to pixels you
374will have to multiply by the number of pixels per scroll increment.
375If either parameter is -1, that position will be ignored (no change in
376that direction).
377
378\wxheading{See also}
379
380\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
381\helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit}
382
383\membersection{wxScrolledWindow::SetScrollbars}\label{wxscrolledwindowsetscrollbars}
384
385\func{void}{SetScrollbars}{\param{int}{ pixelsPerUnitX}, \param{int}{ pixelsPerUnitY},\rtfsp
386\param{int}{ noUnitsX}, \param{int}{ noUnitsY},\rtfsp
50a1f261 387\param{int }{xPos = 0}, \param{int}{ yPos = 0},\rtfsp
cc81d32f 388\param{bool }{noRefresh = false}}
a660d684
KB
389
390Sets up vertical and/or horizontal scrollbars.
391
392\wxheading{Parameters}
393
394\docparam{pixelsPerUnitX}{Pixels per scroll unit in the horizontal direction.}
395
396\docparam{pixelsPerUnitY}{Pixels per scroll unit in the vertical direction.}
397
398\docparam{noUnitsX}{Number of units in the horizontal direction.}
399
400\docparam{noUnitsY}{Number of units in the vertical direction.}
401
402\docparam{xPos}{Position to initialize the scrollbars in the horizontal direction, in scroll units.}
403
404\docparam{yPos}{Position to initialize the scrollbars in the vertical direction, in scroll units.}
405
cc81d32f 406\docparam{noRefresh}{Will not refresh window if true.}
50a1f261 407
a660d684
KB
408\wxheading{Remarks}
409
410The first pair of parameters give the number of pixels per `scroll step', i.e. amount
411moved when the up or down scroll arrows are pressed.
412The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual
413window.
414
415{\it xPos} and {\it yPos} optionally specify a position to scroll to immediately.
416
417For example, the following gives a window horizontal and vertical
418scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000
419pixels) in each direction.
420
421\begin{verbatim}
422 window->SetScrollbars(20, 20, 50, 50);
423\end{verbatim}
424
425wxScrolledWindow manages the page size itself,
426using the current client window size as the page size.
427
428Note that for more sophisticated scrolling applications, for example where
429scroll steps may be variable according to the position in the document, it will be
430necessary to derive a new class from wxWindow, overriding {\bf OnSize} and
431adjusting the scrollbars appropriately.
432
566d84a7
RL
433\wxheading{See also}
434
435\helpref{wxWindow::SetVirtualSize}{wxwindowsetvirtualsize}
436
437\membersection{wxScrolledWindow::SetScrollRate}\label{wxscrolledwindowsetscrollrate}
438
52ee2268 439\func{void}{SetScrollRate}{\param{int}{ xstep}, \param{int}{ ystep}}
566d84a7 440
52ee2268 441Set the horizontal and vertical scrolling increment only. See the pixelsPerUnit
566d84a7
RL
442parameter in SetScrollbars.
443
30760ce7
RR
444\membersection{wxScrolledWindow::SetTargetWindow}\label{wxscrolledwindowsettargetwindow}
445
446\func{void}{SetTargetWindow}{\param{wxWindow* }{window}}
447
566d84a7 448Call this function to tell wxScrolledWindow to perform the actual scrolling on
52ee2268 449a different window (and not on itself).
30760ce7 450