From: Vadim Zeitlin Date: Sat, 30 Jul 2011 11:30:08 +0000 (+0000) Subject: Get rid of ugly wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST macro. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bf8f10225c08bf5473fa35423f56e01f1819f971?ds=inline Get rid of ugly wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST macro. 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 --- diff --git a/include/wx/ctrlsub.h b/include/wx/ctrlsub.h index 82a98dfdfb..76f8353220 100644 --- a/include/wx/ctrlsub.h +++ b/include/wx/ctrlsub.h @@ -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 instead of Window and Container interface directly. +template +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 { 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; } diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index 1d4149e3a8..77d2502cac 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -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 { 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); diff --git a/include/wx/htmllbox.h b/include/wx/htmllbox.h index f610b8383f..1a941159dd 100644 --- a/include/wx/htmllbox.h +++ b/include/wx/htmllbox.h @@ -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 { 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 // ----------------- diff --git a/include/wx/odcombo.h b/include/wx/odcombo.h index 4879c2bbfc..26415e8d24 100644 --- a/include/wx/odcombo.h +++ b/include/wx/odcombo.h @@ -233,15 +233,15 @@ private: // the wxComboCtrl. // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl, - public wxItemContainer +class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : + public wxWindowWithItems { //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); diff --git a/include/wx/osx/combobox.h b/include/wx/osx/combobox.h index 4a31de9135..e814474732 100644 --- a/include/wx/osx/combobox.h +++ b/include/wx/osx/combobox.h @@ -26,12 +26,13 @@ class wxComboWidgetImpl; // Combobox item class WXDLLIMPEXP_CORE wxComboBox : + public wxWindowWithItems< #if wxOSX_USE_CARBON - public wxNavigationEnabled, + wxNavigationEnabled, #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 diff --git a/include/wx/univ/combobox.h b/include/wx/univ/combobox.h index 93b3128633..04343ac4fe 100644 --- a/include/wx/univ/combobox.h +++ b/include/wx/univ/combobox.h @@ -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 { 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) /* diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 06ca2e58a5..6425dd145d 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -902,7 +902,6 @@ wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent, long style, const wxValidator& validator, const wxString& name) - : wxComboCtrl() { Init();