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:
parent
e13df3140f
commit
f57cb6c1d9
@ -49,6 +49,10 @@ public:
|
||||
// primary display and the only one which is always supported
|
||||
wxDisplay(unsigned n = 0);
|
||||
|
||||
// create display object corresponding to the display of the given window
|
||||
// or the default one if the window display couldn't be found
|
||||
explicit wxDisplay(const wxWindow* window);
|
||||
|
||||
// dtor is not virtual as this is a concrete class not meant to be derived
|
||||
// from
|
||||
|
||||
|
@ -26,6 +26,23 @@ public:
|
||||
*/
|
||||
wxDisplay(unsigned int index = 0);
|
||||
|
||||
/**
|
||||
Constructor creating the display object associated with the given
|
||||
window.
|
||||
|
||||
This is the most convenient way of finding the display on which the
|
||||
given window is shown while falling back to the default display if it
|
||||
is not shown at all or positioned outside of any display.
|
||||
|
||||
@param window
|
||||
A valid, i.e. non-null, window.
|
||||
|
||||
@see GetFromWindow()
|
||||
|
||||
@since 3.1.2
|
||||
*/
|
||||
explicit wxDisplay(const wxWindow* window);
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user