Eliminated C++ RTTI (typeid etc) use. Eliminated wxPGVariantData (default default value for new types is now Null variant). Re-created variantdata creator macros based on those found in variant.h. Using DECLARE/IMPLEMENT_VARIANT_OBJECT whenever possible.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55660 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2008-09-16 15:55:53 +00:00
parent e8443ddaa5
commit 0372d42ea5
17 changed files with 495 additions and 559 deletions

View File

@@ -134,8 +134,8 @@ private:
bool WXDLLIMPEXP_PROPGRID
operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataColourPropertyValue,
wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
#endif
#ifndef SWIG

View File

@@ -813,18 +813,20 @@ wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000
You can change the 'value type' of a property by simply assigning different
type of variant with SetValue. <b>It is mandatory to implement
wxVariantData class for all data types used as property values.</b> Also,
it is further recommended to derive your class from wxPGVariantData, like
this:
wxVariantData class for all data types used as property values.</b>
You can use macros declared in wxPropertyGrid headers. For instance:
@code
// In header file:
// (replace DECL with required data declaration, use
// wxEMPTY_PARAMETER_VALUE if none)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass, DECL)
// (If you need to have export declaration, use version of macros
// with _EXPORTED postfix)
WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
// In sources file:
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass)
WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
// Or, if you don't have valid == operator:
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
@endcode
@library{wxpropgrid}

View File

