1. added wxTreeCtrl::DeleteChildren()
2. wxTreeCtrl::CollapseAndReset() doesn't destroy the item itself any more 3. wxTreeCtrl::Delete() sends wxEVT_COMMAND_TREE_CHILDREN event (but DeleteChildren() and DeleteAll() do not!) 4. Sample modified to show the new function too 5. Micro redraw bug fixed (small vertical line was sometimes drawn when it shouldn't have been) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1224 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -81,6 +81,7 @@ public:
|
||||
wxGenericTreeItem *GetParent() const { return m_parent; }
|
||||
|
||||
// operations
|
||||
void DeleteChildren();
|
||||
void Reset();
|
||||
|
||||
// get count of all children (and grand children if 'recursively')
|
||||
@@ -182,9 +183,16 @@ wxGenericTreeItem::~wxGenericTreeItem()
|
||||
{
|
||||
delete m_data;
|
||||
|
||||
DeleteChildren();
|
||||
}
|
||||
|
||||
void wxGenericTreeItem::DeleteChildren()
|
||||
{
|
||||
size_t count = m_children.Count();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
delete m_children[n];
|
||||
|
||||
m_children.Empty();
|
||||
}
|
||||
|
||||
void wxGenericTreeItem::SetText( const wxString &text, wxDC& dc )
|
||||
@@ -207,7 +215,7 @@ void wxGenericTreeItem::Reset()
|
||||
|
||||
m_level = 0;
|
||||
|
||||
m_children.Empty();
|
||||
DeleteChildren();
|
||||
m_isCollapsed = TRUE;
|
||||
|
||||
m_parent = (wxGenericTreeItem *)NULL;
|
||||
@@ -690,11 +698,25 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
|
||||
image, selImage, data);
|
||||
}
|
||||
|
||||
void wxTreeCtrl::DeleteChildren(const wxTreeItemId& itemId)
|
||||
{
|
||||
wxGenericTreeItem *item = itemId.m_pItem;
|
||||
item->DeleteChildren();
|
||||
|
||||
m_dirty = TRUE;
|
||||
}
|
||||
|
||||
void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
|
||||
{
|
||||
wxGenericTreeItem *item = itemId.m_pItem;
|
||||
wxGenericTreeItem *parent = item->GetParent();
|
||||
|
||||
// notify the parent...
|
||||
wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
|
||||
event.m_item = item;
|
||||
event.SetEventObject( this );
|
||||
ProcessEvent( event );
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
parent->GetChildren().Remove(item);
|
||||
@@ -779,7 +801,7 @@ void wxTreeCtrl::Collapse(const wxTreeItemId& itemId)
|
||||
void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item)
|
||||
{
|
||||
Collapse(item);
|
||||
Delete(item);
|
||||
DeleteChildren(item);
|
||||
}
|
||||
|
||||
void wxTreeCtrl::Toggle(const wxTreeItemId& itemId)
|
||||
@@ -1061,22 +1083,26 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &
|
||||
}
|
||||
}
|
||||
|
||||
if ( !item->IsExpanded() )
|
||||
return;
|
||||
|
||||
int semiOldY = y;
|
||||
|
||||
wxArrayTreeItems& children = item->GetChildren();
|
||||
size_t count = children.Count();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
if ( item->IsExpanded() )
|
||||
{
|
||||
y += m_lineHeight;
|
||||
semiOldY = y;
|
||||
int semiOldY = y;
|
||||
|
||||
PaintLevel( children[n], dc, level+1, y );
|
||||
wxArrayTreeItems& children = item->GetChildren();
|
||||
size_t count = children.Count();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
y += m_lineHeight;
|
||||
semiOldY = y;
|
||||
|
||||
PaintLevel( children[n], dc, level+1, y );
|
||||
}
|
||||
|
||||
// it may happen that the item is expanded but has no items (when you
|
||||
// delete all its children for example) - don't draw the vertical line
|
||||
// in this case
|
||||
if ( count > 0 )
|
||||
dc.DrawLine( horizX+15, oldY+5, horizX+15, semiOldY );
|
||||
}
|
||||
|
||||
dc.DrawLine( horizX+15, oldY+5, horizX+15, semiOldY );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user