X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/68654a8295dfa285e712f7bbd9607a703c245969..beedefb9401e8a0c2867aaf163ac6ea42e6dd6a7:/src/mac/carbon/dccg.cpp diff --git a/src/mac/carbon/dccg.cpp b/src/mac/carbon/dccg.cpp index 9beef3c3c8..f73b9be63b 100755 --- a/src/mac/carbon/dccg.cpp +++ b/src/mac/carbon/dccg.cpp @@ -72,12 +72,16 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) : if ( win ) { - int x = 0 , y = 0; - win->MacWindowToRootWindow( &x,&y ) ; - // get area including focus rect - CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ; - if ( !EmptyRgn( m_newClip ) ) - OffsetRgn( m_newClip , x , y ) ; + // guard against half constructed objects, this just leads to a empty clip + if( win->GetPeer() ) + { + int x = 0 , y = 0; + win->MacWindowToRootWindow( &x,&y ) ; + // get area including focus rect + CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ; + if ( !EmptyRgn( m_newClip ) ) + OffsetRgn( m_newClip , x , y ) ; + } SetClip( m_newClip ) ; } @@ -463,68 +467,6 @@ void wxMacCGContext::SetBrush( const wxBrush &brush ) } } -// snippets from Sketch Sample from Apple : - -#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" -/* - This function locates, opens, and returns the profile reference for the calibrated - Generic RGB color space. It is up to the caller to call CMCloseProfile when done - with the profile reference this function returns. -*/ -CMProfileRef wxMacOpenGenericProfile(void) -{ - static CMProfileRef cachedRGBProfileRef = NULL; - - // we only create the profile reference once - if (cachedRGBProfileRef == NULL) - { - CMProfileLocation loc; - - loc.locType = cmPathBasedProfile; - strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr); - - verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) ); - } - - if (cachedRGBProfileRef) - { - // clone the profile reference so that the caller has their own reference, not our cached one - CMCloneProfileRef(cachedRGBProfileRef); - } - - return cachedRGBProfileRef; -} - -/* - Return the generic RGB color space. This is a 'get' function and the caller should - not release the returned value unless the caller retains it first. Usually callers - of this routine will immediately use the returned colorspace with CoreGraphics - so they typically do not need to retain it themselves. - - This function creates the generic RGB color space once and hangs onto it so it can - return it whenever this function is called. -*/ - -CGColorSpaceRef wxMacGetGenericRGBColorSpace() -{ - static CGColorSpaceRef genericRGBColorSpace = NULL; - - if (genericRGBColorSpace == NULL) - { - CMProfileRef genericRGBProfile = wxMacOpenGenericProfile(); - - if (genericRGBProfile) - { - genericRGBColorSpace = CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile); - wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ) ; - - // we opened the profile so it is up to us to close it - CMCloseProfile(genericRGBProfile); - } - } - return genericRGBColorSpace; -} - void AddEllipticArcToPath(CGContextRef c, CGPoint center, float a, float b, float fromDegree , float toDegree ) { CGContextSaveGState(c); @@ -613,7 +555,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxCoord ww = XLOG2DEVREL(w); wxCoord hh = YLOG2DEVREL(h); - CGContextRef cg = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ) ; HIRect r = CGRectMake( xx , yy , ww , hh ) ; HIViewDrawCGImage( cg , &r , image ) ; @@ -632,7 +574,7 @@ void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) wxCoord ww = XLOG2DEVREL(w); wxCoord hh = YLOG2DEVREL(h); - CGContextRef cg = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGRect r = CGRectMake( 00 , 00 , ww , hh ) ; CGContextSaveGState(cg); CGContextTranslateCTM(cg, xx , yy + hh ); @@ -651,7 +593,7 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei ww = XLOG2DEVREL(width); hh = YLOG2DEVREL(height); - CGContextRef cgContext = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGRect clipRect = CGRectMake( xx ,yy , ww, hh ) ; CGContextClipToRect( cgContext , clipRect ) ; @@ -728,7 +670,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) void wxDC::DestroyClippingRegion() { // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; - CGContextRef cgContext = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRestoreGState( cgContext ); CGContextSaveGState( cgContext ); SetPen( m_pen ) ; @@ -1246,7 +1188,7 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) 0 ) ; CGContextClosePath(ctx); - CGContextDrawPath( ctx , kCGPathFillStroke ) ; + CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ; } else { @@ -1317,7 +1259,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, } if ( blit.Ok() ) { - CGContextRef cg = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ; HIRect r = CGRectMake( xxdest , yydest , wwdest , hhdest ) ; HIViewDrawCGImage( cg , &r , image ) ; @@ -1328,7 +1270,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, else { /* - CGContextRef cg = dynamic_cast(source->GetGraphicContext())->GetNativeContext() ; + CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ; void *data = CGBitmapContextGetData( cg ) ; */ return FALSE ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ; @@ -1406,7 +1348,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, atsuTags, atsuSizes, atsuValues ) ; } { - CGContextRef cgContext = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; ATSUAttributeTag atsuTags[] = { kATSUCGContextTag , @@ -1461,13 +1403,13 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, IntToFixed(drawX) , IntToFixed(drawY) , &rect ); wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); - CGContextSaveGState(dynamic_cast(m_graphicContext)->GetNativeContext()); - CGContextTranslateCTM(dynamic_cast(m_graphicContext)->GetNativeContext(), drawX, drawY); - CGContextScaleCTM(dynamic_cast(m_graphicContext)->GetNativeContext(), 1, -1); + CGContextSaveGState(((wxMacCGContext*)(m_graphicContext))->GetNativeContext()); + CGContextTranslateCTM(((wxMacCGContext*)(m_graphicContext))->GetNativeContext(), drawX, drawY); + CGContextScaleCTM(((wxMacCGContext*)(m_graphicContext))->GetNativeContext(), 1, -1); status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, IntToFixed(0) , IntToFixed(0) ); wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); - CGContextRestoreGState( dynamic_cast(m_graphicContext)->GetNativeContext() ) ; + CGContextRestoreGState( ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ) ; CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); @@ -1652,7 +1594,7 @@ void wxDC::Clear(void) if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) { HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ; - CGContextRef cg = dynamic_cast(m_graphicContext)->GetNativeContext() ; + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; switch( m_backgroundBrush.MacGetBrushKind() ) { case kwxMacBrushTheme : @@ -1682,7 +1624,7 @@ void wxDC::Clear(void) { wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 - if ( HIThemeDrawBackground != 0 ) + if ( UMAGetSystemVersion() >= 0x1030 ) { HIThemeBackgroundDrawInfo drawInfo ; drawInfo.version = 0 ;