small optimization in ProcessEvent() (IsKindOf(wxWindow) only called once)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1278 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -10,71 +10,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "event.h"
|
||||
#pragma implementation "event.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/defs.h"
|
||||
#include "wx/control.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/dc.h"
|
||||
#include "wx/defs.h"
|
||||
#include "wx/control.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/dc.h"
|
||||
#endif
|
||||
|
||||
#include "wx/event.h"
|
||||
#include "wx/validate.h"
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
|
||||
|
||||
const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; }
|
||||
const wxEventTable *wxEvtHandler::GetEventTable() const
|
||||
{ return &wxEvtHandler::sm_eventTable; }
|
||||
|
||||
const wxEventTable wxEvtHandler::sm_eventTable =
|
||||
{ (const wxEventTable *) NULL, &wxEvtHandler::sm_eventTableEntries[0] };
|
||||
const wxEventTable wxEvtHandler::sm_eventTable =
|
||||
{ (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
|
||||
|
||||
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0,
|
||||
#ifdef __SGI_CC__
|
||||
// stupid SGI compiler --- offer aug 98
|
||||
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
|
||||
{ { 0, 0, 0,
|
||||
#ifdef __SGI_CC__
|
||||
// stupid SGI compiler --- offer aug 98
|
||||
0L }
|
||||
#else
|
||||
#else // !SGI CC
|
||||
NULL }
|
||||
#endif
|
||||
};
|
||||
#endif // SGI/!SGI
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // !USE_SHARED_LIBRARY
|
||||
|
||||
/*
|
||||
* General wxWindows events, covering
|
||||
@@ -116,8 +118,11 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
|
||||
* Scroll events
|
||||
*/
|
||||
|
||||
wxScrollEvent::wxScrollEvent(wxEventType commandType, int id, int pos, int orient):
|
||||
wxCommandEvent(commandType, id)
|
||||
wxScrollEvent::wxScrollEvent(wxEventType commandType,
|
||||
int id,
|
||||
int pos,
|
||||
int orient)
|
||||
: wxCommandEvent(commandType, id)
|
||||
{
|
||||
m_extraLong = orient;
|
||||
m_commandInt = pos;
|
||||
@@ -147,7 +152,8 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
|
||||
// or any button dclick event (but = -1)
|
||||
bool wxMouseEvent::ButtonDClick(int but) const
|
||||
{
|
||||
switch (but) {
|
||||
switch (but)
|
||||
{
|
||||
case -1:
|
||||
return (LeftDClick() || MiddleDClick() || RightDClick());
|
||||
case 1:
|
||||
@@ -157,16 +163,18 @@ bool wxMouseEvent::ButtonDClick(int but) const
|
||||
case 3:
|
||||
return RightDClick();
|
||||
default:
|
||||
return FALSE;
|
||||
wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonDClick");
|
||||
}
|
||||
// NOTREACHED
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// True if was a button down event (1 = left, 2 = middle, 3 = right)
|
||||
// or any button down event (but = -1)
|
||||
bool wxMouseEvent::ButtonDown(int but) const
|
||||
{
|
||||
switch (but) {
|
||||
switch (but)
|
||||
{
|
||||
case -1:
|
||||
return (LeftDown() || MiddleDown() || RightDown());
|
||||
case 1:
|
||||
@@ -176,9 +184,10 @@ bool wxMouseEvent::ButtonDown(int but) const
|
||||
case 3:
|
||||
return RightDown();
|
||||
default:
|
||||
return FALSE;
|
||||
wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonDown");
|
||||
}
|
||||
// NOTREACHED
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// True if was a button up event (1 = left, 2 = middle, 3 = right)
|
||||
@@ -195,9 +204,10 @@ bool wxMouseEvent::ButtonUp(int but) const
|
||||
case 3:
|
||||
return RightUp();
|
||||
default:
|
||||
return FALSE;
|
||||
wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonUp");
|
||||
}
|
||||
// NOTREACHED
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// True if the given button is currently changing state
|
||||
@@ -213,9 +223,10 @@ bool wxMouseEvent::Button(int but) const
|
||||
case 3:
|
||||
return (RightDown() || RightUp() || RightDClick());
|
||||
default:
|
||||
return FALSE;
|
||||
wxFAIL_MSG("invalid parameter in wxMouseEvent::Button");
|
||||
}
|
||||
// NOTREACHED
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxMouseEvent::ButtonIsDown(int but) const
|
||||
@@ -230,9 +241,10 @@ bool wxMouseEvent::ButtonIsDown(int but) const
|
||||
case 3:
|
||||
return RightIsDown();
|
||||
default:
|
||||
return FALSE;
|
||||
wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonIsDown");
|
||||
}
|
||||
// NOTREACHED
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Find the logical position of the event given the DC
|
||||
@@ -262,7 +274,7 @@ wxKeyEvent::wxKeyEvent(wxEventType type)
|
||||
* Event handler
|
||||
*/
|
||||
|
||||
wxEvtHandler::wxEvtHandler(void)
|
||||
wxEvtHandler::wxEvtHandler()
|
||||
{
|
||||
m_nextHandler = (wxEvtHandler *) NULL;
|
||||
m_previousHandler = (wxEvtHandler *) NULL;
|
||||
@@ -270,7 +282,7 @@ wxEvtHandler::wxEvtHandler(void)
|
||||
m_dynamicEvents = (wxList *) NULL;
|
||||
}
|
||||
|
||||
wxEvtHandler::~wxEvtHandler(void)
|
||||
wxEvtHandler::~wxEvtHandler()
|
||||
{
|
||||
// Takes itself out of the list of handlers
|
||||
if (m_previousHandler)
|
||||
@@ -299,12 +311,15 @@ wxEvtHandler::~wxEvtHandler(void)
|
||||
|
||||
bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
bool isWindow = IsKindOf(CLASSINFO(wxWindow));
|
||||
|
||||
// An event handler can be enabled or disabled
|
||||
if ( GetEvtHandlerEnabled() )
|
||||
{
|
||||
// Handle per-instance dynamic event tables first
|
||||
|
||||
if (SearchDynamicEventTable( event )) return TRUE;
|
||||
if (SearchDynamicEventTable( event ))
|
||||
return TRUE;
|
||||
|
||||
// Then static per-class event tables
|
||||
|
||||
@@ -318,7 +333,7 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||
// THIS CAN BE CURED if PushEventHandler is used instead of
|
||||
// SetEventHandler, and then processing will be passed down the
|
||||
// chain of event handlers.
|
||||
if (IsKindOf(CLASSINFO(wxWindow)))
|
||||
if ( isWindow )
|
||||
{
|
||||
wxWindow *win = (wxWindow *)this;
|
||||
|
||||
@@ -327,8 +342,10 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||
if ( (win == event.GetEventObject()) &&
|
||||
win->GetValidator() &&
|
||||
win->GetValidator()->ProcessEvent(event))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Search upwards through the inheritance hierarchy
|
||||
while (table)
|
||||
@@ -349,7 +366,7 @@ bool wxEvtHandler::ProcessEvent(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 (IsKindOf(CLASSINFO(wxWindow)) && event.IsKindOf(CLASSINFO(wxCommandEvent)))
|
||||
if ( isWindow && event.IsKindOf(CLASSINFO(wxCommandEvent)) )
|
||||
{
|
||||
wxWindow *win = (wxWindow *)this;
|
||||
wxWindow *parent = win->GetParent();
|
||||
@@ -358,12 +375,16 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
|
||||
}
|
||||
|
||||
// Last try - application object.
|
||||
// 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 (wxTheApp && this != wxTheApp && (event.GetEventType() != wxEVT_IDLE) && wxTheApp->ProcessEvent(event))
|
||||
// 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 ( wxTheApp && (this != wxTheApp) && (event.GetEventType() != wxEVT_IDLE)
|
||||
)
|
||||
{
|
||||
if ( wxTheApp->ProcessEvent(event) )
|
||||
return TRUE;
|
||||
else
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -392,7 +413,7 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
i ++;
|
||||
i++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -428,11 +449,12 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
|
||||
|
||||
if (entry->m_fn)
|
||||
{
|
||||
if ((event.GetEventType() == entry->m_eventType) &&
|
||||
(entry->m_id == -1 || // Match, if event spec says any id will do (id == -1)
|
||||
// Match, if event spec says any id will do (id == -1)
|
||||
if ( (event.GetEventType() == entry->m_eventType) &&
|
||||
(entry->m_id == -1 ||
|
||||
(entry->m_lastId == -1 && commandId == entry->m_id) ||
|
||||
(entry->m_lastId != -1 &&
|
||||
(commandId >= entry->m_id && commandId <= entry->m_lastId))))
|
||||
(commandId >= entry->m_id && commandId <= entry->m_lastId))) )
|
||||
{
|
||||
event.Skip(FALSE);
|
||||
event.m_callbackUserData = entry->m_callbackUserData;
|
||||
@@ -450,10 +472,10 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
bool wxEvtHandler::OnClose(void)
|
||||
bool wxEvtHandler::OnClose()
|
||||
{
|
||||
if (GetNextHandler()) return GetNextHandler()->OnClose();
|
||||
else return FALSE;
|
||||
if (GetNextHandler())
|
||||
return GetNextHandler()->OnClose();
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user