Win32-GUI-XMLBuilder
view release on metacpan or search on metacpan
lib/Win32/GUI/XMLBuilder.pm view on Meta::CPAN
}
elsif ($_->gi =~ /^$qrTop/) {
$self->_GenericTop($t, $_);
}
elsif ($_->gi =~ /^$qrFile/) {
$self->_GenericFile($t, $_);
}
elsif ($_->gi =~ /^$qrNoParent/) {
$self->_GenericNoParent($t, $_);
}
}
foreach (sort keys %{$self->{_show_}}) {
$self->debug("show widget $_ with command ${$self->{_show_}}{$_}");
if (${$self->{_show_}}{$_} =~ /\$self|(^\s*exec:)/) {
(my $eval = ${$self->{_show_}}{$_}) =~ s/(^\s*exec:)//;
${$self->{_show_}}{$_} = eval "{ package main; no strict; use Win32::GUI(); ".$eval."}"; print STDERR $@ if $@;
}
$self->{$_}->Show(${$self->{_show_}}{$_});
}
my $u = new XML::Twig(
TwigHandlers => {
PostExec => sub { $self->WGXPost(@_) },
WGXPost => sub { $self->WGXPost(@_) },
}
);
$u->parse($t->sprint);
return $self;
}
=head1 SUPPORTED WIDGETS - ELEMENTS
Most Win32::GUI widgets are supported and general type widgets can added without any modification
being added to this module.
=over 4
=item <WGXPre>
The <WGXPre> element is parsed before GUI construction and is useful for defining subroutines
and global variables. Code is wrapped in a { package main; no strict; .. } so that if subroutines
are created they can contain variables in your program including Win32::GUI::XMLBuilder instances.
The current Win32::GUI::XMLBuilder instance can also be accessed outside subroutines as $self.
If any data is returned it must be valid XML that will be parsed once by the WGXPost phase, see below.
Since you may need to use a illegal XML characters within this element such as
< less than (<)
> greater than (>)
& ampersand (&)
' apostrophe (')
" quotation mark (")
you can use the alternative predefined entity reference or enclose this data in a "<![CDATA[" "]]>" section.
Please look at the samples and read http://www.w3schools.com/xml/xml_cdata.asp.
The <WGXPre> element was previously called <PreExec>. The <PreExec> tag is deprecated but remains
only for backward compatibility and will be removed in a later release.
=cut
sub WGXPre {
my ($self, $t, $e) = @_;
$self->debug($e->text);
my $ret = eval "{ package main; no strict; ".$e->text."}";
print STDERR "$@" if $@;
$self->debug($ret);
$e->set_text('');
my $pcdata= XML::Twig::Elt->new(XML::Twig::ENT, $ret);
$pcdata->paste($e);
$e->erase();
}
=item <WGXExec>
The <WGXExec> element is parsed during GUI construction and allows code to be inserted at arbitrary points in the code.
It otherwise behaves exactly the same as <WGXPre> and can be used to place _Resize subroutines. If any data is returned
it must be valid XML that will be parsed once by the WGXPost phase, see below.
=cut
sub WGXExec { WGXPre(@_) }
=item <WGXPost>
The <WGXPost> element is parsed after GUI construction and allows code to be included at the end of an XML file.
It otherwise behaves exactly the same as <WGXPre> and can be used to place _Resize subroutines.
The <WGXPost> element was previously called <PostExec>. The <PostExec>
tag is deprecated but remains only for backward compatibility and will be removed in a later release.
=cut
sub WGXPost {
my ($self, $t, $e) = @_;
$self->debug($e->text);
my $ret = eval "{ package main; no strict; ".$e->text."}";
print STDERR "$@" if $@;
$self->debug($ret);
}
=item <Icon>, <Bitmap> and <Cursor> elements.
The <Icon> element allows you to specify an Icon for your program.
<Icon file="myicon.ico" name='MyIcon' />
The <Bitmap> element allows you to specify an Bitmap for your program.
<Bitmap file="bitmap.bmp" name='Image' />
The <Cursor> element allows you to specify an Cursor for your program.
<Cursor file="mycursor.cur" name='Cursor' />
=cut
sub _GenericFile {
my ($self, $t, $e) = @_;
my $widget = $e->gi;
my $name = $self->genname($e);
my $file = $e->{'att'}->{'file'} !~ /\$/ ? $e->{'att'}->{'file'} : eval $e->{'att'}->{'file'};;
$self->debug("\n$widget (_GenericFile): $name");
$self->debug("file -> $file");
$self->{$name} = eval "new Win32::GUI::$widget('$file')" || $self->error;
}
=item <ImageList>
( run in 3.232 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )