]> git.saurik.com Git - wxWidgets.git/commitdiff
Implementations of wxPGProperty::ChildChanged() must now return changed value of...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 7 Jun 2009 07:52:53 +0000 (07:52 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 7 Jun 2009 07:52:53 +0000 (07:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60936 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/advprops.h
include/wx/propgrid/property.h
include/wx/propgrid/props.h
interface/wx/propgrid/property.h
samples/propgrid/propgrid.cpp
samples/propgrid/propgrid.h
samples/propgrid/sampleprops.cpp
samples/propgrid/sampleprops.h
src/propgrid/advprops.cpp
src/propgrid/property.cpp
src/propgrid/props.cpp

index 10e6f15626e8d7672a864d5f69c859801667b046..e2f3adea9af3d2c04ea4af834fe9613c2b5b1fae 100644 (file)
@@ -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:
index 199ec099ca326089b8c3be473636b53fc562aba7..106d983896437aadb8ab9422128eff9ed466ec67 100644 (file)
@@ -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.
     */
index 5a31c34bf6cd7d4e44259efcb60bf036ef427d46..53f4db9b7c8e8382f7c2a3dbcc6b4954f8e859ad 100644 (file)
@@ -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 );
 
index 9bf9531fb83f70c62327751a5b0c7faba7878008..190947778a663b414d3e4756a804cf75b48cb733 100644 (file)
@@ -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.
index 092b6c6360429ae0d9e9dae6a9eece401272a309..f373edb4746909a80e0017b6d609dfd3c1bb3e6d 100644 (file)
@@ -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;
 }
 
 
index a4c1ff613e3e78c8414fc02b1072d8716a647604..54c5f15ee392a7012f1e5185c09acb7a327f72b2 100644 (file)
@@ -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:
index e7c29c9d190c491edda1afbc2daca9aebbcf0408..05159aa8fca32e824dfba27970e51fae1063b107 100644 (file)
@@ -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;
 }
 
 
index 3399ec8db8172ee167036e3b95ca56e3f1e4d8cf..963eade80f9aeaeac327808c35736c86e14b5632 100644 (file)
@@ -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:
index 8f4839c4848a6cb01d8245db5402230e2974c4d2..963abd0933eba31e034930baa525aea161d27423 100644 (file)
@@ -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;
 }
 
 /*
index 94c98b5f9da6e05347ad0868eea4f30cdbae5989..8af53f28ab861d1bf94ef042f5bf141943879add 100644 (file)
@@ -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
index 97d5c1ad45d2d13aba14c5f096e5d1d0e8e2cb36..f179ca659252b0c9365c9dd8e5997f22f17f74b6 100644 (file)
@@ -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 )