Debian Codegraph @

pod/Checkbutton.pod

raw
1 # Copyright (c) 1990-1994 The Regents of the University of California.
2 # Copyright (c) 1994-1996 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
10 Tk::Checkbutton - Create and manipulate Checkbutton widgets
11
12 =for category Tk Widget Classes
13
14 =head1 SYNOPSIS
15
16 I<$checkbutton> = I<$parent>-E<gt>B<Checkbutton>(?I<options>?);
17
18 =head1 STANDARD OPTIONS
19
20 B<-activebackground>
21 B<-activeforeground>
22 B<-anchor>
23 B<-background>
24 B<-bitmap>
25 B<-borderwidth>
26 B<-compound>
27 B<-cursor>
28 B<-disabledforeground>
29 B<-font>
30 B<-foreground>
31 B<-highlightbackground>
32 B<-highlightcolor>
33 B<-highlightthickness>
34 B<-image>
35 B<-justify>
36 B<-padx>
37 B<-pady>
38 B<-relief>
39 B<-takefocus>
40 B<-text>
41 B<-textvariable>
42 B<-underline>
43 B<-wraplength>
44
45 See L<Tk::options> for details of the standard options.
46
47 =head1 WIDGET-SPECIFIC OPTIONS
48
49 =over 4
50
51 =item Name: B<command>
52
53 =item Class: B<Command>
54
55 =item Switch: B<-command>
56
57 Specifies a L<perlE<sol>Tk callback|Tk::callbacks> to associate with the button. This command
58 is typically invoked when mouse button 1 is released over the button
59 window. The button's global variable (B<-variable> option) will
60 be updated before the command is invoked.
61
62 =item Name: B<height>
63
64 =item Class: B<Height>
65
66 =item Switch: B<-height>
67
68 Specifies a desired height for the button.
69 If an image or bitmap is being displayed in the button then the value is in
70 screen units (i.e. any of the forms acceptable to B<Tk_GetPixels>);
71 for text it is in lines of text.
72 If this option isn't specified, the button's desired height is computed
73 from the size of the image or bitmap or text being displayed in it.
74
75 =item Name: B<indicatorOn>
76
77 =item Class: B<IndicatorOn>
78
79 =item Switch: B<-indicatoron>
80
81 Specifies whether or not the indicator should be drawn. Must be a
82 proper boolean value. If false, the B<relief> option is
83 ignored and the widget's relief is always sunken if the widget is
84 selected and raised otherwise.
85
86 =item Command-Line Name: B<-offrelief>
87
88 =item Database Name: B<offRelief>
89
90 =item Database Class: B<OffRelief>
91
92 Specifies the relief for the checkbutton when the indicator is not
93 drawn and the checkbutton is off. The default value is B<raised>. By
94 setting this option to B<flat> and setting
95 B<-indicatoron false -overrelief raised>, the effect is achieved of
96 having a flat button
97 that raises on mouse-over and which is depressed when activated. This
98 is the behavior typically exhibited by the Bold, Italic, and
99 Underline checkbuttons on the toolbar of a word-processor, for
100 example.
101
102 =item Name: B<offValue>
103
104 =item Class: B<Value>
105
106 =item Switch: B<-offvalue>
107
108 Specifies value to store in the button's associated variable whenever
109 this button is deselected. Defaults to ``0''.
110
111 =item Name: B<onValue>
112
113 =item Class: B<Value>
114
115 =item Switch: B<-onvalue>
116
117 Specifies value to store in the button's associated variable whenever
118 this button is selected. Defaults to ``1''.
119
120 =item Command-Line Name: B<-overrelief>
121
122 =item Database Name: B<overRelief>
123
124 =item Database Class: B<OverRelief>
125
126 Specifies an alternative relief for the button, to be used when
127 the mouse cursor is over the widget. This option can be used to
128 make toolbar buttons, by configuring B<-relief flat -overrelief
129 raised>. If the value of this option is the empty string, then
130 no alternative relief is used when the mouse cursor is over the
131 button. The empty string is the default value.
132
133 =item Name: B<selectColor>
134
135 =item Class: B<Background>
136
137 =item Switch: B<-selectcolor>
138
139 Specifies a background color to use when the button is selected.
140 If B<indicatorOn> is true then the color applies to the indicator.
141 Under Windows, this color is used as the background for the indicator
142 regardless of the select state.
143 If B<indicatorOn> is false, this color is used as the background
144 for the entire widget, in place of B<background> or B<activeBackground>,
145 whenever the widget is selected.
146 If specified as an empty string then no special color is used for
147 displaying when the widget is selected.
148
149 =item Name: B<selectImage>
150
151 =item Class: B<SelectImage>
152
153 =item Switch: B<-selectimage>
154
155 Specifies an image to display (in place of the B<image> option)
156 when the checkbutton is selected.
157 This option is ignored unless the B<image> option has been
158 specified.
159
160 =item Name: B<state>
161
162 =item Class: B<State>
163
164 =item Switch: B<-state>
165
166 Specifies one of three states for the checkbutton: B<normal>, B<active>,
167 or B<disabled>. In normal state the checkbutton is displayed using the
168 B<foreground> and B<background> options. The active state is
169 typically used when the pointer is over the checkbutton. In active state
170 the checkbutton is displayed using the B<activeForeground> and
171 B<activeBackground> options. Disabled state means that the checkbutton
172 should be insensitive: the default bindings will refuse to activate
173 the widget and will ignore mouse button presses.
174 In this state the B<disabledForeground> and
175 B<background> options determine how the checkbutton is displayed.
176
177 =item Name: B<variable>
178
179 =item Class: B<Variable>
180
181 =item Switch: B<-variable>
182
183 Specifies reference to a variable to set to indicate whether
184 or not this button is selected. Defaults to C<\$widget-E<gt>{'Value'}>
185 member of the widget's hash. In general perl variables are C<undef> unless
186 specifically initialized which will not match either default B<-onvalue> or
187 default B<-offvalue>.
188
189 =item Name: B<width>
190
191 =item Class: B<Width>
192
193 =item Switch: B<-width>
194
195 Specifies a desired width for the button.
196 If an image or bitmap is being displayed in the button then the value is in
197 screen units (i.e. any of the forms acceptable to B<Tk_GetPixels>);
198 for text it is in characters.
199 If this option isn't specified, the button's desired width is computed
200 from the size of the image or bitmap or text being displayed in it.
201
202 =back
203
204 =head1 DESCRIPTION
205
206 The B<Checkbutton> method creates a new window (given by the
207 $widget argument) and makes it into a checkbutton widget.
208 Additional
209 options, described above, may be specified on the command line
210 or in the option database
211 to configure aspects of the checkbutton such as its colors, font,
212 text, and initial relief. The B<checkbutton> command returns its
213 $widget argument. At the time this command is invoked,
214 there must not exist a window named $widget, but
215 $widget's parent must exist.
216
217 A checkbutton is a widget
218 that displays a textual string, bitmap or image
219 and a square called an I<indicator>.
220 If text is displayed, it must all be in a single font, but it
221 can occupy multiple lines on the screen (if it contains newlines
222 or if wrapping occurs because of the B<wrapLength> option) and
223 one of the characters may optionally be underlined using the
224 B<underline> option.
225 A checkbutton has
226 all of the behavior of a simple button, including the
227 following: it can display itself in either of three different
228 ways, according to the B<state> option;
229 it can be made to appear
230 raised, sunken, or flat; it can be made to flash; and it invokes
231 a L<perlE<sol>Tk callback|Tk::callbacks> whenever mouse button 1 is clicked over the
232 checkbutton.
233
234 In addition, checkbuttons can be I<selected>.
235 If a checkbutton is selected then the indicator is normally
236 drawn with a selected appearance, and
237 a Tcl variable associated with the checkbutton is set to a particular
238 value (normally 1).
239 Under Unix, the indicator is drawn with a sunken relief and a special
240 color. Under Windows, the indicator is drawn with a check mark inside.
241 If the checkbutton is not selected, then the indicator is drawn with a
242 deselected appearance, and the associated variable is
243 set to a different value (typically 0).
244 Under Unix, the indicator is drawn with a raised relief and no special
245 color. Under Windows, the indicator is drawn without a check mark inside.
246 By default, the name of the variable associated with a checkbutton is the
247 same as the I<name> used to create the checkbutton.
248 The variable name, and the ``on'' and ``off'' values stored in it,
249 may be modified with options on the command line or in the option
250 database.
251 Configuration options may also be used to modify the way the
252 indicator is displayed (or whether it is displayed at all).
253 By default a checkbutton is configured to select and deselect
254 itself on alternate button clicks.
255 In addition, each checkbutton monitors its associated variable and
256 automatically selects and deselects itself when the variables value
257 changes to and from the button's ``on'' value.
258
259 =head1 WIDGET METHODS
260
261 The B<Checkbutton> method creates a widget object.
262 This object supports the B<configure> and B<cget> methods
263 described in L<Tk::options> which can be used to enquire and
264 modify the options described above.
265 The widget also inherits all the methods provided by the generic
266 L<Tk::Widget|Tk::Widget> class.
267
268 The following additional methods are available for checkbutton widgets:
269
270 =over 4
271
272 =item I<$checkbutton>-E<gt>B<deselect>
273
274 Deselects the checkbutton and sets the associated variable to its ``off''
275 value.
276
277 =item I<$checkbutton>-E<gt>B<flash>
278
279 Flashes the checkbutton. This is accomplished by redisplaying the checkbutton
280 several times, alternating between active and normal colors. At
281 the end of the flash the checkbutton is left in the same normal/active
282 state as when the command was invoked.
283 This command is ignored if the checkbutton's state is B<disabled>.
284
285 =item I<$checkbutton>-E<gt>B<invoke>
286
287 Does just what would have happened if the user invoked the checkbutton
288 with the mouse: toggle the selection state of the button and invoke
289 the L<perlE<sol>Tk callback|Tk::callbacks> associated with the checkbutton, if there is one.
290 The return value is the return value from the L<perlE<sol>Tk callback|Tk::callbacks>, or an
291 empty string if there is no command associated with the checkbutton.
292 This command is ignored if the checkbutton's state is B<disabled>.
293
294 =item I<$checkbutton>-E<gt>B<select>
295
296 Selects the checkbutton and sets the associated variable to its ``on''
297 value.
298
299 =item I<$checkbutton>-E<gt>B<toggle>
300
301 Toggles the selection state of the button, redisplaying it and
302 modifying its associated variable to reflect the new state.
303
304 =back
305
306 =head1 BINDINGS
307
308 Tk automatically creates class bindings for checkbuttons that give them
309 the following default behavior:
310
311 =over 4
312
313 =item [1]
314
315 On Unix systems, a checkbutton activates whenever the mouse passes
316 over it and deactivates whenever the mouse leaves the checkbutton. On
317 Mac and Windows systems, when mouse button 1 is pressed over a
318 checkbutton, the button activates whenever the mouse pointer is inside
319 the button, and deactivates whenever the mouse pointer leaves the
320 button.
321
322 =item [2]
323
324 When mouse button 1 is pressed over a checkbutton, it is invoked (its
325 selection state toggles and the command associated with the button is
326 invoked, if there is one).
327
328 =item [3]
329
330 When a checkbutton has the input focus, the space key causes the checkbutton
331 to be invoked. Under Windows, there are additional key bindings; plus
332 (+) and equal (=) select the button, and minus (-) deselects the button.
333
334 If the checkbutton's state is B<disabled> then none of the above
335 actions occur: the checkbutton is completely non-responsive.
336
337 The behavior of checkbuttons can be changed by defining new bindings for
338 individual widgets or by redefining the class bindings.
339
340 =back
341
342 =head1 KEYWORDS
343
344 checkbutton, widget
345
346 =cut
347