Index: src/common/event.cpp
===================================================================
--- src/common/event.cpp	(revision 55693)
+++ src/common/event.cpp	(working copy)
@@ -115,7 +115,7 @@
 wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable);
 
 const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
-    { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
+    { DECLARE_EVENT_TABLE_TERMINATOR() };
 
 
 // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
@@ -158,8 +158,8 @@
 const wxEventType wxEVT_FIRST = 10000;
 const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
 
-DEFINE_EVENT_TYPE(wxEVT_NULL)
-DEFINE_EVENT_TYPE(wxEVT_IDLE)
+wxDEFINE_EVENT(wxEVT_NULL, wxEvent)
+wxDEFINE_EVENT(wxEVT_IDLE, wxIdleEvent)
 DEFINE_EVENT_TYPE(wxEVT_SOCKET)
 DEFINE_EVENT_TYPE(wxEVT_TIMER)
 
@@ -167,48 +167,48 @@
 
 #if wxUSE_GUI
 
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED)
+wxDEFINE_EVENT(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent)
 
 // Mouse event types
-DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
-DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
-DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
-DEFINE_EVENT_TYPE(wxEVT_MOTION)
-DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
-DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
-DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
-DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
-DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
-DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
-DEFINE_EVENT_TYPE(wxEVT_AUX1_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_AUX1_UP)
-DEFINE_EVENT_TYPE(wxEVT_AUX1_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_AUX2_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_AUX2_UP)
-DEFINE_EVENT_TYPE(wxEVT_AUX2_DCLICK)
+wxDEFINE_EVENT(wxEVT_LEFT_DOWN, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_LEFT_UP, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_MIDDLE_DOWN, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_MIDDLE_UP, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_RIGHT_DOWN, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_RIGHT_UP, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_MOTION, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_ENTER_WINDOW, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_LEAVE_WINDOW, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_LEFT_DCLICK, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_MIDDLE_DCLICK, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_RIGHT_DCLICK, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_SET_FOCUS, wxFocusEvent)
+wxDEFINE_EVENT(wxEVT_KILL_FOCUS, wxFocusEvent)
+wxDEFINE_EVENT(wxEVT_CHILD_FOCUS, wxChildFocusEvent)
+wxDEFINE_EVENT(wxEVT_MOUSEWHEEL, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX1_DOWN, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX1_UP, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX1_DCLICK, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX2_DOWN, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX2_UP, wxMouseEvent)
+wxDEFINE_EVENT(wxEVT_AUX2_DCLICK, wxMouseEvent)
 
 // Non-client mouse events
 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
@@ -225,101 +225,101 @@
 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
 
 // Character input event type
-DEFINE_EVENT_TYPE(wxEVT_CHAR)
-DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
-DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
-DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
+wxDEFINE_EVENT(wxEVT_CHAR, wxKeyEvent)
+wxDEFINE_EVENT(wxEVT_CHAR_HOOK, wxKeyEvent)
+wxDEFINE_EVENT(wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent)
+wxDEFINE_EVENT(wxEVT_KEY_DOWN, wxKeyEvent)
+wxDEFINE_EVENT(wxEVT_KEY_UP, wxKeyEvent)
 #if wxUSE_HOTKEY
-DEFINE_EVENT_TYPE(wxEVT_HOTKEY)
+wxDEFINE_EVENT_TYPE(wxEVT_HOTKEY, wxKeyEvent)
 #endif
 
 // Set cursor event
-DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
+wxDEFINE_EVENT(wxEVT_SET_CURSOR, wxSetCursorEvent)
 
 // wxScrollbar and wxSlider event identifiers
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
-DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED)
+wxDEFINE_EVENT(wxEVT_SCROLL_TOP, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_BOTTOM, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_LINEUP, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_LINEDOWN, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_PAGEUP, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_PAGEDOWN, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_THUMBTRACK, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent)
+wxDEFINE_EVENT(wxEVT_SCROLL_CHANGED, wxScrollEvent)
 
 // Scroll events from wxWindow
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
-DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_TOP, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent)
+wxDEFINE_EVENT(wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent)
 
 // System events
-DEFINE_EVENT_TYPE(wxEVT_SIZE)
-DEFINE_EVENT_TYPE(wxEVT_SIZING)
-DEFINE_EVENT_TYPE(wxEVT_MOVE)
-DEFINE_EVENT_TYPE(wxEVT_MOVING)
-DEFINE_EVENT_TYPE(wxEVT_MOVE_START)
-DEFINE_EVENT_TYPE(wxEVT_MOVE_END)
-DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
-DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
-DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
-DEFINE_EVENT_TYPE(wxEVT_HIBERNATE)
-DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
-DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
-DEFINE_EVENT_TYPE(wxEVT_CREATE)
-DEFINE_EVENT_TYPE(wxEVT_DESTROY)
-DEFINE_EVENT_TYPE(wxEVT_SHOW)
-DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
-DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
-DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_LOST)
-DEFINE_EVENT_TYPE(wxEVT_PAINT)
-DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
-DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
+wxDEFINE_EVENT(wxEVT_SIZE, wxSizeEvent)
+wxDEFINE_EVENT(wxEVT_SIZING, wxSizeEvent)
+wxDEFINE_EVENT(wxEVT_MOVE, wxMoveEvent)
+wxDEFINE_EVENT(wxEVT_MOVING, wxMoveEvent)
+wxDEFINE_EVENT(wxEVT_MOVE_START, wxMoveEvent)
+wxDEFINE_EVENT(wxEVT_MOVE_END, wxMoveEvent)
+wxDEFINE_EVENT(wxEVT_CLOSE_WINDOW, wxCloseEvent)
+wxDEFINE_EVENT(wxEVT_END_SESSION, wxCloseEvent)
+wxDEFINE_EVENT(wxEVT_QUERY_END_SESSION, wxCloseEvent)
+wxDEFINE_EVENT(wxEVT_HIBERNATE, wxActivateEvent)
+wxDEFINE_EVENT(wxEVT_ACTIVATE_APP, wxActivateEvent)
+wxDEFINE_EVENT(wxEVT_ACTIVATE, wxActivateEvent)
+wxDEFINE_EVENT(wxEVT_CREATE, wxWindowCreateEvent)
+wxDEFINE_EVENT(wxEVT_DESTROY, wxWindowDestroyEvent)
+wxDEFINE_EVENT(wxEVT_SHOW, wxShowEvent)
+wxDEFINE_EVENT(wxEVT_ICONIZE, wxIconizeEvent)
+wxDEFINE_EVENT(wxEVT_MAXIMIZE, wxMaximizeEvent)
+wxDEFINE_EVENT(wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent)
+wxDEFINE_EVENT(wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent)
+wxDEFINE_EVENT(wxEVT_PAINT, wxPaintEvent)
+wxDEFINE_EVENT(wxEVT_ERASE_BACKGROUND, wxEraseEvent)
+wxDEFINE_EVENT(wxEVT_NC_PAINT, wxNcPaintEvent)
 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
-DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
-DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
-DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
-DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
-DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
+wxDEFINE_EVENT(wxEVT_MENU_OPEN, wxMenuEvent)
+wxDEFINE_EVENT(wxEVT_MENU_CLOSE, wxMenuEvent)
+wxDEFINE_EVENT(wxEVT_MENU_HIGHLIGHT, wxMenuEvent)
+wxDEFINE_EVENT(wxEVT_CONTEXT_MENU, wxContextMenuEvent)
+wxDEFINE_EVENT(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent)
+wxDEFINE_EVENT(wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent)
 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
-DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
-DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
-DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
-DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
-DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
-DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
+wxDEFINE_EVENT(wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent)
+wxDEFINE_EVENT(wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent)
+wxDEFINE_EVENT(wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent)
+wxDEFINE_EVENT(wxEVT_JOY_BUTTON_UP, wxJoystickEvent)
+wxDEFINE_EVENT(wxEVT_JOY_MOVE, wxJoystickEvent)
+wxDEFINE_EVENT(wxEVT_JOY_ZMOVE, wxJoystickEvent)
+wxDEFINE_EVENT(wxEVT_DROP_FILES, wxDropFilesEvent)
 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_UPDATE_UI)
+wxDEFINE_EVENT(wxEVT_INIT_DIALOG, wxInitDialogEvent)
+wxDEFINE_EVENT(wxEVT_UPDATE_UI, wxUpdateUIEvent)
 
 // Clipboard events
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_COPY)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_CUT)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_PASTE)
+wxDEFINE_EVENT(wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent)
 
 // Generic command events
 // Note: a click is a higher-level event than button down/up
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
+wxDEFINE_EVENT(wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_SET_FOCUS, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent)
+wxDEFINE_EVENT(wxEVT_COMMAND_ENTER, wxCommandEvent)
 
 // Help events
-DEFINE_EVENT_TYPE(wxEVT_HELP)
-DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
+wxDEFINE_EVENT(wxEVT_HELP, wxHelpEvent)
+wxDEFINE_EVENT(wxEVT_DETAILED_HELP, wxHelpEvent)
 
 #endif // wxUSE_GUI
 
@@ -925,7 +925,7 @@
     {
         // Retrieve all valid event handler entries
         const wxEventTableEntry *entry = table->entries;
-        while (entry->m_fn != 0)
+        while (entry->m_eventType != wxEVT_NULL)
         {
             // Add the event entry in the Hash.
             AddEntry(*entry);
@@ -1023,6 +1023,16 @@
 }
 
 // ----------------------------------------------------------------------------
+// wxEventConnection
+// ----------------------------------------------------------------------------
+void wxEventConnection::Disconnect()
+{
+    wxEvtHandler* handler = m_handler.get();
+    if(handler)
+        handler->Disconnect(*this);
+}
+
+// ----------------------------------------------------------------------------
 // wxEvtHandler
 // ----------------------------------------------------------------------------
 
@@ -1255,13 +1265,13 @@
             // call the handler via wxApp method which allows the user to catch
             // any exceptions which may be thrown by any handler in the program
             // in one place
-            wxTheApp->HandleEvent(handler, (wxEventFunction)entry.m_fn, event);
+            wxTheApp->HandleEvent(handler, entry.m_fn, event);
         }
         else
 #endif // wxUSE_EXCEPTIONS
         {
             // no need for an extra virtual function call
-            (handler->*((wxEventFunction) (entry.m_fn)))(event);
+            entry.m_fn->Relay(handler, event);
         }
 
         if (!event.GetSkipped())
@@ -1388,15 +1398,8 @@
     return false;
 }
 
-void wxEvtHandler::Connect( int id, int lastId,
-                            int eventType,
-                            wxObjectEventFunction func,
-                            wxObject *userData,
-                            wxEvtHandler* eventSink )
+wxEventConnection wxEvtHandler::Connect( wxDynamicEventTableEntry* entry )
 {
-    wxDynamicEventTableEntry *entry =
-        new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
-
     if (!m_dynamicEvents)
         m_dynamicEvents = new wxList;
 
@@ -1404,6 +1407,7 @@
     m_dynamicEvents->Insert( (wxObject*) entry );
 
     // Make sure we get to know when a sink is destroyed
+    wxEvtHandler* eventSink = entry->m_fn->GetFunctorObject();
     if ( eventSink && eventSink != this )
     {
         wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink);
@@ -1412,6 +1416,8 @@
         else
             evtConnRef = new wxEventConnectionRef(this, eventSink);
     }
+
+    return wxEventConnection(this, entry->m_fn);
 }
 
 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
@@ -1438,8 +1444,8 @@
         if ((entry->m_id == id) &&
             ((entry->m_lastId == lastId) || (lastId == wxID_ANY)) &&
             ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
-            ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
-            ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
+            ((entry->m_fn->GetFunctorMethod() == func) || (func == (wxObjectEventFunction)NULL)) &&
+            ((entry->m_fn->GetFunctorObject() == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
             ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
         {
             if (entry->m_callbackUserData)
@@ -1453,6 +1459,43 @@
     return false;
 }
 
+bool wxEvtHandler::Disconnect(wxEventConnection conn)
+{
+    // make sure it is ours
+    if(conn.GetEventHandler() != this)
+    {
+        return false;
+    }
+
+    // make sure it is active
+    wxEventFunctor* functor = conn.GetFunctor();
+    if(functor == NULL)
+    {
+        return false;
+    }
+
+    // Find it
+    // We can't just use the generic disconnect because it checks
+    // the m_id
+    wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
+    while(node)
+    {
+        wxDynamicEventTableEntry* entry = (wxDynamicEventTableEntry*)node->GetData();
+
+        if(entry->m_fn == functor)
+        {
+            if(entry->m_callbackUserData)
+                delete entry->m_callbackUserData;
+            m_dynamicEvents->Erase(node);
+            delete entry;
+            return true;
+        }
+        node = node->GetNext();
+    }
+    return false;
+
+}
+
 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
 {
     wxCHECK_MSG( m_dynamicEvents, false,
Index: src/common/appbase.cpp
===================================================================
--- src/common/appbase.cpp	(revision 55693)
+++ src/common/appbase.cpp	(working copy)
@@ -404,11 +404,11 @@
 
 void
 wxAppConsoleBase::HandleEvent(wxEvtHandler *handler,
-                              wxEventFunction func,
+                              wxEventFunctor* func,
                               wxEvent& event) const
 {
     // by default, simply call the handler
-    (handler->*func)(event);
+    func->Relay(handler, event);
 }
 
 void wxAppConsoleBase::OnUnhandledException()
Index: setup.h.in
===================================================================
--- setup.h.in	(revision 55693)
+++ setup.h.in	(working copy)
@@ -554,7 +554,9 @@
 #define wxUSE_THEME_MONO    0
 #define wxUSE_THEME_WIN32   0
 
+#define wxUSE_TYPESAFE_EVENTS 0
 
+
 /* --- end common options --- */
 
 /*
@@ -635,6 +637,11 @@
 #undef HAVE_STATIC_CAST
 
 /*
+ * Define if your compiler supports dynamic_cast<>()
+ */
+#undef HAVE_DYNAMIC_CAST
+
+/*
  * Define if your compiler has C99 va_copy
  */
 #undef HAVE_VA_COPY
Index: include/wx/app.h
===================================================================
--- include/wx/app.h	(revision 55693)
+++ include/wx/app.h	(working copy)
@@ -227,7 +227,7 @@
     // event handler, it would lead to an extra (useless) virtual function call
     // if the exceptions were not used, so it doesn't even exist in that case
     virtual void HandleEvent(wxEvtHandler *handler,
-                             wxEventFunction func,
+                             wxEventFunctor* func,
                              wxEvent& event) const;
 
     // Called when an unhandled C++ exception occurs inside OnRun(): note that
Index: include/wx/event.h
===================================================================
--- include/wx/event.h	(revision 55693)
+++ include/wx/event.h	(working copy)
@@ -25,12 +25,14 @@
 #include "wx/dynarray.h"
 #include "wx/thread.h"
 #include "wx/tracker.h"
+#include "wx/weakref.h"
 
 // ----------------------------------------------------------------------------
 // forward declarations
 // ----------------------------------------------------------------------------
 
 class WXDLLIMPEXP_FWD_BASE wxList;
+class WXDLLIMPEXP_FWD_BASE wxEvent;
 #if wxUSE_GUI
     class WXDLLIMPEXP_FWD_CORE wxDC;
     class WXDLLIMPEXP_FWD_CORE wxMenu;
@@ -58,6 +60,7 @@
 class WXDLLIMPEXP_FWD_BASE wxMSVC_FWD_MULTIPLE_BASES wxEvtHandler;
 class wxEventConnectionRef;
 
+
 // ----------------------------------------------------------------------------
 // Event types
 // ----------------------------------------------------------------------------
@@ -71,7 +74,9 @@
 #define wxStaticCastEvent(type, val) wx_static_cast(type, val)
 
 #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
-    wxEventTableEntry(type, winid, idLast, fn, obj)
+    wxEventTableEntry(type, winid, idLast, wxNewEventFunctor(type, fn), obj)
+#define DECLARE_EVENT_TABLE_TERMINATOR() \
+    wxEventTableEntry(wxEVT_NULL, 0, 0, 0, 0)
 
 // obsolete event declaration/definition macros, we don't need them any longer
 // but we keep them for compatibility as it doesn't cost us anything anyhow
@@ -89,173 +94,606 @@
 // generate a new unique event type
 extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
 
+// macros to create an event type depending on if modern events are used or not
+#if wxUSE_TYPESAFE_EVENTS
+    #define wxDECLARE_EVENT(expdecl, name, type) extern const expdecl wxTypedEventType<type> name;
+    #define wxDEFINE_EVENT(name, type) const wxTypedEventType<type> name(wxNewEventType());
+#else
+    #define wxDECLARE_EVENT(expdecl, name, type) extern const expdecl wxEventType name;
+    #define wxDEFINE_EVENT(name, type) const wxEventType name = wxNewEventType();
+#endif
+
+// Macro used by the handler casting
+#if wxUSE_TYPESAFE_EVENTS
+    #define wxEventHandlerCast(functype, func) &func
+#else
+    #define wxEventHandlerCast(functype, func) \
+        (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(functype, &func)
+#endif
+
+
+// template which associates the correct event object with the event type
+#if wxUSE_TYPESAFE_EVENTS
+template <typename Event >
+class WXDLLIMPEXP_BASE wxTypedEventType
+{
+public:
+    typedef Event CorrespondingEvent;
+
+    wxTypedEventType(wxEventType type)
+    {
+        m_type = type;
+    }
+
+    // used for static event tables
+    operator const wxEventType&() const
+    {
+        return m_type;
+    }
+
+private:
+    wxEventType m_type;
+};
+
+typedef wxTypedEventType<wxEvent> wxTypedEvent;
+
+#endif // wxUSE_TYPESAFE_EVENTS
+
+// These are needed for the functor definitions
+typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
+
+// We had some trouble (specifically with eVC for ARM WinCE build) with using
+// wxEventFunction in the past so we had introduced wxObjectEventFunction which
+// used to be a typedef for a member of wxObject and not wxEvtHandler to work
+// around this but as eVC is not really supported any longer we now only keep
+// this for backwards compatibility and, despite its name, this is a typedef
+// for wxEvtHandler member now -- but if we have the same problem with another
+// compiler we can restore its old definition for it.
+typedef wxEventFunction wxObjectEventFunction;
+
+
+// the functors which will be stored in the static/dynamic tables
+class WXDLLIMPEXP_BASE wxEventFunctor : public wxTrackable
+{
+public:
+    virtual ~wxEventFunctor()
+    {
+    }
+
+    virtual void Relay(wxEvtHandler*, wxEvent&) = 0;
+    virtual wxEvtHandler* GetFunctorObject()
+    {
+        return NULL;
+    }
+    virtual wxObjectEventFunction GetFunctorMethod()
+    {
+        return (wxObjectEventFunction)NULL;
+    }
+};
+
+#if wxUSE_TYPESAFE_EVENTS
+template < typename EventType >
+class WXDLLIMPEXP_BASE wxEventFunctorFunction : public wxEventFunctor
+{
+public:
+    typedef EventType TypedEventType;
+    typedef typename EventType::CorrespondingEvent CorrespondingEvent;
+
+    wxEventFunctorFunction( void ( *handler )( CorrespondingEvent & ))
+    {
+        m_handler = handler;
+    }
+
+    virtual void Relay( wxEvtHandler* WXUNUSED(handler), wxEvent &event )
+    {
+        // Protect against wrong event i.e. wxMouseEvent evt(wxEVT_PAINT):
+        wxASSERT( wx_dynamic_cast( CorrespondingEvent *, &event ) != NULL );
+
+        // Will throw a std::bad_cast exception in release build:
+        ( *m_handler )( wx_dynamic_cast( CorrespondingEvent &, event ));
+    }
+
+private:
+    void ( *m_handler )( CorrespondingEvent & );
+};
+
+
+template < typename EventType, typename Class, typename Derived >
+class WXDLLIMPEXP_BASE wxEventFunctorMethod : public wxEventFunctor
+{
+public:
+    typedef EventType TypedEventType;
+    typedef typename EventType::CorrespondingEvent CorrespondingEvent;
+
+    wxEventFunctorMethod( void ( Class::*method )( CorrespondingEvent & ), Derived *handler )
+    {
+        m_handler = handler;
+        m_method =  method;
+    }
+
+    virtual void Relay( wxEvtHandler* handler, wxEvent &event )
+    {
+        // Compile-time type check 1: This requires Derived to derive from or be of the same type as Class
+        Class *realHandler = m_handler;
+    
+        if( m_handler == NULL )
+        {
+            // Verify that the handler does indeed derive from the class containing the handler method
+            wxASSERT( wx_dynamic_cast(Class*, handler) != NULL);
+
+            realHandler = wx_dynamic_cast( Class *, handler );
+        }
+
+        // Protect against wrong event i.e. wxMouseEvent evt(wxEVT_PAINT):
+        wxASSERT( wx_dynamic_cast( CorrespondingEvent *, &event ) != NULL );
+
+        // Will throw a std::bad_cast exception in release build:
+        ( realHandler->*m_method )( wx_dynamic_cast( CorrespondingEvent &, event ));
+    }
+
+    virtual wxEvtHandler* GetFunctorObject( )
+    {
+        // This makes sure Derived derives from wxEvtHandler
+        // (it is still possible and even ok if Class does not
+        // derive from wxEvtHandler.  In this cass Derived would
+        // end up using multiple inheritance:
+        // class Derived : public wxEvtHandler, public Class { }
+        // where Class contains the method to call, but
+        // wxEvtHandler contains the wxTrackable and code for
+        // weak ref support
+        return m_handler;
+    }
+
+    virtual wxObjectEventFunction GetFunctorMethod( )
+    {
+        return (wxObjectEventFunction)m_method;
+    }
+
+private:
+    Derived *m_handler;
+    void ( Class::*m_method )( CorrespondingEvent & );
+};
+
+
+template < typename EventType, typename Functor >
+class WXDLLIMPEXP_BASE wxEventFunctorAdapter : public wxEventFunctor
+{
+public:
+    typedef EventType TypedEventType;
+    typedef typename EventType::CorrespondingEvent CorrespondingEvent;
+
+    wxEventFunctorAdapter( Functor &functor )
+    {
+        m_functor = functor;
+    }
+
+    virtual void Relay( wxEvtHandler* WXUNUSED(handler), wxEvent &event )
+    {
+        // Protect against wrong event i.e. wxMouseEvent evt(wxEVT_PAINT):
+        wxASSERT( wx_dynamic_cast( CorrespondingEvent *, &event ) != NULL );
+
+        // Will throw a std::bad_cast exception in release build:
+        m_functor( wx_dynamic_cast( CorrespondingEvent &, event ));
+    }
+private:
+    Functor m_functor;
+};
+
+// Specialization for EventType=wxEventType,
+// Class/Derived is ignored and internally treated as wxEvtHandler/wxEvtHandler
+// Should only get created by the corresponding wxNewEventFunctor
+template < typename Class, typename Derived >
+class WXDLLIMPEXP_BASE wxEventFunctorMethod< wxEventType, Class, Derived > : public wxEventFunctor
+{
+public:
+    // CorrespondingEvent is wxEvent
+    typedef wxTypedEvent TypedEventType;
+    typedef wxTypedEvent::CorrespondingEvent CorrespondingEvent;
+
+    wxEventFunctorMethod( wxObjectEventFunction method, wxEvtHandler *handler )
+    {
+        m_handler = handler;
+        m_method =  method;
+    }
+
+    virtual void Relay( wxEvtHandler* handler, wxEvent &event )
+    {
+        wxEvtHandler *realHandler = m_handler;
+    
+        if( m_handler == NULL )
+        {
+            realHandler = handler;
+        }
+
+        ( realHandler->*m_method )( event );
+    }
+
+    virtual wxEvtHandler* GetFunctorObject( )
+    {
+        return m_handler;
+    }
+
+    virtual wxObjectEventFunction GetFunctorMethod( )
+    {
+        return (wxObjectEventFunction)m_method;
+    }
+
+private:
+    wxEvtHandler *m_handler;
+    wxObjectEventFunction m_method;
+};
+
+#else // !wxUSE_TYPESAFE_EVENTS
+
+// A plain method functor
+class WXDLLIMPEXP_BASE wxEventFunctorMethod : public wxEventFunctor
+{
+public:
+    wxEventFunctorMethod( wxObjectEventFunction method, wxEvtHandler *handler )
+    {
+        m_handler = handler;
+        m_method =  method;
+    }
+
+    virtual void Relay( wxEvtHandler* handler, wxEvent &event )
+    {
+        wxEvtHandler* realHandler = m_handler;
+    
+        if( m_handler == NULL )
+        {
+            realHandler = handler;
+        }
+
+        ( realHandler->*m_method )( event );
+    }
+
+    virtual wxEvtHandler* GetFunctorObject( )
+    {
+        return m_handler;
+    }
+
+    virtual wxObjectEventFunction GetFunctorMethod( )
+    {
+        return m_method;
+    }
+
+private:
+    wxEvtHandler *m_handler;
+    wxObjectEventFunction m_method;
+};
+
+#endif // wxUSE_TYPESAFE_EVENT/!wxUSE_TYPESAFE_EVENTS
+
+
+// Helpers to create the functors
+
+#if wxUSE_TYPESAFE_EVENTS
+// Create a functor for the legacy events:
+
+inline wxEventFunctor *wxNewEventFunctor( wxEventType, void ( *function )( wxEvent & ))
+{
+    return ( new wxEventFunctorFunction< wxTypedEvent >( function ));
+}
+
+inline wxEventFunctor *wxNewEventFunctor( wxEventType, wxObjectEventFunction method, wxEvtHandler *handler = NULL )
+{
+    return ( new wxEventFunctorMethod< wxTypedEvent, wxEvtHandler, wxEvtHandler >( method, handler ));
+}
+
+// Create a functor for the correctly typed events:
+
+template < typename EventType, typename Event >
+inline wxEventFunctorFunction< EventType > *wxNewEventFunctor( const EventType &, void ( *function )( Event ))
+{
+    return ( new wxEventFunctorFunction< EventType >( function ));
+}
+
+template < typename EventType, typename Class, typename Event >
+inline wxEventFunctorMethod<EventType, Class, Class > *wxNewEventFunctor( const EventType &, void ( Class::*method )( Event ) )
+{
+    return ( new wxEventFunctorMethod< EventType, Class, Class >( method, NULL ));
+}
+
+template < typename EventType, typename Class, typename Event, typename Derived >
+inline wxEventFunctorMethod< EventType, Class, Derived > *wxNewEventFunctor( const EventType &, void ( Class::*method )( Event ), Derived *handler )
+{
+    return ( new wxEventFunctorMethod< EventType, Class, Derived >( method, handler ));
+}
+
+template < typename EventType, typename Functor >
+inline wxEventFunctorAdapter< EventType, Functor > *wxNewEventFunctor( const EventType &, Functor &functor )
+{
+    return ( new wxEventFunctorAdapter< EventType, Functor >( functor ));
+}
+
+// With EventType=int.  It is possible that user code may have a legacy event, but it's connection may call
+// a handler conversion that does 'not' convert it:
+// window.Connect(wxEVT_MY_COMMAND_EVENT, wxCommandEventHandler(MyWindow::OnAction), this)
+// These are needed for that and also because if 'this' isn't exactly wxEvtHandler*, then the call
+// will not match the member function but the template member function with an EventType=int
+template <typename Class, typename Event>
+inline wxEventFunctorMethod<wxEventType, Class, Class> *wxNewEventFunctor(wxEventType, void (Class::*method)(Event))
+{
+    // Must cast because the specialized version expects it
+    return new wxEventFunctorMethod<wxEventType, Class, Class>((wxObjectEventFunction)(wxEventFunction)method, NULL);
+}
+
+template <typename Class, typename Event, typename Derived>
+inline wxEventFunctorMethod<wxEventType, Class, Derived> *wxNewEventFunctor(wxEventType, void (Class::*method)(Event), Derived* handler)
+{
+    // Must cast because the specialized version expects it 
+    return new wxEventFunctorMethod<wxEventType, Class, Derived>((wxObjectEventFunction)(wxEventFunction)method, (wxEvtHandler*)handler);
+}
+
+
+#else // !wxUSE_TYPESAFE_EVENTS
+inline wxEventFunctor* wxNewEventFunctor(wxEventType, wxObjectEventFunction method, wxEvtHandler* handler)
+{
+    return new wxEventFunctorMethod(method, handler);
+}
+#endif // wxUSE_TYPESAFE_EVENTS/!wxUSE_TYPESAFE_EVENTS
+
+// An event connection
+class WXDLLIMPEXP_BASE wxEventConnection
+{
+public:
+    wxEventConnection()
+    {
+    }
+
+    wxEventConnection(const wxEventConnection& copy) :
+        m_handler(copy.m_handler), m_functor(copy.m_functor)
+    {
+    }
+
+    wxEventConnection(wxEvtHandler* handler, wxEventFunctor* functor) :
+        m_handler(handler), m_functor(functor)
+    {
+    }
+
+    // implicit destructor ok
+    
+    wxEventConnection& operator=(const wxEventConnection& rhs)
+    {
+        if(this != &rhs)
+        {
+            m_handler = rhs.m_handler;
+            m_functor = rhs.m_functor;
+        }
+        return *this;
+    }
+
+    // information
+    wxEvtHandler* GetEventHandler()
+    {
+        return m_handler.get();
+    }
+
+    wxEventFunctor* GetFunctor()
+    {
+        return m_functor.get();
+    }
+
+    bool IsConnected() const
+    {
+        return (m_handler.get() != NULL && m_functor.get() != NULL);
+    }
+
+    void Disconnect();
+private:
+    wxWeakRef<wxEvtHandler> m_handler;
+    wxWeakRef<wxEventFunctor> m_functor;
+};
+
 // many, but not all, standard event types
 
     // some generic events
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_NULL;
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_FIRST;
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_USER_FIRST;
+wxDECLARE_EVENT(WXDLLIMPEXP_BASE, wxEVT_NULL, wxEvent) // Used for event table terminator
+extern const WXDLLIMPEXP_BASE wxEventType wxEVT_FIRST;      // Do we really need these, since user events should use wxNewEventType()
+extern const WXDLLIMPEXP_BASE wxEventType wxEVT_USER_FIRST;
 
+    // Need events declared to do this
+class WXDLLIMPEXP_CORE wxCommandEvent;
+class WXDLLIMPEXP_CORE wxMouseEvent;
+class WXDLLIMPEXP_CORE wxFocusEvent;
+class WXDLLIMPEXP_CORE wxChildFocusEvent;
+class WXDLLIMPEXP_CORE wxKeyEvent;
+class WXDLLIMPEXP_CORE wxNavigationKeyEvent;
+class WXDLLIMPEXP_CORE wxSetCursorEvent;
+class WXDLLIMPEXP_CORE wxScrollEvent;
+class WXDLLIMPEXP_CORE wxScrollWinEvent;
+class WXDLLIMPEXP_CORE wxSizeEvent;
+class WXDLLIMPEXP_CORE wxMoveEvent;
+class WXDLLIMPEXP_CORE wxCloseEvent;
+class WXDLLIMPEXP_CORE wxActivateEvent;
+class WXDLLIMPEXP_CORE wxWindowCreateEvent;
+class WXDLLIMPEXP_CORE wxWindowDestroyEvent;
+class WXDLLIMPEXP_CORE wxShowEvent;
+class WXDLLIMPEXP_CORE wxIconizeEvent;
+class WXDLLIMPEXP_CORE wxMaximizeEvent;
+class WXDLLIMPEXP_CORE wxMouseCaptureChangedEvent;
+class WXDLLIMPEXP_CORE wxMouseCaptureLostEvent;
+class WXDLLIMPEXP_CORE wxPaintEvent;
+class WXDLLIMPEXP_CORE wxEraseEvent;
+class WXDLLIMPEXP_CORE wxNcPaintEvent;
+class WXDLLIMPEXP_CORE wxMenuEvent;
+class WXDLLIMPEXP_CORE wxContextMenuEvent;
+class WXDLLIMPEXP_CORE wxSysColourChangedEvent;
+class WXDLLIMPEXP_CORE wxDisplayChangedEvent;
+class WXDLLIMPEXP_CORE wxQueryNewPaletteEvent;
+class WXDLLIMPEXP_CORE wxPaletteChangedEvent;
+class WXDLLIMPEXP_CORE wxJoystickEvent;
+class WXDLLIMPEXP_CORE wxDropFilesEvent;
+class WXDLLIMPEXP_CORE wxInitDialogEvent;
+class WXDLLIMPEXP_CORE wxIdleEvent;
+class WXDLLIMPEXP_CORE wxUpdateUIEvent;
+class WXDLLIMPEXP_CORE wxClipboardTextEvent;
+class WXDLLIMPEXP_CORE wxHelpEvent;
+
+
     // Command events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_BUTTON_CLICKED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_CHECKBOX_CLICKED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_CHOICE_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_LISTBOX_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_CHECKLISTBOX_TOGGLED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_MENU_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SLIDER_UPDATED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_RADIOBOX_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_RADIOBUTTON_SELECTED;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent)
 
 // wxEVT_COMMAND_SCROLLBAR_UPDATED is deprecated, use wxEVT_SCROLL... events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SCROLLBAR_UPDATED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_VLBOX_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_COMBOBOX_SELECTED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOL_RCLICKED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TOOL_ENTER;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxCommandEvent)
 
     // Sockets and timers send events, too
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_SOCKET;
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_TIMER;
+//wxDECLARE_EVENT(WXDLLIMPEXP_BASE, wxEVT_SOCKET, wxSocketEvent)
+//wxDECLARE_EVENT(WXDLLIMPEXP_BASE, wxEVT_TIMER, wxTimerEvent)
+extern const WXDLLIMPEXP_BASE wxEventType wxEVT_SOCKET;
+extern const WXDLLIMPEXP_BASE wxEventType wxEVT_TIMER;
 
     // Mouse event types
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_LEFT_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_LEFT_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MIDDLE_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MIDDLE_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_RIGHT_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_RIGHT_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOTION;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_ENTER_WINDOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_LEAVE_WINDOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_LEFT_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MIDDLE_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_RIGHT_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SET_FOCUS;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_KILL_FOCUS;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CHILD_FOCUS;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOUSEWHEEL;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX1_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX1_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX1_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX2_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX2_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_AUX2_DCLICK;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DOWN, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_UP, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DOWN, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_UP, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DOWN, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_UP, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOTION, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_ENTER_WINDOW, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEAVE_WINDOW, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DCLICK, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DCLICK, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DCLICK, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_FOCUS, wxFocusEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_KILL_FOCUS, wxFocusEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHILD_FOCUS, wxChildFocusEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSEWHEEL, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DOWN, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_UP, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DCLICK, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DOWN, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_UP, wxMouseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DCLICK, wxMouseEvent)
 
     // Non-client mouse events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_LEFT_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_LEFT_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_MIDDLE_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_MIDDLE_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_RIGHT_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_RIGHT_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_MOTION;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_ENTER_WINDOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_LEAVE_WINDOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_LEFT_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_MIDDLE_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_RIGHT_DCLICK;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_LEFT_DOWN;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_LEFT_UP;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_MIDDLE_DOWN;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_MIDDLE_UP;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_RIGHT_DOWN;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_RIGHT_UP;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_MOTION;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_ENTER_WINDOW;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_LEAVE_WINDOW;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_LEFT_DCLICK;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_MIDDLE_DCLICK;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_NC_RIGHT_DCLICK;
 
     // Character input event type
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CHAR;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CHAR_HOOK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NAVIGATION_KEY;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_KEY_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_KEY_UP;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR, wxKeyEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR_HOOK, wxKeyEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_DOWN, wxKeyEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_UP, wxKeyEvent)
 #if wxUSE_HOTKEY
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_HOTKEY;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_HOTKEY, wxKeyEvent)
 #endif
     // Set cursor event
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SET_CURSOR;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_CURSOR, wxSetCursorEvent)
 
     // wxScrollBar and wxSlider event identifiers
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_TOP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_BOTTOM;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_LINEUP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_LINEDOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_PAGEUP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_PAGEDOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_THUMBTRACK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_THUMBRELEASE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLL_CHANGED;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_TOP, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_BOTTOM, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEUP, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEDOWN, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEUP, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEDOWN, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBTRACK, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_CHANGED, wxScrollEvent)
 
     // Scroll events from wxWindow
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_TOP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_BOTTOM;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_LINEUP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_LINEDOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_PAGEUP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_PAGEDOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_THUMBTRACK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SCROLLWIN_THUMBRELEASE;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_TOP, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent)
 
     // System events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SIZE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOVE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CLOSE_WINDOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_END_SESSION;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_QUERY_END_SESSION;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_ACTIVATE_APP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_ACTIVATE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CREATE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_DESTROY;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SHOW;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_ICONIZE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MAXIMIZE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOUSE_CAPTURE_CHANGED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOUSE_CAPTURE_LOST;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_PAINT;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_ERASE_BACKGROUND;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_NC_PAINT;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_PAINT_ICON;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MENU_OPEN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MENU_CLOSE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MENU_HIGHLIGHT;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CONTEXT_MENU;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SYS_COLOUR_CHANGED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_DISPLAY_CHANGED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SETTING_CHANGED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_QUERY_NEW_PALETTE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_PALETTE_CHANGED;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_JOY_BUTTON_DOWN;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_JOY_BUTTON_UP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_JOY_MOVE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_JOY_ZMOVE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_DROP_FILES;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_DRAW_ITEM;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MEASURE_ITEM;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMPARE_ITEM;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_INIT_DIALOG;
