Merge branch 'osx-fixes'
Fix several Mac-specific problems. Closes https://github.com/wxWidgets/wxWidgets/pull/1990
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
|
||||
// mac
|
||||
#include "wx/osx/private.h"
|
||||
#include "wx/display.h"
|
||||
|
||||
#if defined(WXMAKINGDLL_CORE)
|
||||
# include <mach-o/dyld.h>
|
||||
@@ -324,6 +325,18 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __WXOSX_COCOA__
|
||||
void wxCGDisplayReconfigurationCallBack(CGDirectDisplayID WXUNUSED(display),
|
||||
CGDisplayChangeSummaryFlags WXUNUSED(flags),
|
||||
void* WXUNUSED(userInfo))
|
||||
{
|
||||
// flags could be tested to know about removal, addition etc. right now
|
||||
// this is called multiple times for a change but for invalidating the
|
||||
// cache these things don't matter yet
|
||||
wxDisplay::InvalidateCache();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool wxApp::OnInitGui()
|
||||
{
|
||||
if ( !wxAppBase::OnInitGui() )
|
||||
@@ -332,6 +345,10 @@ bool wxApp::OnInitGui()
|
||||
if ( !DoInitGui() )
|
||||
return false;
|
||||
|
||||
#ifdef __WXOSX_COCOA__
|
||||
CGDisplayRegisterReconfigurationCallback(wxCGDisplayReconfigurationCallBack, NULL);
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
@@ -997,6 +997,13 @@ void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width,
|
||||
|
||||
bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
|
||||
{
|
||||
// macOS caches the contour of the drawn area, so when the region is changed and the content view redrawn
|
||||
// the shape of the tlw does not change, this is a workaround I found that leads to a contour-refresh ...
|
||||
NSRect formerFrame = [m_macWindow frame];
|
||||
NSSize formerSize = [NSWindow contentRectForFrameRect:formerFrame styleMask:[m_macWindow styleMask]].size;
|
||||
[m_macWindow setContentSize:NSMakeSize(10,10)];
|
||||
[m_macWindow setContentSize:formerSize];
|
||||
|
||||
[m_macWindow setOpaque:NO];
|
||||
[m_macWindow setBackgroundColor:[NSColor clearColor]];
|
||||
|
||||
|
||||
@@ -32,6 +32,30 @@
|
||||
|
||||
#include "wx/osx/private.h"
|
||||
|
||||
@interface wxStaticBitmapView : NSImageView
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation wxStaticBitmapView
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
static BOOL initialized = NO;
|
||||
if (!initialized)
|
||||
{
|
||||
initialized = YES;
|
||||
wxOSXCocoaClassAddWXMethods( self );
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
self = [super initWithFrame:frameRect];
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
class wxStaticBitmapCocoaImpl : public wxWidgetCocoaImpl
|
||||
{
|
||||
public :
|
||||
@@ -51,7 +75,7 @@ public :
|
||||
|
||||
void SetScaleMode(wxStaticBitmap::ScaleMode scaleMode)
|
||||
{
|
||||
NSImageView* v = (NSImageView*) m_osxView;
|
||||
wxStaticBitmapView* v = (wxStaticBitmapView*) m_osxView;
|
||||
|
||||
NSImageScaling scaling = NSImageScaleNone;
|
||||
switch ( scaleMode )
|
||||
@@ -92,7 +116,7 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticBitmap( wxWindowMac* wxpeer,
|
||||
long WXUNUSED(extraStyle))
|
||||
{
|
||||
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
|
||||
NSImageView* v = [[NSImageView alloc] initWithFrame:r];
|
||||
wxStaticBitmapView* v = [[wxStaticBitmapView alloc] initWithFrame:r];
|
||||
|
||||
wxWidgetCocoaImpl* c = new wxStaticBitmapCocoaImpl( wxpeer, v );
|
||||
return c;
|
||||
|
||||
@@ -3083,6 +3083,13 @@ void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &hei
|
||||
{
|
||||
left = top = 0;
|
||||
GetSize( width, height );
|
||||
|
||||
int leftinset, topinset, rightinset, bottominset;
|
||||
GetLayoutInset( leftinset, topinset, rightinset, bottominset);
|
||||
left += leftinset;
|
||||
top += topinset;
|
||||
width -= leftinset + rightinset;
|
||||
height -= topinset + bottominset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -510,6 +510,7 @@ void *wxNonOwnedWindow::OSXGetViewOrWindow() const
|
||||
bool wxNonOwnedWindow::DoClearShape()
|
||||
{
|
||||
m_shape.Clear();
|
||||
m_shapePath = wxGraphicsPath();
|
||||
|
||||
wxSize sz = GetClientSize();
|
||||
wxRegion region(0, 0, sz.x, sz.y);
|
||||
@@ -519,11 +520,13 @@ bool wxNonOwnedWindow::DoClearShape()
|
||||
|
||||
bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region)
|
||||
{
|
||||
m_shapePath = wxGraphicsPath();
|
||||
m_shape = region;
|
||||
|
||||
// set the native content view to transparency, this is an implementation detail
|
||||
// no reflected in the wx BackgroundStyle
|
||||
GetPeer()->SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
|
||||
GetPeer()->SetNeedsDisplay();
|
||||
|
||||
return m_nowpeer->SetShape(region);
|
||||
}
|
||||
@@ -534,8 +537,6 @@ bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region)
|
||||
|
||||
bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path)
|
||||
{
|
||||
m_shapePath = path;
|
||||
|
||||
// Convert the path to wxRegion by rendering the path on a window-sized
|
||||
// bitmap, creating a mask from it and finally creating the region from
|
||||
// this mask.
|
||||
@@ -548,12 +549,18 @@ bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path)
|
||||
|
||||
wxScopedPtr<wxGraphicsContext> context(wxGraphicsContext::Create(dc));
|
||||
context->SetBrush(*wxWHITE);
|
||||
context->FillPath(m_shapePath);
|
||||
context->FillPath(path);
|
||||
}
|
||||
|
||||
bmp.SetMask(new wxMask(bmp, *wxBLACK));
|
||||
|
||||
return DoSetRegionShape(wxRegion(bmp));
|
||||
// the shape path has to be set AFTER the region is set, because that method
|
||||
// clears any former path
|
||||
bool success = DoSetRegionShape(wxRegion(bmp));
|
||||
if ( success )
|
||||
m_shapePath = path;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user