simplify ScrollTo()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61241 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-06-28 21:50:55 +00:00
parent 820c05dfd6
commit 842adaf697

View File

@@ -2231,61 +2231,42 @@ void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId& item)
void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item) void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item)
{ {
if (!item.IsOk()) return; if (!item.IsOk())
return;
// We have to call this here because the label in // update the control before scrolling it
// question might just have been added and no screen
// update taken place.
if (m_dirty) if (m_dirty)
#if defined( __WXMSW__ ) || defined(__WXMAC__) #if defined( __WXMSW__ ) || defined(__WXMAC__)
Update(); Update();
#else #else
DoDirtyProcessing(); DoDirtyProcessing();
#endif #endif
wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem; wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem;
// now scroll to the item int itemY = gitem->GetY();
int item_y = gitem->GetY();
int start_x = 0; int start_x = 0;
int start_y = 0; int start_y = 0;
GetViewStart( &start_x, &start_y ); GetViewStart( &start_x, &start_y );
start_y *= PIXELS_PER_UNIT;
int client_h = 0; const int clientHeight = GetClientSize().y;
int client_w = 0;
GetClientSize( &client_w, &client_h );
if (item_y < start_y+3) const int itemHeight = GetLineHeight(gitem) + 2;
if ( itemY + itemHeight > start_y*PIXELS_PER_UNIT + clientHeight )
{ {
// going down // need to scroll up by enough to show this item fully
int x = 0; itemY += itemHeight - clientHeight;
int y = 0;
m_anchor->GetSize( x, y, this );
y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
int x_pos = GetScrollPos( wxHORIZONTAL );
// Item should appear at top
SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT,
x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT,
x_pos, item_y/PIXELS_PER_UNIT );
} }
else if (item_y+GetLineHeight(gitem) > start_y+client_h) else if ( itemY > start_y*PIXELS_PER_UNIT )
{ {
// going up // item is already fully visible, don't do anything
int x = 0; return;
int y = 0;
m_anchor->GetSize( x, y, this );
y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
item_y += PIXELS_PER_UNIT+2;
int x_pos = GetScrollPos( wxHORIZONTAL );
// Item should appear at bottom
SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT,
x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT,
x_pos,
(item_y+GetLineHeight(gitem)-client_h)/PIXELS_PER_UNIT );
} }
//else: scroll down to make this item the top one displayed
Scroll(-1, itemY/PIXELS_PER_UNIT);
} }
// FIXME: tree sorting functions are not reentrant and not MT-safe! // FIXME: tree sorting functions are not reentrant and not MT-safe!