From f915d44b3f310ceabfca6b0e66c6c81fd778f7b9 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Thu, 11 Dec 2008 17:11:35 +0000 Subject: [PATCH] Added wxPropertyGridInterface::RemoveProperty() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/propgridiface.h | 10 ++++++++ include/wx/propgrid/propgridpagestate.h | 2 +- interface/wx/propgrid/propgridiface.h | 10 ++++++++ samples/propgrid/tests.cpp | 17 ++++++++++++++ src/propgrid/propgridiface.cpp | 31 ++++++++++++++++++++++++- src/propgrid/propgridpagestate.cpp | 5 ++-- 6 files changed, 71 insertions(+), 4 deletions(-) diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index a2139e45e9..8d8c010f41 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -245,6 +245,16 @@ public: */ void DeleteProperty( wxPGPropArg id ); + /** + Removes and returns a property. + + @param id + Pointer or name of a property. + + @remarks Removed property cannot have any children. + */ + wxPGProperty* RemoveProperty( wxPGPropArg id ); + /** Disables property. */ bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); } diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index f895366389..65c45f2d29 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -421,7 +421,7 @@ public: Override this member function to add custom behavior on property deletion. */ - virtual void DoDelete( wxPGProperty* item ); + virtual void DoDelete( wxPGProperty* item, bool doDelete = true ); wxSize DoFitColumns( bool allowGridResize = false ); diff --git a/interface/wx/propgrid/propgridiface.h b/interface/wx/propgrid/propgridiface.h index 36f1bfc1a9..021954c63d 100644 --- a/interface/wx/propgrid/propgridiface.h +++ b/interface/wx/propgrid/propgridiface.h @@ -547,6 +547,16 @@ public: */ static void RegisterAdditionalEditors(); + /** + Removes and returns a property. + + @param id + Pointer or name of a property. + + @remarks Removed property cannot have any children. + */ + wxPGProperty* RemoveProperty( wxPGPropArg id ); + /** Replaces property with id with newly created one. For example, this code replaces existing property named "Flags" with one that diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index eb22e52437..1c066ca0d9 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -918,6 +918,23 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) pgman->EnsureVisible(wxT("Cell Colour")); } + { + RT_START_TEST(RemoveProperty) + + wxPGProperty* p; + + wxPGProperty* origParent = + pgman->GetProperty(wxT("Window Styles"))->GetParent(); + + p = pgman->RemoveProperty(wxT("Window Styles")); + pgman->Refresh(); + pgman->Update(); + + pgman->AppendIn(origParent, p); + pgman->Refresh(); + pgman->Update(); + } + { RT_START_TEST(SetPropertyBackgroundColour) wxCommandEvent evt; diff --git a/src/propgrid/propgridiface.cpp b/src/propgrid/propgridiface.cpp index 13b09fc78d..f762133260 100644 --- a/src/propgrid/propgridiface.cpp +++ b/src/propgrid/propgridiface.cpp @@ -317,13 +317,42 @@ void wxPropertyGridInterface::DeleteProperty( wxPGPropArg id ) if ( grid->GetState() == state ) grid->DoSelectProperty(NULL, wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE); - state->DoDelete( p ); + state->DoDelete( p, true ); RefreshGrid(state); } // ----------------------------------------------------------------------- +wxPGProperty* wxPropertyGridInterface::RemoveProperty( wxPGPropArg id ) +{ + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty) + + wxCHECK( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE), + wxNullProperty); + + wxPropertyGridPageState* state = p->GetParentState(); + wxPropertyGrid* grid = state->GetGrid(); + + if ( grid->GetState() == state ) + { + grid->DoSelectProperty(NULL, + wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE); + } + + state->DoDelete( p, false ); + + // Mark the property as 'unattached' + p->m_parentState = NULL; + p->m_parent = NULL; + + RefreshGrid(state); + + return p; +} + +// ----------------------------------------------------------------------- + wxPGProperty* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id, wxPGProperty* property ) { wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty) diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index aa5b0244f8..705baa516a 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1690,7 +1690,7 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index // ----------------------------------------------------------------------- -void wxPropertyGridPageState::DoDelete( wxPGProperty* item ) +void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) { wxCHECK_RET( item->GetParent(), wxT("this property was already deleted") ); @@ -1790,7 +1790,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item ) if ( item->GetBaseName().Len() ) m_dictName.erase(item->GetBaseName()); // We can actually delete it now - delete item; + if ( doDelete ) + delete item; m_itemsAdded = 1; // Not a logical assignment (but required nonetheless). -- 2.45.2