]> git.saurik.com Git - wxWidgets.git/commitdiff
don't scroll to the child which gets focus if it is already fully visible; more impor...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Dec 2008 14:46:09 +0000 (14:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Dec 2008 14:46:09 +0000 (14:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57402 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/scrlwing.cpp

index c3f25599f9f1b9f113ce8bf1d7b81b1fafdc4a0d..55f429e48e02c003470634f8012a19ff640dae4f 100644 (file)
@@ -1354,7 +1354,7 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
         // scrolled into view
         return; 
 
-    wxSize view(m_targetWindow->GetClientSize());
+    const wxRect viewRect(m_targetWindow->GetClientRect());
 
     // For composite controls such as wxComboCtrl we should try to fit the
     // entire control inside the visible area of the target window, not just
@@ -1369,21 +1369,40 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
     {
         wxWindow *parent=win->GetParent();
         wxSize parent_size=parent->GetSize();
-        if (parent_size.GetWidth() <= view.GetWidth() &&
-            parent_size.GetHeight() <= view.GetHeight())
+        if (parent_size.GetWidth() <= viewRect.GetWidth() &&
+            parent_size.GetHeight() <= viewRect.GetHeight())
             // make the immediate parent visible instead of the focused control
             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;
     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;
     GetViewStart(&startx, &starty);
 
@@ -1392,13 +1411,13 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
     {
         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,
             // so that the window is fully visible:
             diff += stepy - 1;
@@ -1412,13 +1431,13 @@ void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
     {
         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,
             // so that the window is fully visible:
             diff += stepx - 1;