@@ -57,19 +57,6 @@ public:
// Replace with your own to affect all properties using default renderer.
wxPGCellRenderer* m_defaultRenderer;
// These are for fast variant type comparison
wxPGVariantDataClassInfo wxVariantClassInfo_long;
wxPGVariantDataClassInfo wxVariantClassInfo_string;
wxPGVariantDataClassInfo wxVariantClassInfo_double;
wxPGVariantDataClassInfo wxVariantClassInfo_bool;
wxPGVariantDataClassInfo wxVariantClassInfo_arrstring;
wxPGVariantDataClassInfo wxVariantClassInfo_wxobject;
wxPGVariantDataClassInfo wxVariantClassInfo_list;
wxPGVariantDataClassInfo wxVariantClassInfo_wxColour;
#if wxUSE_DATETIME
wxPGVariantDataClassInfo wxVariantClassInfo_datetime;
#endif
wxPGChoices m_boolChoices;
wxVariant m_vEmptyString;
@@ -79,6 +66,11 @@ public:
wxVariant m_vFalse;
// Cached constant strings
wxPGCachedString m_strstring;
wxPGCachedString m_strlong;
wxPGCachedString m_strbool;
wxPGCachedString m_strlist;
wxPGCachedString m_strMin;
wxPGCachedString m_strMax;
wxPGCachedString m_strUnits;
@@ -101,13 +93,6 @@ public:
extern WXDLLIMPEXP_PROPGRID wxPGGlobalVarsClass* wxPGGlobalVars;
#define wxPGIsVariantType(VARIANT, T) \
((VARIANT).GetData() && \
typeid(*(VARIANT).GetData()) == *wxPGGlobalVars->wxVariantClassInfo_##T)
#define wxPGIsVariantClassInfo(CLASSINFO, T) \
(*CLASSINFO == *wxPGGlobalVars->wxVariantClassInfo_##T)
#define wxPGVariant_EmptyString (wxPGGlobalVars->m_vEmptyString)
#define wxPGVariant_Zero (wxPGGlobalVars->m_vZero)
#define wxPGVariant_MinusOne (wxPGGlobalVars->m_vMinusOne)
@@ -116,8 +101,6 @@ extern WXDLLIMPEXP_PROPGRID wxPGGlobalVarsClass* wxPGGlobalVars;
#define wxPGVariant_Bool(A) (A?wxPGVariant_True:wxPGVariant_False)
#define wxPGVariantAssign(A, B) A = B
#endif // !SWIG
// -----------------------------------------------------------------------

View File

@@ -453,93 +453,15 @@ WX_PG_DECLARE_EDITOR_WITH_DECL(ChoiceAndButton,WXDLLIMPEXP_PROPGRID)
#ifndef SWIG
/** @class wxPGVariantData
@ingroup classes
wxVariantData with additional functionality.
It is usually enough to use supplied to macros to automatically generate
variant data class. Like so:
@code
// In header
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataMyClass, // Name of the class
MyClass, // Name of the data type
wxEMPTY_PARAMETER_VALUE) // Declaration
// In source
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataMyClass, MyClass)
@endcode
If your class is derived from wxObject, it is recommended that you use
wxObject-versions of the macros (WX_PG_DECLARE_WXOBJECT_VARIANT_DATA and
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA).
*/
class WXDLLIMPEXP_PROPGRID wxPGVariantData : public wxVariantData
{
public:
virtual void* GetValuePtr() = 0;
virtual wxVariant GetDefaultValue() const = 0;
protected:
};
//
// With wxWidgets 2.9 and later we demand native C++ RTTI support
#ifdef wxNO_RTTI
#error "You need to enable compiler RTTI support for wxPropertyGrid"
#endif
#define WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(A)
#define WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(A, B)
typedef const std::type_info* wxPGVariantDataClassInfo;
#define wxPGVariantDataGetClassInfo(A) (&typeid(*A))
#define wxPG_VARIANT_EQ(A, B) \
( ((A).GetData() && \
(B).GetData() && typeid(*(A).GetData()) == typeid(*(B).GetData()) && \
(A == B)) || !((A).GetData() && (B).GetData()) )
#ifndef wxDynamicCastVariantData
#define wxDynamicCastVariantData wxDynamicCast
#endif
inline void wxPGDoesNothing() {}
#define _WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, \
DATATYPE, \
AS_ARG, \
AS_ARG_CONST, \
CTOR_CODE, \
DEFAULT_VALUE, \
SET_CODE) \
WX_PG_DECLARE_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME) \
protected: \
DATATYPE m_value; \
public: \
CLASSNAME() { CTOR_CODE; } \
CLASSNAME(AS_ARG_CONST value) { CTOR_CODE; SET_CODE; m_value = value; } \
DATATYPE GetValue() const { return m_value; } \
AS_ARG_CONST GetValueRef() const { return m_value; } \
AS_ARG GetValueRef() { return m_value; } \
void SetValue(AS_ARG_CONST value) { SET_CODE; m_value = value; } \
virtual bool Eq(wxVariantData&) const { return false; } \
virtual wxString GetType() const { return wxS(#DATATYPE); } \
virtual wxVariantData* Clone() { return new CLASSNAME; } \
virtual bool Read(wxString &) { return false; } \
virtual bool Write(wxString &) const { return true; } \
virtual wxVariant GetDefaultValue() const { return DEFAULT_VALUE; }
//
// Macro WXVARIANT allows creation of wxVariant from any type supported by
// wxWidgets internally, and of all types created using
// WX_PG_DECLARE_VARIANT_DATA.
template<class T>
wxVariant WXVARIANT( const T& value )
wxVariant WXVARIANT( const T& WXUNUSED(value) )
{
return wxVariant((void*)&value);
wxFAIL_MSG("Code should always call specializations of this template");
return wxVariant();
}
template<> inline wxVariant WXVARIANT( const int& value )
@@ -559,127 +481,135 @@ template<> inline wxVariant WXVARIANT( const wxDateTime& value )
{ return wxVariant(value); }
#endif
#define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME) \
extern int CLASSNAME##_d_;
#define _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \
int CLASSNAME##_d_;
#define _WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \
DATATYPE, \
AS_ARG, \
AS_CONST_ARG, \
NULLVAL, \
BASECLASS) \
_WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER(CLASSNAME) \
WX_PG_IMPLEMENT_DYNAMIC_CLASS_VARIANTDATA(CLASSNAME, BASECLASS) \
AS_ARG operator <<( AS_ARG value, const wxVariant &variant ) \
//
// These are modified versions of DECLARE/WX_PG_IMPLEMENT_VARIANT_DATA
// macros found in variant.h. Difference are as follows:
// * These support non-wxObject data
// * These implement classname##RefFromVariant function which returns
// reference to data within.
// * const char* classname##_VariantType which equals classname.
// * WXVARIANT
//
#define WX_PG_DECLARE_VARIANT_DATA(classname) \
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
#define WX_PG_DECLARE_VARIANT_DATA_EXPORTED(classname,expdecl) \
expdecl classname& operator << ( classname &object, const wxVariant &variant ); \
expdecl wxVariant& operator << ( wxVariant &variant, const classname &object ); \
expdecl const classname& classname##RefFromVariant( const wxVariant& variant ); \
expdecl classname& classname##RefFromVariant( wxVariant& variant ); \
template<> inline wxVariant WXVARIANT( const classname& value ) \
{ \
CLASSNAME *data = wxDynamicCastVariantData( variant.GetData(), CLASSNAME ); \
wxASSERT( data ); \
wxVariant variant; \
variant << value; \
return variant; \
} \
extern expdecl const char* classname##_VariantType;
#define WX_PG_IMPLEMENT_VARIANT_DATA(classname) \
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ(classname,expdecl) \
const char* classname##_VariantType = #classname; \
class classname##VariantData: public wxVariantData \
{ \
public:\
classname##VariantData() {} \
classname##VariantData( const classname &value ) { m_value = value; } \
\
classname &GetValue() { return m_value; } \
\
virtual bool Eq(wxVariantData& data) const; \
\
virtual wxString GetType() const; \
\
virtual wxVariantData* Clone() const { return new classname##VariantData(m_value); } \
\
classname& GetValueRef() { return m_value; } \
\
const classname& GetValueRef() const { return m_value; } \
\
protected:\
classname m_value; \
};\
\
wxString classname##VariantData::GetType() const\
{\
return wxS(#classname);\
}\
\
expdecl classname& operator << ( classname &value, const wxVariant &variant )\
{\
wxASSERT( variant.GetType() == #classname );\
\
classname##VariantData *data = (classname##VariantData*) variant.GetData();\
value = data->GetValue();\
return value;\
}\
wxVariant& operator <<( wxVariant &variant, AS_CONST_ARG value ) \
\
expdecl wxVariant& operator << ( wxVariant &variant, const classname &value )\
{\
CLASSNAME *data = new CLASSNAME( value ); \
classname##VariantData *data = new classname##VariantData( value );\
variant.SetData( data );\
return variant;\
} \
AS_ARG DATATYPE##FromVariant( const wxVariant& v ) \
expdecl classname& classname##RefFromVariant( wxVariant& variant ) \
{ \
CLASSNAME *data = wxDynamicCastVariantData( v.GetData(), CLASSNAME ); \
if ( !data ) \
return NULLVAL; \
wxASSERT( variant.GetType() == #classname );\
classname##VariantData *data = (classname##VariantData*) variant.GetData();\
return data->GetValueRef();\
} \
wxVariant DATATYPE##ToVariant( AS_CONST_ARG value ) \
expdecl const classname& classname##RefFromVariant( const wxVariant& variant ) \
{ \
wxVariant variant( new CLASSNAME( value ) ); \
return variant; \
wxASSERT( variant.GetType() == #classname );\
classname##VariantData *data = (classname##VariantData*) variant.GetData();\
return data->GetValueRef();\
}
#define WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE) \
class CLASSNAME : public wxPGVariantData \
// implements a wxVariantData-derived class using for the Eq() method the
// operator== which must have been provided by "classname"
#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname,expdecl) \
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
\
bool classname##VariantData::Eq(wxVariantData& data) const \
{\
_WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \
const DATATYPE&, wxPGDoesNothing(), \
wxVariant(new CLASSNAME(DATATYPE())), \
wxPGDoesNothing()) \
public: \
virtual void* GetValuePtr() { return (void*)&m_value; } \
}; \
_WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, \
DATATYPE, \
DATATYPE&, \
const DATATYPE&, \
(DATATYPE&)*((DATATYPE*)NULL), \
wxPGVariantData)
wxASSERT( GetType() == data.GetType() );\
\
classname##VariantData & otherData = (classname##VariantData &) data;\
\
return otherData.m_value == m_value;\
}
#define WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(CLASSNAME, DATATYPE) \
class CLASSNAME : public wxPGVariantData \
#define WX_PG_IMPLEMENT_VARIANT_DATA(classname) \
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
// with Eq() implementation that always returns false
#define WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(classname,expdecl) \
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
\
bool classname##VariantData::Eq(wxVariantData& WXUNUSED(data)) const \
{\
_WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE, DATATYPE&, \
const DATATYPE&, wxPGDoesNothing(), \
wxVariant(new CLASSNAME(DATATYPE())), \
wxPGDoesNothing()) \
public: \
virtual void* GetValuePtr() { return (void*)&m_value; } \
virtual wxClassInfo* GetValueClassInfo() \
{ return m_value.GetClassInfo(); } \
}; \
_WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE&, \
const DATATYPE&, \
(DATATYPE&)*((DATATYPE*)NULL), \
wxPGVariantData)
return false; \
}
#define WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(classname) \
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(classname, wxEMPTY_PARAMETER_VALUE)
#define WX_PG_DECLARE_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \
DECL DATATYPE& operator <<( DATATYPE& value, const wxVariant &variant ); \
DECL wxVariant& operator <<( wxVariant &variant, const DATATYPE& value ); \
DECL DATATYPE& DATATYPE##FromVariant( const wxVariant& variant ); \
DECL wxVariant DATATYPE##ToVariant( const DATATYPE& value ); \
template<> inline wxVariant WXVARIANT( const DATATYPE& value ) \
{ return DATATYPE##ToVariant(value); } \
DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME);
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxPoint, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxSize, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxArrayInt, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxLongLong, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA_EXPORTED(wxULongLong, WXDLLIMPEXP_PROPGRID)
DECLARE_VARIANT_OBJECT_EXPORTED(wxFont, WXDLLIMPEXP_PROPGRID)
template<> inline wxVariant WXVARIANT( const wxFont& value )
{
wxVariant variant;
variant << value;
return variant;
}
#define WX_PG_DECLARE_WXOBJECT_VARIANT_DATA WX_PG_DECLARE_VARIANT_DATA
#define WX_PG_DECLARE_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DECL) \
DECL DATATYPE* operator <<( DATATYPE* value, const wxVariant &variant ); \
DECL wxVariant& operator <<( wxVariant &variant, DATATYPE* value ); \
DECL DATATYPE* DATATYPE##FromVariant( const wxVariant& variant ); \
DECL wxVariant DATATYPE##ToVariant( DATATYPE* value ); \
DECL _WX_PG_VARIANT_DATA_CLASSINFO_CONTAINER_DECL(CLASSNAME);
#define WX_PG_IMPLEMENT_PTR_VARIANT_DATA(CLASSNAME, DATATYPE, DEFAULT) \
class CLASSNAME : public wxPGVariantData \
{ \
_WX_PG_IMPLEMENT_VARIANT_DATA_CLASS(CLASSNAME, DATATYPE*, DATATYPE*, \
DATATYPE*, m_value = NULL, \
DEFAULT, \
if (m_value) Py_DECREF(m_value); \
if (!value) value = Py_None; \
Py_INCREF(value) ) \
~CLASSNAME() { if (m_value) Py_DECREF(m_value); } \
public: \
virtual void* GetValuePtr() { return (void*)m_value; } \
}; \
_WX_PG_IMPLEMENT_VARIANT_DATA(CLASSNAME, DATATYPE, DATATYPE*, DATATYPE*, \
NULL, wxPGVariantData)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataPoint, wxPoint, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataSize, wxSize, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataArrayInt,
wxArrayInt, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataLongLong,
wxLongLong, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataULongLong,
wxULongLong, WXDLLIMPEXP_PROPGRID)
WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataFont,
wxFont, WXDLLIMPEXP_PROPGRID)
template<> inline wxVariant WXVARIANT( const wxColour& value )
{
wxVariant variant;
@@ -687,8 +617,15 @@ template<> inline wxVariant WXVARIANT( const wxColour& value )
return variant;
}
#define WX_PG_VARIANT_GETVALUEREF(P, T) \
(*((T*)((wxPGVariantData*)(P.GetData()))->GetValuePtr()))
// Define constants for common wxVariant type strings
#define wxPG_VARIANT_TYPE_STRING wxPGGlobalVars->m_strstring
#define wxPG_VARIANT_TYPE_LONG wxPGGlobalVars->m_strlong
#define wxPG_VARIANT_TYPE_BOOL wxPGGlobalVars->m_strbool
#define wxPG_VARIANT_TYPE_LIST wxPGGlobalVars->m_strlist
#define wxPG_VARIANT_TYPE_DOUBLE wxS("double")
#define wxPG_VARIANT_TYPE_ARRSTRING wxS("arrstring")
#define wxPG_VARIANT_TYPE_DATETIME wxS("datetime")
// Safely converts a wxVariant to (long) int. Supports converting from string
// and boolean as well.
@@ -714,28 +651,6 @@ bool wxPGVariantToDouble( const wxVariant& variant, double* pResult );
#ifndef SWIG
WXDLLIMPEXP_PROPGRID
wxObject*
wxPG_VariantToWxObject( const wxVariant& variant, wxClassInfo* classInfo );
//
// Redefine wxGetVariantCast to also take propertygrid variantdata
// classes into account.
//
#undef wxGetVariantCast
#define wxGetVariantCast(var,classname) \
(classname*)wxPG_VariantToWxObject(var,&classname::ms_classInfo)
// TODO: After a while, remove this.
#define WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) \
(CLASSNAME*)wxPG_VariantToWxObject(VARIANT,&CLASSNAME::ms_classInfo)
#endif // !SWIG
// -----------------------------------------------------------------------
#ifndef SWIG
//
// Tokenizer macros.
// NOTE: I have made two versions - worse ones (performance and consistency

View File

@@ -116,10 +116,10 @@ typedef const wxPGPropArgCls& wxPGPropArg;
WXDLLIMPEXP_PROPGRID
void wxPGTypeOperationFailed( const wxPGProperty* p,
const wxChar* typestr,
const wxChar* op );
const wxString& typestr,
const wxString& op );
WXDLLIMPEXP_PROPGRID
void wxPGGetFailed( const wxPGProperty* p, const wxChar* typestr );
void wxPGGetFailed( const wxPGProperty* p, const wxString& typestr );
// -----------------------------------------------------------------------
@@ -550,74 +550,80 @@ public:
#endif
bool GetPropertyValueAsBool( wxPGPropArg id ) const;
double GetPropertyValueAsDouble( wxPGPropArg id ) const;
wxObject* GetPropertyValueAsWxObjectPtr( wxPGPropArg id ) const;
void* GetPropertyValueAsVoidPtr( wxPGPropArg id ) const;
#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
if ( p->m_value.GetType() != TYPENAME ) \
wxString typeName(wxS(TYPENAME)); \
wxVariant value = p->GetValue(); \
if ( value.GetType() != typeName ) \
{ \
wxPGGetFailed(p, TYPENAME); \
wxPGGetFailed(p, typeName); \
return DEFVAL; \
}
#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
if ( p->m_value.GetType() != TYPENAME ) \
wxVariant value = p->GetValue(); \
if ( value.GetType() != wxS(TYPENAME) ) \
return DEFVAL; \
wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("arrstring"),
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("arrstring",
wxArrayString())
return p->m_value.GetArrayString();
return value.GetArrayString();
}
wxPoint GetPropertyValueAsPoint( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxPoint"), wxPoint())
return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxPoint);
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxPoint", wxPoint())
wxPoint pt;
pt << value;
return pt;
}
wxSize GetPropertyValueAsSize( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxSize"), wxSize())
return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxSize);
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxSize", wxSize())
wxSize sz;
sz << value;
return sz;
}
wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxLongLong"),
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxLongLong",
(long) GetPropertyValueAsLong(id))
return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxLongLong).GetValue();
wxLongLong ll;
ll << value;
return ll.GetValue();
}
wxULongLong_t GetPropertyValueAsULongLong( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxULongLong"),
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxULongLong",
(unsigned long) GetPropertyValueAsULong(id))
return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxULongLong).GetValue();
wxULongLong ull;
ull << value;
return ull.GetValue();
}
wxArrayInt GetPropertyValueAsArrayInt( wxPGPropArg id ) const
{
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxArrayInt"),
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxArrayInt",
wxArrayInt())
wxArrayInt arr = WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxArrayInt);
wxArrayInt arr;
arr << value;
return arr;
}
#if wxUSE_DATETIME
wxDateTime GetPropertyValueAsDateTime( wxPGPropArg id ) const
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxDateTime())
if ( wxStrcmp(p->m_value.GetType(), wxT("datetime")) != 0 )
{
wxPGGetFailed(p, wxT("datetime"));
return wxDateTime();
}
return p->m_value.GetDateTime();
wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("datetime",
wxDateTime())
return value.GetDateTime();
}
#endif

View File

@@ -406,18 +406,22 @@ struct wxPGChoiceInfo
they are only really needed if you need to use wxRTTI with your
property class.
You can change the 'value type' of a property by simply assigning different type
of variant with SetValue. <b>It is mandatory to implement wxVariantData class
for all data types used as property values.</b> Also, it is further recommended
to derive your class from wxPGVariantData, like this:
You can change the 'value type' of a property by simply assigning different
type of variant with SetValue. <b>It is mandatory to implement
wxVariantData class for all data types used as property values.</b>
You can use macros declared in wxPropertyGrid headers. For instance:
@code
// In header file:
// (replace DECL with required data declaration, wxEMPTY_PARAMETER_VALUE if none)
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass, DECL)
// (If you need to have export declaration, use version of macros
// with _EXPORTED postfix)
WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
// In sources file:
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass)
WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
// Or, if you don't have valid == operator:
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
@endcode
@library{wxpropgrid}

View File

@@ -350,8 +350,7 @@ public:
return p->GetValidator();
}
/** Returns value as wxVariant. To get wxObject pointer from it,
you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro.
/** Returns value as wxVariant.
If property value is unspecified, Null variant is returned.
*/
@@ -370,7 +369,6 @@ public:
int GetPropertyValueAsInt( wxPGPropArg id ) const { return (int)GetPropertyValueAsLong(id); }
bool GetPropertyValueAsBool( wxPGPropArg id ) const;
double GetPropertyValueAsDouble( wxPGPropArg id ) const;
wxObject* GetPropertyValueAsWxObjectPtr( wxPGPropArg id ) const;
void* GetPropertyValueAsVoidPtr( wxPGPropArg id ) const;
wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const

View File

