1 #############################################################################
3 ## Purpose: main wxPerl module
4 ## Author: Mattia Barbon
7 ## RCS-ID: $Id: Wx.pm 2731 2009-12-29 21:19:56Z mbarbon $
8 ## Copyright: (c) 2000-2009 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 #############################################################################
18 use vars qw(@ISA $VERSION $XS_VERSION $AUTOLOAD @EXPORT_OK %EXPORT_TAGS
19 $_platform $_universal $_msw $_gtk $_motif $_mac $_x11 $_static);
21 $_msw = 1; $_gtk = 2; $_motif = 3; $_mac = 4; $_x11 = 5;
25 $XS_VERSION = $VERSION;
26 $VERSION = eval $VERSION;
29 @EXPORT_OK = qw(wxPOINT wxSIZE wxTheApp);
36 sub wxPOINT { Wx::Point->new( $_[0], $_[1] ) }
37 sub wxSIZE { Wx::Size->new( $_[0], $_[1] ) }
38 sub wxTheApp { $Wx::wxTheApp }
41 my( $constname, $error );
43 ($constname = $AUTOLOAD) =~ s<^.*::>{};
44 return 0 if $constname eq 'wxVERSION';
46 my( $val ) = constant( $constname, 0, $error );
49 # re-add this if need support for autosplitted subroutines
50 # $AutoLoader::AUTOLOAD = $AUTOLOAD;
51 # goto &AutoLoader::AUTOLOAD;
52 Wx::_croak( "Error while autoloading '$AUTOLOAD'" );
55 eval "sub $AUTOLOAD { $val }";
59 # handle :allclasses specially
65 m/^:allclasses$/ and do {
76 $package->export_to_level( 1, $package, @_ );
80 UnLoad() if defined &UnLoad;
83 sub _match(\@$;$$) { &_xsmatch( [@{shift()}],@_ ) }
86 ( 'unable to resolve overloaded method for ', $_[0] || (caller(1))[3] );
95 # wxWidgets DLLs need to be installed in the same directory as Wx.dll,
96 # but then LoadLibrary can't find them unless they are already loaded,
97 # so we explicitly load them (on Win32 and wxWidgets 2.5.x+) just before
98 # calling Wx::wx_boot. Finding the library requires determining the path
99 # and the correct name
107 Wx::wxVERSION() < 2.005 ? DynaLoader::dl_load_file( $_[0], 0 ) :
108 Wx::_load_plugin( $_[0] );
111 my( $load_fun, $unload_fun ) = ( \&_load_dll, \&_unload_dll );
113 sub set_load_function { $load_fun = shift }
114 sub set_end_function { $unload_fun = shift }
117 return if $^O ne 'MSWin32';
122 return if $^O ne 'MSWin32';
131 local $ENV{PATH} = $wx_path . ';' . $ENV{PATH} if $wx_path;
132 return unless exists $Wx::dlls->{$_[0]} && $Wx::dlls->{$_[0]};
133 my $dll = $Wx::dlls->{$_[0]};
134 $dll = $wx_path . '/' . $dll if $wx_path;
135 Wx::_load_file( $dll );
139 _boot_Constant( 'Wx', $XS_VERSION );
140 _boot_Events( 'Wx', $XS_VERSION );
141 _boot_Window( 'Wx', $XS_VERSION );
142 _boot_Controls( 'Wx', $XS_VERSION );
143 _boot_Frames( 'Wx', $XS_VERSION );
144 _boot_GDI( 'Wx', $XS_VERSION );
148 # British vs. American spelling aliases
150 *Wx::Window::Center = \&Wx::Window::Centre;
151 *Wx::Window::CenterOnParent = \&Wx::Window::CentreOnParent;
152 *Wx::Window::CenterOnScreen = \&Wx::Window::CentreOnScreen;
153 *Wx::ListCtrl::InsertStringImageItem = \&Wx::ListCtrl::InsertImageStringItem;
155 *{"Wx::Size::y"} = \&Wx::Size::height; # work around syntax highlighting
157 *Wx::Size::x = \&Wx::Size::width;
159 *Wx::Window::GetClientSizeWH = \&Wx::Window::GetClientSizeXY;
170 UnsetConstants() if defined &UnsetConstants;
174 # set up wxUNIVERSAL, wxGTK, wxMSW, etc
176 eval( "sub wxUNIVERSAL() { $_universal }" );
177 eval( "sub wxPL_STATIC() { $_static }" );
178 eval( "sub wxMOTIF() { $_platform == $_motif }" );
179 eval( "sub wxMSW() { $_platform == $_msw }" );
180 eval( "sub wxGTK() { $_platform == $_gtk }" );
181 eval( "sub wxMAC() { $_platform == $_mac }" );
182 eval( "sub wxX11() { $_platform == $_x11 }" );
185 if( wxMAC() && $^X !~ m{/wxPerl\.app/} && !$ENV{HARNESS_ACTIVE} ) {
186 warn "On Mac OS X please run scripts with the 'wxPerl' interpreter\n";
193 require Wx::RadioBox;
196 # for Wx::Stream & co.
199 package Wx::GDIObject; # warning for non-existent package
200 package Wx::Object; # likewise
203 # overloading for Wx::TreeItemId
207 sub _string { overload::StrVal( $_[0] ) }
208 sub _number { require Scalar::Util; Scalar::Util::refaddr( $_[0] ) }
210 package Wx::TreeItemId;
212 use overload '<=>' => \&tiid_spaceship,
213 'bool' => sub { $_[0]->IsOk },
214 '""' => \&Wx::_string,
215 '0+' => \&Wx::_number,
220 use overload '<=>' => \&font_spaceship,
221 'bool' => sub { $_[0]->IsOk },
222 '""' => \&Wx::_string,
223 '0+' => \&Wx::_number,
232 # easier to implement than to wrap
233 sub GetMultipleChoices {
234 my( $message, $caption, $choices, $parent, $x, $y, $centre,
235 $width, $height ) = @_;
237 my( $dialog ) = Wx::MultiChoiceDialog->new
238 ( $parent, $message, $caption, $choices );
240 if( $dialog->ShowModal() == &Wx::wxID_OK ) {
241 my( @s ) = $dialog->GetSelections();
251 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogTrace( $t );
256 unless( @_ ) { require Carp; Carp::carp( "No message for $m" ); }
257 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogTraceMask( $m, $t );
263 if( ref( $_[0] ) && $_[0]->isa( 'Wx::Frame' ) ) {
266 $t = sprintf( shift, @_ );
267 $t =~ s/\%/\%\%/g; wxLogStatusFrame( $f, $t );
269 $t = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogStatus( $t );
274 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogError( $t );
278 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogFatalError( $t );
282 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogWarning( $t );
286 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogMessage( $t );
290 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogVerbose( $t );
294 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogSysError( $t );
298 my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogDebug( $t );
303 sub Wx::Log::SetTimestamp {
304 Wx::Log::_SetTimestamp( $_[0], $ts_buf );
307 package Wx::PlThreadEvent;
318 Wx - interface to the wxWidgets cross-platform GUI toolkit
324 my $app = Wx::SimpleApp->new;
325 my $frame = Wx::Frame->new( undef, -1, 'Hello, world!' );
332 The Wx module is a wrapper for the wxWidgets (formerly known as wxWindows)
335 This module comes with extensive documentation in HTML format; you
336 can download it from http://wxperl.sourceforge.net/
340 Please see F<docs/INSTALL.pod> in source package.
342 =head1 Windows XP look
344 For standalone (packed using PAR, Perl2Exe, Perl2App, ...)
345 applications to get Windows XP look, a file named C<App.exe.manifest>
346 (assuming the program is named C<App.exe>) and containing the text below
347 must be placed in the same directory as the executable file.
349 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
350 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
352 processorArchitecture="x86"
357 <description>Super wxPerl Application</description>
362 name="Microsoft.Windows.Common-Controls"
364 publicKeyToken="6595b64144ccf1df"
366 processorArchitecture="x86"
374 Mattia Barbon <mbarbon@cpan.org>
378 This program is free software; you can redistribute it and/or
379 modify it under the same terms as Perl itself.