X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce00f59b5b169752d2f05ce3bb1a88ddc1b38b4c..404b319a85dadd7decf7a5a5331020520031a41c:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index cdb43bffdf..7228b910e7 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -95,7 +95,9 @@ wxString wxStringProperty::ValueToString( wxVariant& value, if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE) ) { // Value stored in m_value is non-editable, non-full value - if ( (argFlags & wxPG_FULL_VALUE) || (argFlags & wxPG_EDITABLE_VALUE) ) + if ( (argFlags & wxPG_FULL_VALUE) || + (argFlags & wxPG_EDITABLE_VALUE) || + !s.length() ) { // Calling this under incorrect conditions will fail wxASSERT_MSG( argFlags & wxPG_VALUE_IS_CURRENT, @@ -142,6 +144,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 ( !wxDynamicCast(wnd, wxTextCtrl) ) + return true; + + // Do not allow zero-length string + wxTextCtrl* tc = static_cast(wnd); + wxString text = tc->GetValue(); + + if ( text.empty() ) + return false; + + return true; +} + +#endif // wxUSE_VALIDATORS + // ----------------------------------------------------------------------- // wxIntProperty // ----------------------------------------------------------------------- @@ -184,7 +260,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int wxString s; long value32; - if ( text.length() == 0 ) + if ( text.empty() ) { variant.MakeNull(); return true; @@ -376,9 +452,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 @@ -399,9 +474,9 @@ wxValidator* wxIntProperty::DoGetValidator() const #define wxPG_UINT_TEMPLATE_MAX 8 static const wxChar* const gs_uintTemplates32[wxPG_UINT_TEMPLATE_MAX] = { - wxT("%x"),wxT("0x%x"),wxT("$%x"), - wxT("%X"),wxT("0x%X"),wxT("$%X"), - wxT("%u"),wxT("%o") + wxT("%lx"),wxT("0x%lx"),wxT("$%lx"), + wxT("%lX"),wxT("0x%lX"),wxT("$%lX"), + wxT("%lu"),wxT("%lo") }; static const char* const gs_uintTemplates64[wxPG_UINT_TEMPLATE_MAX] = { @@ -464,7 +539,7 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in wxString variantType = variant.GetType(); bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; - if ( text.length() == 0 ) + if ( text.empty() ) { variant.MakeNull(); return true; @@ -531,6 +606,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 +670,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 ) { @@ -592,7 +682,7 @@ void wxPropertyGrid::DoubleToString(wxString& target, if (!precTemplate) precTemplate = &text1; - if ( !precTemplate->length() ) + if ( precTemplate->empty() ) { *precTemplate = wxS("%."); *precTemplate << wxString::Format( wxS("%i"), precision ); @@ -606,7 +696,7 @@ void wxPropertyGrid::DoubleToString(wxString& target, target.Printf( wxS("%f"), value ); } - if ( removeZeroes && precision != 0 && target.length() ) + if ( removeZeroes && precision != 0 && !target.empty() ) { // Remove excess zeroes (do not remove this code just yet, // since sprintf can't do the same consistently across platforms). @@ -627,6 +717,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, @@ -649,7 +760,7 @@ bool wxFloatProperty::StringToValue( wxVariant& variant, const wxString& text, i wxString s; double value; - if ( text.length() == 0 ) + if ( text.empty() ) { variant.MakeNull(); return true; @@ -701,9 +812,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(); } // ----------------------------------------------------------------------- @@ -788,7 +914,7 @@ bool wxBoolProperty::StringToValue( wxVariant& variant, const wxString& text, in text.CmpNoCase(m_label) == 0 ) boolValue = true; - if ( text.length() == 0 ) + if ( text.empty() ) { variant.MakeNull(); return true; @@ -954,7 +1080,7 @@ bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUS // unless property has string as preferred value type // To reduce code size, use conversion here as well if ( value.GetType() == wxPG_VARIANT_TYPE_STRING && - !this->IsKindOf(CLASSINFO(wxEditEnumProperty)) ) + !wxDynamicCastThis(wxEditEnumProperty) ) return ValueFromString_( value, value.GetString(), wxPG_PROPERTY_SPECIFIC ); return true; @@ -1001,7 +1127,7 @@ bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, i bool asText = false; - bool isEdit = this->IsKindOf(CLASSINFO(wxEditEnumProperty)); + bool isEdit = this->IsKindOf(wxCLASSINFO(wxEditEnumProperty)); // If text not any of the choices, store as text instead // (but only if we are wxEditEnumProperty) @@ -1392,7 +1518,7 @@ bool wxFlagsProperty::StringToValue( wxVariant& variant, const wxString& text, i // semicolons are no longer valid delimeters WX_PG_TOKENIZER1_BEGIN(text,wxS(',')) - if ( token.length() ) + if ( !token.empty() ) { // Determine which one it is long bit = IdToBit( token ); @@ -1557,14 +1683,14 @@ bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid* propGrid, wxPGProperty wxString path; int indFilter = -1; - if ( property->IsKindOf(CLASSINFO(wxFileProperty)) ) + if ( wxDynamicCast(property, wxFileProperty) ) { fileProp = ((wxFileProperty*)property); wxFileName filename = fileProp->GetValue().GetString(); path = filename.GetPath(); indFilter = fileProp->m_indFilter; - if ( !path.length() && fileProp->m_basePath.length() ) + if ( path.empty() && !fileProp->m_basePath.empty() ) path = fileProp->m_basePath; } else @@ -1577,8 +1703,8 @@ bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid* propGrid, wxPGProperty property->GetAttribute(wxS("DialogTitle"), _("Choose a file")), property->GetAttribute(wxS("InitialPath"), path), wxEmptyString, - property->GetAttribute(wxPG_FILE_WILDCARD, _("All files (*.*)|*.*")), - 0, + property->GetAttribute(wxPG_FILE_WILDCARD, wxALL_FILES), + property->GetAttributeAsLong(wxPG_FILE_DIALOG_STYLE, 0), wxDefaultPosition ); if ( indFilter >= 0 ) @@ -1606,7 +1732,7 @@ wxFileProperty::wxFileProperty( const wxString& label, const wxString& name, { m_flags |= wxPG_PROP_SHOW_FULL_FILENAME; m_indFilter = -1; - SetAttribute( wxPG_FILE_WILDCARD, _("All files (*.*)|*.*") ); + SetAttribute( wxPG_FILE_WILDCARD, wxALL_FILES); SetValue(value); } @@ -1655,7 +1781,7 @@ void wxFileProperty::OnSetValue() } // Find index for extension. - if ( m_indFilter < 0 && fnstr.length() ) + if ( m_indFilter < 0 && !fnstr.empty() ) { wxString ext = filename.GetExt(); int curind = 0; @@ -1672,7 +1798,7 @@ void wxFileProperty::OnSetValue() pos = len; wxString found_ext = m_wildcard.substr(ext_begin, pos-ext_begin); - if ( found_ext.length() > 0 ) + if ( !found_ext.empty() ) { if ( found_ext[0] == wxS('*') ) { @@ -1713,7 +1839,7 @@ wxString wxFileProperty::ValueToString( wxVariant& value, return wxEmptyString; wxString fullName = filename.GetFullName(); - if ( !fullName.length() ) + if ( fullName.empty() ) return wxEmptyString; if ( argFlags & wxPG_FULL_VALUE ) @@ -1722,7 +1848,7 @@ wxString wxFileProperty::ValueToString( wxVariant& value, } else if ( m_flags & wxPG_PROP_SHOW_FULL_FILENAME ) { - if ( m_basePath.Length() ) + if ( !m_basePath.empty() ) { wxFileName fn2(filename); fn2.MakeRelativeTo(m_basePath); @@ -2060,7 +2186,7 @@ bool wxPGArrayEditorDialog::Create( wxWindow *parent, wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL ); // Message - if ( message.length() ) + if ( !message.empty() ) topsizer->Add( new wxStaticText(this,-1,message), 0, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxALL, spacing ); @@ -2411,7 +2537,8 @@ wxArrayStringProperty::ArrayStringToString( wxString& dst, if ( flags & Escape ) { preas = delimiter; - pdr = wxS("\\") + static_cast(delimiter); + pdr = wxS("\\"); + pdr += delimiter; } if ( itemCount ) @@ -2429,7 +2556,7 @@ wxArrayStringProperty::ArrayStringToString( wxString& dst, if ( flags & Escape ) { str.Replace( wxS("\\"), wxS("\\\\"), true ); - if ( pdr.length() ) + if ( !pdr.empty() ) str.Replace( preas, pdr, true ); }