@@ -459,7 +459,7 @@ void wxAdvImageFileProperty::OnCustomPaint( wxDC& dc,
// See propgridsample.h for wxVector3f class
WX_PG_IMPLEMENT_VARIANT_DATA(wxVector3fVariantData, wxVector3f)
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxVector3f)
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxVectorProperty,wxPGProperty,
wxVector3f,const wxVector3f&,TextCtrl)
@@ -470,7 +470,7 @@ wxVectorProperty::wxVectorProperty( const wxString& label,
const wxVector3f& value )
: wxPGProperty(label,name)
{
SetValue( wxVector3fToVariant(value) );
SetValue( WXVARIANT(value) );
AddChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
AddChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
@@ -481,7 +481,7 @@ wxVectorProperty::~wxVectorProperty() { }
void wxVectorProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
wxVector3f& vector = wxVector3fFromVariant(m_value);
const wxVector3f& vector = wxVector3fRefFromVariant(m_value);
Item(0)->SetValue( vector.x );
Item(1)->SetValue( vector.y );
Item(2)->SetValue( vector.z );
@@ -489,13 +489,15 @@ void wxVectorProperty::RefreshChildren()
void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
{
wxVector3f& vector = wxVector3fFromVariant(thisValue);
wxVector3f vector;
vector << thisValue;
switch ( childIndex )
{
case 0: vector.x = childValue.GetDouble(); break;
case 1: vector.y = childValue.GetDouble(); break;
case 2: vector.z = childValue.GetDouble(); break;
}
thisValue << vector;
}
@@ -505,7 +507,7 @@ void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVar
// See propgridsample.h for wxTriangle class
WX_PG_IMPLEMENT_VARIANT_DATA(wxTriangleVariantData, wxTriangle)
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxTriangle)
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxTriangleProperty,wxPGProperty,
wxTriangle,const wxTriangle&,TextCtrl)
@@ -516,7 +518,7 @@ wxTriangleProperty::wxTriangleProperty( const wxString& label,
const wxTriangle& value)
: wxPGProperty(label,name)
{
SetValue( wxTriangleToVariant(value) );
SetValue( WXVARIANT(value) );
AddChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
AddChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
AddChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
@@ -527,22 +529,24 @@ wxTriangleProperty::~wxTriangleProperty() { }
void wxTriangleProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
wxTriangle& triangle = wxTriangleFromVariant(m_value);
Item(0)->SetValue( wxVector3fToVariant(triangle.a) );
Item(1)->SetValue( wxVector3fToVariant(triangle.b) );
Item(2)->SetValue( wxVector3fToVariant(triangle.c) );
const wxTriangle& triangle = wxTriangleRefFromVariant(m_value);
Item(0)->SetValue( WXVARIANT(triangle.a) );
Item(1)->SetValue( WXVARIANT(triangle.b) );
Item(2)->SetValue( WXVARIANT(triangle.c) );
}
void wxTriangleProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
{
wxTriangle& triangle = wxTriangleFromVariant(thisValue);
wxVector3f& vector = wxVector3fFromVariant(childValue);
wxTriangle triangle;
triangle << thisValue;
const wxVector3f& vector = wxVector3fRefFromVariant(childValue);
switch ( childIndex )
{
case 0: triangle.a = vector; break;
case 1: triangle.b = vector; break;
case 2: triangle.c = vector; break;
}
thisValue << triangle;
}
@@ -922,34 +926,36 @@ void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event )
else
if ( name == wxT("Font") )
{
wxFont& font = *wxDynamicCast(m_pPropGridManager->GetPropertyValueAsWxObjectPtr(property), wxFont);
wxASSERT( &font && font.Ok() );
wxFont font;
font << value;
wxASSERT( font.Ok() );
m_pPropGridManager->SetFont( font );
}
else
if ( name == wxT("Margin Colour") )
{
wxColourPropertyValue& cpv = *wxGetVariantCast(value,wxColourPropertyValue);
wxColourPropertyValue cpv;
cpv << value;
m_pPropGridManager->GetGrid()->SetMarginColour( cpv.m_colour );
}
else if ( name == wxT("Cell Colour") )
{
wxColourPropertyValue* cpv = wxGetVariantCast(value,wxColourPropertyValue);
wxASSERT( cpv );
m_pPropGridManager->GetGrid()->SetCellBackgroundColour( cpv->m_colour );
wxColourPropertyValue cpv;
cpv << value;
m_pPropGridManager->GetGrid()->SetCellBackgroundColour( cpv.m_colour );
}
else if ( name == wxT("Line Colour") )
{
wxColourPropertyValue* cpv = wxGetVariantCast(value,wxColourPropertyValue);
wxASSERT( cpv );
m_pPropGridManager->GetGrid()->SetLineColour( cpv->m_colour );
wxColourPropertyValue cpv;
cpv << value;
m_pPropGridManager->GetGrid()->SetLineColour( cpv.m_colour );
}
else if ( name == wxT("Cell Text Colour") )
{
wxColourPropertyValue* cpv = wxGetVariantCast(value,wxColourPropertyValue);
wxASSERT( cpv );
m_pPropGridManager->GetGrid()->SetCellTextColour( cpv->m_colour );
wxColourPropertyValue cpv;
cpv << value;
m_pPropGridManager->GetGrid()->SetCellTextColour( cpv.m_colour );
}
}

View File

