Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / Wx.xs
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        Wx.xs
3 // Purpose:     main XS module
4 // Author:      Mattia Barbon
5 // Modified by:
6 // Created:     01/10/2000
7 // RCS-ID:      $Id: Wx.xs 2610 2009-09-20 13:28:54Z mbarbon $
8 // Copyright:   (c) 2000-2002, 2004-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 #undef bool
14 #define PERL_NO_GET_CONTEXT
15
16 #include <stddef.h>
17 #include "cpp/compat.h"
18
19 // THIS IS AN HACK!
20 #if defined(_MSC_VER)
21 #define STRICT
22 #endif
23
24 #include "cpp/wxapi.h"
25
26 #include <wx/window.h>
27 #include <wx/module.h>
28 // FIXME hack
29 #if WXPERL_W_VERSION_GE( 2, 5, 2 ) \
30     && defined(__DARWIN__)
31 #define HACK
32 #include <wx/html/htmlwin.h>
33 #if wxUSE_MEDIACTRL
34 #include <wx/mediactrl.h>
35 #endif
36 #endif
37
38 #if defined(__WXMSW__)
39 #include <wx/msw/private.h>
40 #endif
41
42 #if WXPERL_W_VERSION_GE( 2, 5, 1 )
43     #include <wx/init.h>
44 #else
45 #if defined(__WXGTK__)
46 int  WXDLLEXPORT wxEntryStart( int& argc, char** argv );
47 #else
48 int  WXDLLEXPORT wxEntryStart( int argc, char** argv );
49 #endif
50 int  WXDLLEXPORT wxEntryInitGui();
51 void WXDLLEXPORT wxEntryCleanup();
52 #endif
53
54 #include "cpp/v_cback.h"
55
56 // to declare wxPliUserDataCD
57 #include "cpp/helpers.h"
58 #include "cpp/helpers.cpp"
59 #include "cpp/v_cback.cpp"
60 #include "cpp/overload.cpp"
61 #include "cpp/ovl_const.cpp"
62
63 //
64 // our App
65 //
66 #include <wx/app.h>
67 #include "cpp/app.h"
68
69 IMPLEMENT_APP_NO_MAIN(wxPliApp);
70 static bool wxPerlAppCreated = false;
71 static bool wxPerlInitialized = false;
72 #if !wxUSE_UNICODE
73 bool wxPli_always_utf8;
74 #endif
75
76 #undef THIS
77
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81     XS( boot_Wx_Const );
82     XS( boot_Wx_Ctrl );
83     XS( boot_Wx_Evt );
84     XS( boot_Wx_Win );
85     XS( boot_Wx_Wnd );
86     XS( boot_Wx_GDI );
87 #if defined( WXPL_STATIC )
88     XS( boot_Wx__DocView );
89 #if wxPERL_USE_STC
90     XS( boot_Wx__STC );
91 #endif
92 #if wxPERL_USE_XRC
93     XS( boot_Wx__XRC );
94 #endif
95     XS( boot_Wx__Print );
96     XS( boot_Wx__MDI );
97     XS( boot_Wx__Html );
98     XS( boot_Wx__Help );
99     XS( boot_Wx__Grid );
100     XS( boot_Wx__FS );
101     XS( boot_Wx__DND );
102 #endif
103 #ifdef __cplusplus
104 }
105 #endif
106
107 extern void SetConstants();
108 extern void SetConstantsOnce();
109
110 static int call_oninit( pTHX_ SV* This, SV* sub )
111 {
112     dSP;
113
114     ENTER;
115     SAVETMPS;
116
117     PUSHMARK( SP );
118     XPUSHs( This );
119     PUTBACK;
120
121     int count = call_sv( sub, G_SCALAR|G_EVAL );
122     int retval = 0;
123
124     SPAGAIN;
125
126     if( SvTRUE( ERRSV ) )
127     {
128         croak( Nullch );
129     }
130     else if( count == 1 )
131     {
132         retval = POPi;
133     }
134
135     PUTBACK;
136
137     FREETMPS;
138     LEAVE;
139
140     return retval;
141 }
142
143
144 #if defined(__WXMOTIF__) && WXPERL_W_VERSION_LT( 2, 5, 1 )
145
146 #include <wx/app.h>
147 #include <wx/log.h>
148
149 int wxEntryStart( int argc, char** argv )
150 {
151 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
152     // This seems to be necessary since there are 'rogue'
153     // objects present at this point (perhaps global objects?)
154     // Setting a checkpoint will ignore them as far as the
155     // memory checking facility is concerned.
156     // Of course you may argue that memory allocated in globals should be
157     // checked, but this is a reasonable compromise.
158     wxDebugContext::SetCheckpoint();
159 #endif
160
161     if (!wxApp::Initialize())
162         return -1;
163
164     return 0;
165 }
166
167 int wxEntryInitGui()
168 {
169     int retValue = 0;
170
171     // GUI-specific initialization, such as creating an app context.
172     if( !wxTheApp->OnInitGui() )
173         retValue = -1;
174
175     return retValue;
176 }
177
178 void wxEntryCleanup()
179 {
180     // flush the logged messages if any
181     wxLog *pLog = wxLog::GetActiveTarget();
182     if ( pLog != NULL && pLog->HasPendingMessages() )
183         pLog->Flush();
184
185     delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
186     // for further messages
187
188     wxApp::CleanUp();
189
190     // some code moved to _wxApp destructor
191     // since at this point the app is already destroyed
192 }
193
194 #endif
195
196 DEFINE_PLI_HELPERS( st_wxPliHelpers );
197
198 #include <wx/confbase.h>
199 typedef wxConfigBase::EntryType EntryType;
200
201 WXPLI_BOOT_ONCE_EXP(Wx);
202 #define boot_Wx wxPli_boot_Wx
203
204 extern bool Wx_booted, Wx_Const_booted, Wx_Ctrl_booted,
205     Wx_Evt_booted, Wx_Wnd_booted, Wx_GDI_booted, Wx_Win_booted;
206
207 #if WXPERL_W_VERSION_LT( 2, 9, 0 )
208 typedef int wxPolygonFillMode;
209 #endif
210
211 MODULE=Wx PACKAGE=Wx
212
213 BOOT:
214   newXSproto( "Wx::_boot_Constant", boot_Wx_Const, file, "$$" );
215   newXSproto( "Wx::_boot_Controls", boot_Wx_Ctrl, file, "$$" );
216   newXSproto( "Wx::_boot_Events", boot_Wx_Evt, file, "$$" );
217   newXSproto( "Wx::_boot_Window", boot_Wx_Win, file, "$$" );
218   newXSproto( "Wx::_boot_Frames", boot_Wx_Wnd, file, "$$" );
219   newXSproto( "Wx::_boot_GDI", boot_Wx_GDI, file, "$$" );
220 #if defined( WXPL_STATIC )
221   newXSproto( "Wx::_boot_Wx__DocView", boot_Wx__DocView, file, "$$" );
222 #if wxPERL_USE_STC
223   newXSproto( "Wx::_boot_Wx__STC", boot_Wx__STC, file, "$$" );
224 #endif
225 #if wxPERL_USE_XRC
226   newXSproto( "Wx::_boot_Wx__XRC", boot_Wx__XRC, file, "$$" );
227 #endif
228   newXSproto( "Wx::_boot_Wx__Print", boot_Wx__Print, file, "$$" );
229   newXSproto( "Wx::_boot_Wx__MDI", boot_Wx__MDI, file, "$$" );
230   newXSproto( "Wx::_boot_Wx__Html", boot_Wx__Html, file, "$$" );
231   newXSproto( "Wx::_boot_Wx__Help", boot_Wx__Help, file, "$$" );
232   newXSproto( "Wx::_boot_Wx__Grid", boot_Wx__Grid, file, "$$" );
233   newXSproto( "Wx::_boot_Wx__FS", boot_Wx__FS, file, "$$" );
234   newXSproto( "Wx::_boot_Wx__DND", boot_Wx__DND, file, "$$" );
235 #endif
236   SV* tmp = get_sv( "Wx::_exports", 1 );
237   sv_setiv( tmp, (IV)(void*)&st_wxPliHelpers );
238
239 #if WXPERL_W_VERSION_GE( 2, 5, 1 )
240 #define wxPliEntryStart( argc, argv ) wxEntryStart( (argc), (argv) )
241 #else
242 #define wxPliEntryStart( argc, argv ) ( wxEntryStart( (argc), (argv) ) == 0 )
243 #endif
244
245 bool 
246 Load()
247   CODE:
248     wxPerlAppCreated = wxTheApp != NULL;
249     if( wxPerlInitialized ) { XSRETURN( true ); }
250     wxPerlInitialized = true;
251
252     NV ver = wxMAJOR_VERSION + wxMINOR_VERSION / 1000.0 + 
253         wxRELEASE_NUMBER / 1000000.0;
254     // set up version as soon as possible
255     SV* tmp = get_sv( "Wx::_wx_version", 1 );
256     sv_setnv( tmp, ver );
257     tmp = get_sv( "Wx::wxVERSION", 1 );
258     sv_setnv( tmp, ver );
259
260     int platform;
261     // change App.pm whenever these change
262 #if defined(__WXMSW__)
263     platform = 1;
264 #elif defined(__WXGTK__)
265     platform = 2;
266 #elif defined(__WXMOTIF__)
267     platform = 3;
268 #elif defined(__WXMAC__)
269     platform = 4;
270 #elif defined(__WXX11__)
271     platform = 5;
272 #else
273     #error must add case
274 #endif
275
276     tmp = get_sv( "Wx::_platform", 1 );
277     sv_setiv( tmp, platform );
278
279     if( wxPerlAppCreated || wxTopLevelWindows.GetCount() > 0 )
280         return;
281 #if defined(DEBUGGING) && !defined(PERL_USE_SAFE_PUTENV)
282     // avoid crash on exit in Fedora (and other DEBUGGING Perls)
283     PL_use_safe_putenv = 1;
284 #endif
285
286     int argc = 0;
287 #if wxUSE_UNICODE && WXPERL_W_VERSION_GE( 2, 5, 3 )
288     wxChar** argv = 0;
289
290     argc = wxPli_get_args_argc_argv( (void***) &argv, 1 );
291     wxPerlInitialized = wxPliEntryStart( argc, argv );
292 #if WXPERL_W_VERSION_LE( 2, 5, 2 )
293     wxPli_delete_argv( (void***) &argv, 1 );
294 #endif
295 #else
296     char** argv = 0;
297
298     argc = wxPli_get_args_argc_argv( (void***) &argv, 0 );
299     wxPerlInitialized = wxPliEntryStart( argc, argv );
300 #if WXPERL_W_VERSION_LE( 2, 5, 2 )
301     wxPli_delete_argv( (void***) &argv, 0 );
302 #endif
303 #endif
304     RETVAL = wxPerlInitialized;
305   OUTPUT: RETVAL
306
307 void
308 SetConstants()
309   CODE:
310     // this is after wxEntryStart, since
311     // wxInitializeStockObjects needs to be called
312     // (for colours, cursors, pens, etc...)
313     SetConstants();
314
315 void
316 SetConstantsOnce()
317
318 void
319 SetOvlConstants()
320
321 void
322 UnLoad()
323   CODE:
324     wxPerlAppCreated = wxTheApp != NULL;
325     Wx_booted = Wx_Const_booted = Wx_Ctrl_booted =
326         Wx_Evt_booted = Wx_Wnd_booted = Wx_GDI_booted = Wx_Win_booted = false;
327     if( wxPerlInitialized && !wxPerlAppCreated )
328         wxEntryCleanup();
329     wxPerlInitialized = false;
330
331 void
332 SetAlwaysUTF8( always_utf8 = true )
333     bool always_utf8
334   CODE:
335 #if !wxUSE_UNICODE
336     wxPli_always_utf8 = always_utf8;
337 #endif
338
339 #if WXPERL_W_VERSION_GE( 2, 5, 1 )
340
341 #include <wx/dynload.h>
342
343 bool
344 _load_plugin( string )
345     wxString string
346   CODE:
347 #ifdef HACK
348     delete new wxHtmlWindow();
349 #if wxUSE_MEDIACTRL
350     delete new wxMediaCtrl();
351 #endif
352 #endif
353     RETVAL = wxPluginManager::LoadLibrary( string, wxDL_VERBATIM );
354   OUTPUT:
355     RETVAL
356
357 bool
358 _unload_plugin( string )
359     wxString string
360   CODE:
361     RETVAL = wxPluginManager::UnloadLibrary( string );
362   OUTPUT:
363     RETVAL
364
365 #endif
366
367 bool
368 _xsmatch( avref, proto, required = -1, allowmore = false )
369     SV* avref
370     SV* proto
371     int required
372     bool allowmore
373   PREINIT:
374     AV* av;
375     wxPliPrototype* prototype;
376     int n, len;
377   PROTOTYPE: \@$;$$
378   CODE:
379     av = wxPli_avref_2_av( avref );
380     if( !av ) croak( "first parameter must be an ARRAY reference" );
381     prototype = INT2PTR( wxPliPrototype*, SvIV( proto ) );
382     len = av_len( av ) + 1;
383     EXTEND(SP, len);
384     PUSHMARK(SP);
385     for( int i = 0; i < len; ++i )
386         PUSHs( *av_fetch( av, i, 0 ) );
387     PUTBACK;
388     RETVAL = wxPli_match_arguments( aTHX_ *prototype, required, allowmore );
389     SPAGAIN;
390     POPMARK; // wxPli_match_* does a PUSHMARK
391   OUTPUT: RETVAL
392
393 I32
394 looks_like_number( sval )
395     SV* sval
396   CODE:
397     RETVAL = my_looks_like_number( aTHX_ sval );
398   OUTPUT:
399     RETVAL
400
401 void
402 CLONE( CLASS )
403     char* CLASS
404   CODE:
405     SetConstants();
406
407 INCLUDE: XS/App.xs
408 INCLUDE: XS/Caret.xs
409 INCLUDE: XS/Geom.xs
410 INCLUDE: XS/Menu.xs
411 INCLUDE: XS/Log.xs
412 INCLUDE: XS/ToolTip.xs
413 INCLUDE: XS/Locale.xs
414 INCLUDE: XS/Utils.xs
415 INCLUDE: XS/Timer.xs
416 INCLUDE: XS/Stream.xs
417 INCLUDE: XS/TaskBarIcon.xs
418 INCLUDE: XS/Config.xs
419 INCLUDE: XS/Process.xs
420 INCLUDE: XS/FontMapper.xs
421 INCLUDE: XS/FontEnumerator.xs
422 INCLUDE: XS/Wave.xs
423 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/ArtProvider.xsp |
424
425 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/MimeTypes.xsp |
426
427 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/Sound.xsp |
428
429 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/Power.xsp |
430
431 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/ClassInfo.xs |
432
433 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/Display.xsp |
434
435 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/StandardPaths.xsp |
436
437 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/Variant.xsp |
438
439 INCLUDE: perl -MExtUtils::XSpp::Cmd -e xspp -- -t typemap.xsp XS/NotificationMessage.xsp |
440
441 ##  //FIXME// tricky
442 ##if defined(__WXMSW__)
443 ##undef XS
444 ##define XS( name ) WXXS( name )
445 ##endif
446
447 MODULE=Wx PACKAGE=Wx
448
449 #!irrelevant class wxArray
450 #!irrelevant class wxArray<T>
451 #!irrelevant class wxArrayString
452 #!irrelevant class wxObjArray
453 #!irrelevant class wxBrushList
454 #!irrelevant class wxClientData
455 #!irrelevant class wxClientDataContainer
456 #!irrelevant class wxCondition
457 #!irrelevant class wxCriticalSection
458 #!irrelevant class wxCriticalSectionLocker
459 #!irrelevant class wxDebugContext
460 #!irrelevant class wxDebugStreamBuf
461 #!irrelevant class wxDynamicLibrary
462 #!irrelevant class wxDynamicLibraryDetails
463 #!irrelevant class wxFFile
464 #!irrelevant class wxFFileInputStream
465 #!irrelevant class wxFFileOutputStream
466 #!irrelevant class wxFFileStream
467 #!irrelevant class wxFile
468 #!irrelevant class wxFileInputStream
469 #!irrelevant class wxFileOutputStream
470 #!irrelevant class wxFileStream
471 #!irrelevant class wxFilterClassFactory
472 #!irrelevant class wxFontList
473 #!irrelevant class wxHashMap
474 #!irrelevant class wxHashSet
475 #!irrelevant class wxHashTable
476 #!irrelevant class wxList
477 #!irrelevant class wxLongLong
478 #!irrelevant class wxMemoryBuffer
479 #!irrelevant class wxModule
480 #!irrelevant class wxMutex
481 #!irrelevant class wxMutexLocker
482 #!irrelevant class wxNode
483 #!irrelevant class wxObjectRefData
484 #!irrelevant class wxPathList
485 #!irrelevant class wxPenList
486 #!irrelevant class wxProtocol
487 #!irrelevant class wxRecursionGuard
488 #!irrelevant class wxRecursionGuardFlag
489 #!irrelevant class wxScopedArray
490 #!irrelevant class wxScopedPtr
491 #!irrelevant class wxScopedTiedPtr
492 #!irrelevant class wxSemaphore
493 #!irrelevant class wxString
494 #!irrelevant class wxStringBuffer
495 #!irrelevant class wxStringBufferLength
496 #!irrelevant class wxStringClientData
497 #!irrelevant class wxStringTokenizer
498 #!irrelevant class wxThreadHelper
499
500 #!equivalent class wxThread to Perl modules thread, thread::shared
501
502 #!equivalent class wxArchiveClassFactory to Perl modules Archive::Any, Archive::Zip, Archive::Tar
503 #!equivalent class wxArchiveEntry to Perl modules Archive::Any, Archive::Zip, Archive::Tar
504 #!equivalent class wxArchiveInputStream to Perl modules Archive::Any, Archive::Zip, Archive::Tar
505 #!equivalent class wxArchiveIterator to Perl modules Archive::Any, Archive::Zip, Archive::Tar
506 #!equivalent class wxArchiveNotifier to Perl modules Archive::Any, Archive::Zip, Archive::Tar
507 #!equivalent class wxArchiveOutputStream to Perl modules Archive::Any, Archive::Zip, Archive::Tar
508 #!equivalent class wxAutomationObject to perl module Win32::OLE
509
510 #!equivalent class wxCSConv to Perl module Encode
511 #!equivalent class wxEncodingConverter to Perl module Encode
512 #!equivalent class wxMBConv to Perl module Encode
513 #!equivalent class wxMBConvFile to Perl module Encode
514 #!equivalent class wxMBConvUTF16 to Perl module Encode
515 #!equivalent class wxMBConvUTF32 to Perl module Encode
516 #!equivalent class wxMBConvUTF7 to Perl module Encode
517 #!equivalent class wxMBConvUTF8 to Perl module Encode
518
519 #!equivalent class wxDb to Perl module DBI
520 #!equivalent class wxDbColDataPtr to Perl module DBI
521 #!equivalent class wxDbColDef to Perl module DBI
522 #!equivalent class wxDbColFor to Perl module DBI
523 #!equivalent class wxDbColInf to Perl module DBI
524 #!equivalent class wxDbConnectInf to Perl module DBI
525 #!irrelevant class wxDbGridColInfo
526 #!equivalent class wxDbIdxDef to Perl module DBI
527 #!equivalent class wxDbInf to Perl module DBI
528 #!equivalent class wxDbTable to Perl module DBI
529 #!equivalent class wxDbTableInf to Perl module DBI
530
531 #!equivalent class wxDir to opendir/readdir and to Perl modules File::Find, File::Find::Rule
532 #!equivalent class wxDirTraverser to Perl modules File::Find, File::Find::Rule
533 #!equivalent class wxFileName to File::Spec, Path::Class
534
535 #!equivalent class wxFTP to Perl modules Net::FTP, LWP::UserAgent
536 #!equivalent class wxHTTP to Perl modules Net::HTTP, LWP::UserAgent
537
538 #!equivalent class wxRegEx to a Perl regular expression
539 #!equivalent class wxRegKey to Perl module Win32::Registry
540
541 #!equivalent class wxTarClassFactory to Perl module Archive::Tar
542 #!equivalent class wxTarEntry to Perl module Archive::Tar
543 #!equivalent class wxTarInputStream to Perl module Archive::Tar
544 #!equivalent class wxTarOutputStream to Perl module Archive::Tar
545
546 #!equivalent class wxTempFile to Perl module File::Temp
547 #!equivalent class wxTempFileOutputStream to Perl module File::Temp
548
549 #!equivalent class wxTextValidator to Perl module Wx::Perl::TextValidator
550
551 #!equivalent class wxURI to Perl module URI
552 #!equivalent class wxURL to Perl module URI::URL
553
554 #!equivalent class wxZipClassFactory to Perl module Archive::Zip
555 #!equivalent class wxZipEntry to Perl module Archive::Zip
556 #!equivalent class wxZipInputStream to Perl module Archive::Zip
557 #!equivalent class wxZipNotifier to Perl module Archive::Zip
558 #!equivalent class wxZipOutputStream to Perl module Archive::Zip
559
560 #!equivalent class wxZlibInputStream to Perl module Compress::Zlib, IO::Zlib
561 #!equivalent class wxZlibOutputStream to Perl module Compress::Zlib, IO::Zlib
562
563 #!equivalent class wxBufferedInputStream to Perl input/output
564 #!equivalent class wxBufferedOutputStream to Perl input/output
565 #!equivalent class wxCountingOutputStream to Perl input/output
566 #!equivalent class wxCountingOutputStream to Perl input/output
567 #!equivalent class wxDataInputStream to Perl module Storable
568 #!equivalent class wxDataOutputStream to Perl module Storable
569 #!equivalent class wxFilterInputStream to Perl module PerlIO::via
570 #!equivalent class wxFilterOutputStream to Perl module PerlIO::via
571 #!equivalent class wxMemoryInputStream to Perl module PerlIO::scalar
572 #!equivalent class wxMemoryOutputStream to Perl module PerlIO::scalar
573 #!equivalent class wxSocketInputStream to Perl modules IO::Socket::*
574 #!equivalent class wxSocketOutputStream to Perl modules IO::Socket::*
575 #!equivalent class wxStreamBase to Perl input/output
576 #!equivalent class wxStreamBase to Perl input/output
577 #!equivalent class wxStreamBuffer to Perl input/output
578 #!equivalent class wxStringInputStream to Perl module PerlIO::scalar
579 #!equivalent class wxStringOutputStream to Perl module PerlIO::scalar
580 #!equivalent class wxTextFile to Perl input/output
581 #!equivalent class wxTextInputStream to Perl input/output
582 #!equivalent class wxTextOutputStream to Perl input/output
583
584 #!equivalent class wxMetafile to Perl module Wx::Metafile
585
586 #!equivalent class wxDialUpEvent to Perl module Wx::DialUpEvent
587 #!equivalent class wxDialUpManager to Perl module Wx::DialUpManager      
588
589 #!equivalent class wxGLCanvas to Perl module Wx::GLCanvas
590 #!equivalent class wxGLContext to Perl module Wx::GLCanvas
591
592 #!equivalent class wxDateTime to perl module DateTime, Date::Calc, Date::Manip, Time::Piece
593 #!equivalent class wxDateSpan to perl module DateTime, Date::Calc, Date::Manip, Time::Piece
594 #!equivalent class wxTimeSpan to perl module DateTime, Date::Calc, Date::Manip, Time::Piece