File: wx203.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (355 lines) | stat: -rw-r--r-- 15,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<HTML>
<head><title>wxScrolledWindow</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxscrolledwindow"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx22.htm#classref"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx202.htm#wxscrollevent"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx204.htm#wxsinglechoicedialog"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>wxScrolledWindow</H2>
<P>
The wxScrolledWindow class manages scrolling for its client area, transforming
the coordinates according to the scrollbar positions, and setting the
scroll positions, thumb sizes and ranges according to the area in view.<P>
As with all windows, an application can draw onto a wxScrolledWindow using a <A HREF="wx294.htm#dcoverview">device context</A>.<P>
You have the option of handling the <A HREF="wx203.htm#wxscrolledwindowonpaint">OnPaint</A> handler
or overriding the <A HREF="wx203.htm#wxscrolledwindowondraw">OnDraw</A> function, which is passed
a pre-scrolled device context (prepared by <A HREF="wx203.htm#wxscrolledwindowpreparedc">PrepareDC</A>).<P>
If you don't wish to calculate your own scrolling, you must call PrepareDC when not drawing from
within OnDraw, to set the device origin for the device context according to the current
scroll position.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
<A HREF="wx260.htm#wxwindow">wxWindow</A><BR>

<A HREF="wx85.htm#wxevthandler">wxEvtHandler</A><BR>

<A HREF="wx158.htm#wxobject">wxObject</A><P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/scrolwin.h&gt;<P>
<B><FONT COLOR="#FF0000">Window styles</FONT></B><P>


<TABLE>


<TR><TD VALIGN=TOP>
<B>wxRETAINED</B>
</TD>

<TD VALIGN=TOP>
Uses a backing pixmap to speed refreshes. Motif only.
</TD></TR>


</TABLE>
<P>
See also <A HREF="wx305.htm#windowstyles">window styles overview</A>.<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
Use wxScrolledWindow for applications where the user scrolls by a fixed amount, and
where a 'page' can be interpreted to be the current visible portion of the window. For
more sophisticated applications, use the wxScrolledWindow implementation as a guide
to build your own scroll behaviour.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbar">wxScrollBar</A>, <A HREF="wx43.htm#wxclientdc">wxClientDC</A>, <A HREF="wx163.htm#wxpaintdc">wxPaintDC</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxscrolledwindowconstr">wxScrolledWindow::wxScrolledWindow</A><BR>
<A HREF="#topic808">wxScrolledWindow::~wxScrolledWindow</A><BR>
<A HREF="#wxscrolledwindowcreate">wxScrolledWindow::Create</A><BR>
<A HREF="#wxscrolledwindowenablescrolling">wxScrolledWindow::EnableScrolling</A><BR>
<A HREF="#wxscrolledwindowgetscrollpixelsperunit">wxScrolledWindow::GetScrollPixelsPerUnit</A><BR>
<A HREF="#wxscrolledwindowgetvirtualsize">wxScrolledWindow::GetVirtualSize</A><BR>
<A HREF="#wxscrolledwindowisretained">wxScrolledWindow::IsRetained</A><BR>
<A HREF="#wxscrolledwindowpreparedc">wxScrolledWindow::PrepareDC</A><BR>
<A HREF="#wxscrolledwindowondraw">wxScrolledWindow::OnDraw</A><BR>
<A HREF="#wxscrolledwindowonpaint">wxScrolledWindow::OnPaint</A><BR>
<A HREF="#wxscrolledwindowonscroll">wxScrolledWindow::OnScroll</A><BR>
<A HREF="#wxscrolledwindowscroll">wxScrolledWindow::Scroll</A><BR>
<A HREF="#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A><BR>
<A HREF="#wxscrolledwindowviewstart">wxScrolledWindow::ViewStart</A><BR>
<P>

<HR>
<A NAME="wxscrolledwindowconstr"></A>
<H3>wxScrolledWindow::wxScrolledWindow</H3>
<P>
<B></B> <B>wxScrolledWindow</B>()<P>
Default constructor.<P>
<B></B> <B>wxScrolledWindow</B>(<B>wxWindow*</B><I> parent</I>, <B>wxWindowID </B><I>id = -1</I>,
<B>const wxPoint&amp; </B><I>pos = wxDefaultPosition</I>, <B>const wxSize&amp; </B><I>size = wxDefaultSize</I>,
<B>long</B><I> style = wxHSCROLL |  wxVSCROLL</I>, <B>const wxString&amp; </B><I>name = "scrolledWindow"</I>)<P>
Constructor.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>parent</I><UL><UL>
Parent window.</UL></UL>
<P>
<I>id</I><UL><UL>
Window identifier. A value of -1 indicates a default value.</UL></UL>
<P>
<I>pos</I><UL><UL>
Window position. If a position of (-1, -1) is specified then a default position
is chosen.</UL></UL>
<P>
<I>size</I><UL><UL>
Window size. If a size of (-1, -1) is specified then the window is sized
appropriately.</UL></UL>
<P>
<I>style</I><UL><UL>
Window style. See <A HREF="wx203.htm#wxscrolledwindow">wxScrolledWindow</A>.</UL></UL>
<P>
<I>name</I><UL><UL>
Window name.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
The window is initially created without visible scrollbars.
Call <A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A> to
specify how big the virtual window size should be.<P>

<HR>
<A NAME="topic808"></A>
<H3>wxScrolledWindow::~wxScrolledWindow</H3>
<P>
<B></B> <B>~wxScrolledWindow</B>()<P>
Destructor.<P>

<HR>
<A NAME="wxscrolledwindowcreate"></A>
<H3>wxScrolledWindow::Create</H3>
<P>
<B>bool</B> <B>Create</B>(<B>wxWindow*</B><I> parent</I>, <B>wxWindowID </B><I>id = -1</I>,
<B>const wxPoint&amp; </B><I>pos = wxDefaultPosition</I>, <B>const wxSize&amp; </B><I>size = wxDefaultSize</I>,
<B>long</B><I> style = wxHSCROLL |  wxVSCROLL</I>, <B>const wxString&amp; </B><I>name = "scrolledWindow"</I>)<P>
Creates the window for two-step construction. Derived classes
should call or replace this function. See <A HREF="wx203.htm#wxscrolledwindowconstr">wxScrolledWindow::wxScrolledWindow</A>
for details.<P>

<HR>
<A NAME="wxscrolledwindowenablescrolling"></A>
<H3>wxScrolledWindow::EnableScrolling</H3>
<P>
<B>void</B> <B>EnableScrolling</B>(<B>const bool</B><I> xScrolling</I>, <B>const bool</B><I> yScrolling</I>)<P>
Enable or disable physical scrolling in the given direction. Physical
scrolling is the physical transfer of bits up or down the
screen when a scroll event occurs. If the application scrolls by a
variable amount (e.g. if there are different font sizes) then physical
scrolling will not work, and you should switch it off.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>xScrolling</I><UL><UL>
If TRUE, enables physical scrolling in the x direction.</UL></UL>
<P>
<I>yScrolling</I><UL><UL>
If TRUE, enables physical scrolling in the y direction.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
Physical scrolling may not be available on all platforms. Where it is available, it is enabled
by default.<P>

<HR>
<A NAME="wxscrolledwindowgetscrollpixelsperunit"></A>
<H3>wxScrolledWindow::GetScrollPixelsPerUnit</H3>
<P>
<B>void</B> <B>GetScrollPixelsPerUnit</B>(<B>int* </B><I>xUnit</I>, <B>int* </B><I>yUnit</I>) <B>const</B><P>
Get the number of pixels per scroll unit (line), in each direction, as set
by <A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A>. A value of zero indicates no
scrolling in that direction.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>xUnit</I><UL><UL>
Receives the number of pixels per horizontal unit.</UL></UL>
<P>
<I>yUnit</I><UL><UL>
Receives the number of pixels per vertical unit.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A>,
<A HREF="wx203.htm#wxscrolledwindowgetvirtualsize">wxScrolledWindow::GetVirtualSize</A><P>

