Debian Codegraph @

pod/TList.pod

raw
1 # Copyright (c) 1996, Expert Interface Technologies
2 # See the file "license.terms" for information on usage and redistribution
3 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
4 #
5 # The file man.macros and some of the macros used by this file are
6 # copyrighted: (c) 1990 The Regents of the University of California.
7 # (c) 1994-1995 Sun Microsystems, Inc.
8 # The license terms of the Tcl/Tk distribution are in the file
9 # license.tcl.
10
11 =head1 NAME
12
13 Tk::TList - Create and manipulate Tix Tabular List widgets
14
15 =for category Tix Extensions
16
17 =head1 SYNOPSIS
18
19 S< >I<$tlist> = I<$parent>-E<gt>B<TList>(?I<options>?);
20
21 =head1 SUPER-CLASS
22
23 None.
24
25 =head1 STANDARD OPTIONS
26
27 B<-background> B<-borderwidth> B<-class> B<-cursor> B<-foreground>
28 B<-font> B<-height> B<-highlightcolor> B<-highlightthickness>
29 B<-relief> B<-selectbackground> B<-selectforeground>
30 B<-xscrollcommand> B<-yscrollcommand> B<-width>
31
32 See L<Tk::options> for details of the standard options.
33
34 =head1 WIDGET-SPECIFIC OPTIONS
35
36 =over 4
37
38 =item Name: B<browsecmd>
39
40 =item Class: B<BrowseCmd>
41
42 =item Switch: B<-browsecmd>
43
44 Specifies a perl/Tk B<callback> to be executed when the user browses through the
45 entries in the TList widget.
46
47 =item Name: B<command>
48
49 =item Class: B<Command>
50
51 =item Switch: B<-command>
52
53 Specifies the perl/Tk B<callback> to be executed when the user invokes a list
54 entry in the TList widget. Normally the user invokes a list
55 entry by double-clicking it or pressing the Return key.
56
57 =item Name: B<foreground>
58
59 =item Class: B<Foreground>
60
61 =item Switch: B<-foreground>
62
63 =item Alias: B<-fg>
64
65 Specifies the default foreground color for the list entries.
66
67 =item Name: B<height>
68
69 =item Class: B<Height>
70
71 =item Switch: B<-height>
72
73 Specifies the desired height for the window in number of characters.
74
75 =item Name: B<itemType>
76
77 =item Class: B<ItemType>
78
79 =item Switch: B<-itemtype>
80
81 Specifies the default type of display item for this TList widget. When
82 you call the B<insert> methods, display items of this
83 type will be created if the B<-itemtype> option is not specified.
84
85 =item Name: B<orient>
86
87 =item Class: B<Orient>
88
89 =item Switch: B<-orient>
90
91 Specifies the order of tabularizing the list entries. When set to
92 "B<vertical>", the entries are arranged in a column, from top to
93 bottom. If the entries cannot be contained in one column, the
94 remaining entries will go to the next column, and so on. When set to
95 "B<horizontal>", the entries are arranged in a row, from left to
96 right. If the entries cannot be contained in one row, the remaining
97 entries will go to the next row, and so on.
98
99 =item Name: B<padX>
100
101 =item Class: B<Pad>
102
103 =item Switch: B<-padx>
104
105 The default horizontal padding for list entries.
106
107 =item Name: B<padY>
108
109 =item Class: B<Pad>
110
111 =item Switch: B<-padx>
112
113 The default vertical padding for list entries.
114
115 =item Name: B<selectBackground>
116
117 =item Class: B<SelectBackground>
118
119 =item Switch: B<-selectbackground>
120
121 Specifies the background color for the selected list entries.
122
123 =item Name: B<selectBorderWidth>
124
125 =item Class: B<BorderWidth>
126
127 =item Switch: B<-selectborderwidth>
128
129 Specifies a non-negative value indicating the width of the 3-D border
130 to draw around selected items. The value may have any of the forms
131 acceptable to B<Tk_GetPixels>.
132
133 =item Name: B<selectForeground>
134
135 =item Class: B<SelectForeground>
136
137 =item Switch: B<-selectforeground>
138
139 Specifies the foreground color for the selected list entries.
140
141 =item Name: B<selectMode>
142
143 =item Class: B<SelectMode>
144
145 =item Switch: B<-selectmode>
146
147 Specifies one of several styles for manipulating the selection. The
148 value of the option may be arbitrary, but the default bindings expect
149 it to be either B<single>, B<browse>, B<multiple>, or
150 B<extended>; the default value is B<single>.
151
152 =item Name: B<sizeCmd>
153
154 =item Class: B<SizeCmd>
155
156 =item Switch: B<-sizecmd>
157
158 Specifies a perl/Tk B<callback> to be called whenever the TList widget
159 changes its size. This command can be useful to implement "user scroll
160 bars when needed" features.
161
162 =item Name: B<state>
163
164 =item Class: B<State>
165
166 =item Switch: B<-state>
167
168 Specifies whether the TList command should react to user actions. When
169 set to "B<normal>", the TList reacts to user actions in the normal
170 way. When set to "B<disabled>", the TList can only be scrolled, but
171 its entries cannot be selected or activated.
172
173 =item Name: B<width>
174
175 =item Class: B<Width>
176
177 =item Switch: B<-width>
178
179 Specifies the desired width for the window in characters.
180
181 =back
182
183 =head1 DESCRIPTION
184
185 The B<TList> method creates a new window (given by the
186 $widget argument) and makes it into a TList widget.
187 Additional options, described above, may be specified on the command
188 line or in the option database to configure aspects of the
189 TList widget such as its cursor and relief.
190
191 The TList widget can be used to display data in a tabular format. The
192 list entries of a TList widget are similar to the entries in the Tk
193 listbox widget. The main differences are (1) the TList widget can
194 display the list entries in a two dimensional format and (2) you can
195 use graphical images as well as multiple colors and fonts for
196 the list entries.
197
198 Each list entry is identified by an B<index>, which can be in the
199 following forms:
200
201 =over 4
202
203 =item I<number>
204
205 An integer that indicates the position of the entry in the list. 0
206 means the first position, 1 means the second position, and so on.
207
208 =item B<end>
209
210 Indicates the end of the listbox. For some commands this means just
211 after the last entry; for other commands it means the last entry.
212
213 =item B<@>I<x>,I<y>
214
215 Indicates the element that covers the point in the listbox window
216 specified by x and y (in pixel coordinates). If no element covers that
217 point, then the closest element to that point is used.
218
219 =back
220
221 =head1 DISPLAY ITEMS
222
223 Each list entry in an TList widget is associated with a B<display>
224 item. The display item determines what visual information should
225 be displayed for this list entry. Please see L<Tk::DItem>
226 for a list of all display items.
227
228 When a list entry is created by the B<insert> command, the type of
229 its display item is determined by the B<-itemtype> option passed
230 to these commands. If the B<-itemtype> is omitted, then by default
231 the type specified by this TList widget's B<-itemtype> option is
232 used.
233
234 =head1 WIDGET METHODS
235
236 The B<TList> method creates a widget object.
237
238 This object supports the B<configure> and B<cget> methods
239 described in L<Tk::options> which can be used to enquire and
240 modify the options described above.
241 The widget also inherits all the methods provided by the generic
242 L<Tk::Widget|Tk::Widget> class.
243
244 The following additional methods are available for TList widgets:
245
246 =over 4
247
248 =item I<$tlist>-E<gt>B<anchorSet>(I<index>)
249
250 Sets the anchor to the list entry identified by I<index>. The
251 anchor is the end of the selection that is fixed while dragging out a
252 selection with the mouse.
253
254 =item I<$tlist>-E<gt>B<anchorClear>
255
256 Removes the anchor, if any, from this TList widget. This only removes
257 the surrounding highlights of the anchor entry and does not affect its
258 selection status.
259
260 =item I<$tlist>-E<gt>B<delete>(I<from, >?I<to>?)
261
262 Deletes one or more list entries between the two entries specified by
263 the indices I<from> and I<to>. If I<to> is not specified, deletes
264 the single entry specified by I<from>.
265
266 =item I<$tlist>-E<gt>B<dragsiteSet>(I<index>)
267
268 Sets the dragsite to the list entry identified by
269 I<index>. The dragsite is used to indicate the source of a
270 drag-and-drop action. Currently drag-and-drop functionality has not
271 been implemented in Tix yet.
272
273 =item I<$tlist>-E<gt>B<dragsiteClear>
274
275 Remove the dragsite, if any, from the this TList widget. This only
276 removes the surrounding highlights of the dragsite entry and does not
277 affect its selection status.
278
279 =item I<$tlist>-E<gt>B<dropsiteSet>(I<index>)
280
281 Sets the dropsite to the list entry identified by I<index>. The
282 dropsite is used to indicate the target of a drag-and-drop
283 action. Currently drag-and-drop functionality has not been implemented
284 in Tix yet.
285
286 =item I<$tlist>-E<gt>B<dropsiteClear>
287
288 Remove the dropsite, if any, from the this TList widget. This only
289 removes the surrounding highlights of the dropsite entry and does not
290 affect its selection status.
291
292 =item I<$tlist>-E<gt>B<entrycget>(I<index, option>)
293
294 Returns the current value of the configuration option given by
295 I<option> for the entry indentfied by I<index>. I<Option> may
296 have any of the values accepted by the B<insert> method.
297
298 =item I<$tlist>-E<gt>B<entryconfigure>(I<index, >?I<option>?, I<?value, option, value, ...>?)
299
300 Query or modify the configuration options of the list entry identified
301 by I<index>. If no I<option> is specified, returns a list
302 describing all of the available options for I<index> (see
303 B<Tk_ConfigureInfo> for information on the format of this list). If
304 I<option> is specified with no I<value>, then the method
305 returns a list describing the one named option (this list will be
306 identical to the corresponding sublist of the value returned if no
307 I<option> is specified). If one or more I<option-value> pairs
308 are specified, then the command modifies the given option(s) to have
309 the given value(s); in this case the method returns an empty string.
310 I<Option> may have any of the values accepted by the B<insert>
311 method. The exact set of options depends on the
312 value of the B<-itemtype> option passed to the the B<insert>
313 method when this list entry is created.
314
315 =item I<$tlist>-E<gt>B<insert>(I<index, >?I<option, value, ...>?)
316
317 Creates a new list entry at the position indicated by I<index>. The
318 following configuration options can be given to configure the list
319 entry:
320
321 =over 8
322
323 =item B<-itemtype> => I<type>
324
325 Specifies the type of display item to be display for the new list
326 entry. I<type> must be a valid display item type. Currently the
327 available display item types are B<image>, B<imagetext>,
328 B<text>, and I<$widget>. If this option is not specified, then by
329 default the type specified by this TList widget's B<-itemtype>
330 option is used.
331
332 =item B<-state> => I<state>
333
334 Specifies whether this entry can be selected or invoked by the user.
335 Must be either B<normal> or B<disabled>.
336
337 =item B<-data> => I<data>
338
339 Arbitrary data to be associated with the entry (a perl scalar value).
340
341 =back
342
343 The B<insert> method accepts additional configuration options
344 to configure the display item associated with this list entry. The set
345 of additional configuration options depends on the type of the display
346 item given by the B<-itemtype> option. Please see
347 L<Tk::DItem> for a list of the configuration options for
348 each of the display item types.
349
350 =item I<$tlist>-E<gt>B<info>(I<option, >I<arg, ...>)
351
352 Query information about the TList widget. I<option> can be one
353 of the following:
354
355 =over 8
356
357 =item I<$tlist>-E<gt>B<info>(B<anchor, >I<index>)
358
359 Returns the index of the current anchor, if any, of the TList
360 widget. If the anchor is not set, returns the empty string.
361
362 =item I<$tlist>-E<gt>B<info>(B<dragsite, >I<index>)
363
364 Returns the index of the current dragsite, if any, of the TList
365 widget. If the dragsite is not set, returns the empty string.
366
367 =item I<$tlist>-E<gt>B<info>(B<dropsite, >I<index>)
368
369 Returns the index of the current dropsite, if any, of the TList
370 widget. If the dropsite is not set, returns the empty string.
371
372 =item I<$tlist>-E<gt>B<info>(B<selection>)
373
374 Returns a list of selected elements in the TList widget. If no entries
375 are selected, returns an empty string.
376
377 =back
378
379 =item I<$tlist>-E<gt>B<nearest>(I<x, y>)
380
381 Given an I<(x,y)> coordinate within the TList window, this command
382 returns the index of the TList element nearest to that coordinate.
383
384 =item I<$tlist>-E<gt>B<see>(I<index>)
385
386 Adjust the view in the TList so that the entry given by I<index> is
387 visible. If the entry is already visible then the command has no
388 effect; otherwise TList scrolls to bring the element into view at the edge
389 to which it is nearest.
390
391 =item I<$tlist>-E<gt>B<selection>(I<option, >I<arg, ...>)
392
393 This command is used to adjust the selection within a TList widget. It
394 has several forms, depending on I<option>:
395
396 =over 8
397
398 =item I<$tlist>-E<gt>B<selectionClear>(?I<from>?, ?I<to>?)
399
400 When no extra arguments are given, deselects all of the list entrie(s)
401 in this TList widget. When only I<from> is given, only the list
402 entry identified by I<from> is deselected. When both I<from> and
403 I<to> are given, deselects all of the list entrie(s) between
404 between I<from> and I<to>, inclusive, without affecting the
405 selection state of entries outside that range.
406
407 =item I<$tlist>-E<gt>B<selectionIncludes>(I<index>)
408
409 Returns 1 if the list entry indicated by I<index> is currently
410 selected; returns 0 otherwise.
411
412 =item I<$tlist>-E<gt>B<selectionSet>(I<from, >?I<to>?)
413
414 Selects all of the list entrie(s) between between I<from> and
415 I<to>, inclusive, without affecting the selection state of entries
416 outside that range. When only I<from> is given, only the list entry
417 identified by I<from> is selected.
418
419 =back
420
421 =item I<$tlist>-E<gt>B<xview>(I<args>)
422
423 This command is used to query and change the horizontal position of the
424 information in the widget's window. It can take any of the following
425 forms:
426
427 =over 8
428
429 =item I<$tlist>-E<gt>B<xview>
430
431 Returns a list containing two elements. Each element is a real
432 fraction between 0 and 1; together they describe the horizontal span
433 that is visible in the window. For example, if the first element is
434 0.2 and the second element is 0.6, 20% of the TList entry is
435 off-screen to the left, the middle 40% is visible in the window, and
436 40% of the entry is off-screen to the right. These are the same values
437 passed to scrollbars via the B<-xscrollcommand> option.
438
439 =item I<$tlist>-E<gt>B<xview>(I<index>)
440
441 Adjusts the view in the window so that the list entry identified by
442 I<index> is aligned to the left edge of the window.
443
444 =item I<$tlist>-E<gt>B<xviewMoveto>(I<fraction>)
445
446 Adjusts the view in the window so that I<fraction> of the total
447 width of the TList is off-screen to the left. I<fraction> must be
448 a fraction between 0 and 1.
449
450 =item I<$tlist>-E<gt>B<xviewScroll>(I<number, what>)
451
452 This command shifts the view in the window left or right according to
453 I<number> and I<what>. I<Number> must be an integer.
454 I<What> must be either B<units> or B<pages> or an
455 abbreviation of one of these. If I<what> is B<units>, the view
456 adjusts left or right by I<number> character units (the width of
457 the B<0> character) on the display; if it is B<pages> then the
458 view adjusts by I<number> screenfuls. If I<number> is negative
459 then characters farther to the left become visible; if it is positive
460 then characters farther to the right become visible.
461
462 =back
463
464 =item I<$tlist>-E<gt>B<yview>(I<?args>?)
465
466 This command is used to query and change the vertical position of the
467 entries in the widget's window. It can take any of the following forms:
468
469 =over 8
470
471 =item I<$tlist>-E<gt>B<yview>
472
473 Returns a list containing two elements, both of which are real
474 fractions between 0 and 1. The first element gives the position of
475 the list element at the top of the window, relative to the TList as a
476 whole (0.5 means it is halfway through the TList, for example). The
477 second element gives the position of the list entry just after the
478 last one in the window, relative to the TList as a whole. These are
479 the same values passed to scrollbars via the B<-yscrollcommand>
480 option.
481
482 =item I<$tlist>-E<gt>B<yview>(I<index>)
483
484 Adjusts the view in the window so that the list entry given by
485 I<index> is displayed at the top of the window.
486
487 =item I<$tlist>-E<gt>B<yviewMoveto>(I<fraction>)
488
489 Adjusts the view in the window so that the list entry given by
490 I<fraction> appears at the top of the window. I<Fraction> is a
491 fraction between 0 and 1; 0 indicates the first entry in the TList,
492 0.33 indicates the entry one-third the way through the TList, and so
493 on.
494
495 =item I<$tlist>-E<gt>B<yviewScroll>(I<number, what>)
496
497 This command adjust the view in the window up or down according to
498 I<number> and I<what>. I<Number> must be an integer.
499 I<What> must be either B<units> or B<pages>. If I<what>
500 is B<units>, the view adjusts up or down by I<number> lines; if
501 it is B<pages> then the view adjusts by I<number> screenfuls.
502 If I<number> is negative then earlier entries become visible; if
503 it is positive then later entries become visible.
504
505 =back
506
507 =back
508
509 =head1 BINDINGS
510
511 =over 4
512
513 =item [1]
514
515 If the B<-selectmode> is "browse", when the user drags the mouse
516 pointer over the list entries, the entry under the pointer will be
517 highlighted and the B<-browsecmd> procedure will be called with
518 one parameter, the index of the highlighted entry. Only one entry
519 can be highlighted at a time. The B<-command> procedure will be
520 called when the user double-clicks on a list entry.
521
522 =item [2]
523
524 If the B<-selectmode> is "single", the entries will only be
525 highlighted by mouse E<lt>ButtonRelease-1E<gt> events. When a new list entry
526 is highlighted, the B<-browsecmd> procedure will be called with
527 one parameter indicating the highlighted list entry. The
528 B<-command> procedure will be called when the user double-clicks
529 on a list entry.
530
531 =item [3]
532
533 If the B<-selectmode> is "multiple", when the user drags the mouse
534 pointer over the list entries, all the entries under the pointer will
535 be highlighted. However, only a contiguous region of list entries can
536 be selected. When the highlighted area is changed, the
537 B<-browsecmd> procedure will be called with an undefined
538 parameter. It is the responsibility of the B<-browsecmd> procedure
539 to find out the exact highlighted selection in the TList. The
540 B<-command> procedure will be called when the user double-clicks
541 on a list entry.
542
543 =item [4]
544
545 If the B<-selectmode> is "extended", when the user drags the mouse
546 pointer over the list entries, all the entries under the pointer will
547 be highlighted. The user can also make disjointed selections using
548 E<lt>Control-ButtonPress-1E<gt>. When the highlighted area is changed, the
549 B<-browsecmd> procedure will be called with an undefined
550 parameter. It is the responsibility of the B<-browsecmd> procedure
551 to find out the exact highlighted selection in the TList. The
552 B<-command> procedure will be called when the user double-clicks
553 on a list entry.
554
555 =back
556
557 =cut
558
559 # BUG:
560 # click on 'one' in example below does not make
561 # it 'active' item (didn't GBARR reported this before!?)
562
563 =head1 EXAMPLE
564
565 This example demonstrates how to use an TList to store a list of
566 numbers:
567
568 use strict;
569 use Tk ();
570 use Tk::TList;
571
572 my $mw = Tk::MainWindow->new();
573 my $image = $mw->Getimage('folder');
574 my $tlist = $mw->TList(-orient => 'vertical');
575 for my $text ( qw/one two three four five six seven eight nine/ ) {
576 $tlist->insert('end',
577 -itemtype=>'imagetext', -image=>$image, -text=>$text);
578 }
579
580 $tlist->pack(-expand=>'yes', -fill=>'both');
581
582 Tk::MainLoop;
583
584 =head1 SEE ALSO
585
586 L<Tk::options|Tk::options>
587 L<Tk::Widget|Tk::Widget>
588 L<Tk::DItem|Tk::DItem>
589 L<Tk::HList|Tk::HList>
590 L<Tk::TixGrid|Tk::TixGrid>
591
592 =head1 KEYWORDS
593
594 Tix(n), Tabular Listbox, Display Items
595
596 =cut
597