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
// set flag that indicates presence of private children. E.g.:
//
// SetParentalType(wxPG_PROP_AGGREGATE);
//
// AddChild( new wxStringProperty( "Subprop 1",
// wxPG_LABEL,
// value.GetSubProp1() ) );
// AddPrivateChild( new wxStringProperty("Subprop 1",
// wxPG_LABEL,
// value.GetSubProp1() ) );
}
@endcode
@ -1671,6 +1669,19 @@ public:
*/
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.
*/
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.
@param flag
Use one of the following values: wxPG_PROP_MISC_PARENT (for generic
parents), wxPG_PROP_CATEGORY (for categories), or
Use one of the following values: wxPG_PROP_MISC_PARENT (for
generic parents), wxPG_PROP_CATEGORY (for categories), or
wxPG_PROP_AGGREGATE (for derived property classes with private
children).
@remarks You only need to call this if you use AddChild() to add
child properties. Adding properties with
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn() will automatically set
property to use wxPG_PROP_MISC_PARENT style.
@remarks You generally do not need to call this function.
*/
void SetParentalType( int flag )
{
@ -2052,24 +2059,33 @@ public:
*/
void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
#if wxPG_COMPATIBILITY_1_4
/**
Adds a child property. If you use this instead of
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:
Adds a private child property.
@code
wxPGProperty* prop = new wxStringProperty(wxS("Property"));
prop->SetParentalType(wxPG_PROP_MISC_PARENT);
wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
prop->AddChild(prop2);
@endcode
@deprecated Use AddPrivateChild() instead.
@see AddPrivateChild()
*/
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
by taking expanded/collapsed status into account.
@ -2218,9 +2234,9 @@ protected:
unsigned int hintIndex ) const;
/** This is used by Insert etc. */
void AddChild2( wxPGProperty* prop,
int index = -1,
bool correct_mode = true );
void DoAddChild( wxPGProperty* prop,
int index = -1,
bool correct_mode = true );
void DoGenerateComposedValue( wxString& text,
int argFlags = wxPG_VALUE_IS_CURRENT,
@ -2238,6 +2254,8 @@ protected:
// Removes child property with given pointer. Does not delete it.
void RemoveChild( wxPGProperty* p );
void DoPreAddChild( int index, wxPGProperty* prop );
void SetParentState( wxPropertyGridPageState* pstate )
{ m_parentState = pstate; }

View File

@ -504,8 +504,11 @@ public:
variant << value;
SetValue(variant);
// If has private child properties then create them here. For example:
// AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
// If has private child properties then create them here.
// For example:
// AddPrivateChild( new wxStringProperty("Subprop 1",
// wxPG_LABEL,
// value.GetSubProp1()));
}
@endcode
@ -887,23 +890,22 @@ public:
int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE );
/**
Adds a child property. If you use this instead of
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:
Adds a private child property.
@code
wxPGProperty* prop = new wxStringProperty(wxS("Property"));
prop->SetParentalType(wxPG_PROP_MISC_PARENT);
wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
prop->AddChild(prop2);
@endcode
@deprecated Use AddPrivateChild() instead.
@see AddPrivateChild()
*/
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
@ -911,6 +913,19 @@ public:
*/
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.
@ -1156,6 +1171,19 @@ public:
*/
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.
@ -1338,11 +1366,7 @@ public:
wxPG_PROP_AGGREGATE (for derived property classes with private
children).
@remarks You only need to call this if you use AddChild() to add
child properties. Adding properties with
wxPropertyGridInterface::Insert() or
wxPropertyGridInterface::AppendIn() will automatically set
property to use wxPG_PROP_MISC_PARENT style.
@remarks You generally do not need to call this function.
*/
void SetParentalType( int flag );

View File

