Reset static sizes when DPI changes
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#define _WX_PRIVATE_WINDOW_H_
|
||||
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
namespace wxPrivate
|
||||
{
|
||||
@@ -33,6 +34,67 @@ inline wxSize GetAverageASCIILetterSize(const T& of_what)
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
inline bool SupportsPerMonitorDPI()
|
||||
{
|
||||
static bool s_checkDPI =
|
||||
#if defined(__WXMSW__) && wxUSE_DYNLIB_CLASS
|
||||
// Only check the DPI when GetDpiForWindow is available because the old
|
||||
// method (GetDeviceCaps) is a lot slower (about 1500 times).
|
||||
// And when GetDpiForWindow is not available (for example older Windows
|
||||
// versions), per-monitor DPI (V2) is also not available.
|
||||
wxLoadedDLL("user32.dll").HasSymbol("GetDpiForWindow");
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
return s_checkDPI;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class DpiDependentValue
|
||||
{
|
||||
public:
|
||||
// Explicit initialization is needed if T is a primitive type.
|
||||
DpiDependentValue()
|
||||
: m_value(), m_dpi()
|
||||
{ }
|
||||
|
||||
bool HasChanged(const wxWindowBase* win)
|
||||
{
|
||||
if ( win && SupportsPerMonitorDPI() )
|
||||
{
|
||||
const wxSize dpi = win->GetDPI();
|
||||
if ( dpi != m_dpi )
|
||||
{
|
||||
m_dpi = dpi;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that we return true the first time we're called,
|
||||
// asuming that the value will always be set to a non-default value.
|
||||
return m_value == T();
|
||||
}
|
||||
|
||||
void SetAtNewDPI(const T& value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
T& Get()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_value;
|
||||
wxSize m_dpi;
|
||||
};
|
||||
|
||||
} // namespace wxPrivate
|
||||
|
||||
#endif // _WX_PRIVATE_WINDOW_H_
|
||||
|
@@ -120,13 +120,7 @@ public:
|
||||
// current DPI, do it once (and cache the result) in another function.
|
||||
#define wxNEEDS_BORDER_IN_PX
|
||||
|
||||
// We don't react to dynamic DPI changes, so we can cache the values of
|
||||
// the border in on-screen pixels after computing it once. This
|
||||
// could/should change in the future.
|
||||
if ( !ms_defaultBorderInPx )
|
||||
ms_defaultBorderInPx = DoGetDefaultBorderInPx();
|
||||
|
||||
return ms_defaultBorderInPx;
|
||||
return DoGetDefaultBorderInPx();
|
||||
#endif
|
||||
#else
|
||||
return 0;
|
||||
@@ -230,8 +224,6 @@ public:
|
||||
private:
|
||||
#ifdef wxNEEDS_BORDER_IN_PX
|
||||
static int DoGetDefaultBorderInPx();
|
||||
|
||||
static int ms_defaultBorderInPx;
|
||||
#endif // wxNEEDS_BORDER_IN_PX
|
||||
|
||||
int m_proportion;
|
||||
|
Reference in New Issue
Block a user