X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b014adcc3e0c5ebb68525589eba0568c300be388..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/mac/carbon/dccg.cpp diff --git a/src/mac/carbon/dccg.cpp b/src/mac/carbon/dccg.cpp index 56c2379701..c5ed4a9bae 100755 --- a/src/mac/carbon/dccg.cpp +++ b/src/mac/carbon/dccg.cpp @@ -40,9 +40,7 @@ using namespace std ; #include #include -#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) -#endif //----------------------------------------------------------------------------- // constants @@ -72,12 +70,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 ) ; } @@ -105,6 +107,20 @@ wxMacWindowStateSaver::~wxMacWindowStateSaver() SetThemeDrawingState( m_themeDrawingState , true ) ; } +// minimal implementation only used for appearance drawing < 10.3 + +wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : + m_ph( (GrafPtr) dc->m_macPort ) +{ + wxASSERT( dc->Ok() ) ; + m_dc = dc ; +// dc->MacSetupPort(&m_ph) ; +} +wxMacPortSetter::~wxMacPortSetter() +{ +// m_dc->MacCleanupPort(&m_ph) ; +} + //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- @@ -191,11 +207,12 @@ wxMacCGContext::~wxMacCGContext() { if ( m_cgContext ) { + CGContextSynchronize( m_cgContext ) ; CGContextRestoreGState( m_cgContext ) ; CGContextRestoreGState( m_cgContext ) ; } if ( m_qdPort ) - QDEndCGContext( m_qdPort , &m_cgContext ) ; + CGContextRelease( m_cgContext ) ; } @@ -252,9 +269,10 @@ void wxMacCGContext::FillPath( const wxGraphicPath *p , const wxColor &fillColor wxGraphicPath* wxMacCGContext::CreatePath() { - CGContextRef cg = GetNativeContext() ; // make sure that we now have a real cgref, before doing // anything with paths + CGContextRef cg = GetNativeContext() ; + cg = NULL ; return new wxMacCGPath() ; } @@ -266,7 +284,7 @@ CGContextRef wxMacCGContext::GetNativeContext() { Rect bounds ; GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ; - OSStatus status = QDBeginCGContext( (CGrafPtr) m_qdPort , &m_cgContext ) ; + OSStatus status = CreateCGContextForPort((CGrafPtr) m_qdPort , &m_cgContext) ; CGContextSaveGState( m_cgContext ) ; wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ; @@ -447,68 +465,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); @@ -563,7 +519,7 @@ wxDC::wxDC() m_needComputeScaleY = FALSE; m_ok = FALSE ; - + m_macPort = 0 ; m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ; m_pen = *wxBLACK_PEN; @@ -597,7 +553,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 ) ; @@ -616,7 +572,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 ); @@ -635,7 +591,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 ) ; @@ -712,7 +668,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 ) ; @@ -905,14 +861,26 @@ bool wxDC::DoFloodFill(wxCoord x, wxCoord y, bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const { wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); - wxFAIL_MSG( wxT("GetPixel not implemented on Core Graphics") ) ; - return false ; + wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); + wxMacPortSaver helper((CGrafPtr)m_macPort) ; + RGBColor colour; + GetCPixel( + XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x, + YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour ); + // Convert from Mac colour to wx + col->Set( colour.red >> 8, + colour.green >> 8, + colour.blue >> 8); + return true ; } void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) { wxCHECK_RET(Ok(), wxT("Invalid DC")); + if ( m_logicalFunction != wxCOPY ) + return ; + wxCoord xx1 = XLOG2DEVMAC(x1) ; wxCoord yy1 = YLOG2DEVMAC(y1) ; wxCoord xx2 = XLOG2DEVMAC(x2) ; @@ -933,6 +901,8 @@ void wxDC::DoCrossHair( wxCoord x, wxCoord y ) { wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") ); + if ( m_logicalFunction != wxCOPY ) + return ; int w = 0; int h = 0; @@ -976,6 +946,10 @@ void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord xc, wxCoord yc ) { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC")); + + if ( m_logicalFunction != wxCOPY ) + return ; + wxCoord xx1 = XLOG2DEVMAC(x1); wxCoord yy1 = YLOG2DEVMAC(y1); wxCoord xx2 = XLOG2DEVMAC(x2); @@ -1010,10 +984,9 @@ void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, if( (xx1 > xx2) || (yy1 > yy2) ) { alpha2 *= -1; } - Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad }; wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ; CGContextRef ctx = mctx->GetNativeContext() ; - AddEllipticArcToPath( ctx , CGPointMake( xxc , yyc ) , rad , rad , 0 , 180 ) ; + AddEllipticArcToPath( ctx , CGPointMake( xxc , yyc ) , rad , rad , alpha1 , alpha2 ) ; CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ; } @@ -1022,6 +995,9 @@ void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC")); + if ( m_logicalFunction != wxCOPY ) + return ; + double angle = sa - ea; // Order important Mac in opposite direction to wx // we have to make sure that the filling is always counter-clockwise if ( angle > 0 ) @@ -1051,6 +1027,9 @@ void wxDC::DoDrawLines(int n, wxPoint points[], { wxCHECK_RET(Ok(), wxT("Invalid DC")); + if ( m_logicalFunction != wxCOPY ) + return ; + wxCoord x1, x2 , y1 , y2 ; x1 = XLOG2DEVMAC(points[0].x + xoffset); y1 = YLOG2DEVMAC(points[0].y + yoffset); @@ -1076,6 +1055,9 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], if ( n== 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) return ; + if ( m_logicalFunction != wxCOPY ) + return ; + x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset); y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset); @@ -1100,6 +1082,10 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxCHECK_RET(Ok(), wxT("Invalid DC")); + + if ( m_logicalFunction != wxCOPY ) + return ; + wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); @@ -1129,6 +1115,11 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, double radius) { wxCHECK_RET(Ok(), wxT("Invalid DC")); + + if ( m_logicalFunction != wxCOPY ) + return ; + + if (radius < 0.0) radius = - radius * ((width < height) ? width : height); wxCoord xx = XLOG2DEVMAC(x); @@ -1149,7 +1140,6 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, hh = -hh; yy = yy - hh; } - Rect rect = { yy , xx , yy + hh , xx + ww } ; wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ; CGContextRef ctx = mctx->GetNativeContext() ; AddRoundedRectToPath( ctx , CGRectMake( xx , yy , ww , hh ) , 16 ,16 ) ; @@ -1159,6 +1149,10 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxCHECK_RET(Ok(), wxT("Invalid DC")); + + if ( m_logicalFunction != wxCOPY ) + return ; + wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); @@ -1192,7 +1186,7 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) 0 ) ; CGContextClosePath(ctx); - CGContextDrawPath( ctx , kCGPathFillStroke ) ; + CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ; } else { @@ -1219,36 +1213,65 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, xsrcMask = xsrc; ysrcMask = ysrc; } + wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ; + wxCoord xxsrc = source->XLOG2DEVMAC(xsrc) ; + wxCoord wwsrc = source->XLOG2DEVREL(width ) ; + wxCoord hhsrc = source->YLOG2DEVREL(height) ; + + wxCoord yydest = YLOG2DEVMAC(ydest) ; + wxCoord xxdest = XLOG2DEVMAC(xdest) ; + wxCoord wwdest = XLOG2DEVREL(width ) ; + wxCoord hhdest = YLOG2DEVREL(height) ; + wxMemoryDC* memdc = dynamic_cast(source) ; - if ( memdc ) + if ( memdc && logical_func == wxCOPY ) { wxBitmap blit = memdc->GetSelectedObject() ; wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ; - wxCoord xxdest = XLOG2DEVMAC(xdest); - wxCoord yydest = YLOG2DEVMAC(ydest); - wxCoord ww = XLOG2DEVREL(width); - wxCoord hh = YLOG2DEVREL(height); - wxCoord bmpwidth = blit.GetWidth(); wxCoord bmpheight = blit.GetHeight(); - if ( xsrc != 0 || ysrc != 0 || bmpwidth != width || bmpheight != height ) + if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc ) { - wxRect subrect( xsrc, ysrc, width , height ) ; - blit = blit.GetSubBitmap( subrect ) ; + wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ; + hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ; + if ( wwsrc > 0 && hhsrc > 0 ) + { + if ( xxsrc >= 0 && yysrc >= 0 ) + { + wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ; + blit = blit.GetSubBitmap( subrect ) ; + } + else + { + // in this case we'd probably have to adjust the different coordinates, but + // we have to find out proper contract first + blit = wxNullBitmap ; + } + } + else + { + blit = wxNullBitmap ; + } + } + if ( blit.Ok() ) + { + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; + CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ; + HIRect r = CGRectMake( xxdest , yydest , wwdest , hhdest ) ; + HIViewDrawCGImage( cg , &r , image ) ; + CGImageRelease( image ) ; } - - CGContextRef cg = dynamic_cast(m_graphicContext)->GetNativeContext() ; - CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ; - HIRect r = CGRectMake( xxdest , yydest , ww , hh ) ; - HIViewDrawCGImage( cg , &r , image ) ; - CGImageRelease( image ) ; } else { - wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ; + /* + CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ; + void *data = CGBitmapContextGetData( cg ) ; + */ + return FALSE ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ; } return TRUE; } @@ -1261,6 +1284,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( str.Length() == 0 ) return ; + if ( m_logicalFunction != wxCOPY ) + return ; + wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ; OSStatus status = noErr ; @@ -1268,7 +1294,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, UniCharCount chars = str.Length() ; UniChar* ubuf = NULL ; #if SIZEOF_WCHAR_T == 4 - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; #if wxUSE_UNICODE size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ; @@ -1297,10 +1323,11 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); - int iAngle = int( angle ); - + status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") ); + int iAngle = int( angle ); if ( abs(iAngle) > 0 ) { Fixed atsuAngle = IntToFixed( iAngle ) ; @@ -1320,7 +1347,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 , @@ -1355,14 +1382,14 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, drawX , drawY ) ; path->AddLineToPoint( - drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent) , - drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent) ) ; + (int) (drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent)) , + (int) (drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent)) ) ; path->AddLineToPoint( - drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle/RAD2DEG) * FixedToInt(textAfter) , - drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent) - sin(angle/RAD2DEG) * FixedToInt(textAfter) ) ; + (int) (drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle/RAD2DEG) * FixedToInt(textAfter)) , + (int) (drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent) - sin(angle/RAD2DEG) * FixedToInt(textAfter)) ) ; path->AddLineToPoint( - drawX + cos(angle/RAD2DEG) * FixedToInt(textAfter) , - drawY - sin(angle/RAD2DEG) * FixedToInt(textAfter) ) ; + (int) (drawX + cos(angle/RAD2DEG) * FixedToInt(textAfter)) , + (int) (drawY - sin(angle/RAD2DEG) * FixedToInt(textAfter)) ) ; m_graphicContext->FillPath( path , m_textBackgroundColour ) ; delete path ; @@ -1375,13 +1402,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) ); @@ -1427,7 +1454,7 @@ void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *heigh UniCharCount chars = str.Length() ; UniChar* ubuf = NULL ; #if SIZEOF_WCHAR_T == 4 - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; #if wxUSE_UNICODE size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ; @@ -1495,9 +1522,54 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con if (text.Length() == 0) return false; - wxFAIL_MSG( wxT("Unimplemented for Core Graphics") ) ; - - return false; + ATSUTextLayout atsuLayout ; + UniCharCount chars = text.Length() ; + UniChar* ubuf = NULL ; +#if SIZEOF_WCHAR_T == 4 + wxMBConvUTF16 converter ; +#if wxUSE_UNICODE + size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ) ; + ubuf = (UniChar*) malloc( unicharlen + 2 ) ; + converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ) ; +#else + const wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ; + size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; + ubuf = (UniChar*) malloc( unicharlen + 2 ) ; + converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; +#endif + chars = unicharlen / 2 ; +#else +#if wxUSE_UNICODE + ubuf = (UniChar*) text.wc_str() ; +#else + wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ; + chars = wxWcslen( wchar.data() ) ; + ubuf = (UniChar*) wchar.data() ; +#endif +#endif + + OSStatus status; + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , + &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; + + for ( int pos = 0; pos < chars; pos ++ ) { + unsigned long actualNumberOfBounds = 0; + ATSTrapezoid glyphBounds; + + // We get a single bound, since the text should only require one. If it requires more, there is an issue + OSStatus result; + result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1, kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds ); + if (result != noErr || actualNumberOfBounds != 1 ) + { + return false; + } + + widths[pos] = XDEV2LOGREL(FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x )); + //unsigned char uch = s[i]; + + } + ::ATSUDisposeTextLayout(atsuLayout); + return true; } wxCoord wxDC::GetCharWidth(void) const @@ -1521,39 +1593,63 @@ void wxDC::Clear(void) if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) { HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ; + CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; switch( m_backgroundBrush.MacGetBrushKind() ) { case kwxMacBrushTheme : { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + if ( HIThemeSetFill != 0 ) + { + HIThemeSetFill( m_backgroundBrush.MacGetTheme() , NULL , cg , kHIThemeOrientationNormal ) ; + CGContextFillRect(cg, rect); + + } + else +#endif + { + RGBColor color; + GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme() , 32, true, &color ); + CGContextSetRGBFillColor( cg , (float) color.red / 65536, + (float) color.green / 65536, (float) color.blue / 65536, 1 ); + CGContextFillRect( cg, rect ); + } + // reset to normal value + RGBColor col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ; + CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; } break ; case kwxMacBrushThemeBackground : { + 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 ) + if ( UMAGetSystemVersion() >= 0x1030 ) { HIThemeBackgroundDrawInfo drawInfo ; drawInfo.version = 0 ; drawInfo.state = kThemeStateActive ; drawInfo.kind = m_backgroundBrush.MacGetThemeBackground(NULL) ; if ( drawInfo.kind == kThemeBackgroundMetal ) - HIThemeDrawBackground( &rect , &drawInfo, dynamic_cast(m_graphicContext)->GetNativeContext() , + HIThemeDrawBackground( &rect , &drawInfo, cg , kHIThemeOrientationNormal) ; - HIThemeApplyBackground( &rect , &drawInfo, dynamic_cast(m_graphicContext)->GetNativeContext() , + HIThemeApplyBackground( &rect , &drawInfo, cg , kHIThemeOrientationNormal) ; } + else #endif + { + } } break ; case kwxMacBrushColour : { RGBColor col = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ; - CGContextSetRGBFillColor( dynamic_cast(m_graphicContext)->GetNativeContext() , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; - CGContextFillRect(dynamic_cast(m_graphicContext)->GetNativeContext(), rect); + CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; + CGContextFillRect(cg, rect); // reset to normal value col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ; - CGContextSetRGBFillColor( dynamic_cast(m_graphicContext)->GetNativeContext() , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; + CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; } break ; } @@ -1570,35 +1666,38 @@ void wxDC::MacInstallFont() const m_macATSUIStyle = NULL ; } - OSStatus status = noErr ; - status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ; - wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ; - - Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ; - RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ; - ATSUAttributeTag atsuTags[] = - { - kATSUSizeTag , - kATSUColorTag , - } ; - ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = + if ( m_font.Ok() ) { - sizeof( Fixed ) , - sizeof( RGBColor ) , - } ; -// Boolean kTrue = true ; -// Boolean kFalse = false ; + OSStatus status = noErr ; + status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ; -// ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = - { - &atsuSize , - &atsuColor , - } ; - status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) , - atsuTags, atsuSizes, atsuValues); + Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ; + RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ; + ATSUAttributeTag atsuTags[] = + { + kATSUSizeTag , + kATSUColorTag , + } ; + ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = + { + sizeof( Fixed ) , + sizeof( RGBColor ) , + } ; + // Boolean kTrue = true ; + // Boolean kFalse = false ; - wxASSERT_MSG( status == noErr , wxT("couldn't Modify ATSU style") ) ; + // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; + ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = + { + &atsuSize , + &atsuColor , + } ; + status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) , + atsuTags, atsuSizes, atsuValues); + + wxASSERT_MSG( status == noErr , wxT("couldn't Modify ATSU style") ) ; + } } // ---------------------------------------------------------------------------