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
This commit is contained in:
Francesco Montorsi
2009-01-25 11:58:39 +00:00
parent 838ab05ede
commit 004867dbc5
17 changed files with 76 additions and 32 deletions

View File

@@ -61,7 +61,7 @@ public:
void SetArtProvider(wxAuiTabArt* provider); void SetArtProvider(wxAuiTabArt* provider);
wxAuiTabArt* GetArtProvider(); wxAuiTabArt* GetArtProvider();
wxAuiNotebook* GetNotebook() const; wxAuiNotebook* GetNotebook() const;
#if wxUSE_MENUS #if wxUSE_MENUS
wxMenu* GetWindowMenu() const { return m_pWindowMenu; } wxMenu* GetWindowMenu() const { return m_pWindowMenu; }
void SetWindowMenu(wxMenu* pMenu); void SetWindowMenu(wxMenu* pMenu);
@@ -71,8 +71,6 @@ public:
void SetChildMenuBar(wxAuiMDIChildFrame *pChild); void SetChildMenuBar(wxAuiMDIChildFrame *pChild);
virtual bool ProcessEvent(wxEvent& event);
wxAuiMDIChildFrame *GetActiveChild() const; wxAuiMDIChildFrame *GetActiveChild() const;
void SetActiveChild(wxAuiMDIChildFrame* pChildFrame); void SetActiveChild(wxAuiMDIChildFrame* pChildFrame);
@@ -105,6 +103,8 @@ protected:
void DoHandleMenu(wxCommandEvent &event); void DoHandleMenu(wxCommandEvent &event);
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
virtual bool ProcessEvent(wxEvent& event);
virtual void DoGetClientSize(int *width, int *height) const; virtual void DoGetClientSize(int *width, int *height) const;
private: private:
@@ -147,7 +147,7 @@ public:
virtual void SetIcons(const wxIconBundle& icons); virtual void SetIcons(const wxIconBundle& icons);
virtual const wxIconBundle& GetIcons() const; virtual const wxIconBundle& GetIcons() const;
virtual void SetIcon(const wxIcon& icon); virtual void SetIcon(const wxIcon& icon);
virtual const wxIcon& GetIcon() const; virtual const wxIcon& GetIcon() const;
@@ -196,7 +196,7 @@ public:
void SetMDIParentFrame(wxAuiMDIParentFrame* parent); void SetMDIParentFrame(wxAuiMDIParentFrame* parent);
wxAuiMDIParentFrame* GetMDIParentFrame() const; wxAuiMDIParentFrame* GetMDIParentFrame() const;
protected: protected:
void Init(); void Init();
virtual void DoSetSize(int x, int y, int width, int height, int size_flags); virtual void DoSetSize(int x, int y, int width, int height, int size_flags);

View File

@@ -78,8 +78,6 @@ public:
virtual void SetMenuBar(wxMenuBar *pMenuBar); virtual void SetMenuBar(wxMenuBar *pMenuBar);
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
virtual bool ProcessEvent(wxEvent& event);
virtual wxGenericMDIClientWindow *OnCreateGenericClient(); virtual wxGenericMDIClientWindow *OnCreateGenericClient();
@@ -112,6 +110,8 @@ private:
void OnWindowMenu(wxCommandEvent& event); void OnWindowMenu(wxCommandEvent& event);
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
virtual bool ProcessEvent(wxEvent& event);
void OnClose(wxCloseEvent& event); void OnClose(wxCloseEvent& event);
// return the client window, may be NULL if we hadn't been created yet // return the client window, may be NULL if we hadn't been created yet

View File

@@ -166,7 +166,7 @@ public:
// override this if some events should never be consumed by wxWidgets but // override this if some events should never be consumed by wxWidgets but
// but have to be left for the native control // 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; virtual bool GTKProcessEvent(wxEvent& event) const;
// Map GTK widget direction of the given widget to/from wxLayoutDirection // Map GTK widget direction of the given widget to/from wxLayoutDirection
@@ -178,7 +178,7 @@ public:
// there is also the exception of wxMenuBar) // there is also the exception of wxMenuBar)
virtual bool GTKNeedsParent() const { return !IsTopLevel(); } 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. // fire off capture lost events.
void GTKReleaseMouseAndNotify(); void GTKReleaseMouseAndNotify();
@@ -256,7 +256,7 @@ public:
// this widget will be queried for GTK's focus events // this widget will be queried for GTK's focus events
GtkWidget *m_focusWidget; GtkWidget *m_focusWidget;
void GTKDisableFocusOutEvent(); void GTKDisableFocusOutEvent();
void GTKEnableFocusOutEvent(); void GTKEnableFocusOutEvent();

View File

@@ -634,7 +634,6 @@ public:
#ifndef SWIG #ifndef SWIG
virtual bool ProcessEvent( wxEvent& event );
// //
// Event handlers // Event handlers
// //
@@ -707,6 +706,8 @@ protected:
virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const; virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
#endif*/ #endif*/
virtual bool ProcessEvent( wxEvent& event );
/** Recalculates new positions for components, according to the /** Recalculates new positions for components, according to the
given size. given size.
*/ */

View File

@@ -817,6 +817,26 @@ public:
virtual void SetNextHandler(wxEvtHandler *handler); virtual void SetNextHandler(wxEvtHandler *handler);
virtual void SetPreviousHandler(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 // validators
// ---------- // ----------

View File

@@ -3086,6 +3086,25 @@ protected:
explanations of when you might want to do it. explanations of when you might want to do it.
*/ */
void SendDestroyEvent(); 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);
//@}
}; };

View File

@@ -123,6 +123,8 @@ public:
void OnHandleCrash(wxCommandEvent& event); void OnHandleCrash(wxCommandEvent& event);
#endif #endif
protected:
// 1st-level exception handling: we overload ProcessEvent() to be able to // 1st-level exception handling: we overload ProcessEvent() to be able to
// catch exceptions which occur in MyFrame methods here // catch exceptions which occur in MyFrame methods here
virtual bool ProcessEvent(wxEvent& event); virtual bool ProcessEvent(wxEvent& event);

View File

@@ -181,6 +181,8 @@ public:
void OnPreview(wxCommandEvent& event); void OnPreview(wxCommandEvent& event);
void OnPageSetup(wxCommandEvent& event); void OnPageSetup(wxCommandEvent& event);
protected:
// Forward command events to the current rich text control, if any // Forward command events to the current rich text control, if any
bool ProcessEvent(wxEvent& event); bool ProcessEvent(wxEvent& event);
@@ -958,7 +960,7 @@ bool MyFrame::ProcessEvent(wxEvent& event)
s_id = event.GetId(); s_id = event.GetId();
wxWindow* focusWin = wxFindFocusDescendant(this); wxWindow* focusWin = wxFindFocusDescendant(this);
if (focusWin && focusWin->ProcessEvent(event)) if (focusWin && focusWin->GetEventHandler()->ProcessEvent(event))
{ {
//s_command = NULL; //s_command = NULL;
s_eventType = 0; s_eventType = 0;

View File

@@ -457,7 +457,7 @@ void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
// edit events // edit events
void AppFrame::OnEdit (wxCommandEvent &event) { void AppFrame::OnEdit (wxCommandEvent &event) {
if (m_edit) m_edit->ProcessEvent (event); if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
} }
// private functions // private functions

View File

@@ -2260,7 +2260,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
e.SetEventObject(this); e.SetEventObject(this);
e.SetToolId(-1); e.SetToolId(-1);
e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY())); e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY()));
bool processed = ProcessEvent(e); bool processed = GetEventHandler()->ProcessEvent(e);
if (processed) if (processed)
{ {
@@ -2297,7 +2297,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
{ {
wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res); wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res);
e.SetEventObject(this); e.SetEventObject(this);
GetParent()->ProcessEvent(e); GetParent()->GetEventHandler()->ProcessEvent(e);
} }
} }
@@ -2338,7 +2338,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
e.SetClickPoint(evt.GetPosition()); e.SetClickPoint(evt.GetPosition());
e.SetItemRect(rect); e.SetItemRect(rect);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
} }
@@ -2384,14 +2384,14 @@ void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt)
wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
e.SetEventObject(this); e.SetEventObject(this);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
else else
{ {
wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
e.SetEventObject(this); e.SetEventObject(this);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
} }
@@ -2454,7 +2454,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt)
e.SetEventObject(this); e.SetEventObject(this);
e.SetToolId(m_action_item->id); e.SetToolId(m_action_item->id);
e.SetClickPoint(m_action_pos); e.SetClickPoint(m_action_pos);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
} }
@@ -2465,7 +2465,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt)
e.SetEventObject(this); e.SetEventObject(this);
e.SetToolId(-1); e.SetToolId(-1);
e.SetClickPoint(m_action_pos); e.SetClickPoint(m_action_pos);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
@@ -2525,7 +2525,7 @@ void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt)
e.SetEventObject(this); e.SetEventObject(this);
e.SetToolId(m_action_item->id); e.SetToolId(m_action_item->id);
e.SetClickPoint(m_action_pos); e.SetClickPoint(m_action_pos);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
} }
} }
@@ -2550,7 +2550,7 @@ void wxAuiToolBar::OnMotion(wxMouseEvent& evt)
wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId()); wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId());
e.SetEventObject(this); e.SetEventObject(this);
e.SetToolId(m_action_item->id); e.SetToolId(m_action_item->id);
ProcessEvent(e); GetEventHandler()->ProcessEvent(e);
DoIdleUpdate(); DoIdleUpdate();
return; return;
} }

