Improve wxPropertyGridEditor position with multiple displays

This commit is contained in:
Maarten Bent
2021-02-13 01:41:14 +01:00
parent 01d8c1bf8e
commit 9365df2322

View File

@@ -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,30 @@ wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p,
ImprovedClientToScreen( &x, &y ); ImprovedClientToScreen( &x, &y );
int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X, this ); int displayIdx = wxDisplay::GetFromWindow(this);
int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y, this ); wxRect displayRect = wxDisplay(displayIdx != wxNOT_FOUND ? displayIdx : 0u).GetGeometry();
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());
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------