Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / debian / libwx-perl / usr / lib / perl5 / Wx.pm
1 #############################################################################
2 ## Name:        Wx.pm
3 ## Purpose:     main wxPerl module
4 ## Author:      Mattia Barbon
5 ## Modified by:
6 ## Created:     01/10/2000
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 #############################################################################
12
13 package Wx;
14
15 use strict;
16 require Exporter;
17
18 use vars qw(@ISA $VERSION $XS_VERSION $AUTOLOAD @EXPORT_OK %EXPORT_TAGS
19   $_platform $_universal $_msw $_gtk $_motif $_mac $_x11 $_static);
20
21 $_msw = 1; $_gtk = 2; $_motif = 3; $_mac = 4; $_x11 = 5;
22
23 @ISA = qw(Exporter);
24 $VERSION = '0.96';
25 $XS_VERSION = $VERSION;
26 $VERSION = eval $VERSION;
27
28 sub BEGIN{
29   @EXPORT_OK = qw(wxPOINT wxSIZE wxTheApp);
30   %EXPORT_TAGS = ( );
31 }
32
33 #
34 # utility functions
35 #
36 sub wxPOINT  { Wx::Point->new( $_[0], $_[1] ) }
37 sub wxSIZE   { Wx::Size->new( $_[0], $_[1] )  }
38 sub wxTheApp { $Wx::wxTheApp }
39
40 sub AUTOLOAD {
41   my( $constname, $error );
42
43   ($constname = $AUTOLOAD) =~ s<^.*::>{};
44   return 0 if $constname eq 'wxVERSION';
45
46   my( $val ) = constant( $constname, 0, $error );
47
48   if( $error != 0 ) {
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'" );
53   }
54
55   eval "sub $AUTOLOAD { $val }";
56   goto &$AUTOLOAD;
57 }
58
59 # handle :allclasses specially
60 sub import {
61   my $package = shift;
62   my $count = 0;
63   foreach ( @_ ) {
64     m/^:/ or last;
65     m/^:allclasses$/ and do {
66       eval _get_packages();
67
68       die $@ if $@;
69
70       splice @_, $count, 1;
71     };
72
73     ++$count;
74   }
75
76   $package->export_to_level( 1, $package, @_ );
77 }
78
79 sub END {
80   UnLoad() if defined &UnLoad;
81 }
82
83 sub _match(\@$;$$) { &_xsmatch( [@{shift()}],@_ ) }
84
85 sub _ovl_error {
86   ( 'unable to resolve overloaded method for ', $_[0] || (caller(1))[3] );
87 }
88
89 sub _croak {
90   require Carp;
91   goto &Carp::croak;
92 }
93
94 # Blech! (again...)
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
100 use Wx::Mini;
101
102 _start();
103
104 our( $wx_path );
105
106 sub _load_file {
107   Wx::wxVERSION() < 2.005 ? DynaLoader::dl_load_file( $_[0], 0 ) :
108                             Wx::_load_plugin( $_[0] );
109 }
110
111 my( $load_fun, $unload_fun ) = ( \&_load_dll, \&_unload_dll );
112
113 sub set_load_function { $load_fun = shift }
114 sub set_end_function { $unload_fun = shift }
115
116 sub load_dll {
117   return if $^O ne 'MSWin32';
118   goto &$load_fun;
119 }
120
121 sub unload_dll {
122   return if $^O ne 'MSWin32';
123   goto &$unload_fun;
124 }
125
126 END { unload_dll() }
127
128 sub _unload_dll { }
129
130 sub _load_dll {
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 );
136 }
137
138 {
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 );
145 }
146
147 #
148 # British vs. American spelling aliases
149 #
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;
154 no strict 'refs';
155 *{"Wx::Size::y"} = \&Wx::Size::height; # work around syntax highlighting
156 use strict 'refs';
157 *Wx::Size::x = \&Wx::Size::width;
158
159 *Wx::Window::GetClientSizeWH = \&Wx::Window::GetClientSizeXY;
160
161 if( Load() ) {
162     SetConstants();
163     SetConstantsOnce();
164     SetOvlConstants();
165     SetEvents();
166     SetInheritance();
167 }
168
169 sub END {
170   UnsetConstants() if defined &UnsetConstants;
171 }
172
173 #
174 # set up wxUNIVERSAL, wxGTK, wxMSW, etc
175 #
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 }" );
183
184 # Mac OS X warning
185 if( wxMAC() && $^X !~ m{/wxPerl\.app/} && !$ENV{HARNESS_ACTIVE} ) {
186     warn "On Mac OS X please run scripts with the 'wxPerl' interpreter\n";
187 }
188
189 require Wx::App;
190 require Wx::Event;
191 require Wx::Locale;
192 require Wx::Menu;
193 require Wx::RadioBox;
194 require Wx::Timer;
195 require Wx::Wx_Exp;
196 # for Wx::Stream & co.
197 require Tie::Handle;
198
199 package Wx::GDIObject; # warning for non-existent package
200 package Wx::Object;    # likewise
201
202 #
203 # overloading for Wx::TreeItemId
204 #
205 package Wx;
206
207 sub _string { overload::StrVal( $_[0] ) }
208 sub _number { require Scalar::Util; Scalar::Util::refaddr( $_[0] ) }
209
210 package Wx::TreeItemId;
211
212 use overload '<=>'      => \&tiid_spaceship,
213              'bool'     => sub { $_[0]->IsOk },
214              '""'       => \&Wx::_string,
215              '0+'       => \&Wx::_number,
216              'fallback' => 1;
217
218 package Wx::Font;
219
220 use overload '<=>'      => \&font_spaceship,
221              'bool'     => sub { $_[0]->IsOk },
222              '""'       => \&Wx::_string,
223              '0+'       => \&Wx::_number,
224              'fallback' => 1;
225
226 #
227 # Various functions
228 #
229
230 package Wx;
231
232 # easier to implement than to wrap
233 sub GetMultipleChoices {
234   my( $message, $caption, $choices, $parent, $x, $y, $centre,
235       $width, $height ) = @_;
236
237   my( $dialog ) = Wx::MultiChoiceDialog->new
238     ( $parent, $message, $caption, $choices );
239
240   if( $dialog->ShowModal() == &Wx::wxID_OK ) {
241     my( @s ) = $dialog->GetSelections();
242     $dialog->Destroy();
243     return @s;
244   }
245
246   $dialog->Destroy;
247   return;
248 }
249
250 sub LogTrace {
251   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogTrace( $t );
252 }
253
254 sub LogTraceMask {
255   my( $m ) = shift;
256   unless( @_ ) { require Carp; Carp::carp( "No message for $m" ); }
257   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogTraceMask( $m, $t );
258 }
259
260 sub LogStatus {
261   my( $t );
262
263   if( ref( $_[0] ) && $_[0]->isa( 'Wx::Frame' ) ) {
264     my( $f ) = shift;
265
266     $t = sprintf( shift, @_ );
267     $t =~ s/\%/\%\%/g; wxLogStatusFrame( $f, $t );
268   } else {
269     $t = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogStatus( $t );
270   }
271 }
272
273 sub LogError {
274   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogError( $t );
275 }
276
277 sub LogFatalError {
278   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogFatalError( $t );
279 }
280
281 sub LogWarning {
282   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogWarning( $t );
283 }
284
285 sub LogMessage {
286   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogMessage( $t );
287 }
288
289 sub LogVerbose {
290   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogVerbose( $t );
291 }
292
293 sub LogSysError {
294   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogSysError( $t ); 
295 }
296
297 sub LogDebug {
298   my( $t ) = sprintf( shift, @_ ); $t =~ s/\%/\%\%/g; wxLogDebug( $t ); 
299 }
300
301 my $ts_buf;
302
303 sub Wx::Log::SetTimestamp {
304     Wx::Log::_SetTimestamp( $_[0], $ts_buf );
305 }
306
307 package Wx::PlThreadEvent;
308
309 our %stash : shared;
310 SetStash( \%stash );
311
312 1;
313
314 __END__
315
316 =head1 NAME
317
318 Wx - interface to the wxWidgets cross-platform GUI toolkit
319
320 =head1 SYNOPSIS
321
322     use Wx;
323
324     my $app = Wx::SimpleApp->new;
325     my $frame = Wx::Frame->new( undef, -1, 'Hello, world!' );
326
327     $frame->Show;
328     $app->MainLoop;
329
330 =head1 DESCRIPTION
331
332 The Wx module is a wrapper for the wxWidgets (formerly known as wxWindows)
333 GUI toolkit.
334
335 This module comes with extensive documentation in HTML format; you
336 can download it from http://wxperl.sourceforge.net/
337
338 =head1 INSTALLATION
339
340 Please see F<docs/INSTALL.pod> in source package.
341
342 =head1 Windows XP look
343
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.
348
349   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
350   <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
351       <assemblyIdentity
352           processorArchitecture="x86"
353           version="5.1.0.0"
354           type="win32"
355           name="Controls"
356       />
357       <description>Super wxPerl Application</description>
358       <dependency>
359           <dependentAssembly>
360               <assemblyIdentity
361                   type="win32"
362                   name="Microsoft.Windows.Common-Controls"
363                   version="6.0.0.0"
364                   publicKeyToken="6595b64144ccf1df"
365                   language="*"
366                   processorArchitecture="x86"
367           />
368       </dependentAssembly>
369       </dependency>
370   </assembly>
371
372 =head1 AUTHOR
373
374 Mattia Barbon <mbarbon@cpan.org>
375
376 =head1 LICENSE
377
378 This program is free software; you can redistribute it and/or
379 modify it under the same terms as Perl itself.
380
381 =cut
382
383 # Local variables: #
384 # mode: cperl #
385 # End: #