File: wx201.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 (319 lines) | stat: -rw-r--r-- 11,084 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
<HTML>
<head><title>wxScrollBar</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxscrollbar"></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="wx200.htm#wxscreendc"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx202.htm#wxscrollevent"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>wxScrollBar</H2>
<P>
A wxScrollBar is a control that represents a horizontal or
vertical scrollbar. It is distinct from the two scrollbars that some windows
provide automatically, but the two types of scrollbar share the way
events are received.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
<A HREF="wx56.htm#wxcontrol">wxControl</A><BR>

<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/scrolbar.h&gt;<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
A scrollbar has the following main attributes: <I>range</I>, <I>thumb size</I>, <I>page size</I>, and <I>position</I>.<P>
The range is the total number of units associated with the view represented by the scrollbar.
For a table with 15 columns, the range would be 15.<P>
The thumb size is the number of units that are currently visible. For the table example, the window
might be sized so that only 5 columns are currently visible, in which case the application would
set the thumb size to 5. When the thumb size becomes the same as or greater than the range,
the scrollbar will be automatically hidden on most platforms.<P>
The page size is the number of units that the scrollbar should scroll by, when 'paging' through
the data. This value is normally the same as the thumb size length, because
it is natural to assume that the visible window size defines a page.<P>
The scrollbar position is the current thumb position.<P>
Most applications will find it convenient to provide a function called <B>AdjustScrollbars</B> which can
be called initially, from an <B>OnSize</B> event handler, and whenever the application data
changes in size. It will adjust the view, object and page size according
to the size of the window and the size of the data.<P>
<B><FONT COLOR="#FF0000">Window styles</FONT></B><P>


<TABLE>


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

<TD VALIGN=TOP>
Specifies a horizontal scrollbar.
</TD></TR>


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

<TD VALIGN=TOP>
Specifies a vertical scrollbar.
</TD></TR>


</TABLE>
<P>
See also <A HREF="wx305.htm#windowstyles">window styles overview</A>.<P>
<B><FONT COLOR="#FF0000">Event handling</FONT></B><P>
To process input from a scrollbar, use one of these event handler macros to direct input to member
functions that take a <A HREF="wx202.htm#wxscrollevent">wxScrollEvent</A> argument:<P>