@@ -62,7 +62,7 @@ inline bool operator == (const wxVector3f& a, const wxVector3f& b)
return (a.x == b.x && a.y == b.y && a.z == b.z);
}
WX_PG_DECLARE_VARIANT_DATA(wxVector3fVariantData, wxVector3f, wxEMPTY_PARAMETER_VALUE)
WX_PG_DECLARE_VARIANT_DATA(wxVector3f)
class wxVectorProperty : public wxPGProperty
{
@@ -92,7 +92,7 @@ inline bool operator == (const wxTriangle& a, const wxTriangle& b)
return (a.a == b.a && a.b == b.b && a.c == b.c);
}
WX_PG_DECLARE_VARIANT_DATA(wxTriangleVariantData, wxTriangle, wxEMPTY_PARAMETER_VALUE)
WX_PG_DECLARE_VARIANT_DATA(wxTriangle)
class wxTriangleProperty : public wxPGProperty
{

View File

@@ -48,7 +48,7 @@ bool operator == (const wxFontData&, const wxFontData&)
#include <wx/fontdlg.h>
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(wxPGVariantDataFontData, wxFontData)
IMPLEMENT_VARIANT_OBJECT_SHALLOWCMP(wxFontData)
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontDataProperty,wxFontProperty,
wxFontData,const wxFontData&,TextCtrlAndButton)
@@ -56,52 +56,69 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontDataProperty,wxFontProperty,
wxFontDataProperty::wxFontDataProperty( const wxString& label, const wxString& name,
const wxFontData& value ) : wxFontProperty(label,name,value.GetInitialFont())
{
// Set initial value - should be done in a simpler way like this
// (instead of calling SetValue) in derived (wxObject) properties.
m_value_wxFontData << value;
wxFontData& fontData = wxFontDataFromVariant(m_value_wxFontData);
wxFontData fontData(value);
// Fix value.
fontData.SetChosenFont(value.GetInitialFont());
if ( !fontData.GetColour().Ok() )
fontData.SetColour(*wxBLACK);
// Set initial value - should be done in a simpler way like this
// (instead of calling SetValue) in derived (wxObject) properties.
m_value_wxFontData << value;
// Add extra children.
AddChild( new wxColourProperty(_("Colour"), wxPG_LABEL,
fontData.GetColour() ) );
}
wxFontDataProperty::~wxFontDataProperty () { }
void wxFontDataProperty::OnSetValue()
{
if ( !(&wxFontDataFromVariant(m_value)) )
if ( m_value.GetType() != "wxFontData" )
{
wxFont* pFont = &wxFontFromVariant(m_value);
if ( pFont )
if ( m_value.GetType() == "wxFont" )
{
wxFont font;
font << m_value;
wxFontData fontData;
fontData.SetChosenFont(*pFont);
m_value = WXVARIANT(fontData);
fontData.SetChosenFont(font);
if ( !m_value_wxFontData.IsNull() )
{
wxFontData oldFontData;
oldFontData << m_value_wxFontData;
fontData.SetColour(oldFontData.GetColour());
}
else
{
fontData.SetColour(*wxBLACK);
}
wxVariant variant;
variant << fontData;
m_value_wxFontData = variant;
}
else
{
wxFAIL_MSG(wxT("Value to wxFontDataProperty must be eithe wxFontData or wxFont"));
}
}
else
{
// Set m_value to wxFont so that wxFontProperty methods will work
// correctly.
m_value_wxFontData = m_value;
wxFontData& fontData = wxFontDataFromVariant(m_value_wxFontData);
wxFontData fontData;
fontData << m_value_wxFontData;
wxFont font = fontData.GetChosenFont();
if ( !font.Ok() )
font = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
m_value = WXVARIANT(font);
}
}
wxVariant wxFontDataProperty::DoGetValue() const
{
@@ -117,7 +134,8 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
// Update value from last minute changes
PrepareValueForDialogEditing(propgrid);
wxFontData& fontData = wxFontDataFromVariant(m_value_wxFontData);
wxFontData fontData;
fontData << m_value_wxFontData;
fontData.SetInitialFont(fontData.GetChosenFont());
@@ -125,7 +143,9 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
if ( dlg.ShowModal() == wxID_OK )
{
SetValueInEvent( wxFontDataToVariant(dlg.GetFontData()) );
wxVariant variant;
variant << dlg.GetFontData();
SetValueInEvent( variant );
return true;
}
}
@@ -135,16 +155,17 @@ bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
void wxFontDataProperty::RefreshChildren()
{
wxFontProperty::RefreshChildren();
if ( GetChildCount() < 6 ) // Number is count of inherit prop's children + 1.
if ( GetChildCount() < 6 ) // Number is count of wxFontProperty's children + 1.
return;
wxFontData& fontData = wxFontDataFromVariant(m_value_wxFontData);
wxFontData fontData; fontData << m_value_wxFontData;
wxVariant variant; variant << fontData.GetColour();
Item(6)->SetValue( variant );
}
void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
{
wxFontData& fontData = wxFontDataFromVariant(thisValue);
wxFontData fontData;
fontData << thisValue;
wxColour col;
wxVariant variant;
@@ -155,11 +176,15 @@ void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV
fontData.SetColour( col );
break;
default:
// Transfer between subset to superset.
variant = WXVARIANT(fontData.GetChosenFont());
// Transfer from subset to superset.
wxFont font = fontData.GetChosenFont();
variant = WXVARIANT(font);
wxFontProperty::ChildChanged( variant, childIndex, childValue );
fontData.SetChosenFont(wxFontFromVariant(variant));
font << variant;
fontData.SetChosenFont(font);
}
thisValue << fontData;
}
// -----------------------------------------------------------------------
@@ -182,14 +207,14 @@ wxSizeProperty::~wxSizeProperty() { }
void wxSizeProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
const wxSize& size = wxSizeFromVariant(m_value);
const wxSize& size = wxSizeRefFromVariant(m_value);
Item(0)->SetValue( (long)size.x );
Item(1)->SetValue( (long)size.y );
}
void wxSizeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
{
wxSize& size = wxSizeFromVariant(thisValue);
wxSize& size = wxSizeRefFromVariant(thisValue);
int val = wxPGVariantToInt(childValue);
switch ( childIndex )
{
@@ -218,14 +243,14 @@ wxPointProperty::~wxPointProperty() { }
void wxPointProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
const wxPoint& point = wxPointFromVariant(m_value);
const wxPoint& point = wxPointRefFromVariant(m_value);
Item(0)->SetValue( (long)point.x );
Item(1)->SetValue( (long)point.y );
}
void wxPointProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
{
wxPoint& point = wxPointFromVariant(thisValue);
wxPoint& point = wxPointRefFromVariant(thisValue);
int val = wxPGVariantToInt(childValue);
switch ( childIndex )
{
@@ -452,7 +477,7 @@ bool operator == (const wxArrayDouble& a, const wxArrayDouble& b)
return TRUE;
}
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataArrayDouble, wxArrayDouble)
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxArrayDouble)
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxArrayDoubleProperty,
wxPGProperty,
@@ -478,7 +503,7 @@ wxArrayDoubleProperty::wxArrayDoubleProperty (const wxString& label,
m_delimiter = use_delimiter;
SetValue( wxArrayDoubleToVariant(array) );
SetValue( WXVARIANT(array) );
}
wxArrayDoubleProperty::~wxArrayDoubleProperty () { }
@@ -509,7 +534,7 @@ void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, b
target.Empty();
const wxArrayDouble& value = wxArrayDoubleFromVariant(m_value);
const wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
for ( i=0; i<value.GetCount(); i++ )
{
@@ -529,7 +554,7 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
{
if ( propgrid->IsMainButtonEvent(event) )
{
wxArrayDouble& value = wxArrayDoubleFromVariant(m_value);
wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
// Update the value in case of last minute changes
PrepareValueForDialogEditing(propgrid);
@@ -544,7 +569,7 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
int res = dlg.ShowModal();
if ( res == wxID_OK && dlg.IsModified() )
{
SetValueInEvent( wxArrayDoubleToVariant(dlg.GetArray()) );
SetValueInEvent( WXVARIANT(dlg.GetArray()) );
return true;
}
return false;
@@ -591,9 +616,9 @@ bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& t
return false;
}
if ( !(wxArrayDoubleFromVariant(m_value) == new_array) )
if ( !(wxArrayDoubleRefFromVariant(m_value) == new_array) )
{
variant = wxArrayDoubleToVariant(new_array);
variant = WXVARIANT(new_array);
return true;
}

View File

@@ -13,7 +13,7 @@
#define _WX_SAMPLES_PROPGRID_SAMPLEPROPS_H_
WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataFontData, wxFontData, wxEMPTY_PARAMETER_VALUE)
DECLARE_VARIANT_OBJECT(wxFontData)
class wxFontDataProperty : public wxFontProperty
@@ -61,7 +61,7 @@ protected:
// I stands for internal
void SetValueI( const wxSize& value )
{
m_value = wxSizeToVariant(value);
m_value = WXVARIANT(value);
}
};
@@ -83,7 +83,7 @@ protected:
// I stands for internal
void SetValueI( const wxPoint& value )
{
m_value = wxPointToVariant(value);
m_value = WXVARIANT(value);
}
};
@@ -93,7 +93,7 @@ WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(wxDirsProperty, clas
// -----------------------------------------------------------------------
WX_PG_DECLARE_VARIANT_DATA(wxPGVariantDataArrayDouble, wxArrayDouble, wxEMPTY_PARAMETER_VALUE)
WX_PG_DECLARE_VARIANT_DATA(wxArrayDouble)
class wxArrayDoubleProperty : public wxPGProperty
{

View File

@@ -446,7 +446,7 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
const wxFont& value )
: wxPGProperty(label,name)
{
SetValue( wxFontToVariant(value) );
SetValue(WXVARIANT(value));
// Initialize font family choices list
if ( !wxPGGlobalVars->m_fontFamilyChoices )
@@ -467,7 +467,8 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
wxString emptyString(wxEmptyString);
wxFont& font = wxFontFromVariant(m_value);
wxFont font;
font << m_value;
AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font.GetPointSize() ) );
@@ -502,16 +503,14 @@ wxFontProperty::~wxFontProperty() { }
void wxFontProperty::OnSetValue()
{
wxFont& font = wxFontFromVariant(m_value);
wxASSERT(&font);
wxFont font;
font << m_value;
wxFont font2;
if ( !font.Ok() )
font2 = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
else
font2 = font;
m_value = wxFontToVariant(font2);
{
font = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
m_value << font;
}
}
wxString wxFontProperty::GetValueAsString( int argFlags ) const
@@ -528,7 +527,9 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
PrepareValueForDialogEditing(propgrid);
wxFontData data;
data.SetInitialFont( wxFontFromVariant(m_value) );
wxFont font;
font << m_value;
data.SetInitialFont( font );
data.SetColour(*wxBLACK);
wxFontDialog dlg(propgrid, data);
@@ -536,7 +537,8 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
{
propgrid->EditorsValueWasModified();
wxVariant variant = wxFontToVariant(dlg.GetFontData().GetChosenFont());
wxVariant variant;
variant << dlg.GetFontData().GetChosenFont();
SetValueInEvent( variant );
return true;
}
@@ -547,7 +549,8 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
void wxFontProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
const wxFont& font = wxFontFromVariant(m_value);
wxFont font;
font << m_value;
Item(0)->SetValue( (long)font.GetPointSize() );
Item(1)->SetValue( (long)font.GetFamily() );
Item(2)->SetValueFromString( font.GetFaceName(), wxPG_FULL_VALUE );
@@ -558,7 +561,8 @@ void wxFontProperty::RefreshChildren()
void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& childValue ) const
{
wxFont& font = wxFontFromVariant(thisValue);
wxFont font;
font << thisValue;
if ( ind == 0 )
{
@@ -604,6 +608,8 @@ void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& chi
{
font.SetUnderlined( childValue.GetBool() );
}
thisValue << font;
}
/*
@@ -718,7 +724,7 @@ static long gs_cp_es_syscolour_values[] = {
};
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(wxPGVariantDataColourPropertyValue, wxColourPropertyValue)
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
// Class body is in advprops.h
@@ -738,7 +744,7 @@ void wxSystemColourProperty::Init( int type, const wxColour& colour )
m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
m_value = wxColourPropertyValueToVariant(cpv);
m_value << cpv;
OnSetValue();
}
@@ -797,20 +803,29 @@ wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant
if ( pVariant->IsNull() )
return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED, wxColour());
wxColourPropertyValue* v1 = &wxColourPropertyValueFromVariant(*pVariant);
if ( v1 )
return *v1;
if ( pVariant->GetType() == wxS("wxColourPropertyValue") )
{
wxColourPropertyValue v;
v << *pVariant;
return v;
}
wxColour* pCol = wxGetVariantCast(*pVariant, wxColour);
wxColour col;
bool variantProcessed = true;
if ( pCol )
if ( pVariant->GetType() == wxS("wxColour*") )
{
wxColour* pCol = wxStaticCast(pVariant->GetWxObjectPtr(), wxColour);
col = *pCol;
}
else if ( pVariant->GetType() == wxT("wxArrayInt") )
else if ( pVariant->GetType() == wxS("wxColour") )
{
col << *pVariant;
}
else if ( pVariant->GetType() == wxArrayInt_VariantType )
{
// This code is mostly needed for wxPython bindings, which
// may offer tuple of integers as colour value.
wxArrayInt arr;
arr << *pVariant;
@@ -832,10 +847,6 @@ wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant
variantProcessed = false;
}
}
else if ( pVariant->GetType() == wxT("wxColour") )
{
col << *pVariant;
}
else
{
variantProcessed = false;
@@ -855,7 +866,9 @@ wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant
wxVariant wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue& v ) const
{
return wxColourPropertyValueToVariant(v);
wxVariant variant;
variant << v;
return variant;
}
int wxSystemColourProperty::ColToInd( const wxColour& colour ) const
@@ -889,10 +902,9 @@ static inline wxColour wxColourFromPGLong( long col )
void wxSystemColourProperty::OnSetValue()
{
// Convert from generic wxobject ptr to wxPGVariantDataColour
if ( wxPGIsVariantType(m_value, wxobject) )
if ( m_value.GetType() == wxS("wxColour*") )
{
wxASSERT( m_value.IsValueKindOf(CLASSINFO(wxColour)) );
wxColour* pCol = (wxColour*) m_value.GetWxObjectPtr();
wxColour* pCol = wxStaticCast(m_value.GetWxObjectPtr(), wxColour);
m_value << *pCol;
}
@@ -912,11 +924,37 @@ void wxSystemColourProperty::OnSetValue()
m_value = TranslateVal(val);
}
wxColourPropertyValue* pCpv = &wxColourPropertyValueFromVariant(m_value);
wxColour col;
if ( pCpv )
col = pCpv->m_colour;
int ind;
if ( m_value.GetType() == wxS("wxColourPropertyValue") )
{
wxColourPropertyValue cpv;
cpv << m_value;
wxColour col = cpv.m_colour;
if ( !col.Ok() )
{
SetValueToUnspecified();
SetIndex(wxNOT_FOUND);
return;
}
if ( cpv.m_type < wxPG_COLOUR_WEB_BASE )
{
if ( m_choices.HasValues() )
ind = GetIndexForValue(cpv.m_type);
else
ind = ColToInd(col);
}
else
{
cpv.m_type = wxPG_COLOUR_CUSTOM;
ind = GetCustomColourIndex();
}
}
else
{
wxColour col;
col << m_value;
if ( !col.Ok() )
@@ -926,25 +964,6 @@ void wxSystemColourProperty::OnSetValue()
return;
}
int ind;
if ( pCpv )
{
if ( pCpv->m_type < wxPG_COLOUR_WEB_BASE )
{
if ( m_choices.HasValues() )
ind = GetIndexForValue(pCpv->m_type);
else
ind = ColToInd(col);
}
else
{
pCpv->m_type = wxPG_COLOUR_CUSTOM;
ind = GetCustomColourIndex();
}
}
else
{
ind = ColToInd(col);
if ( ind == wxNOT_FOUND )
@@ -1006,7 +1025,7 @@ int wxSystemColourProperty::GetCustomColourIndex() const
bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
{
wxASSERT( m_value.GetType() != wxT("string") );
wxASSERT( m_value.GetType() != wxPG_VARIANT_TYPE_STRING );
bool res = false;
wxPropertyGrid* propgrid = GetGrid();
@@ -1668,7 +1687,7 @@ void wxMultiChoiceProperty::GenerateValueAsString()
{
wxArrayString strings;
if ( wxPGIsVariantType(m_value, arrstring) )
if ( m_value.GetType() == wxPG_VARIANT_TYPE_ARRSTRING )
strings = m_value.GetArrayString();
wxString& tempStr = m_display;
@@ -1691,7 +1710,7 @@ void wxMultiChoiceProperty::GenerateValueAsString()
wxArrayInt wxMultiChoiceProperty::GetValueAsIndices() const
{
const wxArrayInt& valueArr = wxArrayIntFromVariant(GetValue());
const wxArrayInt& valueArr = wxArrayIntRefFromVariant(GetValue());
unsigned int i;
// Translate values to string indices.

View File

@@ -898,7 +898,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
// List variants are reserved a special purpose
// as intermediate containers for child values
// of properties with children.
if ( wxPGIsVariantType(value, list) )
if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
{
//
// However, situation is different for composed string properties
@@ -919,7 +919,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
if ( pList && !pList->IsNull() )
{
wxASSERT( wxPGIsVariantType(*pList, list) );
wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
wxASSERT( GetChildCount() );
wxASSERT( !IsCategory() );
@@ -938,7 +938,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
if ( child )
{
//wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
if ( wxPGIsVariantType(childValue, list) )
if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
{
if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
{
@@ -951,7 +951,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT);
}
}
else if ( !wxPG_VARIANT_EQ(child->GetValue(), childValue) )
else if ( child->GetValue() != childValue )
{
// For aggregate properties, we will trust RefreshChildren()
// to update child values.
@@ -967,7 +967,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
if ( !value.IsNull() )
{
wxPGVariantAssign(m_value, value);
m_value = value;
OnSetValue();
if ( !(flags & wxPG_SETVAL_FROM_PARENT) )
@@ -1053,34 +1053,34 @@ wxVariant wxPGProperty::GetDefaultValue() const
if ( !value.IsNull() )
{
wxPGVariantDataClassInfo classInfo = wxPGVariantDataGetClassInfo(value.GetData());
if ( wxPGIsVariantClassInfo(classInfo, long) )
wxString valueType(value.GetType());
if ( valueType == wxPG_VARIANT_TYPE_LONG )
return wxPGVariant_Zero;
if ( wxPGIsVariantClassInfo(classInfo, string) )
if ( valueType == wxPG_VARIANT_TYPE_STRING )
return wxPGVariant_EmptyString;
if ( wxPGIsVariantClassInfo(classInfo, bool) )
if ( valueType == wxPG_VARIANT_TYPE_BOOL )
return wxPGVariant_False;
if ( wxPGIsVariantClassInfo(classInfo, double) )
if ( valueType == wxPG_VARIANT_TYPE_DOUBLE )
return wxVariant(0.0);
wxPGVariantData* pgvdata = wxDynamicCastVariantData(m_value.GetData(), wxPGVariantData);
if ( pgvdata )
return pgvdata->GetDefaultValue();
if ( wxPGIsVariantClassInfo(classInfo, arrstring) )
if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
return wxVariant(wxArrayString());
if ( wxPGIsVariantClassInfo(classInfo, wxColour) )
return WXVARIANT(*wxRED);
if ( valueType == wxS("wxLongLong") )
return WXVARIANT(wxLongLong(0));
if ( valueType == wxS("wxULongLong") )
return WXVARIANT(wxULongLong(0));
if ( valueType == wxS("wxColour") )
return WXVARIANT(*wxBLACK);
#if wxUSE_DATETIME
if ( wxPGIsVariantClassInfo(classInfo, datetime) )
if ( valueType == wxPG_VARIANT_TYPE_DATETIME )
return wxVariant(wxDateTime::Now());
#endif
wxFAIL_MSG(
wxString::Format(wxT("Inorder for value to have default value, it must be added to")
wxT("wxPGProperty::GetDefaultValue or it's variantdata must inherit")
wxT("from wxPGVariantData (unrecognized type was '%s')"),m_value.GetType().c_str())
);
if ( valueType == wxS("wxFont") )
return WXVARIANT(*wxNORMAL_FONT);
if ( valueType == wxS("wxPoint") )
return WXVARIANT(wxPoint(0, 0));
if ( valueType == wxS("wxSize") )
return WXVARIANT(wxSize(0, 0));
}
return wxVariant();
@@ -1672,7 +1672,7 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
{
//wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
if ( wxPGIsVariantType(childValue, list) )
if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
{
wxVariant cv2(child->GetValue());
child->AdaptListToValue(childValue, &cv2);
@@ -1916,7 +1916,7 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
{
const wxVariant* childList = NULL;
if ( listValue && wxPGIsVariantType(*listValue, list) )
if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
childList = listValue;
if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )

View File

@@ -199,37 +199,6 @@ wxPGGlobalVarsClass::wxPGGlobalVarsClass()
wxVariant v;
v = (long)0;
wxVariantClassInfo_long = wxPGVariantDataGetClassInfo(v.GetData());
v = wxString();
wxVariantClassInfo_string = wxPGVariantDataGetClassInfo(v.GetData());
v = (double)0.0;
wxVariantClassInfo_double = wxPGVariantDataGetClassInfo(v.GetData());
v = (bool)false;
wxVariantClassInfo_bool = wxPGVariantDataGetClassInfo(v.GetData());
v = wxArrayString();
wxVariantClassInfo_arrstring = wxPGVariantDataGetClassInfo(v.GetData());
wxColour col;
wxVariant v2((wxObject*)&col);
wxVariantClassInfo_wxobject = wxPGVariantDataGetClassInfo(v2.GetData());
wxVariantList list;
v = wxVariant(list);
wxVariantClassInfo_list = wxPGVariantDataGetClassInfo(v.GetData());
v << *wxRED;
wxVariantClassInfo_wxColour = wxPGVariantDataGetClassInfo(v.GetData());
#if wxUSE_DATETIME
v = wxVariant(wxDateTime::Now());
wxVariantClassInfo_datetime = wxPGVariantDataGetClassInfo(v.GetData());
#endif
// Prepare some shared variants
m_vEmptyString = wxString();
m_vZero = (long) 0;
@@ -238,6 +207,10 @@ wxPGGlobalVarsClass::wxPGGlobalVarsClass()
m_vFalse = false;
// Prepare cached string constants
m_strstring = wxS("string");
m_strlong = wxS("long");
m_strbool = wxS("bool");
m_strlist = wxS("list");
m_strMin = wxS("Min");
m_strMax = wxS("Max");
m_strUnits = wxS("Units");
@@ -2826,7 +2799,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
m_validationInfo.m_failureBehavior = m_permanentValidationFailureBehavior;
if ( !wxPGIsVariantType(pendingValue, list) )
if ( pendingValue.GetType() == wxPG_VARIANT_TYPE_LIST )
{
if ( !p->ValidateValue(pendingValue, m_validationInfo) )
return false;
@@ -2873,7 +2846,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
wxVariant value;
wxPGProperty* evtChangingProperty = changedProperty;
if ( !wxPGIsVariantType(*pPendingValue, list) )
if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST )
{
value = *pPendingValue;
}
@@ -2928,7 +2901,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
// If changedProperty is not property which value was edited,
// then call wxPGProperty::ValidateValue() for that as well.
if ( p != changedProperty && !wxPGIsVariantType(value, list) )
if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST )
{
if ( !changedProperty->ValidateValue(value, m_validationInfo) )
return false;

View File

@@ -65,30 +65,13 @@ const wxChar *wxPGTypeName_wxArrayString = wxT("arrstring");
// VariantDatas
// ----------------------------------------------------------------------------
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataPoint, wxPoint)
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataSize, wxSize)
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataArrayInt, wxArrayInt)
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataLongLong, wxLongLong)
WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantDataULongLong, wxULongLong)
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxPoint, WXDLLIMPEXP_PROPGRID)
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxSize, WXDLLIMPEXP_PROPGRID)
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED_DUMMY_EQ(wxArrayInt, WXDLLIMPEXP_PROPGRID)
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxLongLong, WXDLLIMPEXP_PROPGRID)
WX_PG_IMPLEMENT_VARIANT_DATA_EXPORTED(wxULongLong, WXDLLIMPEXP_PROPGRID)
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(wxPGVariantDataFont, wxFont)
wxObject* wxPG_VariantToWxObject( const wxVariant& variant, wxClassInfo* classInfo )
{
if ( !variant.IsValueKindOf(classInfo) )
return (wxObject*) NULL;
wxVariantData* vdata = variant.GetData();
wxPGVariantData* pgvdata = wxDynamicCastVariantData(vdata, wxPGVariantData);
if ( pgvdata )
return (wxObject*) pgvdata->GetValuePtr();
if ( wxPGIsVariantClassInfo(wxPGVariantDataGetClassInfo(vdata), wxobject) )
return variant.GetWxObjectPtr();
return (wxObject*) NULL;
}
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxFont, WXDLLIMPEXP_PROPGRID)
// -----------------------------------------------------------------------
// wxVariant helpers
@@ -99,15 +82,16 @@ long wxPGVariantToInt( const wxVariant& variant, long defVal )
if ( variant.IsNull() )
return defVal;
if ( wxPGIsVariantType(variant, long) )
if ( variant.GetType() == wxS("long") )
return variant.GetLong();
if ( wxPGIsVariantType(variant, bool) )
if ( variant.GetType() == wxS("bool") )
return variant.GetBool() ? 1 : 0;
if ( typeid(*variant.GetData()) == typeid(wxPGVariantDataLongLong) )
if ( variant.GetType() == wxS("wxLongLong") )
{
wxLongLong ll = ((const wxPGVariantDataLongLong&)variant).GetValue();
wxLongLong ll;
ll << variant;
if ( ll >= LONG_MAX )
return LONG_MAX;
else if ( ll <= LONG_MIN )
@@ -117,7 +101,7 @@ long wxPGVariantToInt( const wxVariant& variant, long defVal )
long l = defVal;
if ( wxPGIsVariantType(variant, string) )
if ( variant.GetType() == wxPG_VARIANT_TYPE_STRING )
variant.GetString().ToLong(&l, 0);
return l;
@@ -130,15 +114,19 @@ bool wxPGVariantToLongLong( const wxVariant& variant, wxLongLong_t* pResult )
if ( variant.IsNull() )
return false;
if ( wxPGIsVariantType(variant, long) )
wxString variantType = variant.GetType();
if ( variantType == wxPG_VARIANT_TYPE_LONG )
{
*pResult = variant.GetLong();
return true;
}
if ( typeid(*variant.GetData()) == typeid(wxPGVariantDataLongLong) )
if ( variantType == wxLongLong_VariantType )
{
*pResult = ((const wxPGVariantDataLongLong&)variant).GetValue().GetValue();
wxLongLong ll;
ll << variant;
*pResult = ll.GetValue();
return true;
}
@@ -152,15 +140,19 @@ bool wxPGVariantToULongLong( const wxVariant& variant, wxULongLong_t* pResult )
if ( variant.IsNull() )
return false;
if ( wxPGIsVariantType(variant, long) )
wxString variantType = variant.GetType();
if ( variantType == wxPG_VARIANT_TYPE_LONG )
{
*pResult = (unsigned long)variant.GetLong();
return true;
}
if ( typeid(*variant.GetData()) == typeid(wxPGVariantDataULongLong) )
if ( variantType == wxULongLong_VariantType )
{
*pResult = ((const wxPGVariantDataULongLong&)variant).GetValue().GetValue();
wxULongLong ull;
ull << variant;
*pResult = ull.GetValue();
return true;
}
@@ -174,26 +166,29 @@ bool wxPGVariantToDouble( const wxVariant& variant, double* pResult )
if ( variant.IsNull() )
return false;
if ( wxPGIsVariantType(variant, double) )
wxString variantType = variant.GetType();
if ( variantType == wxPG_VARIANT_TYPE_DOUBLE )
{
*pResult = variant.GetDouble();
return true;
}
if ( wxPGIsVariantType(variant, long) )
if ( variantType == wxPG_VARIANT_TYPE_LONG )
{
*pResult = (double)variant.GetLong();
return true;
}
if ( typeid(*variant.GetData()) == typeid(wxPGVariantDataLongLong) )
if ( variantType == wxLongLong_VariantType )
{
wxLongLong ll = ((const wxPGVariantDataLongLong&)variant).GetValue();
wxLongLong ll;
ll << variant;
*pResult = ll.ToDouble();
return true;
}
if ( wxPGIsVariantType(variant, string) )
if ( variantType == wxPG_VARIANT_TYPE_STRING )
if ( variant.GetString().ToDouble(pResult) )
return true;
@@ -487,19 +482,20 @@ void wxPropertyGridInterface::SetPropertyValueUnspecified( wxPGPropArg id )
// wxPropertyGridInterface property value setting and getting
// -----------------------------------------------------------------------
void wxPGGetFailed( const wxPGProperty* p, const wxChar* typestr )
void wxPGGetFailed( const wxPGProperty* p, const wxString& typestr )
{
wxPGTypeOperationFailed(p,typestr,wxT("Get"));
wxPGTypeOperationFailed(p, typestr, wxS("Get"));
}
// -----------------------------------------------------------------------
void wxPGTypeOperationFailed( const wxPGProperty* p, const wxChar* typestr,
const wxChar* op )
void wxPGTypeOperationFailed( const wxPGProperty* p,
const wxString& typestr,
const wxString& op )
{
wxASSERT( p != NULL );
wxLogError( _("Type operation \"%s\" failed: Property labeled \"%s\" is of type \"%s\", NOT \"%s\"."),
op,p->GetLabel().c_str(),p->GetValue().GetType().c_str(),typestr );
op.c_str(), p->GetLabel().c_str(), p->GetValue().GetType().c_str(), typestr.c_str() );
}
// -----------------------------------------------------------------------
@@ -834,29 +830,6 @@ IMPLEMENT_GET_VALUE(long,long,Long,0)
IMPLEMENT_GET_VALUE(double,double,Double,0.0)
IMPLEMENT_GET_VALUE(void,void*,VoidPtr,NULL)
// wxObject is different than others.
wxObject* wxPropertyGridInterface::GetPropertyValueAsWxObjectPtr( wxPGPropArg id ) const
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL((wxObject*)NULL)
wxVariant value = p->GetValue();
wxVariantData* vdata = value.GetData();
if ( !vdata->GetValueClassInfo() )
return (wxObject*) NULL;
wxPGVariantData* pgvdata = wxDynamicCastVariantData(vdata, wxPGVariantData);
if ( pgvdata )
return (wxObject*) pgvdata->GetValuePtr();
if ( wxPGIsVariantClassInfo(wxPGVariantDataGetClassInfo(vdata), wxobject) )
return (wxObject*) value.GetWxObjectPtr();
return (wxObject*) NULL;
}
// -----------------------------------------------------------------------
bool wxPropertyGridInterface::IsPropertyExpanded( wxPGPropArg id ) const
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)

View File

@@ -1449,7 +1449,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
wxPGProperty* foundProp = BaseGetPropertyByName(propName);
if ( foundProp )
{
wxASSERT( wxPGIsVariantType(*current, list) );
wxASSERT( current->GetType() == wxPG_VARIANT_TYPE_LIST );
wxVariantList& list2 = current->GetList();
wxVariantList::const_iterator node2;

View File

@@ -150,19 +150,23 @@ wxIntProperty::wxIntProperty( const wxString& label, const wxString& name,
wxIntProperty::wxIntProperty( const wxString& label, const wxString& name,
const wxLongLong& value ) : wxPGProperty(label,name)
{
SetValue(wxLongLongToVariant(value));
SetValue(WXVARIANT(value));
}
wxIntProperty::~wxIntProperty() { }
wxString wxIntProperty::GetValueAsString( int ) const
{
if ( wxPGIsVariantType(m_value, long) )
if ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
{
return wxString::Format(wxS("%li"),m_value.GetLong());
wxLongLong* ll = &wxLongLongFromVariant(m_value);
if ( ll )
return ll->ToString();
}
else if ( m_value.GetType() == wxLongLong_VariantType )
{
wxLongLong ll;
ll << m_value;
return ll.ToString();
}
return wxEmptyString;
}
@@ -198,7 +202,8 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
wxString useText = text.substr(firstNonZeroPos, text.length() - firstNonZeroPos);
bool isPrevLong = wxPGIsVariantType(variant, long);
wxString variantType = variant.GetType();
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
wxLongLong_t value64 = 0;
@@ -206,10 +211,20 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
( value64 >= INT_MAX || value64 <= INT_MIN )
)
{
wxLongLong* _m_value64 = &wxLongLongFromVariant(m_value);
if ( isPrevLong || !_m_value64 || _m_value64->GetValue() != value64 )
bool doChangeValue = isPrevLong;
if ( !isPrevLong && variantType == wxLongLong_VariantType )
{
variant = wxLongLongToVariant(value64);
wxLongLong oldValue;
oldValue << variant;
if ( oldValue.GetValue() != value64 )
doChangeValue = true;
}
if ( doChangeValue )
{
wxLongLong ll(value64);
variant << ll;
return true;
}
}
@@ -231,7 +246,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
bool wxIntProperty::IntToValue( wxVariant& variant, int value, int WXUNUSED(argFlags) ) const
{
if ( !wxPGIsVariantType(variant, long) || variant.GetLong() != value )
if ( variant.GetType() != wxPG_VARIANT_TYPE_LONG || variant.GetLong() != value )
{
variant = (long)value;
return true;
@@ -365,7 +380,7 @@ wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name,
const wxULongLong& value ) : wxPGProperty(label,name)
{
Init();
SetValue(wxULongLongToVariant(value));
SetValue(WXVARIANT(value));
}
wxUIntProperty::~wxUIntProperty() { }
@@ -376,16 +391,21 @@ wxString wxUIntProperty::GetValueAsString( int ) const
if ( index >= wxPG_UINT_TEMPLATE_MAX )
index = wxPG_BASE_DEC;
if ( wxPGIsVariantType(m_value, long) )
if ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
{
return wxString::Format(gs_uintTemplates32[index], (unsigned long)m_value.GetLong());
else
return wxString::Format(gs_uintTemplates64[index],wxULongLongFromVariant(m_value).GetValue());
}
wxULongLong ull;
ull << m_value;
return wxString::Format(gs_uintTemplates64[index], ull.GetValue());
}
bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const
{
//long unsigned value32 = 0;
bool isPrevLong = wxPGIsVariantType(variant, long);
wxString variantType = variant.GetType();
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
if ( text.length() == 0 )
{
@@ -404,10 +424,20 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in
{
if ( value64 >= LONG_MAX )
{
wxULongLong* _m_value64 = &wxULongLongFromVariant(m_value);
if ( isPrevLong || !_m_value64 || _m_value64->GetValue() != value64 )
bool doChangeValue = isPrevLong;
if ( !isPrevLong && variantType == wxULongLong_VariantType )
{
variant = wxULongLongToVariant(value64);
wxULongLong oldValue;
oldValue << variant;
if ( oldValue.GetValue() != value64 )
doChangeValue = true;
}
if ( doChangeValue )
{
wxULongLong ull(value64);
variant << ull;
return true;
}
}
@@ -857,9 +887,11 @@ int wxBaseEnumProperty::GetIndexForValue( int value ) const
void wxBaseEnumProperty::OnSetValue()
{
if ( wxPGIsVariantType(m_value, long) )
wxString variantType = m_value.GetType();
if ( variantType == wxPG_VARIANT_TYPE_LONG )
ValueFromInt_( m_value, m_value.GetLong(), wxPG_FULL_VALUE );
else if ( wxPGIsVariantType(m_value, string) )
else if ( variantType == wxPG_VARIANT_TYPE_STRING )
ValueFromString_( m_value, m_value.GetString(), 0 );
else
wxASSERT( false );
@@ -876,7 +908,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX
// Make sure string value is in the list,
// unless property has string as preferred value type
// To reduce code size, use conversion here as well
if ( wxPGIsVariantType(value, string) &&
if ( value.GetType() == wxPG_VARIANT_TYPE_STRING &&
!this->IsKindOf(CLASSINFO(wxEditEnumProperty)) )
return ValueFromString_( value, value.GetString(), wxPG_PROPERTY_SPECIFIC );
@@ -885,7 +917,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX
wxString wxBaseEnumProperty::GetValueAsString( int ) const
{
if ( wxPGIsVariantType(m_value, string) )
if ( m_value.GetType() == wxPG_VARIANT_TYPE_STRING )
return m_value.GetString();
if ( m_index >= 0 )
@@ -938,7 +970,7 @@ bool wxBaseEnumProperty::ValueFromString_( wxVariant& value, const wxString& tex
// If text not any of the choices, store as text instead
// (but only if we are wxEditEnumProperty)
if ( useIndex == -1 &&
(!wxPGIsVariantType(m_value, string) || (m_value.GetString() != text)) &&
(value.GetType() != wxPG_VARIANT_TYPE_STRING || (m_value.GetString() != text)) &&
isEdit )
{
asText = true;