]>
Commit | Line | Data |
---|---|---|
1 | \section{\class{wxScrolledWindow}}\label{wxscrolledwindow} | |
2 | ||
3 | The wxScrolledWindow class manages scrolling for its client area, transforming | |
4 | the coordinates according to the scrollbar positions, and setting the | |
5 | scroll positions, thumb sizes and ranges according to the area in view. | |
6 | ||
7 | As with all windows, an application can draw onto a wxScrolledWindow using a \helpref{device context}{dcoverview}. | |
8 | ||
9 | You have the option of handling the \helpref{OnPaint}{wxscrolledwindowonpaint} handler | |
10 | or overriding the \helpref{OnDraw}{wxscrolledwindowondraw} function, which is passed | |
11 | a pre-scrolled device context (prepared by \helpref{PrepareDC}{wxscrolledwindowpreparedc}). | |
12 | ||
13 | If you don't wish to calculate your own scrolling, you must call PrepareDC when not drawing from | |
14 | within OnDraw, to set the device origin for the device context according to the current | |
15 | scroll position. | |
16 | ||
17 | \wxheading{Derived from} | |
18 | ||
19 | \helpref{wxWindow}{wxwindow}\\ | |
20 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
21 | \helpref{wxObject}{wxobject} | |
22 | ||
23 | \wxheading{Window styles} | |
24 | ||
25 | \twocolwidtha{5cm} | |
26 | \begin{twocollist}\itemsep=0pt | |
27 | \twocolitem{\windowstyle{wxRETAINED}}{Uses a backing pixmap to speed refreshes. Motif only.} | |
28 | \end{twocollist} | |
29 | ||
30 | See also \helpref{window styles overview}{windowstyles}. | |
31 | ||
32 | \wxheading{Remarks} | |
33 | ||
34 | Use wxScrolledWindow for applications where the user scrolls by a fixed amount, and | |
35 | where a `page' can be interpreted to be the current visible portion of the window. For | |
36 | more sophisticated applications, use the wxScrolledWindow implementation as a guide | |
37 | to build your own scroll behaviour. | |
38 | ||
39 | \wxheading{See also} | |
40 | ||
41 | \helpref{wxScrollBar}{wxscrollbar}, \helpref{wxClientDC}{wxclientdc}, \helpref{wxPaintDC}{wxpaintdc} | |
42 | ||
43 | \latexignore{\rtfignore{\wxheading{Members}}} | |
44 | ||
45 | \membersection{wxScrolledWindow::wxScrolledWindow}\label{wxscrolledwindowconstr} | |
46 | ||
47 | \func{}{wxScrolledWindow}{\void} | |
48 | ||
49 | Default constructor. | |
50 | ||
51 | \func{}{wxScrolledWindow}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp | |
52 | \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp | |
53 | \param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}} | |
54 | ||
55 | Constructor. | |
56 | ||
57 | \wxheading{Parameters} | |
58 | ||
59 | \docparam{parent}{Parent window.} | |
60 | ||
61 | \docparam{id}{Window identifier. A value of -1 indicates a default value.} | |
62 | ||
63 | \docparam{pos}{Window position. If a position of (-1, -1) is specified then a default position | |
64 | is chosen.} | |
65 | ||
66 | \docparam{size}{Window size. If a size of (-1, -1) is specified then the window is sized | |
67 | appropriately.} | |
68 | ||
69 | \docparam{style}{Window style. See \helpref{wxScrolledWindow}{wxscrolledwindow}.} | |
70 | ||
71 | \docparam{name}{Window name.} | |
72 | ||
73 | \wxheading{Remarks} | |
74 | ||
75 | The window is initially created without visible scrollbars. | |
76 | Call \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} to | |
77 | specify how big the virtual window size should be. | |
78 | ||
79 | \membersection{wxScrolledWindow::\destruct{wxScrolledWindow}} | |
80 | ||
81 | \func{}{\destruct{wxScrolledWindow}}{\void} | |
82 | ||
83 | Destructor. | |
84 | ||
85 | \membersection{wxScrolledWindow::Create}\label{wxscrolledwindowcreate} | |
86 | ||
87 | \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp | |
88 | \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp | |
89 | \param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}} | |
90 | ||
91 | Creates the window for two-step construction. Derived classes | |
92 | should call or replace this function. See \helpref{wxScrolledWindow::wxScrolledWindow}{wxscrolledwindowconstr}\rtfsp | |
93 | for details. | |
94 | ||
95 | \membersection{wxScrolledWindow::EnableScrolling}\label{wxscrolledwindowenablescrolling} | |
96 | ||
97 | \func{void}{EnableScrolling}{\param{const bool}{ xScrolling}, \param{const bool}{ yScrolling}} | |
98 | ||
99 | Enable or disable physical scrolling in the given direction. Physical | |
100 | scrolling is the physical transfer of bits up or down the | |
101 | screen when a scroll event occurs. If the application scrolls by a | |
102 | variable amount (e.g. if there are different font sizes) then physical | |
103 | scrolling will not work, and you should switch it off. | |
104 | ||
105 | \wxheading{Parameters} | |
106 | ||
107 | \docparam{xScrolling}{If TRUE, enables physical scrolling in the x direction.} | |
108 | ||
109 | \docparam{yScrolling}{If TRUE, enables physical scrolling in the y direction.} | |
110 | ||
111 | \wxheading{Remarks} | |
112 | ||
113 | Physical scrolling may not be available on all platforms. Where it is available, it is enabled | |
114 | by default. | |
115 | ||
116 | \membersection{wxScrolledWindow::GetScrollPixelsPerUnit}\label{wxscrolledwindowgetscrollpixelsperunit} | |
117 | ||
118 | \constfunc{void}{GetScrollPixelsPerUnit}{\param{int* }{xUnit}, \param{int* }{yUnit}} | |
119 | ||
120 | Get the number of pixels per scroll unit (line), in each direction, as set | |
121 | by \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}. A value of zero indicates no | |
122 | scrolling in that direction. | |
123 | ||
124 | \wxheading{Parameters} | |
125 | ||
126 | \docparam{xUnit}{Receives the number of pixels per horizontal unit.} | |
127 | ||
128 | \docparam{yUnit}{Receives the number of pixels per vertical unit.} | |
129 | ||
130 | \wxheading{See also} | |
131 | ||
132 | \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp | |
133 | \helpref{wxScrolledWindow::GetVirtualSize}{wxscrolledwindowgetvirtualsize} | |
134 | ||
135 | \membersection{wxScrolledWindow::GetVirtualSize}\label{wxscrolledwindowgetvirtualsize} | |
136 | ||
137 | \constfunc{void}{GetVirtualSize}{\param{int* }{x}, \param{int* }{y}} | |
138 | ||
139 | Gets the size in device units of the scrollable window area (as | |
140 | opposed to the client size, which is the area of the window currently | |
141 | visible). | |
142 | ||
143 | \wxheading{Parameters} | |
144 | ||
145 | \docparam{x}{Receives the length of the scrollable window, in pixels.} | |
146 | ||
147 | \docparam{y}{Receives the height of the scrollable window, in pixels.} | |
148 | ||
149 | \wxheading{Remarks} | |
150 | ||
151 | Use \helpref{wxDC::DeviceToLogicalX}{wxdcdevicetologicalx} and \helpref{wxDC::DeviceToLogicalY}{wxdcdevicetologicaly}\rtfsp | |
152 | to translate these units to logical units. | |
153 | ||
154 | \wxheading{See also} | |
155 | ||
156 | \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp | |
157 | \helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit} | |
158 | ||
159 | \membersection{wxScrolledWindow::IsRetained}\label{wxscrolledwindowisretained} | |
160 | ||
161 | \constfunc{bool}{IsRetained}{\void} | |
162 | ||
163 | TRUE if the window has a backing bitmap. | |
164 | ||
165 | \membersection{wxScrolledWindow::PrepareDC}\label{wxscrolledwindowpreparedc} | |
166 | ||
167 | \func{void}{PrepareDC}{\param{wxDC\& }{dc}} | |
168 | ||
169 | Call this function to prepare the device context for drawing a scrolled image. It | |
170 | sets the device origin according to the current scroll position. | |
171 | ||
172 | PrepareDC is called automatically within the default \helpref{wxScrolledWindow::OnPaint}{wxscrolledwindowonpaint} event | |
173 | handler, so your \helpref{wxScrolledWindow::OnDraw}{wxscrolledwindowondraw} override | |
174 | will be passed a 'pre-scrolled' device context. However, if you wish to draw from | |
175 | outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you must | |
176 | call this function yourself. For example: | |
177 | ||
178 | \begin{verbatim} | |
179 | void MyWindow::OnEvent(wxMouseEvent& event) | |
180 | { | |
181 | wxClientDC dc(this); | |
182 | PrepareDC(dc); | |
183 | ||
184 | dc.SetPen(*wxBLACK_PEN); | |
185 | float x, y; | |
186 | event.Position(&x, &y); | |
187 | if (xpos > -1 && ypos > -1 && event.Dragging()) | |
188 | { | |
189 | dc.DrawLine(xpos, ypos, x, y); | |
190 | } | |
191 | xpos = x; | |
192 | ypos = y; | |
193 | } | |
194 | \end{verbatim} | |
195 | ||
196 | \membersection{wxScrolledWindow::OnDraw}\label{wxscrolledwindowondraw} | |
197 | ||
198 | \func{virtual void}{OnDraw}{\param{wxDC\& }{dc}} | |
199 | ||
200 | Called by the default \helpref{wxScrolledWindow::OnPaint}{wxscrolledwindowonpaint} implementation | |
201 | to allow the application to define painting behaviour without having to worry about | |
202 | calling \helpref{wxScrolledWindow::PrepareDC}{wxscrolledwindowpreparedc}. | |
203 | ||
204 | \membersection{wxScrolledWindow::OnPaint}\label{wxscrolledwindowonpaint} | |
205 | ||
206 | \func{void}{OnPaint}{\param{wxPaintEvent\& }{event}} | |
207 | ||
208 | Sent to the window when the window must be refreshed. | |
209 | ||
210 | For more details, see \helpref{wxWindow::OnPaint}{wxwindowonpaint}. | |
211 | ||
212 | The default implementation for wxScrolledWindow's OnPaint handler is simply: | |
213 | ||
214 | \begin{verbatim} | |
215 | void wxScrolledWindow::OnPaint(wxPaintEvent& event) | |
216 | { | |
217 | wxPaintDC dc(this); | |
218 | PrepareDC(dc); | |
219 | ||
220 | OnDraw(dc); | |
221 | } | |
222 | \end{verbatim} | |
223 | ||
224 | \membersection{wxScrolledWindow::OnScroll}\label{wxscrolledwindowonscroll} | |
225 | ||
226 | \func{void}{OnScroll}{\param{wxScrollEvent\& }{event}} | |
227 | ||
228 | Override this function to intercept scroll events. This | |
229 | member function implements the default scroll behaviour. If | |
230 | you do not call the default function, you will have to manage | |
231 | all scrolling behaviour including drawing the window contents | |
232 | at an appropriate position relative to the scrollbars. | |
233 | ||
234 | For more details, see \helpref{wxWindow::OnScroll}{wxwindowonscroll}. | |
235 | ||
236 | \wxheading{See also} | |
237 | ||
238 | \helpref{wxScrollEvent}{wxscrollevent} | |
239 | ||
240 | \membersection{wxScrolledWindow::Scroll}\label{wxscrolledwindowscroll} | |
241 | ||
242 | \func{void}{Scroll}{\param{int}{ x}, \param{int}{ y}} | |
243 | ||
244 | Scrolls a window so the view start is at the given point. | |
245 | ||
246 | \wxheading{Parameters} | |
247 | ||
248 | \docparam{x}{The x position to scroll to, in scroll units.} | |
249 | ||
250 | \docparam{y}{The y position to scroll to, in scroll units.} | |
251 | ||
252 | \wxheading{Remarks} | |
253 | ||
254 | The positions are in scroll units, not pixels, so to convert to pixels you | |
255 | will have to multiply by the number of pixels per scroll increment. | |
256 | If either parameter is -1, that position will be ignored (no change in | |
257 | that direction). | |
258 | ||
259 | \wxheading{See also} | |
260 | ||
261 | \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars},\rtfsp | |
262 | \helpref{wxScrolledWindow::GetScrollPixelsPerUnit}{wxscrolledwindowgetscrollpixelsperunit} | |
263 | ||
264 | \membersection{wxScrolledWindow::SetScrollbars}\label{wxscrolledwindowsetscrollbars} | |
265 | ||
266 | \func{void}{SetScrollbars}{\param{int}{ pixelsPerUnitX}, \param{int}{ pixelsPerUnitY},\rtfsp | |
267 | \param{int}{ noUnitsX}, \param{int}{ noUnitsY},\rtfsp | |
268 | \param{int }{xPos = 0}, \param{int}{ yPos = 0}} | |
269 | ||
270 | Sets up vertical and/or horizontal scrollbars. | |
271 | ||
272 | \wxheading{Parameters} | |
273 | ||
274 | \docparam{pixelsPerUnitX}{Pixels per scroll unit in the horizontal direction.} | |
275 | ||
276 | \docparam{pixelsPerUnitY}{Pixels per scroll unit in the vertical direction.} | |
277 | ||
278 | \docparam{noUnitsX}{Number of units in the horizontal direction.} | |
279 | ||
280 | \docparam{noUnitsY}{Number of units in the vertical direction.} | |
281 | ||
282 | \docparam{xPos}{Position to initialize the scrollbars in the horizontal direction, in scroll units.} | |
283 | ||
284 | \docparam{yPos}{Position to initialize the scrollbars in the vertical direction, in scroll units.} | |
285 | ||
286 | \wxheading{Remarks} | |
287 | ||
288 | The first pair of parameters give the number of pixels per `scroll step', i.e. amount | |
289 | moved when the up or down scroll arrows are pressed. | |
290 | The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual | |
291 | window. | |
292 | ||
293 | {\it xPos} and {\it yPos} optionally specify a position to scroll to immediately. | |
294 | ||
295 | For example, the following gives a window horizontal and vertical | |
296 | scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 | |
297 | pixels) in each direction. | |
298 | ||
299 | \begin{verbatim} | |
300 | window->SetScrollbars(20, 20, 50, 50); | |
301 | \end{verbatim} | |
302 | ||
303 | wxScrolledWindow manages the page size itself, | |
304 | using the current client window size as the page size. | |
305 | ||
306 | Note that for more sophisticated scrolling applications, for example where | |
307 | scroll steps may be variable according to the position in the document, it will be | |
308 | necessary to derive a new class from wxWindow, overriding {\bf OnSize} and | |
309 | adjusting the scrollbars appropriately. | |
310 | ||
311 | \membersection{wxScrolledWindow::ViewStart}\label{wxscrolledwindowviewstart} | |
312 | ||
313 | \constfunc{void}{ViewStart}{\param{int* }{x}, \param{int* }{ y}} | |
314 | ||
315 | Get the position at which the visible portion of the window starts. | |
316 | ||
317 | \wxheading{Parameters} | |
318 | ||
319 | \docparam{x}{Receives the first visible x position in scroll units.} | |
320 | ||
321 | \docparam{y}{Receives the first visible y position in scroll units.} | |
322 | ||
323 | \wxheading{Remarks} | |
324 | ||
325 | If either of the scrollbars is not at the home position, {\it x} and/or | |
326 | \rtfsp{\it y} will be greater than zero. Combined with \helpref{wxWindow::GetClientSize}{wxwindowgetclientsize}, | |
327 | the application can use this function to efficiently redraw only the | |
328 | visible portion of the window. The positions are in logical scroll | |
329 | units, not pixels, so to convert to pixels you will have to multiply | |
330 | by the number of pixels per scroll increment. | |
331 | ||
332 | \wxheading{See also} | |
333 | ||
334 | \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} | |
335 |