X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/525b29124a9b69837c1d7973d44da21d2da28ea1..b89b24691e0b81aa9cccdb57bfaaacd25fa747da:/src/propgrid/props.cpp?ds=inline diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 9eea13d63b..0cb64112b5 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -6,7 +6,7 @@ // Created: 2005-05-14 // RCS-ID: $Id$ // Copyright: (c) Jaakko Salli -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". @@ -31,6 +31,7 @@ #include "wx/dcclient.h" #include "wx/dcmemory.h" #include "wx/button.h" + #include "wx/bmpbuttn.h" #include "wx/pen.h" #include "wx/brush.h" #include "wx/cursor.h" @@ -260,11 +261,22 @@ bool wxIntProperty::IntToValue( wxVariant& variant, int value, int WXUNUSED(argF return false; } -bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& value, wxPGValidationInfo* pValidationInfo, int mode ) -{ - // Check for min/max - wxLongLong_t min = wxINT64_MIN; - wxLongLong_t max = wxINT64_MAX; +// +// Common validation code to be called in ValidateValue() +// implementations. +// +// Note that 'value' is reference on purpose, so we can write +// back to it when mode is wxPG_PROPERTY_VALIDATION_SATURATE. +// +template +bool NumericValidation( const wxPGProperty* property, + T& value, + wxPGValidationInfo* pValidationInfo, + int mode, + const wxString& strFmt ) +{ + T min = (T) wxINT64_MIN; + T max = (T) wxINT64_MAX; wxVariant variant; bool minOk = false; bool maxOk = false; @@ -272,14 +284,14 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va variant = property->GetAttribute(wxPGGlobalVars->m_strMin); if ( !variant.IsNull() ) { - min = variant.GetLongLong().GetValue(); + variant.Convert(&min); minOk = true; } variant = property->GetAttribute(wxPGGlobalVars->m_strMax); if ( !variant.IsNull() ) { - max = variant.GetLongLong().GetValue(); + variant.Convert(&max); maxOk = true; } @@ -290,13 +302,16 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; + wxString smin = wxString::Format(strFmt, min); + wxString smax = wxString::Format(strFmt, max); if ( !maxOk ) msg = wxString::Format( - _("Value must be %lld or higher."), min); + _("Value must be %s or higher."), + smin.c_str()); else msg = wxString::Format( - _("Value must be between %lld and %lld."), - min, max); + _("Value must be between %s and %s."), + smin.c_str(), smax.c_str()); pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -314,13 +329,16 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) { wxString msg; + wxString smin = wxString::Format(strFmt, min); + wxString smax = wxString::Format(strFmt, max); if ( !minOk ) msg = wxString::Format( - _("Value must be %lld or lower."), max); + _("Value must be %s or less."), + smax.c_str()); else msg = wxString::Format( - _("Value must be between %lld and %lld."), - min, max); + _("Value must be between %s and %s."), + smin.c_str(), smax.c_str()); pValidationInfo->SetFailureMessage(msg); } else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) @@ -333,6 +351,18 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va return true; } +bool wxIntProperty::DoValidation( const wxPGProperty* property, + wxLongLong_t& value, + wxPGValidationInfo* pValidationInfo, + int mode ) +{ + return NumericValidation(property, + value, + pValidationInfo, + mode, + wxS("%lld")); +} + bool wxIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { @@ -492,39 +522,13 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const { - // Check for min/max - wxULongLong_t ll = value.GetULongLong().GetValue(); - - wxULongLong_t min = 0; - wxULongLong_t max = wxUINT64_MAX; - wxVariant variant; - - variant = GetAttribute(wxPGGlobalVars->m_strMin); - if ( !variant.IsNull() ) - { - min = variant.GetULongLong().GetValue(); - if ( ll < min ) - { - validationInfo.SetFailureMessage( - wxString::Format(_("Value must be %llu or higher"),min) - ); - return false; - } - } - variant = GetAttribute(wxPGGlobalVars->m_strMax); - if ( !variant.IsNull() ) - { - max = variant.GetULongLong().GetValue(); - if ( ll > max ) - { - validationInfo.SetFailureMessage( - wxString::Format(_("Value must be %llu or less"),max) - ); - return false; - } - } - - return true; + wxULongLong_t uul = value.GetULongLong().GetValue(); + return + NumericValidation(this, + uul, + &validationInfo, + wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE, + wxS("%llu")); } bool wxUIntProperty::DoSetAttribute( const wxString& name, wxVariant& value ) @@ -671,60 +675,11 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, wxPGValidationInfo* pValidationInfo, int mode ) { - // Check for min/max - double min = (double)wxINT64_MIN; - double max = (double)wxINT64_MAX; - wxVariant variant; - bool minOk = false; - bool maxOk = false; - - variant = property->GetAttribute(wxPGGlobalVars->m_strMin); - if ( !variant.IsNull() ) - { - min = variant.GetDouble(); - minOk = true; - } - - variant = property->GetAttribute(wxPGGlobalVars->m_strMax); - if ( !variant.IsNull() ) - { - max = variant.GetDouble(); - maxOk = true; - } - - if ( minOk ) - { - if ( value < min ) - { - if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->SetFailureMessage( - wxString::Format(_("Value must be %f or higher"),min) - ); - else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) - value = min; - else - value = max - (min - value); - return false; - } - } - - if ( maxOk ) - { - max = variant.GetDouble(); - if ( value > max ) - { - if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->SetFailureMessage( - wxString::Format(_("Value must be %f or less"),max) - ); - else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) - value = max; - else - value = min + (value - max); - return false; - } - } - return true; + return NumericValidation(property, + value, + pValidationInfo, + mode, + wxS("%g")); } bool @@ -1388,7 +1343,7 @@ void wxFlagsProperty::OnSetValue() flag = choices.GetValue(i); if ( (newFlags & flag) != (m_oldValue & flag) ) - Item(i)->SetFlag( wxPG_PROP_MODIFIED ); + Item(i)->ChangeFlag( wxPG_PROP_MODIFIED, true ); } m_oldValue = newFlags; @@ -1496,7 +1451,7 @@ void wxFlagsProperty::RefreshChildren() wxPGProperty* p = Item(i); if ( subVal != (m_oldValue & flag) ) - p->SetFlag( wxPG_PROP_MODIFIED ); + p->ChangeFlag( wxPG_PROP_MODIFIED, true ); p->SetValue( subVal?true:false ); } @@ -2387,6 +2342,7 @@ wxArrayStringProperty::wxArrayStringProperty( const wxString& label, const wxArrayString& array ) : wxPGProperty(label,name) { + m_delimiter = ','; SetValue( array ); } @@ -2454,9 +2410,8 @@ wxArrayStringProperty::ArrayStringToString( wxString& dst, if ( flags & Escape ) { - preas[0] = delimiter; - pdr = wxS("\\"); - pdr += delimiter; + preas = delimiter; + pdr = wxS("\\") + static_cast(delimiter); } if ( itemCount )