home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / FireButton.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-16  |  5.4 KB  |  226 lines

  1. # POD after __END__
  2. # $Id: FireButton.pm,v 1.2 2003/09/16 18:16:45 joker Exp $
  3.  
  4. package Tk::FireButton;
  5.  
  6. use Tk 402.002 (); # for DefineBitmap
  7. use Tk::Derived;
  8. use Tk::Button;
  9. use strict;
  10.  
  11. use vars qw(@ISA $VERSION);
  12. @ISA = qw(Tk::Derived Tk::Button);
  13. $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  14.  
  15. Construct Tk::Widget 'FireButton';
  16.  
  17. use vars qw($DECBITMAP $INCBITMAP $HORIZDECBITMAP $HORIZINCBITMAP);
  18.  
  19. $INCBITMAP = __PACKAGE__ . "::inc";
  20. $DECBITMAP = __PACKAGE__ . "::dec";
  21. $HORIZINCBITMAP = __PACKAGE__ . "::horizinc";
  22. $HORIZDECBITMAP = __PACKAGE__ . "::horizdec";
  23.  
  24. my $def_bitmaps = 0;
  25.  
  26. sub ClassInit {
  27.     my($class,$mw) = @_;
  28.  
  29.     unless($def_bitmaps) {
  30.     my $bits = pack("b8"x5,    "........",
  31.                 "...11...",
  32.                 "..1111..",
  33.                 ".111111.",
  34.                 "........");
  35.  
  36.     $mw->DefineBitmap($INCBITMAP => 8,5, $bits);
  37.  
  38.     # And of course, decrement is the reverse of increment :-)
  39.     $mw->DefineBitmap($DECBITMAP => 8,5, scalar reverse $bits);
  40.  
  41.     my @rot_bits = (".....",
  42.             ".1...",
  43.             ".11..",
  44.             ".111.",
  45.             ".111.",
  46.             ".11..",
  47.             ".1...",
  48.             ".....");
  49.     my $rot_bits          = pack("b5"x8, @rot_bits);
  50.     my $mirrored_rot_bits = pack("b5"x8, map { scalar reverse } @rot_bits);
  51.  
  52.     $mw->DefineBitmap($HORIZINCBITMAP => 5,8, $rot_bits);
  53.     $mw->DefineBitmap($HORIZDECBITMAP => 5,8, $mirrored_rot_bits);
  54.  
  55.     $def_bitmaps = 1;
  56.     }
  57.  
  58.     $class->SUPER::ClassInit($mw);
  59. }
  60.  
  61.  
  62. sub butDown {
  63.     my $b = shift;
  64.     my $fire = shift || 'initial';
  65.  
  66.     if ($fire eq 'initial') {
  67.     # XXX why isn't relief saving done the Tk::Button as
  68.         #soon as callback is invoked?
  69.     $b->{tk_firebutton_save_relief} = $b->cget('-relief');
  70.  
  71.        $b->RepeatId($b->after( $b->cget('-repeatdelay'),
  72.         [\&butDown, $b, 'again'])
  73.         ); 
  74.     } else {
  75.         $b->invoke;
  76.         $b->RepeatId($b->after( $b->cget('-repeatinterval'),
  77.                 [\&butDown, $b, 'again'])
  78.                 );
  79.     }
  80.  
  81.     $b->SUPER::butDown;
  82. }
  83.  
  84. sub butUp {
  85.     my $b = shift;
  86.     $b->CancelRepeat;
  87.     $b->SUPER::butUp;
  88.     $b->configure(-relief=>$b->{tk_firebutton_save_relief})
  89.     if $b->{tk_firebutton_save_relief};
  90. }
  91.  
  92. sub Populate {
  93.     my($b,$args) = @_;
  94.  
  95.     $b->SUPER::Populate($args);
  96.  
  97.     $b->ConfigSpecs(
  98.     # Override button fallbacks
  99.     -padx             => [qw(SELF padX               Pad                0)],
  100.     -pady             => [qw(SELF padY               Pad                0)],
  101.  
  102.     # new options
  103.         -repeatdelay     => [qw(PASSIVE repeatDelay    RepeatDelay    300)],
  104.     -repeatinterval  => [qw(PASSIVE repeatInterval RepeatInterval 100)],
  105.     );
  106.  
  107.     $b;
  108. }
  109.  
  110. sub INCBITMAP      { $INCBITMAP      }
  111. sub HORIZINCBITMAP { $HORIZINCBITMAP }
  112. sub DECBITMAP      { $DECBITMAP      }
  113. sub HORIZDECBITMAP { $HORIZDECBITMAP }
  114.  
  115. 1;
  116.  
  117. __END__
  118.  
  119. =head1 NAME
  120.  
  121. Tk::FireButton - Button that keeps invoking callback when pressed
  122.  
  123.  
  124. =head1 SYNOPSIS
  125.  
  126.     use Tk::FireButton;
  127.  
  128.     $fire = $parent->FireButton( ... );
  129.  
  130.     # May/should change:
  131.     $w->Whatever(... -bitmap => $Tk::FireButton::INCBITMAP, ...);
  132.     $w->Whatever(... -bitmap => $Tk::FireButton::DECBITMAP, ...);
  133.     $w->Whatever(... -bitmap => $Tk::FireButton::HORIZINCBITMAP, ...);
  134.     $w->Whatever(... -bitmap => $Tk::FireButton::HORIZDECBITMAP, ...);
  135.  
  136.  
  137. =head1 DESCRIPTION
  138.  
  139. B<FireButton> is-a B<Button> widget (see L<Tk::Button>) that
  140. keeps invoking the callback bound to it as long as the <FireButton>
  141. is pressed.
  142.  
  143. Four suitable bitmaps are predefined in this package: $INCBITMAP and
  144. $DECBITMAP for vertical increment and decrement buttons, and
  145. $HORIZINCBITMAP and $HORIZDECBITMAP for horizontal increment and
  146. decrement buttons. See below for methods accessing these bitmaps.
  147.  
  148.  
  149. =head1 SUPER-CLASS
  150.  
  151. The B<FireButton> widget-class is derived from the B<Button>
  152. widget-class and inherits all the methods and options its
  153. super-class (see L<Tk::Button>).
  154.  
  155.  
  156. =head1 STANDARD OPTIONS
  157.  
  158. B<FireButton> supports all the standard options of a B<Button> widget.
  159. See L<Tk::options> for details on the standard options.
  160.  
  161.  
  162. =head1 WIDGET-SPECIFIC OPTIONS
  163.  
  164.  
  165. =over 4
  166.  
  167. =item Name:             B<repeatDelay>
  168.  
  169. =item Class:            B<RepeatDelay>
  170.  
  171. =item Switch:           B<-repeatdelay>
  172.  
  173. =item Fallback:        B<300> (milliseconds)
  174.  
  175. Specifies the amount of time before the callback is first invoked after
  176. the Button-1 is pressed over the widget.
  177.  
  178.  
  179. =item Name:             B<repeatInterval>
  180.  
  181. =item Class:            B<RepeatInterval>
  182.  
  183. =item Switch:           B<-repeatinterval>
  184.  
  185. =item Fallback:        B<100> (milliseconds)
  186.  
  187. Specifies the amount of time between invokations of the
  188. callback bound to the widget with the C<command> option.
  189.  
  190. =back
  191.  
  192. =head1 CHANDED OPTION FALLBACK VALUES
  193.  
  194. The fallback values of the following options as different
  195. from the B<Button> widget:
  196.  
  197.         -padx               => 0,
  198.         -pady               => 0,
  199.  
  200.  
  201. =head1 METHODS
  202.  
  203. Same as for L<Button|Tk::Button> widget.
  204.  
  205. Additionally, there are four methods returning the names of the
  206. standard increment and decrement bitmaps: INCBITMAP, HORIZINCBITMAP,
  207. DECBITMAP, and HORIZDECBITMAP.
  208.  
  209. Subclasses of FireButton may override these methods to supply
  210. different increment and decrement bitmaps.
  211.  
  212. =head1 ADVERTISED WIDGETS
  213.  
  214. None.
  215.  
  216.  
  217. =head1 HISTORY
  218.  
  219. The code was extracted from Tk::NumEntry and slightly modified
  220. by Achim Bohnet E<gt>ach@mpe.mpg.deE<gt>.  Tk::NumEntry's author
  221. is Graham Barr E<gt>gbarr@pobox.comE<gt>. The current maintainer is
  222. Slaven Rezic E<gt>slaven.rezic@berlin.deE<gt>.
  223.  
  224. =cut
  225.  
  226.