| 1 |
|
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Tk::RetEntry - Entry widget with a binding to return and enter |
| 6 |
|
| 7 |
=for pm Tk/RetEntry.pm |
| 8 |
|
| 9 |
=for category Derived Widgets |
| 10 |
|
| 11 |
=head1 SYNOPSIS |
| 12 |
|
| 13 |
use Tk::RetEntry; |
| 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. This takes one additional argument, C<-command>, which |
| 21 |
is a reference to a callback to be bound to the return and enter keys. |
| 22 |
|
| 23 |
=head1 KEYS |
| 24 |
|
| 25 |
widget, entry |
| 26 |
|
| 27 |
=head1 SEE ALSO |
| 28 |
|
| 29 |
L<Tk::Entry> |
| 30 |
|
| 31 |
=cut |
| 32 |
|
| 33 |
|
| 34 |
package Tk::RetEntry; |
| 35 |
|
| 36 |
use Tk (); |
| 37 |
use Tk::Entry; |
| 38 |
use Tk::Derived; |
| 39 |
@ISA = qw(Tk::Derived Tk::Entry); |
| 40 |
use strict; |
| 41 |
|
| 42 |
Construct Tk::Widget 'RetEntry'; |
| 43 |
|
| 44 |
sub Populate { |
| 45 |
my ($self, $args) = @_; |
| 46 |
$self->ConfigSpecs('-command' => ['CALLBACK' => undef, undef, 1], |
| 47 |
# -foreground is special. Has to be specified otherwise Tk sets it to PASSIVE |
| 48 |
## see http://groups-beta.google.com/group/comp.lang.perl.tk/browse_thread/thread/64abac3d77c581a/e236ed8d1584bb5f?q=perl+tk+entry+foreground&rnum=6#e236ed8d1584bb5f |
| 49 |
'-foreground' => ['SELF' => "foreground", "Foreground", Tk::BLACK ], |
| 50 |
'-selectforeground' => ['SELF' => "foreground", "Foreground", Tk::BLACK ], |
| 51 |
); |
| 52 |
my $command = $args->{-command}; |
| 53 |
$self->bind("<KeyPress-Return>" => $command); |
| 54 |
$self->bind("<KeyPress-KP_Enter>" => $command); |
| 55 |
$self; |
| 56 |
}; |
| 57 |
|
| 58 |
1; |