Prepare wxPG to build successfully when wxUSE_LONGLONG or wxUSE_DATETIME is disabled.

Make the code ready to build even when wxLongLong and wxDateTime types are not available.
This commit is contained in:
Artur Wieczorek
2015-04-03 21:12:19 +02:00
parent cc575a7a89
commit 7c6943175b
6 changed files with 145 additions and 59 deletions

View File

@@ -656,10 +656,13 @@ template<> inline wxVariant WXVARIANT( const wxColour& value )
#define wxPG_VARIANT_TYPE_LIST wxPGGlobalVars->m_strlist #define wxPG_VARIANT_TYPE_LIST wxPGGlobalVars->m_strlist
#define wxPG_VARIANT_TYPE_DOUBLE wxS("double") #define wxPG_VARIANT_TYPE_DOUBLE wxS("double")
#define wxPG_VARIANT_TYPE_ARRSTRING wxS("arrstring") #define wxPG_VARIANT_TYPE_ARRSTRING wxS("arrstring")
#if wxUSE_DATETIME
#define wxPG_VARIANT_TYPE_DATETIME wxS("datetime") #define wxPG_VARIANT_TYPE_DATETIME wxS("datetime")
#endif
#if wxUSE_LONGLONG
#define wxPG_VARIANT_TYPE_LONGLONG wxS("longlong") #define wxPG_VARIANT_TYPE_LONGLONG wxS("longlong")
#define wxPG_VARIANT_TYPE_ULONGLONG wxS("ulonglong") #define wxPG_VARIANT_TYPE_ULONGLONG wxS("ulonglong")
#endif
#endif // !SWIG #endif // !SWIG
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@@ -555,7 +555,7 @@ public:
return value.GetArrayString(); return value.GetArrayString();
} }
#ifdef wxLongLong_t #if defined(wxLongLong_t) && wxUSE_LONGLONG
wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const
{ {
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0)
@@ -1217,19 +1217,19 @@ public:
SetPropVal( id, v ); SetPropVal( id, v );
} }
#ifdef wxLongLong_t #if wxUSE_LONGLONG
/** Sets value (wxLongLong&) of a property. /** Sets value (wxLongLong&) of a property.
*/ */
void SetPropertyValue( wxPGPropArg id, wxLongLong_t value ) void SetPropertyValue( wxPGPropArg id, wxLongLong value )
{ {
wxVariant v = WXVARIANT(wxLongLong(value)); wxVariant v = WXVARIANT(value);
SetPropVal( id, v ); SetPropVal( id, v );
} }
/** Sets value (wxULongLong&) of a property. /** Sets value (wxULongLong&) of a property.
*/ */
void SetPropertyValue( wxPGPropArg id, wxULongLong_t value ) void SetPropertyValue( wxPGPropArg id, wxULongLong value )
{ {
wxVariant v = WXVARIANT(wxULongLong(value)); wxVariant v = WXVARIANT(value);
SetPropVal( id, v ); SetPropVal( id, v );
} }
#endif #endif

View File

