]> git.saurik.com Git - wxWidgets.git/commitdiff
add ugly macros to abstract the difference between Bind() and Connect() -- this is...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 2 Mar 2009 12:10:40 +0000 (12:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 2 Mar 2009 12:10:40 +0000 (12:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59262 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/event.h
include/wx/persist/window.h

index 302036e45e9c09ff96160a286431b5365da129e6..ad6469b9582853ad86897234211a7af1cf6f8efd 100644 (file)
@@ -3804,6 +3804,41 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&
 // Helper functions
 // ----------------------------------------------------------------------------
 
+// This is an ugly hack to allow the use of Bind() instead of Connect() inside
+// the library code if the library was built with support for it, here is how
+// it is used:
+//
+// class SomeEventHandlingClass : wxBIND_OR_CONNECT_HACK_BASE_CLASS
+//                                public SomeBaseClass
+// {
+// public:
+//     SomeEventHandlingClass(wxWindow *win)
+//     {
+//         // connect to the event for the given window
+//         wxBIND_OR_CONNECT_HACK(win, wxEVT_SOMETHING, wxSomeEventHandler,
+//                                SomeEventHandlingClass::OnSomeEvent, this);
+//     }
+//
+// private:
+//     void OnSomeEvent(wxSomeEvent&) { ... }
+// };
+//
+// This is *not* meant to be used by library users, it is only defined here
+// (and not in a private header) because the base class must be visible from
+// other public headers, please do NOT use this in your code, it will be
+// removed from future wx versions without warning.
+#if wxEVENTS_COMPATIBILITY_2_8
+    #define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
+    #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
+    #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
+        win->Connect(evt, handler(func), NULL, obj)
+#else // wxEVENTS_COMPATIBILITY_2_8
+    #define wxBIND_OR_CONNECT_HACK_BASE_CLASS
+    #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
+    #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
+        win->Bind(evt, &func, obj)
+#endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
+
 #if wxUSE_GUI
 
 // Find a window with the focus, that is also a descendant of the given window.
index 84c27ba35c3561bacf367b326b1f3d5e87ac09de..30fa88b215e75a4a4867a6905103d8ce298c1634 100644 (file)
 
 // type-independent part of wxPersistentWindow
 class wxPersistentWindowBase :
-#if wxEVENTS_COMPATIBILITY_2_8
-    // in compatibility mode we need to derive from wxEvtHandler to be able to
-    // handle events
-    public wxEvtHandler ,
-#endif
+    wxBIND_OR_CONNECT_HACK_BASE_CLASS
     public wxPersistentObject
 {
 public:
     wxPersistentWindowBase(wxWindow *win)
         : wxPersistentObject(win)
     {
-#if wxEVENTS_COMPATIBILITY_2_8
-        win->Connect
-             (
-                wxEVT_DESTROY,
-                wxWindowDestroyEventHandler(
-                    wxPersistentWindowBase::HandleDestroy),
-                NULL,
-                this
-             );
-#else // !wxEVENTS_COMPATIBILITY_2_8
-        win->Bind(wxEVT_DESTROY, &wxPersistentWindowBase::HandleDestroy, this);
-#endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
+        wxBIND_OR_CONNECT_HACK(win, wxEVT_DESTROY, wxWindowDestroyEventHandler,
+                               wxPersistentWindowBase::HandleDestroy, this);
     }
 
     virtual wxString GetName() const