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:
Vadim Zeitlin
1998-12-29 15:25:07 +00:00
parent 3b1de9c2ee
commit 0b746ba805

View File

@@ -10,71 +10,73 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "event.h" #pragma implementation "event.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/control.h" #include "wx/control.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/dc.h" #include "wx/dc.h"
#endif #endif
#include "wx/event.h" #include "wx/event.h"
#include "wx/validate.h" #include "wx/validate.h"
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent) IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, 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 wxEvtHandler::sm_eventTable =
{ (const wxEventTable *) NULL, &wxEvtHandler::sm_eventTableEntries[0] }; { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
#ifdef __SGI_CC__ { { 0, 0, 0,
// stupid SGI compiler --- offer aug 98 #ifdef __SGI_CC__
// stupid SGI compiler --- offer aug 98
0L } 0L }
#else #else // !SGI CC
NULL } NULL }
#endif #endif // SGI/!SGI
}; };
#endif #endif // !USE_SHARED_LIBRARY
/* /*
* General wxWindows events, covering * General wxWindows events, covering
@@ -116,8 +118,11 @@ wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
* Scroll events * Scroll events
*/ */
wxScrollEvent::wxScrollEvent(wxEventType commandType, int id, int pos, int orient): wxScrollEvent::wxScrollEvent(wxEventType commandType,
wxCommandEvent(commandType, id) int id,
int pos,
int orient)
: wxCommandEvent(commandType, id)
{ {
m_extraLong = orient; m_extraLong = orient;
m_commandInt = pos; m_commandInt = pos;
@@ -147,7 +152,8 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
// or any button dclick event (but = -1) // or any button dclick event (but = -1)
bool wxMouseEvent::ButtonDClick(int but) const bool wxMouseEvent::ButtonDClick(int but) const
{ {
switch (but) { switch (but)
{
case -1: case -1:
return (LeftDClick() || MiddleDClick() || RightDClick()); return (LeftDClick() || MiddleDClick() || RightDClick());
case 1: case 1:
@@ -157,16 +163,18 @@ bool wxMouseEvent::ButtonDClick(int but) const
case 3: case 3:
return RightDClick(); return RightDClick();
default: 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) // True if was a button down event (1 = left, 2 = middle, 3 = right)
// or any button down event (but = -1) // or any button down event (but = -1)
bool wxMouseEvent::ButtonDown(int but) const bool wxMouseEvent::ButtonDown(int but) const
{ {
switch (but) { switch (but)
{
case -1: case -1:
return (LeftDown() || MiddleDown() || RightDown()); return (LeftDown() || MiddleDown() || RightDown());
case 1: case 1:
@@ -176,9 +184,10 @@ bool wxMouseEvent::ButtonDown(int but) const
case 3: case 3:
return RightDown(); return RightDown();
default: 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) // 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: case 3:
return RightUp(); return RightUp();
default: default:
return FALSE; wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonUp");
} }
// NOTREACHED
return FALSE;
} }
// True if the given button is currently changing state // True if the given button is currently changing state
@@ -213,9 +223,10 @@ bool wxMouseEvent::Button(int but) const
case 3: case 3:
return (RightDown() || RightUp() || RightDClick()); return (RightDown() || RightUp() || RightDClick());
default: default:
return FALSE; wxFAIL_MSG("invalid parameter in wxMouseEvent::Button");
} }
// NOTREACHED
return FALSE;
} }
bool wxMouseEvent::ButtonIsDown(int but) const bool wxMouseEvent::ButtonIsDown(int but) const
@@ -230,9 +241,10 @@ bool wxMouseEvent::ButtonIsDown(int but) const
case 3: case 3:
return RightIsDown(); return RightIsDown();
default: default:
return FALSE; wxFAIL_MSG("invalid parameter in wxMouseEvent::ButtonIsDown");
} }
// NOTREACHED
return FALSE;
} }
// Find the logical position of the event given the DC // Find the logical position of the event given the DC
@@ -262,7 +274,7 @@ wxKeyEvent::wxKeyEvent(wxEventType type)
* Event handler * Event handler
*/ */
wxEvtHandler::wxEvtHandler(void) wxEvtHandler::wxEvtHandler()
{ {
m_nextHandler = (wxEvtHandler *) NULL; m_nextHandler = (wxEvtHandler *) NULL;
m_previousHandler = (wxEvtHandler *) NULL; m_previousHandler = (wxEvtHandler *) NULL;
@@ -270,7 +282,7 @@ wxEvtHandler::wxEvtHandler(void)
m_dynamicEvents = (wxList *) NULL; m_dynamicEvents = (wxList *) NULL;
} }
wxEvtHandler::~wxEvtHandler(void) wxEvtHandler::~wxEvtHandler()
{ {
// Takes itself out of the list of handlers // Takes itself out of the list of handlers
if (m_previousHandler) if (m_previousHandler)
@@ -299,12 +311,15 @@ wxEvtHandler::~wxEvtHandler(void)
bool wxEvtHandler::ProcessEvent(wxEvent& event) bool wxEvtHandler::ProcessEvent(wxEvent& event)
{ {
bool 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 )) return TRUE; if (SearchDynamicEventTable( event ))
return TRUE;
// Then static per-class event tables // 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 // 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 (IsKindOf(CLASSINFO(wxWindow))) if ( isWindow )
{ {
wxWindow *win = (wxWindow *)this; wxWindow *win = (wxWindow *)this;
@@ -327,8 +342,10 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
if ( (win == event.GetEventObject()) && if ( (win == event.GetEventObject()) &&
win->GetValidator() && win->GetValidator() &&
win->GetValidator()->ProcessEvent(event)) win->GetValidator()->ProcessEvent(event))
{
return TRUE; return TRUE;
} }
}
// Search upwards through the inheritance hierarchy // Search upwards through the inheritance hierarchy
while (table) while (table)
@@ -349,7 +366,7 @@ 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 (IsKindOf(CLASSINFO(wxWindow)) && event.IsKindOf(CLASSINFO(wxCommandEvent))) if ( isWindow && event.IsKindOf(CLASSINFO(wxCommandEvent)) )
{ {
wxWindow *win = (wxWindow *)this; wxWindow *win = (wxWindow *)this;
wxWindow *parent = win->GetParent(); wxWindow *parent = win->GetParent();
@@ -358,12 +375,16 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
} }
// Last try - application object. // Last try - application object.
// Special case: don't pass wxEVT_IDLE to wxApp, since it'll always swallow it. // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always swallow
// wxEVT_IDLE is sent explicitly to wxApp so it will be processed appropriately // it. wxEVT_IDLE is sent explicitly to wxApp so it will be processed
// via SearchEventTable. // appropriately via SearchEventTable.
if (wxTheApp && this != wxTheApp && (event.GetEventType() != wxEVT_IDLE) && wxTheApp->ProcessEvent(event)) if ( wxTheApp && (this != wxTheApp) && (event.GetEventType() != wxEVT_IDLE)
)
{
if ( wxTheApp->ProcessEvent(event) )
return TRUE; return TRUE;
else }
return FALSE; return FALSE;
} }
@@ -392,7 +413,7 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
else else
return TRUE; return TRUE;
} }
i ++; i++;
} }
return FALSE; return FALSE;
} }
@@ -428,11 +449,12 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
if (entry->m_fn) if (entry->m_fn)
{ {
if ((event.GetEventType() == entry->m_eventType) && // Match, if event spec says any id will do (id == -1)
(entry->m_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) ||
(entry->m_lastId != -1 && (entry->m_lastId != -1 &&
(commandId >= entry->m_id && commandId <= entry->m_lastId)))) (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
{ {
event.Skip(FALSE); event.Skip(FALSE);
event.m_callbackUserData = entry->m_callbackUserData; event.m_callbackUserData = entry->m_callbackUserData;
@@ -450,10 +472,10 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
return FALSE; return FALSE;
}; };
bool wxEvtHandler::OnClose(void) bool wxEvtHandler::OnClose()
{ {
if (GetNextHandler()) return GetNextHandler()->OnClose(); if (GetNextHandler())
else return FALSE; return GetNextHandler()->OnClose();
else
return FALSE;
} }