]> www.wagner.pp.ru Git - oss/ck.git/blob - doc/listbox.n
Ck console graphics toolkit
[oss/ck.git] / doc / listbox.n
1 '\"
2 '\" Copyright (c) 1990 The Regents of the University of California.
3 '\" Copyright (c) 1994-1995 Sun Microsystems, Inc.
4 '\" Copyright (c) 1996-1999 Christian Werner
5 '\"
6 '\" See the file "license.terms" for information on usage and redistribution
7 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 '\" 
9 .so man.macros
10 .TH listbox n 8.0 Ck "Ck Built-In Commands"
11 .BS
12 '\" Note:  do not modify the .SH NAME line immediately below!
13 .SH NAME
14 listbox \- Create and manipulate listbox widgets
15 .SH SYNOPSIS
16 \fBlistbox\fI \fIpathName \fR?\fIoptions\fR?
17 .SH "STANDARD OPTIONS"
18 .LP
19 .nf
20 .ta 4c 8c 12c
21 \fBactiveAttributes\fR  \fBattributes\fR        \fBselectAttributes\fR  \fBtakeFocus\fR
22 \fBactiveBackground\fR  \fBbackground\fR        \fBselectBackground\fR  \fBxScrollCommand\fR
23 \fBactiveForeground\fR  \fBforeground\fR        \fBselectForeground\fR  \fByScrollCommand\fR
24 .fi
25 .LP
26 See the ``options'' manual entry for details on the standard options.
27 .SH "WIDGET-SPECIFIC OPTIONS"
28 .ta 4c
29 .LP
30 .nf
31 Name:   \fBheight\fR
32 Class:  \fBHeight\fR
33 Command-Line Switch:    \fB\-height\fR
34 .fi
35 .IP
36 Specifies the desired height for the window, in lines.
37 If zero or less, then the desired height for the window is made just
38 large enough to hold all the elements in the listbox.
39 .LP
40 .nf
41 Name:   \fBselectMode\fR
42 Class:  \fBSelectMode\fR
43 Command-Line Switch:    \fB\-selectmode\fR
44 .fi
45 .IP
46 Specifies one of several styles for manipulating the selection.
47 The value of the option may be arbitrary, but the default bindings
48 expect it to be either \fBsingle\fR, \fBbrowse\fR or \fBmultiple\fR;
49 the default value is \fBbrowse\fR.
50 .LP
51 .nf
52 Name:   \fBwidth\fR
53 Class:  \fBWidth\fR
54 Command-Line Switch:    \fB\-width\fR
55 .fi
56 .IP
57 Specifies the desired width for the window in characters.
58 If zero or less, then the desired width for the window is made just
59 large enough to hold all the elements in the listbox.
60 .BE
61
62 .SH DESCRIPTION
63 .PP
64 The \fBlistbox\fR command creates a new window (given by the
65 \fIpathName\fR argument) and makes it into a listbox widget.
66 Additional options, described above, may be specified on the command line
67 or in the option database to configure aspects of the listbox such as its
68 colors, attributes and text. The \fBlistbox\fR command returns its
69 \fIpathName\fR argument.  At the time this command is invoked,
70 there must not exist a window named \fIpathName\fR, but
71 \fIpathName\fR's parent must exist.
72 .PP
73 A listbox is a widget that displays a list of strings, one per line.
74 When first created, a new listbox has no elements.
75 Elements may be added or deleted using widget commands described
76 below. In addition, one or more elements may be selected as described
77 below.
78 .PP
79 It is not necessary for all the elements to be
80 displayed in the listbox window at once;  commands described below
81 may be used to change the view in the window.  Listboxes allow
82 scrolling in both directions using the standard \fBxScrollCommand\fR
83 and \fByScrollCommand\fR options.
84
85 .SH "INDICES"
86 .PP
87 Many of the widget commands for listboxes take one or more indices
88 as arguments.
89 An index specifies a particular element of the listbox, in any of
90 the following ways:
91 .TP 12
92 \fInumber\fR
93 Specifies the element as a numerical index, where 0 corresponds
94 to the first element in the listbox.
95 .TP 12
96 \fBactive\fR
97 Indicates the element that has the location cursor.  This element
98 will be displayed with the \fBactiveAttributes\fR, \fBactiveBackground\fR,
99 and \fBactiveForeground\fR options if the keyboard focus is in the
100 listbox. The element is specified with the \fBactivate\fR
101 widget command.
102 .TP 12
103 \fBanchor\fR
104 Indicates the anchor point for the selection, which is set with the
105 \fBselection anchor\fR widget command.
106 .TP 12
107 \fBend\fR
108 Indicates the end of the listbox.
109 For some commands this means just after the last element;
110 for other commands it means the last element.
111 .TP 12
112 \fB@\fIx\fB,\fIy\fR
113 Indicates the element that covers the point in the listbox window
114 specified by \fIx\fR and \fIy\fR (in screen coordinates). If no
115 element covers that point, then the closest element to that
116 point is used.
117 .LP
118 In the widget command descriptions below, arguments named \fIindex\fR,
119 \fIfirst\fR, and \fIlast\fR always contain text indices in one of
120 the above forms.
121
122 .SH "WIDGET COMMAND"
123 .PP
124 The \fBlistbox\fR command creates a new Tcl command whose
125 name is \fIpathName\fR.  This command may be used to invoke various
126 operations on the widget. It has the following general form:
127 .DS C
128 \fIpathName option \fR?\fIarg arg ...\fR?
129 .DE
130 \fIOption\fR and the \fIarg\fRs
131 determine the exact behavior of the command.  The following
132 commands are possible for listbox widgets:
133 .TP
134 \fIpathName \fBactivate\fR \fIindex\fR
135 Sets the active element to the one indicated by \fIindex\fR.
136 The active element is drawn with the \fBactiveAttributes\fR,
137 \fBactiveBackground\fR, and \fBactiveForeground\fR options
138 when the widget has the input focus, and its index may be retrieved
139 with the index \fBactive\fR.
140 .TP
141 \fIpathName \fBcget\fR \fIoption\fR
142 Returns the current value of the configuration option given
143 by \fIoption\fR.
144 \fIOption\fR may have any of the values accepted by the \fBlistbox\fR
145 command.
146 .TP
147 \fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
148 Query or modify the configuration options of the widget.
149 If no \fIoption\fR is specified, returns a list describing all of
150 the available options for \fIpathName\fR. If \fIoption\fR is specified
151 with no \fIvalue\fR, then the command returns a list describing the
152 one named option (this list will be identical to the corresponding
153 sublist of the value returned if no \fIoption\fR is specified).  If
154 one or more \fIoption\-value\fR pairs are specified, then the command
155 modifies the given widget option(s) to have the given value(s);  in
156 this case the command returns an empty string.
157 \fIOption\fR may have any of the values accepted by the \fBlistbox\fR
158 command.
159 .TP
160 \fIpathName \fBcurselection\fR
161 Returns a list containing the numerical indices of
162 all of the elements in the listbox that are currently selected.
163 If there are no elements selected in the listbox then an empty
164 string is returned.
165 .TP
166 \fIpathName \fBdelete \fIfirst \fR?\fIlast\fR?
167 Deletes one or more elements of the listbox.  \fIFirst\fR and \fIlast\fR
168 are indices specifying the first and last elements in the range
169 to delete.  If \fIlast\fR isn't specified it defaults to
170 \fIfirst\fR, i.e. a single element is deleted.
171 .TP
172 \fIpathName \fBget \fIfirst\fR ?\fIlast\fR?
173 If \fIlast\fR is omitted, returns the contents of the listbox
174 element indicated by \fIfirst\fR.
175 If \fIlast\fR is specified, the command returns a list whose elements
176 are all of the listbox elements between \fIfirst\fR and \fIlast\fR,
177 inclusive.
178 Both \fIfirst\fR and \fIlast\fR may have any of the standard
179 forms for indices.
180 .TP
181 \fIpathName \fBindex \fIindex\fR
182 Returns a decimal string giving the integer index value that
183 corresponds to \fIindex\fR.
184 .TP
185 \fIpathName \fBinsert \fIindex \fR?\fIelement element ...\fR?
186 Inserts zero or more new elements in the list just before the
187 element given by \fIindex\fR.  If \fIindex\fR is specified as
188 \fBend\fR then the new elements are added to the end of the
189 list.  Returns an empty string.
190 .TP
191 \fIpathName \fBnearest \fIy\fR
192 Given a y-coordinate within the listbox window, this command returns
193 the index of the (visible) listbox element nearest to that y-coordinate.
194 .TP
195 \fIpathName \fBsee \fIindex\fR
196 Adjust the view in the listbox so that the element given by \fIindex\fR
197 is visible.
198 If the element is already visible then the command has no effect;
199 if the element is near one edge of the window then the listbox
200 scrolls to bring the element into view at the edge;  otherwise
201 the listbox scrolls to center the element.
202 .TP
203 \fIpathName \fBselection \fIoption arg\fR
204 This command is used to adjust the selection within a listbox.  It
205 has several forms, depending on \fIoption\fR:
206 .RS
207 .TP
208 \fIpathName \fBselection anchor \fIindex\fR
209 Sets the selection anchor to the element given by \fIindex\fR.
210 The selection anchor is the end of the selection that is fixed
211 while dragging out a selection with the mouse.
212 The index \fBanchor\fR may be used to refer to the anchor
213 element.
214 .TP
215 \fIpathName \fBselection clear \fIfirst \fR?\fIlast\fR?
216 If any of the elements between \fIfirst\fR and \fIlast\fR
217 (inclusive) are selected, they are deselected.
218 The selection state is not changed for elements outside
219 this range.
220 .TP
221 \fIpathName \fBselection includes \fIindex\fR
222 Returns 1 if the element indicated by \fIindex\fR is currently
223 selected, 0 if it isn't.
224 .TP
225 \fIpathName \fBselection set \fIfirst \fR?\fIlast\fR?
226 Selects all of the elements in the range between
227 \fIfirst\fR and \fIlast\fR, inclusive, without affecting
228 the selection state of elements outside that range.
229 .RE
230 .TP
231 \fIpathName \fBsize\fR
232 Returns a decimal string indicating the total number of elements
233 in the listbox.
234 .TP
235 \fIpathName \fBxview \fIargs\fR
236 This command is used to query and change the horizontal position of the
237 information in the widget's window.  It can take any of the following
238 forms:
239 .RS
240 .TP
241 \fIpathName \fBxview\fR
242 Returns a list containing two elements.
243 Each element is a real fraction between 0 and 1;  together they describe
244 the horizontal span that is visible in the window.
245 For example, if the first element is .2 and the second element is .6,
246 20% of the listbox's text is off-screen to the left, the middle 40% is visible
247 in the window, and 40% of the text is off-screen to the right.
248 These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
249 option.
250 .TP
251 \fIpathName \fBxview\fR \fIindex\fR
252 Adjusts the view in the window so that the character position given by
253 \fIindex\fR is displayed at the left edge of the window.
254 Character positions are defined by the width of the character \fB0\fR.
255 .TP
256 \fIpathName \fBxview moveto\fI fraction\fR
257 Adjusts the view in the window so that \fIfraction\fR of the
258 total width of the listbox text is off-screen to the left.
259 \fIfraction\fR must be a fraction between 0 and 1.
260 .TP
261 \fIpathName \fBxview scroll \fInumber what\fR
262 This command shifts the view in the window left or right according to
263 \fInumber\fR and \fIwhat\fR.
264 \fINumber\fR must be an integer.
265 \fIWhat\fR must be either \fBunits\fR or \fBpages\fR or an abbreviation
266 of one of these.
267 If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
268 \fInumber\fR character units (the width of the \fB0\fR character)
269 on the display;  if it is \fBpages\fR then the view adjusts by
270 \fInumber\fR screenfuls.
271 If \fInumber\fR is negative then characters farther to the left
272 become visible;  if it is positive then characters farther to the right
273 become visible.
274 .RE
275 .TP
276 \fIpathName \fByview \fI?args\fR?
277 This command is used to query and change the vertical position of the
278 text in the widget's window.
279 It can take any of the following forms:
280 .RS
281 .TP
282 \fIpathName \fByview\fR
283 Returns a list containing two elements, both of which are real fractions
284 between 0 and 1.
285 The first element gives the position of the listbox element at the
286 top of the window, relative to the listbox as a whole (0.5 means
287 it is halfway through the listbox, for example).
288 The second element gives the position of the listbox element just after
289 the last one in the window, relative to the listbox as a whole.
290 These are the same values passed to scrollbars via the \fB\-yscrollcommand\fR
291 option.
292 .TP
293 \fIpathName \fByview\fR \fIindex\fR
294 Adjusts the view in the window so that the element given by
295 \fIindex\fR is displayed at the top of the window.
296 .TP
297 \fIpathName \fByview moveto\fI fraction\fR
298 Adjusts the view in the window so that the element given by \fIfraction\fR
299 appears at the top of the window.
300 \fIFraction\fR is a fraction between 0 and 1;  0 indicates the first
301 element in the listbox, 0.33 indicates the element one-third the
302 way through the listbox, and so on.
303 .TP
304 \fIpathName \fByview scroll \fInumber what\fR
305 This command adjusts the view in the window up or down according to
306 \fInumber\fR and \fIwhat\fR.
307 \fINumber\fR must be an integer.
308 \fIWhat\fR must be either \fBunits\fR or \fBpages\fR.
309 If \fIwhat\fR is \fBunits\fR, the view adjusts up or down by
310 \fInumber\fR lines;  if it is \fBpages\fR then
311 the view adjusts by \fInumber\fR screenfuls.
312 If \fInumber\fR is negative then earlier elements
313 become visible;  if it is positive then later elements
314 become visible.
315 .RE
316
317 .SH "DEFAULT BINDINGS"
318 .PP
319 Ck automatically creates class bindings for listboxes. Much of the
320 behavior of a listbox is determined by its \fBselectMode\fR option,
321 which selects one of three ways of dealing with the selection.
322 .PP
323 If the selection mode is \fBsingle\fR or \fBbrowse\fR, at most one
324 element can be selected in the listbox at once.
325 In both modes, clicking button 1 on an element selects
326 it and deselects any other selected item.
327 .PP
328 If the selection mode is \fBmultiple\fR, any number of elements may
329 be selected at once, including discontiguous ranges.
330 Clicking button 1 on an element toggles its selection state without
331 affecting any other elements.
332 .PP
333 Most people will probably want to use \fBbrowse\fR mode for
334 single selections and \fBmultiple\fR mode for multiple selections.
335 .PP
336 In addition to the above behavior, the following additional behavior
337 is defined by the default bindings:
338 .IP [1]
339 If the Up or Down key is pressed, the location cursor (active
340 element) moves up or down one element.
341 If the selection mode is \fBbrowse\fR then the
342 new active element is also selected and all other elements are
343 deselected.
344 .IP [2]
345 The Left and Right keys scroll the listbox view left and right
346 by the one column.
347 .IP [3]
348 The Prior and Next keys scroll the listbox view up and down
349 by one page (the height of the window).
350 .IP [4]
351 The Home and End keys scroll the listbox horizontally to
352 the left and right edges, respectively.
353 .IP [5]
354 The space and Select keys make a selection at the location cursor
355 (active element) just as if mouse button 1 had been pressed over
356 this element.
357 .PP
358 The behavior of listboxes can be changed by defining new bindings for
359 individual widgets or by redefining the class bindings.
360
361 .SH KEYWORDS
362 listbox, widget