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
This commit is contained in:
Jaakko Salli
2009-06-07 07:52:53 +00:00
parent 25f49256ac
commit b8b1ff481c
11 changed files with 124 additions and 54 deletions

View 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:

View 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.
*/

View 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 );

View 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.

View 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;
}

View 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:

View 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;
}

View 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:

View 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;
}
/*

View 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

View 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 )