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

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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.
*/

View File

@@ -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
// ----------

View File

@@ -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);
//@}
};

View File

@@ -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);

View File

@@ -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;

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

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

View File

@@ -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
@@ -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
{

View File

@@ -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);
}
// ----------------------------------------------------------------------------

View File

@@ -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();

View File

@@ -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()

View File

@@ -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 );
}