View File

@@ -772,7 +772,7 @@ wxAuiManager* wxAuiManager::GetManager(wxWindow* window)
wxAuiManagerEvent evt(wxEVT_AUI_FIND_MANAGER); wxAuiManagerEvent evt(wxEVT_AUI_FIND_MANAGER);
evt.SetManager(NULL); evt.SetManager(NULL);
evt.ResumePropagation(wxEVENT_PROPAGATE_MAX); evt.ResumePropagation(wxEVENT_PROPAGATE_MAX);
if (!window->ProcessEvent(evt)) if (!window->GetEventHandler()->ProcessEvent(evt))
return NULL; return NULL;
return evt.GetManager(); return evt.GetManager();
@@ -933,7 +933,7 @@ void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent& event)
// first, give the owner frame a chance to override // first, give the owner frame a chance to override
if (m_frame) if (m_frame)
{ {
if (m_frame->ProcessEvent(event)) if (m_frame->GetEventHandler()->ProcessEvent(event))
return; return;
} }

View File

@@ -49,7 +49,7 @@ wxChoiceBase::~wxChoiceBase()
void wxChoiceBase::Command(wxCommandEvent& event) void wxChoiceBase::Command(wxCommandEvent& event)
{ {
SetSelection(event.GetInt()); SetSelection(event.GetInt());
(void)ProcessEvent(event); (void)GetEventHandler()->ProcessEvent(event);
} }
#endif // wxUSE_CHOICE #endif // wxUSE_CHOICE

View File

@@ -461,7 +461,7 @@ void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
wxWindowList children = m_combo->GetPopupWindow()->GetChildren(); wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
wxWindowList::iterator node = children.begin(); wxWindowList::iterator node = children.begin();
wxWindow* child = (wxWindow*)*node; wxWindow* child = (wxWindow*)*node;
child->AddPendingEvent(event); child->GetEventHandler()->AddPendingEvent(event);
} }
#if USES_WXDIALOG #if USES_WXDIALOG
@@ -1177,7 +1177,7 @@ bool wxComboCtrlBase::Enable(bool enable)
m_btn->Enable(enable); m_btn->Enable(enable);
if ( m_text ) if ( m_text )
m_text->Enable(enable); m_text->Enable(enable);
Refresh(); Refresh();
return true; return true;
@@ -1648,7 +1648,7 @@ void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
if ( IsPopupShown() ) if ( IsPopupShown() )
{ {
// pass it to the popped up control // pass it to the popped up control
GetPopupControl()->GetControl()->AddPendingEvent(event); GetPopupControl()->GetControl()->GetEventHandler()->AddPendingEvent(event);
} }
else // no popup else // no popup
{ {

View File

@@ -201,7 +201,7 @@ void wxListBoxBase::CalcAndSendEvent()
void wxListBoxBase::Command(wxCommandEvent& event) void wxListBoxBase::Command(wxCommandEvent& event)
{ {
SetSelection(event.GetInt(), event.GetExtraLong() != 0); SetSelection(event.GetInt(), event.GetExtraLong() != 0);
(void)ProcessEvent(event); (void)GetEventHandler()->ProcessEvent(event);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -584,7 +584,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
// Reduce flicker by updating the splitter pane sizes before the // Reduce flicker by updating the splitter pane sizes before the
// frame is shown // frame is shown
wxSizeEvent sizeEvent(GetSize(), GetId()); wxSizeEvent sizeEvent(GetSize(), GetId());
ProcessEvent(sizeEvent); GetEventHandler()->ProcessEvent(sizeEvent);
if (m_Splitter) if (m_Splitter)
m_Splitter->UpdateSize(); m_Splitter->UpdateSize();

View File

@@ -102,7 +102,7 @@ void wxJoystickThread::SendEvent(wxEventType type, long ts, int change)
jwx_event.SetEventObject(m_catchwin); jwx_event.SetEventObject(m_catchwin);
if (m_catchwin) if (m_catchwin)
m_catchwin->AddPendingEvent(jwx_event); m_catchwin->GetEventHandler()->AddPendingEvent(jwx_event);
} }
void* wxJoystickThread::Entry() void* wxJoystickThread::Entry()

View File

@@ -184,7 +184,7 @@ void EventPropagationTestCase::WindowWithoutHandler()
TestWindow * const child = new TestWindow(parent, 'c'); TestWindow * const child = new TestWindow(parent, 'c');
child->ProcessEvent(event); child->GetEventHandler()->ProcessEvent(event);
CPPUNIT_ASSERT_EQUAL( "acpA", g_str ); CPPUNIT_ASSERT_EQUAL( "acpA", g_str );
} }