Hello,

in the example below I find the following strange behaviour:
I set the window to a Size so that the vertical scrollbar appears.
If I try to press a Button that is child of a panel which is only partly visible, the scrolled window jumps into a position where the whole panel becomes visible. This happens on BUTTON_DOWN so that the EVT_BUTTON will not be triggered because on BUTTON_RELEASE the Widget has moved away from the Mouse Pointer. (Only the Button that has the Focus reacts without the scrolled window jumping).

Thanks in advance for any insight,

Christoph


use strict;
use warnings;
package TestApp;
use Wx qw(:sizer wxDefaultPosition wxDefaultSize wxVSCROLL wxHSCROLL
          wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER wxSIZE_FORCE );
use Wx::Event qw/ EVT_CLOSE EVT_BUTTON /;
use base 'Wx::App';
sub OnInit{
    my $this = shift;
    my $top = Wx::Dialog->new( undef, -1,'TestApp',
                               wxDefaultPosition, wxDefaultSize,
                               wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
    my $scr = Wx::ScrolledWindow->new($top,-1,
                                      wxDefaultPosition,
                                      wxDefaultSize,
                                     # wxHSCROLL | wxVSCROLL
                                  );
    $scr->SetScrollRate(5,5);
    # a 'toplevel' sizer:
    my $sz = Wx::StaticBoxSizer->new( Wx::StaticBox->new($scr,
                                                         -1,
                                                         'static_box',
                                                     ),wxVERTICAL);
    $scr->SetSizer( $sz );

    # two panels  aligned vertically to hold a set of Buttons each:
    for my $where (qw/Top Bottom/){
        my $panel = Wx::Panel->new( $scr );
        my $sizer = Wx::StaticBoxSizer->new(
                         Wx::StaticBox->new($panel,
                                            -1,
                                            "StaticBox $where",
                                        ),wxVERTICAL);
        $panel->SetSizer( $sizer );
        $sz->Add($panel,0,wxALL,3);

        ## populate the panel with some Buttons
        for my $i (0..5){
            my $b = Wx::Button->new( $panel, -1, "Button $i" );
            $sizer->Add( $b, 0, wxALL, 3 );
            EVT_BUTTON($panel, $b, sub{warn "pressed Button $where $i"});
        }
    }

    EVT_CLOSE( $top, sub{shift->Destroy} );

    $this->SetTopWindow( $top );
    $top->Show( 1 );
    # make the Scrollbar appear ??
    $top->SetSize(-1,-1,200,200);
    $top->SetSize(-1,-1,200,350);

    1;
};

package main;

my $app = TestApp->new;
$app->MainLoop;

Reply via email to