From b7540dc1ecf6de3a9f771c3cd24c688a0122c248 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Tue, 23 May 2006 18:05:30 +0000 Subject: [PATCH] [ 1493005 ] Fix wxComboCtrl popup positioning. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/combocmn.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 44b92449d4..e78ccaaa1a 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -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 ) { -- 2.45.2