From 6c78066f22deac771842e2e784772415486329e1 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 8 Aug 2010 12:22:08 +0000 Subject: [PATCH] Moved wxPGProperty::SetFlag() to protected API since it does not have any side-effects that are usually desired in the user code. Added wxPGProperty::SetAutoUnspecified() since wxPG_PROP_AUTO_UNSPECIFIED can no longer be set (conveniently) with SetFlag(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65218 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/doxygen/overviews/propgrid.h | 5 +++ include/wx/propgrid/property.h | 56 ++++++++++++++++++++----------- interface/wx/propgrid/property.h | 35 +++++++++++++------ samples/propgrid/propgrid.cpp | 2 +- samples/propgrid/tests.cpp | 2 +- src/propgrid/props.cpp | 4 +-- 6 files changed, 70 insertions(+), 34 deletions(-) diff --git a/docs/doxygen/overviews/propgrid.h b/docs/doxygen/overviews/propgrid.h index 85aee250fe..13cf435332 100644 --- a/docs/doxygen/overviews/propgrid.h +++ b/docs/doxygen/overviews/propgrid.h @@ -1015,6 +1015,11 @@ without warnings or errors. - wxPropertyGrid::CanClose() has been removed. Call wxPropertyGridInterface::EditorValidate() instead. + - wxPGProperty::SetFlag() has been moved to private API. This was done to + underline the fact that it was not the preferred method to change a + property's state since it never had any desired side-effects. ChangeFlag() + still exists for those who really need to achieve the same effect. + @subsection propgrid_compat_propdev Property and Editor Sub-classing Changes - Confusing custom property macros have been eliminated. diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index dc1f2c2426..da6e966f7b 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -473,6 +473,8 @@ wxPG_PROP_USES_COMMON_VALUE = 0x00020000, @remarks This flag cannot be used with property iterators. + + @see wxPGProperty::SetAutoUnspecified() */ wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000, @@ -1908,6 +1910,21 @@ public: void SetAttributes( const wxPGAttributeStorage& attributes ); + /** + Set if user can change the property's value to unspecified by + modifying the value of the editor control (usually by clearing + it). Currently, this can work with following properties: + wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty. + + @param enable + Whether to enable or disable this behavior (it is disabled by + default). + */ + void SetAutoUnspecified( bool enable = true ) + { + ChangeFlag(wxPG_PROP_AUTO_UNSPECIFIED, enable); + } + /** Sets property's background colour. @@ -2039,23 +2056,14 @@ public: } /** - Sets given property flag. + Sets or clears given property flag. Mainly for internal use. - @see propgrid_propflags - */ - void SetFlag( wxPGPropertyFlags flag ) - { - // - // NB: While using wxPGPropertyFlags here makes it difficult to - // combine different flags, it usefully prevents user from - // using incorrect flags (say, wxWindow styles). - m_flags |= flag; - } + @remarks Setting a property flag never has any side-effect, and is + intended almost exclusively for internal use. So, for + example, if you want to disable a property, call + Enable(false) instead of setting wxPG_PROP_DISABLED flag. - /** - Sets or clears given property flag. - - @see propgrid_propflags + @see HasFlag(), GetFlags() */ void ChangeFlag( wxPGPropertyFlags flag, bool set ) { @@ -2066,9 +2074,10 @@ public: } /** - Sets or clears given property flag, recursively. + Sets or clears given property flag, recursively. This function is + primarily intended for internal use. - @see propgrid_propflags + @see ChangeFlag() */ void SetFlagRecursively( wxPGPropertyFlags flag, bool set ); @@ -2181,8 +2190,6 @@ public: return m_helpString; } - void ClearFlag( FlagType flag ) { m_flags &= ~(flag); } - // Use, for example, to detect if item is inside collapsed section. bool IsSomeParent( wxPGProperty* candidate_parent ) const; @@ -2375,6 +2382,17 @@ protected: void SetParentState( wxPropertyGridPageState* pstate ) { m_parentState = pstate; } + void SetFlag( wxPGPropertyFlags flag ) + { + // + // NB: While using wxPGPropertyFlags here makes it difficult to + // combine different flags, it usefully prevents user from + // using incorrect flags (say, wxWindow styles). + m_flags |= flag; + } + + void ClearFlag( FlagType flag ) { m_flags &= ~(flag); } + // Call after fixed sub-properties added/removed after creation. // if oldSelInd >= 0 and < new max items, then selection is // moved to it. diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index 23102687cb..d234e78fbb 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -287,6 +287,8 @@ wxPG_PROP_USES_COMMON_VALUE = 0x00020000, @remarks This flag cannot be used with property iterators. + + @see wxPGProperty::SetAutoUnspecified() */ wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000, @@ -1140,9 +1142,14 @@ public: bool AreChildrenComponents() const; /** - Sets or clears given property flag. + Sets or clears given property flag. Mainly for internal use. - @see propgrid_propflags + @remarks Setting a property flag never has any side-effect, and is + intended almost exclusively for internal use. So, for + example, if you want to disable a property, call + Enable(false) instead of setting wxPG_PROP_DISABLED flag. + + @see HasFlag(), GetFlags() */ void ChangeFlag( wxPGPropertyFlags flag, bool set ); @@ -1510,6 +1517,18 @@ public: */ void SetAttribute( const wxString& name, wxVariant value ); + /** + Set if user can change the property's value to unspecified by + modifying the value of the editor control (usually by clearing + it). Currently, this can work with following properties: + wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty. + + @param enable + Whether to enable or disable this behavior (it is disabled by + default). + */ + void SetAutoUnspecified( bool enable = true ); + /** Sets property's background colour. @@ -1581,16 +1600,10 @@ public: void SetDefaultValue( wxVariant& value ); /** - Sets given property flag. + Sets or clears given property flag, recursively. This function is + primarily intended for internal use. - @see propgrid_propflags - */ - void SetFlag( wxPGPropertyFlags flag ); - - /** - Sets or clears given property flag, recursively. - - @see propgrid_propflags + @see ChangeFlag() */ void SetFlagRecursively( wxPGPropertyFlags flag, bool set ); diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 5deb693160..b81ea3cc3e 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -1516,7 +1516,7 @@ void FormMain::PopulateWithExamples () pid = pg->Append( new wxColourProperty(wxT("ColourProperty"),wxPG_LABEL,*wxRED) ); //pg->SetPropertyAttribute(pid,wxPG_COLOUR_ALLOW_CUSTOM,false); pg->SetPropertyEditor( wxT("ColourProperty"), wxPGEditor_ComboBox ); - pg->GetProperty(wxT("ColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED); + pg->GetProperty(wxT("ColourProperty"))->SetAutoUnspecified(true); pg->SetPropertyHelpString( wxT("ColourProperty"), wxT("wxPropertyGrid::SetPropertyEditor method has been used to change ") wxT("editor of this property to wxPGEditor_ComboBox)")); diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index 714f4d4e67..7d04a32313 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -106,7 +106,7 @@ public: void FormMain::AddTestProperties( wxPropertyGridPage* pg ) { pg->Append( new MyColourProperty(wxT("CustomColourProperty"), wxPG_LABEL, *wxGREEN) ); - pg->GetProperty(wxT("CustomColourProperty"))->SetFlag(wxPG_PROP_AUTO_UNSPECIFIED); + pg->GetProperty(wxT("CustomColourProperty"))->SetAutoUnspecified(true); pg->SetPropertyEditor( wxT("CustomColourProperty"), wxPGEditor_ComboBox ); pg->SetPropertyHelpString(wxT("CustomColourProperty"), diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 755a79f1a3..9a4c874374 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -1343,7 +1343,7 @@ void wxFlagsProperty::OnSetValue() flag = choices.GetValue(i); if ( (newFlags & flag) != (m_oldValue & flag) ) - Item(i)->SetFlag( wxPG_PROP_MODIFIED ); + Item(i)->ChangeFlag( wxPG_PROP_MODIFIED, true ); } m_oldValue = newFlags; @@ -1451,7 +1451,7 @@ void wxFlagsProperty::RefreshChildren() wxPGProperty* p = Item(i); if ( subVal != (m_oldValue & flag) ) - p->SetFlag( wxPG_PROP_MODIFIED ); + p->ChangeFlag( wxPG_PROP_MODIFIED, true ); p->SetValue( subVal?true:false ); }