This is mainly intended for Simon, who is working on doc/view.
How to make virtual C++ methods overridable from perl.
I did not test the code. You can find working code in various places.
1 - create a new .h file, say docview.h
2 - put this in the file
class wxPlDocument : public wxDocument
{
WXPLI_DECLARE_DYNAMIC_CLASS( wxPlDocument );
WXPLI_DECLARE_V_CBACK();
public:
wxPlDocument( const char* package )
:m_callback( "Wx::PlSizer" )
{
m_callback.SetSelf( wxPli_make_object( this, package ), TRUE );
}
// overridable methods
// there are various handy macros in cpp/v_cback.h; in this case you can't
// use DEC/DEF_V_CBACK_BOOL__VOID because it uses a non-const method
virtual bool IsModified() const;
};
bool wxPlDocument::IsModified() const
{
if( wxPliVirtualCallback_FindCallback( aTHX_ &m_callback, "IsModified" ) )
{
// you can use _CallCallback( ...., G_SCALAR, "ii", 1, 1 );
// to pass arguments to the callback; I will document the valid
// flag letters ASAP
SV* ret = wxPliVirtualCallback_CallCallback( aTHX_ &m_callback,
G_SCALAR );
bool val = SvTRUE( ret );
SvREFCNT_dec( ret );
return val;
}
return wxDocument::IsModified();
}
WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlDocument, wxDocument );
There are more complex examples of this in various cpp/*.h files.
Feel free to ask if this is not clear enough/need more information.
Regards
Mattia
|