line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: lib/Wx/DemoModules/wxListBox.pm |
3
|
|
|
|
|
|
|
## Purpose: wxPerl demo helper for Wx::ListBox |
4
|
|
|
|
|
|
|
## Author: Mattia Barbon |
5
|
|
|
|
|
|
|
## Modified by: |
6
|
|
|
|
|
|
|
## Created: 13/08/2006 |
7
|
|
|
|
|
|
|
## RCS-ID: $Id: wxListBox.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::wxListBox; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
1150
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
16
|
1
|
|
|
1
|
|
6
|
use base qw(Wx::DemoModules::lib::BaseModule Class::Accessor::Fast); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
153
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Wx qw(:listbox wxNOT_FOUND); |
19
|
|
|
|
|
|
|
use Wx::Event qw(EVT_LISTBOX EVT_LISTBOX_DCLICK); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(listbox) ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub styles { |
24
|
|
|
|
|
|
|
my( $self ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return ( [ wxLB_SORT, 'Sorted' ], |
27
|
|
|
|
|
|
|
[ wxLB_ALWAYS_SB, 'Always show scrollbars' ], |
28
|
|
|
|
|
|
|
[ wxLB_HSCROLL, 'Horizontal scrollbar' ], |
29
|
|
|
|
|
|
|
[ wxLB_SINGLE, 'Single selection' ], |
30
|
|
|
|
|
|
|
[ wxLB_MULTIPLE, 'Multiple selection' ], |
31
|
|
|
|
|
|
|
[ wxLB_EXTENDED, 'Extended selection' ], |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub commands { |
36
|
|
|
|
|
|
|
my( $self ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return ( { label => 'Select item', |
39
|
|
|
|
|
|
|
with_value => 1, |
40
|
|
|
|
|
|
|
action => sub { $self->listbox->SetSelection( $_[0] ) }, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
{ label => 'Select string', |
43
|
|
|
|
|
|
|
with_value => 1, |
44
|
|
|
|
|
|
|
action => sub { $self->listbox |
45
|
|
|
|
|
|
|
->SetStringSelection( $_[0] ) }, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
{ label => 'Clear', |
48
|
|
|
|
|
|
|
action => sub { $self->listbox->Clear }, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
{ label => 'Append', |
51
|
|
|
|
|
|
|
with_value => 1, |
52
|
|
|
|
|
|
|
action => sub { $self->listbox->Append( $_[0] ) }, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
{ label => 'Delete selected item', |
55
|
|
|
|
|
|
|
action => \&on_delete_selected, |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub create_control { |
61
|
|
|
|
|
|
|
my( $self ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $choices = [ 'This', 'is one of my', |
64
|
|
|
|
|
|
|
'really', 'wonderful', 'examples', ]; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $listbox = Wx::ListBox->new( $self, -1, [-1, -1], |
67
|
|
|
|
|
|
|
[-1, -1], $choices, $self->style ); |
68
|
|
|
|
|
|
|
SetControlClientData( 'listbox', $listbox ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
EVT_LISTBOX( $self, $listbox, \&OnListBox ); |
71
|
|
|
|
|
|
|
EVT_LISTBOX_DCLICK( $self, $listbox, \&OnListBoxDoubleClick ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self->listbox( $listbox ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub SetControlClientData { |
77
|
|
|
|
|
|
|
my( $name, $ctrl ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
foreach my $i ( 1 .. $ctrl->GetCount() ) { |
80
|
|
|
|
|
|
|
my $text = $ctrl->GetString( $i - 1 ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$ctrl->SetClientData( $i - 1, "$name client data for $text" ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub OnListBox { |
87
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
if( $event->GetInt() == -1 ) { |
90
|
|
|
|
|
|
|
Wx::LogMessage( "List box has no selections any more" ); |
91
|
|
|
|
|
|
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ListBox Event selection string is '", |
95
|
|
|
|
|
|
|
$event->GetString(), "'" ); |
96
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ListBox Control selection string is '", |
97
|
|
|
|
|
|
|
$self->listbox->GetStringSelection(), "'" ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $cde = $event->GetClientData(); |
100
|
|
|
|
|
|
|
my $cdl = $self->listbox->GetClientData( $self->listbox->GetSelection() ); |
101
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ListBox Event client data is '", |
102
|
|
|
|
|
|
|
( $cde ? $cde : 'none' ) , "'" ); |
103
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ListBox Control client data is '", |
104
|
|
|
|
|
|
|
( $cdl ? $cdl : 'none' ) ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub OnListBoxDoubleClick { |
108
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Wx::LogMessage( join '', "ListBox double click string is '", |
111
|
|
|
|
|
|
|
$event->GetString(), "'" ) ; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub on_delete_selected { |
115
|
|
|
|
|
|
|
my( $self ) = @_; |
116
|
|
|
|
|
|
|
my( $idx ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
if( ( $idx = $self->listbox->GetSelection() ) != wxNOT_FOUND ) { |
119
|
|
|
|
|
|
|
$self->listbox->Delete( $idx ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub add_to_tags { qw(controls) } |
124
|
|
|
|
|
|
|
sub title { 'wxListBox' } |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |