From ed8b46bba32c76a5544e6043a0a6de21eda5a712 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 10 Oct 2010 09:34:29 +0000 Subject: [PATCH] When wxPGProperty is un-attached from wxPropertyGrid, keep its 'default' cell references invalid/NULL (fixes #12552) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/property.h | 12 +++++++ samples/propgrid/tests.cpp | 8 +++-- src/propgrid/property.cpp | 55 ++++++++++++++++++++++++++---- src/propgrid/propgridpagestate.cpp | 2 ++ 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 53308458e5..f72e352e8f 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -306,6 +306,13 @@ public: return *this; } + // Used mostly internally to figure out if this cell is supposed + // to have default values when attached to a grid. + bool IsInvalid() const + { + return ( m_refData == NULL ); + } + private: virtual wxObjectRefData *CreateRefData() const { return new wxPGCellData(); } @@ -2395,6 +2402,11 @@ protected: void ClearFlag( FlagType flag ) { m_flags &= ~(flag); } + // Called when the property is being removed from the grid and/or + // page state (but *not* when it is also deleted). + void OnDetached(wxPropertyGridPageState* state, + wxPropertyGrid* propgrid); + // 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/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index 1b86cff7bc..5d62dbfe81 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -1030,13 +1030,17 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) wxPGProperty* p; wxPGProperty* origParent = - pgman->GetProperty(wxT("Window Styles"))->GetParent(); + pgman->GetProperty("Window Styles")->GetParent(); - p = pgman->RemoveProperty(wxT("Window Styles")); + // For testing purposes, let's set some custom cell colours + p = pgman->GetProperty("Window Styles"); + p->SetCell(2, wxPGCell("style")); + p = pgman->RemoveProperty("Window Styles"); pgman->Refresh(); pgman->Update(); pgman->AppendIn(origParent, p); + wxASSERT( p->GetCell(2).GetText() == "style"); pgman->Refresh(); pgman->Update(); } diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index e759aa5d72..37edd533d9 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -499,6 +499,23 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState, wxPGProperty* parent = m_parent; bool parentIsRoot = parent->IsKindOf(CLASSINFO(wxPGRootProperty)); + // + // Convert invalid cells to default ones in this grid + for ( unsigned int i=0; iGetPropertyDefaultCell(); + const wxPGCell& catDefCell = propgrid->GetCategoryDefaultCell(); + + if ( !HasFlag(wxPG_PROP_CATEGORY) ) + cell = propDefCell; + else + cell = catDefCell; + } + } + m_parentState = pageState; #if wxPG_COMPATIBILITY_1_4 @@ -621,6 +638,27 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState, } } +void wxPGProperty::OnDetached(wxPropertyGridPageState* WXUNUSED(state), + wxPropertyGrid* propgrid) +{ + if ( propgrid ) + { + const wxPGCell& propDefCell = propgrid->GetPropertyDefaultCell(); + const wxPGCell& catDefCell = propgrid->GetCategoryDefaultCell(); + + // Make default cells invalid + for ( unsigned int i=0; iGetPropertyDefaultCell(); - const wxPGCell& catDefCell = pg->GetCategoryDefaultCell(); + if ( pg ) + { + // Work around possible VC6 bug by using intermediate variables + const wxPGCell& propDefCell = pg->GetPropertyDefaultCell(); + const wxPGCell& catDefCell = pg->GetCategoryDefaultCell(); - if ( !HasFlag(wxPG_PROP_CATEGORY) ) - defaultCell = propDefCell; - else - defaultCell = catDefCell; + if ( !HasFlag(wxPG_PROP_CATEGORY) ) + defaultCell = propDefCell; + else + defaultCell = catDefCell; + } // TODO: Replace with resize() call unsigned int cellCountMax = column+1; diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 1ae7c025d2..8ec1e3a1a5 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1934,6 +1934,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) // We can actually delete it now if ( doDelete ) delete item; + else + item->OnDetached(this, pg); m_itemsAdded = 1; // Not a logical assignment (but required nonetheless). -- 2.45.2