Use DPI Aware wxSystemParametersInfo

Require a wxWindow when requesting GetNonClientMetrics.
If no wxWindow is known, use wxTheApp->GetTopWindow().
This commit is contained in:
Maarten Bent
2018-07-22 14:21:36 +02:00
parent c0c6a4b826
commit 0a79c48631
4 changed files with 15 additions and 8 deletions

View File

@@ -10,6 +10,8 @@
#ifndef _WX_MSW_PRIVATE_METRICS_H_ #ifndef _WX_MSW_PRIVATE_METRICS_H_
#define _WX_MSW_PRIVATE_METRICS_H_ #define _WX_MSW_PRIVATE_METRICS_H_
#include "wx/msw/private.h"
namespace wxMSWImpl namespace wxMSWImpl
{ {
@@ -20,10 +22,10 @@ namespace wxMSWImpl
// in the future // in the future
// //
// MT-safety: this function is only meant to be called from the main thread // MT-safety: this function is only meant to be called from the main thread
inline const NONCLIENTMETRICS& GetNonClientMetrics() inline const NONCLIENTMETRICS& GetNonClientMetrics(const wxWindow* win)
{ {
static WinStruct<NONCLIENTMETRICS> nm; static WinStruct<NONCLIENTMETRICS> nm;
if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0) ) if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0 , win) )
{ {
#if WINVER >= 0x0600 #if WINVER >= 0x0600
// a new field has been added to NONCLIENTMETRICS under Vista, so // a new field has been added to NONCLIENTMETRICS under Vista, so
@@ -31,7 +33,7 @@ inline const NONCLIENTMETRICS& GetNonClientMetrics()
// size incorporating this new value on an older system -- retry // size incorporating this new value on an older system -- retry
// without it // without it
nm.cbSize -= sizeof(int); nm.cbSize -= sizeof(int);
if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0) ) if ( !wxSystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0, win) )
#endif // WINVER >= 0x0600 #endif // WINVER >= 0x0600
{ {
// maybe we should initialize the struct with some defaults? // maybe we should initialize the struct with some defaults?

View File

@@ -363,7 +363,7 @@ void MenuDrawData::Init()
else else
#endif // wxUSE_UXTHEME #endif // wxUSE_UXTHEME
{ {
const NONCLIENTMETRICS& metrics = wxMSWImpl::GetNonClientMetrics(); const NONCLIENTMETRICS& metrics = wxMSWImpl::GetNonClientMetrics(window);
CheckMargin.cxLeftWidth = CheckMargin.cxLeftWidth =
CheckMargin.cxRightWidth = wxGetSystemMetrics(SM_CXEDGE, window); CheckMargin.cxRightWidth = wxGetSystemMetrics(SM_CXEDGE, window);

View File

@@ -396,7 +396,8 @@ void wxMessageDialog::AdjustButtonLabels()
/* static */ /* static */
wxFont wxMessageDialog::GetMessageFont() wxFont wxMessageDialog::GetMessageFont()
{ {
const NONCLIENTMETRICS& ncm = wxMSWImpl::GetNonClientMetrics(); const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
const NONCLIENTMETRICS& ncm = wxMSWImpl::GetNonClientMetrics(win);
return wxNativeFontInfo(ncm.lfMessageFont); return wxNativeFontInfo(ncm.lfMessageFont);
} }

View File

@@ -26,6 +26,7 @@
#include "wx/settings.h" #include "wx/settings.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/module.h" #include "wx/module.h"
@@ -181,8 +182,9 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
// for most (simple) controls, e.g. buttons and such but other // for most (simple) controls, e.g. buttons and such but other
// controls may prefer to use lfStatusFont or lfCaptionFont if it // controls may prefer to use lfStatusFont or lfCaptionFont if it
// is more appropriate for them // is more appropriate for them
const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
const wxNativeFontInfo const wxNativeFontInfo
info(wxMSWImpl::GetNonClientMetrics().lfMessageFont); info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont);
gs_fontDefault = new wxFont(info); gs_fontDefault = new wxFont(info);
} }
@@ -337,12 +339,14 @@ extern wxFont wxGetCCDefaultFont()
// font which is also used for the icon titles and not the stock default // font which is also used for the icon titles and not the stock default
// GUI font // GUI font
LOGFONT lf; LOGFONT lf;
if ( ::SystemParametersInfo const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
if ( wxSystemParametersInfo
( (
SPI_GETICONTITLELOGFONT, SPI_GETICONTITLELOGFONT,
sizeof(lf), sizeof(lf),
&lf, &lf,
0 0,
win
) ) ) )
{ {
return wxFont(lf); return wxFont(lf);