@@ -192,7 +192,7 @@ public:
@code @code
wxLongLong value; wxLongLong value;
wxVariant variant = property->GetValue(); wxVariant variant = property->GetValue();
if ( variant.GetType() == "longlong" ) if ( variant.IsType("longlong") )
value = variant.GetLongLong(); value = variant.GetLongLong();
else else
value = variant.GetLong(); value = variant.GetLong();
@@ -223,9 +223,11 @@ public:
long value = 0 ); long value = 0 );
virtual ~wxIntProperty(); virtual ~wxIntProperty();
#if wxUSE_LONGLONG
wxIntProperty( const wxString& label, wxIntProperty( const wxString& label,
const wxString& name, const wxString& name,
const wxLongLong& value ); const wxLongLong& value );
#endif
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
virtual bool StringToValue( wxVariant& variant, virtual bool StringToValue( wxVariant& variant,
const wxString& text, const wxString& text,
@@ -238,13 +240,20 @@ public:
static wxValidator* GetClassValidator(); static wxValidator* GetClassValidator();
virtual wxValidator* DoGetValidator() const; virtual wxValidator* DoGetValidator() const;
/** Validation helper. /** Validation helpers.
*/ */
#if defined(wxLongLong_t) && wxUSE_LONGLONG
static bool DoValidation( const wxPGProperty* property, static bool DoValidation( const wxPGProperty* property,
wxLongLong_t& value, wxLongLong_t& value,
wxPGValidationInfo* pValidationInfo, wxPGValidationInfo* pValidationInfo,
int mode = int mode =
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
#endif
static bool DoValidation(const wxPGProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode =
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
protected: protected:
}; };
@@ -277,9 +286,11 @@ public:
const wxString& name = wxPG_LABEL, const wxString& name = wxPG_LABEL,
unsigned long value = 0 ); unsigned long value = 0 );
virtual ~wxUIntProperty(); virtual ~wxUIntProperty();
#if wxUSE_LONGLONG
wxUIntProperty( const wxString& label, wxUIntProperty( const wxString& label,
const wxString& name, const wxString& name,
const wxULongLong& value ); const wxULongLong& value );
#endif
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
virtual bool StringToValue( wxVariant& variant, virtual bool StringToValue( wxVariant& variant,
const wxString& text, const wxString& text,
@@ -291,12 +302,25 @@ public:
virtual bool IntToValue( wxVariant& variant, virtual bool IntToValue( wxVariant& variant,
int number, int number,
int argFlags = 0 ) const; int argFlags = 0 ) const;
protected: protected:
wxByte m_base; wxByte m_base;
wxByte m_realBase; // translated to 8,16,etc. wxByte m_realBase; // translated to 8,16,etc.
wxByte m_prefix; wxByte m_prefix;
private: private:
void Init(); void Init();
// Validation helpers.
#if defined(wxULongLong_t) && wxUSE_LONGLONG
static bool DoValidation(const wxPGProperty* property,
wxULongLong_t& value,
wxPGValidationInfo* pValidationInfo,
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
#endif
static bool DoValidation(const wxPGProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode = wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@@ -378,11 +378,16 @@ bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* proper
} }
else else
{ {
long step = property->GetAttributeAsLong(wxPG_ATTR_SPINCTRL_STEP, 1);
#if defined(wxLongLong_t) && wxUSE_LONGLONG
wxLongLong_t v_ll; wxLongLong_t v_ll;
wxLongLong_t step = property->GetAttributeAsLong(wxPG_ATTR_SPINCTRL_STEP, 1); // Try long long
// Try (long) long
if ( s.ToLongLong(&v_ll, 10) ) if ( s.ToLongLong(&v_ll, 10) )
#else
long v_ll;
// Try long
if ( s.ToLong(&v_ll, 10) )
#endif
{ {
if ( bigStep ) if ( bigStep )
step *= 10; step *= 10;
@@ -395,7 +400,11 @@ bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* proper
// Min/Max check // Min/Max check
wxIntProperty::DoValidation(property, v_ll, NULL, mode); wxIntProperty::DoValidation(property, v_ll, NULL, mode);
#if defined(wxLongLong_t) && wxUSE_LONGLONG
s = wxLongLong(v_ll).ToString(); s = wxLongLong(v_ll).ToString();
#else
s = wxString::Format(wxT("%ld"), v_ll);
#endif
} }
else else
{ {

View File

@@ -1547,10 +1547,12 @@ wxVariant wxPGProperty::GetDefaultValue() const
return wxVariant(0.0); return wxVariant(0.0);
if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING ) if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
return wxVariant(wxArrayString()); return wxVariant(wxArrayString());
#if wxUSE_LONGLONG
if ( valueType == wxPG_VARIANT_TYPE_LONGLONG ) if ( valueType == wxPG_VARIANT_TYPE_LONGLONG )
return WXVARIANT(wxLongLong(0)); return WXVARIANT(wxLongLong(0));
if ( valueType == wxPG_VARIANT_TYPE_ULONGLONG ) if ( valueType == wxPG_VARIANT_TYPE_ULONGLONG )
return WXVARIANT(wxULongLong(0)); return WXVARIANT(wxULongLong(0));
#endif
if ( valueType == wxS("wxColour") ) if ( valueType == wxS("wxColour") )
return WXVARIANT(*wxBLACK); return WXVARIANT(*wxBLACK);
#if wxUSE_DATETIME #if wxUSE_DATETIME

View File

@@ -228,11 +228,13 @@ wxIntProperty::wxIntProperty( const wxString& label, const wxString& name,
SetValue(value); SetValue(value);
} }
#if wxUSE_LONGLONG
wxIntProperty::wxIntProperty( const wxString& label, const wxString& name, wxIntProperty::wxIntProperty( const wxString& label, const wxString& name,
const wxLongLong& value ) : wxPGProperty(label,name) const wxLongLong& value ) : wxPGProperty(label,name)
{ {
SetValue(WXVARIANT(value)); SetValue(WXVARIANT(value));
} }
#endif
wxIntProperty::~wxIntProperty() { } wxIntProperty::~wxIntProperty() { }
@@ -244,20 +246,19 @@ wxString wxIntProperty::ValueToString( wxVariant& value,
{ {
return wxString::Format(wxS("%li"),value.GetLong()); return wxString::Format(wxS("%li"),value.GetLong());
} }
#if wxUSE_LONGLONG
else if ( valType == wxPG_VARIANT_TYPE_LONGLONG ) else if ( valType == wxPG_VARIANT_TYPE_LONGLONG )
{ {
wxLongLong ll = value.GetLongLong(); wxLongLong ll = value.GetLongLong();
return ll.ToString(); return ll.ToString();
} }
#endif
return wxEmptyString; return wxEmptyString;
} }
bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
{ {
wxString s;
long value32;
if ( text.empty() ) if ( text.empty() )
{ {
variant.MakeNull(); variant.MakeNull();
@@ -287,6 +288,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
const wxString variantType(variant.GetType()); const wxString variantType(variant.GetType());
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
#if defined(wxLongLong_t) && wxUSE_LONGLONG
wxLongLong_t value64 = 0; wxLongLong_t value64 = 0;
if ( useText.ToLongLong(&value64, 10) && if ( useText.ToLongLong(&value64, 10) &&
@@ -309,7 +311,8 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
return true; return true;
} }
} }
#endif
long value32;
if ( useText.ToLong( &value32, 0 ) ) if ( useText.ToLong( &value32, 0 ) )
{ {
if ( !isPrevLong || variant != value32 ) if ( !isPrevLong || variant != value32 )
@@ -347,11 +350,11 @@ template<typename T>
bool NumericValidation( const wxPGProperty* property, bool NumericValidation( const wxPGProperty* property,
T& value, T& value,
wxPGValidationInfo* pValidationInfo, wxPGValidationInfo* pValidationInfo,
int mode, int mode, T defMin, T defMax,
const wxString& strFmt ) const wxString& strFmt )
{ {
T min = (T) wxINT64_MIN; T min = defMin;
T max = (T) wxINT64_MAX; T max = defMax;
wxVariant variant; wxVariant variant;
bool minOk = false; bool minOk = false;
bool maxOk = false; bool maxOk = false;
@@ -359,15 +362,13 @@ bool NumericValidation( const wxPGProperty* property,
variant = property->GetAttribute(wxPG_ATTR_MIN); variant = property->GetAttribute(wxPG_ATTR_MIN);
if ( !variant.IsNull() ) if ( !variant.IsNull() )
{ {
variant.Convert(&min); minOk = variant.Convert(&min);
minOk = true;
} }
variant = property->GetAttribute(wxPG_ATTR_MAX); variant = property->GetAttribute(wxPG_ATTR_MAX);
if ( !variant.IsNull() ) if ( !variant.IsNull() )
{ {
variant.Convert(&max); maxOk = variant.Convert(&max);
maxOk = true;
} }
if ( minOk ) if ( minOk )
@@ -433,11 +434,11 @@ template<>
bool NumericValidation( const wxPGProperty* property, bool NumericValidation( const wxPGProperty* property,
double& value, double& value,
wxPGValidationInfo* pValidationInfo, wxPGValidationInfo* pValidationInfo,
int mode, int mode, double defMin, double defMax,
const wxString& strFmt ) const wxString& strFmt )
{ {
double min = DBL_MIN; double min = defMin;
double max = DBL_MAX; double max = defMax;
wxVariant variant; wxVariant variant;
bool minOk = false; bool minOk = false;
bool maxOk = false; bool maxOk = false;
@@ -445,15 +446,13 @@ bool NumericValidation( const wxPGProperty* property,
variant = property->GetAttribute(wxPG_ATTR_MIN); variant = property->GetAttribute(wxPG_ATTR_MIN);
if ( !variant.IsNull() ) if ( !variant.IsNull() )
{ {
variant.Convert(&min); minOk = variant.Convert(&min);
minOk = true;
} }
variant = property->GetAttribute(wxPG_ATTR_MAX); variant = property->GetAttribute(wxPG_ATTR_MAX);
if ( !variant.IsNull() ) if ( !variant.IsNull() )
{ {
variant.Convert(&max); maxOk = variant.Convert(&max);
maxOk = true;
} }
if ( minOk || maxOk ) if ( minOk || maxOk )
@@ -535,6 +534,7 @@ bool NumericValidation( const wxPGProperty* property,
return true; return true;
} }
#if defined(wxLongLong_t) && wxUSE_LONGLONG
bool wxIntProperty::DoValidation( const wxPGProperty* property, bool wxIntProperty::DoValidation( const wxPGProperty* property,
wxLongLong_t& value, wxLongLong_t& value,
wxPGValidationInfo* pValidationInfo, wxPGValidationInfo* pValidationInfo,
@@ -543,14 +543,28 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property,
return NumericValidation<wxLongLong_t>(property, return NumericValidation<wxLongLong_t>(property,
value, value,
pValidationInfo, pValidationInfo,
mode, mode, LLONG_MIN, LLONG_MAX,
wxS("%lld")); "%" wxLongLongFmtSpec "d");
}
#endif
bool wxIntProperty::DoValidation(const wxPGProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode)
{
return NumericValidation<long>(property, value, pValidationInfo,
mode, LONG_MIN, LONG_MAX, wxS("%ld"));
} }
bool wxIntProperty::ValidateValue( wxVariant& value, bool wxIntProperty::ValidateValue( wxVariant& value,
wxPGValidationInfo& validationInfo ) const wxPGValidationInfo& validationInfo ) const
{ {
#if defined(wxLongLong_t) && wxUSE_LONGLONG
wxLongLong_t ll = value.GetLongLong().GetValue(); wxLongLong_t ll = value.GetLongLong().GetValue();
#else
long ll = value.GetLong();
#endif
return DoValidation(this, ll, &validationInfo, return DoValidation(this, ll, &validationInfo,
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE); wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
} }
@@ -624,12 +638,14 @@ wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name,
SetValue((long)value); SetValue((long)value);
} }
#if wxUSE_LONLONG
wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name, wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name,
const wxULongLong& value ) : wxPGProperty(label,name) const wxULongLong& value ) : wxPGProperty(label,name)
{ {
Init(); Init();
SetValue(WXVARIANT(value)); SetValue(WXVARIANT(value));
} }
#endif
wxUIntProperty::~wxUIntProperty() { } wxUIntProperty::~wxUIntProperty() { }
@@ -640,22 +656,24 @@ wxString wxUIntProperty::ValueToString( wxVariant& value,
if ( index >= wxPG_UINT_TEMPLATE_MAX ) if ( index >= wxPG_UINT_TEMPLATE_MAX )
index = wxPG_UINT_DEC; index = wxPG_UINT_DEC;
if (value.IsType(wxPG_VARIANT_TYPE_LONG)) const wxString valType(value.GetType());
if ( valType == wxPG_VARIANT_TYPE_LONG )
{ {
return wxString::Format(gs_uintTemplates32[index], return wxString::Format(gs_uintTemplates32[index],
(unsigned long)value.GetLong()); (unsigned long)value.GetLong());
} }
#if wxUSE_LONGLONG
wxULongLong ull = value.GetULongLong(); else if ( valType == wxPG_VARIANT_TYPE_ULONGLONG )
{
return wxString::Format(gs_uintTemplates64[index], ull.GetValue()); wxULongLong ull = value.GetULongLong();
return wxString::Format(gs_uintTemplates64[index], ull.GetValue());
}
#endif
return wxEmptyString;
} }
bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const bool wxUIntProperty::StringToValue(wxVariant& variant, const wxString& text, int argFlags) const
{ {
const wxString variantType(variant.GetType());
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
if ( text.empty() ) if ( text.empty() )
{ {
variant.MakeNull(); variant.MakeNull();
@@ -666,9 +684,14 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in
if ( text[0] == wxS('$') ) if ( text[0] == wxS('$') )
start++; start++;
wxULongLong_t value64 = 0;
wxString s = text.substr(start, text.length() - start); wxString s = text.substr(start, text.length() - start);
const wxString variantType(variant.GetType());
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
#if defined(wxULongLong_t) && wxUSE_LONGLONG
wxULongLong_t value64 = 0;
if ( s.ToULongLong(&value64, (unsigned int)m_realBase) ) if ( s.ToULongLong(&value64, (unsigned int)m_realBase) )
{ {
if ( value64 >= LONG_MAX ) if ( value64 >= LONG_MAX )
@@ -688,17 +711,21 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in
return true; return true;
} }
} }
else
{
unsigned long value32 = wxLongLong(value64).GetLo();
if ( !isPrevLong || m_value != (long)value32 )
{
variant = (long)value32;
return true;
}
}
} }
#endif
unsigned long value32;
if ( s.ToULong(&value32, m_realBase) && value32 <= LONG_MAX )
{
if ( !isPrevLong || variant != (long)value32 )
{
variant = (long)value32;
return true;
}
}
else if ( argFlags & wxPG_REPORT_ERROR )
{
}
return false; return false;
} }
@@ -712,15 +739,36 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar
return false; return false;
} }
#if defined(wxULongLong_t) && wxUSE_LONGLONG
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
wxULongLong_t& value,
wxPGValidationInfo* pValidationInfo,
int mode )
{
return NumericValidation<wxULongLong_t>(property, value, pValidationInfo,
mode, 0, ULLONG_MAX,
"%" wxLongLongFmtSpec "u");
}
#endif
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode)
{
return NumericValidation<long>(property, value, pValidationInfo,
mode, 0, ULONG_MAX, wxS("%ld"));
}
bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
{ {
#if defined(wxULongLong_t) && wxUSE_LONGLONG
wxULongLong_t uul = value.GetULongLong().GetValue(); wxULongLong_t uul = value.GetULongLong().GetValue();
return #else
NumericValidation<wxULongLong_t>(this, long uul = value.GetLong();
uul, #endif
&validationInfo, return DoValidation(this, uul, &validationInfo,
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
wxS("%llu"));
} }
wxValidator* wxUIntProperty::DoGetValidator() const wxValidator* wxUIntProperty::DoGetValidator() const
@@ -905,7 +953,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property,
return NumericValidation<double>(property, return NumericValidation<double>(property,
value, value,
pValidationInfo, pValidationInfo,
mode, mode, DBL_MIN, DBL_MAX,
wxS("%g")); wxS("%g"));
} }