Use the new wxDisplay(wxWindow*) ctor to simplify the code

Make the code simpler and, in a couple of places where the fall back to
the primary display in case wxDisplay::GetFromWindow() returned -1 was
missing, also more correct.
This commit is contained in:
Vadim Zeitlin
2018-11-01 00:06:34 +01:00
parent f57cb6c1d9
commit 4ad9cde380
7 changed files with 10 additions and 30 deletions

View File

@@ -871,7 +871,7 @@ int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog* dialog, wxSize& window
wxSize minWindowSize = dialog->GetSizer()->GetMinSize(); wxSize minWindowSize = dialog->GetSizer()->GetMinSize();
windowSize = dialog->GetSize(); windowSize = dialog->GetSize();
windowSize = wxSize(wxMax(windowSize.x, minWindowSize.x), wxMax(windowSize.y, minWindowSize.y)); windowSize = wxSize(wxMax(windowSize.x, minWindowSize.x), wxMax(windowSize.y, minWindowSize.y));
displaySize = wxDisplay(wxDisplay::GetFromWindow(dialog)).GetClientArea().GetSize(); displaySize = wxDisplay(dialog).GetClientArea().GetSize();
int flags = 0; int flags = 0;

View File

@@ -930,15 +930,9 @@ wxSize wxSizer::ComputeFittingClientSize(wxWindow *window)
return tlw->GetClientSize(); return tlw->GetClientSize();
} }
// limit the window to the size of the display it is on // limit the window to the size of the display it is on (or the main
int disp = wxDisplay::GetFromWindow(window); // one if the window display can't be determined)
if ( disp == wxNOT_FOUND ) sizeMax = wxDisplay(window).GetClientArea().GetSize();
{
// or, if we don't know which one it is, of the main one
disp = 0;
}
sizeMax = wxDisplay(disp).GetClientArea().GetSize();
// If determining the display size failed, skip the max size checks as // If determining the display size failed, skip the max size checks as
// we really don't want to create windows of (0, 0) size. // we really don't want to create windows of (0, 0) size.

View File

@@ -249,8 +249,7 @@ void wxTopLevelWindowBase::DoCentre(int dir)
// we need the display rect anyhow so store it first: notice that we should // we need the display rect anyhow so store it first: notice that we should
// be centered on the same display as our parent window, the display of // be centered on the same display as our parent window, the display of
// this window itself is not really defined yet // this window itself is not really defined yet
int nDisplay = wxDisplay::GetFromWindow(GetParent() ? GetParent() : this); wxDisplay dpy(GetParent() ? GetParent() : this);
wxDisplay dpy(nDisplay == wxNOT_FOUND ? 0 : nDisplay);
const wxRect rectDisplay(dpy.GetClientArea()); const wxRect rectDisplay(dpy.GetClientArea());
// what should we centre this window on? // what should we centre this window on?

View File

@@ -318,11 +318,7 @@ private:
// Use GetFromWindow() and not GetFromPoint() here to try to get the // Use GetFromWindow() and not GetFromPoint() here to try to get the
// correct display even if the tip point itself is not visible. // correct display even if the tip point itself is not visible.
int dpy = wxDisplay::GetFromWindow(GetParent()); const wxRect rectDpy = wxDisplay(GetParent()).GetClientArea();
if ( dpy == wxNOT_FOUND )
dpy = 0; // What else can we do?
const wxRect rectDpy = wxDisplay(dpy).GetClientArea();
#ifdef __WXMAC__ #ifdef __WXMAC__
return pos.y > rectDpy.height/2 ? wxTipKind_Bottom : wxTipKind_Top; return pos.y > rectDpy.height/2 ? wxTipKind_Bottom : wxTipKind_Top;

View File

@@ -162,10 +162,7 @@ wxMessageDialog::HookFunction(int code, WXWPARAM wParam, WXLPARAM lParam)
void wxMessageDialog::ReplaceStaticWithEdit() void wxMessageDialog::ReplaceStaticWithEdit()
{ {
// check if the message box fits the display // check if the message box fits the display
int nDisplay = wxDisplay::GetFromWindow(this); const wxRect rectDisplay = wxDisplay(this).GetClientArea();
if ( nDisplay == wxNOT_FOUND )
nDisplay = 0;
const wxRect rectDisplay = wxDisplay(nDisplay).GetClientArea();
if ( rectDisplay.Contains(GetRect()) ) if ( rectDisplay.Contains(GetRect()) )
{ {

View File

@@ -756,8 +756,7 @@ void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const
{ {
// we must use the correct display for the translation as the // we must use the correct display for the translation as the
// task bar might be shown on one display but not the other one // task bar might be shown on one display but not the other one
int n = wxDisplay::GetFromWindow(this); wxDisplay dpy(this);
wxDisplay dpy(n == wxNOT_FOUND ? 0 : n);
const wxPoint ptOfs = dpy.GetClientArea().GetPosition() - const wxPoint ptOfs = dpy.GetClientArea().GetPosition() -
dpy.GetGeometry().GetPosition(); dpy.GetGeometry().GetPosition();
@@ -916,11 +915,7 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
// resize to the size of the display containing us, falling back to the // resize to the size of the display containing us, falling back to the
// primary one // primary one
int dpy = wxDisplay::GetFromWindow(this); const wxRect rect = wxDisplay(this).GetGeometry();
if ( dpy == wxNOT_FOUND )
dpy = 0;
const wxRect rect = wxDisplay(dpy).GetGeometry();
SetSize(rect); SetSize(rect);

View File

@@ -1861,8 +1861,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
position.x = wxRound(position.x + rc.left); position.x = wxRound(position.x + rc.left);
position.y = wxRound(position.y + rc.top); position.y = wxRound(position.y + rc.top);
const int currentDisplay = wxDisplay::GetFromWindow(relativeWin); const wxRect displayRect = wxDisplay(relativeWin).GetClientArea();
const wxRect displayRect = wxDisplay(currentDisplay).GetClientArea();
if (position.x < displayRect.GetLeft()) if (position.x < displayRect.GetLeft())
position.x = displayRect.GetLeft(); position.x = displayRect.GetLeft();