# Copyright (c) 2000 Jeffrey Hobbs. # Copyright (c) 2000 Ajuba Solutions. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # RCS: @(#) $Id: spinbox.n,v 1.3 2001/12/18 23:02:35 hobbs Exp $ =head1 NAME Tk::Spinbox - Create and manipulate Spinbox widgets =for category Tk Generic Methods =head1 SYNOPSIS I<$spinbox> = I<$parent>-ESpinbox(?I?); -activebackground -highlightthickness -repeatinterval -background -insertbackground -selectbackground -borderwidth -insertborderwidth -selectborderwidth -cursor -insertontime -selectforeground -exportselection -insertwidth -takefocus -font -insertofftime -textvariable -foreground -justify -xscrollcommand -highlightbackground -relief -highlightcolor -repeatdelay =head1 WIDGET-SPECIFIC OPTIONS =over 4 =item Option: B<-buttonbackground> =item Name: B =item Class: B The background color to be used for the spin buttons. =item Option: B<-buttoncursor> =item Name: B =item Class: B The cursor to be used when over the spin buttons. If this is empty (the default), a default cursor will be used. =item Option: B<-buttondownrelief> =item Name: B =item Class: B The relief to be used for the upper spin button. =item Option: B<-buttonuprelief> =item Name: B =item Class: B The relief to be used for the lower spin button. =item Option: B<-command> =item Name: B =item Class: B Specifies a Perl/Tk callback to invoke whenever a Spinbutton is invoked. The callback has these two arguments I to any existing callback arguments: the current value of the widget and the direction of the button press (B or B). =item Option: B<-disabledbackground> =item Name: B =item Class: B Specifies the background color to use when the Spinbox is disabled. If this option is the empty string, the normal background color is used. =item Option: B<-disabledforeground> =item Name: B =item Class: B Specifies the foreground color to use when the Spinbox is disabled. If this option is the empty string, the normal foreground color is used. =item Option: B<-format> =item Name: B =item Class: B Specifies an alternate format to use when setting the string value when using the B<-from> and B<-to> range. This must be a format specifier of the form B<%EpadE.EpadEf>, as it will format a floating-point number. =item Option: B<-from> =item Name: B =item Class: B A floating-point value corresponding to the lowest value for a Spinbox, to be used in conjunction with B<-to> and B<-increment>. When all are specified correctly, the Spinbox will use these values to control its contents. This value must be less than the B<-to> option. If B<-values> is specified, it supercedes this option. =item Option: B<-invalidcommand> =item Alias: B<-invcmd> =item Name: B =item Class: B Specifies a script to eval when B returns 0. Setting it to an empty string disables this feature (the default). The best use of this option is to set it to I. See B below for more information. =item Option: B<-increment> =item Name: B =item Class: B A floating-point value specifying the increment. When used with B<-from> and B<-to>, the value in the widget will be adjusted by B<-increment> when a spin button is pressed (up adds the value, down subtracts the value). =item Option: B<-readonlybackground> =item Name: B =item Class: B Specifies the background color to use when the Spinbox is readonly. If this option is the empty string, the normal background color is used. =item Option: B<-state> =item Name: B =item Class: B Specifies one of three states for the Spinbox: B, B, or B. If the Spinbox is readonly, then the value may not be changed using methods 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 Spinbox is disabled, the value may not be changed, no insertion cursor will be displayed, the contents will not be selectable, and the Spinbox may be displayed in a different color, depending on the values of the B<-disabledforeground> and B<-disabledbackground> options. =item Option: B<-to> =item Name: B =item Class: B A floating-point value corresponding to the highest value for the Spinbox, to be used in conjunction with B<-from> and B<-increment>. When all are specified correctly, the Spinbox will use these values to control its contents. This value must be greater than the B<-from> option. If B<-values> is specified, it supercedes this option. =item Option: B<-validate> =item Name: B =item Class: B 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 Option: B<-validatecommand> =item Alias: B<-vcmd> =item Name: B =item Class: B Specifies a script to evaluate when you want to validate the input in the widget. Setting it to an empty string disables this feature (the default). Validation occurs according to the value of B<-validate>. This command must return a valid boolean value. If it returns 0 (or the valid boolean equivalent) then the value of the widget will not change and the B will be evaluated if it is set. If it returns 1, then value will be changed. See B below for more information. =item Option: B<-values> =item Name: B =item Class: B Must be a proper list value. If specified, the Spinbox will use these values as to control its contents, starting with the first value. This option has precedence over the B<-from> and B<-to> range. =item Option: B<-width> =item Name: B =item Class: B Specifies an integer value indicating the desired width of the Spinbox 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. =item Option: B<-wrap> =item Name: B =item Class: B Must be a proper boolean value. If on, the Spinbox will wrap around the values of data in the widget. =back =head1 DESCRIPTION The B method creates a new window (given by the $spinbox argument) and makes it into a Spinbox widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the Spinbox such as its colors, font, and relief. A B is an extended B widget that allows he user to move, or spin, through a fixed set of ascending or descending values such as times or dates in addition to editing the value as in an B. When first created, a Spinbox's string is empty. A portion of the Spinbox may be selected as described below. If a Spinbox is exporting its selection (see the B option), then it will observe the standard protocols for handling the selection; Spinbox selections are available as type B. Spinboxes also observe the standard Tk rules for dealing with the input focus. When a Spinbox has the input focus it displays an I to indicate where new characters will be inserted. Spinboxes 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; commands described below may be used to change the view in the window. Spinboxes use the standard B<-xscrollcommand> 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 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 Spinbox receives or loses focus. =item B B will be called when the Spinbox receives focus. =item B B will be called when the Spinbox loses focus. =item B B will be called when the Spinbox is edited. =item B B will be called for all above conditions. The B and B callbacks are invoked with at least 5 positional arguments, which are I to any already existing callback arguments: =over 4 =item * 1 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 * 2 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 * 3 The current value of entry i.e. before the proposed change. =item * 4 The index of character string to be added/deleted, if any. Otherwise -1. =item * 5 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. Any problems have been overcome so that using the B will not interfere with the traditional behavior of the Spinbox widget. Using the B for read-only purposes will never cause problems. The danger comes when you try set the B to something that the B would not accept, which causes B to become I (the B will not be triggered). The same happens when an error occurs evaluating the B. Primarily, an error will occur when the B or B encounters an error in its script while evaluating or B does not return a valid boolean value. The B option will also set itself to B when you edit the Spinbox widget from within either the B or the B. Such editions will override the one that was being validated. If you wish to edit the value of the widget during validation and still have the B option set, you should include the command my $val = $spinbox->cget(-validate); $spinbox->configure(-validate => $val); in the B or B (whichever one you were editing the Spinbox widget from). It is also recommended to not set an associated B during validation, as that can cause the Spinbox widget to become out of sync with the B. =back =head1 WIDGET METHODS The B command creates a widget object whose name is $widget. This command may be used to invoke various operations on the widget. It has the following general form: $widget->method(?arg arg ...?); Many of the methods for Spinboxes take one or more indices as arguments. An index specifies a particular character in the Spinbox'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 methods. =item B Indicates the character just after the last one in the Spinbox's string. This is equivalent to specifying a numerical index equal to the length of the Spinbox'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 Spinbox 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 Spinbox window. =item B<@>I In this form, I is treated as an x-coordinate in the Spinbox'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 commands are possible for Spinbox widgets: =over 4 =item I<$widget>-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<$widget>-EB(I