]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/event.cpp
It was not acceptable to call the class method from the static initializer
[wxWidgets.git] / src / common / event.cpp
index 60ebe589a74ca32f5f5508653088f7e43c90d225..0c9cac8de1bb38716ef17688049b6e207edbf2b7 100644 (file)
@@ -120,8 +120,22 @@ wxList *wxPendingEvents = (wxList *)NULL;
 
 // common event types are defined here, other event types are defined by the
 // components which use them
+    
+const wxEventType wxEVT_FIRST = 10000;
+const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
 
 DEFINE_EVENT_TYPE(wxEVT_NULL)
+DEFINE_EVENT_TYPE(wxEVT_IDLE)
+DEFINE_EVENT_TYPE(wxEVT_SOCKET)
+
+#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
+
+#endif // wxUSE_BASE
+
+#if wxUSE_GUI
+
+#if !WXWIN_COMPATIBILITY_EVENT_TYPES
+
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
@@ -140,7 +154,6 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
 
 // Sockets and timers send events, too
-DEFINE_EVENT_TYPE(wxEVT_SOCKET)
 DEFINE_EVENT_TYPE(wxEVT_TIMER)
 
 // Mouse event types
@@ -245,7 +258,6 @@ DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
-DEFINE_EVENT_TYPE(wxEVT_IDLE)
 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
 
 // Generic command events
@@ -264,6 +276,10 @@ DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
 
 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
 
+#endif // wxUSE_GUI
+
+#if wxUSE_BASE
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -779,8 +795,6 @@ void wxEvtHandler::ProcessPendingEvents()
 #endif
 }
 
-#endif // wxUSE_BASE
-
 /*
  * Event table stuff
  */
@@ -821,24 +835,25 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
     // An event handler can be enabled or disabled
     if ( GetEvtHandlerEnabled() )
     {
-        // Handle per-instance dynamic event tables first
-        if ( m_dynamicEvents && SearchDynamicEventTable(event) )
-            return TRUE;
-
+        // if we have a validator, it has higher priority than our own event
+        // table
 #if wxUSE_VALIDATORS
         if ( TryValidator(event) )
             return TRUE;
 #endif // wxUSE_VALIDATORS
 
-        // Then static per-class event tables
-        const wxEventTable *table = GetEventTable();
+        // Handle per-instance dynamic event tables first
+        if ( m_dynamicEvents && SearchDynamicEventTable(event) )
+            return TRUE;
 
-        // Search upwards through the inheritance hierarchy
-        while (table)
+        // Then static per-class event tables (and search upwards through the
+        // inheritance hierarchy)
+        for ( const wxEventTable *table = GetEventTable();
+              table;
+              table = table->baseTable )
         {
             if ( SearchEventTable((wxEventTable&)*table, event) )
                 return TRUE;
-            table = table->baseTable;
         }
     }
 
@@ -849,11 +864,11 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
             return TRUE;
     }
 
+    // Finally propagate the event upwards the window chain and/or to the
+    // application object as necessary
     return TryParent(event);
 }
 
-#if wxUSE_BASE
-
 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
 {
     wxEventType eventType = event.GetEventType();
@@ -901,7 +916,8 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
 void wxEvtHandler::Connect( int id, int lastId,
                             int eventType,
                             wxObjectEventFunction func,
-                            wxObject *userData )
+                            wxObject *userData,
+                            wxEvtHandler* eventSink )
 {
 #if WXWIN_COMPATIBILITY_EVENT_TYPES
     wxEventTableEntry *entry = new wxEventTableEntry;
@@ -912,7 +928,7 @@ void wxEvtHandler::Connect( int id, int lastId,
     entry->m_callbackUserData = userData;
 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
     wxDynamicEventTableEntry *entry =
-        new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
+        new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
 
     if (!m_dynamicEvents)
@@ -924,7 +940,8 @@ void wxEvtHandler::Connect( int id, int lastId,
 
 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
                   wxObjectEventFunction func,
-                  wxObject *userData )
+                  wxObject *userData,
+                  wxEvtHandler* eventSink )
 {
     if (!m_dynamicEvents)
         return FALSE;
@@ -942,6 +959,7 @@ bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
             ((entry->m_lastId == lastId) || (lastId == -1)) &&
             ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
             ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
+            ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
             ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
         {
             if (entry->m_callbackUserData)
@@ -983,7 +1001,12 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
                 event.Skip(FALSE);
                 event.m_callbackUserData = entry->m_callbackUserData;
 
-                (this->*((wxEventFunction) (entry->m_fn)))(event);
+#if !WXWIN_COMPATIBILITY_EVENT_TYPES
+                if (entry->m_eventSink)
+                    ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event);
+                else
+#endif                    
+                    (this->*((wxEventFunction) (entry->m_fn)))(event);
 
                 if ( ! event.GetSkipped() )
                     return TRUE;