home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Scrollbar / ButtonDown.al < prev    next >
Encoding:
Text File  |  1997-08-10  |  1.1 KB  |  52 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Scrollbar.pm.  Changes made here will be lost.
  2. package Tk::Scrollbar;
  3.  
  4. # tkScrollButtonDown --
  5. # This procedure is invoked when a button is pressed in a scrollbar.
  6. # It changes the way the scrollbar is displayed and takes actions
  7. # depending on where the mouse is.
  8. #
  9. # Arguments:
  10. # w -        The scrollbar widget.
  11. # x, y -    Mouse coordinates.
  12.  
  13. sub ButtonDown 
  14. {my $w = shift;
  15.  my $e = $w->XEvent;
  16.  my $element = $w->identify($e->x,$e->y);
  17.  $w->configure("-activerelief" => "sunken");
  18.  if ($e->b == 1 and
  19.      (defined($element) && $element eq "slider"))
  20.   {
  21.    $w->StartDrag($e->x,$e->y);
  22.   }
  23.  elsif ($e->b == 2 and
  24.     (defined($element) && $element =~ /^(trough[12]|slider)$/o))
  25.   {
  26.     my $pos = $w->fraction($e->x, $e->y);
  27.     my($head, $tail) = $w->get;
  28.     my $len = $tail - $head;
  29.          
  30.     $head = $pos - $len/2;
  31.     $tail = $pos + $len/2;
  32.     if ($head < 0) {
  33.         $head = 0;
  34.         $tail = $len;
  35.     }
  36.     elsif ($tail > 1) {
  37.         $head = 1 - $len;
  38.         $tail = 1;
  39.     }
  40.     $w->ScrlToPos($head);
  41.     $w->set($head, $tail);
  42.  
  43.     $w->StartDrag($e->x,$e->y);
  44.    }
  45.  else
  46.   {
  47.    $w->Select($element,"initial");
  48.   }
  49. }
  50.  
  51. 1;
  52.