Fix deleting and clearing wxTreeListCtrl columns.
The model columns were not updated before, resulting in a mismatch between view and model columns if ClearColumns() followed by AppendColumn() was called. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68966 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
35219832c9
commit
2bad2b6d60
@ -160,6 +160,37 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void OnDeleteColumn(unsigned col, unsigned numColumns)
|
||||
{
|
||||
wxASSERT_MSG( col, "Shouldn't be called for the first column" );
|
||||
|
||||
if ( !m_columnsTexts )
|
||||
return;
|
||||
|
||||
wxScopedArray<wxString> oldTexts(m_columnsTexts);
|
||||
m_columnsTexts = new wxString[numColumns - 2];
|
||||
for ( unsigned n = 1, m = 1; n < numColumns - 1; n++, m++ )
|
||||
{
|
||||
if ( n == col )
|
||||
{
|
||||
n--;
|
||||
}
|
||||
else // Not the deleted column.
|
||||
{
|
||||
m_columnsTexts[n - 1] = oldTexts[m - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnClearColumns()
|
||||
{
|
||||
if ( m_columnsTexts )
|
||||
{
|
||||
delete [] m_columnsTexts;
|
||||
m_columnsTexts = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Functions for modifying the tree.
|
||||
|
||||
@ -306,6 +337,8 @@ public:
|
||||
|
||||
// Methods called by wxTreeListCtrl.
|
||||
void InsertColumn(unsigned col);
|
||||
void DeleteColumn(unsigned col);
|
||||
void ClearColumns();
|
||||
|
||||
Node* InsertItem(Node* parent,
|
||||
Node* previous,
|
||||
@ -583,6 +616,32 @@ void wxTreeListModel::InsertColumn(unsigned col)
|
||||
}
|
||||
}
|
||||
|
||||
void wxTreeListModel::DeleteColumn(unsigned col)
|
||||
{
|
||||
wxCHECK_RET( col < m_numColumns, "Invalid column index" );
|
||||
|
||||
// Update all the items to remove the text for the non first columns.
|
||||
if ( col > 0 )
|
||||
{
|
||||
for ( Node* node = m_root->GetChild(); node; node = node->NextInTree() )
|
||||
{
|
||||
node->OnDeleteColumn(col, m_numColumns);
|
||||
}
|
||||
}
|
||||
|
||||
m_numColumns--;
|
||||
}
|
||||
|
||||
void wxTreeListModel::ClearColumns()
|
||||
{
|
||||
m_numColumns = 0;
|
||||
|
||||
for ( Node* node = m_root->GetChild(); node; node = node->NextInTree() )
|
||||
{
|
||||
node->OnClearColumns();
|
||||
}
|
||||
}
|
||||
|
||||
wxTreeListModelNode*
|
||||
wxTreeListModel::InsertItem(Node* parent,
|
||||
Node* previous,
|
||||
@ -1026,13 +1085,24 @@ bool wxTreeListCtrl::DeleteColumn(unsigned col)
|
||||
{
|
||||
wxCHECK_MSG( col < GetColumnCount(), false, "Invalid column index" );
|
||||
|
||||
return m_view->DeleteColumn(m_view->GetColumn(col));
|
||||
if ( !m_view->DeleteColumn(m_view->GetColumn(col)) )
|
||||
return false;
|
||||
|
||||
m_model->DeleteColumn(col);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxTreeListCtrl::ClearColumns()
|
||||
{
|
||||
if ( m_view )
|
||||
m_view->ClearColumns();
|
||||
// Don't assert here, clearing columns of the control before it's created
|
||||
// can be considered valid (just useless).
|
||||
if ( !m_model )
|
||||
return;
|
||||
|
||||
m_view->ClearColumns();
|
||||
|
||||
m_model->ClearColumns();
|
||||
}
|
||||
|
||||
void wxTreeListCtrl::SetColumnWidth(unsigned col, int width)
|
||||
|
Loading…
Reference in New Issue
Block a user