-extern WXDLLIMPEXP_BASE const wxEventType wxEVT_IDLE;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_UPDATE_UI;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_SIZING;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOVING;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOVE_START;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_MOVE_END;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_HIBERNATE;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZE, wxSizeEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE, wxMoveEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CLOSE_WINDOW, wxCloseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_END_SESSION, wxCloseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_END_SESSION, wxCloseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE_APP, wxActivateEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE, wxActivateEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CREATE, wxWindowCreateEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_DESTROY, wxWindowDestroyEvent) 
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SHOW, wxShowEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_ICONIZE, wxIconizeEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAXIMIZE, wxMaximizeEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_ERASE_BACKGROUND, wxEraseEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_NC_PAINT, wxNcPaintEvent)
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_PAINT_ICON;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_OPEN, wxMenuEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_CLOSE, wxMenuEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_HIGHLIGHT, wxMenuEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_CONTEXT_MENU, wxContextMenuEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent)
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_SETTING_CHANGED;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_UP, wxJoystickEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_MOVE, wxJoystickEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_ZMOVE, wxJoystickEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_DROP_FILES, wxDropFilesEvent)
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_DRAW_ITEM;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_MEASURE_ITEM;
+extern const WXDLLIMPEXP_CORE wxEventType wxEVT_COMPARE_ITEM;
 
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_INIT_DIALOG, wxInitDialogEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_BASE, wxEVT_IDLE, wxIdleEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_UPDATE_UI, wxUpdateUIEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZING, wxSizeEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVING, wxMoveEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_START, wxMoveEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_END, wxMoveEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_HIBERNATE, wxActivateEvent)
+
     // Clipboard events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_COPY;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_CUT;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_TEXT_PASTE;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent)
 
     // Generic command events
     // Note: a click is a higher-level event than button down/up
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_LEFT_CLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_LEFT_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_RIGHT_CLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_RIGHT_DCLICK;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_SET_FOCUS;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_KILL_FOCUS;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_ENTER;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SET_FOCUS, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_ENTER, wxCommandEvent)
 
     // Help events
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_HELP;
-extern WXDLLIMPEXP_CORE const wxEventType wxEVT_DETAILED_HELP;
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_HELP, wxHelpEvent)
+wxDECLARE_EVENT(WXDLLIMPEXP_CORE, wxEVT_DETAILED_HELP, wxHelpEvent)
 
 // these 2 events are the same
 #define wxEVT_COMMAND_TOOL_CLICKED wxEVT_COMMAND_MENU_SELECTED
