Merge branch 'owner-combo' of https://github.com/MaartenBent/wxWidgets
Improve wxComboCtrl popup position and add DPI change handling. See https://github.com/wxWidgets/wxWidgets/pull/2231
This commit is contained in:
@@ -93,6 +93,7 @@ public:
|
|||||||
virtual void OnComboDoubleClick() wxOVERRIDE;
|
virtual void OnComboDoubleClick() wxOVERRIDE;
|
||||||
virtual bool LazyCreate() wxOVERRIDE;
|
virtual bool LazyCreate() wxOVERRIDE;
|
||||||
virtual bool FindItem(const wxString& item, wxString* trueItem) wxOVERRIDE;
|
virtual bool FindItem(const wxString& item, wxString* trueItem) wxOVERRIDE;
|
||||||
|
virtual void OnDPIChanged(wxDPIChangedEvent& event);
|
||||||
|
|
||||||
// Item management
|
// Item management
|
||||||
void SetSelection( int item );
|
void SetSelection( int item );
|
||||||
|
@@ -252,10 +252,7 @@ public:
|
|||||||
virtual wxCoord OnMeasureItem( size_t item ) const wxOVERRIDE
|
virtual wxCoord OnMeasureItem( size_t item ) const wxOVERRIDE
|
||||||
{
|
{
|
||||||
// Simply demonstrate the ability to have variable-height items
|
// Simply demonstrate the ability to have variable-height items
|
||||||
if ( item & 1 )
|
return FromDIP( item & 1 ? 36 : 24 );
|
||||||
return 36;
|
|
||||||
else
|
|
||||||
return 24;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const wxOVERRIDE
|
virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const wxOVERRIDE
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "wx/combo.h"
|
#include "wx/combo.h"
|
||||||
|
#include "wx/display.h"
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
@@ -2292,10 +2293,11 @@ void wxComboCtrlBase::ShowPopup()
|
|||||||
int maxHeightPopup;
|
int maxHeightPopup;
|
||||||
wxSize ctrlSz = GetSize();
|
wxSize ctrlSz = GetSize();
|
||||||
|
|
||||||
screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y, this );
|
wxRect displayRect = wxDisplay(this).GetGeometry();
|
||||||
|
screenHeight = displayRect.GetHeight();
|
||||||
scrPos = GetScreenPosition();
|
scrPos = GetScreenPosition();
|
||||||
|
|
||||||
spaceAbove = scrPos.y;
|
spaceAbove = scrPos.y - displayRect.GetY();
|
||||||
spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
|
spaceBelow = screenHeight - spaceAbove - ctrlSz.y;
|
||||||
|
|
||||||
maxHeightPopup = spaceBelow;
|
maxHeightPopup = spaceBelow;
|
||||||
@@ -2370,7 +2372,7 @@ void wxComboCtrlBase::ShowPopup()
|
|||||||
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
|
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
|
||||||
leftX -= ctrlSz.x;
|
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 not enough horizontal space, anchor on the other side.
|
||||||
// If there is no space even then, place the popup at x 0.
|
// If there is no space even then, place the popup at x 0.
|
||||||
|
@@ -84,6 +84,10 @@ bool wxVListBoxComboPopup::Create(wxWindow* parent)
|
|||||||
// TODO: Move this to SetFont
|
// TODO: Move this to SetFont
|
||||||
m_itemHeight = m_combo->GetCharHeight();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +108,11 @@ void wxVListBoxComboPopup::SetFocus()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxVListBoxComboPopup::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_itemHeight = m_combo->GetCharHeight();
|
||||||
|
}
|
||||||
|
|
||||||
bool wxVListBoxComboPopup::LazyCreate()
|
bool wxVListBoxComboPopup::LazyCreate()
|
||||||
{
|
{
|
||||||
// NB: There is a bug with wxVListBox that can be avoided by creating
|
// NB: There is a bug with wxVListBox that can be avoided by creating
|
||||||
|
@@ -62,6 +62,7 @@
|
|||||||
#include "wx/timer.h"
|
#include "wx/timer.h"
|
||||||
#include "wx/dcbuffer.h"
|
#include "wx/dcbuffer.h"
|
||||||
#include "wx/scopeguard.h"
|
#include "wx/scopeguard.h"
|
||||||
|
#include "wx/display.h"
|
||||||
|
|
||||||
// Two pics for the expand / collapse buttons.
|
// Two pics for the expand / collapse buttons.
|
||||||
// Files are not supplied with this project (since it is
|
// Files are not supplied with this project (since it is
|
||||||
@@ -1715,27 +1716,29 @@ wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
|
|||||||
|
|
||||||
ImprovedClientToScreen( &x, &y );
|
ImprovedClientToScreen( &x, &y );
|
||||||
|
|
||||||
int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X, this );
|
wxRect displayRect = wxDisplay(this).GetGeometry();
|
||||||
int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y, this );
|
|
||||||
|
x -= displayRect.GetX();
|
||||||
|
y -= displayRect.GetY();
|
||||||
|
|
||||||
int new_x;
|
int new_x;
|
||||||
int new_y;
|
int new_y;
|
||||||
|
|
||||||
if ( x > (sw/2) )
|
if ( x > (displayRect.GetWidth()/2) )
|
||||||
// left
|
// left
|
||||||
new_x = x + (m_width-splitterX) - sz.x;
|
new_x = x + (m_width-splitterX) - sz.x;
|
||||||
else
|
else
|
||||||
// right
|
// right
|
||||||
new_x = x;
|
new_x = x;
|
||||||
|
|
||||||
if ( y > (sh/2) )
|
if ( y > (displayRect.GetHeight()/2) )
|
||||||
// above
|
// above
|
||||||
new_y = y - sz.y;
|
new_y = y - sz.y;
|
||||||
else
|
else
|
||||||
// below
|
// below
|
||||||
new_y = y + m_lineHeight;
|
new_y = y + m_lineHeight;
|
||||||
|
|
||||||
return wxPoint(new_x,new_y);
|
return wxPoint(new_x + displayRect.GetX(), new_y + displayRect.GetY());
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user