got rid of wxEvtHandler::m_isWindow, use virtual functions (overridden in wxWindow) instead
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21418 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2094,6 +2094,22 @@ private:
|
|||||||
static const wxEventTableEntry sm_eventTableEntries[];
|
static const wxEventTableEntry sm_eventTableEntries[];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// hooks for wxWindow used by ProcessEvent()
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
// this one is called before trying our own event table to allow plugging
|
||||||
|
// in the validators
|
||||||
|
#if wxUSE_VALIDATORS
|
||||||
|
virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; }
|
||||||
|
#endif // wxUSE_VALIDATORS
|
||||||
|
|
||||||
|
// this one is called after failing to find the event handle in our own
|
||||||
|
// table to give a chance to the other windows to process it
|
||||||
|
//
|
||||||
|
// base class implementation passes the event to wxTheApp
|
||||||
|
virtual bool TryParent(wxEvent& event);
|
||||||
|
|
||||||
|
|
||||||
static const wxEventTable sm_eventTable;
|
static const wxEventTable sm_eventTable;
|
||||||
|
|
||||||
virtual const wxEventTable *GetEventTable() const;
|
virtual const wxEventTable *GetEventTable() const;
|
||||||
@@ -2111,10 +2127,6 @@ protected:
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// optimization: instead of using costly IsKindOf() to decide whether we're
|
|
||||||
// a window (which is true in 99% of cases), use this flag
|
|
||||||
bool m_isWindow;
|
|
||||||
|
|
||||||
// Is event handler enabled?
|
// Is event handler enabled?
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
|
||||||
|
@@ -876,6 +876,13 @@ public:
|
|||||||
#endif // wxUSE_PALETTE
|
#endif // wxUSE_PALETTE
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// event handling specific to wxWindow
|
||||||
|
#if wxUSE_VALIDATORS
|
||||||
|
virtual bool TryValidator(wxEvent& event);
|
||||||
|
#endif // wxUSE_VALIDATORS
|
||||||
|
virtual bool TryParent(wxEvent& event);
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_CONSTRAINTS
|
#if wxUSE_CONSTRAINTS
|
||||||
// satisfy the constraints for the windows but don't set the window sizes
|
// satisfy the constraints for the windows but don't set the window sizes
|
||||||
void SatisfyConstraints();
|
void SatisfyConstraints();
|
||||||
|
@@ -620,7 +620,6 @@ wxEvtHandler::wxEvtHandler()
|
|||||||
m_previousHandler = (wxEvtHandler *) NULL;
|
m_previousHandler = (wxEvtHandler *) NULL;
|
||||||
m_enabled = TRUE;
|
m_enabled = TRUE;
|
||||||
m_dynamicEvents = (wxList *) NULL;
|
m_dynamicEvents = (wxList *) NULL;
|
||||||
m_isWindow = FALSE;
|
|
||||||
m_pendingEvents = (wxList *) NULL;
|
m_pendingEvents = (wxList *) NULL;
|
||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
# if !defined(__VISAGECPP__)
|
# if !defined(__VISAGECPP__)
|
||||||
@@ -786,47 +785,25 @@ void wxEvtHandler::ProcessPendingEvents()
|
|||||||
* Event table stuff
|
* Event table stuff
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
bool wxEvtHandler::TryParent(wxEvent& event)
|
||||||
{
|
{
|
||||||
#if wxUSE_GUI
|
if ( wxTheApp && (this != wxTheApp) )
|
||||||
|
|
||||||
// We have to use the actual window or processing events from
|
|
||||||
// wxWindowNative destructor won't work (we don't see the wxWindow class)
|
|
||||||
#ifdef __WXDEBUG__
|
|
||||||
// check that our flag corresponds to reality
|
|
||||||
wxClassInfo* info = NULL;
|
|
||||||
#ifdef __WXUNIVERSAL__
|
|
||||||
# if defined(__WXMSW__)
|
|
||||||
info = CLASSINFO(wxWindowMSW);
|
|
||||||
# elif defined(__WXGTK__)
|
|
||||||
info = CLASSINFO(wxWindowGTK);
|
|
||||||
# elif defined(__WXX11__)
|
|
||||||
info = CLASSINFO(wxWindowX11);
|
|
||||||
# elif defined(__WXMGL__)
|
|
||||||
info = CLASSINFO(wxWindowMGL);
|
|
||||||
# elif defined(__WXPM__)
|
|
||||||
info = CLASSINFO(wxWindowOS2);
|
|
||||||
# elif defined(__WXMAC__)
|
|
||||||
info = CLASSINFO(wxWindowMac);
|
|
||||||
# elif defined(__WXMOTIF__)
|
|
||||||
info = CLASSINFO(wxWindowMotif);
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
info = CLASSINFO(wxWindow);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( m_isWindow != IsKindOf(info) )
|
|
||||||
{
|
{
|
||||||
wxString msg = GetClassInfo()->GetClassName();
|
// Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
|
||||||
msg += _T(" should [not] be a window but it is [not]");
|
// swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
|
||||||
|
// processed appropriately via SearchEventTable.
|
||||||
wxFAIL_MSG( msg );
|
if ( event.GetEventType() != wxEVT_IDLE )
|
||||||
|
{
|
||||||
|
if ( wxTheApp->ProcessEvent(event) )
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __WXDEBUG__
|
return FALSE;
|
||||||
|
}
|
||||||
#endif // wxUSE_GUI
|
|
||||||
|
|
||||||
|
bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||||
|
{
|
||||||
// allow the application to hook into event processing
|
// allow the application to hook into event processing
|
||||||
if ( wxTheApp )
|
if ( wxTheApp )
|
||||||
{
|
{
|
||||||
@@ -844,52 +821,18 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
// An event handler can be enabled or disabled
|
// An event handler can be enabled or disabled
|
||||||
if ( GetEvtHandlerEnabled() )
|
if ( GetEvtHandlerEnabled() )
|
||||||
{
|
{
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
What is this? When using GUI threads, a non main
|
|
||||||
threads can send an event and process it itself.
|
|
||||||
This breaks GTK's GUI threads, so please explain.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Check whether we are in a child thread.
|
|
||||||
if ( !wxThread::IsMain() )
|
|
||||||
return ProcessThreadEvent(event);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Handle per-instance dynamic event tables first
|
// Handle per-instance dynamic event tables first
|
||||||
if ( m_dynamicEvents && SearchDynamicEventTable(event) )
|
if ( m_dynamicEvents && SearchDynamicEventTable(event) )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
#if wxUSE_VALIDATORS
|
||||||
|
if ( TryValidator(event) )
|
||||||
|
return TRUE;
|
||||||
|
#endif // wxUSE_VALIDATORS
|
||||||
|
|
||||||
// Then static per-class event tables
|
// Then static per-class event tables
|
||||||
const wxEventTable *table = GetEventTable();
|
const wxEventTable *table = GetEventTable();
|
||||||
|
|
||||||
#if wxUSE_GUI && wxUSE_VALIDATORS
|
|
||||||
// Try the associated validator first, if this is a window.
|
|
||||||
// Problem: if the event handler of the window has been replaced,
|
|
||||||
// this wxEvtHandler may no longer be a window.
|
|
||||||
// Therefore validators won't be processed if the handler
|
|
||||||
// has been replaced with SetEventHandler.
|
|
||||||
// THIS CAN BE CURED if PushEventHandler is used instead of
|
|
||||||
// SetEventHandler, and then processing will be passed down the
|
|
||||||
// chain of event handlers.
|
|
||||||
if (m_isWindow)
|
|
||||||
{
|
|
||||||
wxWindow *win = (wxWindow *)this;
|
|
||||||
|
|
||||||
// Can only use the validator of the window which
|
|
||||||
// is receiving the event
|
|
||||||
if ( win == event.GetEventObject() )
|
|
||||||
{
|
|
||||||
wxValidator *validator = win->GetValidator();
|
|
||||||
if ( validator && validator->ProcessEvent(event) )
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Search upwards through the inheritance hierarchy
|
// Search upwards through the inheritance hierarchy
|
||||||
while (table)
|
while (table)
|
||||||
{
|
{
|
||||||
@@ -906,43 +849,11 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_GUI
|
return TryParent(event);
|
||||||
// Carry on up the parent-child hierarchy, but only if event is a command
|
|
||||||
// event: it wouldn't make sense for a parent to receive a child's size
|
|
||||||
// event, for example
|
|
||||||
if ( m_isWindow && event.IsCommandEvent() )
|
|
||||||
{
|
|
||||||
wxWindow *win = (wxWindow *)this;
|
|
||||||
|
|
||||||
// honour the requests to stop propagation at this window: this is
|
|
||||||
// used by the dialogs, for example, to prevent processing the events
|
|
||||||
// from the dialog controls in the parent frame which rarely, if ever,
|
|
||||||
// makes sense
|
|
||||||
if ( !(win->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
|
|
||||||
{
|
|
||||||
wxWindow *parent = win->GetParent();
|
|
||||||
if ( parent && !parent->IsBeingDeleted() )
|
|
||||||
return parent->GetEventHandler()->ProcessEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // wxUSE_GUI
|
|
||||||
|
|
||||||
// Last try - application object.
|
|
||||||
if ( wxTheApp && (this != wxTheApp) )
|
|
||||||
{
|
|
||||||
// Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
|
|
||||||
// swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
|
|
||||||
// processed appropriately via SearchEventTable.
|
|
||||||
if ( event.GetEventType() != wxEVT_IDLE )
|
|
||||||
{
|
|
||||||
if ( wxTheApp->ProcessEvent(event) )
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_BASE
|
||||||
|
|
||||||
bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
|
bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
|
||||||
{
|
{
|
||||||
wxEventType eventType = event.GetEventType();
|
wxEventType eventType = event.GetEventType();
|
||||||
@@ -1135,6 +1046,8 @@ bool wxEvtHandler::OnClose()
|
|||||||
}
|
}
|
||||||
#endif // WXWIN_COMPATIBILITY
|
#endif // WXWIN_COMPATIBILITY
|
||||||
|
|
||||||
|
#endif // wxUSE_BASE
|
||||||
|
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
|
|
||||||
// Find a window with the focus, that is also a descendant of the given window.
|
// Find a window with the focus, that is also a descendant of the given window.
|
||||||
|
@@ -2101,6 +2101,52 @@ void wxWindowBase::SendDestroyEvent()
|
|||||||
GetEventHandler()->ProcessEvent(event);
|
GetEventHandler()->ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// event processing
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if wxUSE_VALIDATORS
|
||||||
|
|
||||||
|
bool wxWindowBase::TryValidator(wxEvent& event)
|
||||||
|
{
|
||||||
|
// Can only use the validator of the window which
|
||||||
|
// is receiving the event
|
||||||
|
if ( event.GetEventObject() == this )
|
||||||
|
{
|
||||||
|
wxValidator *validator = GetValidator();
|
||||||
|
if ( validator && validator->ProcessEvent(event) )
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_VALIDATORS
|
||||||
|
|
||||||
|
bool wxWindowBase::TryParent(wxEvent& event)
|
||||||
|
{
|
||||||
|
// Carry on up the parent-child hierarchy, but only if event is a command
|
||||||
|
// event: it wouldn't make sense for a parent to receive a child's size
|
||||||
|
// event, for example
|
||||||
|
if ( event.IsCommandEvent() )
|
||||||
|
{
|
||||||
|
// honour the requests to stop propagation at this window: this is
|
||||||
|
// used by the dialogs, for example, to prevent processing the events
|
||||||
|
// from the dialog controls in the parent frame which rarely, if ever,
|
||||||
|
// makes sense
|
||||||
|
if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
|
||||||
|
{
|
||||||
|
wxWindow *parent = GetParent();
|
||||||
|
if ( parent && !parent->IsBeingDeleted() )
|
||||||
|
return parent->GetEventHandler()->ProcessEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxEvtHandler::TryParent(event);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// global functions
|
// global functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user