wxTreeCtrl::Delete() bug corrected, sample expanded to test it
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8a0a092b3c
commit
ff5bf2590f
@ -43,6 +43,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
|
||||
EVT_MENU(TreeTest_About, MyFrame::OnAbout)
|
||||
EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
|
||||
EVT_MENU(TreeTest_Delete, MyFrame::OnDelete)
|
||||
EVT_MENU(TreeTest_DeleteAll, MyFrame::OnDeleteAll)
|
||||
EVT_MENU(TreeTest_Recreate, MyFrame::OnRecreate)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
|
||||
@ -93,7 +96,10 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(TreeTest_Dump, "&Dump tree items");
|
||||
file_menu->Append(TreeTest_Dump, "D&ump tree items");
|
||||
file_menu->Append(TreeTest_Delete, "&Delete this item");
|
||||
file_menu->Append(TreeTest_DeleteAll, "Delete &all items");
|
||||
file_menu->Append(TreeTest_Recreate, "&Recreate the tree");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(TreeTest_About, "&About...");
|
||||
file_menu->AppendSeparator();
|
||||
@ -161,6 +167,23 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
|
||||
m_treeCtrl->GetItemsRecursively(root, -1);
|
||||
}
|
||||
|
||||
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxTreeItemId item = m_treeCtrl->GetSelection();
|
||||
m_treeCtrl->Delete(item);
|
||||
}
|
||||
|
||||
void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_treeCtrl->DeleteAllItems();
|
||||
}
|
||||
|
||||
void MyFrame::OnRecreate(wxCommandEvent& event)
|
||||
{
|
||||
OnDeleteAll(event);
|
||||
m_treeCtrl->AddTestItemsToTree(3, 2);
|
||||
}
|
||||
|
||||
// MyTreeCtrl implementation
|
||||
MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
|
@ -58,15 +58,15 @@ public:
|
||||
|
||||
void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
|
||||
|
||||
void AddTestItemsToTree(size_t numChildren,
|
||||
size_t depth);
|
||||
|
||||
private:
|
||||
void AddItemsRecursively(const wxTreeItemId& idParent,
|
||||
size_t nChildren,
|
||||
size_t depth,
|
||||
size_t folder);
|
||||
|
||||
void AddTestItemsToTree(size_t numChildren,
|
||||
size_t depth);
|
||||
|
||||
wxImageList *m_imageListNormal;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
@ -84,6 +84,9 @@ public:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnDump(wxCommandEvent& event);
|
||||
void OnDelete(wxCommandEvent& event);
|
||||
void OnDeleteAll(wxCommandEvent& event);
|
||||
void OnRecreate(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
MyTreeCtrl *m_treeCtrl;
|
||||
@ -97,6 +100,9 @@ enum
|
||||
TreeTest_Quit,
|
||||
TreeTest_About,
|
||||
TreeTest_Dump,
|
||||
TreeTest_Delete,
|
||||
TreeTest_DeleteAll,
|
||||
TreeTest_Recreate,
|
||||
TreeTest_Ctrl = 100
|
||||
};
|
||||
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
int image, int selImage,
|
||||
wxTreeItemData *data );
|
||||
|
||||
inline ~wxGenericTreeItem();
|
||||
~wxGenericTreeItem();
|
||||
|
||||
// trivial accessors
|
||||
wxArrayTreeItems& GetChildren() { return m_children; }
|
||||
@ -688,6 +688,12 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
|
||||
void wxTreeCtrl::Delete(const wxTreeItemId& itemId)
|
||||
{
|
||||
wxGenericTreeItem *item = itemId.m_pItem;
|
||||
wxGenericTreeItem *parent = item->GetParent();
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
parent->GetChildren().Remove(item);
|
||||
}
|
||||
|
||||
delete item;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user