I have been having some trouble getting my scroll bars to work well. I
have been modifying an example I found on Rob May's weblog
(http://blog.robmay.me.uk/search/label/perl-win32-gui).

Sample code is included below. The problems I am having are:

1) The ScrollRange() call does not seem to be doing anything - I can
scroll well beyond the range specified.

2) SB_PAGE(UP|DOWN) events are not working at all

I am rather new to Win32::GUI and would appreciate any help.

Thanks

__CODE__
#!/usr/bin/perl
use strict; use warnings;

use Win32::GUI 1.05 qw(
    SB_VERT SB_LINEUP SB_LINEDOWN SB_PAGEUP SB_PAGEDOWN
    SB_THUMBTRACK SB_THUMBPOSITION
);

my $window = Win32::GUI::DialogBox->new(
    -name => "scroll_test",
    -text => "Scroll Test",
    -size => [400, 400],
    -vscroll => 1,
    -onScroll => \&process_scroll,
);

my $v_pos = 5;
for ( 0..100 ) {
    $window->AddLabel(
        -name => "label-$_",
        -text => "Label " . ($_ + 1),
        -pos => [5, $v_pos],
        -size => [100, 30],
    );

    $v_pos += 35;
}

$window->ScrollRange(SB_VERT, 0, 35 * 100);

$window->Show();
Win32::GUI::Dialog();

sub process_scroll {
    my ( $self, $bar, $op, $pos ) = @_;

    my $prev_pos = $self->ScrollPos($bar);
    my $new_pos  = $prev_pos;

    my $use_rel = 0;
    my $rel_move = 0;

    if ( $op == SB_LINEUP ) {    # or SB_LINELEFT
        $new_pos -= 35;
        $rel_move -= 35;
        $use_rel = 1;
    } elsif ( $op == SB_LINEDOWN ) {    # or SB_LINERIGHT
        $new_pos += 35;
        $rel_move += 35;
        $use_rel = 1;
    } elsif ( $op == SB_PAGEUP ) {      # or SB_PAGELEFT
        $new_pos -= $self->ScrollPage($bar);
    } elsif ( $op == SB_PAGEDOWN ) {    # or SB_PAGERIGHT
        $new_pos += $self->ScrollPage($bar);
    } elsif ( $op == SB_THUMBTRACK ) {
        $new_pos = $pos;
    } elsif ( $op == SB_THUMBPOSITION ) {
        $new_pos = $pos;
    }

    $self->ScrollPos( $bar, $new_pos );

    if ( $bar == SB_VERT ) {
        for my $key ( %$self ) {
            next unless ref($self->{$key}) eq "Win32::GUI::Label";
            $self->{$key}->Top( -$new_pos );        # doesn't work

            my $cur = $self->{$key}->Top();
            #$self->{$key}->Top($cur - $rel_move);  # works better, but only
                                                    # for SB_LINE(UP|DOWN)
        }
    }

    1;
}

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to