From 1c63ec5564b1a63d7783a8d7294af6a5fb1cd521 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 May 2015 15:51:09 +0200 Subject: [PATCH] Don't scale the value(s) of -1 in wxWindow::FromDIP(). Using FromDIP() in wxXRC broke creating controls whose width or height was specified as -1 as it became -2 when sufficiently high DPI was used, and so lost the special meaning of "unspecified" that -1 had. Avoid this problem by never scaling -1 in FromDIP(), this is unlikely to ever be useful and could result in more difficult to debug problems in the future. --- interface/wx/window.h | 8 ++++++++ src/common/wincmn.cpp | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/interface/wx/window.h b/interface/wx/window.h index 61ddf118d0..2b288e75c0 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -943,6 +943,11 @@ public: controls automatic best size determination and using sizers to lay out them. + Also note that if either component of @a sz has the special value of + -1, it is returned unchanged independently of the current DPI, to + preserve the special value of -1 in wxWidgets API (it is often used to + mean "unspecified"). + @since 3.1.0 */ wxSize FromDIP(const wxSize& sz) const; @@ -957,6 +962,9 @@ public: This is the same as FromDIP(const wxSize& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions. + If @a d has the special value of -1, it is returned unchanged + independently of the current DPI. + @since 3.1.0 */ int FromDIP(int d) const; diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index d00f11c1e1..679c6ea5e8 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2873,8 +2873,10 @@ wxWindowBase::FromDIP(const wxSize& sz, const wxWindowBase* WXUNUSED(w)) { const wxSize dpi = wxScreenDC().GetPPI(); - return wxSize(wxMulDivInt32(sz.x, dpi.x, BASELINE_DPI), - wxMulDivInt32(sz.y, dpi.y, BASELINE_DPI)); + // Take care to not scale -1 because it has a special meaning of + // "unspecified" which should be preserved. + return wxSize(sz.x == -1 ? -1 : wxMulDivInt32(sz.x, dpi.x, BASELINE_DPI), + sz.y == -1 ? -1 : wxMulDivInt32(sz.y, dpi.y, BASELINE_DPI)); } #endif // !wxHAVE_DPI_INDEPENDENT_PIXELS