File Coverage

blib/lib/Wx/DemoModules/wxSpinButton.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/wxSpinButton.pm
3             ## Purpose: wxPerl demo helper for Wx::SpinButton
4             ## Author: Mattia Barbon
5             ## Modified by:
6             ## Created: 13/08/2006
7             ## RCS-ID: $Id: wxSpinButton.pm 2189 2007-08-21 18:15:31Z mbarbon $
8             ## Copyright: (c) 2000, 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::wxSpinButton;
14              
15 1     1   1379 use strict;
  1         3  
  1         39  
16 1     1   5 use base qw(Wx::DemoModules::lib::BaseModule Class::Accessor::Fast);
  1         2  
  1         79  
17              
18             use Wx qw(:spinbutton :sizer wxNOT_FOUND);
19             use Wx::Event qw(EVT_SPIN EVT_SPIN_UP EVT_SPIN_DOWN);
20              
21             __PACKAGE__->mk_accessors( qw(spinbutton value) );
22              
23             sub styles {
24             my( $self ) = @_;
25              
26             return ( [ wxSP_HORIZONTAL, 'Horizontal' ],
27             [ wxSP_VERTICAL, 'Vertical' ],
28             [ wxSP_ARROW_KEYS, 'Allow arrow keys' ],
29             [ wxSP_WRAP, 'Wrap' ],
30             );
31             }
32              
33             sub commands {
34             my( $self ) = @_;
35              
36             return ( { with_value => 1,
37             label => 'Set Value',
38             action => sub { $self->spinbutton->SetValue( $_[0] ) },
39             },
40             { with_value => 2,
41             label => 'Set Range',
42             action => sub {
43             $self->spinbutton->SetRange( $_[0], $_[1] )
44             },
45             },
46             );
47             }
48              
49             sub add_commands {
50             my( $self, $sizer ) = @_;
51              
52             $self->SUPER::add_commands( $sizer );
53              
54             my $sz = Wx::BoxSizer->new( wxHORIZONTAL );
55             $sz->Add( Wx::StaticText->new( $self, -1, 'Value' ), 1, wxALL, 3 );
56             $sz->Add( $self->value( Wx::TextCtrl->new( $self, -1, '' ) ), 1, wxALL, 3 );
57              
58             $sizer->Add( $sz, 0, wxGROW );
59             }
60              
61             sub create_control {
62             my( $self ) = @_;
63              
64             my $spinbutton = Wx::SpinButton->new( $self, -1, [-1, -1], [-1, -1],
65             $self->style );
66             $spinbutton->SetRange( -10, 30 );
67             $spinbutton->SetValue( -5 );
68              
69             EVT_SPIN( $self, $spinbutton, \&OnSpinUpdate );
70             EVT_SPIN_UP( $self, $spinbutton, \&OnSpinUp );
71             EVT_SPIN_DOWN( $self, $spinbutton, \&OnSpinDown );
72              
73             return $self->spinbutton( $spinbutton );
74             }
75              
76             sub OnSpinUp {
77             my( $self, $event ) = @_;
78              
79             Wx::LogMessage( "Spin control up: current = %d",
80             $self->spinbutton->GetValue );
81              
82             if( $self->spinbutton->GetValue > 17 ) {
83             Wx::LogMessage( "Preventing the spin button from going above 17" );
84             $event->Veto;
85             }
86             }
87              
88             sub OnSpinDown {
89             my( $self, $event ) = @_;
90              
91             Wx::LogMessage( "Spin control down: current = %d",
92             $self->spinbutton->GetValue );
93              
94             if( $self->spinbutton->GetValue < -17 ) {
95             Wx::LogMessage( "Preventing the spin button from going below -17" );
96             $event->Veto;
97             }
98             }
99              
100             sub OnSpinUpdate {
101             my( $self, $event ) = @_;
102              
103             $self->value->SetValue( $event->GetPosition );
104             Wx::LogMessage( "Spin control range: ( %d, %d ) current = %d",
105             $self->spinbutton->GetMin,
106             $self->spinbutton->GetMax,
107             $self->spinbutton->GetValue );
108             }
109              
110             sub add_to_tags { qw(controls) }
111             sub title { 'wxSpinButton' }
112              
113             1;