@@ -2124,17 +2562,7 @@
 // event handler and related classes
 // ============================================================================
 
-typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
 
-// We had some trouble (specifically with eVC for ARM WinCE build) with using
-// wxEventFunction in the past so we had introduced wxObjectEventFunction which
-// used to be a typedef for a member of wxObject and not wxEvtHandler to work
-// around this but as eVC is not really supported any longer we now only keep
-// this for backwards compatibility and, despite its name, this is a typedef
-// for wxEvtHandler member now -- but if we have the same problem with another
-// compiler we can restore its old definition for it.
-typedef wxEventFunction wxObjectEventFunction;
-
 // struct containing the members common to static and dynamic event tables
 // entries
 struct WXDLLIMPEXP_BASE wxEventTableEntryBase
@@ -2144,7 +2572,7 @@
 
 public:
     wxEventTableEntryBase(int winid, int idLast,
-                          wxObjectEventFunction fn, wxObject *data)
+                          wxEventFunctor* fn, wxObject *data)
         : m_id(winid),
           m_lastId(idLast),
           m_fn(fn),
@@ -2156,15 +2584,23 @@
           m_lastId(event.m_lastId),
           m_fn(event.m_fn),
           m_callbackUserData(event.m_callbackUserData)
-    { }
+    {
+        // Don't allow the destruction of 'event' to delete the functor
+        (const_cast<wxEventTableEntryBase&>(event)).m_fn = NULL;
+    }
 
+    ~wxEventTableEntryBase()
+    {
+        wxDELETE(m_fn);
+    }
+
     // the range of ids for this entry: if m_lastId == wxID_ANY, the range
     // consists only of m_id, otherwise it is m_id..m_lastId inclusive
     int m_id,
         m_lastId;
 
     // function to call: not wxEventFunction, because of dependency problems
