Debian Codegraph @

lib/Tk/KeyEntry.pm

raw
1
2
3 =head1 NAME
4
5 Tk::KeyEntry - perl/Tk Entry widget for entering single characters
6
7 =for pm Tk/KeyEntry.pm
8
9 =for category Derived Widgets
10
11 =head1 SYNOPSIS
12
13 use Tk::KeyEntry;
14 ...
15 $ppe = $mw->KeyEntry(?options,...?);
16
17 =head1 DESCRIPTION
18
19 This "I<IS A>" entry widget with all bindings identical to the normal
20 entry widget. However, it only allows the entered string to be one
21 character long. Each keystroke replaces the contents of the widget
22 with the new key stroke. Only the first character of a clipboard
23 selection is inserted.
24
25 =head1 KEYS
26
27 widget, entry
28
29 =head1 SEE ALSO
30
31 L<Tk::Entry>
32
33 =cut
34
35 package Tk::KeyEntry;
36
37 use Tk::Entry;
38 use base qw(Tk::Entry);
39
40 Construct Tk::Widget 'KeyEntry';
41
42 sub Insert
43 {
44 my $w = shift;
45 my $s = shift;
46 return unless (defined $s && $s ne '');
47 $w -> delete(0, 'end');
48 $w->insert('insert',$s);
49 $w->SeeInsert
50 };
51
52
53 sub InsertSelection
54 {
55 my $w = shift;
56 eval {local $SIG{__DIE__};
57 $w -> delete(0, 'end');
58 $w->Insert(substr($w->SelectionGet,0,1))
59 }
60 };
61
62 sub ButtonRelease_2
63 {
64 my $w = shift;
65 my $Ev = $w->XEvent;
66 if (!$Tk::mouseMoved) {
67 eval
68 {local $SIG{__DIE__};
69 $w -> delete(0, 'end');
70 $w->insert('insert',substr($w->SelectionGet,0,1));
71 $w->SeeInsert;
72 }
73 }
74 }
75
76
77
78 1;