X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8fc3508e77811dbce06afa7703cfbeb3b037962..bbd65eb80378f24d2e60c0721c2dfa705f98a76a:/src/osx/cocoa/window.mm diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index c26fe0dfaf..f19ebfb231 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -200,6 +200,8 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) int intchar = [s characterAtIndex: 0]; if ( intchar >= NSF1FunctionKey && intchar <= NSF24FunctionKey ) retval = WXK_F1 + (intchar - NSF1FunctionKey ); + else if ( intchar > 0 && intchar < 32 ) + retval = intchar; break; } } @@ -214,7 +216,7 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) // command key case 54: case 55: - retval = WXK_COMMAND; + retval = WXK_CONTROL; break; // caps locks key case 57: // Capslock @@ -233,7 +235,7 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) // ctrl key case 59: // Left Ctrl case 62: // Right Ctrl - retval = WXK_CONTROL; + retval = WXK_RAW_CONTROL; break; // clear key case 71: @@ -1199,13 +1201,28 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd)) updateRgn.Offset( wxpeer->MacGetLeftBorderSize() , wxpeer->MacGetTopBorderSize() ); } - if ( wxpeer->MacGetTopLevelWindow()->GetWindowStyle() & wxFRAME_SHAPED ) + // Restrict the update region to the shape of the window, if any, and also + // remember the region that we need to clear later. + wxNonOwnedWindow* const tlwParent = wxpeer->MacGetTopLevelWindow(); + const bool isTopLevel = tlwParent == wxpeer; + wxRegion clearRgn; + if ( tlwParent->GetWindowStyle() & wxFRAME_SHAPED ) { + if ( isTopLevel ) + clearRgn = updateRgn; + int xoffset = 0, yoffset = 0; - wxRegion rgn = wxpeer->MacGetTopLevelWindow()->GetShape(); + wxRegion rgn = tlwParent->GetShape(); wxpeer->MacRootWindowToWindow( &xoffset, &yoffset ); rgn.Offset( xoffset, yoffset ); updateRgn.Intersect(rgn); + + if ( isTopLevel ) + { + // Exclude the window shape from the region to be cleared below. + rgn.Xor(wxpeer->GetSize()); + clearRgn.Intersect(rgn); + } } wxpeer->GetUpdateRegion() = updateRgn; @@ -1257,6 +1274,35 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd)) CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height ); CGContextScaleCTM( context, 1, -1 ); } + + if ( isTopLevel ) + { + // We also need to explicitly draw the part of the top level window + // outside of its region with transparent colour to ensure that it is + // really transparent. + if ( clearRgn.IsOk() ) + { + wxMacCGContextStateSaver saveState(context); + wxWindowDC dc(wxpeer); + dc.SetBackground(wxBrush(wxTransparentColour)); + dc.SetDeviceClippingRegion(clearRgn); + dc.Clear(); + } + +#if wxUSE_GRAPHICS_CONTEXT + // If the window shape is defined by a path, stroke the path to show + // the window border. + const wxGraphicsPath& path = tlwParent->GetShapePath(); + if ( !path.IsNull() ) + { + CGContextSetLineWidth(context, 1); + CGContextSetStrokeColorWithColor(context, wxLIGHT_GREY->GetCGColor()); + CGContextAddPath(context, (CGPathRef) path.GetNativePath()); + CGContextStrokePath(context); + } +#endif // wxUSE_GRAPHICS_CONTEXT + } + wxpeer->MacPaintChildrenBorders(); wxpeer->MacSetCGContextRef( NULL ); CGContextRestoreGState( context ); @@ -1953,7 +1999,11 @@ void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap ) { if ( [m_osxView respondsToSelector:@selector(setImage:)] ) { - [m_osxView setImage:bitmap.GetNSImage()]; + if (bitmap.IsOk()) + [m_osxView setImage:bitmap.GetNSImage()]; + else + [m_osxView setImage:nil]; + [m_osxView setNeedsDisplay:YES]; } } @@ -2141,6 +2191,7 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) { // eventually we could setup a doCommandBySelector catcher and retransform this into the wx key chars wxKeyEvent wxevent2(wxevent) ; + wxevent2.SetEventType(wxEVT_CHAR); wxevent2.m_keyCode = keycode; result = GetWXPeer()->OSXHandleKeyEvent(wxevent2); }