-    wxObjectEventFunction m_fn;
+    wxEventFunctor* m_fn;
 
     // arbitrary user data asosciated with the callback
     wxObject* m_callbackUserData;
@@ -2174,7 +2610,7 @@
 struct WXDLLIMPEXP_BASE wxEventTableEntry : public wxEventTableEntryBase
 {
     wxEventTableEntry(const int& evType, int winid, int idLast,
-                      wxObjectEventFunction fn, wxObject *data)
+                      wxEventFunctor* fn, wxObject *data)
         : wxEventTableEntryBase(winid, idLast, fn, data),
         m_eventType(evType)
     { }
@@ -2195,10 +2631,10 @@
 struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase
 {
     wxDynamicEventTableEntry(int evType, int winid, int idLast,
-                             wxObjectEventFunction fn, wxObject *data, wxEvtHandler* eventSink)
+                             wxEventFunctor* fn, wxObject *data)
         : wxEventTableEntryBase(winid, idLast, fn, data),
           m_eventType(evType),
-          m_eventSink(eventSink)
+          m_eventSink(fn->GetFunctorObject())
     { }
 
     // not a reference here as we can't keep a reference to a temporary int
@@ -2345,28 +2781,40 @@
 
     // Dynamic association of a member function handler with the event handler,
     // winid and event type
