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.
This commit is contained in:
Vadim Zeitlin
2015-05-16 15:51:09 +02:00
parent 4b8e8adf16
commit 1c63ec5564
2 changed files with 12 additions and 2 deletions

View File

@@ -943,6 +943,11 @@ public:
controls automatic best size determination and using sizers to lay out controls automatic best size determination and using sizers to lay out
them. 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 @since 3.1.0
*/ */
wxSize FromDIP(const wxSize& sz) const; wxSize FromDIP(const wxSize& sz) const;
@@ -957,6 +962,9 @@ public:
This is the same as FromDIP(const wxSize& sz) overload, but assumes This is the same as FromDIP(const wxSize& sz) overload, but assumes
that the resolution is the same in horizontal and vertical directions. 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 @since 3.1.0
*/ */
int FromDIP(int d) const; int FromDIP(int d) const;

View File

@@ -2873,8 +2873,10 @@ wxWindowBase::FromDIP(const wxSize& sz, const wxWindowBase* WXUNUSED(w))
{ {
const wxSize dpi = wxScreenDC().GetPPI(); const wxSize dpi = wxScreenDC().GetPPI();
return wxSize(wxMulDivInt32(sz.x, dpi.x, BASELINE_DPI), // Take care to not scale -1 because it has a special meaning of
wxMulDivInt32(sz.y, dpi.y, BASELINE_DPI)); // "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 #endif // !wxHAVE_DPI_INDEPENDENT_PIXELS