git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35860
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
wxSize wxTreeCtrl::DoGetBestSize() const
{
wxSize size;
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;
{
if ( size.x < rect.x + rect.width )
size.x = rect.x + rect.width;
+ // need some minimal size even for empty tree
+ if ( !size.x || !size.y )
+ size = wxControl::DoGetBestSize();
+