Add wxWindow::WXNotifyDPIChange() for wxOSX and wxGTK
This refactors the already existing code in wxOSX to make it available in the common class and allow reusing it in wxGTK. No changes yet.
This commit is contained in:
parent
e679e5d4c2
commit
6080dca576
5 changed files with 33 additions and 28 deletions
|
|
@ -151,7 +151,6 @@ public:
|
|||
// --------------
|
||||
|
||||
void OnMouseEvent( wxMouseEvent &event );
|
||||
void OnDPIChanged( wxDPIChangedEvent& event );
|
||||
|
||||
void MacOnScroll( wxScrollEvent&event );
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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<wxWindow*>(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
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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) )
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue