# Copyright (c) 1990-1994 The Regents of the University of California. # Copyright (c) 1994-1996 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::Entry - Create and manipulate Entry widgets =for category Tk Widget Classes =head1 SYNOPSIS S< >I<$entry> = I<$parent>-EB(?I?); =head1 STANDARD OPTIONS B<-background> B<-highlightbackground> B<-insertontime> B<-selectforeground> B<-borderwidth> B<-highlightcolor> B<-insertwidth> B<-takefocus> B<-cursor> B<-highlightthickness> B<-justify> B<-textvariable> B<-exportselection> B<-insertbackground> B<-relief> B<-xscrollcommand> B<-font> B<-insertborderwidth> B<-selectbackground> B<-foreground> B<-insertofftime> B<-selectborderwidth> =head1 WIDGET-SPECIFIC OPTIONS =over 4 =item Command-Line Name: B<-disabledbackground> =item Database Name: B =item Database Class: B Specifies the background color to use when the entry is disabled. If this option is the empty string, the normal background color is used. =item Command-Line Name: B<-disabledforeground> =item Database Name: B =item Database Class: B Specifies the foreground color to use when the entry is disabled. If this option is the empty string, the normal foreground color is used. =item Name: B =item Class: B =item Switch: B<-invalidcommand> =item Alias: B<-invcmd> Specifies a script to eval when B returns 0. Setting it to disables this feature (the default). The best use of this option is to set it to I. See B below for more information. =item Command-Line Name: B<-readonlybackground> =item Database Name: B =item Database Class: B Specifies the background color to use when the entry is read-only. If this option is the empty string, the normal background color is used. =item Name: B =item Class: B =item Switch: B<-show> If this option is specified, then the true contents of the entry are not displayed in the window. Instead, each character in the entry's value will be displayed as the first character in the value of this option, such as ``*''. This is useful, for example, if the entry is to be used to enter a password. If characters in the entry are selected and copied elsewhere, the information copied will be what is displayed, not the true contents of the entry. =item Name: B =item Class: B =item Switch: B<-state> Specifies one of three states for the entry: B, B, or B. If the entry is B, then the value may not be changed using widget commands and no insertion cursor will be displayed, even if the input focus is in the widget; the contents of the widget may still be selected. If the entry is B, the value may not be changed, no insertion cursor will be displayed, the contents will not be selectable, and the entry may be displayed in a different color, depending on the values of the B<-disabledforeground> and B<-disabledbackground> options. =item Name: B =item Class: B =item Switch: B<-validate> Specifies the mode in which validation should operate: B, B, B, B, B, or B. It defaults to B. When you want validation, you must explicitly state which mode you wish to use. See B below for more. =item Name: B =item Class: B =item Switch: B<-validatecommand> =item Alias: B<-vcmd> Specifies a script to eval when you want to validate the input into the entry widget. Setting it to C disables this feature (the default). This command must return a valid boolean value. If it returns 0 (or the valid boolean equivalent) then it means you reject the new edition and it will not occur and the B will be evaluated if it is set. If it returns 1, then the new edition occurs. See B below for more information. =item Name: B =item Class: B =item Switch: B<-width> Specifies an integer value indicating the desired width of the entry window, in average-size characters of the widget's font. If the value is less than or equal to zero, the widget picks a size just large enough to hold its current text. =back =head1 DESCRIPTION The B method creates a new window (given by the $entry argument) and makes it into an entry widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the entry such as its colors, font, and relief. The B command returns its $entry argument. At the time this command is invoked, there must not exist a window named $entry, but $entry's parent must exist. An entry is a widget that displays a one-line text string and allows that string to be edited using methods described below, which are typically bound to keystrokes and mouse actions. When first created, an entry's string is empty. A portion of the entry may be selected as described below. If an entry is exporting its selection (see the B option), then it will observe the standard X11 protocols for handling the selection; entry selections are available as type B. Entries also observe the standard Tk rules for dealing with the input focus. When an entry has the input focus it displays an I to indicate where new characters will be inserted. Entries are capable of displaying strings that are too long to fit entirely within the widget's window. In this case, only a portion of the string will be displayed; methods described below may be used to change the view in the window. Entries use the standard B mechanism for interacting with scrollbars (see the description of the B<-xscrollcommand> option for details). They also support scanning, as described below. =head1 VALIDATION Validation of entry widgets is derived from part of the patch written by jhobbs@cs.uoregon.edu. This works by setting the B option to a callback which will be evaluated according to the B option as follows: =over 4 =item B Default. This means no validation will occur. =item B B will be called when the entry receives or loses focus. =item B B will be called when the entry receives focus. =item B B will be called when the entry loses focus. =item B B will be called when the entry is edited. =item B B will be called for all above conditions. =back The B and B are called with the following arguments: =over 4 =item * The proposed value of the entry. If you are configuring the entry widget to have a new textvariable, this will be the value of that textvariable. =item * The characters to be added (or deleted). This will be C if validation is due to focus, explcit call to validate or if change is due to C<-textvariable> changing. =item * The current value of entry i.e. before the proposed change. =item * index of char string to be added/deleted, if any. -1 otherwise =item * type of action. 1 == INSERT, 0 == DELETE, -1 if it's a forced validation or textvariable validation =back In general, the B and B can be dangerous to mix. If you try set the B to something that the B will not accept it will be set back to the value of the entry widget. Using the B for read-only purposes will never cause problems. The B will turn itself off by setting B to B when an error occurs, for example when the B or B encounters an error in its script while evaluating, or B does not return a valid boolean value. With the perl/Tk version B option is supposed to be "suspended" while executing the B or the B. This is experimental but in theory either callback can "correct" the value of the widget, and override the proposed change. (B should still return false to inhibit the change from happening when it returns.) =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. Many of the additional methods for entries take one or more indices as arguments. An index specifies a particular character in the entry's string, in any of the following ways: =over 4 =item I Specifies the character as a numerical index, where 0 corresponds to the first character in the string. =item B Indicates the anchor point for the selection, which is set with the B and B methods. =item B Indicates the character just after the last one in the entry's string. This is equivalent to specifying a numerical index equal to the length of the entry's string. =item B Indicates the character adjacent to and immediately following the insertion cursor. =item B Indicates the first character in the selection. It is an error to use this form if the selection isn't in the entry window. =item B Indicates the character just after the last one in the selection. It is an error to use this form if the selection isn't in the entry window. =item B<@>I In this form, I is treated as an x-coordinate in the entry's window; the character spanning that x-coordinate is used. For example, ``B<@0>'' indicates the left-most character in the window. =back Abbreviations may be used for any of the forms above, e.g. ``B'' or ``B''. In general, out-of-range indices are automatically rounded to the nearest legal value. The following additional methods are available for entry widgets: =over 4 =item I<$entry>-EB(I) Returns a list of four numbers describing the bounding box of the character 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 character (in pixels relative to the widget) and the last two elements give the width and height of the character, in pixels. The bounding box may refer to a region outside the visible area of the window. =item I<$entry>-EB(I?I?) Returns the current value of the configuration option given by I