<HR>
<A NAME="wxscrolledwindowgetvirtualsize"></A>
<H3>wxScrolledWindow::GetVirtualSize</H3>
<P>
<B>void</B> <B>GetVirtualSize</B>(<B>int* </B><I>x</I>, <B>int* </B><I>y</I>) <B>const</B><P>
Gets the size in device units of the scrollable window area (as
opposed to the client size, which is the area of the window currently
visible).<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>x</I><UL><UL>
Receives the length of the scrollable window, in pixels.</UL></UL>
<P>
<I>y</I><UL><UL>
Receives the height of the scrollable window, in pixels.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
Use <A HREF="wx65.htm#wxdcdevicetologicalx">wxDC::DeviceToLogicalX</A> and <A HREF="wx65.htm#wxdcdevicetologicaly">wxDC::DeviceToLogicalY</A>
to translate these units to logical units.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A>,
<A HREF="wx203.htm#wxscrolledwindowgetscrollpixelsperunit">wxScrolledWindow::GetScrollPixelsPerUnit</A><P>

<HR>
<A NAME="wxscrolledwindowisretained"></A>
<H3>wxScrolledWindow::IsRetained</H3>
<P>
<B>bool</B> <B>IsRetained</B>() <B>const</B><P>
TRUE if the window has a backing bitmap.<P>

<HR>
<A NAME="wxscrolledwindowpreparedc"></A>
<H3>wxScrolledWindow::PrepareDC</H3>
<P>
<B>void</B> <B>PrepareDC</B>(<B>wxDC&amp; </B><I>dc</I>)<P>
Call this function to prepare the device context for drawing a scrolled image. It
sets the device origin according to the current scroll position.<P>
PrepareDC is called automatically within the default <A HREF="wx203.htm#wxscrolledwindowonpaint">wxScrolledWindow::OnPaint</A> event
handler, so your <A HREF="wx203.htm#wxscrolledwindowondraw">wxScrolledWindow::OnDraw</A> override
will be passed a 'pre-scrolled' device context. However, if you wish to draw from
outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you must
call this function yourself. For example:<P>
<PRE>
void MyWindow::OnEvent(wxMouseEvent& event)
{
  wxClientDC dc(this);
  PrepareDC(dc);

  dc.SetPen(*wxBLACK_PEN);
  float x, y;
  event.Position(&x, &y);
  if (xpos &gt; -1 && ypos &gt; -1 && event.Dragging())
  {
    dc.DrawLine(xpos, ypos, x, y);
  }
  xpos = x;
  ypos = y;
}
</PRE>

<HR>
<A NAME="wxscrolledwindowondraw"></A>
<H3>wxScrolledWindow::OnDraw</H3>
<P>
<B>virtual void</B> <B>OnDraw</B>(<B>wxDC&amp; </B><I>dc</I>)<P>
Called by the default <A HREF="wx203.htm#wxscrolledwindowonpaint">wxScrolledWindow::OnPaint</A> implementation
to allow the application to define painting behaviour without having to worry about
calling <A HREF="wx203.htm#wxscrolledwindowpreparedc">wxScrolledWindow::PrepareDC</A>.<P>

<HR>
<A NAME="wxscrolledwindowonpaint"></A>
<H3>wxScrolledWindow::OnPaint</H3>
<P>
<B>void</B> <B>OnPaint</B>(<B>wxPaintEvent&amp; </B><I>event</I>)<P>
Sent to the window when the window must be refreshed.<P>
For more details, see <A HREF="wx260.htm#wxwindowonpaint">wxWindow::OnPaint</A>.<P>
The default implementation for wxScrolledWindow's OnPaint handler is simply:<P>
<PRE>
void wxScrolledWindow::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);
	PrepareDC(dc);

	OnDraw(dc);
}
</PRE>

<HR>
<A NAME="wxscrolledwindowonscroll"></A>
<H3>wxScrolledWindow::OnScroll</H3>
<P>
<B>void</B> <B>OnScroll</B>(<B>wxScrollEvent&amp; </B><I>event</I>)<P>
Override this function to intercept scroll events. This
member function implements the default scroll behaviour. If
you do not call the default function, you will have to manage
all scrolling behaviour including drawing the window contents
at an appropriate position relative to the scrollbars.<P>
For more details, see <A HREF="wx260.htm#wxwindowonscroll">wxWindow::OnScroll</A>.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx202.htm#wxscrollevent">wxScrollEvent</A><P>

