Hello, me again...

Since some people mentioned window scrollbars in the list a while back, I
decided to implement some functions to make them actually work.

I've also added the relevant constants for scrollbars and statusbars, fixed
the bug with $window->Result(x) (thanks to Glenn Linderman), and applied
Laurent Rocher's tweaks for the Status Bar code.

New functions. Use these in the form:

$window->foo(bar, baz);

 ###########################################################################
 # (@)METHOD:ScrollPos(scrollbar,[pos])
 # Sets / Gets position of a window scrollbar (if enabled). scrollbar
 # argument should be set as follows:
 # 0 - Horizontal scrollbar
 # 1 - Vertical scrollbar
 #
 # Returns the scrollbar position or undef on failure.

 ###########################################################################
 # (@)METHOD:ScrollPage(scrollbar,[pagesize])
 # Sets / Gets page size of a window scrollbar (if enabled). scrollbar
 # argument should be set as follows:
 # 0 - Horizontal scrollbar
 # 1 - Vertical scrollbar
 #
 # Returns the scrollbar page size or undef on failure.

 ###########################################################################
 # (@)METHOD:ScrollRange(scrollbar,[min, max])
 # Sets / Gets range for a window scrollbar (if enabled). scrollbar
 # argument should be set as follows:
 # 0 - Horizontal scrollbar
 # 1 - Vertical scrollbar
 #
 # Returns the scrollbar range as an array, or undef on failure.

 ###########################################################################
 # (@)METHOD:Scroll(scrollbar,operation,position)
 # Handles scrollbar scrolling if you don't want to do it yourself. This is
 # most useful in the Scroll event handler for a window or dialog box.
 #
 # scrollbar can be:
 # 0 - Horizontal scrollbar
 # 1 - Vertical scrollbar
 #
 # type is an identifier for the operation being performed on the scrollbar,
 # this can be:
 # SB_LINEUP, SB_LINELEFT, SB_LINEDOWN, SB_LINERIGHT, SB_PAGEUP
 # SB_PAGELEFT, SB_PAGEDOWN, SB_PAGERIGHT, SB_THUMBPOSITION,
 # SB_THUMBTRACK, SB_TOP, SB_LEFT, SB_BOTTOM, SB_RIGHT, or SB_ENDSCROLL
 #
 # Returns the position of the scrollbar or undef on failure.
 #

New events for WINDOW/DIALOGBOX:
/*
* (@)EVENT:Scroll(SCROLLBAR, OPERATION, POSITION)
* Sent when one of the window scrollbars is moved. SCROLLBAR identifies
* which bar was moved, 0 for horizontal and 1 for vertical.
*
* OPERATION can be compared against one of the following constants:
* SB_LINEUP, SB_LINELEFT, SB_LINEDOWN, SB_LINERIGHT, SB_PAGEUP
* SB_PAGELEFT, SB_PAGEDOWN, SB_PAGERIGHT, SB_THUMBPOSITION,
* SB_THUMBTRACK, SB_TOP, SB_LEFT, SB_BOTTOM, SB_RIGHT, SB_ENDSCROLL
*
* NEM equivalent: onScroll
* Related messages: WM_HSCROLL, WM_VSCROLL
*/

Example code:

use Win32::GUI;
my $win = new Win32::GUI::Window (
 -name => "MainWin",
 -left => 0,
 -top => 100,
 -width => 500,
 -height => 300,
 -sizable => 1,
 -text => "Scrollbar Test",
 -noflicker => 0,
 -hscroll => 1,
 -onScroll => \&scrolled
);

$win->ScrollRange(0,0,100));
$win->ScrollPage(0,10);
$win->ScrollPos(0,50);

$win->Show;
Win32::GUI::Dialog;

sub scrolled {
 my($object,$bar,$operation,$pos) = @_;
 $object->Scroll($bar,$operation,$pos);
# You could also do something like this if you want more control:
#    if($operation == SB_LINEUP) {
#        $object->ScrollPos($bar,$object->ScrollPos($bar) - 1);
#    }
#    elsif($operation == SB_PAGEUP) {
#        $object->ScrollPos($bar,$object->ScrollPos($bar) -
$object->ScrollPage($bar));
#    }
#    elsif($operation == SB_THUMBTRACK) {
#        print "Tracking ".($bar == 0 ? "horizontal" : "vertical")."
scrollbar thumb position: ".$pos."\n";
#    }
#    .... and so on.
}

Steve.


Reply via email to