File Coverage

lib/Devel/ebug/Wx/View/Configuration/Simple.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Devel::ebug::Wx::View::Configuration::Simple;
2              
3 1     1   2237 use strict;
  1         2  
  1         36  
4 1     1   6 use base qw(Wx::Panel Class::Accessor::Fast);
  1         1  
  1         814  
5             use Devel::ebug::Wx::Plugin qw(:plugin);
6              
7             __PACKAGE__->mk_ro_accessors( qw(attributes _controls) );
8              
9             use Wx qw(:sizer wxNullFont wxFNTP_DEFAULT_STYLE);
10              
11             sub tag { 'configuration_simple' }
12              
13             sub new : Configuration {
14             my( $class, $parent, $attributes ) = @_;
15             my $self = $class->SUPER::new( $parent );
16             $self->{attributes} = $attributes;
17             $self->{_controls} = {};
18              
19             $self->create_fields;
20             $self->set_data;
21             $self->SetMinSize( [250, 200] );
22              
23             return $self;
24             }
25              
26             # FIXME switch-like type handling sucks
27             sub create_fields {
28             my( $self ) = @_;
29              
30             my $sz = Wx::FlexGridSizer->new( 0, 2, 3, 3 );
31             $sz->AddGrowableCol( $_ ) foreach 0 .. 2 - 1;
32             foreach my $key ( @{$self->attributes->{keys}} ) {
33             my $label = Wx::StaticText->new( $self, -1, $key->{label} );
34             my $control;
35             if( $key->{type} eq 'font' ) {
36             $control = Wx::FontPickerCtrl->new
37             ( $self, -1, wxNullFont, [-1, -1], [-1, -1],
38             wxFNTP_DEFAULT_STYLE );
39             } elsif( $key->{type} eq 'string' ) {
40             $control = Wx::TextCtrl->new( $self, -1, '' );
41             }
42             $self->_controls->{$key} = $control;
43             $sz->Add( $label, 0 );
44             $sz->Add( $control, 0, wxGROW );
45             }
46             $self->SetSizer( $sz );
47             }
48              
49             sub set_data {
50             my( $self ) = @_;
51              
52             foreach my $key ( @{$self->attributes->{keys}} ) {
53             my $control = $self->_controls->{$key};
54             next unless defined $key->{value};
55             if( $key->{type} eq 'font' ) {
56             my $font = Wx::Font->new( $key->{value} );
57             $control->SetSelectedFont( $font );
58             } elsif( $key->{type} eq 'string' ) {
59             $control->SetValue( $key->{value} );
60             }
61             }
62             }
63              
64             sub retrieve_data {
65             my( $self ) = @_;
66              
67             foreach my $key ( @{$self->attributes->{keys}} ) {
68             my $control = $self->_controls->{$key};
69             if( $key->{type} eq 'font' ) {
70             $key->{value} = $control->GetSelectedFont->GetNativeFontInfoDesc;
71             } elsif( $key->{type} eq 'string' ) {
72             $key->{value} = $control->GetValue;
73             }
74             }
75             }
76              
77             1;