wxEvtHandler::Connect problems and question
Posted: Sun Mar 04, 2012 8:28 pm
Greetings.
Using wxEvtHandler::Conect() im binding certain event to a function processing that event.
Now, as I understand, this function can be a method from any class, since I can create functor using wxObjectEventFunction().
Yet, when I call function from class derived from wxEvtHandler - I can keep my access to member's of this class [ eventSink* aint this ].
My question is - is there any way to call method from a class not derived from wxEvtHandler ( 60 additional bytes are a lot in my case ) [and not being a fuctor, since I lost access to class members] ?
Also - what's the actual difference between wxCommandEventHandler() and wxObjectEventFunction() used in function argument of Connect() ?
I can use first only with connecting to functions from class I currently call Connect().
Simple code presenting my problem:
Thanks in advance for your answers
Best regards.
Using wxEvtHandler::Conect() im binding certain event to a function processing that event.
Now, as I understand, this function can be a method from any class, since I can create functor using wxObjectEventFunction().
Yet, when I call function from class derived from wxEvtHandler - I can keep my access to member's of this class [ eventSink* aint this ].
My question is - is there any way to call method from a class not derived from wxEvtHandler ( 60 additional bytes are a lot in my case ) [and not being a fuctor, since I lost access to class members] ?
Also - what's the actual difference between wxCommandEventHandler() and wxObjectEventFunction() used in function argument of Connect() ?
I can use first only with connecting to functions from class I currently call Connect().
Simple code presenting my problem:
Code: Select all
/**
W jaki sposób NIE używając STATIC i NIE dziedzicząc z exEvtHandler wywołać funkcję onEvent z odpowiedniej klasy ?
**/
#include <wx/wx.h>
class some_class {
private:
int x;
public:
void onClickRight(wxCommandEvent &evt) {
wxString str;
str << x;
wxMessageBox(str);
}
some_class() :
x(15)
{}
} o_some_class ;
class some_class_derived : public wxEvtHandler {
private:
int x;
public:
void onClickLeft(wxCommandEvent &evt) {
wxString str;
str << x;
wxMessageBox(str);
}
some_class_derived() :
x(15)
{}
} o_some_class_derived ;
class my_frame : public wxFrame {
public:
void onClickMiddle(wxCommandEvent &evt) {
wxMessageBox(L"wxCommandEvent vs wxObjectEventFunction");
}
my_frame() : wxFrame(NULL, wxID_ANY, L"Title")
{
Centre();
Connect(wxEVT_RIGHT_DOWN, wxObjectEventFunction(&some_class::onClickRight) /*, NULL, &o_some_class*/); // Can't do that, some_class aint derived from EvtHandler
Connect(wxEVT_LEFT_DOWN, wxObjectEventFunction(&some_class_derived::onClickLeft), NULL, &o_some_class_derived);
Connect(wxEVT_MIDDLE_DOWN, wxCommandEventHandler(my_frame::onClickMiddle));
}
};
class app : public wxApp {
virtual bool OnInit() {
my_frame* f = new my_frame();
f->Show();
return true;
}
};
IMPLEMENT_APP(app);
Best regards.