]> git.saurik.com Git - wxWidgets.git/commitdiff
Get rid of ugly wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST macro.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 30 Jul 2011 11:30:08 +0000 (11:30 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 30 Jul 2011 11:30:08 +0000 (11:30 +0000)
Replace it with wxWindowWithItems<> template class which takes care of
disambiguating between the two inherited Get/SetClientXXX() versions and use
it as a base class in all clases that previously used the macro.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68460 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/ctrlsub.h
include/wx/gtk1/combobox.h
include/wx/htmllbox.h
include/wx/odcombo.h
include/wx/osx/combobox.h
include/wx/univ/combobox.h
src/generic/odcombo.cpp

index 82a98dfdfb835f9b1d39cc0a768aa9b8fca3c512..76f8353220ac281b8f58bbdf0c4ee70c204de1e3 100644 (file)
@@ -395,41 +395,48 @@ private:
     wxClientDataType m_clientDataItemsType;
 };
 
-// this macro must (unfortunately) be used in any class deriving from both
-// wxItemContainer and wxControl because otherwise there is ambiguity when
-// calling GetClientXXX() functions -- the compiler can't choose between the
-// two versions
-#define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST                    \
-    void SetClientData(void *data)                                         \
-        { wxEvtHandler::SetClientData(data); }                             \
-    void *GetClientData() const                                            \
-        { return wxEvtHandler::GetClientData(); }                          \
-    void SetClientObject(wxClientData *data)                               \
-        { wxEvtHandler::SetClientObject(data); }                           \
-    wxClientData *GetClientObject() const                                  \
-        { return wxEvtHandler::GetClientObject(); }                        \
-    void SetClientData(unsigned int n, void* clientData)                   \
-        { wxItemContainer::SetClientData(n, clientData); }                 \
-    void* GetClientData(unsigned int n) const                              \
-        { return wxItemContainer::GetClientData(n); }                      \
-    void SetClientObject(unsigned int n, wxClientData* clientData)         \
-        { wxItemContainer::SetClientObject(n, clientData); }               \
-    wxClientData* GetClientObject(unsigned int n) const                    \
+// Inheriting directly from a wxWindow-derived class and wxItemContainer
+// unfortunately introduces an ambiguity for all GetClientXXX() methods as they
+// are inherited twice: the "global" versions from wxWindow and the per-item
+// versions taking the index from wxItemContainer.
+//
+// So we need to explicitly resolve them and this helper template class is
+// provided to do it. To use it, simply inherit from wxWindowWithItems<Window,
+// Container> instead of Window and Container interface directly.
+template <class W, class C>
+class wxWindowWithItems : public W, public C
+{
+public:
+    typedef W BaseWindowClass;
+    typedef C BaseContainerInterface;
+
+    wxWindowWithItems() { }
+
+    void SetClientData(void *data)
+        { BaseWindowClass::SetClientData(data); }
+    void *GetClientData() const
+        { return BaseWindowClass::GetClientData(); }
+    void SetClientObject(wxClientData *data)
+        { BaseWindowClass::SetClientObject(data); }
+    wxClientData *GetClientObject() const
+        { return BaseWindowClass::GetClientObject(); }
+
+    void SetClientData(unsigned int n, void* clientData)
+        { wxItemContainer::SetClientData(n, clientData); }
+    void* GetClientData(unsigned int n) const
+        { return wxItemContainer::GetClientData(n); }
+    void SetClientObject(unsigned int n, wxClientData* clientData)
+        { wxItemContainer::SetClientObject(n, clientData); }
+    wxClientData* GetClientObject(unsigned int n) const
         { return wxItemContainer::GetClientObject(n); }
+};
 
