1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cpp/e_cback.cpp
3 // Purpose: implementation for e_cback.h
4 // Author: Mattia Barbon
7 // RCS-ID: $Id: e_cback.cpp 2454 2008-08-31 11:12:47Z mbarbon $
8 // Copyright: (c) 2000-2002, 2004-2008 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 /////////////////////////////////////////////////////////////////////////////
13 wxPliEventCallback::wxPliEventCallback( SV* method, SV* self )
17 SvREFCNT_inc( m_method );
19 SvREFCNT_inc( m_self );
20 m_is_method = !SvROK( m_method ) || !SvRV( m_method );
23 wxPliEventCallback::~wxPliEventCallback()
26 SvREFCNT_dec( m_method );
27 SvREFCNT_dec( m_self );
44 wxPli_thread_sv_unregister( aTHX_ wxPli_get_class( aTHX_ m_sv ),
45 (void*)SvIV( m_sv ), m_sv );
50 void SetSV( SV* sv ) { m_sv = sv; }
55 void wxPliEventCallback::Handler( wxEvent& event )
57 wxPliEventCallback* This = (wxPliEventCallback*) event.m_callbackUserData;
66 // similar to wxPli_object_2_sv
70 wxClassInfo *ci = event.GetClassInfo();
71 const wxChar* classname = ci->GetClassName();
74 if( wcsncmp( classname, wxT("wxPl"), 4 ) == 0 )
76 if( strnEQ( classname, "wxPl", 4 ) )
79 wxPliClassInfo* cci = (wxPliClassInfo*)ci;
80 wxPliSelfRef* sr = cci->m_func( &event );
84 // this needs to have the refcount incremented, otherwise
85 // the refcount will be decremented one time too much when
86 // exiting from the handler
87 e = sv_2mortal( newRV_inc( SvRV( sr->m_self ) ) );
93 char buffer[WXPL_BUF_SIZE];
94 const char* CLASS = wxPli_cpp_class_2_perl( classname, buffer );
97 sv_setref_pv( e, CHAR_P CLASS, &event );
99 // corner case: prevent destruction if referrer is
104 wxPli_thread_sv_register( aTHX_ CLASS, &event, e );
108 XPUSHs( This->m_self );
112 if( This->m_is_method )
114 call_method( SvPV_nolen( This->m_method ), G_EVAL|G_VOID|G_DISCARD );
118 call_sv( This->m_method, G_EVAL|G_VOID|G_DISCARD );
124 if( SvTRUE( ERRSV ) )
134 // Local variables: //