Add wxDisplay(wxWindow*) ctor with fall back on primary display

This is more convenient than calling GetFromWindow() and then checking
its return value.
This commit is contained in:
Vadim Zeitlin
2018-11-01 00:02:47 +01:00
parent e13df3140f
commit f57cb6c1d9
3 changed files with 30 additions and 0 deletions

View File

@@ -85,6 +85,13 @@ wxDisplay::wxDisplay(unsigned n)
m_impl = Factory().GetDisplay(n);
}
wxDisplay::wxDisplay(const wxWindow* window)
{
const int n = GetFromWindow(window);
m_impl = Factory().GetDisplay(n != wxNOT_FOUND ? n : 0);
}
// ----------------------------------------------------------------------------
// static functions forwarded to wxDisplayFactory
// ----------------------------------------------------------------------------
@@ -233,6 +240,8 @@ wxDisplayFactory::~wxDisplayFactory()
int wxDisplayFactory::GetFromWindow(const wxWindow *window)
{
wxCHECK_MSG( window, wxNOT_FOUND, "window can't be NULL" );
// consider that the window belongs to the display containing its centre
const wxRect r(window->GetScreenRect());
return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));