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 / NumEntry.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-16  |  5.7 KB  |  215 lines

  1. # $Id: NumEntry.pm,v 1.2 2003/09/16 18:16:45 joker Exp $
  2.  
  3. package Tk::NumEntry;
  4.  
  5. use Tk ();
  6. use Tk::Frame;
  7. use Tk::Derived;
  8. use strict;
  9.  
  10. use vars qw(@ISA $VERSION);
  11. @ISA = qw(Tk::Derived Tk::Frame);
  12. $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  13.  
  14. Construct Tk::Widget 'NumEntry';
  15.  
  16. { my $foo = $Tk::FireButton::INCBITMAP;
  17.      $foo = $Tk::FireButton::DECBITMAP; # peacify -w
  18. }
  19.  
  20. sub Populate {
  21.     my($f,$args) = @_;
  22.  
  23.     require Tk::FireButton;
  24.     require Tk::NumEntryPlain;
  25.  
  26.     my $orient = delete $args->{-orient} || "vertical";
  27.  
  28.     my $readonly = delete $args->{-readonly};
  29.  
  30.     my $e = $f->Component( $f->NumEntryPlainWidget => 'entry',
  31.         -borderwidth        => 0,
  32.         -highlightthickness => 0,
  33.     );
  34.     if ($readonly) {
  35.     $e->bindtags([]);
  36.     }
  37.  
  38.     my $binc = $f->Component( $f->IncFireButtonWidget() => 'inc',
  39.     -command        => sub { $e->incdec($e->cget(-increment)) },
  40.     -takefocus        => 0,
  41.     -highlightthickness => 0,
  42.     -anchor             => 'center',
  43.     );
  44.     $binc->configure(-bitmap => ($orient =~ /^vert/
  45.                  ? $binc->INCBITMAP
  46.                  : $binc->HORIZINCBITMAP
  47.                 )
  48.             );
  49.  
  50.     my $bdec = $f->Component( $f->DecFireButtonWidget() => 'dec',
  51.     -command        => sub { $e->incdec(- $e->cget(-increment)) },
  52.     -takefocus        => 0,
  53.     -highlightthickness => 0,
  54.     -anchor             => 'center',
  55.     );
  56.     $bdec->configure(-bitmap => ($orient =~ /^vert/
  57.                  ? $bdec->DECBITMAP
  58.                  : $bdec->HORIZDECBITMAP
  59.                 )
  60.             );
  61.  
  62.     $f->gridColumnconfigure(0, -weight => 1);
  63.     $f->gridColumnconfigure(1, -weight => 0);
  64.  
  65.     $f->gridRowconfigure(0, -weight => 1);
  66.     $f->gridRowconfigure(1, -weight => 1);
  67.  
  68.     if ($orient eq 'vertical') {
  69.     $binc->grid(-row => 0, -column => 1, -sticky => 'news');
  70.     $bdec->grid(-row => 1, -column => 1, -sticky => 'news');
  71.     } else {
  72.     $binc->grid(-row => 0, -column => 2, -sticky => 'news');
  73.     $bdec->grid(-row => 0, -column => 1, -sticky => 'news');
  74.     }
  75.  
  76.     $e->grid(-row => 0, -column => 0, -rowspan => 2, -sticky => 'news');
  77.  
  78.     $f->ConfigSpecs(
  79.     -borderwidth => ['SELF'     => "borderWidth", "BorderWidth", 2         ],
  80.     -relief      => ['SELF'     => "relief",      "Relief",        "sunken"  ],
  81.     -background  => ['CHILDREN' => "background",  "Background", Tk::NORMAL_BG ],
  82.     -foreground  => ['CHILDREN' => "background",  "Background", Tk::BLACK ],
  83.     -buttons     => ['METHOD'   => undef,        undef,       1         ],
  84.     -state       => ['CHILDREN' => "state",         "State",        "normal"  ],
  85.     -repeatdelay => [[$binc,$bdec]
  86.                   => "repeatDelay", "RepeatDelay", 300         ],
  87.     -repeatinterval
  88.              => [[$binc,$bdec]
  89.                   => "repeatInterval",
  90.                             "RepeatInterval",
  91.                                    100         ],
  92.     -highlightthickness
  93.                      => [SELF     => "highlightThickness",
  94.                             "HighlightThickness",
  95.                                    2         ],
  96.     DEFAULT      => [$e],
  97.     );
  98.  
  99.     $f->Delegates(DEFAULT => $e);
  100.  
  101.     $f;
  102. }
  103.  
  104. sub NumEntryPlainWidget { "NumEntryPlain"         }
  105. sub FireButtonWidget    { "FireButton"            }
  106. sub IncFireButtonWidget { shift->FireButtonWidget }
  107. sub DecFireButtonWidget { shift->FireButtonWidget }
  108.  
  109. sub buttons {
  110.     my $f = shift;
  111.     my $var = \$f->{Configure}{'-buttons'};
  112.     my $old = $$var;
  113.  
  114.     if(@_) {
  115.     my $val = shift;
  116.     $$var = $val ? 1 : 0;
  117.     my $e = $f->Subwidget('entry');
  118.     my %info = $e->gridInfo; $info{'-sticky'} = 'news';
  119.     delete $info{' -sticky'};
  120.     $e->grid(%info, -columnspan => $val ? 1 : 2);
  121.     $e->raise;
  122.     }
  123.  
  124.     $old;
  125. }
  126.  
  127. 1;
  128.  
  129. __END__
  130.  
  131. =head1 NAME
  132.  
  133. Tk::NumEntry - A numeric Entry widget with inc. & dec. Buttons
  134.  
  135. =head1 SYNOPSIS
  136.  
  137. S<    >B<use Tk::NumEntry;>
  138.  
  139. S<    >I<$parent>-E<gt>B<NumEntry>(?I<-option>=E<gt>I<value>, ...?);
  140.  
  141. =head1 DESCRIPTION
  142.  
  143. B<Tk::NumEntry> defines a widget for entering integer numbers. The widget
  144. also contains buttons for increment and decrement.
  145.  
  146. B<Tk::NumEntry> supports all the options and methods that the plain 
  147. NumEntry widget provides (see L<Tk::NumEntryPlain>), plus the
  148. following options
  149.  
  150. =head1 STANDARD OPTIONS
  151.  
  152. Besides the standard options of the L<Entry|Tk::Entry> widget
  153. NumEntry supports:
  154.  
  155. B<-orient> B<-repeatdelay> B<-repeatinterval>
  156.  
  157. The B<-orient> option specifies the packing order of the increment and
  158. decrement buttons. This option can only be set at creation time.
  159.  
  160. =head1 WIDGET-SPECIFIC OPTIONS
  161.  
  162. =over 4
  163.  
  164. =item Name:             B<buttons>
  165.  
  166. =item Class:            B<Buttons>
  167.  
  168. =item Switch:           B<-buttons>
  169.  
  170. =item Fallback:        B<1>
  171.  
  172. Boolean that defines if the inc and dec buttons are visible.
  173.  
  174.  
  175. =item Switch:           B<-readonly>
  176.  
  177. =item Fallback:        B<0>
  178.  
  179. If B<-readonly> is set to a true value, then the value can only be
  180. changed by pressing the increment/decrement buttons. This option can
  181. only be set at creation time.
  182.  
  183. =back
  184.  
  185. =head1 WIDGET METHODS
  186.  
  187. Subclasses of NumEntry may override the following methods to use
  188. different widgets for the composition of the NumEntry. These are:
  189. NumEntryPlainWidget (usually C<NumEntryPlain>), FireButtonWidget
  190. (usually C<FireButton>, IncFireButtonWidget and DecFireButtonWidget.
  191. FireButtonWidget is used if IncFireButtonWidget or DecFireButtonWidget
  192. are not defined.
  193.  
  194. =head1 AUTHOR
  195.  
  196. Graham Barr <F<gbarr@pobox.com>>
  197.  
  198. Current maintainer is Slaven Rezic <F<slaven.rezic@berlin.de>>.
  199.  
  200. =head1 ACKNOWLEDGEMENTS
  201.  
  202. I would to thank  Achim Bohnet <F<ach@mpe.mpg.de>>
  203. for all the feedback and testing. And for the splitting of the original
  204. Tk::NumEntry into Tk::FireButton, Tk::NumEntryPlain and Tk::NumEntry
  205.  
  206. =head1 COPYRIGHT
  207.  
  208. Copyright (c) 1997-1998 Graham Barr. All rights reserved.
  209. This program is free software; you can redistribute it and/or modify it
  210. under the same terms as Perl itself.
  211.  
  212. Except the typo's, they blong to Achim :-)
  213.  
  214. =cut
  215.