- }
- else
- {
- // This is for the wxMSW tree control
- wxScrolledWindow* scrolledWindow = GetScrolledWindow();
- if (scrolledWindow)
- {
- wxRect itemRect;
- if (GetBoundingRect(GetRootItem(), itemRect))
- {
- int itemHeight = itemRect.GetHeight();
-
- int w, h;
- GetClientSize(&w, &h);
-
- wxRect rect(0, 0, 0, 0);
- CalcTreeSize(rect);
- int treeViewHeight = rect.GetHeight()/itemHeight;
-
- int scrollPixelsPerLine = itemHeight;
- int scrollPos = - (itemRect.y / itemHeight);
-
- scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos);
-
- // Ensure that when a scrollbar becomes hidden or visible,
- // the contained window sizes are right.
- // Problem: this is called too early (?)
- wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId());
- scrolledWindow->GetEventHandler()->ProcessEvent(event);
- }
- }
- }
+ }
+ else
+#endif
+ {
+ // This is for the wxMSW tree control
+ wxScrolledWindow* scrolledWindow = GetScrolledWindow();
+ if (scrolledWindow)
+ {
+ wxRect itemRect;
+ if (GetBoundingRect(GetFirstVisibleItem(), itemRect))
+ {
+ // Actually, the real height seems to be 1 less than reported
+ // (e.g. 16 instead of 16)
+ int itemHeight = itemRect.GetHeight() - 1;
+
+ int w, h;
+ GetClientSize(&w, &h);
+
+ wxRect rect(0, 0, 0, 0);
+ CalcTreeSize(rect);
+
+ double f = ((double) (rect.GetHeight()) / (double) itemHeight) ;
+ int treeViewHeight = (int) ceil(f);
+
+ int scrollPixelsPerLine = itemHeight;
+ int scrollPos = - (itemRect.y / itemHeight);
+
+ scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos);
+
+ // Ensure that when a scrollbar becomes hidden or visible,
+ // the contained window sizes are right.
+ // Problem: this is called too early (?)
+ wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId());
+ scrolledWindow->GetEventHandler()->ProcessEvent(event);
+ }
+ }
+ }