-class WXDLLIMPEXP_CORE wxControlWithItemsBase : public wxControl,
-                                           public wxItemContainer
+class WXDLLIMPEXP_CORE wxControlWithItemsBase :
+    public wxWindowWithItems<wxControl, wxItemContainer>
 {
 public:
     wxControlWithItemsBase() { }
 
-    // we have to redefine these functions here to avoid ambiguities in classes
-    // deriving from us which would arise otherwise because both base classses
-    // have the methods with the same names - hopefully, a smart compiler can
-    // optimize away these simple inline wrappers so we don't suffer much from
-    // this
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
     // usually the controls like list/combo boxes have their own background
     // colour
     virtual bool ShouldInheritColours() const { return false; }
index 1d4149e3a8b49b1b1f1cd213fb705b6c03c8a536..77d2502cac2a836a5c73ffbb03eb00f8fb3f668f 100644 (file)
@@ -34,7 +34,8 @@ extern WXDLLIMPEXP_BASE const wxChar* wxEmptyString;
 // wxComboBox
 //-----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
+class WXDLLIMPEXP_CORE wxComboBox :
+    public wxWindowWithItems<wxControl, wxComboBoxBase>
 {
 public:
     inline wxComboBox() {}
@@ -154,8 +155,6 @@ public:
     bool IsOwnGtkWindow( GdkWindow *window );
     void DoApplyWidgetStyle(GtkRcStyle *style);
 
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
     static wxVisualAttributes
     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
index f610b8383f868f4bf475c3594b638cc662d87c86..1a941159ddb0f9f4898d8f81209e9177a15dc23a 100644 (file)
@@ -196,8 +196,8 @@ private:
 #define wxHLB_DEFAULT_STYLE     wxBORDER_SUNKEN
 #define wxHLB_MULTIPLE          wxLB_MULTIPLE
 
-class WXDLLIMPEXP_HTML wxSimpleHtmlListBox : public wxHtmlListBox,
-                                             public wxItemContainer
+class WXDLLIMPEXP_HTML wxSimpleHtmlListBox :
+    public wxWindowWithItems<wxHtmlListBox, wxItemContainer>
 {
     DECLARE_ABSTRACT_CLASS(wxSimpleHtmlListBox)
 public:
@@ -254,9 +254,6 @@ public:
     int GetSelection() const
         { return wxVListBox::GetSelection(); }
 
-    // see ctrlsub.h for more info about this:
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
 
     // accessing strings
     // -----------------
index 4879c2bbfc217fb627abf855a2f03cc7074c347a..26415e8d246cf7c02044869a7cfb1fe71728614a 100644 (file)
@@ -233,15 +233,15 @@ private:
 // the wxComboCtrl.
 // ----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl,
-                                             public wxItemContainer
+class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox :
+    public wxWindowWithItems<wxComboCtrl, wxItemContainer>
 {
     //friend class wxComboPopupWindow;
     friend class wxVListBoxComboPopup;
 public:
 
     // ctors and such
-    wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); }
+    wxOwnerDrawnComboBox() { Init(); }
 
     wxOwnerDrawnComboBox(wxWindow *parent,
                          wxWindowID id,
@@ -253,7 +253,6 @@ public:
                          long style = 0,
                          const wxValidator& validator = wxDefaultValidator,
                          const wxString& name = wxComboBoxNameStr)
-        : wxComboCtrl()
     {
         Init();
 
@@ -339,8 +338,6 @@ public:
 
     virtual bool IsSorted() const { return HasFlag(wxCB_SORT); }
 
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
 protected:
     virtual void DoClear();
     virtual void DoDeleteOneItem(unsigned int n);
index 4a31de913562e5431f0cc9ea3e2b4b0362b7d0be..e814474732e0e32c07ebe4ae88675b7d7d0e60f5 100644 (file)
@@ -26,12 +26,13 @@ class wxComboWidgetImpl;
 
 // Combobox item
 class WXDLLIMPEXP_CORE wxComboBox :
+    public wxWindowWithItems<
 #if wxOSX_USE_CARBON
-    public wxNavigationEnabled<wxControl>,
+                wxNavigationEnabled<wxControl>,
 #else
-    public wxControl,
+                wxControl,
 #endif
-    public wxComboBoxBase
+                wxComboBoxBase>
 {
     DECLARE_DYNAMIC_CLASS(wxComboBox)
 
@@ -144,8 +145,6 @@ class WXDLLIMPEXP_CORE wxComboBox :
 
     virtual bool        OSXHandleClicked( double timestampsec );
 
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
 #if wxOSX_USE_COCOA
     wxComboWidgetImpl* GetComboPeer() const;
 #endif
index 93b3128633892e81924ba58cd0c97bff7be06c60..04343ac4fe36545bd25faaa5a3dab7638607095e 100644 (file)
@@ -34,7 +34,8 @@ class WXDLLIMPEXP_FWD_CORE wxListBox;
 // NB: Normally we'd like wxComboBox to inherit from wxComboBoxBase, but here
 //     we can't really do that since both wxComboBoxBase and wxComboCtrl inherit
 //     from wxTextCtrl.
-class WXDLLIMPEXP_CORE wxComboBox : public wxComboCtrl, public wxItemContainer
+class WXDLLIMPEXP_CORE wxComboBox :
+    public wxWindowWithItems<wxComboCtrl, wxItemContainer>
 {
 public:
     // ctors and such
@@ -141,8 +142,6 @@ public:
     virtual int GetSelection() const;
     virtual wxString GetStringSelection() const;
 
-    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
-
     // we have our own input handler and our own actions
     // (but wxComboCtrl already handled Popup/Dismiss)
     /*
index 06ca2e58a5ce3f497406b03227999183fe175322..6425dd145de84fa542f64659e81aeb4a29ea8b51 100644 (file)
@@ -902,7 +902,6 @@ wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent,
                                            long style,
                                            const wxValidator& validator,
                                            const wxString& name)
-    : wxComboCtrl()
 {
     Init();