diff --git a/docs/doxygen/mainpages/samples.h b/docs/doxygen/mainpages/samples.h index 352e175f33..db03c9942f 100644 --- a/docs/doxygen/mainpages/samples.h +++ b/docs/doxygen/mainpages/samples.h @@ -274,7 +274,7 @@ wxDataObject to achieve this. This sample demonstrates various features of the wxWidgets events. It shows how to dynamic events and connecting/disconnecting the event handlers -during run time by using wxEvtHandler::Connect() and wxEvtHandler::Disconnect(), +during run time by using wxEvtHandler::Bind() and wxEvtHandler::Unbind(), and also how to use wxWindow::PushEventHandler() and wxWindow::PopEventHandler(). @sampledir{event} diff --git a/samples/calendar/calendar.cpp b/samples/calendar/calendar.cpp index ab523405ad..29cabc3488 100644 --- a/samples/calendar/calendar.cpp +++ b/samples/calendar/calendar.cpp @@ -809,10 +809,9 @@ wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style) wxDefaultSize, style); - calendar->Connect(wxEVT_RIGHT_DOWN, - wxMouseEventHandler(MyFrame::OnCalRClick), - NULL, - ( MyFrame * )wxGetTopLevelParent(this)); + calendar->Bind(wxEVT_RIGHT_DOWN, + &MyFrame::OnCalRClick, + ( MyFrame * )wxGetTopLevelParent(this)); return calendar; } diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 1393a86fee..26fbc1dde6 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -622,9 +622,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l m_ctrl[0] = new wxDataViewCtrl( parent, ID_MUSIC_CTRL, wxDefaultPosition, wxDefaultSize, style ); - m_ctrl[0]->Connect(wxEVT_CHAR, - wxKeyEventHandler(MyFrame::OnDataViewChar), - NULL, this); + m_ctrl[0]->Bind(wxEVT_CHAR, &MyFrame::OnDataViewChar, this); m_music_model = new MyMusicTreeModel; m_ctrl[0]->AssociateModel( m_music_model.get() ); diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index c0ea4641a3..9de1fa2ab5 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -676,10 +676,8 @@ MyFrame::MyFrame(const wxString& title) m_infoBarAdvanced->AddButton(wxID_UNDO); m_infoBarAdvanced->AddButton(wxID_REDO); - m_infoBarAdvanced->Connect(wxID_REDO, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnInfoBarRedo), - NULL, - this); + m_infoBarAdvanced->Bind(wxEVT_BUTTON, &MyFrame::OnInfoBarRedo, this, + wxID_REDO); // adding and removing a button immediately doesn't make sense here, of // course, it's done just to show that it is possible @@ -723,8 +721,8 @@ MyFrame::MyFrame(const wxString& title) static const int DIALOGS_SYSTEM_ABOUT = 0x4010; menu->Append(DIALOGS_SYSTEM_ABOUT, "&About"); - Connect(DIALOGS_SYSTEM_ABOUT, wxEVT_MENU, - wxCommandEventHandler(MyFrame::ShowSimpleAboutDialog)); + Bind(wxEVT_MENU, &MyFrame::ShowSimpleAboutDialog, this, + DIALOGS_SYSTEM_ABOUT); } #endif // __WXMSW__ } @@ -966,7 +964,8 @@ void MyFrame::MessageBoxWindowModal(wxCommandEvent& WXUNUSED(event)) "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used."; } dialog->SetExtendedMessage(extmsg); - dialog->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed), NULL, this ); + dialog->Bind(wxEVT_WINDOW_MODAL_DIALOG_CLOSED, + &MyFrame::MessageBoxWindowModalClosed, this); dialog->ShowWindowModal(); } @@ -1513,12 +1512,9 @@ MyExtraPanel::MyExtraPanel(wxWindow *parent) m_btn = new wxButton(this, -1, wxT("Custom Button")); m_btn->Enable(false); m_cb = new wxCheckBox(this, -1, wxT("Enable Custom Button")); - m_cb->Connect(wxEVT_CHECKBOX, - wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this); + m_cb->Bind(wxEVT_CHECKBOX, &MyExtraPanel::OnCheckBox, this); m_label = new wxStaticText(this, wxID_ANY, "Nothing selected"); - m_label->Connect(wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(MyExtraPanel::OnUpdateLabelUI), - NULL, this); + m_label->Bind(wxEVT_UPDATE_UI, &MyExtraPanel::OnUpdateLabelUI, this); m_text = new wxTextCtrl(this, -1, m_str, wxDefaultPosition, wxSize(40*GetCharWidth(), -1)); @@ -2416,21 +2412,8 @@ public: // And connect the event handlers. - btnShowText->Connect - ( - wxEVT_BUTTON, - wxCommandEventHandler(RichTipDialog::OnShowTipForText), - NULL, - this - ); - - btnShowBtn->Connect - ( - wxEVT_BUTTON, - wxCommandEventHandler(RichTipDialog::OnShowTipForBtn), - NULL, - this - ); + btnShowText->Bind(wxEVT_BUTTON, &RichTipDialog::OnShowTipForText, this); + btnShowBtn->Bind(wxEVT_BUTTON, &RichTipDialog::OnShowTipForBtn, this); } private: @@ -3624,11 +3607,8 @@ bool TestMessageBoxDialog::Create() m_labels[n] = new wxTextCtrl(this, wxID_ANY); sizerBtns->Add(m_labels[n], wxSizerFlags().Expand()); - m_labels[n]->Connect(wxEVT_UPDATE_UI, - wxUpdateUIEventHandler( - TestMessageBoxDialog::OnUpdateLabelUI), - NULL, - this); + m_labels[n]->Bind(wxEVT_UPDATE_UI, + &TestMessageBoxDialog::OnUpdateLabelUI, this); } sizerBtnsBox->Add(sizerBtns, wxSizerFlags().Expand()); @@ -3663,11 +3643,8 @@ bool TestMessageBoxDialog::Create() sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags"); m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default"); - m_chkNoDefault->Connect(wxEVT_UPDATE_UI, - wxUpdateUIEventHandler( - TestMessageBoxDialog::OnUpdateNoDefaultUI), - NULL, - this); + m_chkNoDefault->Bind(wxEVT_UPDATE_UI, + &TestMessageBoxDialog::OnUpdateNoDefaultUI, this); sizerFlags->Add(m_chkNoDefault, wxSizerFlags().Border()); m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent"); diff --git a/samples/dll/my_dll.cpp b/samples/dll/my_dll.cpp index ba269bc36d..1038acb969 100644 --- a/samples/dll/my_dll.cpp +++ b/samples/dll/my_dll.cpp @@ -147,12 +147,8 @@ MyDllApp::MyDllApp() // by shutting the thread down when it's no longer needed, though. SetExitOnFrameDelete(false); - Connect(CMD_SHOW_WINDOW, - wxEVT_THREAD, - wxThreadEventHandler(MyDllApp::OnShowWindow)); - Connect(CMD_TERMINATE, - wxEVT_THREAD, - wxThreadEventHandler(MyDllApp::OnTerminate)); + Bind(wxEVT_THREAD, &MyDllApp::OnShowWindow, this, CMD_SHOW_WINDOW); + Bind(wxEVT_THREAD, &MyDllApp::OnTerminate, this, CMD_TERMINATE); } void MyDllApp::OnShowWindow(wxThreadEvent& event) diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 58d0e23224..2f99e5c622 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -1018,14 +1018,7 @@ DnDFrame::DnDFrame() m_ctrlText->SetDropTarget(new DnDText(m_ctrlText)); #if wxUSE_DRAG_AND_DROP - m_ctrlDir->Connect - ( - wxID_ANY, - wxEVT_TREE_BEGIN_DRAG, - wxTreeEventHandler(DnDFrame::OnBeginDrag), - NULL, - this - ); + m_ctrlDir->Bind(wxEVT_TREE_BEGIN_DRAG, &DnDFrame::OnBeginDrag, this); #endif // wxUSE_DRAG_AND_DROP #if wxUSE_LOG diff --git a/samples/docview/doc.cpp b/samples/docview/doc.cpp index 4d75fa5c5e..50ab0ba337 100644 --- a/samples/docview/doc.cpp +++ b/samples/docview/doc.cpp @@ -193,13 +193,7 @@ bool wxTextDocument::OnCreate(const wxString& path, long flags) // subscribe to changes in the text control to update the document state // when it's modified - GetTextCtrl()->Connect - ( - wxEVT_TEXT, - wxCommandEventHandler(wxTextDocument::OnTextChange), - NULL, - this - ); + GetTextCtrl()->Bind(wxEVT_TEXT, &wxTextDocument::OnTextChange, this); return true; } diff --git a/samples/erase/erase.cpp b/samples/erase/erase.cpp index 71b54e1b79..5336bfe155 100644 --- a/samples/erase/erase.cpp +++ b/samples/erase/erase.cpp @@ -159,8 +159,7 @@ public: } Create (parent, wxID_ANY, pos, size, wxBORDER_NONE); - Connect(wxEVT_PAINT, - wxPaintEventHandler(ControlWithTransparency::OnPaint)); + Bind(wxEVT_PAINT, &ControlWithTransparency::OnPaint, this); if ( !reason.empty() ) { diff --git a/samples/event/event.cpp b/samples/event/event.cpp index 8cc96efd18..2963860050 100644 --- a/samples/event/event.cpp +++ b/samples/event/event.cpp @@ -92,8 +92,7 @@ public: : wxButton(parent, BUTTON_ID, label) { // Add a dynamic handler for this button event to button itself - Connect(wxEVT_BUTTON, - wxCommandEventHandler(MyEvtTestButton::OnClickDynamicHandler)); + Bind(wxEVT_BUTTON, &MyEvtTestButton::OnClickDynamicHandler, this); } private: @@ -307,8 +306,8 @@ bool MyApp::OnInit() frame->Show(true); // Add a dynamic handler at the application level for the test button - Connect(MyEvtTestButton::BUTTON_ID, wxEVT_BUTTON, - wxCommandEventHandler(MyApp::OnClickDynamicHandlerApp)); + Bind(wxEVT_BUTTON, &MyApp::OnClickDynamicHandlerApp, this, + MyEvtTestButton::BUTTON_ID); // success: wxApp::OnRun() will be called which will enter the main message // loop and the application will run. If we returned false here, the @@ -427,15 +426,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) // event handlers (see class definition); // Add a dynamic handler for this button event in the parent frame - Connect(m_testBtn->GetId(), wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnClickDynamicHandlerFrame)); + Bind(wxEVT_BUTTON, &MyFrame::OnClickDynamicHandlerFrame, this, + m_testBtn->GetId()); // Bind a method of this frame (notice "this" argument!) to the button // itself - m_testBtn->Connect(wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnClickDynamicHandlerButton), - NULL, - this); + m_testBtn->Bind(wxEVT_BUTTON, &MyFrame::OnClickDynamicHandlerButton, this); mainSizer->Add(m_testBtn); panel->SetSizer(mainSizer); @@ -545,19 +541,13 @@ void MyFrame::OnConnect(wxCommandEvent& event) { if ( event.IsChecked() ) { - m_btnDynamic->Connect(wxID_ANY, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnDynamic), - NULL, this); - Connect(Event_Dynamic, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnDynamic)); + m_btnDynamic->Bind(wxEVT_BUTTON, &MyFrame::OnDynamic, this); + Bind(wxEVT_MENU, &MyFrame::OnDynamic, this, Event_Dynamic); } else // disconnect { - m_btnDynamic->Disconnect(wxID_ANY, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnDynamic), - NULL, this); - Disconnect(Event_Dynamic, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnDynamic)); + m_btnDynamic->Unbind(wxEVT_BUTTON, &MyFrame::OnDynamic, this); + Unbind(wxEVT_MENU, &MyFrame::OnDynamic, this, Event_Dynamic); } UpdateDynamicStatus(event.IsChecked()); diff --git a/samples/fswatcher/fswatcher.cpp b/samples/fswatcher/fswatcher.cpp index 0c532a85ea..187345f003 100644 --- a/samples/fswatcher/fswatcher.cpp +++ b/samples/fswatcher/fswatcher.cpp @@ -180,8 +180,7 @@ MyFrame::MyFrame(const wxString& title) _("If checked, dereference symlinks") ); it->Check(false); - Connect(MENU_ID_DEREFERENCE, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnFollowLinks)); + Bind(wxEVT_MENU, &MyFrame::OnFollowLinks, this, MENU_ID_DEREFERENCE); #endif // __UNIX__ // the "About" item should be in the help menu @@ -267,28 +266,18 @@ MyFrame::MyFrame(const wxString& title) // event handlers & show // menu - Connect(MENU_ID_CLEAR, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnClear)); - Connect(MENU_ID_QUIT, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnQuit)); - Connect(MENU_ID_WATCH, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnWatch)); - Connect(wxID_ABOUT, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnAbout)); + Bind(wxEVT_MENU, &MyFrame::OnClear, this, MENU_ID_CLEAR); + Bind(wxEVT_MENU, &MyFrame::OnQuit, this, MENU_ID_QUIT); + Bind(wxEVT_MENU, &MyFrame::OnWatch, this, MENU_ID_WATCH); + Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); // buttons - Connect(BTN_ID_ADD, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnAdd)); - Connect(BTN_ID_ADD_TREE, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnAddTree)); - Connect(BTN_ID_REMOVE, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnRemove)); - Connect(BTN_ID_REMOVE, wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(MyFrame::OnRemoveUpdateUI)); - Connect(BTN_ID_REMOVE_ALL, wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnRemoveAll)); - Connect(BTN_ID_REMOVE_ALL, wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(MyFrame::OnRemoveAllUpdateUI)); + Bind(wxEVT_BUTTON, &MyFrame::OnAdd, this, BTN_ID_ADD); + Bind(wxEVT_BUTTON, &MyFrame::OnAddTree, this, BTN_ID_ADD_TREE); + Bind(wxEVT_BUTTON, &MyFrame::OnRemove, this, BTN_ID_REMOVE); + Bind(wxEVT_UPDATE_UI, &MyFrame::OnRemoveUpdateUI, this, BTN_ID_REMOVE); + Bind(wxEVT_BUTTON, &MyFrame::OnRemoveAll, this, BTN_ID_REMOVE_ALL); + Bind(wxEVT_UPDATE_UI, &MyFrame::OnRemoveAllUpdateUI, this, BTN_ID_REMOVE_ALL); // and show itself (the frames, unlike simple controls, are not shown when // created initially) @@ -306,8 +295,7 @@ bool MyFrame::CreateWatcherIfNecessary() return false; CreateWatcher(); - Connect(wxEVT_FSWATCHER, - wxFileSystemWatcherEventHandler(MyFrame::OnFileSystemEvent)); + Bind(wxEVT_FSWATCHER, &MyFrame::OnFileSystemEvent, this); return true; } diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 974959aea7..774efad4b3 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -719,8 +719,7 @@ void GridFrame::SetTabBehaviour(wxCommandEvent& event) { // To make any built-in behaviour work, we need to disable the custom TAB // handler, otherwise it would be overriding them. - grid->Disconnect(wxEVT_GRID_TABBING, - wxGridEventHandler(GridFrame::OnGridCustomTab)); + grid->Unbind(wxEVT_GRID_TABBING, &GridFrame::OnGridCustomTab, this); grid->SetTabBehaviour( static_cast(event.GetId() - ID_TAB_STOP) @@ -729,9 +728,7 @@ void GridFrame::SetTabBehaviour(wxCommandEvent& event) void GridFrame::SetTabCustomHandler(wxCommandEvent&) { - grid->Connect(wxEVT_GRID_TABBING, - wxGridEventHandler(GridFrame::OnGridCustomTab), - NULL, this); + grid->Bind(wxEVT_GRID_TABBING, &GridFrame::OnGridCustomTab, this); } @@ -2349,10 +2346,7 @@ void GridFrame::OnGridRender( wxCommandEvent& event ) m_gridBitmap = bmp; - canvas->Connect( wxEVT_PAINT, - wxPaintEventHandler(GridFrame::OnRenderPaint), - NULL, - this ); + canvas->Bind( wxEVT_PAINT, &GridFrame::OnRenderPaint, this ); frame->Show(); } diff --git a/samples/image/image.cpp b/samples/image/image.cpp index c5cd562c63..d53c506a6a 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -875,7 +875,7 @@ public: m_bitmap = wxBitmap(m_image); - Connect(wxEVT_PAINT, wxPaintEventHandler(MyGraphicsFrame::OnPaint)); + Bind(wxEVT_PAINT, &MyGraphicsFrame::OnPaint, this); Show(); } diff --git a/samples/ipc/baseclient.cpp b/samples/ipc/baseclient.cpp index b128e032b8..a3f139987e 100644 --- a/samples/ipc/baseclient.cpp +++ b/samples/ipc/baseclient.cpp @@ -47,7 +47,7 @@ class MyClient; class MyApp : public wxApp { public: - MyApp() { Connect(wxEVT_IDLE, wxIdleEventHandler(MyApp::OnIdle)); } + MyApp() { Bind(wxEVT_IDLE, &MyApp::OnIdle, this); } virtual bool OnInit() wxOVERRIDE; virtual int OnExit() wxOVERRIDE; diff --git a/samples/keyboard/keyboard.cpp b/samples/keyboard/keyboard.cpp index 5c0417f6ec..800bac943c 100644 --- a/samples/keyboard/keyboard.cpp +++ b/samples/keyboard/keyboard.cpp @@ -224,35 +224,19 @@ MyFrame::MyFrame(const wxString& title) // connect menu event handlers - Connect(QuitID, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnQuit)); - - Connect(wxID_ABOUT, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnAbout)); - - Connect(ClearID, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnClear)); - - Connect(SkipHook, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnSkipHook)); - Connect(SkipDown, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnSkipDown)); - - Connect(IDInputCustom, IDInputText, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnInputWindowKind)); - - Connect(TestAccelA, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnTestAccelA)); - - Connect(TestAccelCtrlA, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnTestAccelCtrlA)); - - Connect(TestAccelEsc, wxEVT_MENU, - wxCommandEventHandler(MyFrame::OnTestAccelEsc)); + Bind(wxEVT_MENU, &MyFrame::OnQuit, this, QuitID); + Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); + Bind(wxEVT_MENU, &MyFrame::OnClear, this, ClearID); + Bind(wxEVT_MENU, &MyFrame::OnSkipHook, this, SkipHook); + Bind(wxEVT_MENU, &MyFrame::OnSkipDown, this, SkipDown); + Bind(wxEVT_MENU, &MyFrame::OnInputWindowKind, this, IDInputCustom, IDInputText); + Bind(wxEVT_MENU, &MyFrame::OnTestAccelA, this, TestAccelA); + Bind(wxEVT_MENU, &MyFrame::OnTestAccelCtrlA, this, TestAccelCtrlA); + Bind(wxEVT_MENU, &MyFrame::OnTestAccelEsc, this, TestAccelEsc); // notice that we don't connect OnCharHook() to the input window, unlike // the usual key events this one is propagated upwards - Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(MyFrame::OnCharHook)); + Bind(wxEVT_CHAR_HOOK, &MyFrame::OnCharHook, this); // status bar is useful for showing the menu items help strings CreateStatusBar(); @@ -300,18 +284,13 @@ void MyFrame::DoCreateInputWindow(InputKind inputKind) m_inputWin->SetForegroundColour(*wxWHITE); // connect event handlers for the blue input window - m_inputWin->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyFrame::OnKeyDown), - NULL, this); - m_inputWin->Connect(wxEVT_KEY_UP, wxKeyEventHandler(MyFrame::OnKeyUp), - NULL, this); - m_inputWin->Connect(wxEVT_CHAR, wxKeyEventHandler(MyFrame::OnChar), - NULL, this); + m_inputWin->Bind(wxEVT_KEY_DOWN, &MyFrame::OnKeyDown, this); + m_inputWin->Bind(wxEVT_KEY_UP, &MyFrame::OnKeyUp, this); + m_inputWin->Bind(wxEVT_CHAR, &MyFrame::OnChar, this); if ( inputKind == Input_Custom ) { - m_inputWin->Connect(wxEVT_PAINT, - wxPaintEventHandler(MyFrame::OnPaintInputWin), - NULL, this); + m_inputWin->Bind(wxEVT_PAINT, &MyFrame::OnPaintInputWin, this); } if ( oldWin ) diff --git a/samples/layout/layout.cpp b/samples/layout/layout.cpp index 35c08aed54..e33c6a98cd 100644 --- a/samples/layout/layout.cpp +++ b/samples/layout/layout.cpp @@ -270,10 +270,8 @@ MyProportionsFrame::MyProportionsFrame(wxFrame *parent) SetSizerAndFit(sizerTop); // and connect the events - Connect(wxEVT_TEXT, - wxCommandEventHandler(MyProportionsFrame::OnProportionUpdated)); - Connect(wxEVT_SPINCTRL, - wxSpinEventHandler(MyProportionsFrame::OnProportionChanged)); + Bind(wxEVT_TEXT, &MyProportionsFrame::OnProportionUpdated, this); + Bind(wxEVT_SPINCTRL, &MyProportionsFrame::OnProportionChanged, this); } void MyProportionsFrame::UpdateProportions() diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index 657ac0b338..cdafb201ab 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -220,14 +220,14 @@ MyFrame::MyFrame() #endif // wxUSE_ACCEL // connect it only now, after creating m_textWindow - Connect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize)); + Bind(wxEVT_SIZE, &MyFrame::OnSize, this); } MyFrame::~MyFrame() { // and disconnect it to prevent accessing already deleted m_textWindow in // the size event handler if it's called during destruction - Disconnect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize)); + Unbind(wxEVT_SIZE, &MyFrame::OnSize, this); // also prevent its use as log target delete wxLog::SetActiveTarget(NULL); diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp index 1708dbb78e..8ffb27b767 100644 --- a/samples/mediaplayer/mediaplayer.cpp +++ b/samples/mediaplayer/mediaplayer.cpp @@ -579,129 +579,48 @@ wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title) // // Connect events. // - // There are two ways in wxWidgets to use events - - // Message Maps and Connections. - // - // Message Maps are implemented by putting - // DECLARE_MESSAGE_MAP in your wxEvtHandler-derived - // class you want to use for events, such as wxMediaPlayerFrame. - // - // Then after your class declaration you put - // wxBEGIN_EVENT_TABLE(wxMediaPlayerFrame, wxFrame) - // EVT_XXX(XXX)... - // wxEND_EVENT_TABLE() - // - // Where wxMediaPlayerFrame is the class with the DECLARE_MESSAGE_MAP - // in it. EVT_XXX(XXX) are each of your handlers, such - // as EVT_MENU for menu events and the XXX inside - // is the parameters to the event macro - in the case - // of EVT_MENU the menu id and then the function to call. - // - // However, with wxEvtHandler::Connect you can avoid a - // global message map for your class and those annoying - // macros. You can also change the context in which - // the call the handler (more later). - // - // The downside is that due to the limitation that - // wxWidgets doesn't use templates in certain areas, - // You have to triple-cast the event function. - // - // There are five parameters to wxEvtHandler::Connect - - // - // The first is the id of the instance whose events - // you want to handle - i.e. a menu id for menus, - // a control id for controls (wxControl::GetId()) - // and so on. - // - // The second is the event id. This is the same - // as the message maps (EVT_MENU) except prefixed - // with "wx" (wxEVT_MENU). - // - // The third is the function handler for the event - - // You need to cast it to the specific event handler - // type, then to a wxEventFunction, then to a - // wxObjectEventFunction - I.E. - // (wxObjectEventFunction)(wxEventFunction) - // (wxCommandEventFunction) &wxMediaPlayerFrame::MyHandler - // - // Or, you can use the new (2.5.5+) event handler - // conversion macros - for instance the above could - // be done as - // wxCommandEventHandler(wxMediaPlayerFrame::MyHandler) - // pretty simple, eh? - // - // The fourth is an optional userdata param - - // this is of historical relevance only and is - // there only for backwards compatibility. - // - // The fifth is the context in which to call the - // handler - by default (this param is optional) - // this. For example in your event handler - // if you were to call "this->MyFunc()" - // it would literally do this->MyFunc. However, - // if you were to pass myHandler as the fifth - // parameter, for instance, you would _really_ - // be calling myHandler->MyFunc, even though - // the compiler doesn't really know it. - // // // Menu events // - this->Connect(wxID_EXIT, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnQuit)); - - this->Connect(wxID_ABOUT, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnAbout)); - - this->Connect(wxID_LOOP, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnLoop)); - - this->Connect(wxID_SHOWINTERFACE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnShowInterface)); - - this->Connect(wxID_OPENFILENEWPAGE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileNewPage)); - - this->Connect(wxID_OPENFILESAMEPAGE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnOpenFileSamePage)); - - this->Connect(wxID_OPENURLNEWPAGE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLNewPage)); - - this->Connect(wxID_OPENURLSAMEPAGE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnOpenURLSamePage)); - - this->Connect(wxID_CLOSECURRENTPAGE, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnCloseCurrentPage)); - - this->Connect(wxID_PLAY, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnPlay)); - - this->Connect(wxID_STOP, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnStop)); - - this->Connect(wxID_NEXT, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnNext)); - - this->Connect(wxID_PREV, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnPrev)); - - this->Connect(wxID_SELECTBACKEND, wxEVT_MENU, - wxCommandEventHandler(wxMediaPlayerFrame::OnSelectBackend)); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnQuit, this, + wxID_EXIT); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnAbout, this, + wxID_ABOUT); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnLoop, this, + wxID_LOOP); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnShowInterface, this, + wxID_SHOWINTERFACE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnOpenFileNewPage, this, + wxID_OPENFILENEWPAGE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnOpenFileSamePage, this, + wxID_OPENFILESAMEPAGE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnOpenURLNewPage, this, + wxID_OPENURLNEWPAGE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnOpenURLSamePage, this, + wxID_OPENURLSAMEPAGE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnCloseCurrentPage, this, + wxID_CLOSECURRENTPAGE); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnPlay, this, + wxID_PLAY); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnStop, this, + wxID_STOP); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnNext, this, + wxID_NEXT); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnPrev, this, + wxID_PREV); + Bind(wxEVT_MENU, &wxMediaPlayerFrame::OnSelectBackend, this, + wxID_SELECTBACKEND); // // Key events // - wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, - wxKeyEventHandler(wxMediaPlayerFrame::OnKeyDown), - (wxObject*)0, this); + wxTheApp->Bind(wxEVT_KEY_DOWN, &wxMediaPlayerFrame::OnKeyDown, this); // // Close events // - this->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, - wxCloseEventHandler(wxMediaPlayerFrame::OnClose)); + Bind(wxEVT_CLOSE_WINDOW, &wxMediaPlayerFrame::OnClose, this); // // End of Events @@ -1710,58 +1629,50 @@ wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentF // // ListCtrl events // - this->Connect( wxID_LISTCTRL, wxEVT_LIST_ITEM_ACTIVATED, - wxListEventHandler(wxMediaPlayerFrame::OnChangeSong), - (wxObject*)0, parentFrame); + Bind(wxEVT_LIST_ITEM_ACTIVATED, &wxMediaPlayerFrame::OnChangeSong, parentFrame, + wxID_LISTCTRL); // // Slider events // - this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBTRACK, - wxScrollEventHandler(wxMediaPlayerNotebookPage::OnBeginSeek)); - this->Connect(wxID_SLIDER, wxEVT_SCROLL_THUMBRELEASE, - wxScrollEventHandler(wxMediaPlayerNotebookPage::OnEndSeek)); - this->Connect(wxID_PBSLIDER, wxEVT_SCROLL_THUMBRELEASE, - wxScrollEventHandler(wxMediaPlayerNotebookPage::OnPBChange)); - this->Connect(wxID_VOLSLIDER, wxEVT_SCROLL_THUMBRELEASE, - wxScrollEventHandler(wxMediaPlayerNotebookPage::OnVolChange)); + Bind(wxEVT_SCROLL_THUMBTRACK, &wxMediaPlayerNotebookPage::OnBeginSeek, this, + wxID_SLIDER); + Bind(wxEVT_SCROLL_THUMBRELEASE, &wxMediaPlayerNotebookPage::OnEndSeek, this, + wxID_SLIDER); + Bind(wxEVT_SCROLL_THUMBRELEASE, &wxMediaPlayerNotebookPage::OnPBChange, this, + wxID_PBSLIDER); + Bind(wxEVT_SCROLL_THUMBRELEASE, &wxMediaPlayerNotebookPage::OnVolChange, this, + wxID_VOLSLIDER); // // Media Control events // - this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PLAY, - wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPlay)); - this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_PAUSE, - wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaPause)); - this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_STOP, - wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaStop)); - this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_FINISHED, - wxMediaEventHandler(wxMediaPlayerNotebookPage::OnMediaFinished)); - this->Connect(wxID_MEDIACTRL, wxEVT_MEDIA_LOADED, - wxMediaEventHandler(wxMediaPlayerFrame::OnMediaLoaded), - (wxObject*)0, parentFrame); + Bind(wxEVT_MEDIA_PLAY, &wxMediaPlayerNotebookPage::OnMediaPlay, this, + wxID_MEDIACTRL); + Bind(wxEVT_MEDIA_PAUSE, &wxMediaPlayerNotebookPage::OnMediaPause, this, + wxID_MEDIACTRL); + Bind(wxEVT_MEDIA_STOP, &wxMediaPlayerNotebookPage::OnMediaStop, this, + wxID_MEDIACTRL); + Bind(wxEVT_MEDIA_FINISHED, &wxMediaPlayerNotebookPage::OnMediaFinished, this, + wxID_MEDIACTRL); + Bind(wxEVT_MEDIA_LOADED, &wxMediaPlayerFrame::OnMediaLoaded, parentFrame, + wxID_MEDIACTRL); // // Button events // - this->Connect( wxID_BUTTONPREV, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnPrev), - (wxObject*)0, parentFrame); - this->Connect( wxID_BUTTONPLAY, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnPlay), - (wxObject*)0, parentFrame); - this->Connect( wxID_BUTTONSTOP, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnStop), - (wxObject*)0, parentFrame); - this->Connect( wxID_BUTTONNEXT, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnNext), - (wxObject*)0, parentFrame); - this->Connect( wxID_BUTTONVD, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeDown), - (wxObject*)0, parentFrame); - this->Connect( wxID_BUTTONVU, wxEVT_BUTTON, - wxCommandEventHandler(wxMediaPlayerFrame::OnVolumeUp), - (wxObject*)0, parentFrame); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnPrev, parentFrame, + wxID_BUTTONPREV); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnPlay, parentFrame, + wxID_BUTTONPLAY); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnStop, parentFrame, + wxID_BUTTONSTOP); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnNext, parentFrame, + wxID_BUTTONNEXT); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnVolumeDown, parentFrame, + wxID_BUTTONVD); + Bind(wxEVT_BUTTON, &wxMediaPlayerFrame::OnVolumeUp, parentFrame, + wxID_BUTTONVU); } // ---------------------------------------------------------------------------- diff --git a/samples/popup/popup.cpp b/samples/popup/popup.cpp index 9e104ecfe5..46df8a2f5c 100644 --- a/samples/popup/popup.cpp +++ b/samples/popup/popup.cpp @@ -116,9 +116,7 @@ SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent, bool scrolled ) // Keep this code to verify if mouse events work, they're required if // you're making a control like a combobox where the items are highlighted // under the cursor, the m_panel is set focus in the Popup() function - m_panel->Connect(wxEVT_MOTION, - wxMouseEventHandler(SimpleTransientPopup::OnMouse), - NULL, this); + m_panel->Bind(wxEVT_MOTION, &SimpleTransientPopup::OnMouse, this); wxStaticText *text = new wxStaticText( m_panel, wxID_ANY, wxT("wxPopupTransientWindow is a\n") diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 2496138fac..4638bac948 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -1969,14 +1969,6 @@ void FormMain::CreateGrid( int style, int extraStyle ) //m_pPropGridManager->SetSplitterLeft(true); //m_pPropGridManager->SetSplitterPosition(137); - /* - // This would setup event handling without event table entries - Connect(m_pPropGridManager->GetId(), wxEVT_PG_SELECTED, - wxPropertyGridEventHandler(FormMain::OnPropertyGridSelect) ); - Connect(m_pPropGridManager->GetId(), wxEVT_PG_CHANGED, - wxPropertyGridEventHandler(FormMain::OnPropertyGridChange) ); - */ - m_topSizer->Add( m_pPropGridManager, wxSizerFlags(1).Expand()); FinalizePanel(wasCreated); diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 3428ab9317..fcea79627f 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -49,7 +49,7 @@ public: SetVirtualSize( WIDTH, HEIGHT ); SetBackgroundColour( *wxWHITE ); - Connect(wxEVT_PAINT, wxPaintEventHandler(MySimpleCanvas::OnPaint)); + Bind(wxEVT_PAINT, &MySimpleCanvas::OnPaint, this); } private: @@ -125,10 +125,8 @@ public: mbar->Append(menuFile, "&File"); SetMenuBar( mbar ); - Connect(wxID_DELETE, wxEVT_MENU, - wxCommandEventHandler(MyCanvasFrame::OnDeleteAll)); - Connect(wxID_NEW, wxEVT_MENU, - wxCommandEventHandler(MyCanvasFrame::OnInsertNew)); + Bind(wxEVT_MENU, &MyCanvasFrame::OnDeleteAll, this, wxID_DELETE); + Bind(wxEVT_MENU, &MyCanvasFrame::OnInsertNew, this, wxID_NEW); Show(); } @@ -197,7 +195,7 @@ public: { m_owner = parent; - Connect(wxEVT_PAINT, wxPaintEventHandler(MySubColLabels::OnPaint)); + Bind(wxEVT_PAINT, &MySubColLabels::OnPaint, this); } private: @@ -232,7 +230,7 @@ public: { m_owner = parent; - Connect(wxEVT_PAINT, wxPaintEventHandler(MySubRowLabels::OnPaint)); + Bind(wxEVT_PAINT, &MySubRowLabels::OnPaint, this); } private: @@ -289,7 +287,7 @@ public: SetBackgroundColour("WHEAT"); - Connect(wxEVT_PAINT, wxPaintEventHandler(MySubCanvas::OnPaint)); + Bind(wxEVT_PAINT, &MySubCanvas::OnPaint, this); } // override the base class function so that when this window is scrolled, @@ -396,7 +394,7 @@ public: SetScrollbars(10, 10, 50, 50); - Connect(wxEVT_SIZE, wxSizeEventHandler(MySubScrolledWindow::OnSize)); + Bind(wxEVT_SIZE, &MySubScrolledWindow::OnSize, this); } protected: @@ -808,8 +806,8 @@ MySizerScrolledWindow::MySizerScrolledWindow(wxWindow *parent) SetSizer( sizer ); - Connect(wxID_RESIZE_FRAME, wxEVT_BUTTON, - wxCommandEventHandler(MySizerScrolledWindow::OnResizeClick)); + Bind(wxEVT_BUTTON, &MySizerScrolledWindow::OnResizeClick, this, + wxID_RESIZE_FRAME); } void MySizerScrolledWindow::OnResizeClick(wxCommandEvent &WXUNUSED(event)) diff --git a/samples/shaped/shaped.cpp b/samples/shaped/shaped.cpp index 3f2087a959..e3d5948040 100644 --- a/samples/shaped/shaped.cpp +++ b/samples/shaped/shaped.cpp @@ -172,7 +172,7 @@ public: ShowWithEffect(m_effect, m_timeout); - Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(EffectFrame::OnClose)); + Bind(wxEVT_CLOSE_WINDOW, &EffectFrame::OnClose, this); } private: diff --git a/samples/taborder/taborder.cpp b/samples/taborder/taborder.cpp index 0efaaa9a1c..17e36b0394 100644 --- a/samples/taborder/taborder.cpp +++ b/samples/taborder/taborder.cpp @@ -134,7 +134,7 @@ public: wxDefaultPosition, wxDefaultSize, flags) { - Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyTabTextCtrl::OnKeyDown)); + Bind(wxEVT_KEY_DOWN, &MyTabTextCtrl::OnKeyDown, this); } private: diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 856169e195..1dd4b68487 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -474,140 +474,80 @@ WebFrame::WebFrame(const wxString& url) : // Connect the toolbar events - Connect(m_toolbar_back->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnBack), NULL, this ); - Connect(m_toolbar_forward->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnForward), NULL, this ); - Connect(m_toolbar_stop->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnStop), NULL, this ); - Connect(m_toolbar_reload->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnReload),NULL, this ); - Connect(m_toolbar_tools->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnToolsClicked), NULL, this ); + Bind(wxEVT_TOOL, &WebFrame::OnBack, this, m_toolbar_back->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnForward, this, m_toolbar_forward->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnStop, this, m_toolbar_stop->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnReload, this, m_toolbar_reload->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnToolsClicked, this, m_toolbar_tools->GetId()); - Connect(m_url->GetId(), wxEVT_TEXT_ENTER, - wxCommandEventHandler(WebFrame::OnUrl), NULL, this ); + Bind(wxEVT_TEXT_ENTER, &WebFrame::OnUrl, this, m_url->GetId()); // Connect find toolbar events. - Connect(m_find_toolbar_done->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnFindDone), NULL, this ); - Connect(m_find_toolbar_next->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnFindText), NULL, this ); - Connect(m_find_toolbar_previous->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnFindText), NULL, this ); + Bind(wxEVT_TOOL, &WebFrame::OnFindDone, this, m_find_toolbar_done->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnFindText, this, m_find_toolbar_next->GetId()); + Bind(wxEVT_TOOL, &WebFrame::OnFindText, this, m_find_toolbar_previous->GetId()); // Connect find control events. - Connect(m_find_ctrl->GetId(), wxEVT_TEXT, - wxCommandEventHandler(WebFrame::OnFindText), NULL, this ); - Connect(m_find_ctrl->GetId(), wxEVT_TEXT_ENTER, - wxCommandEventHandler(WebFrame::OnFindText), NULL, this ); + Bind(wxEVT_TEXT, &WebFrame::OnFindText, this, m_find_ctrl->GetId()); + Bind(wxEVT_TEXT_ENTER, &WebFrame::OnFindText, this, m_find_ctrl->GetId()); // Connect the webview events - Connect(m_browser->GetId(), wxEVT_WEBVIEW_NAVIGATING, - wxWebViewEventHandler(WebFrame::OnNavigationRequest), NULL, this); - Connect(m_browser->GetId(), wxEVT_WEBVIEW_NAVIGATED, - wxWebViewEventHandler(WebFrame::OnNavigationComplete), NULL, this); - Connect(m_browser->GetId(), wxEVT_WEBVIEW_LOADED, - wxWebViewEventHandler(WebFrame::OnDocumentLoaded), NULL, this); - Connect(m_browser->GetId(), wxEVT_WEBVIEW_ERROR, - wxWebViewEventHandler(WebFrame::OnError), NULL, this); - Connect(m_browser->GetId(), wxEVT_WEBVIEW_NEWWINDOW, - wxWebViewEventHandler(WebFrame::OnNewWindow), NULL, this); - Connect(m_browser->GetId(), wxEVT_WEBVIEW_TITLE_CHANGED, - wxWebViewEventHandler(WebFrame::OnTitleChanged), NULL, this); + Bind(wxEVT_WEBVIEW_NAVIGATING, &WebFrame::OnNavigationRequest, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_NAVIGATED, &WebFrame::OnNavigationComplete, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_LOADED, &WebFrame::OnDocumentLoaded, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_ERROR, &WebFrame::OnError, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_NEWWINDOW, &WebFrame::OnNewWindow, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_TITLE_CHANGED, &WebFrame::OnTitleChanged, this, m_browser->GetId()); // Connect the menu events - Connect(setPage->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetPage), NULL, this ); - Connect(viewSource->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnViewSourceRequest), NULL, this ); - Connect(viewText->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnViewTextRequest), NULL, this ); - Connect(print->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnPrint), NULL, this ); - Connect(m_tools_layout->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnZoomLayout), NULL, this ); - Connect(m_tools_tiny->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); - Connect(m_tools_small->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); - Connect(m_tools_medium->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); - Connect(m_tools_large->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); - Connect(m_tools_largest->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); - Connect(clearhist->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this ); - Connect(m_tools_enable_history->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this ); - Connect(m_edit_cut->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnCut), NULL, this ); - Connect(m_edit_copy->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnCopy), NULL, this ); - Connect(m_edit_paste->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnPaste), NULL, this ); - Connect(m_edit_undo->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnUndo), NULL, this ); - Connect(m_edit_redo->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRedo), NULL, this ); - Connect(m_edit_mode->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnMode), NULL, this ); - Connect(m_scroll_line_up->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnScrollLineUp), NULL, this ); - Connect(m_scroll_line_down->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnScrollLineDown), NULL, this ); - Connect(m_scroll_page_up->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnScrollPageUp), NULL, this ); - Connect(m_scroll_page_down->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnScrollPageDown), NULL, this ); - Connect(m_script_string->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptString), NULL, this ); - Connect(m_script_integer->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptInteger), NULL, this ); - Connect(m_script_double->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptDouble), NULL, this ); - Connect(m_script_bool->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptBool), NULL, this ); - Connect(m_script_object->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptObject), NULL, this ); - Connect(m_script_array->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptArray), NULL, this ); - Connect(m_script_dom->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptDOM), NULL, this ); - Connect(m_script_undefined->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptUndefined), NULL, this ); - Connect(m_script_null->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptNull), NULL, this ); - Connect(m_script_date->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptDate), NULL, this ); + Bind(wxEVT_MENU, &WebFrame::OnSetPage, this, setPage->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnViewSourceRequest, this, viewSource->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnViewTextRequest, this, viewText->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnPrint, this, print->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnZoomLayout, this, m_tools_layout->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSetZoom, this, m_tools_tiny->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSetZoom, this, m_tools_small->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSetZoom, this, m_tools_medium->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSetZoom, this, m_tools_large->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSetZoom, this, m_tools_largest->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnClearHistory, this, clearhist->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnEnableHistory, this, m_tools_enable_history->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnCut, this, m_edit_cut->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnCopy, this, m_edit_copy->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnPaste, this, m_edit_paste->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnUndo, this, m_edit_undo->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRedo, this, m_edit_redo->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnMode, this, m_edit_mode->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnScrollLineUp, this, m_scroll_line_up->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnScrollLineDown, this, m_scroll_line_down->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnScrollPageUp, this, m_scroll_page_up->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnScrollPageDown, this, m_scroll_page_down->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptString, this, m_script_string->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptInteger, this, m_script_integer->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptDouble, this, m_script_double->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptBool, this, m_script_bool->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptObject, this, m_script_object->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptArray, this, m_script_array->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptDOM, this, m_script_dom->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptUndefined, this, m_script_undefined->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptNull, this, m_script_null->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptDate, this, m_script_date->GetId()); #if wxUSE_WEBVIEW_IE - Connect(m_script_object_el->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptObjectWithEmulationLevel), NULL, this ); - Connect(m_script_date_el->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptDateWithEmulationLevel), NULL, this ); - Connect(m_script_array_el->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptArrayWithEmulationLevel), NULL, this ); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptObjectWithEmulationLevel, this, m_script_object_el->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptDateWithEmulationLevel, this, m_script_date_el->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptArrayWithEmulationLevel, this, m_script_array_el->GetId()); #endif - Connect(m_script_custom->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnRunScriptCustom), NULL, this ); - Connect(m_selection_clear->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnClearSelection), NULL, this ); - Connect(m_selection_delete->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnDeleteSelection), NULL, this ); - Connect(selectall->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnSelectAll), NULL, this ); - Connect(loadscheme->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnLoadScheme), NULL, this ); - Connect(usememoryfs->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnUseMemoryFS), NULL, this ); - Connect(m_find->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnFind), NULL, this ); - Connect(m_context_menu->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnEnableContextMenu), NULL, this ); + Bind(wxEVT_MENU, &WebFrame::OnRunScriptCustom, this, m_script_custom->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnClearSelection, this, m_selection_clear->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnDeleteSelection, this, m_selection_delete->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnSelectAll, this, selectall->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnLoadScheme, this, loadscheme->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnUseMemoryFS, this, usememoryfs->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnFind, this, m_find->GetId()); + Bind(wxEVT_MENU, &WebFrame::OnEnableContextMenu, this, m_context_menu->GetId()); //Connect the idle events - Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this); + Bind(wxEVT_IDLE, &WebFrame::OnIdle, this); } WebFrame::~WebFrame() @@ -1011,8 +951,7 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt)) { item = m_tools_history_menu->AppendRadioItem(wxID_ANY, back[i]->GetTitle()); m_histMenuItems[item->GetId()] = back[i]; - Connect(item->GetId(), wxEVT_MENU, - wxCommandEventHandler(WebFrame::OnHistory), NULL, this ); + Bind(wxEVT_MENU, &WebFrame::OnHistory, this, item->GetId()); } wxString title = m_browser->GetCurrentTitle(); @@ -1028,8 +967,7 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt)) { item = m_tools_history_menu->AppendRadioItem(wxID_ANY, forward[i]->GetTitle()); m_histMenuItems[item->GetId()] = forward[i]; - Connect(item->GetId(), wxEVT_TOOL, - wxCommandEventHandler(WebFrame::OnHistory), NULL, this ); + Bind(wxEVT_TOOL, &WebFrame::OnHistory, this, item->GetId()); } wxPoint position = ScreenToClient( wxGetMousePosition() ); diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 28bfbde471..623d2b92e3 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -205,12 +205,6 @@ wxMenu* SearchCtrlWidgetsPage::CreateTestMenu() wxString tipText = wxString::Format(wxT("tip %i"),i); menu->Append(ID_SEARCHMENU+i, itemText, tipText, wxITEM_NORMAL); } -// target->Connect( -// ID_SEARCHMENU, -// ID_SEARCHMENU+SEARCH_MENU_SIZE, -// wxEVT_MENU, -// wxCommandEventHandler(MySearchCtrl::OnSearchMenu) -// ); return menu; } diff --git a/samples/widgets/statbmp.cpp b/samples/widgets/statbmp.cpp index 08a69c6952..b31b3a0370 100644 --- a/samples/widgets/statbmp.cpp +++ b/samples/widgets/statbmp.cpp @@ -115,10 +115,8 @@ void StatBmpWidgetsPage::CreateContent() wxInitAllImageHandlers(); - Connect(wxEVT_FILEPICKER_CHANGED, - wxFileDirPickerEventHandler(StatBmpWidgetsPage::OnFileChange)); - Connect(wxEVT_RADIOBOX, - wxCommandEventHandler(StatBmpWidgetsPage::OnRadioChange)); + Bind(wxEVT_FILEPICKER_CHANGED, &StatBmpWidgetsPage::OnFileChange, this); + Bind(wxEVT_RADIOBOX, &StatBmpWidgetsPage::OnRadioChange, this); m_statbmp = NULL; RecreateWidget(); @@ -171,9 +169,8 @@ void StatBmpWidgetsPage::RecreateWidget() } m_sbsizer->Add(m_statbmp, wxSizerFlags(1).Expand()); GetSizer()->Layout(); - m_statbmp->Connect(wxEVT_LEFT_DOWN, - wxMouseEventHandler(StatBmpWidgetsPage::OnMouseEvent), - NULL, this); + m_statbmp->Bind(wxEVT_LEFT_DOWN, &StatBmpWidgetsPage::OnMouseEvent, this); + // When switching from generic to native control on wxMSW under Wine, // the explicit Refresh() is necessary m_statbmp->Refresh(); diff --git a/samples/widgets/static.cpp b/samples/widgets/static.cpp index ed5fc8d04b..143205238d 100644 --- a/samples/widgets/static.cpp +++ b/samples/widgets/static.cpp @@ -310,9 +310,7 @@ void StaticWidgetsPage::CreateContent() m_textBox = new wxTextCtrl(this, wxID_ANY, wxEmptyString); wxButton *b1 = new wxButton(this, wxID_ANY, "Change &box label"); - b1->Connect(wxEVT_BUTTON, - wxCommandEventHandler(StaticWidgetsPage::OnButtonBoxText), - NULL, this); + b1->Bind(wxEVT_BUTTON, &StaticWidgetsPage::OnButtonBoxText, this); sizerMiddle->Add(m_textBox, 0, wxEXPAND|wxALL, 5); sizerMiddle->Add(b1, 0, wxLEFT|wxBOTTOM, 5); @@ -320,9 +318,7 @@ void StaticWidgetsPage::CreateContent() wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxHSCROLL); wxButton *b2 = new wxButton(this, wxID_ANY, "Change &text label"); - b2->Connect(wxEVT_BUTTON, - wxCommandEventHandler(StaticWidgetsPage::OnButtonLabelText), - NULL, this); + b2->Bind(wxEVT_BUTTON, &StaticWidgetsPage::OnButtonLabelText, this); sizerMiddle->Add(m_textLabel, 0, wxEXPAND|wxALL, 5); sizerMiddle->Add(b2, 0, wxLEFT|wxBOTTOM, 5); @@ -332,9 +328,7 @@ void StaticWidgetsPage::CreateContent() wxTE_MULTILINE|wxHSCROLL); wxButton *b3 = new wxButton(this, wxID_ANY, "Change decorated text label"); - b3->Connect(wxEVT_BUTTON, - wxCommandEventHandler(StaticWidgetsPage::OnButtonLabelWithMarkupText), - NULL, this); + b3->Bind(wxEVT_BUTTON, &StaticWidgetsPage::OnButtonLabelWithMarkupText, this); sizerMiddle->Add(m_textLabelWithMarkup, 0, wxEXPAND|wxALL, 5); sizerMiddle->Add(b3, 0, wxLEFT|wxBOTTOM, 5); @@ -562,12 +556,8 @@ void StaticWidgetsPage::CreateStatic() m_sizerStatic->Layout(); - m_statText->Connect(wxEVT_LEFT_UP, - wxMouseEventHandler(StaticWidgetsPage::OnMouseEvent), - NULL, this); - staticBox->Connect(wxEVT_LEFT_UP, - wxMouseEventHandler(StaticWidgetsPage::OnMouseEvent), - NULL, this); + m_statText->Bind(wxEVT_LEFT_UP, &StaticWidgetsPage::OnMouseEvent, this); + staticBox->Bind(wxEVT_LEFT_UP, &StaticWidgetsPage::OnMouseEvent, this); SetUpWidget(); } diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index cb42f7d16e..3cd4f6c6a3 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -628,9 +628,7 @@ void WidgetsFrame::InitBook() } } - Connect( wxID_ANY, - wxEVT_COMMAND_WIDGETS_PAGE_CHANGED, - wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged) ); + Bind(wxEVT_COMMAND_WIDGETS_PAGE_CHANGED, &WidgetsFrame::OnPageChanged, this); const bool pageSet = wxPersistentRegisterAndRestore(m_book); diff --git a/samples/wrapsizer/wrapsizer.cpp b/samples/wrapsizer/wrapsizer.cpp index 6a13f310c6..8da72f27fc 100644 --- a/samples/wrapsizer/wrapsizer.cpp +++ b/samples/wrapsizer/wrapsizer.cpp @@ -144,8 +144,7 @@ WrapSizerFrame::WrapSizerFrame() // OK Button sizerRoot->Add(new wxButton(m_panel, wxID_OK), wxSizerFlags().Centre().DoubleBorder()); - Connect(wxID_OK, wxEVT_BUTTON, - wxCommandEventHandler(WrapSizerFrame::OnButton)); + Bind(wxEVT_BUTTON, &WrapSizerFrame::OnButton, this, wxID_OK); // Set sizer for the panel m_panel->SetSizer(sizerRoot); diff --git a/samples/xrc/myframe.cpp b/samples/xrc/myframe.cpp index 90a40d482c..0acee89c5e 100644 --- a/samples/xrc/myframe.cpp +++ b/samples/xrc/myframe.cpp @@ -261,8 +261,8 @@ void MyFrame::OnControlsToolOrMenuCommand(wxCommandEvent& WXUNUSED(event)) #if wxUSE_ANIMATIONCTRL // dynamically connect our event handler for the "clicked" event of the "play" button // in the animation ctrl page of our dialog - dlg.Connect(XRCID("controls_animation_button_play"), wxEVT_BUTTON, - wxCommandEventHandler(MyFrame::OnAnimationCtrlPlay)); + dlg.Bind(wxEVT_BUTTON, &MyFrame::OnAnimationCtrlPlay, this, + XRCID("controls_animation_button_play")); #endif // All done. Show the dialog. diff --git a/samples/xrc/objrefdlg.cpp b/samples/xrc/objrefdlg.cpp index 086641feeb..89ff6ec264 100644 --- a/samples/xrc/objrefdlg.cpp +++ b/samples/xrc/objrefdlg.cpp @@ -48,38 +48,26 @@ ObjrefDialog::ObjrefDialog(wxWindow* parent) wxCHECK_RET(nb, "failed to find objref_notebook"); // Connect different event handlers. - nb->Connect(wxEVT_NOTEBOOK_PAGE_CHANGED, - wxNotebookEventHandler(ObjrefDialog::OnNotebookPageChanged), - NULL, this); + nb->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &ObjrefDialog::OnNotebookPageChanged, this); // We want to direct UpdateUI events for the ID range 'first_row' to // OnUpdateUIFirst(). We could achieve this using first_row[0] and // first_row[2], but what if a fourth column were added? It's safer to use // the 'typedefs' for the two ends of the range: wxNotebookPage *page = nb->GetPage(icons_page); - page->Connect(XRCID("first_row[start]"), XRCID("first_row[end]"), - wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUIFirst), - NULL, this); - page->Connect(XRCID("second_row[start]"), XRCID("second_row[end]"), - wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUISecond), - NULL, this); - page->Connect(XRCID("third_row[start]"), XRCID("third_row[end]"), - wxEVT_UPDATE_UI, - wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUIThird), - NULL, this); + page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUIFirst, this, + XRCID("first_row[start]"), XRCID("first_row[end]")); + page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUISecond, this, + XRCID("second_row[start]"), XRCID("second_row[end]")); + page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUIThird, this, + XRCID("third_row[start]"), XRCID("third_row[end]")); // Connect the id ranges, using the [start] and [end] 'typedefs' page = nb->GetPage(calc_page); - page->Connect(XRCID("digits[start]"), XRCID("digits[end]"), - wxEVT_BUTTON, - wxCommandEventHandler(ObjrefDialog::OnNumeralClick), - NULL, this); - page->Connect(XRCID("operators[start]"), XRCID("operators[end]"), - wxEVT_BUTTON, - wxCommandEventHandler(ObjrefDialog::OnOperatorClick), - NULL, this); + page->Bind(wxEVT_BUTTON, &ObjrefDialog::OnNumeralClick, this, + XRCID("digits[start]"), XRCID("digits[end]")); + page->Bind(wxEVT_BUTTON, &ObjrefDialog::OnOperatorClick, this, + XRCID("operators[start]"), XRCID("operators[end]")); } diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index bf700ec508..a38235c47a 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -488,6 +488,55 @@ void MenuTestCase::ChangeBitmap() wxDELETE(menu); } +#if wxUSE_UIACTIONSIMULATOR + +// In C++98 this class can't be defined inside Events() method, unfortunately, +// as its OnMenu() method wouldn't be usable with template Bind() then. +class MenuEventHandler : public wxEvtHandler +{ +public: + MenuEventHandler(wxWindow* win) + : m_win(win) + { + m_win->Bind(wxEVT_MENU, &MenuEventHandler::OnMenu, this); + + m_gotEvent = false; + m_event = NULL; + } + + virtual ~MenuEventHandler() + { + m_win->Unbind(wxEVT_MENU, &MenuEventHandler::OnMenu, this); + + delete m_event; + } + + const wxCommandEvent& GetEvent() + { + CPPUNIT_ASSERT( m_gotEvent ); + + m_gotEvent = false; + + return *m_event; + } + +private: + void OnMenu(wxCommandEvent& event) + { + CPPUNIT_ASSERT( !m_gotEvent ); + + delete m_event; + m_event = static_cast(event.Clone()); + m_gotEvent = true; + } + + wxWindow* const m_win; + wxCommandEvent* m_event; + bool m_gotEvent; +}; + +#endif // wxUSE_UIACTIONSIMULATOR + void MenuTestCase::Events() { #ifdef __WXGTK__ @@ -502,55 +551,6 @@ void MenuTestCase::Events() #endif // __WXGTK__ #if wxUSE_UIACTIONSIMULATOR - class MenuEventHandler : public wxEvtHandler - { - public: - MenuEventHandler(wxWindow* win) - : m_win(win) - { - m_win->Connect(wxEVT_MENU, - wxCommandEventHandler(MenuEventHandler::OnMenu), - NULL, - this); - - m_gotEvent = false; - m_event = NULL; - } - - virtual ~MenuEventHandler() - { - m_win->Disconnect(wxEVT_MENU, - wxCommandEventHandler(MenuEventHandler::OnMenu), - NULL, - this); - - delete m_event; - } - - const wxCommandEvent& GetEvent() - { - CPPUNIT_ASSERT( m_gotEvent ); - - m_gotEvent = false; - - return *m_event; - } - - private: - void OnMenu(wxCommandEvent& event) - { - CPPUNIT_ASSERT( !m_gotEvent ); - - delete m_event; - m_event = static_cast(event.Clone()); - m_gotEvent = true; - } - - wxWindow* const m_win; - wxCommandEvent* m_event; - bool m_gotEvent; - }; - MenuEventHandler handler(m_frame); // Invoke the accelerator. diff --git a/utils/screenshotgen/src/guiframe.cpp b/utils/screenshotgen/src/guiframe.cpp index 5e928c2ea5..050902b0c9 100644 --- a/utils/screenshotgen/src/guiframe.cpp +++ b/utils/screenshotgen/src/guiframe.cpp @@ -56,7 +56,7 @@ GUIFrame::GUIFrame( wxWindow* parent, wxWindowID id, const wxString& title, cons statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY ); // Connect Events - this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( GUIFrame::OnClose ) ); + Bind(wxEVT_CLOSE_WINDOW, &GUIFrame::OnClose, this); } void GUIFrame::AddMenuBar() @@ -102,11 +102,11 @@ void GUIFrame::AddMenuBar() this->SetMenuBar( mbar ); // Connect Events - this->Connect( m_menuSeeScr->GetId(), wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnSeeScreenshots ) ); - this->Connect( m_menuFileQuit->GetId(), wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnQuit ) ); - this->Connect( m_menuCapFullScreen->GetId(), wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnCaptureFullScreen ) ); - this->Connect( m_menuCapAll->GetId(), wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnCaptureAllControls ) ); - this->Connect( m_menuHelpAbout->GetId(), wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnAbout ) ); + Bind(wxEVT_MENU, &GUIFrame::OnSeeScreenshots, this, m_menuSeeScr->GetId()); + Bind(wxEVT_MENU, &GUIFrame::OnQuit, this, m_menuFileQuit->GetId()); + Bind(wxEVT_MENU, &GUIFrame::OnCaptureFullScreen, this, m_menuCapFullScreen->GetId()); + Bind(wxEVT_MENU, &GUIFrame::OnCaptureAllControls, this, m_menuCapAll->GetId()); + Bind(wxEVT_MENU, &GUIFrame::OnAbout, this, m_menuHelpAbout->GetId()); } void GUIFrame::AddPanel_1() @@ -493,10 +493,10 @@ void GUIFrame::AddPanel_5() GUIFrame::~GUIFrame() { // Disconnect Events - this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( GUIFrame::OnClose ) ); - this->Disconnect( wxID_ANY, wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnSeeScreenshots ) ); - this->Disconnect( wxID_ANY, wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnQuit ) ); - this->Disconnect( wxID_ANY, wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnCaptureFullScreen ) ); - this->Disconnect( wxID_ANY, wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnCaptureAllControls ) ); - this->Disconnect( wxID_ANY, wxEVT_MENU, wxCommandEventHandler( GUIFrame::OnAbout ) ); + Unbind(wxEVT_CLOSE_WINDOW, &GUIFrame::OnClose, this); + Unbind(wxEVT_MENU, &GUIFrame::OnSeeScreenshots, this); + Unbind(wxEVT_MENU, &GUIFrame::OnQuit, this); + Unbind(wxEVT_MENU, &GUIFrame::OnCaptureFullScreen, this); + Unbind(wxEVT_MENU, &GUIFrame::OnCaptureAllControls, this); + Unbind(wxEVT_MENU, &GUIFrame::OnAbout, this); }