#include <wx/wx.h>
class MyApp: public wxApp
{
public:
virtual bool OnInit();
protected:
void OnSetFocus(wxCommandEvent& event);
};
class MyFrame : public wxFrame {
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) :
wxFrame(NULL, wxID_ANY, title, pos, size) {}
void OnSetFocus(wxFocusEvent& event);
void OnKillFocus(wxFocusEvent& event);
};
void MyFrame::OnSetFocus(wxFocusEvent& event) {
wxWindow *w = (wxWindow*) event.GetEventObject();
wxMessageOutputDebug().Printf("Focus received: %s", w->GetName());
}
void MyFrame::OnKillFocus(wxFocusEvent& event) {
wxWindow *w = (wxWindow*) event.GetEventObject();
wxMessageOutputDebug().Printf("Focus lost: %s", w->GetName());
}
bool MyApp::OnInit() {
MyFrame *frame = new MyFrame("Test", wxPoint(50, 50), wxSize(450, 340));
wxPanel *panel = new wxPanel(frame, -1);
wxChoice *choice = new wxChoice(panel, -1, wxPoint(-1, -1));
choice->Append("One");
choice->Append("Two");
choice->SetName("wxChoice");
choice->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
choice->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);
wxTextCtrl *field = new wxTextCtrl(panel, -1, "", wxPoint(-1, -1));
field->SetName("wxTextCtrl");
field->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
field->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);
wxButton *button = new wxButton(panel, -1, "Ok", wxPoint(-1, -1));
button->SetName("wxButton");
button->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
button->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(choice, 0, wxALL, 5);
sizer->Add(field, 0, wxALL, 5);
sizer->Add(button, 0, wxALL, 5);
panel->SetSizer(sizer);
frame->Show(true);
return true;
}
IMPLEMENT_APP(MyApp);