From: Jaakko Salli Date: Sun, 8 Aug 2010 11:41:20 +0000 (+0000) Subject: Added wxPGProperty::Enable() for conveniency. Refactored related code and improved... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9ceed261f809dacf8f64c2287c5de9e45d22e5cb 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 --- diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 14eca1252b..dc1f2c2426 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -1523,6 +1523,17 @@ public: */ 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 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. void RemoveChild( wxPGProperty* p ); + void DoEnable( bool enable ); + void DoPreAddChild( int index, wxPGProperty* prop ); void SetParentState( wxPropertyGridPageState* pstate ) diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 839ade4774..8aa26d070e 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -267,7 +267,11 @@ public: */ wxPGProperty* RemoveProperty( wxPGPropArg id ); - /** Disables property. */ + /** + Disables a property. + + @see EnableProperty(), wxPGProperty::Enable() + */ bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); } /** @@ -280,7 +284,14 @@ public: /** 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 ); diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index faf12fdce8..3f72dc92d4 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -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. */ unsigned int GetVirtualHeight() const diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index 0e314680f1..23102687cb 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -1161,6 +1161,17 @@ public: /** Deletes all child properties. */ 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. */ diff --git a/interface/wx/propgrid/propgridiface.h b/interface/wx/propgrid/propgridiface.h index 7309f907fd..bdf9576171 100644 --- a/interface/wx/propgrid/propgridiface.h +++ b/interface/wx/propgrid/propgridiface.h @@ -153,6 +153,8 @@ public: /** Disables a property. + + @see EnableProperty(), wxPGProperty::Enable() */ bool DisableProperty( wxPGPropArg id ); @@ -164,12 +166,15 @@ public: bool EditorValidate(); /** - Enables or disables property. + Enables or disables property. 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 ); diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 333a27d0c8..e759aa5d72 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -1492,6 +1492,31 @@ wxVariant wxPGProperty::GetDefaultValue() const 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 ) { if ( column >= m_cells.size() ) diff --git a/src/propgrid/propgridiface.cpp b/src/propgrid/propgridiface.cpp index 66dcd9e67c..f8aab46507 100644 --- a/src/propgrid/propgridiface.cpp +++ b/src/propgrid/propgridiface.cpp @@ -277,7 +277,7 @@ bool wxPropertyGridInterface::EnableProperty( wxPGPropArg id, bool enable ) grid->DoSelectProperty( p, wxPG_SEL_FORCE ); } - state->DoEnableProperty(p, enable); + p->DoEnable(enable); RefreshProperty( p ); diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 74b1adbe1f..1ae7c025d2 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1398,42 +1398,6 @@ bool wxPropertyGridPageState::DoHideProperty( wxPGProperty* p, bool hide, int fl 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 // -----------------------------------------------------------------------