# Conversion from Tk4.0 scrollbar.tcl competed.
import Tk
qw($XS_VERSION);
$VERSION = '3.014'; # $Id: //depot/Tk8/Scrollbar/Scrollbar.pm#14 $
Construct Tk
::Widget
'Scrollbar';
sub Tk_cmd
{ \
&Tk
::scrollbar
}
Tk
::Methods
('activate','delta','fraction','get','identify','set');
return 1 unless (@val == 2);
return 1 if $val[0] != 0.0;
return 1 if $val[1] != 1.0;
$mw->bind($class, '<Enter>', 'Enter');
$mw->bind($class, '<Motion>', 'Motion');
$mw->bind($class, '<Leave>', 'Leave');
$mw->bind($class, '<1>', 'ButtonDown');
$mw->bind($class, '<B1-Motion>', 'Drag');
$mw->bind($class, '<ButtonRelease-1>', 'ButtonUp');
$mw->bind($class, '<B1-Leave>', 'NoOp'); # prevent generic <Leave>
$mw->bind($class, '<B1-Enter>', 'NoOp'); # prevent generic <Enter>
$mw->bind($class, '<Control-1>', 'ScrlTopBottom');
$mw->bind($class, '<2>', 'ButtonDown');
$mw->bind($class, '<B2-Motion>', 'Drag');
$mw->bind($class, '<ButtonRelease-2>', 'ButtonUp');
$mw->bind($class, '<B2-Leave>', 'NoOp'); # prevent generic <Leave>
$mw->bind($class, '<B2-Enter>', 'NoOp'); # prevent generic <Enter>
$mw->bind($class, '<Control-2>', 'ScrlTopBottom');
$mw->bind($class, '<Up>', ['ScrlByUnits','v',-1]);
$mw->bind($class, '<Down>', ['ScrlByUnits','v', 1]);
$mw->bind($class, '<Control-Up>', ['ScrlByPages','v',-1]);
$mw->bind($class, '<Control-Down>', ['ScrlByPages','v', 1]);
$mw->bind($class, '<Left>', ['ScrlByUnits','h',-1]);
$mw->bind($class, '<Right>', ['ScrlByUnits','h', 1]);
$mw->bind($class, '<Control-Left>', ['ScrlByPages','h',-1]);
$mw->bind($class, '<Control-Right>', ['ScrlByPages','h', 1]);
$mw->bind($class, '<Prior>', ['ScrlByPages','hv',-1]);
$mw->bind($class, '<Next>', ['ScrlByPages','hv', 1]);
$mw->bind($class, '<Home>', ['ScrlToPos', 0]);
$mw->bind($class, '<End>', ['ScrlToPos', 1]);
my $bg = $w->cget('-background');
$activeBg = $w->cget('-activebackground');
$w->configure('-activebackground' => $bg);
$w->activate($w->identify($e->x,$e->y));
$w->configure('-activebackground' => $activeBg) if (defined $activeBg) ;
$w->activate($w->identify($e->x,$e->y));
# This procedure is invoked when a button is pressed in a scrollbar.
# It changes the way the scrollbar is displayed and takes actions
# depending on where the mouse is.
# w - The scrollbar widget.
# x, y - Mouse coordinates.
my $element = $w->identify($e->x,$e->y);
$w->configure('-activerelief' => 'sunken');
(defined($element) && $element eq 'slider'))
$w->StartDrag($e->x,$e->y);
(defined($element) && $element =~ /^(trough[12]|slider)$/o))
my $pos = $w->fraction($e->x, $e->y);
my($head, $tail) = $w->get;
$w->StartDrag($e->x,$e->y);
$w->Select($element,'initial');
# This procedure is invoked when a button is released in a scrollbar.
# It cancels scans and auto-repeats that were in progress, and restores
# the way the active element is displayed.
# w - The scrollbar widget.
# x, y - Mouse coordinates.
$w->configure('-activerelief' => 'raised');
$w->EndDrag($e->x,$e->y);
$w->activate($w->identify($e->x,$e->y));
# This procedure is invoked when button 1 is pressed over the scrollbar.
# It invokes one of several scrolling actions depending on where in
# the scrollbar the button was pressed.
# w - The scrollbar widget.
# element - The element of the scrollbar that was selected, such
# as "arrow1" or "trough2". Shouldn't be "slider".
# repeat - Whether and how to auto-repeat the action: "noRepeat"
# means don't auto-repeat, "initial" means this is the
# first action in an auto-repeat sequence, and "again"
# means this is the second repetition or later.
return unless defined ($element);
if ($element eq 'arrow1')
$w->ScrlByUnits('hv',-1);
elsif ($element eq 'trough1')
$w->ScrlByPages('hv',-1);
elsif ($element eq 'trough2')
$w->ScrlByPages('hv', 1);
elsif ($element eq 'arrow2')
$w->ScrlByUnits('hv', 1);
$w->RepeatId($w->after($w->cget('-repeatinterval'),['Select',$w,$element,'again']));
elsif ($repeat eq 'initial')
$w->RepeatId($w->after($w->cget('-repeatdelay'),['Select',$w,$element,'again']));
# This procedure is called to initiate a drag of the slider. It just
# remembers the starting position of the slider.
# w - The scrollbar widget.
# x, y - The mouse position at the start of the drag operation.
return unless (defined ($w->cget('-command')));
$initMouse = $w->fraction($x,$y);
$initPos = $initValues[0];
$initPos = $initValues[2] / $initValues[0];
# This procedure is called for each mouse motion even when the slider
# is being dragged. It notifies the associated widget if we're not
# jump scrolling, and it just updates the scrollbar if we are jump
# w - The scrollbar widget.
# x, y - The current mouse position.
return unless (defined $initMouse);
my $f = $w->fraction($e->x,$e->y);
my $delta = $f - $initMouse;
$w->set($initValues[0]+$delta,$initValues[1]+$delta);
$delta = int($delta * $initValues[0]);
$initValues[2] += $delta;
$initValues[3] += $delta;
$w->ScrlToPos($initPos+$delta);
# This procedure is called to end an interactive drag of the slider.
# It scrolls the window if we're in jump mode, otherwise it does nothing.
# w - The scrollbar widget.
# x, y - The mouse position at the end of the drag operation.
return unless defined($initMouse);
$w->ScrlToPos($initPos + $w->fraction($x,$y) - $initMouse);
# This procedure tells the scrollbar's associated widget to scroll up
# or down by a given number of units. It notifies the associated widget
# in different ways for old and new command syntaxes.
# w - The scrollbar widget.
# orient - Which kinds of scrollbars this applies to: "h" for
# horizontal, "v" for vertical, "hv" for both.
# amount - How many units to scroll: typically 1 or -1.
my $cmd = $w->cget('-command');
return unless (defined $cmd);
return if (index($orient,substr($w->cget('-orient'),0,1)) < 0);
$cmd->Call('scroll',$amount,'units');
$cmd->Call($info[2]+$amount);
# This procedure tells the scrollbar's associated widget to scroll up
# or down by a given number of screenfuls. It notifies the associated
# widget in different ways for old and new command syntaxes.
# w - The scrollbar widget.
# orient - Which kinds of scrollbars this applies to: "h" for
# horizontal, "v" for vertical, "hv" for both.
# amount - How many screens to scroll: typically 1 or -1.
my $cmd = $w->cget('-command');
return unless (defined $cmd);
return if (index($orient,substr($w->cget('-orient'),0,1)) < 0);
$cmd->Call('scroll',$amount,'pages');
$cmd->Call($info[2]+$amount*($info[1]-1));
# This procedure tells the scrollbar's associated widget to scroll to
# a particular location, given by a fraction between 0 and 1. It notifies
# the associated widget in different ways for old and new command syntaxes.
# w - The scrollbar widget.
# pos - A fraction between 0 and 1 indicating a desired position
my $cmd = $w->cget('-command');
return unless (defined $cmd);
$cmd->Call('moveto',$pos);
$cmd->Call(int($info[0]*$pos));
# Scroll to the top or bottom of the document, depending on the mouse
# w - The scrollbar widget.
# x, y - Mouse coordinates within the widget.
my $element = $w->identify($e->x,$e->y);
return unless ($element);