Reworked the way child properties can be added to a property that has not yet been added to a grid or page; AddChild() deprecated, now use AddPrivateChild() instead. For public children, new member functions AppendChild() and InsertChild() should do the job.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-03-12 18:17:55 +00:00
parent 69cf69be93
commit 48a32cf671
8 changed files with 193 additions and 107 deletions

View File

@@ -1077,11 +1077,9 @@ public:
// If has private child properties then create them here. Also // If has private child properties then create them here. Also
// set flag that indicates presence of private children. E.g.: // set flag that indicates presence of private children. E.g.:
// //
// SetParentalType(wxPG_PROP_AGGREGATE); // AddPrivateChild( new wxStringProperty("Subprop 1",
// // wxPG_LABEL,
// AddChild( new wxStringProperty( "Subprop 1", // value.GetSubProp1() ) );
// wxPG_LABEL,
// value.GetSubProp1() ) );
} }
@endcode @endcode
@@ -1671,6 +1669,19 @@ public:
*/ */
bool HasVisibleChildren() const; bool HasVisibleChildren() const;
/**
Use this member function to add independent (ie. regular) children to
a property.
@return Inserted childProperty.
@remarks wxPropertyGrid is not automatically refreshed by this
function.
@see AddPrivateChild()
*/
wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
/** Inserts a new choice to property's list of choices. /** Inserts a new choice to property's list of choices.
*/ */
int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE ); int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
@@ -1947,16 +1958,12 @@ public:
Changes what sort of parent this property is for its children. Changes what sort of parent this property is for its children.
@param flag @param flag
Use one of the following values: wxPG_PROP_MISC_PARENT (for generic Use one of the following values: wxPG_PROP_MISC_PARENT (for
parents), wxPG_PROP_CATEGORY (for categories), or generic parents), wxPG_PROP_CATEGORY (for categories), or
wxPG_PROP_AGGREGATE (for derived property classes with private wxPG_PROP_AGGREGATE (for derived property classes with private
children). children).
@remarks You only need to call this if you use AddChild() to add @remarks You generally do not need to call this function.
child properties. Adding properties with
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn() will automatically set
property to use wxPG_PROP_MISC_PARENT style.
*/ */
void SetParentalType( int flag ) void SetParentalType( int flag )
{ {
@@ -2052,24 +2059,33 @@ public:
*/ */
void AdaptListToValue( wxVariant& list, wxVariant* value ) const; void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
#if wxPG_COMPATIBILITY_1_4
/** /**
Adds a child property. If you use this instead of Adds a private child property.
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn(), then you must set up
property's parental type before making the call. To do this,
call property's SetParentalType() function with either
wxPG_PROP_MISC_PARENT (normal, public children) or with
wxPG_PROP_AGGREGATE (private children for subclassed property).
For instance:
@code @deprecated Use AddPrivateChild() instead.
wxPGProperty* prop = new wxStringProperty(wxS("Property"));
prop->SetParentalType(wxPG_PROP_MISC_PARENT); @see AddPrivateChild()
wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
prop->AddChild(prop2);
@endcode
*/ */
void AddChild( wxPGProperty* prop ); wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
#endif
/**
Adds a private child property. If you use this instead of
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn(), then property's parental
type will automatically be set up to wxPG_PROP_AGGREGATE. In other
words, all properties of this property will become private.
*/
void AddPrivateChild( wxPGProperty* prop );
/**
Appends a new child property.
*/
wxPGProperty* AppendChild( wxPGProperty* prop )
{
return InsertChild(-1, prop);
}
/** Returns height of children, recursively, and /** Returns height of children, recursively, and
by taking expanded/collapsed status into account. by taking expanded/collapsed status into account.
@@ -2218,9 +2234,9 @@ protected:
unsigned int hintIndex ) const; unsigned int hintIndex ) const;
/** This is used by Insert etc. */ /** This is used by Insert etc. */
void AddChild2( wxPGProperty* prop, void DoAddChild( wxPGProperty* prop,
int index = -1, int index = -1,
bool correct_mode = true ); bool correct_mode = true );
void DoGenerateComposedValue( wxString& text, void DoGenerateComposedValue( wxString& text,
int argFlags = wxPG_VALUE_IS_CURRENT, int argFlags = wxPG_VALUE_IS_CURRENT,
@@ -2238,6 +2254,8 @@ protected:
// Removes child property with given pointer. Does not delete it. // Removes child property with given pointer. Does not delete it.
void RemoveChild( wxPGProperty* p ); void RemoveChild( wxPGProperty* p );
void DoPreAddChild( int index, wxPGProperty* prop );
void SetParentState( wxPropertyGridPageState* pstate ) void SetParentState( wxPropertyGridPageState* pstate )
{ m_parentState = pstate; } { m_parentState = pstate; }

View File

@@ -504,8 +504,11 @@ public:
variant << value; variant << value;
SetValue(variant); SetValue(variant);
// If has private child properties then create them here. For example: // If has private child properties then create them here.
// AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) ); // For example:
// AddPrivateChild( new wxStringProperty("Subprop 1",
// wxPG_LABEL,
// value.GetSubProp1()));
} }
@endcode @endcode
@@ -887,23 +890,22 @@ public:
int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE ); int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE );
/** /**
Adds a child property. If you use this instead of Adds a private child property.
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn(), then you must set up
property's parental type before making the call. To do this,
call property's SetParentalType() function with either
wxPG_PROP_MISC_PARENT (normal, public children) or with
wxPG_PROP_AGGREGATE (private children for subclassed property).
For instance:
@code @deprecated Use AddPrivateChild() instead.
wxPGProperty* prop = new wxStringProperty(wxS("Property"));
prop->SetParentalType(wxPG_PROP_MISC_PARENT); @see AddPrivateChild()
wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
prop->AddChild(prop2);
@endcode
*/ */
void AddChild( wxPGProperty* property ); wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
/**
Adds a private child property. If you use this instead of
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn(), then property's parental
type will automatically be set up to wxPG_PROP_AGGREGATE. In other
words, all properties of this property will become private.
*/
void AddPrivateChild( wxPGProperty* prop );
/** /**
Adapts list variant into proper value using consecutive Adapts list variant into proper value using consecutive
@@ -911,6 +913,19 @@ public:
*/ */
void AdaptListToValue( wxVariant& list, wxVariant* value ) const; void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
/**
Use this member function to add independent (ie. regular) children to
a property.
@return Appended childProperty.
@remarks wxPropertyGrid is not automatically refreshed by this
function.
@see InsertChild(), AddPrivateChild()
*/
wxPGProperty* AppendChild( wxPGProperty* childProperty );
/** /**
Determines, recursively, if all children are not unspecified. Determines, recursively, if all children are not unspecified.
@@ -1156,6 +1171,19 @@ public:
*/ */
int Index( const wxPGProperty* p ) const; int Index( const wxPGProperty* p ) const;
/**
Use this member function to add independent (ie. regular) children to
a property.
@return Inserted childProperty.
@remarks wxPropertyGrid is not automatically refreshed by this
function.
@see AppendChild(), AddPrivateChild()
*/
wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
/** /**
Inserts a new choice to property's list of choices. Inserts a new choice to property's list of choices.
@@ -1338,11 +1366,7 @@ public:
wxPG_PROP_AGGREGATE (for derived property classes with private wxPG_PROP_AGGREGATE (for derived property classes with private
children). children).
@remarks You only need to call this if you use AddChild() to add @remarks You generally do not need to call this function.
child properties. Adding properties with
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn() will automatically set
property to use wxPG_PROP_MISC_PARENT style.
*/ */
void SetParentalType( int flag ); void SetParentalType( int flag );

