Hide operator<<() overloads used for wxVariant support too
Add new wxDECLARE_VARIANT_OBJECT_EXPORTED() macro defining these operators as friend functions inside the class declaration and replace all uses of DECLARE_VARIANT_OBJECT_EXPORTED() inside the core library with the new macro to avoid defining any operator<<() overloads in the global scope. Also add wxIMPLEMENT_VARIANT_OBJECT() for consistency, even though it is not really needed.
This commit is contained in:
parent
7f56c7c068
commit
09eff033d9
10 changed files with 63 additions and 54 deletions
|
|
@ -18,6 +18,7 @@
|
|||
#include "wx/gdicmn.h" // for wxBitmapType
|
||||
#include "wx/colour.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/variant.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxBitmap;
|
||||
class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
|
||||
|
|
@ -28,15 +29,6 @@ class WXDLLIMPEXP_FWD_CORE wxMask;
|
|||
class WXDLLIMPEXP_FWD_CORE wxPalette;
|
||||
class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
#include "wx/variant.h"
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLIMPEXP_CORE)
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMask represents the transparent area of the bitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
@ -100,6 +92,9 @@ public:
|
|||
|
||||
// Rescale the given bitmap to the requested size.
|
||||
static void Rescale(wxBitmap& bmp, const wxSize& sizeNeeded);
|
||||
|
||||
// wxVariant support
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap, WXDLLIMPEXP_CORE);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/gdiobj.h"
|
||||
#include "wx/variant.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxColour;
|
||||
|
||||
|
|
@ -53,15 +54,6 @@ const unsigned char wxALPHA_OPAQUE = 0xff;
|
|||
#define wxTransparentColour wxColour(0, 0, 0, wxALPHA_TRANSPARENT)
|
||||
#define wxTransparentColor wxTransparentColour
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
#include "wx/variant.h"
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxColourBase: this class has no data members, just some functions to avoid
|
||||
// code redundancy in all native wxColour implementations
|
||||
|
|
@ -188,6 +180,8 @@ public:
|
|||
wxColour ChangeLightness(int ialpha) const;
|
||||
wxColour& MakeDisabled(unsigned char brightness = 255);
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxColour, WXDLLIMPEXP_CORE);
|
||||
|
||||
protected:
|
||||
// Some ports need Init() and while we don't, provide a stub so that the
|
||||
// ports which don't need it are not forced to define it
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ public:
|
|||
return !IsSameAs(other);
|
||||
}
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_CORE);
|
||||
|
||||
private:
|
||||
wxString m_text;
|
||||
wxBitmapBundle m_bitmap;
|
||||
|
|
@ -74,8 +76,6 @@ private:
|
|||
wxDECLARE_DYNAMIC_CLASS(wxDataViewIconText);
|
||||
};
|
||||
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_CORE)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataViewCheckIconText: value class used by wxDataViewCheckIconTextRenderer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
@ -94,14 +94,14 @@ public:
|
|||
wxCheckBoxState GetCheckedState() const { return m_checkedState; }
|
||||
void SetCheckedState(wxCheckBoxState state) { m_checkedState = state; }
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewCheckIconText, WXDLLIMPEXP_CORE);
|
||||
|
||||
private:
|
||||
wxCheckBoxState m_checkedState;
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS(wxDataViewCheckIconText);
|
||||
};
|
||||
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewCheckIconText, WXDLLIMPEXP_CORE)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataViewRendererBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ public:
|
|||
// ctors, assignment operators...), but it's ok to have such function
|
||||
void CopyFromBitmap(const wxBitmap& bmp);
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxIcon, WXDLLIMPEXP_CORE);
|
||||
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxIcon);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#define _WX_ICON_H_BASE_
|
||||
|
||||
#include "wx/iconloc.h"
|
||||
|
||||
#include "wx/variant.h"
|
||||
|
||||
// a more readable way to tell
|
||||
#define wxICON_SCREEN_DEPTH (-1)
|
||||
|
|
@ -57,15 +57,5 @@
|
|||
#define wxICON_IS_BITMAP
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
#include "wx/variant.h"
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxIcon,WXDLLIMPEXP_CORE)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
// _WX_ICON_H_BASE_
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include "wx/gdicmn.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/arrstr.h"
|
||||
#include "wx/variant.h"
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
# include "wx/stream.h"
|
||||
|
|
@ -98,15 +99,6 @@ class WXDLLIMPEXP_FWD_CORE wxImageHandler;
|
|||
class WXDLLIMPEXP_FWD_CORE wxImage;
|
||||
class WXDLLIMPEXP_FWD_CORE wxPalette;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
#include "wx/variant.h"
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxImage,WXDLLIMPEXP_CORE)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxImageHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -594,6 +586,9 @@ public:
|
|||
static HSVValue RGBtoHSV(const RGBValue& rgb);
|
||||
static RGBValue HSVtoRGB(const HSVValue& hsv);
|
||||
|
||||
// wxVariant support
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxImage, WXDLLIMPEXP_CORE);
|
||||
|
||||
protected:
|
||||
static wxList sm_handlers;
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ public:
|
|||
// ctors, assignment operators...), but it's ok to have such function
|
||||
void CopyFromBitmap(const wxBitmap& bmp);
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxIcon, WXDLLIMPEXP_CORE);
|
||||
|
||||
protected:
|
||||
virtual wxGDIImageRefData *CreateData() const override
|
||||
{
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ public:
|
|||
Init( cpv.m_type, cpv.m_colour );
|
||||
}
|
||||
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID);
|
||||
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxColourPropertyValue);
|
||||
};
|
||||
|
|
@ -121,8 +123,6 @@ private:
|
|||
bool WXDLLIMPEXP_PROPGRID
|
||||
operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
|
||||
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
// Property representing wxFont.
|
||||
|
|
|
|||
|
|
@ -470,7 +470,16 @@ REGISTER_WXANY_CONVERSION(T, CLASSNAME)
|
|||
|
||||
#endif // wxUSE_ANY/!wxUSE_ANY
|
||||
|
||||
// Note: these macros must be used inside "classname" declaration.
|
||||
#define wxDECLARE_VARIANT_OBJECT(classname) \
|
||||
wxDECLARE_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
|
||||
|
||||
#define wxDECLARE_VARIANT_OBJECT_EXPORTED(classname,expdecl) \
|
||||
friend expdecl classname& operator<<(classname &object, const wxVariant &variant); \
|
||||
friend expdecl wxVariant& operator<<(wxVariant &variant, const classname &object)
|
||||
|
||||
// These macros are deprecated, consider using wxDECLARE_VARIANT_OBJECT() above
|
||||
// instead.
|
||||
#define DECLARE_VARIANT_OBJECT(classname) \
|
||||
DECLARE_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
|
||||
|
||||
|
|
@ -478,6 +487,13 @@ REGISTER_WXANY_CONVERSION(T, CLASSNAME)
|
|||
expdecl classname& operator << ( classname &object, const wxVariant &variant ); \
|
||||
expdecl wxVariant& operator << ( wxVariant &variant, const classname &object );
|
||||
|
||||
// These macros use "wx" prefix and require a semicolon after them for
|
||||
// consistency with the rest of wx macros, but are otherwise the same as the
|
||||
// older IMPLEMENT_VARIANT_XXX macros.
|
||||
#define wxIMPLEMENT_VARIANT_OBJECT(classname) \
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE) \
|
||||
struct wxDummyVariantStructFwdDecl /* to force a semicolon */
|
||||
|
||||
#define IMPLEMENT_VARIANT_OBJECT(classname) \
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
|
||||
|
||||
|
|
@ -578,6 +594,13 @@ bool classname##VariantData::Eq(wxVariantData& data) const \
|
|||
|
||||
extern wxVariant WXDLLIMPEXP_BASE wxNullVariant;
|
||||
|
||||
#endif // wxUSE_VARIANT
|
||||
#else // !wxUSE_VARIANT
|
||||
|
||||
// Define these macros to allow using them without checking for wxUSE_VARIANT
|
||||
// and simply do nothing in them in this case.
|
||||
#define wxDECLARE_VARIANT_OBJECT(classname)
|
||||
#define wxDECLARE_VARIANT_OBJECT_EXPORTED(classname,expdecl)
|
||||
|
||||
#endif // wxUSE_VARIANT/!wxUSE_VARIANT
|
||||
|
||||
#endif // _WX_VARIANT_H_
|
||||
|
|
|
|||
|
|
@ -42,21 +42,24 @@
|
|||
required.
|
||||
|
||||
Note that as of wxWidgets 2.7.1, wxVariant is
|
||||
@ref overview_refcount "reference counted". Additionally, the convenience
|
||||
macros DECLARE_VARIANT_OBJECT() and IMPLEMENT_VARIANT_OBJECT() were added
|
||||
so that adding (limited) support for conversion to and from wxVariant can
|
||||
be very easily implemented without modifying either wxVariant or the class
|
||||
to be stored by wxVariant. Since assignment operators cannot be declared
|
||||
outside the class, the shift left operators are used like this:
|
||||
@ref overview_refcount "reference counted".
|
||||
|
||||
Convenience macros wxDECLARE_VARIANT_OBJECT() and wxIMPLEMENT_VARIANT_OBJECT()
|
||||
allow easily adding support for conversion to and from wxVariant to custom
|
||||
classes. The first of these macros must be used inside the class declaration
|
||||
and the second one outside of it in the implementation file, e.g.
|
||||
|
||||
@code
|
||||
// in the header file
|
||||
DECLARE_VARIANT_OBJECT(MyClass)
|
||||
class MyClass : public wxObject {
|
||||
...
|
||||
wxDECLARE_VARIANT_OBJECT(MyClass);
|
||||
};
|
||||
|
||||
// in the implementation file
|
||||
IMPLEMENT_VARIANT_OBJECT(MyClass)
|
||||
wxIMPLEMENT_VARIANT_OBJECT(MyClass);
|
||||
|
||||
// in the user code
|
||||
// and then objects of MyClass can be used with wxVariant like this:
|
||||
wxVariant variant;
|
||||
MyClass value;
|
||||
variant << value;
|
||||
|
|
@ -79,6 +82,11 @@
|
|||
- wxBitmap
|
||||
- wxBitmapBundle
|
||||
|
||||
@note There also are legacy versions of the above macros without `wx`
|
||||
prefix, working in a slightly different way. Please use the new
|
||||
versions in the new code and consider replacing any existing use of
|
||||
the legacy macros with the new ones.
|
||||
|
||||
Note that as of wxWidgets 2.9.0, wxVariantData no longer inherits from
|
||||
wxObject and wxVariant no longer uses the type-unsafe wxList class for list
|
||||
operations but the type-safe wxVariantList class. Also, wxVariantData now
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue