line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: lib/Wx/DemoModules/wxComboBox.pm |
3
|
|
|
|
|
|
|
## Purpose: wxPerl demo helper for Wx::ComboBox |
4
|
|
|
|
|
|
|
## Author: Mattia Barbon |
5
|
|
|
|
|
|
|
## Modified by: |
6
|
|
|
|
|
|
|
## Created: 13/08/2006 |
7
|
|
|
|
|
|
|
## RCS-ID: $Id: wxComboBox.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::wxComboBox; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
1608
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
16
|
1
|
|
|
1
|
|
5
|
use base qw(Wx::DemoModules::lib::BaseModule Class::Accessor::Fast); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Wx qw(:combobox :textctrl wxNOT_FOUND); |
19
|
|
|
|
|
|
|
use Wx::Event qw(EVT_COMBOBOX EVT_TEXT EVT_TEXT_ENTER); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(combobox) ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub styles { |
24
|
|
|
|
|
|
|
my( $self ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return ( [ wxCB_SORT, 'Sorted' ], |
27
|
|
|
|
|
|
|
[ wxCB_SIMPLE, 'Simple' ], |
28
|
|
|
|
|
|
|
[ wxCB_DROPDOWN, 'Dropdown' ], |
29
|
|
|
|
|
|
|
[ wxCB_READONLY, 'Read-only' ], |
30
|
|
|
|
|
|
|
[ wxTE_PROCESS_ENTER, 'Process enter' ], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub commands { |
35
|
|
|
|
|
|
|
my( $self ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return ( { label => 'Select item', |
38
|
|
|
|
|
|
|
with_value => 1, |
39
|
|
|
|
|
|
|
action => sub { $self->combobox->SetSelection( $_[0] ) }, |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
{ label => 'Select string', |
42
|
|
|
|
|
|
|
with_value => 1, |
43
|
|
|
|
|
|
|
action => sub { $self->combobox |
44
|
|
|
|
|
|
|
->SetStringSelection( $_[0] ) }, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
{ label => 'Clear', |
47
|
|
|
|
|
|
|
action => sub { $self->combobox->Clear }, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
{ label => 'Append', |
50
|
|
|
|
|
|
|
with_value => 1, |
51
|
|
|
|
|
|
|
action => sub { $self->combobox->Append( $_[0] ) } |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
{ label => 'Delete selected item', |
54
|
|
|
|
|
|
|
action => \&on_delete_selected, |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub create_control { |
60
|
|
|
|
|
|
|
my( $self ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $choices = [ 'This', 'is one of my', |
63
|
|
|
|
|
|
|
'really', 'wonderful', 'examples', ]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $combobox = Wx::DemoModules::wxComboBox::Custom->new |
66
|
|
|
|
|
|
|
( $self, -1, "This", [-1, -1], [-1, -1], |
67
|
|
|
|
|
|
|
$choices, $self->style ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
EVT_COMBOBOX( $self, $combobox, \&OnCombo ); |
70
|
|
|
|
|
|
|
EVT_TEXT( $self, $combobox, \&OnComboTextChanged ); |
71
|
|
|
|
|
|
|
EVT_TEXT_ENTER( $self, $combobox, \&OnComboTextEnter ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self->combobox( $combobox ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub OnCombo { |
77
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ComboBox event selection string is: '", |
80
|
|
|
|
|
|
|
$event->GetString(), "'" ); |
81
|
|
|
|
|
|
|
Wx::LogMessage( "ComboBox control selection string is: '", |
82
|
|
|
|
|
|
|
$self->combobox->GetStringSelection(), "'" ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub OnComboTextChanged { |
86
|
|
|
|
|
|
|
my( $self ) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Wx::LogMessage( "Text in the combobox changed: now is '%s'.", |
89
|
|
|
|
|
|
|
$self->combobox->GetValue() ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub OnComboTextEnter { |
93
|
|
|
|
|
|
|
my( $self ) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Wx::LogMessage( "Enter pressed in the combobox changed: now is '%s'.", |
96
|
|
|
|
|
|
|
$self->combobox->GetValue() ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub on_delete_selected { |
100
|
|
|
|
|
|
|
my( $self ) = @_; |
101
|
|
|
|
|
|
|
my( $idx ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if( ( $idx = $self->combobox->GetSelection() ) != wxNOT_FOUND ) { |
104
|
|
|
|
|
|
|
$self->combobox->Delete( $idx ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub add_to_tags { qw(controls) } |
109
|
|
|
|
|
|
|
sub title { 'wxComboBox' } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
package Wx::DemoModules::wxComboBox::Custom; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
use strict; |
114
|
|
|
|
|
|
|
use base qw(Wx::ComboBox); |
115
|
|
|
|
|
|
|
use Wx::Event qw(EVT_SET_FOCUS EVT_CHAR EVT_KEY_DOWN EVT_KEY_UP); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub new { |
118
|
|
|
|
|
|
|
my( $class ) = shift; |
119
|
|
|
|
|
|
|
my( $self ) = $class->SUPER::new( @_ ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
EVT_SET_FOCUS( $self, \&OnFocusGot ); |
122
|
|
|
|
|
|
|
EVT_CHAR( $self, \&OnChar ); |
123
|
|
|
|
|
|
|
EVT_KEY_DOWN( $self, \&OnKeyDown ); |
124
|
|
|
|
|
|
|
EVT_KEY_UP( $self, \&OnKeyUp ); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $self; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub OnChar { |
130
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Wx::LogMessage( 'Wx::DemoModules::wxComboBox::Custom::OnChar' ); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
if( $event->GetKeyCode() == ord( 'w' ) ) { |
135
|
|
|
|
|
|
|
Wx::LogMessage( "Wx::DemoModules::wxComboBox::Custom: 'w' ignored" ); |
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
$event->Skip(); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub OnKeyDown { |
142
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Wx::LogMessage( 'Wx::DemoModules::wxComboBox::Custom::OnKeyDown' ); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
if( $event->GetKeyCode() == ord( 'w' ) ) { |
147
|
|
|
|
|
|
|
Wx::LogMessage( "Wx::DemoModules::wxComboBox::Custom: 'w' ignored" ); |
148
|
|
|
|
|
|
|
} else { |
149
|
|
|
|
|
|
|
$event->Skip(); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub OnKeyUp { |
154
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Wx::LogMessage( 'Wx::DemoModules::wxComboBox::Custom::OnKeyUp' ); |
157
|
|
|
|
|
|
|
$event->Skip(); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub OnFocusGot { |
161
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Wx::LogMessage( 'Wx::DemoModules::wxComboBox::Custom::FocusGot' ); |
164
|
|
|
|
|
|
|
$event->Skip(); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |