File Coverage

blib/lib/Wx/DemoModules/wxScrollBar.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             #############################################################################
2             ## Name: lib/Wx/DemoModules/wxScrollBar.pm
3             ## Purpose: wxPerl demo helper for Wx::ScrollBar
4             ## Author: Mattia Barbon
5             ## Modified by:
6             ## Created: 27/05/2003
7             ## RCS-ID: $Id: wxScrollBar.pm 2189 2007-08-21 18:15:31Z mbarbon $
8             ## Copyright: (c) 2003, 2005-2006 Mattia Barbon
9             ## Licence: This program is free software; you can redistribute it and/or
10             ## modify it under the same terms as Perl itself
11             #############################################################################
12              
13             package Wx::DemoModules::wxScrollBar;
14              
15 1     1   1113 use strict;
  1         3  
  1         50  
16 1     1   6 use base qw(Wx::DemoModules::lib::BaseModule Class::Accessor::Fast);
  1         3  
  1         128  
17             use Wx qw(:sizer :scrollbar wxWHITE wxHORIZONTAL wxVERTICAL);
18             use Wx::Event qw(/EVT_SCROLL_*/ EVT_BUTTON);
19              
20             __PACKAGE__->mk_accessors( qw(scrollbar) );
21              
22             sub log_scroll_event {
23             my( $event, $type ) = @_;
24              
25             Wx::LogMessage( 'Scroll %s event: orientation = %s, position = %d', $type,
26             ( $event->GetOrientation == wxHORIZONTAL ) ? 'horizontal' :
27             'vertical',
28             $event->GetPosition );
29              
30             # important! skip event for default processing to happen
31             $event->Skip;
32             }
33              
34             sub styles {
35             my( $self ) = @_;
36              
37             return ( [ wxSB_HORIZONTAL, 'Horizontal' ],
38             [ wxSB_VERTICAL, 'Vertical' ],
39             );
40             }
41              
42             sub commands { 1 }
43              
44             sub add_commands {
45             my( $self, $sizer ) = @_;
46              
47             my $szpos = Wx::BoxSizer->new( wxHORIZONTAL );
48             my $szthumb = Wx::BoxSizer->new( wxHORIZONTAL );
49             my $szrange = Wx::BoxSizer->new( wxHORIZONTAL );
50             my $szpagesz = Wx::BoxSizer->new( wxHORIZONTAL );
51              
52             my $vpos = Wx::TextCtrl->new( $self, -1, '0' );
53             my $vthumb = Wx::TextCtrl->new( $self, -1, '15' );
54             my $vrange = Wx::TextCtrl->new( $self, -1, '100' );
55             my $vpagesz = Wx::TextCtrl->new( $self, -1, '10' );
56              
57             $szpos->Add( Wx::StaticText->new( $self, -1, 'Position' ),
58             1, wxALL, 3 );
59             $szpos->Add( $vpos, 1, wxALL, 3 );
60             $szthumb->Add( Wx::StaticText->new( $self, -1, 'Thumb size' ),
61             1, wxALL, 3 );
62             $szthumb->Add( $vthumb, 1, wxALL, 3 );
63             $szrange->Add( Wx::StaticText->new( $self, -1, 'Range' ),
64             1, wxALL, 3 );
65             $szrange->Add( $vrange, 1, wxALL, 3 );
66             $szpagesz->Add( Wx::StaticText->new( $self, -1, 'Page size' ),
67             1, wxALL, 3 );
68             $szpagesz->Add( $vpagesz, 1, wxALL, 3 );
69              
70             my $doit = Wx::Button->new( $self, -1, 'Set values' );
71             EVT_BUTTON( $self, $doit, sub {
72             $self->scrollbar->SetScrollbar( $vpos->GetValue,
73             $vthumb->GetValue,
74             $vrange->GetValue,
75             $vpagesz->GetValue );
76             } );
77              
78             $sizer->Add( $szpos, 0, wxGROW );
79             $sizer->Add( $szthumb, 0, wxGROW );
80             $sizer->Add( $szrange, 0, wxGROW );
81             $sizer->Add( $szpagesz, 0, wxGROW );
82             $sizer->Add( $doit, 0, wxGROW );
83             }
84              
85             sub create_control {
86             my( $self ) = @_;
87              
88             my $size = [ ( $self->style & wxSB_HORIZONTAL ) ? 200 : -1,
89             ( $self->style & wxSB_VERTICAL ) ? 200 : -1 ];
90             my $scrollbar = Wx::ScrollBar->new
91             ( $self, -1, [ -1, -1 ], $size,
92             $self->style );
93              
94             $scrollbar->SetScrollbar( 0, 15, 100, 10 );
95              
96             EVT_SCROLL_TOP( $scrollbar,
97             sub { log_scroll_event( $_[1], 'to top' ) } );
98             EVT_SCROLL_BOTTOM( $scrollbar,
99             sub { log_scroll_event( $_[1], 'to bottom' ) } );
100             EVT_SCROLL_LINEUP( $scrollbar,
101             sub { log_scroll_event( $_[1], 'a line up' ) } );
102             EVT_SCROLL_LINEDOWN( $scrollbar,
103             sub { log_scroll_event( $_[1], 'a line down' ) } );
104             EVT_SCROLL_PAGEUP( $scrollbar,
105             sub { log_scroll_event( $_[1], 'a page up' ) } );
106             EVT_SCROLL_PAGEDOWN( $scrollbar,
107             sub { log_scroll_event( $_[1], 'a page down' ) } );
108             # EVT_SCROLL_THUMBTRACK( $scrollbar,
109             # sub { log_scroll_event( $_[1], 'thumbtrack' ) } );
110             EVT_SCROLL_THUMBRELEASE( $scrollbar,
111             sub { log_scroll_event( $_[1], 'thumbrelease' ) } );
112              
113             return $self->scrollbar( $scrollbar );
114             }
115              
116             sub add_to_tags { qw(controls) }
117             sub title { 'wxScrollBar' }
118              
119             1;