File Coverage

blib/lib/Wx/DemoModules/wxXrc.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             #############################################################################
2             ## Name: lib/Wx/DemoModules/wxXrc.pm
3             ## Purpose: wxWidgets' XML Resources demo
4             ## Author: Mattia Barbon
5             ## Modified by: Scott Lanning, 11/09/2002
6             ## Created: 12/09/2001
7             ## RCS-ID: $Id: wxXrc.pm 2189 2007-08-21 18:15:31Z mbarbon $
8             ## Copyright: (c) 2001, 2004, 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 1     1   1369 use Wx::XRC;
  0            
  0            
14              
15             package Wx::DemoModules::wxXrc;
16              
17             use strict;
18             use base qw(Wx::Panel Class::Accessor::Fast);
19              
20             use Wx::Event qw(EVT_BUTTON EVT_MENU);
21              
22             __PACKAGE__->mk_ro_accessors( qw(xrc) );
23              
24             sub new {
25             my( $class, $parent ) = @_;
26             my $self = $class->SUPER::new( $parent );
27              
28             # load XRC file
29             $self->{xrc} = Wx::XmlResource->new();
30             $self->xrc->InitAllHandlers();
31             $self->xrc->Load( Wx::Demo->get_data_file( 'xrc/resource.xrc' ) );
32              
33             # basic layout
34             my $but_frame = Wx::Button->new( $self, -1, 'Load frame', [10, 10] );
35             my $but_dialog = Wx::Button->new( $self, -1, 'Load dialog', [150, 10] );
36              
37             EVT_BUTTON( $self, $but_frame, \&show_frame );
38             EVT_BUTTON( $self, $but_dialog, \&show_dialog );
39              
40             return $self;
41             }
42              
43             sub show_frame {
44             my( $self ) = @_;
45              
46             my $frame = Wx::Frame->new
47             ( undef, -1, 'XML resources demo', [50, 50], [450, 340] );
48             my $menubar = $self->xrc->LoadMenuBar( 'mainmenu' );
49             my $toolbar = $self->xrc->LoadToolBar( $self, 'toolbar' );
50              
51             $frame->SetMenuBar( $menubar );
52             $frame->SetToolBar( $toolbar );
53              
54             EVT_MENU( $frame, Wx::XmlResource::GetXRCID( 'menu_quit' ),
55             sub { $frame->Close } );
56             EVT_MENU( $frame, Wx::XmlResource::GetXRCID( 'menu_dlg1' ),
57             sub { $self->show_dialog( $frame, undef ) } );
58              
59             $frame->Show;
60             }
61              
62             sub show_dialog {
63             my( $self, $event, $parent ) = @_;
64              
65             my $dialog = $self->xrc->LoadDialog( $parent || $self, 'dlg1' );
66             $dialog->ShowModal;
67             $dialog->Destroy;
68             }
69              
70             sub add_to_tags { qw(misc/xrc) }
71             sub title { 'Simple' }
72              
73             1;