From: Vadim Zeitlin Date: Sat, 17 Jan 2009 13:16:25 +0000 (+0000) Subject: implement wxTreeCtrl::ItemHasChildren() properly for virtual root item; added unit... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fa97ee2490d920eaf1e2ad7a719a7797222e2c5b implement wxTreeCtrl::ItemHasChildren() properly for virtual root item; added unit test for it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58177 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 7aa4079cf6..d358be2f32 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1213,6 +1213,12 @@ bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const { wxCHECK_MSG( item.IsOk(), false, wxT("invalid tree item") ); + if ( IS_VIRTUAL_ROOT(item) ) + { + wxTreeItemIdValue cookie; + return GetFirstChild(item, cookie).IsOk(); + } + wxTreeViewItem tvItem(item, TVIF_CHILDREN); DoGetItem(&tvItem); diff --git a/tests/Makefile.in b/tests/Makefile.in index fa91752321..bf0ba869ec 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -130,6 +130,7 @@ TEST_GUI_OBJECTS = \ test_gui_listctrltest.o \ test_gui_textctrltest.o \ test_gui_textentrytest.o \ + test_gui_treectrltest.o \ test_gui_propagation.o \ test_gui_rawbmp.o \ test_gui_htmlwindow.o \ @@ -566,6 +567,9 @@ test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP) test_gui_textentrytest.o: $(srcdir)/controls/textentrytest.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textentrytest.cpp +test_gui_treectrltest.o: $(srcdir)/controls/treectrltest.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/treectrltest.cpp + test_gui_propagation.o: $(srcdir)/events/propagation.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/events/propagation.cpp diff --git a/tests/controls/treectrltest.cpp b/tests/controls/treectrltest.cpp new file mode 100644 index 0000000000..4d0bee2c50 --- /dev/null +++ b/tests/controls/treectrltest.cpp @@ -0,0 +1,96 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/controls/treectrltest.cpp +// Purpose: wxTreeCtrl unit test +// Author: Vadim Zeitlin +// Created: 2008-11-26 +// RCS-ID: $Id$ +// Copyright: (c) 2008 Vadim Zeitlin +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif // WX_PRECOMP + +#include "wx/treectrl.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class TreeCtrlTestCase : public CppUnit::TestCase +{ +public: + TreeCtrlTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE( TreeCtrlTestCase ); + CPPUNIT_TEST( HasChildren ); + CPPUNIT_TEST( PseudoTest_SetHiddenRoot ); + CPPUNIT_TEST( HasChildren ); + CPPUNIT_TEST_SUITE_END(); + + void HasChildren(); + void PseudoTest_SetHiddenRoot() { ms_hiddenRoot = true; } + + static bool ms_hiddenRoot; + + wxTreeCtrl *m_tree; + + DECLARE_NO_COPY_CLASS(TreeCtrlTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( TreeCtrlTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreeCtrlTestCase, "TreeCtrlTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +bool TreeCtrlTestCase::ms_hiddenRoot = false; + +void TreeCtrlTestCase::setUp() +{ + m_tree = new wxTreeCtrl(wxTheApp->GetTopWindow()); + if ( ms_hiddenRoot ) + m_tree->ToggleWindowStyle(wxTR_HIDE_ROOT); // actually set it +} + +void TreeCtrlTestCase::tearDown() +{ + delete m_tree; + m_tree = NULL; +} + +// ---------------------------------------------------------------------------- +// the tests themselves +// ---------------------------------------------------------------------------- + +void TreeCtrlTestCase::HasChildren() +{ + const wxTreeItemId root = m_tree->AddRoot("root"); + const wxTreeItemId child1 = m_tree->AppendItem(root, "child1"); + const wxTreeItemId child2 = m_tree->AppendItem(root, "child2"); + const wxTreeItemId grandchild = m_tree->AppendItem(child1, "grandchild"); + + CPPUNIT_ASSERT( m_tree->HasChildren(root) ); + CPPUNIT_ASSERT( m_tree->HasChildren(child1) ); + CPPUNIT_ASSERT( !m_tree->HasChildren(child2) ); + CPPUNIT_ASSERT( !m_tree->HasChildren(grandchild) ); +} + diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 57b50ecb1b..9271298a01 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -115,6 +115,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_listctrltest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ + $(OBJS)\test_gui_treectrltest.obj \ $(OBJS)\test_gui_propagation.obj \ $(OBJS)\test_gui_rawbmp.obj \ $(OBJS)\test_gui_htmlwindow.obj \ @@ -606,6 +607,9 @@ $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp $(OBJS)\test_gui_textentrytest.obj: .\controls\textentrytest.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textentrytest.cpp +$(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp + $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 5d5018057a..db755e8a1c 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -108,6 +108,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_listctrltest.o \ $(OBJS)\test_gui_textctrltest.o \ $(OBJS)\test_gui_textentrytest.o \ + $(OBJS)\test_gui_treectrltest.o \ $(OBJS)\test_gui_propagation.o \ $(OBJS)\test_gui_rawbmp.o \ $(OBJS)\test_gui_htmlwindow.o \ @@ -586,6 +587,9 @@ $(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp $(OBJS)\test_gui_textentrytest.o: ./controls/textentrytest.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_treectrltest.o: ./controls/treectrltest.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_propagation.o: ./events/propagation.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 4370ab158c..ae369520e3 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -111,6 +111,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_listctrltest.obj \ $(OBJS)\test_gui_textctrltest.obj \ $(OBJS)\test_gui_textentrytest.obj \ + $(OBJS)\test_gui_treectrltest.obj \ $(OBJS)\test_gui_propagation.obj \ $(OBJS)\test_gui_rawbmp.obj \ $(OBJS)\test_gui_htmlwindow.obj \ @@ -691,6 +692,9 @@ $(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp $(OBJS)\test_gui_textentrytest.obj: .\controls\textentrytest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textentrytest.cpp +$(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\treectrltest.cpp + $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 59c74ef3d1..195a2072d9 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -342,6 +342,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_listctrltest.obj & $(OBJS)\test_gui_textctrltest.obj & $(OBJS)\test_gui_textentrytest.obj & + $(OBJS)\test_gui_treectrltest.obj & $(OBJS)\test_gui_propagation.obj & $(OBJS)\test_gui_rawbmp.obj & $(OBJS)\test_gui_htmlwindow.obj & @@ -643,6 +644,9 @@ $(OBJS)\test_gui_textctrltest.obj : .AUTODEPEND .\controls\textctrltest.cpp $(OBJS)\test_gui_textentrytest.obj : .AUTODEPEND .\controls\textentrytest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_treectrltest.obj : .AUTODEPEND .\controls\treectrltest.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_propagation.obj : .AUTODEPEND .\events\propagation.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index 7122b54a83..56ef3ef897 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -112,6 +112,7 @@ controls/listctrltest.cpp controls/textctrltest.cpp controls/textentrytest.cpp + controls/treectrltest.cpp events/propagation.cpp image/rawbmp.cpp html/htmlwindow.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index 56db639fbe..28eb179fe3 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -319,6 +319,10 @@ SOURCE=.\controls\textctrltest.cpp SOURCE=.\controls\textentrytest.cpp # End Source File +# Begin Source File + +SOURCE=.\controls\treectrltest.cpp +# End Source File # End Group # End Target # End Project diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index 66a78cc7cd..ea1232cfab 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -657,6 +657,9 @@ + + + + + +