#endif
#include "wx/event.h"
+#include "wx/module.h"
#if wxUSE_GUI
#include "wx/validate.h"
const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
{ DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
+
+#ifdef __WXDEBUG__
+// Clear up event hash table contents or we can get problems
+// when C++ is cleaning up the static object
+class wxEventTableEntryModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule)
+public:
+ wxEventTableEntryModule() {}
+ bool OnInit() { return true; }
+ void OnExit()
+ {
+ wxEventHashTable::ClearAll();
+ }
+};
+IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule)
+#endif
+
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
m_linesPerAction = event.m_linesPerAction;
}
-// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
-// or any button dclick event (but = -1)
+// return true if was a button dclick event
bool wxMouseEvent::ButtonDClick(int but) const
{
switch (but)
{
- case -1:
+ default:
+ wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
+ // fall through
+
+ case wxMOUSE_BTN_ANY:
return (LeftDClick() || MiddleDClick() || RightDClick());
- case 1:
+
+ case wxMOUSE_BTN_LEFT:
return LeftDClick();
- case 2:
+
+ case wxMOUSE_BTN_MIDDLE:
return MiddleDClick();
- case 3:
+
+ case wxMOUSE_BTN_RIGHT:
return RightDClick();
- default:
- wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
}
-
- return false;
}
-// True if was a button down event (1 = left, 2 = middle, 3 = right)
-// or any button down event (but = -1)
+// return true if was a button down event
bool wxMouseEvent::ButtonDown(int but) const
{
switch (but)
{
- case -1:
+ default:
+ wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
+ // fall through
+
+ case wxMOUSE_BTN_ANY:
return (LeftDown() || MiddleDown() || RightDown());
- case 1:
+
+ case wxMOUSE_BTN_LEFT:
return LeftDown();
- case 2:
+
+ case wxMOUSE_BTN_MIDDLE:
return MiddleDown();
- case 3:
+
+ case wxMOUSE_BTN_RIGHT:
return RightDown();
- default:
- wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
}
-
- return false;
}
-// True if was a button up event (1 = left, 2 = middle, 3 = right)
-// or any button up event (but = -1)
+// return true if was a button up event
bool wxMouseEvent::ButtonUp(int but) const
{
switch (but)
{
- case -1:
+ default:
+ wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
+ // fall through
+
+ case wxMOUSE_BTN_ANY:
return (LeftUp() || MiddleUp() || RightUp());
- case 1:
+
+ case wxMOUSE_BTN_LEFT:
return LeftUp();
- case 2:
+
+ case wxMOUSE_BTN_MIDDLE:
return MiddleUp();
- case 3:
+
+ case wxMOUSE_BTN_RIGHT:
return RightUp();
- default:
- wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
}
-
- return false;
}
-// True if the given button is currently changing state
+// return true if the given button is currently changing state
bool wxMouseEvent::Button(int but) const
{
switch (but)
{
- case -1:
- return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
- case 1:
- return (LeftDown() || LeftUp() || LeftDClick());
- case 2:
- return (MiddleDown() || MiddleUp() || MiddleDClick());
- case 3:
- return (RightDown() || RightUp() || RightDClick());
default:
wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
- }
+ // fall through
- return false;
+ case wxMOUSE_BTN_ANY:
+ return ButtonUp(wxMOUSE_BTN_ANY) ||
+ ButtonDown(wxMOUSE_BTN_ANY) ||
+ ButtonDClick(wxMOUSE_BTN_ANY);
+
+ case wxMOUSE_BTN_LEFT:
+ return LeftDown() || LeftUp() || LeftDClick();
+
+ case wxMOUSE_BTN_MIDDLE:
+ return MiddleDown() || MiddleUp() || MiddleDClick();
+
+ case wxMOUSE_BTN_RIGHT:
+ return RightDown() || RightUp() || RightDClick();
+ }
}
bool wxMouseEvent::ButtonIsDown(int but) const
{
switch (but)
{
- case -1:
- return (LeftIsDown() || MiddleIsDown() || RightIsDown());
- case 1:
+ default:
+ wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
+ // fall through
+
+ case wxMOUSE_BTN_ANY:
+ return LeftIsDown() || MiddleIsDown() || RightIsDown();
+
+ case wxMOUSE_BTN_LEFT:
return LeftIsDown();
- case 2:
+
+ case wxMOUSE_BTN_MIDDLE:
return MiddleIsDown();
- case 3:
+
+ case wxMOUSE_BTN_RIGHT:
return RightIsDown();
- default:
- wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
}
-
- return false;
}
int wxMouseEvent::GetButton() const
}
}
- return -1;
+ return wxMOUSE_BTN_NONE;
}
// Find the logical position of the event given the DC
// wxEventHashTable
// ----------------------------------------------------------------------------
-static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not to big not to small...
+static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not too big not too small...
+
+wxEventHashTable* wxEventHashTable::sm_first = NULL;
wxEventHashTable::wxEventHashTable(const wxEventTable &table)
: m_table(table),
m_rebuildHash(true)
{
AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
+
+ m_next = sm_first;
+ if (m_next)
+ m_next->m_previous = this;
+ sm_first = this;
}
wxEventHashTable::~wxEventHashTable()
+{
+ if (m_next)
+ m_next->m_previous = m_previous;
+ if (m_previous)
+ m_previous->m_next = m_next;
+ if (sm_first == this)
+ sm_first = m_next;
+
+ Clear();
+}
+
+void wxEventHashTable::Clear()
{
size_t i;
for(i = 0; i < m_size; i++)
}
}
- delete[] m_eventTypeTable;
+ // Necessary in order to not invoke the
+ // overloaded delete operator when statics are cleaned up
+ if (m_eventTypeTable)
+ delete[] m_eventTypeTable;
+
+ m_eventTypeTable = NULL;
+ m_size = 0;
+}
+
+// Clear all tables
+void wxEventHashTable::ClearAll()
+{
+ wxEventHashTable* table = sm_first;
+ while (table)
+ {
+ table->Clear();
+ table = table->m_next;
+ }
}
bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
InitHashTable();
m_rebuildHash = false;
}
+
+ if (!m_eventTypeTable)
+ return FALSE;
// Find all entries for the given event type.
wxEventType eventType = event.GetEventType();
void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
{
+ // This might happen 'accidentally' as the app is exiting
+ if (!m_eventTypeTable)
+ return;
+
EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
EventTypeTablePointer eTTnode = *peTTnode;
delete[] oldEventTypeTable;
}
+
// ----------------------------------------------------------------------------
// wxEvtHandler
// ----------------------------------------------------------------------------
void wxEvtHandler::ProcessPendingEvents()
{
+ // DE: It doesn't look like this method was intended to be called unless
+ // pending events have already been created.
+ wxASSERT_MSG(m_pendingEvents,wxT("Please call wxApp::ProcessPendingEvents() instead"));
#if defined(__VISAGECPP__)
wxENTER_CRIT_SECT( m_eventsLocker);
#else
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
- if ((event.m_eventType == entry->m_eventType) && entry->m_fn)
+ if ((event.m_eventType == entry->m_eventType) && (entry->m_fn != 0))
{
wxEvtHandler *handler =
#if !WXWIN_COMPATIBILITY_EVENT_TYPES