diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 02221c1b76..d00f147b67 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -656,10 +656,13 @@ template<> inline wxVariant WXVARIANT( const wxColour& value ) #define wxPG_VARIANT_TYPE_LIST wxPGGlobalVars->m_strlist #define wxPG_VARIANT_TYPE_DOUBLE wxS("double") #define wxPG_VARIANT_TYPE_ARRSTRING wxS("arrstring") +#if wxUSE_DATETIME #define wxPG_VARIANT_TYPE_DATETIME wxS("datetime") +#endif +#if wxUSE_LONGLONG #define wxPG_VARIANT_TYPE_LONGLONG wxS("longlong") #define wxPG_VARIANT_TYPE_ULONGLONG wxS("ulonglong") - +#endif #endif // !SWIG // ----------------------------------------------------------------------- diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 5fc29de8c5..6413296d5e 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -555,7 +555,7 @@ public: return value.GetArrayString(); } -#ifdef wxLongLong_t +#if defined(wxLongLong_t) && wxUSE_LONGLONG wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const { wxPG_PROP_ARG_CALL_PROLOG_RETVAL(0) @@ -1217,19 +1217,19 @@ public: SetPropVal( id, v ); } -#ifdef wxLongLong_t +#if wxUSE_LONGLONG /** 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 ); } /** 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 ); } #endif diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index eaf91379f2..baaf63449c 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -192,7 +192,7 @@ public: @code wxLongLong value; wxVariant variant = property->GetValue(); - if ( variant.GetType() == "longlong" ) + if ( variant.IsType("longlong") ) value = variant.GetLongLong(); else value = variant.GetLong(); @@ -223,9 +223,11 @@ public: long value = 0 ); virtual ~wxIntProperty(); +#if wxUSE_LONGLONG wxIntProperty( const wxString& label, const wxString& name, const wxLongLong& value ); +#endif virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, @@ -238,13 +240,20 @@ public: static wxValidator* GetClassValidator(); virtual wxValidator* DoGetValidator() const; - /** Validation helper. + /** Validation helpers. */ +#if defined(wxLongLong_t) && wxUSE_LONGLONG static bool DoValidation( const wxPGProperty* property, wxLongLong_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); protected: }; @@ -277,9 +286,11 @@ public: const wxString& name = wxPG_LABEL, unsigned long value = 0 ); virtual ~wxUIntProperty(); +#if wxUSE_LONGLONG wxUIntProperty( const wxString& label, const wxString& name, const wxULongLong& value ); +#endif virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool StringToValue( wxVariant& variant, const wxString& text, @@ -291,12 +302,25 @@ public: virtual bool IntToValue( wxVariant& variant, int number, int argFlags = 0 ) const; + protected: wxByte m_base; wxByte m_realBase; // translated to 8,16,etc. wxByte m_prefix; private: 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); }; // ----------------------------------------------------------------------- diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 070830f26e..b8ebd1d5be 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -378,11 +378,16 @@ bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* proper } else { + long step = property->GetAttributeAsLong(wxPG_ATTR_SPINCTRL_STEP, 1); +#if defined(wxLongLong_t) && wxUSE_LONGLONG 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) ) +#else + long v_ll; + // Try long + if ( s.ToLong(&v_ll, 10) ) +#endif { if ( bigStep ) step *= 10; @@ -395,7 +400,11 @@ bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* proper // Min/Max check wxIntProperty::DoValidation(property, v_ll, NULL, mode); +#if defined(wxLongLong_t) && wxUSE_LONGLONG s = wxLongLong(v_ll).ToString(); +#else + s = wxString::Format(wxT("%ld"), v_ll); +#endif } else { diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index bf0c6a262e..0fb01ad4d0 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -1547,10 +1547,12 @@ wxVariant wxPGProperty::GetDefaultValue() const return wxVariant(0.0); if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING ) return wxVariant(wxArrayString()); +#if wxUSE_LONGLONG if ( valueType == wxPG_VARIANT_TYPE_LONGLONG ) return WXVARIANT(wxLongLong(0)); if ( valueType == wxPG_VARIANT_TYPE_ULONGLONG ) return WXVARIANT(wxULongLong(0)); +#endif if ( valueType == wxS("wxColour") ) return WXVARIANT(*wxBLACK); #if wxUSE_DATETIME diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index dc676ad0a4..b74619040b 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -228,11 +228,13 @@ wxIntProperty::wxIntProperty( const wxString& label, const wxString& name, SetValue(value); } +#if wxUSE_LONGLONG wxIntProperty::wxIntProperty( const wxString& label, const wxString& name, const wxLongLong& value ) : wxPGProperty(label,name) { SetValue(WXVARIANT(value)); } +#endif wxIntProperty::~wxIntProperty() { } @@ -244,20 +246,19 @@ wxString wxIntProperty::ValueToString( wxVariant& value, { return wxString::Format(wxS("%li"),value.GetLong()); } +#if wxUSE_LONGLONG else if ( valType == wxPG_VARIANT_TYPE_LONGLONG ) { wxLongLong ll = value.GetLongLong(); return ll.ToString(); } +#endif return wxEmptyString; } bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const { - wxString s; - long value32; - if ( text.empty() ) { variant.MakeNull(); @@ -287,6 +288,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int const wxString variantType(variant.GetType()); bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; +#if defined(wxLongLong_t) && wxUSE_LONGLONG wxLongLong_t value64 = 0; if ( useText.ToLongLong(&value64, 10) && @@ -309,7 +311,8 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int return true; } } - +#endif + long value32; if ( useText.ToLong( &value32, 0 ) ) { if ( !isPrevLong || variant != value32 ) @@ -347,11 +350,11 @@ template bool NumericValidation( const wxPGProperty* property, T& value, wxPGValidationInfo* pValidationInfo, - int mode, + int mode, T defMin, T defMax, const wxString& strFmt ) { - T min = (T) wxINT64_MIN; - T max = (T) wxINT64_MAX; + T min = defMin; + T max = defMax; wxVariant variant; bool minOk = false; bool maxOk = false; @@ -359,15 +362,13 @@ bool NumericValidation( const wxPGProperty* property, variant = property->GetAttribute(wxPG_ATTR_MIN); if ( !variant.IsNull() ) { - variant.Convert(&min); - minOk = true; + minOk = variant.Convert(&min); } variant = property->GetAttribute(wxPG_ATTR_MAX); if ( !variant.IsNull() ) { - variant.Convert(&max); - maxOk = true; + maxOk = variant.Convert(&max); } if ( minOk ) @@ -433,11 +434,11 @@ template<> bool NumericValidation( const wxPGProperty* property, double& value, wxPGValidationInfo* pValidationInfo, - int mode, + int mode, double defMin, double defMax, const wxString& strFmt ) { - double min = DBL_MIN; - double max = DBL_MAX; + double min = defMin; + double max = defMax; wxVariant variant; bool minOk = false; bool maxOk = false; @@ -445,15 +446,13 @@ bool NumericValidation( const wxPGProperty* property, variant = property->GetAttribute(wxPG_ATTR_MIN); if ( !variant.IsNull() ) { - variant.Convert(&min); - minOk = true; + minOk = variant.Convert(&min); } variant = property->GetAttribute(wxPG_ATTR_MAX); if ( !variant.IsNull() ) { - variant.Convert(&max); - maxOk = true; + maxOk = variant.Convert(&max); } if ( minOk || maxOk ) @@ -535,6 +534,7 @@ bool NumericValidation( const wxPGProperty* property, return true; } +#if defined(wxLongLong_t) && wxUSE_LONGLONG bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& value, wxPGValidationInfo* pValidationInfo, @@ -543,14 +543,28 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, return NumericValidation(property, value, pValidationInfo, - mode, - wxS("%lld")); + mode, LLONG_MIN, LLONG_MAX, + "%" wxLongLongFmtSpec "d"); +} +#endif + +bool wxIntProperty::DoValidation(const wxPGProperty* property, + long& value, + wxPGValidationInfo* pValidationInfo, + int mode) +{ + return NumericValidation(property, value, pValidationInfo, + mode, LONG_MIN, LONG_MAX, wxS("%ld")); } bool wxIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { +#if defined(wxLongLong_t) && wxUSE_LONGLONG wxLongLong_t ll = value.GetLongLong().GetValue(); +#else + long ll = value.GetLong(); +#endif return DoValidation(this, ll, &validationInfo, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE); } @@ -624,12 +638,14 @@ wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name, SetValue((long)value); } +#if wxUSE_LONLONG wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name, const wxULongLong& value ) : wxPGProperty(label,name) { Init(); SetValue(WXVARIANT(value)); } +#endif wxUIntProperty::~wxUIntProperty() { } @@ -640,22 +656,24 @@ wxString wxUIntProperty::ValueToString( wxVariant& value, if ( index >= wxPG_UINT_TEMPLATE_MAX ) 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], (unsigned long)value.GetLong()); } - - wxULongLong ull = value.GetULongLong(); - - return wxString::Format(gs_uintTemplates64[index], ull.GetValue()); +#if wxUSE_LONGLONG + else if ( valType == wxPG_VARIANT_TYPE_ULONGLONG ) + { + 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() ) { variant.MakeNull(); @@ -666,9 +684,14 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in if ( text[0] == wxS('$') ) start++; - wxULongLong_t value64 = 0; 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 ( value64 >= LONG_MAX ) @@ -688,17 +711,21 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in 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; } @@ -712,15 +739,36 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar return false; } +#if defined(wxULongLong_t) && wxUSE_LONGLONG +bool wxUIntProperty::DoValidation(const wxPGProperty* property, + wxULongLong_t& value, + wxPGValidationInfo* pValidationInfo, + int mode ) +{ + return NumericValidation(property, value, pValidationInfo, + mode, 0, ULLONG_MAX, + "%" wxLongLongFmtSpec "u"); +} +#endif + +bool wxUIntProperty::DoValidation(const wxPGProperty* property, + long& value, + wxPGValidationInfo* pValidationInfo, + int mode) +{ + return NumericValidation(property, value, pValidationInfo, + mode, 0, ULONG_MAX, wxS("%ld")); +} + bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { +#if defined(wxULongLong_t) && wxUSE_LONGLONG wxULongLong_t uul = value.GetULongLong().GetValue(); - return - NumericValidation(this, - uul, - &validationInfo, - wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE, - wxS("%llu")); +#else + long uul = value.GetLong(); +#endif + return DoValidation(this, uul, &validationInfo, + wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE); } wxValidator* wxUIntProperty::DoGetValidator() const @@ -905,7 +953,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, return NumericValidation(property, value, pValidationInfo, - mode, + mode, DBL_MIN, DBL_MAX, wxS("%g")); }