small optimizations: m_isWindow and m_isCommandEvent flags introduced
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1762 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -283,6 +283,10 @@ public:
|
|||||||
void Skip(bool skip = TRUE) { m_skipped = skip; }
|
void Skip(bool skip = TRUE) { m_skipped = skip; }
|
||||||
bool GetSkipped() const { return m_skipped; };
|
bool GetSkipped() const { return m_skipped; };
|
||||||
|
|
||||||
|
// implementation only: this test is explicitlty anti OO and this functions
|
||||||
|
// exists only for optimization purposes
|
||||||
|
bool IsCommandEvent() const { return m_isCommandEvent; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool m_skipped;
|
bool m_skipped;
|
||||||
wxObject* m_eventObject;
|
wxObject* m_eventObject;
|
||||||
@@ -291,6 +295,10 @@ public:
|
|||||||
long m_timeStamp;
|
long m_timeStamp;
|
||||||
int m_id;
|
int m_id;
|
||||||
wxObject* m_callbackUserData;
|
wxObject* m_callbackUserData;
|
||||||
|
|
||||||
|
// optimization: instead of using costly IsKindOf() we keep a flag telling
|
||||||
|
// whether we're a command event (by far the most common case)
|
||||||
|
bool m_isCommandEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Item or menu event class
|
// Item or menu event class
|
||||||
@@ -1182,13 +1190,19 @@ private:
|
|||||||
static const wxEventTableEntry sm_eventTableEntries[];
|
static const wxEventTableEntry sm_eventTableEntries[];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const wxEventTable sm_eventTable;
|
static const wxEventTable sm_eventTable;
|
||||||
virtual const wxEventTable* GetEventTable() const;
|
|
||||||
|
virtual const wxEventTable *GetEventTable() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxEvtHandler* m_nextHandler;
|
wxEvtHandler* m_nextHandler;
|
||||||
wxEvtHandler* m_previousHandler;
|
wxEvtHandler* m_previousHandler;
|
||||||
bool m_enabled; // Is event handler enabled?
|
bool m_enabled; // Is event handler enabled?
|
||||||
wxList* m_dynamicEvents;
|
wxList* m_dynamicEvents;
|
||||||
|
|
||||||
|
// 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
|
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
|
||||||
|
@@ -96,6 +96,7 @@ wxEvent::wxEvent(int theId)
|
|||||||
m_id = theId;
|
m_id = theId;
|
||||||
m_skipped = FALSE;
|
m_skipped = FALSE;
|
||||||
m_callbackUserData = (wxObject *) NULL;
|
m_callbackUserData = (wxObject *) NULL;
|
||||||
|
m_isCommandEvent = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -112,6 +113,7 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
|
|||||||
m_commandInt = 0;
|
m_commandInt = 0;
|
||||||
m_id = theId;
|
m_id = theId;
|
||||||
m_commandString = (char *) NULL;
|
m_commandString = (char *) NULL;
|
||||||
|
m_isCommandEvent = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -280,6 +282,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxEvtHandler::~wxEvtHandler()
|
wxEvtHandler::~wxEvtHandler()
|
||||||
@@ -311,14 +314,15 @@ wxEvtHandler::~wxEvtHandler()
|
|||||||
|
|
||||||
bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||||
{
|
{
|
||||||
bool isWindow = IsKindOf(CLASSINFO(wxWindow));
|
// check that our flag corresponds to reality
|
||||||
|
wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) );
|
||||||
|
|
||||||
// An event handler can be enabled or disabled
|
// An event handler can be enabled or disabled
|
||||||
if ( GetEvtHandlerEnabled() )
|
if ( GetEvtHandlerEnabled() )
|
||||||
{
|
{
|
||||||
// Handle per-instance dynamic event tables first
|
// Handle per-instance dynamic event tables first
|
||||||
|
|
||||||
if (SearchDynamicEventTable( event ))
|
if ( m_dynamicEvents && SearchDynamicEventTable(event) )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
// Then static per-class event tables
|
// Then static per-class event tables
|
||||||
@@ -333,24 +337,26 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
// THIS CAN BE CURED if PushEventHandler is used instead of
|
// THIS CAN BE CURED if PushEventHandler is used instead of
|
||||||
// SetEventHandler, and then processing will be passed down the
|
// SetEventHandler, and then processing will be passed down the
|
||||||
// chain of event handlers.
|
// chain of event handlers.
|
||||||
if ( isWindow )
|
if ( m_isWindow )
|
||||||
{
|
{
|
||||||
wxWindow *win = (wxWindow *)this;
|
wxWindow *win = (wxWindow *)this;
|
||||||
|
|
||||||
// Can only use the validator of the window which
|
// Can only use the validator of the window which
|
||||||
// is receiving the event
|
// is receiving the event
|
||||||
if ( (win == event.GetEventObject()) &&
|
if ( win == event.GetEventObject() )
|
||||||
win->GetValidator() &&
|
|
||||||
win->GetValidator()->ProcessEvent(event))
|
|
||||||
{
|
{
|
||||||
return TRUE;
|
wxValidator *validator = win->GetValidator();
|
||||||
|
if ( validator && validator->ProcessEvent(event) )
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search upwards through the inheritance hierarchy
|
// Search upwards through the inheritance hierarchy
|
||||||
while (table)
|
while ( table )
|
||||||
{
|
{
|
||||||
if (SearchEventTable((wxEventTable&)*table, event))
|
if ( SearchEventTable((wxEventTable&)*table, event) )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
table = table->baseTable;
|
table = table->baseTable;
|
||||||
}
|
}
|
||||||
@@ -366,23 +372,25 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
// Carry on up the parent-child hierarchy,
|
// Carry on up the parent-child hierarchy,
|
||||||
// but only if event is a command event: it wouldn't
|
// 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
|
// make sense for a parent to receive a child's size event, for example
|
||||||
if ( isWindow && event.IsKindOf(CLASSINFO(wxCommandEvent)) )
|
if ( m_isWindow && event.IsCommandEvent() )
|
||||||
{
|
{
|
||||||
wxWindow *win = (wxWindow *)this;
|
wxWindow *win = (wxWindow *)this;
|
||||||
wxWindow *parent = win->GetParent();
|
wxWindow *parent = win->GetParent();
|
||||||
if (parent && !parent->IsBeingDeleted())
|
if (parent && !parent->IsBeingDeleted())
|
||||||
return win->GetParent()->GetEventHandler()->ProcessEvent(event);
|
return parent->GetEventHandler()->ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last try - application object.
|
// Last try - application object.
|
||||||
// Special case: don't pass wxEVT_IDLE to wxApp, since it'll always swallow
|
if ( wxTheApp && (this != wxTheApp) )
|
||||||
// it. wxEVT_IDLE is sent explicitly to wxApp so it will be processed
|
|
||||||
// appropriately via SearchEventTable.
|
|
||||||
if ( wxTheApp && (this != wxTheApp) && (event.GetEventType() != wxEVT_IDLE)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if ( wxTheApp->ProcessEvent(event) )
|
// Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
|
||||||
return TRUE;
|
// 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;
|
return FALSE;
|
||||||
@@ -442,7 +450,8 @@ void wxEvtHandler::Connect( int id, int lastId,
|
|||||||
|
|
||||||
bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
|
bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
|
||||||
{
|
{
|
||||||
if (!m_dynamicEvents) return FALSE;
|
wxCHECK_MSG( m_dynamicEvents, FALSE,
|
||||||
|
"caller should check that we have dynamic events" );
|
||||||
|
|
||||||
int commandId = event.GetId();
|
int commandId = event.GetId();
|
||||||
|
|
||||||
@@ -484,5 +493,5 @@ bool wxEvtHandler::OnClose()
|
|||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif // WXWIN_COMPATIBILITY
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user