| 1 |
package Tk::Spinbox; |
| 2 |
use strict; |
| 3 |
|
| 4 |
use vars qw($VERSION); |
| 5 |
$VERSION = '4.007'; # sprintf '4.%03d',q$Revision: #6 $ =~ /#(\d+)/; |
| 6 |
|
| 7 |
use base 'Tk::Entry'; |
| 8 |
|
| 9 |
sub Tk_cmd { \&Tk::spinbox } |
| 10 |
|
| 11 |
# Also inherits Entry's methods |
| 12 |
Tk::Methods( "identify", "invoke", "set" ); |
| 13 |
use Tk::Submethods ( 'selection' => ["element"] ); |
| 14 |
|
| 15 |
Construct Tk::Widget 'Spinbox'; |
| 16 |
|
| 17 |
sub ClassInit |
| 18 |
{ |
| 19 |
my ($class,$mw) = @_; |
| 20 |
|
| 21 |
$class->SUPER::ClassInit($mw); |
| 22 |
|
| 23 |
$mw->bind($class, '<Up>', [invoke => 'buttonup']); |
| 24 |
$mw->bind($class, '<4>', [invoke => 'buttonup']); |
| 25 |
$mw->bind($class, '<Down>',[invoke => 'buttondown']); |
| 26 |
$mw->bind($class, '<5>', [invoke => 'buttondown']); |
| 27 |
|
| 28 |
return $class; |
| 29 |
} |
| 30 |
|
| 31 |
sub Invoke |
| 32 |
{ |
| 33 |
my ($w,$elem) = @_; |
| 34 |
unless ($w->{_outside}) |
| 35 |
{ |
| 36 |
$w->invoke($elem); |
| 37 |
$w->{_repeated}++; |
| 38 |
} |
| 39 |
my $delay = $w->cget('-repeatinterval'); |
| 40 |
if ($delay > 0) |
| 41 |
{ |
| 42 |
$w->RepeatId($w->after($delay,[Invoke => $w,$elem])); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
sub Button1 |
| 47 |
{ |
| 48 |
my ($w,$x,$y) = @_; |
| 49 |
my $elem = $w->identify($x,$y); |
| 50 |
$w->{_element} = $elem || 'entry'; |
| 51 |
if ($w->{_element} eq 'entry') |
| 52 |
{ |
| 53 |
$w->SUPER::Button1($x,$y); |
| 54 |
} |
| 55 |
elsif ($w->cget('-state') ne 'disabled') |
| 56 |
{ |
| 57 |
$w->selectionElement($elem); |
| 58 |
$w->{_repeated} = 0; |
| 59 |
$w->{_outside} = 0; |
| 60 |
$w->{_relief} = $w->cget("-${elem}relief"); |
| 61 |
$w->CancelRepeat; |
| 62 |
my $delay = $w->cget('-repeatdelay'); |
| 63 |
$w->RepeatId($w->after($delay,[Invoke => $w,$elem])) if $delay > 0; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
sub Motion |
| 68 |
{ |
| 69 |
my ($w,$x,$y) = @_; |
| 70 |
my $elem = $w->identify($x,$y); |
| 71 |
$w->{_element} = $elem || 'entry' unless $w->{_element}; |
| 72 |
if ($w->{_element} eq 'entry') |
| 73 |
{ |
| 74 |
$w->SUPER::Motion($x,$y); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
if (!defined($elem) || $elem ne $w->{_element}) |
| 79 |
{ |
| 80 |
# Moved outside the button |
| 81 |
unless ($w->{_outside}) |
| 82 |
{ |
| 83 |
$w->{_outside} = 1; |
| 84 |
$w->selectionElement('none'); |
| 85 |
} |
| 86 |
} |
| 87 |
elsif ($w->{_outside}) |
| 88 |
{ |
| 89 |
# Moved back over the button |
| 90 |
$w->selectionElement($elem); |
| 91 |
$w->{_outside} = 0; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
sub Button1Release |
| 97 |
{ |
| 98 |
my ($w,$x,$y) = @_; |
| 99 |
$w->SUPER::Button1Release($x,$y); |
| 100 |
my $elem = $w->{_element}; |
| 101 |
if (defined($elem) && $elem ne 'entry') |
| 102 |
{ |
| 103 |
my $repeated = $w->{_repeated}; |
| 104 |
if (defined($repeated) && !$repeated) |
| 105 |
{ |
| 106 |
$w->invoke($elem); |
| 107 |
} |
| 108 |
my $relief = delete $w->{_relief}; |
| 109 |
$w->configure("-${elem}relief",$relief) if $relief |
| 110 |
} |
| 111 |
$w->selectionElement('none'); |
| 112 |
} |
| 113 |
|
| 114 |
1; |
| 115 |
__END__ |