Merge branch 'osx-dpi'
DPI-related improvements in wxOSX. See https://github.com/wxWidgets/wxWidgets/pull/1984
This commit is contained in:
@@ -120,6 +120,8 @@ public:
|
|||||||
virtual bool UnregisterHotKey(int hotkeyId) wxOVERRIDE;
|
virtual bool UnregisterHotKey(int hotkeyId) wxOVERRIDE;
|
||||||
#endif // wxUSE_HOTKEY
|
#endif // wxUSE_HOTKEY
|
||||||
|
|
||||||
|
virtual wxSize GetDPI() const wxOVERRIDE;
|
||||||
|
|
||||||
#if wxUSE_DRAG_AND_DROP
|
#if wxUSE_DRAG_AND_DROP
|
||||||
virtual void SetDropTarget( wxDropTarget *dropTarget ) wxOVERRIDE;
|
virtual void SetDropTarget( wxDropTarget *dropTarget ) wxOVERRIDE;
|
||||||
|
|
||||||
@@ -149,6 +151,7 @@ public:
|
|||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
void OnMouseEvent( wxMouseEvent &event );
|
void OnMouseEvent( wxMouseEvent &event );
|
||||||
|
void OnDPIChanged( wxDPIChangedEvent& event );
|
||||||
|
|
||||||
void MacOnScroll( wxScrollEvent&event );
|
void MacOnScroll( wxScrollEvent&event );
|
||||||
|
|
||||||
@@ -291,6 +294,9 @@ public:
|
|||||||
// internal response to size events
|
// internal response to size events
|
||||||
virtual void MacOnInternalSize() {}
|
virtual void MacOnInternalSize() {}
|
||||||
|
|
||||||
|
// Return the DPI corresponding to the given scale factor.
|
||||||
|
static wxSize OSXMakeDPIFromScaleFactor(double scaleFactor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// For controls like radio buttons which are genuinely composite
|
// For controls like radio buttons which are genuinely composite
|
||||||
wxList m_subControls;
|
wxList m_subControls;
|
||||||
|
@@ -34,6 +34,7 @@ wxScreenDCImpl::wxScreenDCImpl( wxDC *owner ) :
|
|||||||
SetGraphicsContext( wxGraphicsContext::Create() );
|
SetGraphicsContext( wxGraphicsContext::Create() );
|
||||||
m_ok = true ;
|
m_ok = true ;
|
||||||
#endif
|
#endif
|
||||||
|
m_contentScaleFactor = wxOSXGetMainScreenContentScaleFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxScreenDCImpl::~wxScreenDCImpl()
|
wxScreenDCImpl::~wxScreenDCImpl()
|
||||||
|
@@ -321,6 +321,7 @@ static void *EffectiveAppearanceContext = &EffectiveAppearanceContext;
|
|||||||
- (BOOL)windowShouldClose:(id)window;
|
- (BOOL)windowShouldClose:(id)window;
|
||||||
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
|
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
|
||||||
- (void)windowWillEnterFullScreen:(NSNotification *)notification;
|
- (void)windowWillEnterFullScreen:(NSNotification *)notification;
|
||||||
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -613,6 +614,42 @@ extern int wxOSXGetIdFromSelector(SEL action );
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html
|
||||||
|
|
||||||
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
NSWindow* theWindow = (NSWindow*)[notification object];
|
||||||
|
wxNonOwnedWindowCocoaImpl* windowimpl = [theWindow WX_implementation];
|
||||||
|
wxNonOwnedWindow* wxpeer = windowimpl ? windowimpl->GetWXPeer() : NULL;
|
||||||
|
if (wxpeer)
|
||||||
|
{
|
||||||
|
CGFloat newBackingScaleFactor = [theWindow backingScaleFactor];
|
||||||
|
CGFloat oldBackingScaleFactor = [[[notification userInfo]
|
||||||
|
objectForKey:@"NSBackingPropertyOldScaleFactorKey"]
|
||||||
|
doubleValue];
|
||||||
|
if (newBackingScaleFactor != oldBackingScaleFactor)
|
||||||
|
{
|
||||||
|
const wxSize oldDPI = wxWindow::OSXMakeDPIFromScaleFactor(oldBackingScaleFactor);
|
||||||
|
const wxSize newDPI = wxWindow::OSXMakeDPIFromScaleFactor(newBackingScaleFactor);
|
||||||
|
|
||||||
|
wxDPIChangedEvent event(oldDPI, newDPI);
|
||||||
|
event.SetEventObject(wxpeer);
|
||||||
|
wxpeer->HandleWindowEvent(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NSColorSpace *newColorSpace = [theWindow colorSpace];
|
||||||
|
NSColorSpace *oldColorSpace = [[notification userInfo]
|
||||||
|
objectForKey:@"NSBackingPropertyOldColorSpaceKey"];
|
||||||
|
if (![newColorSpace isEqual:oldColorSpace])
|
||||||
|
{
|
||||||
|
wxSysColourChangedEvent event;
|
||||||
|
event.SetEventObject(wxpeer);
|
||||||
|
wxpeer->HandleWindowEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)addObservers:(NSWindow*)win
|
- (void)addObservers:(NSWindow*)win
|
||||||
{
|
{
|
||||||
[win addObserver:self forKeyPath:@"effectiveAppearance"
|
[win addObserver:self forKeyPath:@"effectiveAppearance"
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
|
#include "wx/math.h"
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/panel.h"
|
#include "wx/panel.h"
|
||||||
@@ -79,6 +80,7 @@
|
|||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
|
wxBEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
|
||||||
EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
|
EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
|
||||||
|
EVT_DPI_CHANGED(wxWindowMac::OnDPIChanged)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
#define wxMAC_DEBUG_REDRAW 0
|
#define wxMAC_DEBUG_REDRAW 0
|
||||||
@@ -2345,6 +2347,25 @@ 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) )
|
void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -2599,6 +2620,25 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event )
|
|||||||
return handled ;
|
return handled ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxSize wxWindowMac::OSXMakeDPIFromScaleFactor(double scaleFactor)
|
||||||
|
{
|
||||||
|
const int dpi = wxRound(scaleFactor*72.0);
|
||||||
|
|
||||||
|
return wxSize(dpi, dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxWindowMac::GetDPI() const
|
||||||
|
{
|
||||||
|
double scaleFactor;
|
||||||
|
if ( wxNonOwnedWindow* tlw = MacGetTopLevelWindow() )
|
||||||
|
scaleFactor = tlw->GetContentScaleFactor();
|
||||||
|
else
|
||||||
|
scaleFactor = wxOSXGetMainScreenContentScaleFactor();
|
||||||
|
|
||||||
|
return OSXMakeDPIFromScaleFactor(scaleFactor);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// wxWidgetImpl
|
// wxWidgetImpl
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user