]> git.saurik.com Git - wxWidgets.git/commitdiff
[ 1493005 ] Fix wxComboCtrl popup positioning.
authorWłodzimierz Skiba <abx@abx.art.pl>
Tue, 23 May 2006 18:05:30 +0000 (18:05 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Tue, 23 May 2006 18:05:30 +0000 (18:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/combocmn.cpp

index 44b92449d44fa28466d226247dc8df53a902d825..e78ccaaa1ac4d2755bfbce26ab37ec74ba176eb1 100644 (file)
@@ -1653,15 +1653,45 @@ void wxComboCtrlBase::ShowPopup()
     int popupX;
     int popupY = scrPos.y + ctrlSz.y;
 
+    // Default anchor is wxLEFT
     int anchorSide = m_anchorSide;
     if ( !anchorSide )
-        anchorSide = m_btnSide;
+        anchorSide = wxLEFT;
 
-    // Anchor popup to the side the dropbutton is on
+    int rightX = scrPos.x + ctrlSz.x + m_extRight - szp.x;
+    int leftX = scrPos.x - m_extLeft;
+    int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
+
+    // If there is not enough horizontal space, anchor on the other side.
+    // If there is no space even then, place the popup at x 0.
+    if ( anchorSide == wxRIGHT )
+    {
+        if ( rightX < 0 )
+        {
+            if ( (leftX+szp.x) < screenWidth )
+                anchorSide = wxLEFT;
+            else
+                anchorSide = 0;
+        }
+    }
+    else
+    {
+        if ( (leftX+szp.x) >= screenWidth )
+        {
+            if ( rightX >= 0 )
+                anchorSide = wxRIGHT;
+            else
+                anchorSide = 0;
+        }
+    }
+
+    // Select x coordinate according to the anchor side
     if ( anchorSide == wxRIGHT )
-        popupX = scrPos.x + ctrlSz.x + m_extRight- szp.x;
+        popupX = rightX;
+    else if ( anchorSide == wxLEFT )
+        popupX = leftX;
     else
-        popupX = scrPos.x - m_extLeft;
+        popupX = 0;
 
     if ( spaceBelow < szp.y )
     {