Check if window is created before getting the display it is on
If it is not initialised, getting the screen rectangle will fail, so don't even try doing it, but just return wxNOT_FOUND instead, so the main display will be used -- this is the best we can do if the window hasn't been created yet, as we don't know on which display it will appear. Closes https://github.com/wxWidgets/wxWidgets/pull/1527 Closes #18481.
This commit is contained in:
committed by
Vadim Zeitlin
parent
3d73b30b56
commit
2c27f9851b
@@ -249,6 +249,13 @@ int wxDisplayFactory::GetFromWindow(const wxWindow *window)
|
||||
{
|
||||
wxCHECK_MSG( window, wxNOT_FOUND, "window can't be NULL" );
|
||||
|
||||
// Check if the window is created: we can't find its display before this is
|
||||
// done anyhow, as we simply don't know on which display will it appear,
|
||||
// and trying to do this below would just result in assert failures inside
|
||||
// GetScreenRect() if the window doesn't yet exist, so return immediately.
|
||||
if ( !window->GetHandle() )
|
||||
return wxNOT_FOUND;
|
||||
|
||||
// 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));
|
||||
|
Reference in New Issue
Block a user