Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / Listbox.pod
CommitLineData
86530b38
AT
1# Copyright (c) 1990 The Regents of the University of California.
2# Copyright (c) 1994-1997 Sun Microsystems, Inc.
3# See the file "license.terms" for information on usage and redistribution
4# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5#
6#
7
8=head1 NAME
9
10Tk::Listbox - Create and manipulate Listbox widgets
11
12=for category Tk Widget Classes
13
14=head1 SYNOPSIS
15
16I<$listbox> = I<$parent>-E<gt>B<Listbox>(?I<options>?);
17
18=head1 STANDARD OPTIONS
19
20B<-background> B<-foreground> B<-relief> B<-takefocus>
21B<-borderwidth> B<-height> B<-selectbackground> B<-width>
22B<-cursor> B<-highlightbackground> B<-selectborderwidth> B<-xscrollcommand>
23B<-exportselection> B<-highlightcolor> B<-selectforeground> B<-yscrollcommand>
24B<-font> B<-highlightthickness> B<-setgrid>
25
26See L<Tk::options> for details of the standard options.
27
28=head1 WIDGET-SPECIFIC OPTIONS
29
30=over 4
31
32=item Name: B<height>
33
34=item Class: B<Height>
35
36=item Switch: B<-height>
37
38Specifies the desired height for the window, in lines.
39If zero or less, then the desired height for the window is made just
40large enough to hold all the elements in the listbox.
41
42=item Name: B<selectMode>
43
44=item Class: B<SelectMode>
45
46=item Switch: B<-selectmode>
47
48Specifies one of several styles for manipulating the selection.
49The value of the option may be arbitrary, but the default bindings
50expect it to be either B<single>, B<browse>, B<multiple>,
51or B<extended>; the default value is B<browse>.
52
53=item Name: B<width>
54
55=item Class: B<Width>
56
57=item Switch: B<-width>
58
59Specifies the desired width for the window in characters.
60If the font doesn't have a uniform width then the width of the
61character ``0'' is used in translating from character units to
62screen units.
63If zero or less, then the desired width for the window is made just
64large enough to hold all the elements in the listbox.
65
66=back
67
68=head1 DESCRIPTION
69
70The B<Listbox> method creates a new window (given by the
71$widget argument) and makes it into a listbox widget.
72Additional
73options, described above, may be specified on the command line
74or in the option database
75to configure aspects of the listbox such as its colors, font,
76text, and relief. The B<listbox> command returns its
77$widget argument. At the time this command is invoked,
78there must not exist a window named $widget, but
79$widget's parent must exist.
80
81A listbox is a widget that displays a list of strings, one per line.
82When first created, a new listbox has no elements.
83Elements may be added or deleted using methods described
84below. In addition, one or more elements may be selected as described
85below.
86If a listbox is exporting its selection (see B<exportSelection>
87option), then it will observe the standard X11 protocols
88for handling the selection.
89Listbox selections are available as type B<STRING>;
90the value of the selection will be the text of the selected elements, with
91newlines separating the elements.
92
93It is not necessary for all the elements to be
94displayed in the listbox window at once; commands described below
95may be used to change the view in the window. Listboxes allow
96scrolling in both directions using the standard B<xScrollCommand>
97and B<yScrollCommand> options.
98They also support scanning, as described below.
99
100=head1 INDICES
101
102Many of the methods for listboxes take one or more indices
103as arguments.
104An index specifies a particular element of the listbox, in any of
105the following ways:
106
107=over 4
108
109=item I<number>
110
111Specifies the element as a numerical index, where 0 corresponds
112to the first element in the listbox.
113
114=item B<active>
115
116Indicates the element that has the location cursor. This element
117will be displayed with an underline when the listbox has the
118keyboard focus, and it is specified with the B<activate>
119method.
120
121=item B<anchor>
122
123Indicates the anchor point for the selection, which is set with the
124B<selection anchor> method.
125
126=item B<end>
127
128Indicates the end of the listbox.
129For most commands this refers to the last element in the listbox,
130but for a few commands such as B<index> and B<insert>
131it refers to the element just after the last one.
132
133=item B<@>I<x>B<,>I<y>
134
135Indicates the element that covers the point in the listbox window
136specified by I<x> and I<y> (in pixel coordinates). If no
137element covers that point, then the closest element to that
138point is used.
139
140=back
141
142In the method descriptions below, arguments named I<index>,
143I<first>, and I<last> always contain text indices in one of
144the above forms.
145
146=head1 WIDGET METHODS
147
148The B<Listbox> method creates a widget object.
149This object supports the B<configure> and B<cget> methods
150described in L<Tk::options> which can be used to enquire and
151modify the options described above.
152The widget also inherits all the methods provided by the generic
153L<Tk::Widget|Tk::Widget> class.
154
155The following additional methods are available for listbox widgets:
156
157=over 4
158
159=item I<$listbox>-E<gt>B<activate>(I<index>)
160
161Sets the active element to the one indicated by I<index>.
162If I<index> is outside the range of elements in the listbox
163then the closest element is activated.
164The active element is drawn with an underline when the widget
165has the input focus, and its index may be retrieved with the
166index B<active>.
167
168=item I<$listbox>-E<gt>B<bbox>(I<index>)
169
170Returns a list of four numbers describing the bounding box of
171the text in the element given by I<index>.
172The first two elements of the list give the x and y coordinates
173of the upper-left corner of the screen area covered by the text
174(specified in pixels relative to the widget) and the last two
175elements give the width and height of the area, in pixels.
176If no part of the element given by I<index> is visible on the
177screen,
178or if I<index> refers to a non-existent element,
179then the result is an empty string; if the element is
180partially visible, the result gives the full area of the element,
181including any parts that are not visible.
182
183=item I<$listbox>-E<gt>B<curselection>
184
185Returns a list containing the numerical indices of
186all of the elements in the listbox that are currently selected.
187If there are no elements selected in the listbox then an empty
188string is returned.
189
190=item I<$listbox>-E<gt>B<delete>(I<first, >?I<last>?)
191
192Deletes one or more elements of the listbox. I<First> and I<last>
193are indices specifying the first and last elements in the range
194to delete. If I<last> isn't specified it defaults to
195I<first>, i.e. a single element is deleted.
196
197=item I<$listbox>-E<gt>B<get>(I<first, >?I<last>?)
198
199If I<last> is omitted, returns the contents of the listbox
200element indicated by I<first>,
201or an empty string if I<first> refers to a non-existent element.
202If I<last> is specified, the command returns a list whose elements
203are all of the listbox elements between I<first> and I<last>,
204inclusive.
205Both I<first> and I<last> may have any of the standard
206forms for indices.
207
208=item I<$listbox>-E<gt>B<index>(I<index>)
209
210Returns the integer index value that corresponds to I<index>.
211If I<index> is B<end> the return value is a count of the number
212of elements in the listbox (not the index of the last element).
213
214=item I<$listbox>-E<gt>B<insert>(I<index, >?I<element, element, ...>?)
215
216Inserts zero or more new elements in the list just before the
217element given by I<index>. If I<index> is specified as
218B<end> then the new elements are added to the end of the
219list. Returns an empty string.
220
221=item I<$listbox>-E<gt>B<nearest>(I<y>)
222
223Given a y-coordinate within the listbox window, this command returns
224the index of the (visible) listbox element nearest to that y-coordinate.
225
226=item I<$listbox>-E<gt>B<scan>(I<option, args>)
227
228This command is used to implement scanning on listboxes. It has
229two forms, depending on I<option>:
230
231=over 8
232
233=item I<$listbox>-E<gt>B<scanMark>(I<x, y>)
234
235Records I<x> and I<y> and the current view in the listbox
236window; used in conjunction with later B<scan dragto> commands.
237Typically this command is associated with a mouse button press in
238the widget. It returns an empty string.
239
240=item I<$listbox>-E<gt>B<scanDragto>(I<x, y>.)
241
242This command computes the difference between its I<x> and I<y>
243arguments and the I<x> and I<y> arguments to the last
244B<scan mark> command for the widget.
245It then adjusts the view by 10 times the
246difference in coordinates. This command is typically associated
247with mouse motion events in the widget, to produce the effect of
248dragging the list at high speed through the window. The return
249value is an empty string.
250
251=back
252
253=item I<$listbox>-E<gt>B<see>(I<index>)
254
255Adjust the view in the listbox so that the element given by I<index>
256is visible.
257If the element is already visible then the command has no effect;
258if the element is near one edge of the window then the listbox
259scrolls to bring the element into view at the edge; otherwise
260the listbox scrolls to center the element.
261
262=item I<$listbox>-E<gt>B<selection>(I<option, arg>)
263
264This command is used to adjust the selection within a listbox. It
265has several forms, depending on I<option>:
266
267=over 8
268
269=item I<$listbox>-E<gt>B<selectionAnchor>(I<index>)
270
271Sets the selection anchor to the element given by I<index>.
272If I<index> refers to a non-existent element, then the closest
273element is used.
274The selection anchor is the end of the selection that is fixed
275while dragging out a selection with the mouse.
276The index B<anchor> may be used to refer to the anchor
277element.
278
279=item I<$listbox>-E<gt>B<selectionClear>(I<first, >?I<last>?)
280
281If any of the elements between I<first> and I<last>
282(inclusive) are selected, they are deselected.
283The selection state is not changed for elements outside
284this range.
285
286=item I<$listbox>-E<gt>B<selectionIncludes>(I<index>)
287
288Returns 1 if the element indicated by I<index> is currently
289selected, 0 if it isn't.
290
291=item I<$listbox>-E<gt>B<selectionSet>(I<first, >?I<last>?)
292
293Selects all of the elements in the range between
294I<first> and I<last>, inclusive, without affecting
295the selection state of elements outside that range.
296
297=back
298
299=item I<$listbox>-E<gt>B<size>
300
301Returns a decimal string indicating the total number of elements
302in the listbox.
303
304=item I<$listbox>-E<gt>B<xview>(I<args>)
305
306This command is used to query and change the horizontal position of the
307information in the widget's window. It can take any of the following
308forms:
309
310=over 8
311
312=item I<$listbox>-E<gt>B<xview>
313
314Returns a list containing two elements.
315Each element is a real fraction between 0 and 1; together they describe
316the horizontal span that is visible in the window.
317For example, if the first element is .2 and the second element is .6,
31820% of the listbox's text is off-screen to the left, the middle 40% is visible
319in the window, and 40% of the text is off-screen to the right.
320These are the same values passed to scrollbars via the B<-xscrollcommand>
321option.
322
323=item I<$listbox>-E<gt>B<xview>(I<index>)
324
325Adjusts the view in the window so that the character position given by
326I<index> is displayed at the left edge of the window.
327Character positions are defined by the width of the character B<0>.
328
329=item I<$listbox>-E<gt>B<xview>(B<moveto> =E<gt> I<fraction>)
330
331Adjusts the view in the window so that I<fraction> of the
332total width of the listbox text is off-screen to the left.
333I<fraction> must be a fraction between 0 and 1.
334
335=item I<$listbox>-E<gt>B<xview>(B<scroll> =E<gt> I<number, what>)
336
337This command shifts the view in the window left or right according to
338I<number> and I<what>.
339I<Number> must be an integer.
340I<What> must be either B<units> or B<pages> or an abbreviation
341of one of these.
342If I<what> is B<units>, the view adjusts left or right by
343I<number> character units (the width of the B<0> character)
344on the display; if it is B<pages> then the view adjusts by
345I<number> screenfuls.
346If I<number> is negative then characters farther to the left
347become visible; if it is positive then characters farther to the right
348become visible.
349
350=back
351
352=item I<$listbox>-E<gt>B<yview>(I<?args>?)
353
354This command is used to query and change the vertical position of the
355text in the widget's window.
356It can take any of the following forms:
357
358=over 8
359
360=item I<$listbox>-E<gt>B<yview>
361
362Returns a list containing two elements, both of which are real fractions
363between 0 and 1.
364The first element gives the position of the listbox element at the
365top of the window, relative to the listbox as a whole (0.5 means
366it is halfway through the listbox, for example).
367The second element gives the position of the listbox element just after
368the last one in the window, relative to the listbox as a whole.
369These are the same values passed to scrollbars via the B<-yscrollcommand>
370option.
371
372=item I<$listbox>-E<gt>B<yview>(I<index>)
373
374Adjusts the view in the window so that the element given by
375I<index> is displayed at the top of the window.
376
377=item I<$listbox>-E<gt>B<yview>(B<moveto> =E<gt> I<fraction>)
378
379Adjusts the view in the window so that the element given by I<fraction>
380appears at the top of the window.
381I<Fraction> is a fraction between 0 and 1; 0 indicates the first
382element in the listbox, 0.33 indicates the element one-third the
383way through the listbox, and so on.
384
385=item I<$listbox>-E<gt>B<yview>(B<scroll> =E<gt> I<number, what>)
386
387This command adjusts the view in the window up or down according to
388I<number> and I<what>.
389I<Number> must be an integer.
390I<What> must be either B<units> or B<pages>.
391If I<what> is B<units>, the view adjusts up or down by
392I<number> lines; if it is B<pages> then
393the view adjusts by I<number> screenfuls.
394If I<number> is negative then earlier elements
395become visible; if it is positive then later elements
396become visible.
397
398=back
399
400=back
401
402=head1 DEFAULT BINDINGS
403
404Tk automatically creates class bindings for listboxes that give them
405Motif-like behavior. Much of the behavior of a listbox is determined
406by its B<selectMode> option, which selects one of four ways
407of dealing with the selection.
408
409If the selection mode is B<single> or B<browse>, at most one
410element can be selected in the listbox at once.
411In both modes, clicking button 1 on an element selects
412it and deselects any other selected item.
413In B<browse> mode it is also possible to drag the selection
414with button 1.
415
416If the selection mode is B<multiple> or B<extended>,
417any number of elements may be selected at once, including discontiguous
418ranges. In B<multiple> mode, clicking button 1 on an element
419toggles its selection state without affecting any other elements.
420In B<extended> mode, pressing button 1 on an element selects
421it, deselects everything else, and sets the anchor to the element
422under the mouse; dragging the mouse with button 1
423down extends the selection to include all the elements between
424the anchor and the element under the mouse, inclusive.
425
426Most people will probably want to use B<browse> mode for
427single selections and B<extended> mode for multiple selections;
428the other modes appear to be useful only in special situations.
429
430In addition to the above behavior, the following additional behavior
431is defined by the default bindings:
432
433=over 4
434
435=item [1]
436
437In B<extended> mode, the selected range can be adjusted by pressing
438button 1 with the Shift key down: this modifies the selection to
439consist of the elements between the anchor and the element under
440the mouse, inclusive.
441The un-anchored end of this new selection can also be dragged with
442the button down.
443
444=item [2]
445
446In B<extended> mode, pressing button 1 with the Control key down
447starts a toggle operation: the anchor is set to the element under
448the mouse, and its selection state is reversed. The selection state
449of other elements isn't changed.
450If the mouse is dragged with button 1 down, then the selection state
451of all elements between the anchor and the element under the mouse
452is set to match that of the anchor element; the selection state of
453all other elements remains what it was before the toggle operation
454began.
455
456=item [3]
457
458If the mouse leaves the listbox window with button 1 down, the window
459scrolls away from the mouse, making information visible that used
460to be off-screen on the side of the mouse.
461The scrolling continues until the mouse re-enters the window, the
462button is released, or the end of the listbox is reached.
463
464=item [4]
465
466Mouse button 2 may be used for scanning.
467If it is pressed and dragged over the listbox, the contents of
468the listbox drag at high speed in the direction the mouse moves.
469
470=item [5]
471
472If the Up or Down key is pressed, the location cursor (active
473element) moves up or down one element.
474If the selection mode is B<browse> or B<extended> then the
475new active element is also selected and all other elements are
476deselected.
477In B<extended> mode the new active element becomes the
478selection anchor.
479
480=item [6]
481
482In B<extended> mode, Shift-Up and Shift-Down move the location
483cursor (active element) up or down one element and also extend
484the selection to that element in a fashion similar to dragging
485with mouse button 1.
486
487=item [7]
488
489The Left and Right keys scroll the listbox view left and right
490by the width of the character B<0>.
491Control-Left and Control-Right scroll the listbox view left and
492right by the width of the window.
493Control-Prior and Control-Next also scroll left and right by
494the width of the window.
495
496=item [8]
497
498The Prior and Next keys scroll the listbox view up and down
499by one page (the height of the window).
500
501=item [9]
502
503The Home and End keys scroll the listbox horizontally to
504the left and right edges, respectively.
505
506=item [10]
507
508Control-Home sets the location cursor to the the first element in
509the listbox, selects that element, and deselects everything else
510in the listbox.
511
512=item [11]
513
514Control-End sets the location cursor to the the last element in
515the listbox, selects that element, and deselects everything else
516in the listbox.
517
518=item [12]
519
520In B<extended> mode, Control-Shift-Home extends the selection
521to the first element in the listbox and Control-Shift-End extends
522the selection to the last element.
523
524=item [13]
525
526In B<multiple> mode, Control-Shift-Home moves the location cursor
527to the first element in the listbox and Control-Shift-End moves
528the location cursor to the last element.
529
530=item [14]
531
532The space and Select keys make a selection at the location cursor
533(active element) just as if mouse button 1 had been pressed over
534this element.
535
536=item [15]
537
538In B<extended> mode, Control-Shift-space and Shift-Select
539extend the selection to the active element just as if button 1
540had been pressed with the Shift key down.
541
542=item [16]
543
544In B<extended> mode, the Escape key cancels the most recent
545selection and restores all the elements in the selected range
546to their previous selection state.
547
548=item [17]
549
550Control-slash selects everything in the widget, except in
551B<single> and B<browse> modes, in which case it selects
552the active element and deselects everything else.
553
554=item [18]
555
556Control-backslash deselects everything in the widget, except in
557B<browse> mode where it has no effect.
558
559=item [19]
560
561The F16 key (labelled Copy on many Sun workstations) or Meta-w
562copies the selection in the widget to the clipboard, if there is
563a selection.
564
565The behavior of listboxes can be changed by defining new bindings for
566individual widgets or by redefining the class bindings.
567
568=back
569
570=head1 KEYWORDS
571
572listbox, widget
573
574=cut
575