Debian Codegraph @

pod/Entry.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::Entry - Create and manipulate Entry widgets
11
12 =for category Tk Widget Classes
13
14 =head1 SYNOPSIS
15
16 S< >I<$entry> = I<$parent>-E<gt>B<Entry>(?I<options>?);
17
18 =head1 STANDARD OPTIONS
19
20 B<-background> B<-highlightbackground> B<-insertontime> B<-selectforeground>
21 B<-borderwidth> B<-highlightcolor> B<-insertwidth> B<-takefocus>
22 B<-cursor> B<-highlightthickness> B<-justify> B<-textvariable>
23 B<-exportselection> B<-insertbackground> B<-relief> B<-xscrollcommand>
24 B<-font> B<-insertborderwidth> B<-selectbackground>
25 B<-foreground> B<-insertofftime> B<-selectborderwidth>
26
27 =head1 WIDGET-SPECIFIC OPTIONS
28
29 =over 4
30
31 =item Command-Line Name: B<-disabledbackground>
32
33 =item Database Name: B<disabledBackground>
34
35 =item Database Class: B<DisabledBackground>
36
37 Specifies the background color to use when the entry is disabled. If
38 this option is the empty string, the normal background color is used.
39
40 =item Command-Line Name: B<-disabledforeground>
41
42 =item Database Name: B<disabledForeground>
43
44 =item Database Class: B<DisabledForeground>
45
46 Specifies the foreground color to use when the entry is disabled. If
47 this option is the empty string, the normal foreground color is used.
48
49 =item Name: B<invalidCommand>
50
51 =item Class: B<InvalidCommand>
52
53 =item Switch: B<-invalidcommand>
54
55 =item Alias: B<-invcmd>
56
57 Specifies a script to eval when B<validateCommand> returns 0.
58 Setting it to <undef> disables this feature (the default). The best use
59 of this option is to set it to I<bell>. See B<Validation>
60 below for more information.
61
62 =item Command-Line Name: B<-readonlybackground>
63
64 =item Database Name: B<readonlyBackground>
65
66 =item Database Class: B<ReadonlyBackground>
67
68 Specifies the background color to use when the entry is read-only. If
69 this option is the empty string, the normal background color is used.
70
71 =item Name: B<show>
72
73 =item Class: B<Show>
74
75 =item Switch: B<-show>
76
77 If this option is specified, then the true contents of the entry
78 are not displayed in the window.
79 Instead, each character in the entry's value will be displayed as
80 the first character in the value of this option, such as ``*''.
81 This is useful, for example, if the entry is to be used to enter
82 a password.
83 If characters in the entry are selected and copied elsewhere, the
84 information copied will be what is displayed, not the true contents
85 of the entry.
86
87 =item Name: B<state>
88
89 =item Class: B<State>
90
91 =item Switch: B<-state>
92
93 Specifies one of three states for the entry: B<normal>, B<disabled>, or
94 B<readonly>. If the entry is B<readonly>, then the value may not be changed
95 using widget commands and no insertion cursor will be displayed, even
96 if the input focus is in the widget; the contents of the widget may
97 still be selected. If the entry is B<disabled>, the value may not be
98 changed, no insertion cursor will be displayed, the contents will not
99 be selectable, and the entry may be displayed in a different color,
100 depending on the values of the B<-disabledforeground> and
101 B<-disabledbackground> options.
102
103 =item Name: B<validate>
104
105 =item Class: B<Validate>
106
107 =item Switch: B<-validate>
108
109 Specifies the mode in which validation should operate: B<none>,
110 B<focus>, B<focusin>, B<focusout>, B<key>, or B<all>.
111 It defaults to B<none>. When you want validation, you must explicitly
112 state which mode you wish to use. See B<Validation> below for more.
113
114 =item Name: B<validateCommand>
115
116 =item Class: B<ValidateCommand>
117
118 =item Switch: B<-validatecommand>
119
120 =item Alias: B<-vcmd>
121
122 Specifies a script to eval when you want to validate the input into
123 the entry widget. Setting it to C<undef> disables this feature (the default).
124 This command must return a valid boolean value. If it returns 0 (or
125 the valid boolean equivalent) then it means you reject the new edition
126 and it will not occur and the B<invalidCommand> will be evaluated if it
127 is set. If it returns 1, then the new edition occurs.
128 See B<Validation> below for more information.
129
130 =item Name: B<width>
131
132 =item Class: B<Width>
133
134 =item Switch: B<-width>
135
136 Specifies an integer value indicating the desired width of the entry window,
137 in average-size characters of the widget's font.
138 If the value is less than or equal to zero, the widget picks a
139 size just large enough to hold its current text.
140
141 =back
142
143 =head1 DESCRIPTION
144
145 The B<Entry> method creates a new window (given by the
146 $entry argument) and makes it into an entry widget.
147 Additional options, described above, may be specified on the
148 command line or in the option database
149 to configure aspects of the entry such as its colors, font,
150 and relief. The B<entry> command returns its
151 $entry argument. At the time this command is invoked,
152 there must not exist a window named $entry, but
153 $entry's parent must exist.
154
155 An entry is a widget that displays a one-line text string and
156 allows that string to be edited using methods described below, which
157 are typically bound to keystrokes and mouse actions.
158 When first created, an entry's string is empty.
159 A portion of the entry may be selected as described below.
160 If an entry is exporting its selection (see the B<exportSelection>
161 option), then it will observe the standard X11 protocols for handling the
162 selection; entry selections are available as type B<STRING>.
163 Entries also observe the standard Tk rules for dealing with the
164 input focus. When an entry has the input focus it displays an
165 I<insertion cursor> to indicate where new characters will be
166 inserted.
167
168 Entries are capable of displaying strings that are too long to
169 fit entirely within the widget's window. In this case, only a
170 portion of the string will be displayed; methods described below
171 may be used to change the view in the window. Entries use
172 the standard B<xScrollCommand> mechanism for interacting with
173 scrollbars (see the description of the B<-xscrollcommand> option
174 for details). They also support scanning, as described below.
175
176 =head1 VALIDATION
177
178 Validation of entry widgets is derived from part of the patch written by
179 [email protected]. This works by setting the B<validateCommand>
180 option to a callback which will be evaluated according to the B<validate>
181 option as follows:
182
183 =over 4
184
185 =item B<none>
186
187 Default. This means no validation will occur.
188
189 =item B<focus>
190
191 B<validateCommand> will be called when the entry receives or
192 loses focus.
193
194 =item B<focusin>
195
196 B<validateCommand> will be called when the entry receives focus.
197
198 =item B<focusout>
199
200 B<validateCommand> will be called when the entry loses focus.
201
202 =item B<key>
203
204 B<validateCommand> will be called when the entry is edited.
205
206 =item B<all>
207
208 B<validateCommand> will be called for all above conditions.
209
210 =back
211
212 The B<validateCommand> and B<invalidCommand> are called with the following
213 arguments:
214
215 =over 4
216
217 =item * The proposed value of the entry. If you are configuring the
218 entry widget to have a new textvariable, this will be the value of that
219 textvariable.
220
221 =item * The characters to be added (or deleted). This will be C<undef>
222 if validation is due to focus, explcit call to validate or if change
223 is due to C<-textvariable> changing.
224
225 =item * The current value of entry i.e. before the proposed change.
226
227 =item * index of char string to be added/deleted, if any. -1 otherwise
228
229 =item * type of action. 1 == INSERT, 0 == DELETE,
230 -1 if it's a forced validation or textvariable validation
231
232 =back
233
234 In general, the B<textVariable> and B<validateCommand> can be
235 dangerous to mix. If you try set the B<textVariable>
236 to something that the B<validateCommand> will not accept it will
237 be set back to the value of the entry widget.
238 Using the B<textVariable> for read-only purposes will never cause problems.
239
240 The B<validateCommand> will turn itself off by setting
241 B<validate> to B<none> when an error occurs, for example
242 when the B<validateCommand> or B<invalidCommand> encounters
243 an error in its script while evaluating, or
244 B<validateCommand> does not return a valid boolean value.
245
246 With the perl/Tk version B<validate> option is supposed to be
247 "suspended" while executing the B<validateCommand> or the B<invalidCommand>.
248 This is experimental but in theory either callback can "correct" the
249 value of the widget, and override the proposed change. (B<validateCommand>
250 should still return false to inhibit the change from happening when
251 it returns.)
252
253 =head1 WIDGET METHODS
254
255 The B<Entry> method creates a widget object.
256 This object supports the B<configure> and B<cget> methods
257 described in L<Tk::options> which can be used to enquire and
258 modify the options described above.
259 The widget also inherits all the methods provided by the generic
260 L<Tk::Widget|Tk::Widget> class.
261
262 Many of the additional methods for entries take one or more indices as
263 arguments. An index specifies a particular character in the entry's
264 string, in any of the following ways:
265
266 =over 4
267
268 =item I<number>
269
270 Specifies the character as a numerical index, where 0 corresponds
271 to the first character in the string.
272
273 =item B<anchor>
274
275 Indicates the anchor point for the selection, which is set with the
276 B<selectionFrom> and B<selectionAdjust> methods.
277
278 =item B<end>
279
280 Indicates the character just after the last one in the entry's string.
281 This is equivalent to specifying a numerical index equal to the length
282 of the entry's string.
283
284 =item B<insert>
285
286 Indicates the character adjacent to and immediately following the
287 insertion cursor.
288
289 =item B<sel.first>
290
291 Indicates the first character in the selection. It is an error to
292 use this form if the selection isn't in the entry window.
293
294 =item B<sel.last>
295
296 Indicates the character just after the last one in the selection.
297 It is an error to use this form if the selection isn't in the
298 entry window.
299
300 =item B<@>I<number>
301
302 In this form, I<number> is treated as an x-coordinate in the
303 entry's window; the character spanning that x-coordinate is used.
304 For example, ``B<@0>'' indicates the left-most character in the
305 window.
306
307 =back
308
309 Abbreviations may be used for any of the forms above, e.g. ``B<e>''
310 or ``B<sel.f>''. In general, out-of-range indices are automatically
311 rounded to the nearest legal value.
312
313 The following additional methods are available for entry widgets:
314
315 =over 4
316
317 =item I<$entry>-E<gt>B<bbox>(I<index>)
318
319 Returns a list of four numbers describing the bounding box of the
320 character given by I<index>.
321 The first two elements of the list give the x and y coordinates of
322 the upper-left corner of the screen area covered by the character
323 (in pixels relative to the widget) and the last two elements give
324 the width and height of the character, in pixels.
325 The bounding box may refer to a region outside the visible area
326 of the window.
327
328 =item I<$entry>-E<gt>B<cget>(?I<option>?)
329
330 Returns the current value of the configuration option given
331 by I<option>.
332 I<Option> may have any of the values accepted by the B<entry>
333 command.
334
335 =item I<$entry>-E<gt>B<configure>(?I<option>?, ?I<value, option, value, ...>?)
336
337 Query or modify the configuration options of the widget.
338 If no I<option> is specified, returns a list describing all of
339 the available options for $entry (see L<Tk::configure> for
340 information on the format of this list). If I<option> is specified
341 with no I<value>, then the command returns a list describing the
342 one named option (this list will be identical to the corresponding
343 sublist of the value returned if no I<option> is specified). If
344 one or more I<option-value> pairs are specified, then the command
345 modifies the given widget option(s) to have the given value(s); in
346 this case the command returns an empty string.
347 I<Option> may have any of the values accepted by the B<entry>
348 command.
349
350 =item I<$entry>-E<gt>B<delete>(I<first, >?I<last>?)
351
352 Delete one or more elements of the entry.
353 I<First> is the index of the first character to delete, and
354 I<last> is the index of the character just after the last
355 one to delete.
356 If I<last> isn't specified it defaults to I<first>+1,
357 i.e. a single character is deleted.
358 This method returns an empty string.
359
360 =item I<$entry>-E<gt>B<get>
361
362 Returns the entry's string.
363
364 =item I<$entry>-E<gt>B<icursor>(I<index>)
365
366 Arrange for the insertion cursor to be displayed just before the character
367 given by I<index>. Returns an empty string.
368
369 =item I<$entry>-E<gt>B<index>(I<index>)
370
371 Returns the numerical index corresponding to I<index>.
372
373 =item I<$entry>-E<gt>B<insert>(I<index, string>)
374
375 Insert the characters of I<string> just before the character
376 indicated by I<index>. Returns an empty string.
377
378 =item I<$entry>->B<scan>(I<option, args>)
379
380 =item I<$entry>->B<scan>I<Option>(I<args>)
381
382 This method is used to implement scanning on entries. It has
383 two forms, depending on I<Option>:
384
385 =over 8
386
387 =item I<$entry>->B<scanMark>(I<x>)
388
389 Records I<x> and the current view in the entry widget; used in
390 conjunction with later B<scanDragto> methods. Typically this
391 method is associated with a mouse button press in the widget. It
392 returns an empty string.
393
394 =item I<$entry>->B<scanDragto>(I<x>)
395
396 This method computes the difference between its I<x> argument
397 and the I<x> argument to the last B<scanMark> method for
398 the widget. It then adjusts the view left or right by 10 times the
399 difference in x-coordinates. This method is typically associated
400 with mouse motion events in the widget, to produce the effect of
401 dragging the entry at high speed through the widget. The return
402 value is an empty string.
403
404 =back
405
406 =item I<$entry>->B<selection>(I<option, arg>)
407
408 =item I<$entry>->B<selection>I<Option>(I<arg>)
409
410 This method is used to adjust the selection within an entry. It
411 has several forms, depending on I<Option>:
412
413 =over 8
414
415 =item I<$entry>-E<gt>B<selectionAdjust>(I<index>)
416
417 Locate the end of the selection nearest to the character given by
418 I<index>, and adjust that end of the selection to be at I<index>
419 (i.e including but not going beyond I<index>). The other
420 end of the selection is made the anchor point for future
421 B<selectionTo> methods. If the selection
422 isn't currently in the entry, then a new selection is created to
423 include the characters between I<index> and the most recent
424 selection anchor point, inclusive.
425 Returns an empty string.
426
427 =item I<$entry>-E<gt>B<selectionClear>
428
429 Clear the selection if it is currently in this widget. If the
430 selection isn't in this widget then the method has no effect.
431 Returns an empty string.
432
433 =item I<$entry>-E<gt>B<selectionFrom>(I<index>)
434
435 Set the selection anchor point to just before the character
436 given by I<index>. Doesn't change the selection.
437 Returns an empty string.
438
439 =item I<$entry>-E<gt>B<selectionPresent>
440
441 Returns 1 if there is are characters selected in the entry,
442 0 if nothing is selected.
443
444 =item I<$entry>-E<gt>B<selectionRange>(I<start, >I<end>)
445
446 Sets the selection to include the characters starting with
447 the one indexed by I<start> and ending with the one just
448 before I<end>.
449 If I<end> refers to the same character as I<start> or an
450 earlier one, then the entry's selection is cleared.
451
452 =item I<$entry>-E<gt>B<selectionTo>(I<index>)
453
454 If I<index> is before the anchor point, set the selection
455 to the characters from I<index> up to but not including
456 the anchor point.
457 If I<index> is the same as the anchor point, do nothing.
458 If I<index> is after the anchor point, set the selection
459 to the characters from the anchor point up to but not including
460 I<index>.
461 The anchor point is determined by the most recent B<selectionFrom>
462 or B<selectionAdjust> method in this widget.
463 If the selection isn't in this widget then a new selection is
464 created using the most recent anchor point specified for the widget.
465 Returns an empty string.
466
467 =back
468
469 =item I<$entry>-E<gt>B<validate>
470
471 This command is used to force an evaluation of the B<validateCommand>
472 independent of the conditions specified by the B<validate> option. It
473 returns 0 or 1.
474
475 =item I<$entry>-E<gt>B<xview>(I<args>)
476
477 This command is used to query and change the horizontal position of the
478 text in the widget's window. It can take any of the following
479 forms:
480
481 =over 8
482
483 =item I<$entry>-E<gt>B<xview>
484
485 Returns a list containing two elements.
486 Each element is a real fraction between 0 and 1; together they describe
487 the horizontal span that is visible in the window.
488 For example, if the first element is .2 and the second element is .7,
489 20% of the entry's text is off-screen to the left, the middle 50% is visible
490 in the window, and 30% of the text is off-screen to the right.
491 These are the same values passed to scrollbars via the B<-xscrollcommand>
492 option.
493
494 =item I<$entry>-E<gt>B<xview>(I<index>)
495
496 Adjusts the view in the window so that the character given by I<index>
497 is displayed at the left edge of the window.
498
499 =item I<$entry>-E<gt>B<xviewMoveto>(I<fraction>)
500
501 Adjusts the view in the window so that the character I<fraction> of the
502 way through the text appears at the left edge of the window.
503 I<Fraction> must be a fraction between 0 and 1.
504
505 =item I<$entry>-E<gt>B<xviewScroll>(I<number, what>)
506
507 This method shifts the view in the window left or right according to
508 I<number> and I<what>.
509 I<Number> must be an integer.
510 I<What> must be either B<units> or B<pages> or an abbreviation
511 of one of these.
512 If I<what> is B<units>, the view adjusts left or right by
513 I<number> average-width characters on the display; if it is
514 B<pages> then the view adjusts by I<number> screenfuls.
515 If I<number> is negative then characters farther to the left
516 become visible; if it is positive then characters farther to the right
517 become visible.
518
519 =back
520
521 =back
522
523 =head1 DEFAULT BINDINGS
524
525 Tk automatically creates class bindings for entries that give them
526 the following default behavior.
527 In the descriptions below, ``word'' refers to a contiguous group
528 of letters, digits, or ``_'' characters, or any single character
529 other than these.
530
531 =over 4
532
533 =item [1]
534
535 Clicking mouse button 1 positions the insertion cursor
536 just before the character underneath the mouse cursor, sets the
537 input focus to this widget, and clears any selection in the widget.
538 Dragging with mouse button 1 strokes out a selection between
539 the insertion cursor and the character under the mouse.
540
541 =item [2]
542
543 Double-clicking with mouse button 1 selects the word under the mouse
544 and positions the insertion cursor at the beginning of the word.
545 Dragging after a double click will stroke out a selection consisting
546 of whole words.
547
548 =item [3]
549
550 Triple-clicking with mouse button 1 selects all of the text in the
551 entry and positions the insertion cursor before the first character.
552
553 =item [4]
554
555 The ends of the selection can be adjusted by dragging with mouse
556 button 1 while the Shift key is down; this will adjust the end
557 of the selection that was nearest to the mouse cursor when button
558 1 was pressed.
559 If the button is double-clicked before dragging then the selection
560 will be adjusted in units of whole words.
561
562 =item [5]
563
564 Clicking mouse button 1 with the Control key down will position the
565 insertion cursor in the entry without affecting the selection.
566
567 =item [6]
568
569 If any normal printing characters are typed in an entry, they are
570 inserted at the point of the insertion cursor.
571
572 =item [7]
573
574 The view in the entry can be adjusted by dragging with mouse button 2.
575 If mouse button 2 is clicked without moving the mouse, the selection
576 is copied into the entry at the position of the mouse cursor.
577
578 =item [8]
579
580 If the mouse is dragged out of the entry on the left or right sides
581 while button 1 is pressed, the entry will automatically scroll to
582 make more text visible (if there is more text off-screen on the side
583 where the mouse left the window).
584
585 =item [9]
586
587 The Left and Right keys move the insertion cursor one character to the
588 left or right; they also clear any selection in the entry and set
589 the selection anchor.
590 If Left or Right is typed with the Shift key down, then the insertion
591 cursor moves and the selection is extended to include the new character.
592 Control-Left and Control-Right move the insertion cursor by words, and
593 Control-Shift-Left and Control-Shift-Right move the insertion cursor
594 by words and also extend the selection.
595 Control-b and Control-f behave the same as Left and Right, respectively.
596 Meta-b and Meta-f behave the same as Control-Left and Control-Right,
597 respectively.
598
599 =item [10]
600
601 The Home key, or Control-a, will move the insertion cursor to the
602 beginning of the entry and clear any selection in the entry.
603 Shift-Home moves the insertion cursor to the beginning of the entry
604 and also extends the selection to that point.
605
606 =item [11]
607
608 The End key, or Control-e, will move the insertion cursor to the
609 end of the entry and clear any selection in the entry.
610 Shift-End moves the cursor to the end and extends the selection
611 to that point.
612
613 =item [12]
614
615 The Select key and Control-Space set the selection anchor to the position
616 of the insertion cursor. They don't affect the current selection.
617 Shift-Select and Control-Shift-Space adjust the selection to the
618 current position of the insertion cursor, selecting from the anchor
619 to the insertion cursor if there was not any selection previously.
620
621 =item [13]
622
623 Control-/ selects all the text in the entry.
624
625 =item [14]
626
627 Control-\ clears any selection in the entry.
628
629 =item [15]
630
631 The F16 key (labelled Copy on many Sun workstations) or Meta-w
632 copies the selection in the widget to the clipboard, if there is a selection.
633
634 =item [16]
635
636 The F20 key (labelled Cut on many Sun workstations) or Control-w
637 copies the selection in the widget to the clipboard and deletes
638 the selection.
639 If there is no selection in the widget then these keys have no effect.
640
641 =item [17]
642
643 The F18 key (labelled Paste on many Sun workstations) or Control-y
644 inserts the contents of the clipboard at the position of the
645 insertion cursor.
646
647 =item [18]
648
649 The Delete key deletes the selection, if there is one in the entry.
650 If there is no selection, it deletes the character to the right of
651 the insertion cursor.
652
653 =item [19]
654
655 The BackSpace key and Control-h delete the selection, if there is one
656 in the entry.
657 If there is no selection, it deletes the character to the left of
658 the insertion cursor.
659
660 =item [20]
661
662 Control-d deletes the character to the right of the insertion cursor.
663
664 =item [21]
665
666 Meta-d deletes the word to the right of the insertion cursor.
667
668 =item [22]
669
670 Control-k deletes all the characters to the right of the insertion
671 cursor.
672
673 =item [23]
674
675 Control-t reverses the order of the two characters to the right of
676 the insertion cursor.
677
678 If the entry is disabled using the B<-state> option, then the entry's
679 view can still be adjusted and text in the entry can still be selected,
680 but no insertion cursor will be displayed and no text modifications will
681 take place.
682
683 The behavior of entries can be changed by defining new bindings for
684 individual widgets or by redefining the class bindings.
685
686 =back
687
688 =head1 KEYWORDS
689
690 entry, widget
691
692 =cut
693