<TABLE>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_SCROLL(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch all scroll commands.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_TOP(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a command to put the scroll thumb at the maximum position.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_BOTTOM(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a command to put the scroll thumb at the maximum position.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_LINEUP(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a line up command.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_LINEDOWN(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a line down command.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_PAGEUP(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a page up command.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_PAGEDOWN(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a page down command.
</TD></TR>


<TR><TD VALIGN=TOP>
<B>EVT_COMMAND_THUMBTRACK(id, func)</B>
</TD>

<TD VALIGN=TOP>
Catch a thumbtrack command (continuous movement of the scroll thumb).
</TD></TR>


</TABLE>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx297.htm#scrollingoverview">Scrolling overview</A>,
<A HREF="wx299.htm#eventhandlingoverview">Event handling overview</A>,
<A HREF="wx203.htm#wxscrolledwindow">wxScrolledWindow</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxscrollbarconstr">wxScrollBar::wxScrollBar</A><BR>
<A HREF="#topic806">wxScrollBar::~wxScrollBar</A><BR>
<A HREF="#wxscrollbarcreate">wxScrollBar::Create</A><BR>
<A HREF="#wxscrollbargetrange">wxScrollBar::GetRange</A><BR>
<A HREF="#wxscrollbargetpagesize">wxScrollBar::GetPageSize</A><BR>
<A HREF="#wxscrollbargetthumbposition">wxScrollBar::GetThumbPosition</A><BR>
<A HREF="#wxscrollbargetthumblength">wxScrollBar::GetThumbLength</A><BR>
<A HREF="#wxscrollbarsetthumbposition">wxScrollBar::SetThumbPosition</A><BR>
<A HREF="#wxscrollbarsetscrollbar">wxScrollBar::SetScrollbar</A><BR>
<P>

<HR>
<A NAME="wxscrollbarconstr"></A>
<H3>wxScrollBar::wxScrollBar</H3>
<P>
<B></B> <B>wxScrollBar</B>()<P>
Default constructor.<P>
<B></B> <B>wxScrollBar</B>(<B>wxWindow*</B><I> parent</I>, <B>wxWindowID </B><I>id</I>,
<B>const wxPoint&amp; </B><I>pos = wxDefaultPosition</I>, <B>const wxSize&amp; </B><I>size = wxDefaultSize</I>,
<B>long</B><I> style = wxSB_HORIZONTAL</I>, <B>const wxValidator&amp; </B><I>validator = wxDefaultValidator</I>,
<B>const wxString&amp; </B><I>name = "scrollBar"</I>)<P>
Constructor, creating and showing a scrollbar.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>parent</I><UL><UL>
Parent window. Must not be NULL.</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 the position (-1, -1) is specified then a default position is chosen.</UL></UL>
<P>
<I>size</I><UL><UL>
Window size. If the default size (-1, -1) is specified then a default size is chosen.</UL></UL>
<P>
<I>style</I><UL><UL>
Window style. See <A HREF="wx201.htm#wxscrollbar">wxScrollBar</A>.</UL></UL>
<P>
<I>validator</I><UL><UL>
Window validator.</UL></UL>
<P>
<I>name</I><UL><UL>
Window name.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbarcreate">wxScrollBar::Create</A>, <A HREF="wx255.htm#wxvalidator">wxValidator</A><P>

<HR>
<A NAME="topic806"></A>
<H3>wxScrollBar::~wxScrollBar</H3>
<P>
<B>void</B> <B>~wxScrollBar</B>()<P>
Destructor, destroying the scrollbar.<P>

<HR>
<A NAME="wxscrollbarcreate"></A>
<H3>wxScrollBar::Create</H3>
<P>
<B>bool</B> <B>Create</B>(<B>wxWindow*</B><I> parent</I>, <B>wxWindowID </B><I>id</I>,
<B>const wxPoint&amp; </B><I>pos = wxDefaultPosition</I>, <B>const wxSize&amp; </B><I>size = wxDefaultSize</I>,
<B>long</B><I> style = wxSB_HORIZONTAL</I>, <B>const wxValidator&amp; </B><I>validator = wxDefaultValidator</I>,
<B>const wxString&amp; </B><I>name = "scrollBar"</I>)<P>
Scrollbar creation function called by the scrollbar constructor.
See <A HREF="wx201.htm#wxscrollbarconstr">wxScrollBar::wxScrollBar</A> for details.<P>

<HR>
<A NAME="wxscrollbargetrange"></A>
<H3>wxScrollBar::GetRange</H3>
<P>
<B>int</B> <B>GetRange</B>() <B>const</B><P>
Returns the length of the scrollbar.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbarsetscrollbar">wxScrollBar::SetScrollbar</A><P>

<HR>
<A NAME="wxscrollbargetpagesize"></A>
<H3>wxScrollBar::GetPageSize</H3>
<P>
<B>int</B> <B>GetPageSize</B>() <B>const</B><P>
Returns the page size of the scrollbar. This is the number of scroll units
that will be scrolled when the user pages up or down. Often it is the
same as the thumb size.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbarsetscrollbar">wxScrollBar::SetScrollbar</A><P>

<HR>
<A NAME="wxscrollbargetthumbposition"></A>
<H3>wxScrollBar::GetThumbPosition</H3>
<P>
<B>int</B> <B>GetThumbPosition</B>() <B>const</B><P>
Returns the current position of the scrollbar thumb.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbarsetthumbposition">wxScrollBar::SetThumbPosition</A><P>

<HR>
<A NAME="wxscrollbargetthumblength"></A>
<H3>wxScrollBar::GetThumbLength</H3>
<P>
<B>int</B> <B>GetThumbLength</B>() <B>const</B><P>
Returns the thumb or 'view' size.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbarsetscrollbar">wxScrollBar::SetScrollbar</A><P>

<HR>
<A NAME="wxscrollbarsetthumbposition"></A>
<H3>wxScrollBar::SetThumbPosition</H3>
<P>
<B>void</B> <B>SetThumbPosition</B>(<B>int</B><I> viewStart</I>)<P>
Sets the position of the scrollbar.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>viewStart</I><UL><UL>
The position of the scrollbar thumb.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx201.htm#wxscrollbargetthumbposition">wxScrollBar::GetThumbPosition</A><P>

<HR>
<A NAME="wxscrollbarsetscrollbar"></A>
<H3>wxScrollBar::SetScrollbar</H3>
<P>
<B>virtual void</B> <B>SetScrollbar</B>(<B>int </B><I>position</I>,
<B>int </B><I>thumbSize</I>, <B>int </B><I>range</I>,
<B>int </B><I>pageSize</I>,
<B>const bool </B><I>refresh = TRUE</I>)<P>
Sets the scrollbar properties.<P>
<B><FONT COLOR="#FF0000">Parameters</FONT></B><P>
<I>position</I><UL><UL>
The position of the scrollbar in scroll units.</UL></UL>
<P>
<I>thumbSize</I><UL><UL>
The size of the thumb, or visible portion of the scrollbar, in scroll units.</UL></UL>
<P>
<I>range</I><UL><UL>
The maximum position of the scrollbar.</UL></UL>
<P>
<I>pageSize</I><UL><UL>
The size of the page size in scroll units. This is the number of units
the scrollbar will scroll when it is paged up or down. Often it is the same as
the thumb size.</UL></UL>
<P>
<I>refresh</I><UL><UL>
TRUE to redraw the scrollbar, FALSE otherwise.</UL></UL>
<P>
<B><FONT COLOR="#FF0000">Remarks</FONT></B><P>
Let's say you wish to display 50 lines of text, using the same font.
The window is sized so that you can only see 16 lines at a time.<P>
You would use:<P>
<FONT SIZE=2><PRE>
  scrollbar-&gt;SetScrollbar(0, 16, 50, 15);
</PRE>
</FONT><P>
The page size is 1 less than the thumb size so that the last line of the previous
page will be visible on the next page, to help orient the user.<P>
Note that with the window at this size, the thumb position can never go
above 50 minus 16, or 34.<P>
You can determine how many lines are currently visible by dividing the current view
size by the character height in pixels.<P>
When defining your own scrollbar behaviour, you will always need to recalculate
the scrollbar settings when the window size changes. You could therefore put your
scrollbar calculations and SetScrollbar
call into a function named AdjustScrollbars, which can be called initially and also
from a <A HREF="wx260.htm#wxwindowonsize">wxWindow::OnSize</A> event handler function.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx297.htm#scrollingoverview">Scrolling overview</A>,
<A HREF="wx260.htm#wxwindowsetscrollbar">wxWindow::SetScrollbar</A>, <A HREF="wx203.htm#wxscrolledwindow">wxScrolledWindow</A><P>

</BODY></HTML>