Added wxPGProperty::Enable() for conveniency. Refactored related code and improved related documentation.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65216 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2010-08-08 11:41:20 +00:00
parent 62e9285aba
commit 9ceed261f8
8 changed files with 69 additions and 43 deletions

View File

@@ -1523,6 +1523,17 @@ public:
*/ */
void DeleteChoice( int index ); void DeleteChoice( int index );
/**
Enables or disables the property. Disabled property usually appears
as having grey text.
@param enable
If @false, property is disabled instead.
@see wxPropertyGridInterface::EnableProperty()
*/
void Enable( bool enable = true );
/** /**
Call to enable or disable usage of common value (integer value that can Call to enable or disable usage of common value (integer value that can
be selected for properties instead of their normal values) for this be selected for properties instead of their normal values) for this
@@ -2357,6 +2368,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 DoEnable( bool enable );
void DoPreAddChild( int index, wxPGProperty* prop ); void DoPreAddChild( int index, wxPGProperty* prop );
void SetParentState( wxPropertyGridPageState* pstate ) void SetParentState( wxPropertyGridPageState* pstate )

View File

@@ -267,7 +267,11 @@ public:
*/ */
wxPGProperty* RemoveProperty( wxPGPropArg id ); wxPGProperty* RemoveProperty( wxPGPropArg id );
/** Disables property. */ /**
Disables a property.
@see EnableProperty(), wxPGProperty::Enable()
*/
bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); } bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); }
/** /**
@@ -280,7 +284,14 @@ public:
/** /**
Enables or disables property, depending on whether enable is true or Enables or disables property, depending on whether enable is true or
false. false. Disabled property usually appears as having grey text.
@param id
Name or pointer to a property.
@param enable
If @false, property is disabled instead.
@see wxPGProperty::Enable()
*/ */
bool EnableProperty( wxPGPropArg id, bool enable = true ); bool EnableProperty( wxPGPropArg id, bool enable = true );

View File

@@ -473,9 +473,6 @@ public:
} }
} }
/** Enables or disables given property and its subproperties. */
bool DoEnableProperty( wxPGProperty* p, bool enable );
/** Returns (precalculated) height of contained visible properties. /** Returns (precalculated) height of contained visible properties.
*/ */
unsigned int GetVirtualHeight() const unsigned int GetVirtualHeight() const

View File

@@ -1161,6 +1161,17 @@ public:
/** Deletes all child properties. */ /** Deletes all child properties. */
void Empty(); void Empty();
/**
Enables or disables the property. Disabled property usually appears
as having grey text.
@param enable
If @false, property is disabled instead.
@see wxPropertyGridInterface::EnableProperty()
*/
void Enable( bool enable = true );
/** /**
Composes text from values of child properties. Composes text from values of child properties.
*/ */

View File

@@ -153,6 +153,8 @@ public:
/** /**
Disables a property. Disables a property.
@see EnableProperty(), wxPGProperty::Enable()
*/ */
bool DisableProperty( wxPGPropArg id ); bool DisableProperty( wxPGPropArg id );
@@ -164,12 +166,15 @@ public:
bool EditorValidate(); bool EditorValidate();
/** /**
Enables or disables property. Enables or disables property. Disabled property usually appears as
having grey text.
@param id @param id
Name or pointer to a property. Name or pointer to a property.
@param enable @param enable
If @false, property is disabled instead. If @false, property is disabled instead.
@see wxPGProperty::Enable()
*/ */
bool EnableProperty( wxPGPropArg id, bool enable = true ); bool EnableProperty( wxPGPropArg id, bool enable = true );

View File

@@ -1492,6 +1492,31 @@ wxVariant wxPGProperty::GetDefaultValue() const
return wxVariant(); return wxVariant();
} }
void wxPGProperty::Enable( bool enable )
{
wxPropertyGrid* pg = GetGrid();
// Preferably call the version in the owning wxPropertyGrid,
// since it handles the editor de-activation.
if ( pg )
pg->EnableProperty(this, enable);
else
DoEnable(enable);
}
void wxPGProperty::DoEnable( bool enable )
{
if ( enable )
ClearFlag(wxPG_PROP_DISABLED);
else
SetFlag(wxPG_PROP_DISABLED);
// Apply same to sub-properties as well
unsigned int i;
for ( i = 0; i < GetChildCount(); i++ )
Item(i)->DoEnable( enable );
}
void wxPGProperty::EnsureCells( unsigned int column ) void wxPGProperty::EnsureCells( unsigned int column )
{ {
if ( column >= m_cells.size() ) if ( column >= m_cells.size() )

View File

@@ -277,7 +277,7 @@ bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id, bool enable )
grid->DoSelectProperty( p, wxPG_SEL_FORCE ); grid->DoSelectProperty( p, wxPG_SEL_FORCE );
} }
state->DoEnableProperty(p, enable); p->DoEnable(enable);
RefreshProperty( p ); RefreshProperty( p );

View File

@@ -1398,42 +1398,6 @@ bool wxPropertyGridPageState::DoHideProperty( wxPGProperty* p, bool hide, int fl
return true; return true;
} }
// -----------------------------------------------------------------------
bool wxPropertyGridPageState::DoEnableProperty( wxPGProperty* p, bool enable )
{
if ( p )
{
if ( enable )
{
if ( !(p->m_flags & wxPG_PROP_DISABLED) )
return false;
// Enabling
p->m_flags &= ~(wxPG_PROP_DISABLED);
}
else
{
if ( p->m_flags & wxPG_PROP_DISABLED )
return false;
// Disabling
p->m_flags |= wxPG_PROP_DISABLED;
}
// Apply same to sub-properties as well
unsigned int i;
for ( i = 0; i < p->GetChildCount(); i++ )
DoEnableProperty( p->Item(i), enable );
return true;
}
return false;
}
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// wxPropertyGridPageState wxVariant related routines // wxPropertyGridPageState wxVariant related routines
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------