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