View File

@@ -477,10 +477,9 @@ wxVectorProperty::wxVectorProperty( const wxString& label,
: wxPGProperty(label,name) : wxPGProperty(label,name)
{ {
SetValue( WXVARIANT(value) ); SetValue( WXVARIANT(value) );
SetParentalType(wxPG_PROP_AGGREGATE); AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
AddChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) ); AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) ); AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
AddChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
} }
wxVectorProperty::~wxVectorProperty() { } wxVectorProperty::~wxVectorProperty() { }
@@ -526,10 +525,9 @@ wxTriangleProperty::wxTriangleProperty( const wxString& label,
: wxPGProperty(label,name) : wxPGProperty(label,name)
{ {
SetValue( WXVARIANT(value) ); SetValue( WXVARIANT(value) );
SetParentalType(wxPG_PROP_AGGREGATE); AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
AddChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) ); AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
AddChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) ); AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
AddChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
} }
wxTriangleProperty::~wxTriangleProperty() { } wxTriangleProperty::~wxTriangleProperty() { }
@@ -1727,11 +1725,12 @@ void FormMain::PopulateWithExamples ()
// For testing purposes, combine two methods of adding children // For testing purposes, combine two methods of adding children
// //
// AddChild() requires that we call this pid->AppendChild( new wxStringProperty(wxT("Latest Release"),
pid->SetParentalType(wxPG_PROP_MISC_PARENT); wxPG_LABEL,
wxT("2.8.10")));
pid->AddChild( new wxStringProperty(wxT("Latest Release"), wxPG_LABEL, wxT("2.8.8"))); pid->AppendChild( new wxBoolProperty(wxT("Win API"),
pid->AddChild( new wxBoolProperty(wxT("Win API"), wxPG_LABEL, true) ); wxPG_LABEL,
true) );
pg->Append( pid ); pg->Append( pid );

