line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wx::Perl::ListView; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Wx::Perl::ListView - virtual list control interface |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 METHODS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1514
|
use Wx; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use strict; |
14
|
|
|
|
|
|
|
use base qw(Wx::ListCtrl); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Wx qw(:listctrl); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 new |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $listview = Wx::Perl::ListView->new( $model, $parent, $id, |
23
|
|
|
|
|
|
|
$position, $size, $style ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Constructs a C using the given model. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
my( $class, $model, $parent, $id, $pos, $size, $style ) = @_; |
31
|
|
|
|
|
|
|
my $self = $class->SUPER::new( $parent, $id || -1, |
32
|
|
|
|
|
|
|
$pos || [-1, -1], $size || [-1,-1], |
33
|
|
|
|
|
|
|
( $style || 0 ) |wxLC_VIRTUAL|wxLC_REPORT ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{_model} = $model; |
36
|
|
|
|
|
|
|
$self->{_cache} = { row => -1, column => -1 }; |
37
|
|
|
|
|
|
|
$self->{_attr} = Wx::ListItemAttr->new; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _get_item { |
43
|
|
|
|
|
|
|
my( $self, $row, $column ) = @_; |
44
|
|
|
|
|
|
|
return $self->{_cache}{item} |
45
|
|
|
|
|
|
|
if $self->{_cache}{row} == $row |
46
|
|
|
|
|
|
|
&& $self->{_cache}{column} == $column; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $item = $self->{_model}->get_item( $row, $column ); |
49
|
|
|
|
|
|
|
die "Could not get item for ($row, $column)" unless $item; |
50
|
|
|
|
|
|
|
if( $item->{font} || $item->{foreground} || $item->{background} ) { |
51
|
|
|
|
|
|
|
$item->{attr} = Wx::ListItemAttr->new; |
52
|
|
|
|
|
|
|
$item->{attr}->SetTextColour( $item->{foreground} ) |
53
|
|
|
|
|
|
|
if $item->{foreground}; |
54
|
|
|
|
|
|
|
$item->{attr}->SetBackgroundColour( $item->{background} ) |
55
|
|
|
|
|
|
|
if $item->{background}; |
56
|
|
|
|
|
|
|
$item->{attr}->SetFont( $item->{font} ) |
57
|
|
|
|
|
|
|
if $item->{font}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->{_cache} = { row => $row, column => $column, item => $item }; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return $item; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub OnGetItemText { |
66
|
|
|
|
|
|
|
my( $self, $row, $column ) = @_; |
67
|
|
|
|
|
|
|
my $item = $self->_get_item( $row, $column ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return defined $item->{string} ? $item->{string} : ''; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub OnGetItemImage { |
73
|
|
|
|
|
|
|
my( $self, $row ) = @_; |
74
|
|
|
|
|
|
|
my $item = $self->_get_item( $row, 0 ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return defined $item->{image} ? $item->{image} : -1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub OnGetItemColumnImage { |
80
|
|
|
|
|
|
|
my( $self, $row, $column ) = @_; |
81
|
|
|
|
|
|
|
my $item = $self->_get_item( $row, $column ); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return defined $item->{image} ? $item->{image} : -1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub OnGetItemAttr { |
87
|
|
|
|
|
|
|
my( $self, $row ) = @_; |
88
|
|
|
|
|
|
|
my $item = $self->_get_item( $row, 0 ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return $item->{attr} || $self->{_attr}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 refresh |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$listview->refresh; |
96
|
|
|
|
|
|
|
$listview->refresh( $item ); |
97
|
|
|
|
|
|
|
$listview->refresh( $from, $to ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Refreshes the displayed data from the model. Might also change |
100
|
|
|
|
|
|
|
the number of items in the control. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub refresh { |
105
|
|
|
|
|
|
|
my( $self, $from, $to ) = @_; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$self->{_cache} = { row => -1, column => -1 }; |
108
|
|
|
|
|
|
|
$self->SetItemCount( $self->{_model}->get_item_count ); |
109
|
|
|
|
|
|
|
$self->RefreshItems( $from, $to ), return if @_ == 3; |
110
|
|
|
|
|
|
|
$self->RefreshItem( $from ), return if @_ == 2; |
111
|
|
|
|
|
|
|
$self->Refresh, return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 model |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $model = $listview->model; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub model { $_[0]->{_model} } |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |