Merge branch 'per-monitor-dpi-aware-framework' of https://github.com/MaartenBent/wxWidgets

Add preliminary support for per-monitor DPI awareness to wxMSW.

Individual controls still need to be fixed, so this support is still
experimental/unfinished for now.

See https://github.com/wxWidgets/wxWidgets/pull/1499
This commit is contained in:
Vadim Zeitlin
2019-08-27 12:59:56 +02:00
18 changed files with 335 additions and 28 deletions

View File

@@ -2830,6 +2830,7 @@ WX_MSW_DECLARE_HANDLE(HBITMAP);
WX_MSW_DECLARE_HANDLE(HIMAGELIST);
WX_MSW_DECLARE_HANDLE(HGLOBAL);
WX_MSW_DECLARE_HANDLE(HDC);
WX_MSW_DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
typedef WXHINSTANCE WXHMODULE;
#undef WX_MSW_DECLARE_HANDLE

View File

@@ -641,6 +641,7 @@ class WXDLLIMPEXP_FWD_CORE wxMenuEvent;
class WXDLLIMPEXP_FWD_CORE wxContextMenuEvent;
class WXDLLIMPEXP_FWD_CORE wxSysColourChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxDisplayChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxDPIChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxQueryNewPaletteEvent;
class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxJoystickEvent;
@@ -793,6 +794,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_HIGHLIGHT, wxMenuEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CONTEXT_MENU, wxContextMenuEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DPI_CHANGED, wxDPIChangedEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent);
@@ -3031,6 +3033,32 @@ public:
virtual wxEvent *Clone() const wxOVERRIDE { return new wxDisplayChangedEvent(*this); }
};
/*
wxEVT_DPI_CHANGED
*/
class WXDLLIMPEXP_CORE wxDPIChangedEvent : public wxEvent
{
public:
explicit
wxDPIChangedEvent(const wxSize& oldDPI = wxDefaultSize,
const wxSize& newDPI = wxDefaultSize)
: wxEvent(0, wxEVT_DPI_CHANGED),
m_oldDPI(oldDPI),
m_newDPI(newDPI)
{ }
wxSize GetOldDPI() const { return m_oldDPI; }
wxSize GetNewDPI() const { return m_newDPI; }
virtual wxEvent *Clone() const wxOVERRIDE { return new wxDPIChangedEvent(*this); }
private:
wxSize m_oldDPI;
wxSize m_newDPI;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDPIChangedEvent);
};
/*
wxEVT_PALETTE_CHANGED
*/
@@ -4108,6 +4136,7 @@ typedef void (wxEvtHandler::*wxDropFilesEventFunction)(wxDropFilesEvent&);
typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&);
typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
typedef void (wxEvtHandler::*wxDPIChangedEventFunction)(wxDPIChangedEvent&);
typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
@@ -4171,6 +4200,8 @@ typedef void (wxEvtHandler::*wxPressAndTapEventFunction)(wxPressAndTapEvent&);
wxEVENT_HANDLER_CAST(wxSysColourChangedEventFunction, func)
#define wxDisplayChangedEventHandler(func) \
wxEVENT_HANDLER_CAST(wxDisplayChangedEventFunction, func)
#define wxDPIChangedEventHandler(func) \
wxEVENT_HANDLER_CAST(wxDPIChangedEventFunction, func)
#define wxUpdateUIEventHandler(func) \
wxEVENT_HANDLER_CAST(wxUpdateUIEventFunction, func)
#define wxCloseEventHandler(func) \
@@ -4430,6 +4461,7 @@ typedef void (wxEvtHandler::*wxPressAndTapEventFunction)(wxPressAndTapEvent&);
#define EVT_INIT_DIALOG(func) wx__DECLARE_EVT0(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(func))
#define EVT_SYS_COLOUR_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler(func))
#define EVT_DISPLAY_CHANGED(func) wx__DECLARE_EVT0(wxEVT_DISPLAY_CHANGED, wxDisplayChangedEventHandler(func))
#define EVT_DPI_CHANGED(func) wx__DECLARE_EVT0(wxEVT_DPI_CHANGED, wxDPIChangedEventHandler(func))
#define EVT_SHOW(func) wx__DECLARE_EVT0(wxEVT_SHOW, wxShowEventHandler(func))
#define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func))
#define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func))