View File

@@ -67,11 +67,9 @@ wxFontDataProperty::wxFontDataProperty( const wxString& label, const wxString& n
// (instead of calling SetValue) in derived (wxObject) properties. // (instead of calling SetValue) in derived (wxObject) properties.
m_value_wxFontData << value; m_value_wxFontData << value;
SetParentalType(wxPG_PROP_AGGREGATE);
// Add extra children. // Add extra children.
AddChild( new wxColourProperty(_("Colour"), wxPG_LABEL, AddPrivateChild( new wxColourProperty(_("Colour"), wxPG_LABEL,
fontData.GetColour() ) ); fontData.GetColour() ) );
} }
wxFontDataProperty::~wxFontDataProperty () { } wxFontDataProperty::~wxFontDataProperty () { }
@@ -199,9 +197,8 @@ wxSizeProperty::wxSizeProperty( const wxString& label, const wxString& name,
const wxSize& value) : wxPGProperty(label,name) const wxSize& value) : wxPGProperty(label,name)
{ {
SetValueI(value); SetValueI(value);
SetParentalType(wxPG_PROP_AGGREGATE); AddPrivateChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) );
AddChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) ); AddPrivateChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) );
AddChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) );
} }
wxSizeProperty::~wxSizeProperty() { } wxSizeProperty::~wxSizeProperty() { }
@@ -236,9 +233,8 @@ wxPointProperty::wxPointProperty( const wxString& label, const wxString& name,
const wxPoint& value) : wxPGProperty(label,name) const wxPoint& value) : wxPGProperty(label,name)
{ {
SetValueI(value); SetValueI(value);
SetParentalType(wxPG_PROP_AGGREGATE); AddPrivateChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) );
AddChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) ); AddPrivateChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) );
} }
wxPointProperty::~wxPointProperty() { } wxPointProperty::~wxPointProperty() { }

View File

@@ -619,13 +619,12 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
wxFont font; wxFont font;
font << m_value; font << m_value;
SetParentalType(wxPG_PROP_AGGREGATE); AddPrivateChild( new wxIntProperty( _("Point Size"),
wxS("Point Size"),(long)font.GetPointSize() ) );
AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font.GetPointSize() ) ); AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
gs_fp_es_family_labels,gs_fp_es_family_values,
AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"), font.GetFamily()) );
gs_fp_es_family_labels,gs_fp_es_family_values,
font.GetFamily()) );
wxString faceName = font.GetFaceName(); wxString faceName = font.GetFaceName();
// If font was not in there, add it now // If font was not in there, add it now
@@ -638,16 +637,18 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
p->SetValueFromString(faceName, wxPG_FULL_VALUE); p->SetValueFromString(faceName, wxPG_FULL_VALUE);
AddChild( p ); AddPrivateChild( p );
AddChild( new wxEnumProperty(_("Style"), wxS("Style"), AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
gs_fp_es_style_labels,gs_fp_es_style_values,font.GetStyle()) ); gs_fp_es_style_labels,gs_fp_es_style_values,
font.GetStyle()) );
AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"), AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
gs_fp_es_weight_labels,gs_fp_es_weight_values,font.GetWeight()) ); gs_fp_es_weight_labels,gs_fp_es_weight_values,
font.GetWeight()) );
AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"), AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
font.GetUnderlined()) ); font.GetUnderlined()) );
} }
wxFontProperty::~wxFontProperty() { } wxFontProperty::~wxFontProperty() { }

View File

