line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
## Name: lib/Wx/DemoModules/wxXrcCustom.pm |
3
|
|
|
|
|
|
|
## Purpose: wxWidgets' XML Resources demo |
4
|
|
|
|
|
|
|
## Author: Mattia Barbon |
5
|
|
|
|
|
|
|
## Created: 25/08/2003 |
6
|
|
|
|
|
|
|
## RCS-ID: $Id: wxXrcCustom.pm 2189 2007-08-21 18:15:31Z mbarbon $ |
7
|
|
|
|
|
|
|
## Copyright: (c) 2003, 2006 Mattia Barbon |
8
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself |
10
|
|
|
|
|
|
|
############################################################################# |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1722
|
use Wx::XRC; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Wx::FS; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Wx::DemoModules::wxXrcCustom::XmlHandler; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use strict; |
18
|
|
|
|
|
|
|
use base 'Wx::PlXmlResourceHandler'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# this methods must return true if the handler can handle |
21
|
|
|
|
|
|
|
# the given XML node |
22
|
|
|
|
|
|
|
sub CanHandle { |
23
|
|
|
|
|
|
|
my( $self, $xmlnode ) = @_; |
24
|
|
|
|
|
|
|
return $self->IsOfClass( $xmlnode, 'HelloWorld' ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# this method is where the actual creation takes place |
28
|
|
|
|
|
|
|
sub DoCreateResource { |
29
|
|
|
|
|
|
|
my( $self ) = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# this is the case when the user called LoadOnXXX, to load |
32
|
|
|
|
|
|
|
# an already created object. We could handle this case as well, |
33
|
|
|
|
|
|
|
# (just calling ->Create instead of ->new), but that would |
34
|
|
|
|
|
|
|
# just complicate the code |
35
|
|
|
|
|
|
|
die 'LoadOnXXX not supported by this handler' if $self->GetInstance; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $ctrl = Wx::DemoModules::wxXrcCustom::HelloWorldCtrl->new |
38
|
|
|
|
|
|
|
( $self->GetParentAsWindow, |
39
|
|
|
|
|
|
|
$self->GetID, |
40
|
|
|
|
|
|
|
$self->GetColour( 'colour' ), |
41
|
|
|
|
|
|
|
$self->GetPosition, |
42
|
|
|
|
|
|
|
$self->GetSize, |
43
|
|
|
|
|
|
|
$self->GetStyle( "style", 0 ), |
44
|
|
|
|
|
|
|
$self->GetName ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->SetupWindow( $ctrl ); |
47
|
|
|
|
|
|
|
$self->CreateChildren( $ctrl ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return $ctrl; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package Wx::DemoModules::wxXrcCustom; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
use strict; |
55
|
|
|
|
|
|
|
use base qw(Wx::Panel); |
56
|
|
|
|
|
|
|
use Wx qw(wxDefaultPosition wxDefaultSize wxVERSION_STRING |
57
|
|
|
|
|
|
|
wxOK wxICON_INFORMATION wxPOINT wxSIZE); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
|
|
|
|
|
|
my( $class, $parent ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# could load from file, but this keeps the code inline |
63
|
|
|
|
|
|
|
Wx::FileSystem::AddHandler( Wx::MemoryFSHandler->new ); |
64
|
|
|
|
|
|
|
local $/; |
65
|
|
|
|
|
|
|
Wx::MemoryFSHandler::AddTextFile( 'sample.xrc', <
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#ffffff |
71
|
|
|
|
|
|
|
20, 20 |
72
|
|
|
|
|
|
|
100, 20 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#ff0000 |
76
|
|
|
|
|
|
|
20, 60 |
77
|
|
|
|
|
|
|
200, 50 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
300, 300 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
EOT |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $res = Wx::XmlResource->new; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$res->InitAllHandlers(); |
87
|
|
|
|
|
|
|
$res->AddHandler( Wx::DemoModules::wxXrcCustom::XmlHandler->new ); |
88
|
|
|
|
|
|
|
$res->Load( 'memory:sample.xrc' ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $self = $res->LoadPanel( $parent, 'MyPanel' ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub tags { [ 'misc/xrc', 'XRC' ] } |
96
|
|
|
|
|
|
|
sub add_to_tags { qw(misc/xrc) } |
97
|
|
|
|
|
|
|
sub title { 'Custom handler' } |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
package Wx::DemoModules::wxXrcCustom::HelloWorldCtrl; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
use strict; |
102
|
|
|
|
|
|
|
use base 'Wx::StaticText'; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
use Wx qw(wxBLACK); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new { |
107
|
|
|
|
|
|
|
my( $class, $parent, $id, $colour, $pos, $size, $style, $name ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$colour ||= wxBLACK; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $self = $class->SUPER::new( $parent, $id, 'Hello, world!', $pos, $size, |
112
|
|
|
|
|
|
|
$style, $name ); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->SetForegroundColour( $colour ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return $self; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |