File Coverage

lib/Wx/Perl/EntryList/ListBoxView.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Wx::Perl::EntryList::ListBoxView;
2              
3 1     1   1389 use Wx;
  0            
  0            
4              
5             =head1 NAME
6              
7             Wx::Perl::EntryList::ListBoxView - display an entry list
8              
9             =head1 DESCRIPTION
10              
11             Uses a C to display an entry list.
12              
13             =head1 METHODS
14              
15             =cut
16              
17             use strict;
18             use base qw(Wx::ListBox Class::Accessor::Fast);
19              
20             __PACKAGE__->mk_accessors( qw(list model) );
21              
22             sub new {
23             my( $class, $entrylist, $model, $parent, $style ) = @_;
24             my $self = $class->SUPER::new( $parent, -1, [-1, -1], [-1, -1],
25             [], $style );
26             $self->model( $model );
27             $self->set_list( $entrylist );
28              
29             return $self;
30             }
31              
32             sub set_list {
33             my( $self, $entrylist ) = @_;
34              
35             $self->list->delete_subscriber( '*', $self ) if $self->list;
36             if( $entrylist ) {
37             $entrylist->add_subscriber( '*', $self, '_list_changed' );
38             $self->list( $entrylist );
39             $self->_fill_list;
40             }
41             }
42              
43             sub DESTROY {
44             my( $self ) = @_;
45              
46             $self->set_list( undef );
47             }
48              
49             sub _fill_list {
50             my( $self ) = @_;
51              
52             $self->Clear;
53              
54             for( my $i = 0; $i < $self->list->count; ++$i ) {
55             $self->Append( $self->model->( $self->list->get_entry_at( $i ) ) );
56             }
57             }
58              
59             sub _list_changed {
60             my( $self, $list, $event, %args ) = @_;
61              
62             if( $event eq 'delete_entries' ) {
63             $self->Delete( $args{index} );
64             } elsif( $event eq 'add_entries' ) {
65             my $entry = $list->get_entry_at( $args{index} );
66             my( $label, $data ) = $self->model->( $entry );
67             $self->InsertItems( [ $label ], $args{index} );
68             $self->SetClientData( $args{index}, $data );
69             } elsif( $event eq 'move_entries' ) {
70             my $label = $self->GetString( $args{from} );
71             my $data = $self->GetClientData( $args{from} );
72             $self->Delete( $args{from} );
73             $args{to}-- if $args{from} < $args{to};
74             $self->InsertItems( [ $label ], $args{to} );
75             $self->SetClientData( $args{to}, $data );
76             }
77             }
78              
79             1;