don't scroll to the child which gets focus if it's already fully visible (see #9563) [backport of r57402 from trunk]

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@60600 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-05-12 10:33:49 +00:00
parent 7ccf7265a8
commit fb2275f5b3

View File

@@ -1386,7 +1386,7 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
// scrolled into view // scrolled into view
return; return;
wxSize view(m_targetWindow->GetClientSize()); const wxRect viewRect(m_targetWindow->GetClientRect());
// For composite controls such as wxComboCtrl we should try to fit the // For composite controls such as wxComboCtrl we should try to fit the
// entire control inside the visible area of the target window, not just // entire control inside the visible area of the target window, not just
@@ -1401,21 +1401,40 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
{ {
wxWindow *parent=win->GetParent(); wxWindow *parent=win->GetParent();
wxSize parent_size=parent->GetSize(); wxSize parent_size=parent->GetSize();
if (parent_size.GetWidth() <= view.GetWidth() && if (parent_size.GetWidth() <= viewRect.GetWidth() &&
parent_size.GetHeight() <= view.GetHeight()) parent_size.GetHeight() <= viewRect.GetHeight())
// make the immediate parent visible instead of the focused control // make the immediate parent visible instead of the focused control
win=parent; win=parent;
} }
// if the child is not fully visible, try to scroll it into view: // make win position relative to the m_targetWindow viewing area instead of
// its parent
const wxRect
winRect(m_targetWindow->ScreenToClient(win->GetScreenPosition()),
win->GetSize());
// check if it's fully visible
if ( viewRect.Contains(winRect) )
{
// it is, nothing to do
return;
}
// check if we can make it fully visible: this is only possible if it's not
// larger than our view area
if ( winRect.GetWidth() > viewRect.GetWidth() ||
winRect.GetHeight() > viewRect.GetHeight() )
{
// we can't make it fit so avoid scrolling it at all, this is only
// going to be confusing and not helpful
return;
}
// do make the window fit inside the view area by scrolling to it
int stepx, stepy; int stepx, stepy;
GetScrollPixelsPerUnit(&stepx, &stepy); GetScrollPixelsPerUnit(&stepx, &stepy);
// 'win' position coordinates are relative to it's parent
// convert them so that they are relative to the m_targetWindow viewing area
wxRect winrect(m_targetWindow->ScreenToClient(win->GetScreenPosition()),
win->GetSize());
int startx, starty; int startx, starty;
GetViewStart(&startx, &starty); GetViewStart(&startx, &starty);
@@ -1424,13 +1443,13 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
{ {
int diff = 0; int diff = 0;
if ( winrect.GetTop() < 0 ) if ( winRect.GetTop() < 0 )
{ {
diff = winrect.GetTop(); diff = winRect.GetTop();
} }
else if ( winrect.GetBottom() > view.y ) else if ( winRect.GetBottom() > viewRect.GetHeight() )
{ {
diff = winrect.GetBottom() - view.y + 1; diff = winRect.GetBottom() - viewRect.GetHeight() + 1;
// round up to next scroll step if we can't get exact position, // round up to next scroll step if we can't get exact position,
// so that the window is fully visible: // so that the window is fully visible:
diff += stepy - 1; diff += stepy - 1;
@@ -1444,13 +1463,13 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
{ {
int diff = 0; int diff = 0;
if ( winrect.GetLeft() < 0 ) if ( winRect.GetLeft() < 0 )
{ {
diff = winrect.GetLeft(); diff = winRect.GetLeft();
} }
else if ( winrect.GetRight() > view.x ) else if ( winRect.GetRight() > viewRect.GetWidth() )
{ {
diff = winrect.GetRight() - view.x + 1; diff = winRect.GetRight() - viewRect.GetWidth() + 1;
// round up to next scroll step if we can't get exact position, // round up to next scroll step if we can't get exact position,
// so that the window is fully visible: // so that the window is fully visible:
diff += stepx - 1; diff += stepx - 1;