@ -477,10 +477,9 @@ wxVectorProperty::wxVectorProperty( const wxString& label,
: wxPGProperty(label,name)
{
SetValue( WXVARIANT(value) );
SetParentalType(wxPG_PROP_AGGREGATE);
AddChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
AddChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
AddPrivateChild( new wxFloatProperty(wxT("X"),wxPG_LABEL,value.x) );
AddPrivateChild( new wxFloatProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddPrivateChild( new wxFloatProperty(wxT("Z"),wxPG_LABEL,value.z) );
}
wxVectorProperty::~wxVectorProperty() { }
@ -526,10 +525,9 @@ wxTriangleProperty::wxTriangleProperty( const wxString& label,
: wxPGProperty(label,name)
{
SetValue( WXVARIANT(value) );
SetParentalType(wxPG_PROP_AGGREGATE);
AddChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
AddChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
AddChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
AddPrivateChild( new wxVectorProperty(wxT("A"),wxPG_LABEL,value.a) );
AddPrivateChild( new wxVectorProperty(wxT("B"),wxPG_LABEL,value.b) );
AddPrivateChild( new wxVectorProperty(wxT("C"),wxPG_LABEL,value.c) );
}
wxTriangleProperty::~wxTriangleProperty() { }
@ -1727,11 +1725,12 @@ void FormMain::PopulateWithExamples ()
// For testing purposes, combine two methods of adding children
//
// AddChild() requires that we call this
pid->SetParentalType(wxPG_PROP_MISC_PARENT);
pid->AddChild( new wxStringProperty(wxT("Latest Release"), wxPG_LABEL, wxT("2.8.8")));
pid->AddChild( new wxBoolProperty(wxT("Win API"), wxPG_LABEL, true) );
pid->AppendChild( new wxStringProperty(wxT("Latest Release"),
wxPG_LABEL,
wxT("2.8.10")));
pid->AppendChild( new wxBoolProperty(wxT("Win API"),
wxPG_LABEL,
true) );
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.
m_value_wxFontData << value;
SetParentalType(wxPG_PROP_AGGREGATE);
// Add extra children.
AddChild( new wxColourProperty(_("Colour"), wxPG_LABEL,
fontData.GetColour() ) );
AddPrivateChild( new wxColourProperty(_("Colour"), wxPG_LABEL,
fontData.GetColour() ) );
}
wxFontDataProperty::~wxFontDataProperty () { }
@ -199,9 +197,8 @@ wxSizeProperty::wxSizeProperty( const wxString& label, const wxString& name,
const wxSize& value) : wxPGProperty(label,name)
{
SetValueI(value);
SetParentalType(wxPG_PROP_AGGREGATE);
AddChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) );
AddChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) );
AddPrivateChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) );
AddPrivateChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) );
}
wxSizeProperty::~wxSizeProperty() { }
@ -236,9 +233,8 @@ wxPointProperty::wxPointProperty( const wxString& label, const wxString& name,
const wxPoint& value) : wxPGProperty(label,name)
{
SetValueI(value);
SetParentalType(wxPG_PROP_AGGREGATE);
AddChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) );
AddChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) );
AddPrivateChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) );
AddPrivateChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) );
}
wxPointProperty::~wxPointProperty() { }

View File

@ -619,13 +619,12 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
wxFont font;
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() ) );
AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
gs_fp_es_family_labels,gs_fp_es_family_values,
font.GetFamily()) );
AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
gs_fp_es_family_labels,gs_fp_es_family_values,
font.GetFamily()) );
wxString faceName = font.GetFaceName();
// 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);
AddChild( p );
AddPrivateChild( p );
AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
gs_fp_es_style_labels,gs_fp_es_style_values,font.GetStyle()) );
AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
gs_fp_es_style_labels,gs_fp_es_style_values,
font.GetStyle()) );
AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
gs_fp_es_weight_labels,gs_fp_es_weight_values,font.GetWeight()) );
AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
gs_fp_es_weight_labels,gs_fp_es_weight_values,
font.GetWeight()) );
AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
font.GetUnderlined()) );
AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
font.GetUnderlined()) );
}
wxFontProperty::~wxFontProperty() { }

View File

@ -539,10 +539,12 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
if ( GetChildCount() )
{
// Check parental flags
wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS),
"Call SetFlag(wxPG_PROP_MISC_PARENT) or"
"SetFlag(wxPG_PROP_AGGREGATE) before calling"
"wxPGProperty::AddChild()." );
wxASSERT_MSG( ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
wxPG_PROP_AGGREGATE) ||
((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
wxPG_PROP_MISC_PARENT),
"wxPGProperty parental flags set incorrectly at "
"this time" );
if ( HasFlag(wxPG_PROP_AGGREGATE) )
{
@ -2034,7 +2036,8 @@ int wxPGProperty::GetY() const
}
// 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() )
{
@ -2050,14 +2053,15 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
prop->m_parent = this;
}
// This is used by properties that have fixed sub-properties
void wxPGProperty::AddChild( wxPGProperty* prop )
void wxPGProperty::DoPreAddChild( int index, wxPGProperty* prop )
{
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();
m_children.push_back( prop );
prop->m_arrIndex = index;
m_children.insert( m_children.begin()+index,
prop );
int custImgHeight = prop->OnMeasureImage().y;
if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
@ -2066,6 +2070,52 @@ void wxPGProperty::AddChild( wxPGProperty* prop )
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 )
{
wxArrayPGProperty::iterator it;

View File

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

View File

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