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
This commit is contained in:
Vadim Zeitlin
2011-07-30 11:30:08 +00:00
parent c29c95fe24
commit bf8f10225c
7 changed files with 50 additions and 53 deletions

View File

@@ -395,41 +395,48 @@ private:
wxClientDataType m_clientDataItemsType; wxClientDataType m_clientDataItemsType;
}; };
// this macro must (unfortunately) be used in any class deriving from both // Inheriting directly from a wxWindow-derived class and wxItemContainer
// wxItemContainer and wxControl because otherwise there is ambiguity when // unfortunately introduces an ambiguity for all GetClientXXX() methods as they
// calling GetClientXXX() functions -- the compiler can't choose between the // are inherited twice: the "global" versions from wxWindow and the per-item
// two versions // versions taking the index from wxItemContainer.
#define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST \ //
void SetClientData(void *data) \ // So we need to explicitly resolve them and this helper template class is
{ wxEvtHandler::SetClientData(data); } \ // provided to do it. To use it, simply inherit from wxWindowWithItems<Window,
void *GetClientData() const \ // Container> instead of Window and Container interface directly.
{ return wxEvtHandler::GetClientData(); } \ template <class W, class C>
void SetClientObject(wxClientData *data) \ class wxWindowWithItems : public W, public C
{ wxEvtHandler::SetClientObject(data); } \ {
wxClientData *GetClientObject() const \ public:
{ return wxEvtHandler::GetClientObject(); } \ typedef W BaseWindowClass;
void SetClientData(unsigned int n, void* clientData) \ typedef C BaseContainerInterface;
{ 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, wxWindowWithItems() { }
public wxItemContainer
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 wxWindowWithItems<wxControl, wxItemContainer>
{ {
public: public:
wxControlWithItemsBase() { } 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 // usually the controls like list/combo boxes have their own background
// colour // colour
virtual bool ShouldInheritColours() const { return false; } virtual bool ShouldInheritColours() const { return false; }

View File

@@ -34,7 +34,8 @@ extern WXDLLIMPEXP_BASE const wxChar* wxEmptyString;
// wxComboBox // wxComboBox
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase class WXDLLIMPEXP_CORE wxComboBox :
public wxWindowWithItems<wxControl, wxComboBoxBase>
{ {
public: public:
inline wxComboBox() {} inline wxComboBox() {}
@@ -154,8 +155,6 @@ public:
bool IsOwnGtkWindow( GdkWindow *window ); bool IsOwnGtkWindow( GdkWindow *window );
void DoApplyWidgetStyle(GtkRcStyle *style); void DoApplyWidgetStyle(GtkRcStyle *style);
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
static wxVisualAttributes static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);

View File

@@ -196,8 +196,8 @@ private:
#define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN #define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN
#define wxHLB_MULTIPLE wxLB_MULTIPLE #define wxHLB_MULTIPLE wxLB_MULTIPLE
class WXDLLIMPEXP_HTML wxSimpleHtmlListBox : public wxHtmlListBox, class WXDLLIMPEXP_HTML wxSimpleHtmlListBox :
public wxItemContainer public wxWindowWithItems<wxHtmlListBox, wxItemContainer>
{ {
DECLARE_ABSTRACT_CLASS(wxSimpleHtmlListBox) DECLARE_ABSTRACT_CLASS(wxSimpleHtmlListBox)
public: public:
@@ -254,9 +254,6 @@ public:
int GetSelection() const int GetSelection() const
{ return wxVListBox::GetSelection(); } { return wxVListBox::GetSelection(); }
// see ctrlsub.h for more info about this:
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
// accessing strings // accessing strings
// ----------------- // -----------------

View File

@@ -233,15 +233,15 @@ private:
// the wxComboCtrl. // the wxComboCtrl.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl, class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox :
public wxItemContainer public wxWindowWithItems<wxComboCtrl, wxItemContainer>
{ {
//friend class wxComboPopupWindow; //friend class wxComboPopupWindow;
friend class wxVListBoxComboPopup; friend class wxVListBoxComboPopup;
public: public:
// ctors and such // ctors and such
wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); } wxOwnerDrawnComboBox() { Init(); }
wxOwnerDrawnComboBox(wxWindow *parent, wxOwnerDrawnComboBox(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -253,7 +253,6 @@ public:
long style = 0, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr) const wxString& name = wxComboBoxNameStr)
: wxComboCtrl()
{ {
Init(); Init();
@@ -339,8 +338,6 @@ public:
virtual bool IsSorted() const { return HasFlag(wxCB_SORT); } virtual bool IsSorted() const { return HasFlag(wxCB_SORT); }
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
protected: protected:
virtual void DoClear(); virtual void DoClear();
virtual void DoDeleteOneItem(unsigned int n); virtual void DoDeleteOneItem(unsigned int n);

View File

@@ -26,12 +26,13 @@ class wxComboWidgetImpl;
// Combobox item // Combobox item
class WXDLLIMPEXP_CORE wxComboBox : class WXDLLIMPEXP_CORE wxComboBox :
public wxWindowWithItems<
#if wxOSX_USE_CARBON #if wxOSX_USE_CARBON
public wxNavigationEnabled<wxControl>, wxNavigationEnabled<wxControl>,
#else #else
public wxControl, wxControl,
#endif #endif
public wxComboBoxBase wxComboBoxBase>
{ {
DECLARE_DYNAMIC_CLASS(wxComboBox) DECLARE_DYNAMIC_CLASS(wxComboBox)
@@ -144,8 +145,6 @@ class WXDLLIMPEXP_CORE wxComboBox :
virtual bool OSXHandleClicked( double timestampsec ); virtual bool OSXHandleClicked( double timestampsec );
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
#if wxOSX_USE_COCOA #if wxOSX_USE_COCOA
wxComboWidgetImpl* GetComboPeer() const; wxComboWidgetImpl* GetComboPeer() const;
#endif #endif

View File

@@ -34,7 +34,8 @@ class WXDLLIMPEXP_FWD_CORE wxListBox;
// NB: Normally we'd like wxComboBox to inherit from wxComboBoxBase, but here // NB: Normally we'd like wxComboBox to inherit from wxComboBoxBase, but here
// we can't really do that since both wxComboBoxBase and wxComboCtrl inherit // we can't really do that since both wxComboBoxBase and wxComboCtrl inherit
// from wxTextCtrl. // from wxTextCtrl.
class WXDLLIMPEXP_CORE wxComboBox : public wxComboCtrl, public wxItemContainer class WXDLLIMPEXP_CORE wxComboBox :
public wxWindowWithItems<wxComboCtrl, wxItemContainer>
{ {
public: public:
// ctors and such // ctors and such
@@ -141,8 +142,6 @@ public:
virtual int GetSelection() const; virtual int GetSelection() const;
virtual wxString GetStringSelection() const; virtual wxString GetStringSelection() const;
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
// we have our own input handler and our own actions // we have our own input handler and our own actions
// (but wxComboCtrl already handled Popup/Dismiss) // (but wxComboCtrl already handled Popup/Dismiss)
/* /*

View File

@@ -902,7 +902,6 @@ wxOwnerDrawnComboBox::wxOwnerDrawnComboBox(wxWindow *parent,
long style, long style,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
: wxComboCtrl()
{ {
Init(); Init();