Improve wxComboCtrl popup position and add DPI change handling.

See https://github.com/wxWidgets/wxWidgets/pull/2231
This commit is contained in:
Vadim Zeitlin
2021-02-14 19:27:13 +01:00
5 changed files with 24 additions and 12 deletions

View File

@@ -93,6 +93,7 @@ public:
virtual void OnComboDoubleClick() wxOVERRIDE;
virtual bool LazyCreate() wxOVERRIDE;
virtual bool FindItem(const wxString& item, wxString* trueItem) wxOVERRIDE;
virtual void OnDPIChanged(wxDPIChangedEvent& event);
// Item management
void SetSelection( int item );

View File

@@ -252,10 +252,7 @@ public:
virtual wxCoord OnMeasureItem( size_t item ) const wxOVERRIDE
{
// Simply demonstrate the ability to have variable-height items
if ( item & 1 )
return 36;
else
return 24;
return FromDIP( item & 1 ? 36 : 24 );
}
virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const wxOVERRIDE

View File

@@ -20,6 +20,7 @@
#include "wx/combo.h"
#include "wx/display.h"
#ifdef __WXMSW__
#include "wx/msw/private.h"
@@ -2292,10 +2293,11 @@ void wxComboCtrlBase::ShowPopup()
int maxHeightPopup;
wxSize ctrlSz = GetSize();
screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y, this );
wxRect displayRect = wxDisplay(this).GetGeometry();
screenHeight = displayRect.GetHeight();
scrPos = GetScreenPosition();
spaceAbove = scrPos.y;
spaceAbove = scrPos.y - displayRect.GetY();
spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
maxHeightPopup = spaceBelow;
@@ -2370,7 +2372,7 @@ void wxComboCtrlBase::ShowPopup()
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
leftX -= ctrlSz.x;
int screenWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X, this );
int screenWidth = displayRect.GetWidth();
// 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.

View File

@@ -84,6 +84,10 @@ bool wxVListBoxComboPopup::Create(wxWindow* parent)
// TODO: Move this to SetFont
m_itemHeight = m_combo->GetCharHeight();
// Bind to the DPI event of the combobox. We get our own once the popup
// is shown, but this is too late, m_itemHeight is already being used.
m_combo->Bind(wxEVT_DPI_CHANGED, &wxVListBoxComboPopup::OnDPIChanged, this);
return true;
}
@@ -104,6 +108,11 @@ void wxVListBoxComboPopup::SetFocus()
#endif
}
void wxVListBoxComboPopup::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event))
{
m_itemHeight = m_combo->GetCharHeight();
}
bool wxVListBoxComboPopup::LazyCreate()
{
// NB: There is a bug with wxVListBox that can be avoided by creating

View File

@@ -62,6 +62,7 @@
#include "wx/timer.h"
#include "wx/dcbuffer.h"
#include "wx/scopeguard.h"
#include "wx/display.h"
// Two pics for the expand / collapse buttons.
// Files are not supplied with this project (since it is
@@ -1715,27 +1716,29 @@ wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
ImprovedClientToScreen( &x, &y );
int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X, this );
int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y, this );
wxRect displayRect = wxDisplay(this).GetGeometry();
x -= displayRect.GetX();
y -= displayRect.GetY();
int new_x;
int new_y;
if ( x > (sw/2) )
if ( x > (displayRect.GetWidth()/2) )
// left
new_x = x + (m_width-splitterX) - sz.x;
else
// right
new_x = x;
if ( y > (sh/2) )
if ( y > (displayRect.GetHeight()/2) )
// above
new_y = y - sz.y;
else
// below
new_y = y + m_lineHeight;
return wxPoint(new_x,new_y);
return wxPoint(new_x + displayRect.GetX(), new_y + displayRect.GetY());
}
// -----------------------------------------------------------------------