View File

@@ -501,6 +501,13 @@ public:
// account as well.
static int GetNumericWeightOf(wxFontWeight weight);
// Some ports need to modify the font object when the DPI of the window it
// is used with changes, this function can be used to do it.
//
// Currently it is only used in wxMSW and is not considered to be part of
// wxWidgets public API.
virtual void WXAdjustToPPI(const wxSize& WXUNUSED(ppi)) { }
// this doesn't do anything and is kept for compatibility only
#if WXWIN_COMPATIBILITY_2_8
wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no);)

View File

@@ -120,25 +120,17 @@ public:
#elif defined(__WXMSW__)
wxNativeFontInfo(const LOGFONT& lf_)
: lf(lf_),
pointSize(GetPointSizeFromLogFontHeight(lf.lfHeight))
pointSize(GetPointSizeAtPPI(lf.lfHeight))
{
}
// MSW-specific: get point size from LOGFONT height using the default DPI.
static float GetPointSizeFromLogFontHeight(int height);
// MSW-specific: get point size from LOGFONT height using specified DPI,
// or screen DPI when 0.
static float GetPointSizeAtPPI(int lfHeight, int ppi = 0);
// MSW-specific: get the height value in pixels using LOGFONT convention
// (i.e. negative) corresponding to the given size in points and DPI.
static int GetLogFontHeightAtPPI(float size, int ppi)
{
return -wxRound(size * ppi / 72.0);
}
// And the same thing for the size of this font.
int GetLogFontHeightAtPPI(int ppi) const
{
return GetLogFontHeightAtPPI(pointSize, ppi);
}
static int GetLogFontHeightAtPPI(float size, int ppi);
LOGFONT lf;

View File

@@ -120,6 +120,8 @@ public:
virtual bool IsFixedWidth() const wxOVERRIDE;
virtual void WXAdjustToPPI(const wxSize& ppi) wxOVERRIDE;
wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants ie: wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD")
wxFont(int size,
int family,

View File

@@ -23,7 +23,11 @@
#endif
#ifndef WM_PRINTCLIENT
#define WM_PRINTCLIENT 0x318
#define WM_PRINTCLIENT 0x0318
#endif
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
#ifndef DT_HIDEPREFIX

View File

@@ -165,6 +165,9 @@ protected:
int& x, int& y,
int& w, int& h) const wxOVERRIDE;
// WM_DPICHANGED handler.
bool HandleDPIChange(const wxSize& newDPI, const wxRect& newRect);
// This field contains the show command to use when showing the window the
// next time and also indicates whether the window should be considered
// being iconized or maximized (which may be different from whether it's
@@ -191,6 +194,14 @@ protected:
wxWindowRef m_winLastFocused;
private:
// Keep track of the DPI used in this window. So when per-monitor dpi
// awareness is enabled, both old and new DPI are known for
// wxDPIChangedEvent and wxWindow::MSWUpdateOnDPIChange.
wxSize m_activeDPI;
// This window supports handling per-monitor DPI awareness when the
// application manifest contains <dpiAwareness>PerMonitorV2</dpiAwareness>.
bool m_perMonitorDPIaware;
// The system menu: initially NULL but can be set (once) by
// MSWGetSystemMenu(). Owned by this window.

View File

@@ -586,7 +586,17 @@ public:
// Should be overridden by all classes storing the "last focused" window.
virtual void WXDoUpdatePendingFocus(wxWindow* WXUNUSED(win)) {}
// Called from WM_DPICHANGED handler for all windows to let them update
// any sizes and fonts used internally when the DPI changes and generate
// wxDPIChangedEvent to let the user code do the same thing as well.
void MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI);
protected:
// Called from MSWUpdateOnDPIChange() specifically to update the control
// font, as this may need to be done differently for some specific native
// controls. The default version updates m_font of this window.
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI);
// this allows you to implement standard control borders without
// repeating the code in different classes that are not derived from
// wxControl