From 4ad9cde3805f16958bdb6e072ae072e999ce798d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 1 Nov 2018 00:06:34 +0100 Subject: [PATCH] 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. --- src/common/dlgcmn.cpp | 2 +- src/common/sizer.cpp | 12 +++--------- src/common/toplvcmn.cpp | 3 +-- src/generic/richtooltipg.cpp | 6 +----- src/msw/msgdlg.cpp | 5 +---- src/msw/toplevel.cpp | 9 ++------- src/stc/PlatWX.cpp | 3 +-- 7 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 55e37cc2e6..a7a6803bb3 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -871,7 +871,7 @@ int wxStandardDialogLayoutAdapter::DoMustScroll(wxDialog* dialog, wxSize& window wxSize minWindowSize = dialog->GetSizer()->GetMinSize(); windowSize = dialog->GetSize(); 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; diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index ba50b6c9c0..8f2dc9f887 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -930,15 +930,9 @@ wxSize wxSizer::ComputeFittingClientSize(wxWindow *window) return tlw->GetClientSize(); } - // limit the window to the size of the display it is on - int disp = wxDisplay::GetFromWindow(window); - if ( disp == wxNOT_FOUND ) - { - // or, if we don't know which one it is, of the main one - disp = 0; - } - - sizeMax = wxDisplay(disp).GetClientArea().GetSize(); + // limit the window to the size of the display it is on (or the main + // one if the window display can't be determined) + sizeMax = wxDisplay(window).GetClientArea().GetSize(); // If determining the display size failed, skip the max size checks as // we really don't want to create windows of (0, 0) size. diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index a5660a3b23..7619328a18 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -249,8 +249,7 @@ void wxTopLevelWindowBase::DoCentre(int dir) // 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 // this window itself is not really defined yet - int nDisplay = wxDisplay::GetFromWindow(GetParent() ? GetParent() : this); - wxDisplay dpy(nDisplay == wxNOT_FOUND ? 0 : nDisplay); + wxDisplay dpy(GetParent() ? GetParent() : this); const wxRect rectDisplay(dpy.GetClientArea()); // what should we centre this window on? diff --git a/src/generic/richtooltipg.cpp b/src/generic/richtooltipg.cpp index 574f36b672..b774341d33 100644 --- a/src/generic/richtooltipg.cpp +++ b/src/generic/richtooltipg.cpp @@ -318,11 +318,7 @@ private: // Use GetFromWindow() and not GetFromPoint() here to try to get the // correct display even if the tip point itself is not visible. - int dpy = wxDisplay::GetFromWindow(GetParent()); - if ( dpy == wxNOT_FOUND ) - dpy = 0; // What else can we do? - - const wxRect rectDpy = wxDisplay(dpy).GetClientArea(); + const wxRect rectDpy = wxDisplay(GetParent()).GetClientArea(); #ifdef __WXMAC__ return pos.y > rectDpy.height/2 ? wxTipKind_Bottom : wxTipKind_Top; diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index 017991a4b4..61a0a878a8 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -162,10 +162,7 @@ wxMessageDialog::HookFunction(int code, WXWPARAM wParam, WXLPARAM lParam) void wxMessageDialog::ReplaceStaticWithEdit() { // check if the message box fits the display - int nDisplay = wxDisplay::GetFromWindow(this); - if ( nDisplay == wxNOT_FOUND ) - nDisplay = 0; - const wxRect rectDisplay = wxDisplay(nDisplay).GetClientArea(); + const wxRect rectDisplay = wxDisplay(this).GetClientArea(); if ( rectDisplay.Contains(GetRect()) ) { diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index df9e001c93..b883d9d8f9 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -756,8 +756,7 @@ void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const { // we must use the correct display for the translation as the // task bar might be shown on one display but not the other one - int n = wxDisplay::GetFromWindow(this); - wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); + wxDisplay dpy(this); const wxPoint ptOfs = dpy.GetClientArea().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 // primary one - int dpy = wxDisplay::GetFromWindow(this); - if ( dpy == wxNOT_FOUND ) - dpy = 0; - - const wxRect rect = wxDisplay(dpy).GetGeometry(); + const wxRect rect = wxDisplay(this).GetGeometry(); SetSize(rect); diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 4fd42772bb..ffb3db94bc 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -1861,8 +1861,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { position.x = wxRound(position.x + rc.left); position.y = wxRound(position.y + rc.top); - const int currentDisplay = wxDisplay::GetFromWindow(relativeWin); - const wxRect displayRect = wxDisplay(currentDisplay).GetClientArea(); + const wxRect displayRect = wxDisplay(relativeWin).GetClientArea(); if (position.x < displayRect.GetLeft()) position.x = displayRect.GetLeft();