]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/scrolwin.tex
added wxFileType::GetMimeTypes
[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
7As with all windows, an application can draw onto a wxScrolledWindow using a \helpref{device context}{dcoverview}.
8
d7cb14ce 9You have the option of handling the OnPaint handler
a660d684
KB
10or overriding the \helpref{OnDraw}{wxscrolledwindowondraw} function, which is passed
11a pre-scrolled device context (prepared by \helpref{PrepareDC}{wxscrolledwindowpreparedc}).
12
13If you don't wish to calculate your own scrolling, you must call PrepareDC when not drawing from
14within OnDraw, to set the device origin for the device context according to the current
15scroll position.
16
30760ce7
RR
17A wxScrolledWindow will normally scroll itself and therefore its child windows as well. It
18might however be desired to scroll a different window than itself: e.g. when designing a
19spreadsheet, you'll normally only have to scroll the (usually white) cell area, whereas the
20(usually grey) label area will scroll very differently. For this special purpose, you can
21call \helpref{SetTargetWindow}{wxscrolledwindowsettargetwindow} which means that pressing
22the scrollbars will scroll a different window.
23
27d029c7 24Note that the underlying system knows nothing about scrolling coordinates, so that all system
b32c6ff0 25functions (mouse events, expose events, refresh calls etc) as well as the position of subwindows
27d029c7
RR
26are relative to the "physical" origin of the scrolled window. If the user insert a child window at
27position (10,10) and scrolls the window down 100 pixels (moving the child window out of the visible
28area), the child window will report a position of (10,-90).
29
30760ce7 30
a660d684
KB
31\wxheading{Derived from}
32
ad9edf45 33\helpref{wxPanel}{wxpanel}\\
a660d684
KB
34\helpref{wxWindow}{wxwindow}\\
35\helpref{wxEvtHandler}{wxevthandler}\\
36\helpref{wxObject}{wxobject}
37
954b8ae6
JS
38\wxheading{Include files}
39
40<wx/scrolwin.h>
41
a660d684
KB
42\wxheading{Window styles}
43
44\twocolwidtha{5cm}
45\begin{twocollist}\itemsep=0pt
46\twocolitem{\windowstyle{wxRETAINED}}{Uses a backing pixmap to speed refreshes. Motif only.}
47\end{twocollist}
48
49See also \helpref{window styles overview}{windowstyles}.
50
51\wxheading{Remarks}
52
53Use wxScrolledWindow for applications where the user scrolls by a fixed amount, and
54where a `page' can be interpreted to be the current visible portion of the window. For
55more sophisticated applications, use the wxScrolledWindow implementation as a guide
56to build your own scroll behaviour.
57
58\wxheading{See also}
59
60\helpref{wxScrollBar}{wxscrollbar}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc}
61
62\latexignore{\rtfignore{\wxheading{Members}}}
63
64\membersection{wxScrolledWindow::wxScrolledWindow}\label{wxscrolledwindowconstr}
65
66\func{}{wxScrolledWindow}{\void}
67
68Default constructor.
69
eaaa6a06 70\func{}{wxScrolledWindow}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp
a660d684 71\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 72\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}
a660d684
KB
73
74Constructor.
75
76\wxheading{Parameters}
77
78\docparam{parent}{Parent window.}
79
80\docparam{id}{Window identifier. A value of -1 indicates a default value.}
81
82\docparam{pos}{Window position. If a position of (-1, -1) is specified then a default position
83is chosen.}
84
85\docparam{size}{Window size. If a size of (-1, -1) is specified then the window is sized
86appropriately.}
87
88\docparam{style}{Window style. See \helpref{wxScrolledWindow}{wxscrolledwindow}.}
89
90\docparam{name}{Window name.}
91
92\wxheading{Remarks}
93
94The window is initially created without visible scrollbars.
95Call \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} to
96specify how big the virtual window size should be.
97
98\membersection{wxScrolledWindow::\destruct{wxScrolledWindow}}
99
100\func{}{\destruct{wxScrolledWindow}}{\void}
101
102Destructor.
103
4092d6f2
VZ
104\membersection{wxScrolledWindow::CalcScrolledPosition}\label{wxscrolledwindowcalcscrolledposition}
105
106\constfunc{void}{CalcScrolledPosition}{
107 \param{int }{x},
108 \param{int }{y},
109 \param{int *}{xx}
110 \param{int *}{yy}}
111
112Translates the logical coordinates to the device ones. For example, if a window is
113scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0)
114(as always), but the logical coordinates are (0, 10) and so the call to
115CalcScrolledPosition(0, 0, \&xx, \&yy) will return 10 in yy.
116
117\wxheading{See also}
118
119\helpref{CalcUnscrolledPosition}{wxscrolledwindowcalcunscrolledposition}
120
b32c6ff0
RD
121\pythonnote{The wxPython version of this methods accepts only two
122parameters and returns xx and yy as a tuple of values.}
123
4092d6f2
VZ
124\membersection{wxScrolledWindow::CalcUnscrolledPosition}\label{wxscrolledwindowcalcunscrolledposition}
125
126\constfunc{void}{CalcUnscrolledPosition}{
127 \param{int }{x},
128 \param{int }{y},
129 \param{int *}{xx}
130 \param{int *}{yy}}
131
132Translates the device coordinates to the logical ones. For example, if a window is
133scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0)
134(as always), but the logical coordinates are (0, 10) and so the call to
135CalcUnscrolledPosition(0, 10, \&xx, \&yy) will return 0 in yy.
136
137\wxheading{See also}
138
139\helpref{CalcScrolledPosition}{wxscrolledwindowcalcscrolledposition}
140
b32c6ff0
RD
141\pythonnote{The wxPython version of this methods accepts only two
142parameters and returns xx and yy as a tuple of values.}
143
a660d684
KB
144\membersection{wxScrolledWindow::Create}\label{wxscrolledwindowcreate}
145
eaaa6a06 146\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp
a660d684 147\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
eaaa6a06 148\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}
a660d684
KB
149
150Creates the window for two-step construction. Derived classes
151should call or replace this function. See \helpref{wxScrolledWindow::wxScrolledWindow}{wxscrolledwindowconstr}\rtfsp
152for details.
153
154\membersection{wxScrolledWindow::EnableScrolling}\label{wxscrolledwindowenablescrolling}
155
156\func{void}{EnableScrolling}{\param{const bool}{ xScrolling}, \param{const bool}{ yScrolling}}
157
158Enable or disable physical scrolling in the given direction. Physical
159scrolling is the physical transfer of bits up or down the
160screen when a scroll event occurs. If the application scrolls by a
161variable amount (e.g. if there are different font sizes) then physical
27d029c7
RR
162scrolling will not work, and you should switch it off. Note that you
163will have to reposition child windows yourself, if physical scrolling
164is disabled.
a660d684
KB
165
166\wxheading{Parameters}
167
168\docparam{xScrolling}{If TRUE, enables physical scrolling in the x direction.}
169
170\docparam{yScrolling}{If TRUE, enables physical scrolling in the y direction.}
171
172\wxheading{Remarks}
173
174Physical scrolling may not be available on all platforms. Where it is available, it is enabled
175by default.
176
177\membersection{wxScrolledWindow::GetScrollPixelsPerUnit}\label{wxscrolledwindowgetscrollpixelsperunit}
178
179\constfunc{void}{GetScrollPixelsPerUnit}{\param{int* }{xUnit}, \param{int* }{yUnit}}
180
181Get the number of pixels per scroll unit (line), in each direction, as set
182by \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}. A value of zero indicates no
183scrolling in that direction.
184
185\wxheading{Parameters}
186
187\docparam{xUnit}{Receives the number of pixels per horizontal unit.}
188
189\docparam{yUnit}{Receives the number of pixels per vertical unit.}
190
191\wxheading{See also}
192
193\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
bd0df01f 194\helpref{wxScrolledWindow::GetVirtualSize}{wxscrolledwindowgetvirtualsize}
a660d684 195
b32c6ff0
RD
196\pythonnote{The wxPython version of this methods accepts no
197parameters and returns a tuple of values for xUnit and yUnit.}
198
199
a660d684
KB
200\membersection{wxScrolledWindow::GetVirtualSize}\label{wxscrolledwindowgetvirtualsize}
201
202\constfunc{void}{GetVirtualSize}{\param{int* }{x}, \param{int* }{y}}
203
204Gets the size in device units of the scrollable window area (as
205opposed to the client size, which is the area of the window currently
206visible).
207
208\wxheading{Parameters}
209
210\docparam{x}{Receives the length of the scrollable window, in pixels.}
211
212\docparam{y}{Receives the height of the scrollable window, in pixels.}
213
214\wxheading{Remarks}
215
216Use \helpref{wxDC::DeviceToLogicalX}{wxdcdevicetologicalx} and \helpref{wxDC::DeviceToLogicalY}{wxdcdevicetologicaly}\rtfsp
217to translate these units to logical units.
218
219\wxheading{See also}
220
221\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
bd0df01f 222\helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit}
a660d684 223
b32c6ff0
RD
224\pythonnote{The wxPython version of this methods accepts no
225parameters and returns a tuple of values for x and y.}
226
a660d684
KB
227\membersection{wxScrolledWindow::IsRetained}\label{wxscrolledwindowisretained}
228
229\constfunc{bool}{IsRetained}{\void}
230
4092d6f2 231Motif only: TRUE if the window has a backing bitmap.
a660d684
KB
232
233\membersection{wxScrolledWindow::PrepareDC}\label{wxscrolledwindowpreparedc}
234
235\func{void}{PrepareDC}{\param{wxDC\& }{dc}}
236
237Call this function to prepare the device context for drawing a scrolled image. It
238sets the device origin according to the current scroll position.
239
d7cb14ce 240PrepareDC is called automatically within the default wxScrolledWindow::OnPaint event
a660d684
KB
241handler, so your \helpref{wxScrolledWindow::OnDraw}{wxscrolledwindowondraw} override
242will be passed a 'pre-scrolled' device context. However, if you wish to draw from
243outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you must
244call this function yourself. For example:
245
246\begin{verbatim}
fe604ccd 247void MyWindow::OnEvent(wxMouseEvent& event)
a660d684
KB
248{
249 wxClientDC dc(this);
250 PrepareDC(dc);
251
252 dc.SetPen(*wxBLACK_PEN);
253 float x, y;
254 event.Position(&x, &y);
255 if (xpos > -1 && ypos > -1 && event.Dragging())
256 {
257 dc.DrawLine(xpos, ypos, x, y);
258 }
259 xpos = x;
260 ypos = y;
261}
262\end{verbatim}
263
264\membersection{wxScrolledWindow::OnDraw}\label{wxscrolledwindowondraw}
265
266\func{virtual void}{OnDraw}{\param{wxDC\& }{dc}}
267
4092d6f2 268Called by the default paint event handler to allow the application to define
b32c6ff0 269painting behaviour without having to worry about calling
4092d6f2 270\helpref{wxScrolledWindow::PrepareDC}{wxscrolledwindowpreparedc}.
a660d684 271
4092d6f2
VZ
272Instead of overriding this function you may also just process the paint event
273in the derived class as usual, but then you will have to call PrepareDC()
274yourself.
a660d684
KB
275
276\membersection{wxScrolledWindow::Scroll}\label{wxscrolledwindowscroll}
277
278\func{void}{Scroll}{\param{int}{ x}, \param{int}{ y}}
279
280Scrolls a window so the view start is at the given point.
281
282\wxheading{Parameters}
283
284\docparam{x}{The x position to scroll to, in scroll units.}
285
286\docparam{y}{The y position to scroll to, in scroll units.}
287
288\wxheading{Remarks}
289
290The positions are in scroll units, not pixels, so to convert to pixels you
291will have to multiply by the number of pixels per scroll increment.
292If either parameter is -1, that position will be ignored (no change in
293that direction).
294
295\wxheading{See also}
296
297\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp
298\helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit}
299
300\membersection{wxScrolledWindow::SetScrollbars}\label{wxscrolledwindowsetscrollbars}
301
302\func{void}{SetScrollbars}{\param{int}{ pixelsPerUnitX}, \param{int}{ pixelsPerUnitY},\rtfsp
303\param{int}{ noUnitsX}, \param{int}{ noUnitsY},\rtfsp
304\param{int }{xPos = 0}, \param{int}{ yPos = 0}}
305
306Sets up vertical and/or horizontal scrollbars.
307
308\wxheading{Parameters}
309
310\docparam{pixelsPerUnitX}{Pixels per scroll unit in the horizontal direction.}
311
312\docparam{pixelsPerUnitY}{Pixels per scroll unit in the vertical direction.}
313
314\docparam{noUnitsX}{Number of units in the horizontal direction.}
315
316\docparam{noUnitsY}{Number of units in the vertical direction.}
317
318\docparam{xPos}{Position to initialize the scrollbars in the horizontal direction, in scroll units.}
319
320\docparam{yPos}{Position to initialize the scrollbars in the vertical direction, in scroll units.}
321
322\wxheading{Remarks}
323
324The first pair of parameters give the number of pixels per `scroll step', i.e. amount
325moved when the up or down scroll arrows are pressed.
326The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual
327window.
328
329{\it xPos} and {\it yPos} optionally specify a position to scroll to immediately.
330
331For example, the following gives a window horizontal and vertical
332scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000
333pixels) in each direction.
334
335\begin{verbatim}
336 window->SetScrollbars(20, 20, 50, 50);
337\end{verbatim}
338
339wxScrolledWindow manages the page size itself,
340using the current client window size as the page size.
341
342Note that for more sophisticated scrolling applications, for example where
343scroll steps may be variable according to the position in the document, it will be
344necessary to derive a new class from wxWindow, overriding {\bf OnSize} and
345adjusting the scrollbars appropriately.
346
30760ce7
RR
347\membersection{wxScrolledWindow::SetTargetWindow}\label{wxscrolledwindowsettargetwindow}
348
349\func{void}{SetTargetWindow}{\param{wxWindow* }{window}}
350
351Call this function to tell wxScrolledWindow to perform the actually scrolling on
352a different window (not on itself).
353
cf3da716 354\membersection{wxScrolledWindow::GetViewStart}\label{wxscrolledwindowgetviewstart}
a660d684 355
cf3da716 356\constfunc{void}{GetViewStart}{\param{int* }{x}, \param{int* }{ y}}
a660d684
KB
357
358Get the position at which the visible portion of the window starts.
359
360\wxheading{Parameters}
361
362\docparam{x}{Receives the first visible x position in scroll units.}
363
364\docparam{y}{Receives the first visible y position in scroll units.}
365
366\wxheading{Remarks}
367
368If either of the scrollbars is not at the home position, {\it x} and/or
369\rtfsp{\it y} will be greater than zero. Combined with \helpref{wxWindow::GetClientSize}{wxwindowgetclientsize},
370the application can use this function to efficiently redraw only the
371visible portion of the window. The positions are in logical scroll
372units, not pixels, so to convert to pixels you will have to multiply
373by the number of pixels per scroll increment.
374
375\wxheading{See also}
376
377\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}
378
b32c6ff0
RD
379\pythonnote{The wxPython version of this methods accepts no
380parameters and returns a tuple of values for x and y.}
381