# Copyright (c) 1990 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # =head1 NAME Tk::Listbox - Create and manipulate Listbox widgets =for category Tk Widget Classes =head1 SYNOPSIS I<$listbox> = I<$parent>-EB(?I?); =head1 STANDARD OPTIONS B<-background> B<-borderwidth> B<-cursor> B<-disabledforeground> B<-exportselection> B<-font> B<-foreground> B<-height> B<-highlightbackground> B<-highlightcolor> B<-highlightthickness> B<-offset> B<-relief> B<-selectbackground> B<-selectborderwidth> B<-selectforeground> B<-setgrid> B<-state> B<-takefocus> B<-tile> B<-width> B<-xscrollcommand> B<-yscrollcommand> See L for details of the standard options. =head1 WIDGET-SPECIFIC OPTIONS =over 4 =item Name: B =item Class: B =item Switch: B<-activestyle> Specifies the style in which to draw the active element. This must be one of B (show a focus ring around the active element), B (no special indication of active element) or B (underline the active element). The default is B. =item Name: B =item Class: B =item Switch: B<-height> Specifies the desired height for the window, in lines. If zero or less, then the desired height for the window is made just large enough to hold all the elements in the listbox. =item Name: B =item Class: B =item Switch: B<-listvariable> I Specifies the reference of a variable. The value of the variable is an array to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value. Attempts to assign a variable with an invalid list value to B<-listvariable> will cause an error. Attempts to unset a variable in use as a B<-listvariable> will fail but will not generate an error. =item Name: B =item Class: B =item Switch: B<-selectmode> Specifies one of several styles for manipulating the selection. The value of the option may be arbitrary, but the default bindings expect it to be either B, B, B, or B; the default value is B. =item Name: B =item Class: B =item Switch: B<-state> Specifies one of two states for the listbox: B or B. If the listbox is disabled then items may not be inserted or deleted, items are drawn in the B<-disabledforeground> color, and selection cannot be modified and is not shown (though selection information is retained). =item Name: B =item Class: B =item Switch: B<-width> Specifies the desired width for the window in characters. If the font doesn't have a uniform width then the width of the character ``0'' is used in translating from character units to screen units. If zero or less, then the desired width for the window is made just large enough to hold all the elements in the listbox. =back =head1 DESCRIPTION The B method creates a new window (given by the $widget argument) and makes it into a listbox widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the listbox such as its colors, font, text, and relief. The B command returns its $widget argument. At the time this command is invoked, there must not exist a window named $widget, but $widget's parent must exist. A listbox is a widget that displays a list of strings, one per line. When first created, a new listbox has no elements. Elements may be added or deleted using methods described below. In addition, one or more elements may be selected as described below. If a listbox is exporting its selection (see B option), then it will observe the standard X11 protocols for handling the selection. Listbox selections are available as type B; the value of the selection will be the text of the selected elements, with newlines separating the elements. It is not necessary for all the elements to be displayed in the listbox window at once; commands described below may be used to change the view in the window. Listboxes allow scrolling in both directions using the standard B and B options. They also support scanning, as described below. =head1 INDICES Many of the methods for listboxes take one or more indices as arguments. An index specifies a particular element of the listbox, in any of the following ways: =over 4 =item I Specifies the element as a numerical index, where 0 corresponds to the first element in the listbox. =item B Indicates the element that has the location cursor. This element will be displayed with an underline when the listbox has the keyboard focus, and it is specified with the B method. =item B Indicates the anchor point for the selection, which is set with the B method. =item B Indicates the end of the listbox. For most commands this refers to the last element in the listbox, but for a few commands such as B and B it refers to the element just after the last one. =item B<@>IB<,>I Indicates the element that covers the point in the listbox window specified by I and I (in pixel coordinates). If no element covers that point, then the closest element to that point is used. =back In the method descriptions below, arguments named I, I, and I always contain text indices in one of the above forms. =head1 WIDGET METHODS The B method creates a widget object. This object supports the B and B methods described in L which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic L class. The following additional methods are available for listbox widgets: =over 4 =item I<$listbox>-EB(I) Sets the active element to the one indicated by I. If I is outside the range of elements in the listbox then the closest element is activated. The active element is drawn with an underline when the widget has the input focus, and its index may be retrieved with the index B. =item I<$listbox>-EB(I) Returns a list of four numbers describing the bounding box of the text in the element given by I. The first two elements of the list give the x and y coordinates of the upper-left corner of the screen area covered by the text (specified in pixels relative to the widget) and the last two elements give the width and height of the area, in pixels. If no part of the element given by I is visible on the screen, or if I refers to a non-existent element, then the result is an empty string; if the element is partially visible, the result gives the full area of the element, including any parts that are not visible. =item I<$listbox>-EB Returns a list containing the numerical indices of all of the elements in the listbox that are currently selected. If there are no elements selected in the listbox then an empty string is returned. =item I<$listbox>-EB(I?I?) Deletes one or more elements of the listbox. I and I are indices specifying the first and last elements in the range to delete. If I isn't specified it defaults to I, i.e. a single element is deleted. =item I<$listbox>-EB(I?I?) If I is omitted, returns the contents of the listbox element indicated by I, or an empty string if I refers to a non-existent element. If I is specified, the command returns a list whose elements are all of the listbox elements between I and I, inclusive. Both I and I may have any of the standard forms for indices. =item I<$listbox>-EB(I) Returns the integer index value that corresponds to I. If I is B the return value is a count of the number of elements in the listbox (not the index of the last element). =item I<$listbox>-EB(I?I?) Inserts zero or more new elements in the list just before the element given by I. If I is specified as B then the new elements are added to the end of the list. Returns an empty string. =item I<$listbox>-EB(I, I