From 49732ef2016ce983a66945007f093692cc734b0b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Oct 2005 17:19:43 +0000 Subject: [PATCH] corrected GetBestSize() implementation: take all items, not just the currently visible ones git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35860 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/treectrl.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 0be3c82ae3..840aa202c4 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -2140,12 +2140,20 @@ bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId& item, wxSize wxTreeCtrl::DoGetBestSize() const { wxSize size; - wxRect rect; - for ( wxTreeItemId node = GetFirstVisibleItem(); - node.IsOk(); - node = GetNextVisible(node) ) + + // this doesn't really compute the total bounding rectangle of all items + // but a not too bad guess of it which has the advantage of not having to + // examine all (potentially hundreds or thousands) items in the control + for ( wxTreeItemId item = GetRootItem(); + item.IsOk(); + item = GetLastChild(item) ) { - if ( GetBoundingRect(node, rect) ) + wxRect rect; + + // last parameter is "true" to get only the dimensions of the text + // label, we don't want to get the entire item width as it's determined + // by the current size + if ( GetBoundingRect(item, rect, true) ) { if ( size.x < rect.x + rect.width ) size.x = rect.x + rect.width; @@ -2154,6 +2162,10 @@ wxSize wxTreeCtrl::DoGetBestSize() const } } + // need some minimal size even for empty tree + if ( !size.x || !size.y ) + size = wxControl::DoGetBestSize(); + return size; } -- 2.45.2