-    void Connect(int winid,
+    
+    wxEventConnection Connect(int winid,
                  int lastId,
                  int eventType,
                  wxObjectEventFunction func,
                  wxObject *userData = (wxObject *) NULL,
-                 wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
+                 wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
+    {
+        wxEventFunctor* functor = wxNewEventFunctor(eventType, func, eventSink);
 
+        // Create the event table entry and add it
+        wxDynamicEventTableEntry *entry =
+            new wxDynamicEventTableEntry(eventType, winid, lastId, functor, userData);
+
+        return Connect(entry);
+    }
+
     // Convenience function: take just one id
-    void Connect(int winid,
+    wxEventConnection Connect(int winid,
                  int eventType,
                  wxObjectEventFunction func,
                  wxObject *userData = (wxObject *) NULL,
                  wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
-        { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
+        { return Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
 
     // Even more convenient: without id (same as using id of wxID_ANY)
-    void Connect(int eventType,
+    wxEventConnection Connect(int eventType,
                  wxObjectEventFunction func,
                  wxObject *userData = (wxObject *) NULL,
                  wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
-        { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
+        { return Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
 
+
+    // Disconnect
     bool Disconnect(int winid,
                     int lastId,
                     wxEventType eventType,
@@ -2387,6 +2835,220 @@
                     wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
         { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
 
+
+    #if wxUSE_TYPESAFE_EVENTS
+    // Apparently if you use a legacy Connect function but the eventSink is 'NOT'
+    // exactly a wxEvtHandler* it will not match the above without a cast:
+    // window.Connect(wxEVT_LEGACY, wxLegacyEventHandler(MyWindow::OnLegacy), (wxEvtHandler*)this);
+    // And instead will try to match one below with EventType=int, so these are needed
+    /*
+    template <typename EventSink>
+    wxEventConnection Connect(int winid, int lastId,
+                              wxEventType eventType,
+                              wxObjectEventFunction func,
+                              wxObject* userData,
+                              EventSink* eventSink)
+    {
+        return Connect(winid, lastId, eventType, func, userData, (wxEvtHandler*)eventSink);
+    }
+
+    template <typename EventSink>
+    wxEventConnection Connect(int winid,
+                              wxEventType eventType,
+                              wxObjectEventFunction func,
+                              wxObject* userData,
+                              EventSink* eventSink)
+    {
+        return Connect(winid, eventType, func, userData, (wxEvtHandler*)eventSink);
+    }
+    template <typename EventSink>
+    wxEventConnection Connect(wxEventType eventType,
+                              wxObjectEventFunction func,
+                              wxObject* userData,
+                              EventSink* eventSink)
+    {
+        return Connect(eventType, func, userData, (wxEvtHandler*)eventSink);
+    }
+    
+
+    template <typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(int winid, int lastId,
+                              wxEventType eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        return Connect(winid, lastId, eventType,
+            (wxObjectEventFunction)(wxEventFunction)func, userData,
+            (wxEvtHandler*)eventSink);
+    }
+
+    template <typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(int winid,
+                              wxEventType eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        return Connect(winid, eventType, 
+            (wxObjectEventFunction)(wxEventFunction)func, userData,
+            (wxEvtHandler*)eventSink);
+    }
+    template <typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(wxEventType eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        return Connect(eventType, 
+            (wxObjectEventFunction)(wxEventFunction)func, userData,
+            (wxEvtHandler*)eventSink);
+    }
+    */
+
+    // Modern
+    template <typename EventType, typename Class, typename Event>
+    wxEventConnection Connect(int winid, int lastId,
+                              const EventType& eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData = NULL)
+    {
+        // Do runtime test if possible to see that 'this' can be used
+        wxASSERT(wx_dynamic_cast(Class*, this) != NULL);
+
+        wxEventFunctorMethod<EventType, Class, Class>* functor =
+            wxNewEventFunctor(eventType, func, wx_dynamic_cast(Class*, this));
+
+        return Connect(eventType, functor, winid, lastId, userData);
+    }
+
+    template <typename EventType, typename Class, typename Event>
+    wxEventConnection Connect(int winid,
+                              const EventType& eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData = NULL)
+    {
+        return Connect(winid, wxID_ANY, eventType, func, userData);
+    }
+
+    template <typename EventType, typename Class, typename Event>
+    wxEventConnection Connect(const EventType& eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData = NULL)
+    {
+        return Connect(wxID_ANY, wxID_ANY, eventType, func, userData);
+    }
+
+    // There is no problem with these because type checking between handler and
+    // method is done at compile time
+    template <typename EventType, typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(int winid, int lastId,
+                              const EventType& eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        wxEventFunctorMethod<EventType, Class, Derived>* functor =
+            wxNewEventFunctor(eventType, func, eventSink);
+
+        return Connect(eventType, functor, winid, lastId, userData);
+    }
+
+    template <typename EventType, typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(int winid,
+                              const EventType& eventType,
+                              void (Class::*func)(Event), 
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        return Connect(winid, wxID_ANY, eventType, func, userData, eventSink);
+    }
+    
+    template <typename EventType, typename Class, typename Event, typename Derived>
+    wxEventConnection Connect(const EventType& eventType,
+                              void (Class::*func)(Event),
+                              wxObject* userData,
+                              Derived* eventSink)
+    {
+        return Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink);
+    }
+
+    // Templated disconnects
+    template <typename EventType, typename Class, typename Event>
+    bool Disconnect(int winid, int lastId,
+                    const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData = NULL)
+    {
+        return Disconnect(winid, lastId, (wxEventType)eventType, (wxObjectEventFunction)func, userData);
+    }
+
+    template <typename EventType, typename Class, typename Event>
+    bool Disconnect(int winid,
+                    const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData = NULL)
+    {
+        return Disconnect(winid, (wxEventType)eventType, (wxObjectEventFunction)func, userData);
+    }
+
+    template <typename EventType, typename Class, typename Event>
+    bool Disconnect(const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData = NULL)
+    {
+        return Disconnect((wxEventType)eventType, (wxObjectEventFunction)func, userData);
+    }
+
+
+    template <typename EventType, typename Class, typename Event, class Derived>
+    bool Disconnect(int winid, int lastId,
+                    const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData,
+                    Derived* eventSink)
+    {
+        return Disconnect(winid, lastId, (wxEventType)eventType, (wxObjectEventFunction)func, userData, eventSink);
+    }
+
+    template <typename EventType, typename Class, typename Event, class Derived>
+    bool Disconnect(int winid,
+                    const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData,
+                    Derived* eventSink)
+    {
+        return Disconnect(winid, (wxEventType)eventType, (wxObjectEventFunction)func, userData, eventSink);
+    }
+
+    template <typename EventType, typename Class, typename Event, class Derived>
+    bool Disconnect(const EventType& eventType,
+                    void (Class::*func)(Event),
+                    wxObject* userData,
+                    Derived* eventSink)
+    {
+        return Disconnect((wxEventType)eventType, (wxObjectEventFunction)func, userData, eventSink);
+    }
+
+    // This makes sure the functor type matches the event type
+    // This is used by the template Connects above as well as by template wxConnect
+    template <typename Functor>
+    wxEventConnection Connect(const typename Functor::TypedEventType& eventType,
+                              Functor* functor, 
+                              int winid = wxID_ANY, int lastId = wxID_ANY,
+                              wxObject* userData = NULL)
+    {
+        wxDynamicEventTableEntry* entry =
+            new wxDynamicEventTableEntry(eventType, winid, lastId, functor, userData);
+
+        return Connect(entry);
+    }
+
+    #endif // wxUSE_TYPESAFE_EVENTS
+
+    // New disconnect
+    bool Disconnect(wxEventConnection conn);
+
     wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
 
     // User data can be associated with each wxEvtHandler
@@ -2414,6 +3076,11 @@
     void OnSinkDestroyed( wxEvtHandler *sink );
 
 private:
+    // This should be private, it simply connects the entry
+    // and avoids it's code getting duplicated for each possible
+    // template instantiation of Connect
+    wxEventConnection Connect(wxDynamicEventTableEntry* entry);
+
     static const wxEventTableEntry sm_eventTableEntries[];
 
 protected:
@@ -2487,6 +3154,92 @@
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
 };
 
+// wxConnect
+
+// Legacy
+inline wxEventConnection wxConnect(wxEvtHandler* sender,
+                            wxEventType eventType,
+                            wxObjectEventFunction func,
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    return sender->Connect(winid, lastId, eventType, func, userData);
+}
+
+inline wxEventConnection wxConnect(wxEvtHandler* sender,
+                            wxEventType eventType,
+                            wxObjectEventFunction func,
+                            wxEvtHandler* eventSink,
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    return sender->Connect(winid, lastId, eventType, func, userData, eventSink);
+}
+
+#if wxUSE_TYPESAFE_EVENTS
+
+// Method using Sender as the event sink
+template <typename Sender, typename EventType, typename Class, typename Event>
+inline wxEventConnection wxConnect(Sender* sender,
+                            const EventType& eventType,
+                            void (Class::*func)(Event),
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    wxEventFunctorMethod<EventType, Class, Class>* functor =
+        wxNewEventFunctor(eventType, func, sender);
+
+    return sender->Connect(eventType, functor, winid, lastId, userData);
+}
+
+// Method using a different event sink
+template <typename Sender, typename EventType, typename Class, typename Event, typename Derived>
+inline wxEventConnection wxConnect(Sender* sender,
+                            const EventType& eventType,
+                            void (Class::*func)(Event),
+                            Derived* eventSink,
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    wxEventFunctorMethod<EventType, Class, Derived>* functor =
+        wxNewEventFunctor(eventType, func, eventSink);
+
+    return sender->Connect(eventType, functor, winid, lastId, userData);
+}
+
+// Function
+template <typename Sender, typename EventType, typename Event>
+inline wxEventConnection wxConnect(Sender* sender,
+                            const EventType& eventType,
+                            void (*func)(Event),
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    wxEventFunctorFunction<EventType>* functor =
+        wxNewEventFunctor(eventType, func);
+
+    return sender->Connect(eventType, functor, winid, lastId, userData);
+}
+
+// Adapter
+template <typename Sender, typename EventType, typename Functor>
+inline wxEventConnection wxConnect(Sender* sender,
+                            const EventType& eventType,
+                            Functor& functor,
+                            int winid = wxID_ANY, int lastId = wxID_ANY,
+                            wxObject* userData = NULL)
+{
+    wxEventFunctorAdapter<EventType, Functor>* adapter =
+        wxNewEventFunctor(eventType, functor);
+
+    return sender->Connect(eventType, adapter, winid, lastId, userData);
+}
+
+#endif // wxUSE_TYPESAFE_EVENTS
+
+
+
+
 // ----------------------------------------------------------------------------
 // wxEventConnectionRef represents all connections between two event handlers
 // and enables automatic disconnect when an event handler sink goes out of
@@ -2560,10 +3313,8 @@
 typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
 typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
 
-#define wxEventHandler(func) \
-    (wxObjectEventFunction)wxStaticCastEvent(wxEventFunction, &func)
-#define wxIdleEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIdleEventFunction, &func)
+#define wxEventHandler(func) wxEventHandlerCast(wxEventFunction, func)
+#define wxIdleEventHandler(func) wxEventHandlerCast(wxIdleEventFunction, func)
 
 #if wxUSE_GUI
 
@@ -2629,79 +3380,43 @@
 typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&);
 
 
-#define wxCommandEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCommandEventFunction, &func)
-#define wxScrollEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxScrollEventFunction, &func)
-#define wxScrollWinEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxScrollWinEventFunction, &func)
-#define wxSizeEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSizeEventFunction, &func)
-#define wxMoveEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMoveEventFunction, &func)
-#define wxPaintEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxPaintEventFunction, &func)
-#define wxNcPaintEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNcPaintEventFunction, &func)
-#define wxEraseEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxEraseEventFunction, &func)
-#define wxMouseEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMouseEventFunction, &func)
-#define wxCharEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCharEventFunction, &func)
+#define wxCommandEventHandler(func) wxEventHandlerCast(wxCommandEventFunction, func)
+#define wxScrollEventHandler(func) wxEventHandlerCast(wxScrollEventFunction, func)
+#define wxScrollWinEventHandler(func) wxEventHandlerCast(wxScrollWinEventFunction, func)
+#define wxSizeEventHandler(func) wxEventHandlerCast(wxSizeEventFunction, func)
+#define wxMoveEventHandler(func) wxEventHandlerCast(wxMoveEventFunction, func)
+#define wxPaintEventHandler(func) wxEventHandlerCast(wxPaintEventFunction, func)
+#define wxNcPaintEventHandler(func) wxEventHandlerCast(wxNcPaintEventFunction, func) 
+#define wxEraseEventHandler(func) wxEventHandlerCast(wxEraseEventFunction, func)
+#define wxMouseEventHandler(func) wxEventHandlerCast(wxMouseEventFunction, func) 
+#define wxCharEventHandler(func) wxEventHandlerCast(wxCharEventFunction, func) 
 #define wxKeyEventHandler(func) wxCharEventHandler(func)
-#define wxFocusEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFocusEventFunction, &func)
-#define wxChildFocusEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxChildFocusEventFunction, &func)
-#define wxActivateEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxActivateEventFunction, &func)
-#define wxMenuEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMenuEventFunction, &func)
-#define wxJoystickEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxJoystickEventFunction, &func)
-#define wxDropFilesEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDropFilesEventFunction, &func)
-#define wxInitDialogEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxInitDialogEventFunction, &func)
-#define wxSysColourChangedEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSysColourChangedEventFunction, &func)
-#define wxDisplayChangedEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDisplayChangedEventFunction, &func)
-#define wxUpdateUIEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxUpdateUIEventFunction, &func)
-#define wxCloseEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCloseEventFunction, &func)
-#define wxShowEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxShowEventFunction, &func)
-#define wxIconizeEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIconizeEventFunction, &func)
-#define wxMaximizeEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMaximizeEventFunction, &func)
-#define wxNavigationKeyEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNavigationKeyEventFunction, &func)
-#define wxPaletteChangedEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxPaletteChangedEventFunction, &func)
-#define wxQueryNewPaletteEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxQueryNewPaletteEventFunction, &func)
-#define wxWindowCreateEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWindowCreateEventFunction, &func)
-#define wxWindowDestroyEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWindowDestroyEventFunction, &func)
-#define wxSetCursorEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSetCursorEventFunction, &func)
-#define wxNotifyEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNotifyEventFunction, &func)
-#define wxHelpEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHelpEventFunction, &func)
-#define wxContextMenuEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxContextMenuEventFunction, &func)
-#define wxMouseCaptureChangedEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMouseCaptureChangedEventFunction, &func)
-#define wxMouseCaptureLostEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMouseCaptureLostEventFunction, &func)
-#define wxClipboardTextEventHandler(func) \
-    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxClipboardTextEventFunction, &func)
+#define wxFocusEventHandler(func) wxEventHandlerCast(wxFocusEventFunction, func)
+#define wxChildFocusEventHandler(func) wxEventHandlerCast(wxChildFocusEventFunction, func) 
+#define wxActivateEventHandler(func) wxEventHandlerCast(wxActivateEventFunction, func) 
+#define wxMenuEventHandler(func) wxEventHandlerCast(wxMenuEventFunction, func) 
+#define wxJoystickEventHandler(func) wxEventHandlerCast(wxJoystickEventFunction, func) 
+#define wxDropFilesEventHandler(func) wxEventHandlerCast(wxDropFilesEventFunction, func) 
+#define wxInitDialogEventHandler(func) wxEventHandlerCast(wxInitDialogEventFunction, func) 
+#define wxSysColourChangedEventHandler(func) wxEventHandlerCast(wxSysColourChangedEventFunction, func) 
+#define wxDisplayChangedEventHandler(func) wxEventHandlerCast(wxDisplayChangedEventFunction, func) 
+#define wxUpdateUIEventHandler(func) wxEventHandlerCast(wxUpdateUIEventFunction, func)
+#define wxCloseEventHandler(func) wxEventHandlerCast(wxCloseEventFunction, func) 
+#define wxShowEventHandler(func) wxEventHandlerCast(wxShowEventFunction, func) 
+#define wxIconizeEventHandler(func) wxEventHandlerCast(wxIconizeEventFunction, func) 
+#define wxMaximizeEventHandler(func) wxEventHandlerCast(wxMaximizeEventFunction, func) 
+#define wxNavigationKeyEventHandler(func) wxEventHandlerCast(wxNavigationKeyEventFunction, func)
+#define wxPaletteChangedEventHandler(func) wxEventHandlerCast(wxPaletteChangedEventFunction, func)
+#define wxQueryNewPaletteEventHandler(func) wxEventHandlerCast(wxQueryNewPaletteEventFunction, func)
+#define wxWindowCreateEventHandler(func) wxEventHandlerCast(wxWindowCreateEventFunction, func) 
+#define wxWindowDestroyEventHandler(func) wxEventHandlerCast(wxWindowDestroyEventFunction, func) 
+#define wxSetCursorEventHandler(func) wxEventHandlerCast(wxSetCursorEventFunction, func) 
+#define wxNotifyEventHandler(func) wxEventHandlerCast(wxNotifyEventFunction, func) 
+#define wxHelpEventHandler(func) wxEventHandlerCast(wxHelpEventFunction, func) 
+#define wxContextMenuEventHandler(func) wxEventHandlerCast(wxContextMenuEventFunction, func) 
+#define wxMouseCaptureChangedEventHandler(func) wxEventHandlerCast(wxMouseCaptureChangedEventFunction, func) 
+#define wxMouseCaptureLostEventHandler(func) wxEventHandlerCast(wxMouseCaptureLostEventFunction, func) 
+#define wxClipboardTextEventHandler(func) wxEventHandlerCast(wxClipboardTextEventFunction, func)
 
 #endif // wxUSE_GUI
 
@@ -2836,7 +3551,7 @@
     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
     const wxEventTableEntry theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTableEntries[] = { \
 
-#define END_EVENT_TABLE() DECLARE_EVENT_TABLE_ENTRY( wxEVT_NULL, 0, 0, 0, 0 ) };
+#define END_EVENT_TABLE() DECLARE_EVENT_TABLE_TERMINATOR() };
 
 /*
  * Event table macros
Index: include/wx/defs.h
===================================================================
--- include/wx/defs.h	(revision 55693)
+++ include/wx/defs.h	(working copy)
@@ -340,6 +340,12 @@
     #define wx_reinterpret_cast(t, x) ((t)(x))
 #endif
 
+#ifdef HAVE_DYNAMIC_CAST
+    #define wx_dynamic_cast(t, x) dynamic_cast<t>(x)
+#else
+    #define wx_dynamic_cast wx_static_cast
+#endif
+
 /*
    This one is a wx invention: like static cast but used when we intentionally
    truncate from a larger to smaller type, static_cast<> can't be used for it
Index: samples/minimal/minimal.cpp
===================================================================
--- samples/minimal/minimal.cpp	(revision 55693)
+++ samples/minimal/minimal.cpp	(working copy)
@@ -41,6 +41,27 @@
 #endif
 
 // ----------------------------------------------------------------------------
+// Custom events
+// ----------------------------------------------------------------------------
+class MyEvent;
+const wxTypedEventType<MyEvent> MY_EVENT(wxNewEventType());
+
+class MyEvent : public wxEvent
+{
+public:
+    // Implicit dtor/copy/assign are fine as we contain no extra data
+    MyEvent(int id, wxEventType type) : wxEvent(id, type) { }
+    
+protected:
+    wxEvent* Clone() const
+    {
+        return new MyEvent(*this);
+    }
+};
+
+#define EVT_TEST(id, func) DECLARE_EVENT_TABLE_ENTRY(MY_EVENT, id, wxID_ANY, &func, 0),
+
+// ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
 
@@ -68,11 +89,29 @@
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
 
+    void OnTest1(wxCommandEvent& event);
+    void OnTest2(wxCommandEvent& event);
+    void OnTest3(wxCommandEvent& event);
+
+    void OnMyEvent1(MyEvent& event);
+    void OnMyEvent2(MyEvent& event);
+
 private:
+
     // any class wishing to process wxWidgets events must use this macro
     DECLARE_EVENT_TABLE()
 };
 
+void OnMyEvent3(MyEvent& WXUNUSED(event))
+{
+    ::wxMessageBox("::OnMyEvent3");
+}
+
+void OnBadMyEvent3(wxCommandEvent& WXUNUSED(event))
+{
+    ::wxMessageBox("::OnBadMyEvent3");
+}
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -86,7 +125,16 @@
     // it is important for the id corresponding to the "About" command to have
     // this standard value as otherwise it won't be handled properly under Mac
     // (where it is special and put into the "Apple" menu)
-    Minimal_About = wxID_ABOUT
+    Minimal_About = wxID_ABOUT,
+
+    // Tests
+    Minimal_Test1 = wxID_HIGHEST + 1,
+    Minimal_Test2,
+    Minimal_Test3,
+
+    ID_TEST1,
+    ID_TEST2,
+    ID_TEST3
 };
 
 // ----------------------------------------------------------------------------
@@ -99,6 +147,17 @@
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
     EVT_MENU(Minimal_About, MyFrame::OnAbout)
+    EVT_MENU(Minimal_Test1, MyFrame::OnTest1)
+    EVT_MENU(Minimal_Test2, MyFrame::OnTest2)
+    EVT_MENU(Minimal_Test3, MyFrame::OnTest3)
+
+    EVT_TEST(ID_TEST1, MyFrame::OnMyEvent1)
+    EVT_TEST(ID_TEST2, MyFrame::OnMyEvent2)
+    EVT_TEST(ID_TEST3, OnMyEvent3)
+
+    // Fail to compile (good)
+    //EVT_TEST(ID_TEST1, MyFrame::OnTest1)
+    //EVT_TEST(ID_TEST1, OnBadMyEvent3)
 END_EVENT_TABLE()
 
 // Create a new application object: this macro will allow wxWidgets to create
@@ -158,10 +217,18 @@
 
     fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
 
+    // the "Test' item
+     wxMenu* testMenu = new wxMenu;
+
+     testMenu->Append(Minimal_Test1, "Test1");
+     testMenu->Append(Minimal_Test2, "Test2");
+     testMenu->Append(Minimal_Test3, "Test3");
+
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar();
     menuBar->Append(fileMenu, "&File");
     menuBar->Append(helpMenu, "&Help");
+    menuBar->Append(testMenu, "&Test");
 
     // ... and attach this menu bar to the frame
     SetMenuBar(menuBar);
@@ -198,3 +265,42 @@
                  wxOK | wxICON_INFORMATION,
                  this);
 }
+
+void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
+{
+    MyEvent evt(ID_TEST1, MY_EVENT);
+    ProcessEvent(evt);
+
+    ::wxMessageBox("Connecting ::OnMyEvent3");
+    wxEventConnection conn = wxConnect(this, MY_EVENT, &OnMyEvent3, ID_TEST1);
+    ProcessEvent(evt);
+    ::wxMessageBox("Disconnecting ::OnMyEvent3");
+    conn.Disconnect();
+    ProcessEvent(evt);
+
+    // Fail to compile (good)
+    // wxConnect(this, ID_TEST1, MY_EVENT, &OnBadMyEvent3);
+}
+
+void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event))
+{
+    MyEvent evt(ID_TEST2, MY_EVENT);
+    ProcessEvent(evt);
+}
+
+void MyFrame::OnTest3(wxCommandEvent& WXUNUSED(event))
+{
+    MyEvent evt(ID_TEST3, MY_EVENT);
+    ProcessEvent(evt);
+}
+
+void MyFrame::OnMyEvent1(MyEvent& WXUNUSED(event))
+{
+    ::wxMessageBox("MyFrame::OnMyEvent1");
+}
+
+void MyFrame::OnMyEvent2(MyEvent& WXUNUSED(event))
+{
+    ::wxMessageBox("MyFrame::OnMyEvent2");
+}
+
