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