From: Francesco Montorsi Date: Sun, 25 Jan 2009 11:58:39 +0000 (+0000) Subject: Change in wxWindow the access specifier of the wxEvtHandler event processing and... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/004867dbc54950a43acc7d250fa4a966f046a679 Change in wxWindow the access specifier of the wxEvtHandler event processing and queuing functions from public to protected. Adapt wxWidgets code and wxWidgets samples to always use wxWindow::GetEventHandler() when calling such functions on a wxWindow rather than directly using wxWindow::ProcessEvent, etc. This enables correct event dispatching to the event handlers which have been pushed (with PushEventHandler) on the windows. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58381 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/aui/tabmdi.h b/include/wx/aui/tabmdi.h index 2da0bdd809..e4e7b8182c 100644 --- a/include/wx/aui/tabmdi.h +++ b/include/wx/aui/tabmdi.h @@ -61,7 +61,7 @@ public: void SetArtProvider(wxAuiTabArt* provider); wxAuiTabArt* GetArtProvider(); wxAuiNotebook* GetNotebook() const; - + #if wxUSE_MENUS wxMenu* GetWindowMenu() const { return m_pWindowMenu; } void SetWindowMenu(wxMenu* pMenu); @@ -71,8 +71,6 @@ public: void SetChildMenuBar(wxAuiMDIChildFrame *pChild); - virtual bool ProcessEvent(wxEvent& event); - wxAuiMDIChildFrame *GetActiveChild() const; void SetActiveChild(wxAuiMDIChildFrame* pChildFrame); @@ -105,6 +103,8 @@ protected: void DoHandleMenu(wxCommandEvent &event); #endif // wxUSE_MENUS + virtual bool ProcessEvent(wxEvent& event); + virtual void DoGetClientSize(int *width, int *height) const; private: @@ -147,7 +147,7 @@ public: virtual void SetIcons(const wxIconBundle& icons); virtual const wxIconBundle& GetIcons() const; - + virtual void SetIcon(const wxIcon& icon); virtual const wxIcon& GetIcon() const; @@ -196,7 +196,7 @@ public: void SetMDIParentFrame(wxAuiMDIParentFrame* parent); wxAuiMDIParentFrame* GetMDIParentFrame() const; - + protected: void Init(); virtual void DoSetSize(int x, int y, int width, int height, int size_flags); diff --git a/include/wx/generic/mdig.h b/include/wx/generic/mdig.h index d21366b3c5..46708ed6fc 100644 --- a/include/wx/generic/mdig.h +++ b/include/wx/generic/mdig.h @@ -78,8 +78,6 @@ public: virtual void SetMenuBar(wxMenuBar *pMenuBar); #endif // wxUSE_MENUS - virtual bool ProcessEvent(wxEvent& event); - virtual wxGenericMDIClientWindow *OnCreateGenericClient(); @@ -112,6 +110,8 @@ private: void OnWindowMenu(wxCommandEvent& event); #endif // wxUSE_MENUS + virtual bool ProcessEvent(wxEvent& event); + void OnClose(wxCloseEvent& event); // return the client window, may be NULL if we hadn't been created yet diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 4d30ba2256..075a40cb7b 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -166,7 +166,7 @@ public: // override this if some events should never be consumed by wxWidgets but // but have to be left for the native control // - // base version just does GetEventHandler()->ProcessEvent() + // base version just calls HandleWindowEvent() virtual bool GTKProcessEvent(wxEvent& event) const; // Map GTK widget direction of the given widget to/from wxLayoutDirection @@ -178,7 +178,7 @@ public: // there is also the exception of wxMenuBar) virtual bool GTKNeedsParent() const { return !IsTopLevel(); } - // This is called when capture is taken from the window. It will + // This is called when capture is taken from the window. It will // fire off capture lost events. void GTKReleaseMouseAndNotify(); @@ -256,7 +256,7 @@ public: // this widget will be queried for GTK's focus events GtkWidget *m_focusWidget; - + void GTKDisableFocusOutEvent(); void GTKEnableFocusOutEvent(); diff --git a/include/wx/propgrid/manager.h b/include/wx/propgrid/manager.h index 5885072264..c93c669420 100644 --- a/include/wx/propgrid/manager.h +++ b/include/wx/propgrid/manager.h @@ -634,7 +634,6 @@ public: #ifndef SWIG - virtual bool ProcessEvent( wxEvent& event ); // // Event handlers // @@ -707,6 +706,8 @@ protected: virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const; #endif*/ + virtual bool ProcessEvent( wxEvent& event ); + /** Recalculates new positions for components, according to the given size. */ diff --git a/include/wx/window.h b/include/wx/window.h index 932ac84f36..ec6a5644f9 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -817,6 +817,26 @@ public: virtual void SetNextHandler(wxEvtHandler *handler); virtual void SetPreviousHandler(wxEvtHandler *handler); +protected: + + // NOTE: we change the access specifier of the following wxEvtHandler functions + // so that the user won't be able to call them directly. + // Calling wxWindow::ProcessEvent in fact only works when there are NO + // event handlers pushed on the window. + // To ensure correct operation, instead of wxWindow::ProcessEvent + // you must always call wxWindow::GetEventHandler()->ProcessEvent() + // or HandleWindowEvent(). + // The same holds for all other wxEvtHandler functions. + + wxEvtHandler::ProcessEvent; + wxEvtHandler::ProcessThreadEvent; + wxEvtHandler::SafelyProcessEvent; + wxEvtHandler::ProcessPendingEvents; + wxEvtHandler::AddPendingEvent; + wxEvtHandler::QueueEvent; + +public: + // validators // ---------- diff --git a/interface/wx/window.h b/interface/wx/window.h index a77ebf3604..03eb0a6894 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -3086,6 +3086,25 @@ protected: explanations of when you might want to do it. */ void SendDestroyEvent(); + + //@{ + /** + This function is public in wxEvtHandler but is protected in wxWindow because + for wxWindows you should always use this function on the pointer returned + by GetEventHandler() and not on the wxWindow object itself. + + Note that it's still possible to call these functions directly on the + wxWindow object (e.g. downcasting it to wxEvtHandler) but doing that + will create subtle bugs when windows with event handlers pushed on them + are involved. + */ + virtual bool ProcessEvent(wxEvent& event); + bool SafelyProcessEvent(wxEvent& event); + virtual void QueueEvent(wxEvent *event); + virtual void AddPendingEvent(const wxEvent& event); + void ProcessPendingEvents(); + bool ProcessThreadEvent(const wxEvent& event); + //@} }; diff --git a/samples/except/except.cpp b/samples/except/except.cpp index 5e487845d5..95502800c7 100644 --- a/samples/except/except.cpp +++ b/samples/except/except.cpp @@ -123,6 +123,8 @@ public: void OnHandleCrash(wxCommandEvent& event); #endif +protected: + // 1st-level exception handling: we overload ProcessEvent() to be able to // catch exceptions which occur in MyFrame methods here virtual bool ProcessEvent(wxEvent& event); diff --git a/samples/richtext/richtext.cpp b/samples/richtext/richtext.cpp index c13f182983..d41e8e90f9 100644 --- a/samples/richtext/richtext.cpp +++ b/samples/richtext/richtext.cpp @@ -181,6 +181,8 @@ public: void OnPreview(wxCommandEvent& event); void OnPageSetup(wxCommandEvent& event); +protected: + // Forward command events to the current rich text control, if any bool ProcessEvent(wxEvent& event); @@ -958,7 +960,7 @@ bool MyFrame::ProcessEvent(wxEvent& event) s_id = event.GetId(); wxWindow* focusWin = wxFindFocusDescendant(this); - if (focusWin && focusWin->ProcessEvent(event)) + if (focusWin && focusWin->GetEventHandler()->ProcessEvent(event)) { //s_command = NULL; s_eventType = 0; diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 203cd15bbc..14db821fc5 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -457,7 +457,7 @@ void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) { // edit events void AppFrame::OnEdit (wxCommandEvent &event) { - if (m_edit) m_edit->ProcessEvent (event); + if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event); } // private functions diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index aba3001507..8e03594c16 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -2260,7 +2260,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(-1); e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY())); - bool processed = ProcessEvent(e); + bool processed = GetEventHandler()->ProcessEvent(e); if (processed) { @@ -2297,7 +2297,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) { wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res); e.SetEventObject(this); - GetParent()->ProcessEvent(e); + GetParent()->GetEventHandler()->ProcessEvent(e); } } @@ -2338,7 +2338,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) e.SetClickPoint(evt.GetPosition()); e.SetItemRect(rect); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2384,14 +2384,14 @@ void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt) wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); e.SetEventObject(this); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } else { wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); e.SetEventObject(this); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2454,7 +2454,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(m_action_item->id); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2465,7 +2465,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(-1); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } @@ -2525,7 +2525,7 @@ void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(m_action_item->id); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2550,7 +2550,7 @@ void wxAuiToolBar::OnMotion(wxMouseEvent& evt) wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId()); e.SetEventObject(this); e.SetToolId(m_action_item->id); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); return; } diff --git a/src/aui/framemanager.cpp b/src/aui/framemanager.cpp index 2c85e56551..05e6bbfb18 100644 --- a/src/aui/framemanager.cpp +++ b/src/aui/framemanager.cpp @@ -772,7 +772,7 @@ wxAuiManager* wxAuiManager::GetManager(wxWindow* window) wxAuiManagerEvent evt(wxEVT_AUI_FIND_MANAGER); evt.SetManager(NULL); evt.ResumePropagation(wxEVENT_PROPAGATE_MAX); - if (!window->ProcessEvent(evt)) + if (!window->GetEventHandler()->ProcessEvent(evt)) return NULL; return evt.GetManager(); @@ -933,7 +933,7 @@ void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent& event) // first, give the owner frame a chance to override if (m_frame) { - if (m_frame->ProcessEvent(event)) + if (m_frame->GetEventHandler()->ProcessEvent(event)) return; } diff --git a/src/common/choiccmn.cpp b/src/common/choiccmn.cpp index 6685fda3cf..64f8a92347 100644 --- a/src/common/choiccmn.cpp +++ b/src/common/choiccmn.cpp @@ -49,7 +49,7 @@ wxChoiceBase::~wxChoiceBase() void wxChoiceBase::Command(wxCommandEvent& event) { SetSelection(event.GetInt()); - (void)ProcessEvent(event); + (void)GetEventHandler()->ProcessEvent(event); } #endif // wxUSE_CHOICE diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 89367d068b..50449b2344 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -461,7 +461,7 @@ void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event ) wxWindowList children = m_combo->GetPopupWindow()->GetChildren(); wxWindowList::iterator node = children.begin(); wxWindow* child = (wxWindow*)*node; - child->AddPendingEvent(event); + child->GetEventHandler()->AddPendingEvent(event); } #if USES_WXDIALOG @@ -1177,7 +1177,7 @@ bool wxComboCtrlBase::Enable(bool enable) m_btn->Enable(enable); if ( m_text ) m_text->Enable(enable); - + Refresh(); return true; @@ -1648,7 +1648,7 @@ void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event) if ( IsPopupShown() ) { // pass it to the popped up control - GetPopupControl()->GetControl()->AddPendingEvent(event); + GetPopupControl()->GetControl()->GetEventHandler()->AddPendingEvent(event); } else // no popup { diff --git a/src/common/lboxcmn.cpp b/src/common/lboxcmn.cpp index 9b114d7c1b..a9beae01cc 100644 --- a/src/common/lboxcmn.cpp +++ b/src/common/lboxcmn.cpp @@ -201,7 +201,7 @@ void wxListBoxBase::CalcAndSendEvent() void wxListBoxBase::Command(wxCommandEvent& event) { SetSelection(event.GetInt(), event.GetExtraLong() != 0); - (void)ProcessEvent(event); + (void)GetEventHandler()->ProcessEvent(event); } // ---------------------------------------------------------------------------- diff --git a/src/html/helpwnd.cpp b/src/html/helpwnd.cpp index e66a5be432..78b4719acf 100644 --- a/src/html/helpwnd.cpp +++ b/src/html/helpwnd.cpp @@ -584,7 +584,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id, // Reduce flicker by updating the splitter pane sizes before the // frame is shown wxSizeEvent sizeEvent(GetSize(), GetId()); - ProcessEvent(sizeEvent); + GetEventHandler()->ProcessEvent(sizeEvent); if (m_Splitter) m_Splitter->UpdateSize(); diff --git a/src/unix/joystick.cpp b/src/unix/joystick.cpp index b96c009826..f9f2ba9d41 100644 --- a/src/unix/joystick.cpp +++ b/src/unix/joystick.cpp @@ -102,7 +102,7 @@ void wxJoystickThread::SendEvent(wxEventType type, long ts, int change) jwx_event.SetEventObject(m_catchwin); if (m_catchwin) - m_catchwin->AddPendingEvent(jwx_event); + m_catchwin->GetEventHandler()->AddPendingEvent(jwx_event); } void* wxJoystickThread::Entry() diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index e0918af3aa..e240dd6e17 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -184,7 +184,7 @@ void EventPropagationTestCase::WindowWithoutHandler() TestWindow * const child = new TestWindow(parent, 'c'); - child->ProcessEvent(event); + child->GetEventHandler()->ProcessEvent(event); CPPUNIT_ASSERT_EQUAL( "acpA", g_str ); }