+ // We move in slightly so we are not on the edge
+ wxPoint point = m_tree->ClientToScreen(pos.GetPosition()) + wxPoint(4, 4);
+
+ sim.MouseMove(point);
+ wxYield();
+
+ sim.MouseDblClick();
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_TREE_ITEM_EXPANDING));
+ CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_TREE_ITEM_EXPANDED));
+
+ sim.MouseDblClick();
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_TREE_ITEM_COLLAPSING));
+ CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_TREE_ITEM_COLLAPSED));
+}
+
+void TreeCtrlTestCase::SelectionChange()
+{
+ wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
+ wxTestableFrame);
+
+ m_tree->ExpandAll();
+ m_tree->UnselectAll();
+
+ EventCounter count(m_tree, wxEVT_COMMAND_TREE_SEL_CHANGED);
+ EventCounter count1(m_tree, wxEVT_COMMAND_TREE_SEL_CHANGING);
+
+ wxUIActionSimulator sim;
+
+ wxRect poschild1, poschild2;
+ m_tree->GetBoundingRect(m_child1, poschild1, true);
+ m_tree->GetBoundingRect(m_child1, poschild2, true);
+
+ // We move in slightly so we are not on the edge
+ wxPoint point1 = m_tree->ClientToScreen(poschild1.GetPosition()) + wxPoint(4, 4);
+ wxPoint point2 = m_tree->ClientToScreen(poschild2.GetPosition()) + wxPoint(4, 4);
+
+ sim.MouseMove(point1);
+ wxYield();
+
+ sim.MouseClick();
+ wxYield();
+
+ sim.MouseMove(point2);
+ wxYield();
+
+ sim.MouseClick();
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(2, frame->GetEventCount(wxEVT_COMMAND_TREE_SEL_CHANGED));
+ CPPUNIT_ASSERT_EQUAL(2, frame->GetEventCount(wxEVT_COMMAND_TREE_SEL_CHANGING));
+}
+
+#endif // !__WXGTK__
+
+void TreeCtrlTestCase::Menu()
+{
+ wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
+ wxTestableFrame);
+
+ EventCounter count(m_tree, wxEVT_COMMAND_TREE_ITEM_MENU);
+ wxUIActionSimulator sim;
+
+ wxRect pos;
+ m_tree->GetBoundingRect(m_child1, pos, true);
+
+ // We move in slightly so we are not on the edge
+ wxPoint point = m_tree->ClientToScreen(pos.GetPosition()) + wxPoint(4, 4);
+
+ sim.MouseMove(point);
+ wxYield();
+
+ sim.MouseClick(wxMOUSE_BTN_RIGHT);
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_TREE_ITEM_MENU));
+}
+
+#endif // wxUSE_UIACTIONSIMULATOR
+
+void TreeCtrlTestCase::ItemData()
+{
+ wxTreeItemData* child1data = new wxTreeItemData();
+ wxTreeItemData* appenddata = new wxTreeItemData();
+ wxTreeItemData* insertdata = new wxTreeItemData();
+
+ m_tree->SetItemData(m_child1, child1data);
+
+ CPPUNIT_ASSERT_EQUAL(child1data, m_tree->GetItemData(m_child1));
+ CPPUNIT_ASSERT_EQUAL(m_child1, child1data->GetId());
+
+ wxTreeItemId append = m_tree->AppendItem(m_root, "new", -1, -1, appenddata);
+
+ CPPUNIT_ASSERT_EQUAL(appenddata, m_tree->GetItemData(append));
+ CPPUNIT_ASSERT_EQUAL(append, appenddata->GetId());
+
+ wxTreeItemId insert = m_tree->InsertItem(m_root, m_child1, "new", -1, -1,
+ insertdata);
+
+ CPPUNIT_ASSERT_EQUAL(insertdata, m_tree->GetItemData(insert));
+ CPPUNIT_ASSERT_EQUAL(insert, insertdata->GetId());
+}
+
+void TreeCtrlTestCase::Iteration()
+{
+ // Get first / next / last child
+ wxTreeItemIdValue cookie;
+ CPPUNIT_ASSERT_EQUAL(m_tree->GetFirstChild(m_root, cookie), m_child1);
+ CPPUNIT_ASSERT_EQUAL(m_tree->GetNextChild(m_root, cookie),
+ m_tree->GetLastChild(m_root));
+ CPPUNIT_ASSERT_EQUAL(m_child2, m_tree->GetLastChild(m_root));
+
+ // Get next / previous sibling
+ CPPUNIT_ASSERT_EQUAL(m_child2, m_tree->GetNextSibling(m_child1));
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetPrevSibling(m_child2));
+}
+
+void TreeCtrlTestCase::Parent()
+{
+ CPPUNIT_ASSERT_EQUAL(m_root, m_tree->GetRootItem());
+ CPPUNIT_ASSERT_EQUAL(m_root, m_tree->GetItemParent(m_child1));
+ CPPUNIT_ASSERT_EQUAL(m_root, m_tree->GetItemParent(m_child2));
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetItemParent(m_grandchild));
+}
+
+void TreeCtrlTestCase::CollapseExpand()
+{
+ m_tree->ExpandAll();
+
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_root));
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_child1));
+
+ m_tree->CollapseAll();
+
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_root));
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_child1));
+
+ m_tree->ExpandAllChildren(m_root);
+
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_root));
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_child1));
+
+ m_tree->CollapseAllChildren(m_child1);
+
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_child1));
+
+ m_tree->Expand(m_child1);
+
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_child1));
+
+ m_tree->Collapse(m_root);
+
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_root));
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_child1));
+
+ m_tree->CollapseAndReset(m_root);
+
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_root));
+}
+
+void TreeCtrlTestCase::AssignImageList()
+{
+ wxSize size(16, 16);
+
+ wxImageList *imagelist = new wxImageList(size.x, size.y);
+ imagelist->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
+
+ wxImageList *statelist = new wxImageList(size.x, size.y);
+ statelist->Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, size));
+
+ m_tree->AssignImageList(imagelist);
+ m_tree->AssignStateImageList(statelist);
+
+ CPPUNIT_ASSERT_EQUAL(imagelist, m_tree->GetImageList());
+ CPPUNIT_ASSERT_EQUAL(statelist, m_tree->GetStateImageList());
+}
+
+void TreeCtrlTestCase::Focus()
+{
+#if !defined(__WXGTK__) && !defined(__WXOSX__)
+ m_tree->SetFocusedItem(m_child1);
+
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetFocusedItem());
+
+ m_tree->ClearFocusedItem();
+
+ CPPUNIT_ASSERT(!m_tree->GetFocusedItem());
+#endif
+}
+
+void TreeCtrlTestCase::Bold()
+{
+ CPPUNIT_ASSERT(!m_tree->IsBold(m_child1));
+
+ m_tree->SetItemBold(m_child1);
+
+ CPPUNIT_ASSERT(m_tree->IsBold(m_child1));
+
+ m_tree->SetItemBold(m_child1, false);
+
+ CPPUNIT_ASSERT(!m_tree->IsBold(m_child1));
+}
+
+void TreeCtrlTestCase::Visible()
+{
+ m_tree->CollapseAll();
+
+ CPPUNIT_ASSERT(m_tree->IsVisible(m_root));
+ CPPUNIT_ASSERT(!m_tree->IsVisible(m_child1));
+
+ m_tree->EnsureVisible(m_grandchild);
+
+ CPPUNIT_ASSERT(m_tree->IsVisible(m_grandchild));
+
+ m_tree->ExpandAll();
+
+ CPPUNIT_ASSERT_EQUAL(m_root, m_tree->GetFirstVisibleItem());
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetNextVisible(m_root));
+ CPPUNIT_ASSERT_EQUAL(m_grandchild, m_tree->GetNextVisible(m_child1));
+ CPPUNIT_ASSERT_EQUAL(m_child2, m_tree->GetNextVisible(m_grandchild));
+
+ CPPUNIT_ASSERT(!m_tree->GetNextVisible(m_child2));
+ CPPUNIT_ASSERT(!m_tree->GetPrevVisible(m_root));
+}
+
+void TreeCtrlTestCase::Sort()
+{
+ wxTreeItemId zitem = m_tree->AppendItem(m_root, "zzzz");
+ wxTreeItemId aitem = m_tree->AppendItem(m_root, "aaaa");
+
+ m_tree->SortChildren(m_root);
+
+ wxTreeItemIdValue cookie;
+
+ CPPUNIT_ASSERT_EQUAL(aitem, m_tree->GetFirstChild(m_root, cookie));
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetNextChild(m_root, cookie));
+ CPPUNIT_ASSERT_EQUAL(m_child2, m_tree->GetNextChild(m_root, cookie));
+ CPPUNIT_ASSERT_EQUAL(zitem, m_tree->GetNextChild(m_root, cookie));
+}
+
+void TreeCtrlTestCase::KeyNavigation()
+{
+#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
+ wxUIActionSimulator sim;
+
+ m_tree->CollapseAll();
+
+ m_tree->SelectItem(m_root);
+
+ m_tree->SetFocus();
+ sim.Char(WXK_RIGHT);
+ wxYield();
+
+ CPPUNIT_ASSERT(m_tree->IsExpanded(m_root));
+
+ sim.Char(WXK_LEFT);
+ wxYield();
+
+ CPPUNIT_ASSERT(!m_tree->IsExpanded(m_root));
+
+ sim.Char(WXK_RIGHT);
+ sim.Char(WXK_DOWN);
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(m_child1, m_tree->GetSelection());
+
+ sim.Char(WXK_DOWN);
+ wxYield();
+
+ CPPUNIT_ASSERT_EQUAL(m_child2, m_tree->GetSelection());
+#endif