# POD after __END__ package Tk::FireButton; use Tk 402.002 (); # for DefineBitmap use Tk::Derived; use Tk::Button; use strict; use vars qw(@ISA $VERSION); @ISA = qw(Tk::Derived Tk::Button); $VERSION = '0.01'; Construct Tk::Widget 'FireButton'; #my($DECBITMAP,$INCBITMAP); use vars qw($DECBITMAP $INCBITMAP); $INCBITMAP = __PACKAGE__ . "::inc"; $DECBITMAP = __PACKAGE__ . "::dec"; my $def_bitmaps = 0; sub ClassInit { my($class,$mw) = @_; unless($def_bitmaps) { my $bits = pack("b8"x5, "........", "...11...", "..1111..", ".111111.", "........"); $mw->DefineBitmap($INCBITMAP => 8,5, $bits); # And of course, decrement is the reverse of increment :-) $mw->DefineBitmap($DECBITMAP => 8,5, scalar reverse $bits); } $class->SUPER::ClassInit($mw); } sub butDown { my $b = shift; my $fire = shift || 'initial'; if ($fire eq 'initial') { # XXX why isn't relief saving done the Tk::Button as #soon as callback is invoked? $b->{my_save_relief} = $b->cget('-relief'); $b->RepeatId($b->after( $b->cget('-repeatdelay'), [\&butDown, $b, 'again']) ); } else { $b->invoke; $b->RepeatId($b->after( $b->cget('-repeatinterval'), [\&butDown, $b, 'again']) ); } $b->SUPER::butDown; } sub butUp { my $b = shift; $b->CancelRepeat; $b->SUPER::butUp; # XXX $b->configure(-relief=>$b->{my_save_relief}); } sub Populate { my($b,$args) = @_; $b->SUPER::Populate($args); $b->ConfigSpecs( -anchor => 'center', -highlightthickness => 0, -takefocus => 0, -padx => 0, -pady => 0, -repeatdelay => [PASSIVE => "repeatDelay", "RepeatDelay", 300 ], -repeatinterval => [PASSIVE => "repeatInterval", "RepeatInterval", 100 ], ); $b; } 1; __END__ =head1 NAME Tk::FireButton - Button that keeps invoking command when pressed =head1 SYNOPSIS use Tk::FireButton; $fire = $parent->FireButton( ... ); # May/should change: $w->Whatever(... -bitmap => $Tk::FireButton::INCBITMAP, ...); $w->Whatever(... -bitmap => $Tk::FireButton::DECBITMAP, ...); =head1 DESCRIPTION B is-a B