1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#############################################################################
## Name: XS/EventFilter.xsp
## Purpose: XS++ for wxEventFilter class
## Author: Mark Dootson
## Modified by:
## Created: 2012-09-26
## RCS-ID: $Id:$
## Copyright: (c) 2012 Mark Dootson
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################
%module{Wx};
%file{xspp/eventfilter.h};
%{
class wxPlEventFilter : public wxEventFilter
{
WXPLI_DECLARE_V_CBACK();
public:
wxPlEventFilter( const char* package )
: wxEventFilter(),
m_callback( "Wx::EventFilter" )
{
dTHX;
m_callback.SetSelf( wxPli_non_object_2_sv(aTHX_ sv_newmortal(), this, package ), true );
}
virtual int FilterEvent(wxEvent& event)
{
dTHX;
if( wxPliFCback( aTHX_ &m_callback, "FilterEvent" ) )
{
// code from e_cback.h
dSP;
ENTER;
SAVETMPS;
int retval;
{
wxPliGuard guard;
SV* e = 0;
SV* rv = 0;
wxClassInfo *ci = event.GetClassInfo();
const wxChar* classname = ci->GetClassName();
if( wcsncmp( classname, wxT("wxPl"), 4 ) == 0 )
{
wxPliClassInfo* cci = (wxPliClassInfo*)ci;
wxPliSelfRef* sr = cci->m_func( &event );
if( sr )
{
// this needs to have the refcount incremented, otherwise
// the refcount will be decremented one time too much when
// exiting from the handler
e = sv_2mortal( newRV_inc( SvRV( sr->m_self ) ) );
}
}
if( !e )
{
char buffer[WXPL_BUF_SIZE];
const char* CLASS = wxPli_cpp_class_2_perl( classname, buffer );
e = sv_newmortal();
sv_setref_pv( e, CHAR_P CLASS, &event );
rv = SvRV( e );
// corner case: prevent destruction if referrer is
// destroyed
SvREFCNT_inc( rv );
sv_2mortal( rv );
guard.SetSV( rv );
wxPli_thread_sv_register( aTHX_ CLASS, &event, e );
}
PUSHMARK( SP );
XPUSHs( m_callback.GetSelf() );
XPUSHs( e );
PUTBACK;
SV* method = sv_2mortal( newRV_inc( (SV*) m_callback.GetMethod() ) );
call_sv( method, G_SCALAR );
SPAGAIN;
retval = POPi;
}
PUTBACK;
FREETMPS;
LEAVE;
return retval;
}
else
return -1; // constant Event_Skip
}
};
%}
%file{-};
#if WXPERL_W_VERSION_GE( 2, 9, 3 )
#include <wx/eventfilter.h>
#include "cpp/e_cback.h"
#include "xspp/eventfilter.h"
%typemap{wxPlEventFilter*}{simple};
%typemap{wxEventFilter*}{simple};
%typemap{wxEvent*}{simple};
%name{Wx::EventFilter} class wxEventFilter
{
%{
static void
wxEventFilter::CLONE()
CODE:
wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
%}
public:
%name{Destroy} virtual ~wxEventFilter()
%code%{ wxPli_thread_sv_unregister( aTHX_ "Wx::EventFilter", THIS, ST(0) );
delete THIS;
%};
virtual int FilterEvent(wxEvent* event)
%code%{ RETVAL = -1; %};
};
%name{Wx::PlEventFilter} class wxPlEventFilter : public %name{Wx::EventFilter} wxEventFilter
{
public:
wxPlEventFilter()
%code{% RETVAL = new wxPlEventFilter( CLASS ); %};
};
#endif
|