diff --git a/include/wx/event.h b/include/wx/event.h index c13e7336b1..062351d60d 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -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); @@ -3044,6 +3046,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 */ @@ -4121,6 +4149,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&); @@ -4184,6 +4213,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) \ @@ -4443,6 +4474,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)) diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 318033b2a3..cd28a4deaa 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -587,7 +587,8 @@ public: 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. + // 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: diff --git a/interface/wx/event.h b/interface/wx/event.h index 3b80a529fb..e9e124998d 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -3318,6 +3318,62 @@ public: }; + +/** + @class wxDPIChangedEvent + + Event sent when the resolution (measured in dots-per-inch, or DPI) of the + monitor a window is on changes. + + The event is sent to each wxTopLevelWindow affected by the change, and all + its children recursively. For example, this event is sent to the window + when it is moved, by the user, from a display using some DPI value to + another display using a different DPI value. It also sent to all program + windows on the given display if its DPI changes due to a change in the + system settings. + + Currently this event is generated by wxMSW port if only and only if the + MSW application runs under Windows 10 Creators Update (v1703) or later and + is marked as being "per-monitor DPI aware", i.e. contains a @c dpiAwareness + tag with the value "PerMonitorV2" in its manifest (see Microsoft + "Application Manifests" documentation + for more details). + + @note Per-monitor DPI support is an experimental feature that is still in + development. It might not work correctly for some controls. + + @beginEventTable{wxDPIChangedEvent} + @event{EVT_DPI_CHANGED(func)} + Process a @c wxEVT_DPI_CHANGED event. + @endEventTable + + @since 3.1.3 + + @library{wxcore} + @category{events} + + @see @ref overview_events +*/ +class wxDPIChangedEvent : public wxEvent +{ +public: + /** + Returns the old DPI. + + @since 3.1.3 + */ + wxSize GetOldDPI() const; + + /** + Returns the new DPI. + + @since 3.1.3 + */ + wxSize GetNewDPI() const; +}; + + + class wxPaletteChangedEvent : public wxEvent { public: diff --git a/interface/wx/window.h b/interface/wx/window.h index 8628ce5d26..d8d8fff28c 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -2044,7 +2044,7 @@ public: If the DPI is not available, returns @c wxSize(0,0) object. - @see wxDisplay::GetPPI() + @see wxDisplay::GetPPI(), wxDPIChangedEvent @since 3.1.3 */ diff --git a/src/common/event.cpp b/src/common/event.cpp index 7d269005ba..b0bed5a4ce 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -92,6 +92,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent); + wxIMPLEMENT_DYNAMIC_CLASS(wxDPIChangedEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent); @@ -302,6 +303,7 @@ wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT, wxMenuEvent ); wxDEFINE_EVENT( wxEVT_CONTEXT_MENU, wxContextMenuEvent ); wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent ); wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent ); +wxDEFINE_EVENT( wxEVT_DPI_CHANGED, wxDPIChangedEvent ); wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent ); wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent ); wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent ); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index f64a7d30a1..ec12b9cad6 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4876,6 +4876,10 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI) current = current->GetNext(); } + + wxDPIChangedEvent event(oldDPI, newDPI); + event.SetEventObject(this); + HandleWindowEvent(event); } // ---------------------------------------------------------------------------