diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index 282b7cd964..2c99923b80 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -459,6 +459,11 @@ public: // insert cell at the end of m_Cells list void InsertCell(wxHtmlCell *cell); + // Detach a child cell. After calling this method, it's the caller + // responsibility to destroy this cell (possibly by calling InsertCell() + // with it to attach it elsewhere). + void Detach(wxHtmlCell *cell); + // sets horizontal/vertical alignment void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;} int GetAlignHor() const {return m_AlignHor;} diff --git a/interface/wx/html/htmlcell.h b/interface/wx/html/htmlcell.h index 406a37b709..fe17b29ddd 100644 --- a/interface/wx/html/htmlcell.h +++ b/interface/wx/html/htmlcell.h @@ -473,6 +473,20 @@ public: */ wxHtmlContainerCell(wxHtmlContainerCell* parent); + /** + Detach a child cell. + + Detaching a cell removes it from this container and allows to reattach + it to another one by using InsertCell(). Alternatively, this method can + be used to selectively remove some elements of the HTML document tree + by deleting the cell after calling it. + + @param cell Must be non-null and an immediate child of this cell. + + @since 3.1.2 + */ + void Detach(wxHtmlCell* cell); + /** Returns container's horizontal alignment. */ diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index e4392edc35..1768178b65 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -1159,6 +1159,43 @@ void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) +void wxHtmlContainerCell::Detach(wxHtmlCell *cell) +{ + wxHtmlCell* const firstChild = GetFirstChild(); + if ( cell == firstChild ) + { + m_Cells = cell->GetNext(); + if ( m_LastCell == cell ) + m_LastCell = NULL; + } + else // Not the first child. + { + for ( wxHtmlCell* prev = firstChild;; ) + { + wxHtmlCell* const next = prev->GetNext(); + + // We can't reach the end of the children list without finding this + // cell, normally. + wxCHECK_RET( next, "Detaching cell which is not our child" ); + + if ( cell == next ) + { + prev->SetNext(cell->GetNext()); + if ( m_LastCell == cell ) + m_LastCell = prev; + break; + } + + prev = next; + } + } + + cell->SetParent(NULL); + cell->SetNext(NULL); +} + + + void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) { wxString alg; diff --git a/tests/html/htmlparser.cpp b/tests/html/htmlparser.cpp index 4577b5baf0..61042a4616 100644 --- a/tests/html/htmlparser.cpp +++ b/tests/html/htmlparser.cpp @@ -46,4 +46,64 @@ TEST_CASE("wxHtmlParser::ParseInvalid", "[html][parser][error]") p.Parse("