<HR>
<A NAME="wxscrolledwindowscroll"></A>
<H3>wxScrolledWindow::Scroll</H3>
<P>
<B>void</B> <B>Scroll</B>(<B>int</B><I> x</I>, <B>int</B><I> y</I>)<P>
Scrolls a window so the view start is at the given point.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>x</I><UL><UL>
The x position to scroll to, in scroll units.</UL></UL>
<P>
<I>y</I><UL><UL>
The y position to scroll to, in scroll units.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
The positions are in scroll units, not pixels, so to convert to pixels you
will have to multiply by the number of pixels per scroll increment.
If either parameter is -1, that position will be ignored (no change in
that direction).<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A>,
<A HREF="wx203.htm#wxscrolledwindowgetscrollpixelsperunit">wxScrolledWindow::GetScrollPixelsPerUnit</A><P>

<HR>
<A NAME="wxscrolledwindowsetscrollbars"></A>
<H3>wxScrolledWindow::SetScrollbars</H3>
<P>
<B>void</B> <B>SetScrollbars</B>(<B>int</B><I> pixelsPerUnitX</I>, <B>int</B><I> pixelsPerUnitY</I>,
<B>int</B><I> noUnitsX</I>, <B>int</B><I> noUnitsY</I>,
<B>int </B><I>xPos = 0</I>, <B>int</B><I> yPos = 0</I>)<P>
Sets up vertical and/or horizontal scrollbars.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>pixelsPerUnitX</I><UL><UL>
Pixels per scroll unit in the horizontal direction.</UL></UL>
<P>
<I>pixelsPerUnitY</I><UL><UL>
Pixels per scroll unit in the vertical direction.</UL></UL>
<P>
<I>noUnitsX</I><UL><UL>
Number of units in the horizontal direction.</UL></UL>
<P>
<I>noUnitsY</I><UL><UL>
Number of units in the vertical direction.</UL></UL>
<P>
<I>xPos</I><UL><UL>
Position to initialize the scrollbars in the horizontal direction, in scroll units.</UL></UL>
<P>
<I>yPos</I><UL><UL>
Position to initialize the scrollbars in the vertical direction, in scroll units.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
The first pair of parameters give the number of pixels per 'scroll step', i.e. amount
moved when the up or down scroll arrows are pressed.
The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual
window.<P>
<I>xPos</I> and <I>yPos</I> optionally specify a position to scroll to immediately.<P>
For example, the following gives a window horizontal and vertical
scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000
pixels) in each direction.<P>
<PRE>
  window-&gt;SetScrollbars(20, 20, 50, 50);
</PRE>
wxScrolledWindow manages the page size itself,
using the current client window size as the page size.<P>
Note that for more sophisticated scrolling applications, for example where
scroll steps may be variable according to the position in the document, it will be
necessary to derive a new class from wxWindow, overriding <B>OnSize</B> and
adjusting the scrollbars appropriately.<P>

<HR>
<A NAME="wxscrolledwindowviewstart"></A>
<H3>wxScrolledWindow::ViewStart</H3>
<P>
<B>void</B> <B>ViewStart</B>(<B>int* </B><I>x</I>, <B>int* </B><I> y</I>) <B>const</B><P>
Get the position at which the visible portion of the window starts.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>x</I><UL><UL>
Receives the first visible x position in scroll units.</UL></UL>
<P>
<I>y</I><UL><UL>
Receives the first visible y position in scroll units.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
If either of the scrollbars is not at the home position, <I>x</I> and/or
<I>y</I> will be greater than zero.  Combined with <A HREF="wx260.htm#wxwindowgetclientsize">wxWindow::GetClientSize</A>,
the application can use this function to efficiently redraw only the
visible portion of the window.  The positions are in logical scroll
units, not pixels, so to convert to pixels you will have to multiply
by the number of pixels per scroll increment.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx203.htm#wxscrolledwindowsetscrollbars">wxScrolledWindow::SetScrollbars</A><P>

</BODY></HTML>