diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 10201fd165..dff2181a70 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -151,7 +151,6 @@ public: // -------------- void OnMouseEvent( wxMouseEvent &event ); - void OnDPIChanged( wxDPIChangedEvent& event ); void MacOnScroll( wxScrollEvent&event ); diff --git a/include/wx/window.h b/include/wx/window.h index b58442515c..e596814923 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1675,6 +1675,10 @@ public: #ifdef wxHAS_DPI_INDEPENDENT_PIXELS // Return the DPI corresponding to the given scale factor. static wxSize MakeDPIFromScaleFactor(double scaleFactor); + + // Notify all non-top-level children of the given (typically top-level + // itself) window about the DPI change. + void WXNotifyDPIChange(double oldScaleFactor, double newScaleFactor); #endif // wxHAS_DPI_INDEPENDENT_PIXELS protected: diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 3285d8053a..b101088047 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -2835,6 +2835,34 @@ wxSize wxWindowBase::MakeDPIFromScaleFactor(double scaleFactor) return wxDisplay::GetStdPPI()*scaleFactor; } +namespace +{ + +// Send the DPI change event to all children recursively. +void NotifyAboutDPIChange(wxWindow* win, wxDPIChangedEvent& event) +{ + for ( const auto child : win->GetChildren() ) + { + // Top level windows will get their own WXNotifyDPIChange(). + if ( child->IsTopLevel() ) + continue; + + NotifyAboutDPIChange(child, event); + } + + event.SetEventObject(win); + win->HandleWindowEvent(event); +} + +} // anonymous namespace +void wxWindowBase::WXNotifyDPIChange(double oldScaleFactor, double newScaleFactor) +{ + wxDPIChangedEvent event(MakeDPIFromScaleFactor(oldScaleFactor), + MakeDPIFromScaleFactor(newScaleFactor)); + + NotifyAboutDPIChange(static_cast(this), event); +} + // In this case logical pixels are DIPs, so we don't need to define conversion // to/from them (or, rather, they are already defined as trivial inline // functions in the header), but we do need to define conversions to/from diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index e70f799585..834ce75191 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -674,13 +674,7 @@ static void SendFullScreenWindowEvent(NSNotification* notification, bool fullscr doubleValue]; if (newBackingScaleFactor != oldBackingScaleFactor) { - const wxSize oldDPI = wxWindow::MakeDPIFromScaleFactor(oldBackingScaleFactor); - const wxSize newDPI = wxWindow::MakeDPIFromScaleFactor(newBackingScaleFactor); - - wxDPIChangedEvent event(oldDPI, newDPI); - event.SetEventObject(wxpeer); - wxpeer->HandleWindowEvent(event); - + wxpeer->WXNotifyDPIChange(oldBackingScaleFactor, newBackingScaleFactor); } NSColorSpace *newColorSpace = [theWindow colorSpace]; diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index a1131d0ab9..6154fd8757 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -79,7 +79,6 @@ wxBEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) - EVT_DPI_CHANGED(wxWindowMac::OnDPIChanged) wxEND_EVENT_TABLE() #define wxMAC_DEBUG_REDRAW 0 @@ -2321,25 +2320,6 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) } } -// propagate the dpi changed event to the subwindows -void wxWindowMac::OnDPIChanged(wxDPIChangedEvent& event) -{ - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - while ( node ) - { - // Only propagate to non-top-level windows - wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() ) - { - wxDPIChangedEvent event2( event.GetOldDPI(), event.GetNewDPI() ); - event2.SetEventObject(win); - win->GetEventHandler()->ProcessEvent(event2); - } - - node = node->GetNext(); - } -} - void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) ) { }