From b8b1ff481cbc6116cf970eec994de930b6f1cb9b Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 7 Jun 2009 07:52:53 +0000 Subject: [PATCH] Implementations of wxPGProperty::ChildChanged() must now return changed value of the whole property instead of writing it back to 'thisValue' argument. This change was done primarily for better compatibility with wxPython bindings, but should also be slightly more cleaner behavior API-wise. Breaks backwards compatibility, but not silently. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60936 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/advprops.h | 5 +++-- include/wx/propgrid/property.h | 35 ++++++++++++++++++++--------- include/wx/propgrid/props.h | 6 ++--- interface/wx/propgrid/property.h | 38 +++++++++++++++++++++++--------- samples/propgrid/propgrid.cpp | 16 ++++++++++---- samples/propgrid/propgrid.h | 10 +++++---- samples/propgrid/sampleprops.cpp | 22 ++++++++++++++---- samples/propgrid/sampleprops.h | 15 ++++++++----- src/propgrid/advprops.cpp | 8 +++++-- src/propgrid/property.cpp | 12 ++++++---- src/propgrid/props.cpp | 11 +++++---- 11 files changed, 124 insertions(+), 54 deletions(-) diff --git a/include/wx/propgrid/advprops.h b/include/wx/propgrid/advprops.h index 10e6f15626..e2f3adea9a 100644 --- a/include/wx/propgrid/advprops.h +++ b/include/wx/propgrid/advprops.h @@ -183,8 +183,9 @@ public: virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const; virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ); - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); protected: diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 199ec099ca..106d983896 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -1274,17 +1274,21 @@ public: wxEvent& event ); /** - Called after value of a child property has been altered. + Called after value of a child property has been altered. Must return + new value of the whole property (after any alterations warrented by + child's new value). Note that this function is usually called at the time that value of - this property, or given child property, is still pending for change. + this property, or given child property, is still pending for change, + and as such, result of GetValue() or m_value should not be relied + on. Sample pseudo-code implementation: @code - void MyProperty::ChildChanged( wxVariant& thisValue, - int childIndex, - wxVariant& childValue ) const + wxVariant MyProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { // Acquire reference to actual type of data stored in variant // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros @@ -1302,19 +1306,28 @@ public: break; ... } + + // Return altered data + return data; } @endcode @param thisValue - Value of this property, that should be altered. + Value of this property. Changed value should be returned (in + previous versions of wxPropertyGrid it was only necessary to + write value back to this argument). @param childIndex - Index of child changed (you can use Item(childIndex) to get). + Index of child changed (you can use Item(childIndex) to get + child property). @param childValue - Value of the child property. + (Pending) value of the child property. + + @return + Modified value of the whole property. */ - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, - wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; /** Returns pointer to an instance of used editor. */ diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index 5a31c34bf6..53f4db9b7c 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -534,9 +534,9 @@ public: virtual bool StringToValue( wxVariant& variant, const wxString& text, int flags ) const; - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, - wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); virtual bool DoSetAttribute( const wxString& name, wxVariant& value ); diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index 9bf9531fb8..190947778a 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -698,18 +698,25 @@ public: virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_primary, wxEvent& event ); /** - Called after value of a child property has been altered. Note that this function is - usually called at the time that value of this property, or given child property, is - still pending for change. + Called after value of a child property has been altered. Must return + new value of the whole property (after any alterations warrented by + child's new value). + + Note that this function is usually called at the time that value of + this property, or given child property, is still pending for change, + and as such, result of GetValue() or m_value should not be relied + on. Sample pseudo-code implementation: @code - void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const + wxVariant MyProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { // Acquire reference to actual type of data stored in variant - // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create - // the variant class). + // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros + // were used to create the variant class). T& data = TFromVariant(thisValue); // Copy childValue into data. @@ -723,17 +730,28 @@ public: break; ... } + + // Return altered data + return data; } @endcode @param thisValue - Value of this property, that should be altered. + Value of this property. Changed value should be returned (in + previous versions of wxPropertyGrid it was only necessary to + write value back to this argument). @param childIndex - Index of child changed (you can use Item(childIndex) to get). + Index of child changed (you can use Item(childIndex) to get + child property). @param childValue - Value of the child property. + (Pending) value of the child property. + + @return + Modified value of the whole property. */ - virtual void ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; /** Returns pointer to an instance of used editor. diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 092b6c6360..f373edb474 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -493,7 +493,9 @@ void wxVectorProperty::RefreshChildren() Item(2)->SetValue( vector.z ); } -void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxVectorProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxVector3f vector; vector << thisValue; @@ -503,7 +505,9 @@ void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVar case 1: vector.y = childValue.GetDouble(); break; case 2: vector.z = childValue.GetDouble(); break; } - thisValue << vector; + wxVariant newVariant; + newVariant << vector; + return newVariant; } @@ -541,7 +545,9 @@ void wxTriangleProperty::RefreshChildren() Item(2)->SetValue( WXVARIANT(triangle.c) ); } -void wxTriangleProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxTriangleProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxTriangle triangle; triangle << thisValue; @@ -552,7 +558,9 @@ void wxTriangleProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV case 1: triangle.b = vector; break; case 2: triangle.c = vector; break; } - thisValue << triangle; + wxVariant newVariant; + newVariant << triangle; + return newVariant; } diff --git a/samples/propgrid/propgrid.h b/samples/propgrid/propgrid.h index a4c1ff613e..54c5f15ee3 100644 --- a/samples/propgrid/propgrid.h +++ b/samples/propgrid/propgrid.h @@ -76,8 +76,9 @@ public: const wxVector3f& value = wxVector3f() ); virtual ~wxVectorProperty(); - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); protected: @@ -108,8 +109,9 @@ public: const wxTriangle& value = wxTriangle() ); virtual ~wxTriangleProperty(); - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); protected: diff --git a/samples/propgrid/sampleprops.cpp b/samples/propgrid/sampleprops.cpp index e7c29c9d19..05159aa8fc 100644 --- a/samples/propgrid/sampleprops.cpp +++ b/samples/propgrid/sampleprops.cpp @@ -161,7 +161,9 @@ void wxFontDataProperty::RefreshChildren() Item(6)->SetValue( variant ); } -void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxFontDataProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxFontData fontData; fontData << thisValue; @@ -183,7 +185,9 @@ void wxFontDataProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV fontData.SetChosenFont(font); } - thisValue << fontData; + wxVariant newVariant; + newVariant << fontData; + return newVariant; } // ----------------------------------------------------------------------- @@ -211,7 +215,9 @@ void wxSizeProperty::RefreshChildren() Item(1)->SetValue( (long)size.y ); } -void wxSizeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxSizeProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxSize& size = wxSizeRefFromVariant(thisValue); int val = wxPGVariantToInt(childValue); @@ -220,6 +226,9 @@ void wxSizeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVaria case 0: size.x = val; break; case 1: size.y = val; break; } + wxVariant newVariant; + newVariant << size; + return newVariant; } // ----------------------------------------------------------------------- @@ -247,7 +256,9 @@ void wxPointProperty::RefreshChildren() Item(1)->SetValue( (long)point.y ); } -void wxPointProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxPointProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxPoint& point = wxPointRefFromVariant(thisValue); int val = wxPGVariantToInt(childValue); @@ -256,6 +267,9 @@ void wxPointProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVari case 0: point.x = val; break; case 1: point.y = val; break; } + wxVariant newVariant; + newVariant << point; + return newVariant; } diff --git a/samples/propgrid/sampleprops.h b/samples/propgrid/sampleprops.h index 3399ec8db8..963eade80f 100644 --- a/samples/propgrid/sampleprops.h +++ b/samples/propgrid/sampleprops.h @@ -34,8 +34,9 @@ public: // in base class to function properly. virtual wxVariant DoGetValue() const; - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ); @@ -56,8 +57,9 @@ public: const wxSize& value = wxSize() ); virtual ~wxSizeProperty(); - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); protected: @@ -80,8 +82,9 @@ public: const wxPoint& value = wxPoint() ); virtual ~wxPointProperty(); - virtual void ChildChanged( wxVariant& thisValue, - int childIndex, wxVariant& childValue ) const; + virtual wxVariant ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const; virtual void RefreshChildren(); protected: diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 8f4839c484..963abd0933 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -711,7 +711,9 @@ void wxFontProperty::RefreshChildren() Item(5)->SetValue( font.GetUnderlined() ); } -void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& childValue ) const +wxVariant wxFontProperty::ChildChanged( wxVariant& thisValue, + int ind, + wxVariant& childValue ) const { wxFont font; font << thisValue; @@ -761,7 +763,9 @@ void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& chi font.SetUnderlined( childValue.GetBool() ); } - thisValue << font; + wxVariant newVariant; + newVariant << font; + return newVariant; } /* diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 94c98b5f9d..8af53f28ab 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2163,7 +2163,10 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const } if ( allChildrenSpecified ) - ChildChanged(*value, i, childValue); + { + *value = ChildChanged(*value, i, childValue); + } + n++; if ( n == (unsigned int)list.GetCount() ) break; @@ -2365,10 +2368,11 @@ void wxPGProperty::DeleteChildren() } } -void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue), - int WXUNUSED(childIndex), - wxVariant& WXUNUSED(childValue) ) const +wxVariant wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue), + int WXUNUSED(childIndex), + wxVariant& WXUNUSED(childValue) ) const { + return wxNullVariant; } bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 97d5c1ad45..f179ca6592 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -1487,15 +1487,18 @@ void wxFlagsProperty::RefreshChildren() m_oldValue = flags; } -void wxFlagsProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxFlagsProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { long oldValue = thisValue.GetLong(); long val = childValue.GetLong(); unsigned long vi = m_choices.GetValue(childIndex); + if ( val ) - thisValue = (long)(oldValue | vi); - else - thisValue = (long)(oldValue & ~(vi)); + return (long) (oldValue | vi); + + return (long) (oldValue & ~(vi)); } bool wxFlagsProperty::DoSetAttribute( const wxString& name, wxVariant& value ) -- 2.45.2