| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ############################################################################# | 
| 2 |  |  |  |  |  |  | ## Name:        lib/Wx/DemoModules/wxChoice.pm | 
| 3 |  |  |  |  |  |  | ## Purpose:     wxPerl demo helper for Wx::Choice | 
| 4 |  |  |  |  |  |  | ## Author:      Mattia Barbon | 
| 5 |  |  |  |  |  |  | ## Modified by: | 
| 6 |  |  |  |  |  |  | ## Created:     13/08/2006 | 
| 7 |  |  |  |  |  |  | ## RCS-ID:      $Id: wxChoice.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::wxChoice; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  | 1 |  | 1377 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 43 |  | 
| 16 | 1 |  |  | 1 |  | 5 | use base qw(Wx::DemoModules::lib::BaseModule Class::Accessor::Fast); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 124 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | use Wx qw(:combobox wxNOT_FOUND); | 
| 19 |  |  |  |  |  |  | use Wx::Event qw(EVT_CHOICE); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | __PACKAGE__->mk_accessors( qw(choice) ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub styles { | 
| 24 |  |  |  |  |  |  | my( $self ) = @_; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | return ( [ wxCB_SORT, 'Sorted' ], | 
| 27 |  |  |  |  |  |  | ); | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub commands { | 
| 31 |  |  |  |  |  |  | my( $self ) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | return ( { label       => 'Select item', | 
| 34 |  |  |  |  |  |  | with_value  => 1, | 
| 35 |  |  |  |  |  |  | action      => sub { $self->choice->SetSelection( $_[0] ) }, | 
| 36 |  |  |  |  |  |  | }, | 
| 37 |  |  |  |  |  |  | { label       => 'Select string', | 
| 38 |  |  |  |  |  |  | with_value  => 1, | 
| 39 |  |  |  |  |  |  | action      => sub { $self->choice | 
| 40 |  |  |  |  |  |  | ->SetStringSelection( $_[0] ) }, | 
| 41 |  |  |  |  |  |  | }, | 
| 42 |  |  |  |  |  |  | { label       => 'Clear', | 
| 43 |  |  |  |  |  |  | action      => sub { $self->choice->Clear }, | 
| 44 |  |  |  |  |  |  | }, | 
| 45 |  |  |  |  |  |  | { label       => 'Append', | 
| 46 |  |  |  |  |  |  | with_value  => 1, | 
| 47 |  |  |  |  |  |  | action      => sub { $self->choice->Append( $_[0] ) }, | 
| 48 |  |  |  |  |  |  | }, | 
| 49 |  |  |  |  |  |  | { label       => 'Delete selected item', | 
| 50 |  |  |  |  |  |  | action      => \&on_delete_selected, | 
| 51 |  |  |  |  |  |  | }, | 
| 52 |  |  |  |  |  |  | ); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub create_control { | 
| 56 |  |  |  |  |  |  | my( $self ) = @_; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | my $choices = [ 'This', 'is one of my', | 
| 59 |  |  |  |  |  |  | 'really', 'wonderful', 'examples', ]; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | my $choice =  Wx::Choice->new( $self, -1, | 
| 62 |  |  |  |  |  |  | [-1, -1], [120, -1], $choices, | 
| 63 |  |  |  |  |  |  | $self->style ); | 
| 64 |  |  |  |  |  |  | EVT_CHOICE( $self, $choice, \&OnChoice ); | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | return $self->choice( $choice ); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub OnChoice { | 
| 70 |  |  |  |  |  |  | my( $self, $event ) = @_; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Wx::LogMessage( join '', "Choice event selection string is: '", | 
| 73 |  |  |  |  |  |  | $event->GetString(), "'" ); | 
| 74 |  |  |  |  |  |  | Wx::LogMessage( "Choice control selection string is: '", | 
| 75 |  |  |  |  |  |  | $self->choice->GetStringSelection(), "'" ); | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub on_delete_selected { | 
| 79 |  |  |  |  |  |  | my( $self ) = @_; | 
| 80 |  |  |  |  |  |  | my( $idx ); | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | if( ( $idx = $self->choice->GetSelection() ) != wxNOT_FOUND ) { | 
| 83 |  |  |  |  |  |  | $self->choice->Delete( $idx ); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub add_to_tags { qw(controls) } | 
| 88 |  |  |  |  |  |  | sub title { 'wxChoice' } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | 1; |