Generate wxDPIChangedEvent when DPI changes

This commit is contained in:
Maarten Bent
2016-10-05 21:42:33 +02:00
parent 137713e0c8
commit e3d3a0b7e8
6 changed files with 97 additions and 2 deletions

View File

@@ -641,6 +641,7 @@ class WXDLLIMPEXP_FWD_CORE wxMenuEvent;
class WXDLLIMPEXP_FWD_CORE wxContextMenuEvent; class WXDLLIMPEXP_FWD_CORE wxContextMenuEvent;
class WXDLLIMPEXP_FWD_CORE wxSysColourChangedEvent; class WXDLLIMPEXP_FWD_CORE wxSysColourChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxDisplayChangedEvent; class WXDLLIMPEXP_FWD_CORE wxDisplayChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxDPIChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxQueryNewPaletteEvent; class WXDLLIMPEXP_FWD_CORE wxQueryNewPaletteEvent;
class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent; class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxJoystickEvent; 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_CONTEXT_MENU, wxContextMenuEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent); 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_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_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent); wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent);
@@ -3044,6 +3046,32 @@ public:
virtual wxEvent *Clone() const wxOVERRIDE { return new wxDisplayChangedEvent(*this); } 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 wxEVT_PALETTE_CHANGED
*/ */
@@ -4121,6 +4149,7 @@ typedef void (wxEvtHandler::*wxDropFilesEventFunction)(wxDropFilesEvent&);
typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&); typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&);
typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&); typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&); typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
typedef void (wxEvtHandler::*wxDPIChangedEventFunction)(wxDPIChangedEvent&);
typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&); typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&); typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&); typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
@@ -4184,6 +4213,8 @@ typedef void (wxEvtHandler::*wxPressAndTapEventFunction)(wxPressAndTapEvent&);
wxEVENT_HANDLER_CAST(wxSysColourChangedEventFunction, func) wxEVENT_HANDLER_CAST(wxSysColourChangedEventFunction, func)
#define wxDisplayChangedEventHandler(func) \ #define wxDisplayChangedEventHandler(func) \
wxEVENT_HANDLER_CAST(wxDisplayChangedEventFunction, func) wxEVENT_HANDLER_CAST(wxDisplayChangedEventFunction, func)
#define wxDPIChangedEventHandler(func) \
wxEVENT_HANDLER_CAST(wxDPIChangedEventFunction, func)
#define wxUpdateUIEventHandler(func) \ #define wxUpdateUIEventHandler(func) \
wxEVENT_HANDLER_CAST(wxUpdateUIEventFunction, func) wxEVENT_HANDLER_CAST(wxUpdateUIEventFunction, func)
#define wxCloseEventHandler(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_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_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_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_SHOW(func) wx__DECLARE_EVT0(wxEVT_SHOW, wxShowEventHandler(func))
#define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func)) #define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func))
#define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func)) #define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func))

View File

@@ -587,7 +587,8 @@ public:
virtual void WXDoUpdatePendingFocus(wxWindow* WXUNUSED(win)) {} virtual void WXDoUpdatePendingFocus(wxWindow* WXUNUSED(win)) {}
// Called from WM_DPICHANGED handler for all windows to let them update // 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); void MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI);
protected: protected:

View File

@@ -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
<a href="https://docs.microsoft.com/en-us/windows/desktop/sbscs/application-manifests">"Application Manifests" documentation</a>
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 class wxPaletteChangedEvent : public wxEvent
{ {
public: public:

View File

@@ -2044,7 +2044,7 @@ public:
If the DPI is not available, returns @c wxSize(0,0) object. If the DPI is not available, returns @c wxSize(0,0) object.
@see wxDisplay::GetPPI() @see wxDisplay::GetPPI(), wxDPIChangedEvent
@since 3.1.3 @since 3.1.3
*/ */

View File

@@ -92,6 +92,7 @@
wxIMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxDPIChangedEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent); wxIMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, 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_CONTEXT_MENU, wxContextMenuEvent );
wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent ); wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent );
wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent ); wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent );
wxDEFINE_EVENT( wxEVT_DPI_CHANGED, wxDPIChangedEvent );
wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent ); wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent );
wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent ); wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent );
wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent ); wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent );

View File

@@ -4876,6 +4876,10 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
current = current->GetNext(); current = current->GetNext();
} }
wxDPIChangedEvent event(oldDPI, newDPI);
event.SetEventObject(this);
HandleWindowEvent(event);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------