1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: C++ helpers for user-defined events
4 // Author: Mattia Barbon
7 // RCS-ID: $Id: event.h 2526 2009-02-07 14:35:21Z mbarbon $
8 // Copyright: (c) 2002-2004, 2006-2007, 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 /////////////////////////////////////////////////////////////////////////////
15 #include "cpp/v_cback.h"
17 class wxPlEvent : public wxEvent
19 WXPLI_DECLARE_DYNAMIC_CLASS_CTOR( wxPlEvent );
20 WXPLI_DECLARE_V_CBACK();
22 // only to appease wxWidgets' RTTI
23 wxPlEvent() : m_callback( NULL ) {}
25 wxPlEvent( const char* package, int id, wxEventType eventType )
26 : wxEvent( id, eventType ),
27 m_callback( "Wx::PlEvent" )
29 m_callback.SetSelf( wxPli_make_object( this, package ), true );
34 m_callback.DeleteSelf( false );
37 virtual wxEvent* Clone() const;
40 wxEvent* wxPlEvent::Clone() const
43 wxPlEvent* self = (wxPlEvent*)this;
45 // only to appease wxWidgets' RTTI
46 if( !self->m_callback.IsOk() )
47 return new wxPlEvent();
49 if( wxPliVirtualCallback_FindCallback( aTHX_ &self->m_callback, "Clone" ) )
51 SV* ret = wxPliVirtualCallback_CallCallback
52 ( aTHX_ &self->m_callback, G_SCALAR, NULL );
54 (wxPlEvent*)wxPli_sv_2_object( aTHX_ ret, "Wx::PlEvent" );
62 WXPLI_IMPLEMENT_DYNAMIC_CLASS_CTOR( wxPlEvent, wxEvent );
64 class wxPlCommandEvent : public wxCommandEvent
66 WXPLI_DECLARE_DYNAMIC_CLASS_CTOR( wxPlCommandEvent );
67 WXPLI_DECLARE_V_CBACK();
69 // only to appease wxWidgets' RTTI
70 wxPlCommandEvent() : m_callback( NULL ) {}
72 wxPlCommandEvent( const char* package, int id, wxEventType eventType )
73 : wxCommandEvent( id, eventType ),
74 m_callback( "Wx::PlCommandEvent" )
76 m_callback.SetSelf( wxPli_make_object( this, package ), true );
79 virtual ~wxPlCommandEvent()
81 m_callback.DeleteSelf( false );
84 virtual wxEvent* Clone() const;
87 wxEvent* wxPlCommandEvent::Clone() const
90 wxPlCommandEvent* self = (wxPlCommandEvent*)this;
92 // only to appease wxWidgets' RTTI
93 if( !self->m_callback.IsOk() )
94 return new wxPlCommandEvent();
96 if( wxPliVirtualCallback_FindCallback( aTHX_ &self->m_callback, "Clone" ) )
98 SV* ret = wxPliVirtualCallback_CallCallback
99 ( aTHX_ &self->m_callback, G_SCALAR, NULL );
100 wxPlCommandEvent* clone = (wxPlCommandEvent*)
101 wxPli_sv_2_object( aTHX_ ret, "Wx::PlCommandEvent" );
109 WXPLI_IMPLEMENT_DYNAMIC_CLASS_CTOR( wxPlCommandEvent, wxCommandEvent );
111 class wxPlThreadEvent : public wxEvent
113 WXPLI_DECLARE_DYNAMIC_CLASS_CTOR( wxPlThreadEvent );
115 static void SetStash( SV* hv_ref )
117 m_hv = (HV*)SvRV( hv_ref );
119 static HV* GetStash() { return m_hv; }
121 wxPlThreadEvent() : m_data( 0 ) {}
122 wxPlThreadEvent( pTHX_ const char* package, int id, wxEventType eventType,
124 : wxEvent( id, eventType )
126 PL_lockhook( aTHX_ (SV*)GetStash() );
127 PL_sharehook( aTHX_ data );
134 length = sprintf( buffer, "%d", data_id );
135 if( !hv_exists( GetStash(), buffer, length ) )
138 SV** dst = hv_fetch( GetStash(), buffer, length, 1 );
139 sv_setsv( *dst, data );
144 wxPlThreadEvent( const wxPlThreadEvent& e )
159 PL_lockhook( aTHX_ (SV*)m_hv );
162 size_t length = sprintf( buffer, "%d", m_data );
164 hv_delete( m_hv, buffer, length, G_DISCARD );
170 int _GetData() const { return m_data; }
179 PL_lockhook( aTHX_ (SV*)m_hv );
182 size_t length = sprintf( buffer, "%d", m_data );
184 SV** value = hv_fetch( m_hv, buffer, length, 0 );
188 SvREFCNT_inc( *value );
193 virtual wxEvent* Clone() const;
199 wxEvent* wxPlThreadEvent::Clone() const
201 wxEvent* clone = new wxPlThreadEvent( *this );
202 ((wxPlThreadEvent*)this)->m_data = 0;
207 HV* wxPlThreadEvent::m_hv = NULL;
209 wxPliSelfRef* wxPliGetSelfForwxPlThreadEvent( wxObject* object ) { return 0; }
211 #if wxUSE_EXTENDED_RTTI
212 const wxClassInfo* wxPlThreadEvent::ms_classParents[] =
213 { &wxEvent::ms_classInfo , NULL };
214 wxPliClassInfo wxPlThreadEvent::ms_classInfo(
215 ms_classParents, (wxChar*)wxT( "wxPlPlThreadEvent"),
216 (int)sizeof(wxPlThreadEvent), wxPlThreadEvent::wxCreateObject,
217 (wxPliGetCallbackObjectFn) wxPliGetSelfForwxPlThreadEvent );
219 wxPliClassInfo wxPlThreadEvent::ms_classInfo(
220 (wxChar*)wxT( "wxPlPlThreadEvent"), &wxEvent::ms_classInfo,
221 NULL, (int)sizeof(wxPlThreadEvent), wxPlThreadEvent::wxCreateObject,
222 (wxPliGetCallbackObjectFn) wxPliGetSelfForwxPlThreadEvent );
224 wxObject* wxPlThreadEvent::wxCreateObject() { return new wxPlThreadEvent(); }
226 // local variables: //