diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index c4f08984d6..a6c415a86c 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -242,13 +242,21 @@ public: /** Validation helpers. */ -#if defined(wxLongLong_t) && wxUSE_LONGLONG +#if wxUSE_LONGLONG + static bool DoValidation( const wxPGProperty* property, + wxLongLong& value, + wxPGValidationInfo* pValidationInfo, + int mode = + wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); + +#if defined(wxLongLong_t) static bool DoValidation( const wxPGProperty* property, wxLongLong_t& value, wxPGValidationInfo* pValidationInfo, int mode = wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ); -#endif +#endif // wxLongLong_t +#endif // wxUSE_LONGLONG static bool DoValidation(const wxPGProperty* property, long& value, wxPGValidationInfo* pValidationInfo, @@ -311,12 +319,18 @@ private: void Init(); // Validation helpers. -#if defined(wxULongLong_t) && wxUSE_LONGLONG +#if wxUSE_LONGLONG + static bool DoValidation(const wxPGProperty* property, + wxULongLong& value, + wxPGValidationInfo* pValidationInfo, + int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE); +#if defined(wxULongLong_t) static bool DoValidation(const wxPGProperty* property, wxULongLong_t& value, wxPGValidationInfo* pValidationInfo, int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE); -#endif +#endif // wxULongLong_t +#endif // wxUSE_LONGLONG static bool DoValidation(const wxPGProperty* property, long& value, wxPGValidationInfo* pValidationInfo, diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index dda461f465..39b185b9b2 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -352,8 +352,7 @@ template bool NumericValidation( const wxPGProperty* property, T& value, wxPGValidationInfo* pValidationInfo, - int mode, T defMin, T defMax, - const wxString& strFmt ) + int mode, T defMin, T defMax) { T min = defMin; T max = defMax; @@ -380,16 +379,20 @@ bool NumericValidation( const wxPGProperty* property, if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; - wxString smin = wxString::Format(strFmt, min); - wxString smax = wxString::Format(strFmt, max); + wxVariant vmin = WXVARIANT(min); + wxString smin = property->ValueToString(vmin); if ( !maxOk ) msg = wxString::Format( _("Value must be %s or higher."), smin.c_str()); else + { + wxVariant vmax = WXVARIANT(max); + wxString smax = property->ValueToString(vmax); msg = wxString::Format( _("Value must be between %s and %s."), smin.c_str(), smax.c_str()); + } pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -407,16 +410,20 @@ bool NumericValidation( const wxPGProperty* property, if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; - wxString smin = wxString::Format(strFmt, min); - wxString smax = wxString::Format(strFmt, max); + wxVariant vmax = WXVARIANT(max); + wxString smax = property->ValueToString(vmax); if ( !minOk ) msg = wxString::Format( _("Value must be %s or less."), smax.c_str()); else + { + wxVariant vmin = WXVARIANT(min); + wxString smin = property->ValueToString(vmin); msg = wxString::Format( _("Value must be between %s and %s."), smin.c_str(), smax.c_str()); + } pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -436,8 +443,7 @@ template<> bool NumericValidation( const wxPGProperty* property, double& value, wxPGValidationInfo* pValidationInfo, - int mode, double defMin, double defMax, - const wxString& strFmt ) + int mode, double defMin, double defMax) { double min = defMin; double max = defMax; @@ -487,16 +493,20 @@ bool NumericValidation( const wxPGProperty* property, if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; - wxString smin = wxString::Format(strFmt, min); - wxString smax = wxString::Format(strFmt, max); + wxVariant vmin = WXVARIANT(min); + wxString smin = property->ValueToString(vmin); if ( !maxOk ) msg = wxString::Format( _("Value must be %s or higher."), smin.c_str()); else + { + wxVariant vmax = WXVARIANT(max); + wxString smax = property->ValueToString(vmax); msg = wxString::Format( _("Value must be between %s and %s."), smin.c_str(), smax.c_str()); + } pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -514,16 +524,20 @@ bool NumericValidation( const wxPGProperty* property, if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; - wxString smin = wxString::Format(strFmt, min); - wxString smax = wxString::Format(strFmt, max); + wxVariant vmax = WXVARIANT(max); + wxString smax = property->ValueToString(vmax); if ( !minOk ) msg = wxString::Format( _("Value must be %s or less."), smax.c_str()); else + { + wxVariant vmin = WXVARIANT(min); + wxString smin = property->ValueToString(vmin); msg = wxString::Format( _("Value must be between %s and %s."), smin.c_str(), smax.c_str()); + } pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -536,19 +550,29 @@ bool NumericValidation( const wxPGProperty* property, return true; } -#if defined(wxLongLong_t) && wxUSE_LONGLONG +#if wxUSE_LONGLONG +bool wxIntProperty::DoValidation( const wxPGProperty* property, + wxLongLong& value, + wxPGValidationInfo* pValidationInfo, + int mode ) +{ + return NumericValidation(property, + value, + pValidationInfo, + mode, wxLongLong(LLONG_MIN), wxLongLong(LLONG_MAX)); +} + +#if defined(wxLongLong_t) bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& value, wxPGValidationInfo* pValidationInfo, int mode ) { - return NumericValidation(property, - value, - pValidationInfo, - mode, LLONG_MIN, LLONG_MAX, - wxS("%") wxS(wxLongLongFmtSpec) wxS("d")); + wxLongLong llval(value); + return DoValidation(property, llval, pValidationInfo, mode); } -#endif +#endif // wxLongLong_t +#endif // wxUSE_LONGLONG bool wxIntProperty::DoValidation(const wxPGProperty* property, long& value, @@ -556,14 +580,14 @@ bool wxIntProperty::DoValidation(const wxPGProperty* property, int mode) { return NumericValidation(property, value, pValidationInfo, - mode, LONG_MIN, LONG_MAX, wxS("%ld")); + mode, LONG_MIN, LONG_MAX); } bool wxIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { -#if defined(wxLongLong_t) && wxUSE_LONGLONG - wxLongLong_t ll = value.GetLongLong().GetValue(); +#if wxUSE_LONGLONG + wxLongLong ll = value.GetLongLong(); #else long ll = value.GetLong(); #endif @@ -772,17 +796,27 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar return false; } -#if defined(wxULongLong_t) && wxUSE_LONGLONG +#if wxUSE_LONGLONG +bool wxUIntProperty::DoValidation(const wxPGProperty* property, + wxULongLong& value, + wxPGValidationInfo* pValidationInfo, + int mode ) +{ + return NumericValidation(property, value, pValidationInfo, + mode, wxULongLong(0), wxULongLong(ULLONG_MAX)); +} + +#if defined(wxULongLong_t) bool wxUIntProperty::DoValidation(const wxPGProperty* property, wxULongLong_t& value, wxPGValidationInfo* pValidationInfo, int mode ) { - return NumericValidation(property, value, pValidationInfo, - mode, 0, ULLONG_MAX, - wxS("%") wxS(wxLongLongFmtSpec) wxS("u")); + wxULongLong ullval(value); + return DoValidation(property, ullval, pValidationInfo, mode); } -#endif +#endif // wxULongLong_t +#endif // wxUSE_LONGLONG bool wxUIntProperty::DoValidation(const wxPGProperty* property, long& value, @@ -790,13 +824,13 @@ bool wxUIntProperty::DoValidation(const wxPGProperty* property, int mode) { return NumericValidation(property, value, pValidationInfo, - mode, 0, ULONG_MAX, wxS("%ld")); + mode, 0, ULONG_MAX); } bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { -#if defined(wxULongLong_t) && wxUSE_LONGLONG - wxULongLong_t uul = value.GetULongLong().GetValue(); +#if wxUSE_LONGLONG + wxULongLong uul = value.GetULongLong(); #else long uul = value.GetLong(); #endif @@ -986,8 +1020,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, return NumericValidation(property, value, pValidationInfo, - mode, DBL_MIN, DBL_MAX, - wxS("%g")); + mode, DBL_MIN, DBL_MAX); } bool