Mauro Ziliani
2014-03-11 22:35:11 UTC
Hi all.
My question is about PushEventHandler.
I need to add the same event handler to many wxWindow objects.
So I think of define a wxEvtHandler derived class, and push it into
wxWindows I need it.
Example:
class MyEventHandler : public wxEvtHandler
{
public:
MyEventHandler(wxWindow *container)
{
m_container = container;
Bind(wxEVT_MY_EVENT, &MyEventHandler::on_ioEvent, this);
}
~MyEventHandler(wxWindow *container)
{
Unbind(wxEVT_MY_EVENT, &MyEventHandler::on_ioEvent, this);
}
protected:
void on_ioEvent(wxNotifyEvent& event)
{
wxWindowList& children = m_container->GetChildren();
wxWindowList::iterator child;
for (child=children.begin(); child!=children.end())
{
wxStaticText *st = wxDynamicCast( *child, wxStaticText );
if (st)
st->SetLabelText(event.GetString());
}
}
};
class Display : public wxPanel
{
public:
Display(wxWindow *parent): wxPanel(parent, -1)
{
PushEventHandler( new MyEventHandler(this) );
}
~Display
{
PopEventHandler(true);
}
};
Inside a timer event I send the wxNotifyEvent to the display object
class MainFrame : public wxFrame
{
public:
MainFrame() : wxFrame(NULL, -1, "Test IO"), m_timer(this, 1)
{
m_display = new Display(this);
Bind(wxEVT_TIMER, &MainFrame::on_timerEvent, this);
m_timer.Start(1000);
}
~MainFrame()
{
Unbind(wxEVT_TIMER, &MainFrame::on_timerEvent, this);
}
private:
wxTimer m_timer;
Display *m_display;
void on_timereEvent(wxTimerEvent& event)
{
wxNotifyEvent evt_io_values(wxEVT_MY_EVENT);
evt_io_value.SetString("test");
wxQueueEvent(m_display, evt_io_values.Clone());
}
};
The matter is: the pushed event handlder is not executed.
Where is the mistake?
Mauro
My question is about PushEventHandler.
I need to add the same event handler to many wxWindow objects.
So I think of define a wxEvtHandler derived class, and push it into
wxWindows I need it.
Example:
class MyEventHandler : public wxEvtHandler
{
public:
MyEventHandler(wxWindow *container)
{
m_container = container;
Bind(wxEVT_MY_EVENT, &MyEventHandler::on_ioEvent, this);
}
~MyEventHandler(wxWindow *container)
{
Unbind(wxEVT_MY_EVENT, &MyEventHandler::on_ioEvent, this);
}
protected:
void on_ioEvent(wxNotifyEvent& event)
{
wxWindowList& children = m_container->GetChildren();
wxWindowList::iterator child;
for (child=children.begin(); child!=children.end())
{
wxStaticText *st = wxDynamicCast( *child, wxStaticText );
if (st)
st->SetLabelText(event.GetString());
}
}
};
class Display : public wxPanel
{
public:
Display(wxWindow *parent): wxPanel(parent, -1)
{
PushEventHandler( new MyEventHandler(this) );
}
~Display
{
PopEventHandler(true);
}
};
Inside a timer event I send the wxNotifyEvent to the display object
class MainFrame : public wxFrame
{
public:
MainFrame() : wxFrame(NULL, -1, "Test IO"), m_timer(this, 1)
{
m_display = new Display(this);
Bind(wxEVT_TIMER, &MainFrame::on_timerEvent, this);
m_timer.Start(1000);
}
~MainFrame()
{
Unbind(wxEVT_TIMER, &MainFrame::on_timerEvent, this);
}
private:
wxTimer m_timer;
Display *m_display;
void on_timereEvent(wxTimerEvent& event)
{
wxNotifyEvent evt_io_values(wxEVT_MY_EVENT);
evt_io_value.SetString("test");
wxQueueEvent(m_display, evt_io_values.Clone());
}
};
The matter is: the pushed event handlder is not executed.
Where is the mistake?
Mauro
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users