X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aae9e5bd567cc8736c64c9f8ee313c8f264a3fff..5eed855656b3996f4c0aa0a585a4820a2af6d628:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 0cb64112b5..e399674bd5 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -142,6 +142,80 @@ bool wxStringProperty::DoSetAttribute( const wxString& name, wxVariant& value ) return true; } +// ----------------------------------------------------------------------- +// wxNumericPropertyValidator +// ----------------------------------------------------------------------- + +#if wxUSE_VALIDATORS + +wxNumericPropertyValidator:: + wxNumericPropertyValidator( NumericType numericType, int base ) + : wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST) +{ + wxArrayString arr; + arr.Add(wxS("0")); + arr.Add(wxS("1")); + arr.Add(wxS("2")); + arr.Add(wxS("3")); + arr.Add(wxS("4")); + arr.Add(wxS("5")); + arr.Add(wxS("6")); + arr.Add(wxS("7")); + + if ( base >= 10 ) + { + arr.Add(wxS("8")); + arr.Add(wxS("9")); + if ( base >= 16 ) + { + arr.Add(wxS("a")); arr.Add(wxS("A")); + arr.Add(wxS("b")); arr.Add(wxS("B")); + arr.Add(wxS("c")); arr.Add(wxS("C")); + arr.Add(wxS("d")); arr.Add(wxS("D")); + arr.Add(wxS("e")); arr.Add(wxS("E")); + arr.Add(wxS("f")); arr.Add(wxS("F")); + } + } + + if ( numericType == Signed ) + { + arr.Add(wxS("+")); + arr.Add(wxS("-")); + } + else if ( numericType == Float ) + { + arr.Add(wxS("+")); + arr.Add(wxS("-")); + arr.Add(wxS("e")); + + // Use locale-specific decimal point + arr.Add(wxString::Format("%g", 1.1)[1]); + } + + SetIncludes(arr); +} + +bool wxNumericPropertyValidator::Validate(wxWindow* parent) +{ + if ( !wxTextValidator::Validate(parent) ) + return false; + + wxWindow* wnd = GetWindow(); + if ( !wnd->IsKindOf(CLASSINFO(wxTextCtrl)) ) + return true; + + // Do not allow zero-length string + wxTextCtrl* tc = static_cast(wnd); + wxString text = tc->GetValue(); + + if ( !text.length() ) + return false; + + return true; +} + +#endif // wxUSE_VALIDATORS + // ----------------------------------------------------------------------- // wxIntProperty // ----------------------------------------------------------------------- @@ -376,9 +450,8 @@ wxValidator* wxIntProperty::GetClassValidator() #if wxUSE_VALIDATORS WX_PG_DOGETVALIDATOR_ENTRY() - // Atleast wxPython 2.6.2.1 required that the string argument is given - static wxString v; - wxTextValidator* validator = new wxTextValidator(wxFILTER_NUMERIC,&v); + wxValidator* validator = new wxNumericPropertyValidator( + wxNumericPropertyValidator::Signed); WX_PG_DOGETVALIDATOR_EXIT(validator) #else @@ -531,6 +604,21 @@ bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& valida wxS("%llu")); } +wxValidator* wxUIntProperty::DoGetValidator() const +{ +#if wxUSE_VALIDATORS + WX_PG_DOGETVALIDATOR_ENTRY() + + wxValidator* validator = new wxNumericPropertyValidator( + wxNumericPropertyValidator::Unsigned, + m_realBase); + + WX_PG_DOGETVALIDATOR_EXIT(validator) +#else + return NULL; +#endif +} + bool wxUIntProperty::DoSetAttribute( const wxString& name, wxVariant& value ) { if ( name == wxPG_UINT_BASE ) @@ -580,11 +668,11 @@ wxFloatProperty::~wxFloatProperty() { } // This helper method provides standard way for floating point-using // properties to convert values to string. -void wxPropertyGrid::DoubleToString(wxString& target, - double value, - int precision, - bool removeZeroes, - wxString* precTemplate) +const wxString& wxPropertyGrid::DoubleToString(wxString& target, + double value, + int precision, + bool removeZeroes, + wxString* precTemplate) { if ( precision >= 0 ) { @@ -627,6 +715,27 @@ void wxPropertyGrid::DoubleToString(wxString& target, if ( new_len != target.length() ) target.resize(new_len); } + + // Remove sign from zero + if ( target.length() >= 2 && target[0] == wxS('-') ) + { + bool isZero = true; + wxString::const_iterator i = target.begin() + 1; + + for ( ; i != target.end(); i++ ) + { + if ( *i != wxS('0') && *i != wxS('.') && *i != wxS(',') ) + { + isZero = false; + break; + } + } + + if ( isZero ) + target.erase(target.begin()); + } + + return target; } wxString wxFloatProperty::ValueToString( wxVariant& value, @@ -701,9 +810,24 @@ bool wxFloatProperty::DoSetAttribute( const wxString& name, wxVariant& value ) return false; } +wxValidator* +wxFloatProperty::GetClassValidator() +{ +#if wxUSE_VALIDATORS + WX_PG_DOGETVALIDATOR_ENTRY() + + wxValidator* validator = new wxNumericPropertyValidator( + wxNumericPropertyValidator::Float); + + WX_PG_DOGETVALIDATOR_EXIT(validator) +#else + return NULL; +#endif +} + wxValidator* wxFloatProperty::DoGetValidator() const { - return wxIntProperty::GetClassValidator(); + return GetClassValidator(); } // ----------------------------------------------------------------------- @@ -2153,7 +2277,7 @@ void wxPGArrayEditorDialog::OnAddClick(wxCommandEvent& event) wxListCtrl* lc = m_elb->GetListCtrl(); int newItemIndex = lc->GetItemCount() - 1; - if ( m_hasCustomNewAction ) + if ( m_hasCustomNewAction ) { wxString str; if ( OnCustomNewAction(&str) )