I an trying to write a custom event, and I am trying to follow "Creating a Custom Event - Method 4" in the wiki page http://wiki.wxwidgets.org/Custom_Events.
I am having trouble, I think, trying to translate the example to my own use. First it is a "command event" example, and I think I want a "regular" event.
Here is my code for the header file:
Code: Select all
#ifndef CAPTUREEVENT_H
#define CAPTUREEVENT_H
#include <wx/event.h>
#include "CapturedData.h"
DECLARE_EVENT_TYPE( DataReadyEvent, -1 )
class CaptureEvent : public wxEvent
{
public:
// class constructor
CaptureEvent();
// class destructor
~CaptureEvent();
CaptureEvent( const CaptureEvent &event );
virtual wxEvent *Clone() const { return new CaptureEvent(*this); };
wxString GetText() const { return m_Text; };
void SetText( const wxString& text ) { m_Text = text; };
void SetData( CapturedData* cd) { data = cd; };
CapturedData* GetData(void) const { return data; };
private:
wxString m_Text;
CapturedData* data;
//** the following line was commented-out because it caused a linker error
//DECLARE_DYNAMIC_CLASS( CaptureEvent );
};
#endif // CAPTUREEVENT_H
The example also includes the following suggested code:
Code: Select all
typedef void (wxEvtHandler::*MyFooEventFunction)(MyFooEvent &);
// This #define simplifies the one below, and makes the syntax less
// ugly if you want to use Connect() instead of an event table.
#define MyFooEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)\
wxStaticCastEvent(MyFooEventFunction, &func)
// Define the event table entry. Yes, it really *does* end in a comma.
#define EVT_MYFOO(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( MyFooCommandEvent, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) \
(wxCommandEventFunction) wxStaticCastEvent( \
MyFooEventFunction, &fn ), (wxObject*) NULL ),
// Optionally, you can do a similar #define for EVT_MYFOO_RANGE.
#define EVT_MYFOO_RANGE(id1,id2, fn) \
DECLARE_EVENT_TABLE_ENTRY( MyFooCommandEvent, id1, id2, \
MyFooEventHandler(fn), (wxObject*) NULL ),
I plan on handling the events by using the Connect() function. Also, I am uncertain what code needs to appear in the constructor and destructor methods (I did not include the CPP file because the constructor and destructor methods are empty...).
Can anyone help me out with the this so that I can have it function properly? Thanks in advance!
-Tony