From f275b5dbfd061df2d64d0cdda203dc0fb468f229 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Mon, 20 Oct 2008 17:01:17 +0000 Subject: [PATCH] User should no longer be able to modify disabled or read only child properties by editing their parent (wxPG sf bug #2181860) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/property.h | 2 +- include/wx/propgrid/propgriddefs.h | 5 ++- src/propgrid/property.cpp | 71 +++++++++++++++++------------- src/propgrid/propgrid.cpp | 3 +- src/propgrid/propgridpagestate.cpp | 2 +- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 8a087be51e..90494f0783 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -1107,7 +1107,7 @@ public: @return true if value was changed. */ - bool SetValueFromString( const wxString& text, int flags = 0 ); + bool SetValueFromString( const wxString& text, int flags = wxPG_PROGRAMMATIC_VALUE ); /** Converts integer to a value, and if succesful, calls SetValue() on it. Default behavior is to do nothing. diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 98c339c062..2f9be1eea7 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -405,7 +405,10 @@ enum wxPG_MISC_ARG_FLAGS // ValueToString() called from GetValueAsString() // (guarantees that input wxVariant value is current own value) - wxPG_VALUE_IS_CURRENT = 0x00000040 + wxPG_VALUE_IS_CURRENT = 0x00000040, + + // Value is being set programmatically (ie. not by user) + wxPG_PROGRAMMATIC_VALUE = 0x00000080 }; // ----------------------------------------------------------------------- diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 093793c802..65811cca7a 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -881,7 +881,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int wxVariantList temp_list; wxVariant list(temp_list); - int propagatedFlags = argFlags & wxPG_REPORT_ERROR; + int propagatedFlags = argFlags & (wxPG_REPORT_ERROR|wxPG_PROGRAMMATIC_VALUE); #ifdef __WXDEBUG__ bool debug_print = false; @@ -914,41 +914,45 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int if ( !addOnlyIfNotEmpty || len > 0 ) { const wxPGProperty* child = Item(curChild); + wxVariant variant(child->GetValue()); + variant.SetName(child->GetBaseName()); + #ifdef __WXDEBUG__ if ( debug_print ) wxLogDebug(wxT("token = '%s', child = %s"),token.c_str(),child->GetLabel().c_str()); #endif - if ( len > 0 ) + // Add only if editable or setting programmatically + if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || + !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) { - bool wasUnspecified = child->IsValueUnspecified(); - - wxVariant variant(child->GetValueRef()); - if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) ) + if ( len > 0 ) { - variant.SetName(child->GetBaseName()); + bool wasUnspecified = child->IsValueUnspecified(); - // Clear unspecified flag only if OnSetValue() didn't - // affect it. - if ( child->IsValueUnspecified() && - (wasUnspecified || !UsesAutoUnspecified()) ) + if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) ) { - variant = child->GetDefaultValue(); - } + // Clear unspecified flag only if OnSetValue() didn't + // affect it. + if ( child->IsValueUnspecified() && + (wasUnspecified || !UsesAutoUnspecified()) ) + { + variant = child->GetDefaultValue(); + } - list.Append(variant); + list.Append(variant); + changed = true; + } + } + else + { + // Empty, becomes unspecified + variant.MakeNull(); + list.Append(variant); changed = true; } } - else - { - // Empty, becomes unspecified - wxVariant variant2; - variant2.SetName(child->GetBaseName()); - list.Append(variant2); - changed = true; - } curChild++; if ( curChild >= iMax ) @@ -997,17 +1001,22 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int wxVariant oldChildValue = child->GetValue(); wxVariant variant(oldChildValue); - bool stvRes = child->StringToValue( variant, token, propagatedFlags ); - if ( stvRes || (variant != oldChildValue) ) + + if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) || + !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) ) { - if ( stvRes ) + bool stvRes = child->StringToValue( variant, token, propagatedFlags ); + if ( stvRes || (variant != oldChildValue) ) + { + if ( stvRes ) + changed = true; + } + else + { + // Failed, becomes unspecified + variant.MakeNull(); changed = true; - } - else - { - // Failed, becomes unspecified - variant.MakeNull(); - changed = true; + } } variant.SetName(child->GetBaseName()); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 1c364c0862..4e790e7525 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -5855,7 +5855,8 @@ wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass, m_state->DoInsert(parent, -1, property); if ( propValue ) - property->SetValueFromString( *propValue, wxPG_FULL_VALUE ); + property->SetValueFromString( *propValue, wxPG_FULL_VALUE| + wxPG_PROGRAMMATIC_VALUE ); return property; } diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index fe2c7a0d66..1b2f47a091 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1100,7 +1100,7 @@ bool wxPropertyGridPageState::DoSetPropertyValueString( wxPGProperty* p, const w { if ( p ) { - int flags = wxPG_REPORT_ERROR|wxPG_FULL_VALUE; + int flags = wxPG_REPORT_ERROR|wxPG_FULL_VALUE|wxPG_PROGRAMMATIC_VALUE; wxVariant variant = p->GetValueRef(); bool res; -- 2.47.2