@@ -539,10 +539,12 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
if ( GetChildCount() ) if ( GetChildCount() )
{ {
// Check parental flags // Check parental flags
wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS), wxASSERT_MSG( ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
"Call SetFlag(wxPG_PROP_MISC_PARENT) or" wxPG_PROP_AGGREGATE) ||
"SetFlag(wxPG_PROP_AGGREGATE) before calling" ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
"wxPGProperty::AddChild()." ); wxPG_PROP_MISC_PARENT),
"wxPGProperty parental flags set incorrectly at "
"this time" );
if ( HasFlag(wxPG_PROP_AGGREGATE) ) if ( HasFlag(wxPG_PROP_AGGREGATE) )
{ {
@@ -2034,7 +2036,8 @@ int wxPGProperty::GetY() const
} }
// This is used by Insert etc. // This is used by Insert etc.
void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode ) void wxPGProperty::DoAddChild( wxPGProperty* prop, int index,
bool correct_mode )
{ {
if ( index < 0 || (size_t)index >= m_children.size() ) if ( index < 0 || (size_t)index >= m_children.size() )
{ {
@@ -2050,14 +2053,15 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
prop->m_parent = this; prop->m_parent = this;
} }
// This is used by properties that have fixed sub-properties void wxPGProperty::DoPreAddChild( int index, wxPGProperty* prop )
void wxPGProperty::AddChild( wxPGProperty* prop )
{ {
wxASSERT_MSG( prop->GetBaseName().length(), wxASSERT_MSG( prop->GetBaseName().length(),
"Property's children must have unique, non-empty names within their scope" ); "Property's children must have unique, non-empty "
"names within their scope" );
prop->m_arrIndex = m_children.size(); prop->m_arrIndex = index;
m_children.push_back( prop ); m_children.insert( m_children.begin()+index,
prop );
int custImgHeight = prop->OnMeasureImage().y; int custImgHeight = prop->OnMeasureImage().y;
if ( custImgHeight < 0 /*|| custImgHeight > 1*/ ) if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
@@ -2066,6 +2070,52 @@ void wxPGProperty::AddChild( wxPGProperty* prop )
prop->m_parent = this; prop->m_parent = this;
} }
void wxPGProperty::AddPrivateChild( wxPGProperty* prop )
{
if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
SetParentalType(wxPG_PROP_AGGREGATE);
wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
wxPG_PROP_AGGREGATE,
"Do not mix up AddPrivateChild() calls with other "
"property adders." );
DoPreAddChild( m_children.size(), prop );
}
#if wxPG_COMPATIBILITY_1_4
void wxPGProperty::AddChild( wxPGProperty* prop )
{
AddPrivateChild(prop);
}
#endif
wxPGProperty* wxPGProperty::InsertChild( int index,
wxPGProperty* childProperty )
{
if ( index < 0 )
index = m_children.size();
if ( m_parentState )
{
m_parentState->DoInsert(this, index, childProperty);
}
else
{
if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
SetParentalType(wxPG_PROP_MISC_PARENT);
wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
wxPG_PROP_MISC_PARENT,
"Do not mix up AddPrivateChild() calls with other "
"property adders." );
DoPreAddChild( index, childProperty );
}
return childProperty;
}
void wxPGProperty::RemoveChild( wxPGProperty* p ) void wxPGProperty::RemoveChild( wxPGProperty* p )
{ {
wxArrayPGProperty::iterator it; wxArrayPGProperty::iterator it;

View File

@@ -255,7 +255,7 @@ void wxPropertyGridPageState::InitNonCatMode()
wxPGProperty* parent = p->GetParent(); wxPGProperty* parent = p->GetParent();
if ( parent->IsCategory() || parent->IsRoot() ) if ( parent->IsCategory() || parent->IsRoot() )
{ {
m_abcArray->AddChild2(p); m_abcArray->DoAddChild(p);
p->m_parent = &m_regularArray; p->m_parent = &m_regularArray;
} }
} }
@@ -1655,11 +1655,11 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
if ( m_abcArray && !property->IsCategory() && if ( m_abcArray && !property->IsCategory() &&
(parentIsCategory || parentIsRoot) ) (parentIsCategory || parentIsRoot) )
{ {
m_abcArray->AddChild2( property, -1, false ); m_abcArray->DoAddChild( property, -1, false );
} }
// Add to current mode. // Add to current mode.
parent->AddChild2( property, index, true ); parent->DoAddChild( property, index, true );
} }
else else
{ {
@@ -1667,14 +1667,14 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
if ( parentIsCategory ) if ( parentIsCategory )
// Parent is category. // Parent is category.
parent->AddChild2( property, index, false ); parent->DoAddChild( property, index, false );
else if ( parentIsRoot ) else if ( parentIsRoot )
// Parent is root. // Parent is root.
m_regularArray.AddChild2( property, -1, false ); m_regularArray.DoAddChild( property, -1, false );
// Add to current mode // Add to current mode
if ( !property->IsCategory() ) if ( !property->IsCategory() )
m_abcArray->AddChild2( property, index, true ); m_abcArray->DoAddChild( property, index, true );
} }
// category stuff // category stuff

View File

@@ -1187,8 +1187,6 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty,long,TextCtrl)
void wxFlagsProperty::Init() void wxFlagsProperty::Init()
{ {
SetParentalType(wxPG_PROP_AGGREGATE);
long value = m_value; long value = m_value;
// //
@@ -1248,7 +1246,7 @@ void wxFlagsProperty::Init()
{ {
boolProp = new wxBoolProperty( label, label, child_val ); boolProp = new wxBoolProperty( label, label, child_val );
} }
AddChild(boolProp); AddPrivateChild(boolProp);
} }
m_oldChoicesData = m_choices.GetDataPtr(); m_oldChoicesData = m_choices.GetDataPtr();