X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f3450784cc9c696f269ff1bfde3623c180d4b58..80a779275ae04443c568dca919adb26cf6f5002c:/src/mac/carbon/dccg.cpp?ds=sidebyside diff --git a/src/mac/carbon/dccg.cpp b/src/mac/carbon/dccg.cpp index 1d6f223a2f..845f0bf88e 100755 --- a/src/mac/carbon/dccg.cpp +++ b/src/mac/carbon/dccg.cpp @@ -17,16 +17,12 @@ #ifndef WX_PRECOMP #include "wx/log.h" - #include "wx/app.h" #include "wx/dcmemory.h" - #include "wx/dcprint.h" #include "wx/region.h" - #include "wx/image.h" #endif #include "wx/mac/uma.h" - #ifdef __MSL__ #if __MSL__ >= 0x6000 #include "math.h" @@ -58,12 +54,9 @@ const double M_PI = 3.14159265358979 ; #endif #endif -const double RAD2DEG = 180.0 / M_PI; -const short kEmulatedMode = -1 ; -const short kUnsupportedMode = -2 ; - -extern TECObjectRef s_TECNativeCToUnicode ; +static const double RAD2DEG = 180.0 / M_PI; +#ifndef __LP64__ // TODO: update // The textctrl implementation still needs that (needs what?) for the non-HIView implementation @@ -131,13 +124,12 @@ wxMacPortSetter::~wxMacPortSetter() { // m_dc->MacCleanupPort(&m_ph) ; } +#endif //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- -static inline double dmin(double a, double b) { return a < b ? a : b; } -static inline double dmax(double a, double b) { return a > b ? a : b; } static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } //----------------------------------------------------------------------------- @@ -252,9 +244,10 @@ wxMacCGContext::~wxMacCGContext() CGContextRestoreGState( m_cgContext ) ; CGContextRestoreGState( m_cgContext ) ; } - +#ifndef __LP64__ if ( m_qdPort ) - CGContextRelease( m_cgContext ) ; + QDEndCGContext( m_qdPort, &m_cgContext ) ; +#endif } @@ -266,8 +259,23 @@ void wxMacCGContext::Clip( const wxRegion ®ion ) void wxMacCGContext::StrokePath( const wxGraphicPath *p ) { const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ; + + int width = m_pen.GetWidth(); + if ( width == 0 ) + width = 1 ; + if ( m_pen.GetStyle() == wxTRANSPARENT ) + width = 0 ; + + bool offset = ( width % 2 ) == 1 ; + + if ( offset ) + CGContextTranslateCTM( m_cgContext, 0.5, 0.5 ); + CGContextAddPath( m_cgContext , path->GetPath() ) ; CGContextStrokePath( m_cgContext ) ; + + if ( offset ) + CGContextTranslateCTM( m_cgContext, -0.5, -0.5 ); } void wxMacCGContext::DrawPath( const wxGraphicPath *p , int fillStyle ) @@ -283,8 +291,22 @@ void wxMacCGContext::DrawPath( const wxGraphicPath *p , int fillStyle ) mode = kCGPathEOFillStroke ; } + int width = m_pen.GetWidth(); + if ( width == 0 ) + width = 1 ; + if ( m_pen.GetStyle() == wxTRANSPARENT ) + width = 0 ; + + bool offset = ( width % 2 ) == 1 ; + + if ( offset ) + CGContextTranslateCTM( m_cgContext, 0.5, 0.5 ); + CGContextAddPath( m_cgContext , path->GetPath() ) ; CGContextDrawPath( m_cgContext , mode ) ; + + if ( offset ) + CGContextTranslateCTM( m_cgContext, -0.5, -0.5 ); } void wxMacCGContext::FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle ) @@ -324,8 +346,11 @@ CGContextRef wxMacCGContext::GetNativeContext() if ( m_cgContext == NULL ) { Rect bounds ; + OSStatus status = noErr; +#ifndef __LP64__ GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ; - OSStatus status = CreateCGContextForPort((CGrafPtr) m_qdPort , &m_cgContext) ; + status = QDBeginCGContext((CGrafPtr) m_qdPort , &m_cgContext) ; +#endif CGContextSaveGState( m_cgContext ) ; wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ; @@ -364,14 +389,24 @@ void wxMacCGContext::Scale( wxCoord xScale , wxCoord yScale ) void wxMacCGContext::DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) { CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ) ; - HIRect r = CGRectMake( x , y , w , h ) ; - HIViewDrawCGImage( m_cgContext , &r , image ) ; + HIRect r = CGRectMake( 0 , 0 , w , h ); + + CGContextSaveGState( m_cgContext ); + CGContextTranslateCTM( m_cgContext, x , y + h ); + CGContextScaleCTM( m_cgContext, 1, -1 ); + + // in case image is a mask, set the foreground color + CGContextSetRGBFillColor( m_cgContext , m_textForegroundColor.Red() / 255.0 , m_textForegroundColor.Green() / 255.0 , + m_textForegroundColor.Blue() / 255.0 , m_textForegroundColor.Alpha() / 255.0 ) ; + CGContextDrawImage( m_cgContext, r, image ); + CGContextRestoreGState( m_cgContext ); + CGImageRelease( image ) ; } void wxMacCGContext::DrawIcon( const wxIcon &icon, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) { - CGRect r = CGRectMake( 00 , 00 , w , h ) ; + CGRect r = CGRectMake( 0 , 0 , w , h ) ; CGContextSaveGState( m_cgContext ); CGContextTranslateCTM( m_cgContext, x , y + h ); CGContextScaleCTM( m_cgContext, 1, -1 ); @@ -440,7 +475,7 @@ const CGPatternCallbacks wxMacCGPattern::ms_Callbacks = { 0, &wxMacCGPattern::_R class ImagePattern : public wxMacCGPattern { public : - ImagePattern( const wxBitmap* bmp , CGAffineTransform transform ) + ImagePattern( const wxBitmap* bmp , const CGAffineTransform& transform ) { wxASSERT( bmp && bmp->Ok() ) ; @@ -448,7 +483,7 @@ public : } // ImagePattern takes ownership of CGImageRef passed in - ImagePattern( CGImageRef image , CGAffineTransform transform ) + ImagePattern( CGImageRef image , const CGAffineTransform& transform ) { if ( image ) CFRetain( image ) ; @@ -463,7 +498,7 @@ public : } protected : - void Init( CGImageRef image, CGAffineTransform transform ) + void Init( CGImageRef image, const CGAffineTransform& transform ) { m_image = image ; if ( m_image ) @@ -489,7 +524,7 @@ protected : class HatchPattern : public wxMacCGPattern { public : - HatchPattern( int hatchstyle, CGAffineTransform transform ) + HatchPattern( int hatchstyle, const CGAffineTransform& transform ) { m_hatch = hatchstyle ; m_imageBounds = CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ; @@ -613,7 +648,7 @@ void wxMacCGContext::SetPen( const wxPen &pen ) CGContextSetShouldAntialias( m_cgContext , false ) ; #endif - if ( fill | stroke ) + if ( fill || stroke ) { // set up brushes m_mode = kCGPathFill ; // just a default @@ -790,7 +825,7 @@ void wxMacCGContext::SetBrush( const wxBrush &brush ) CGContextSetShouldAntialias( m_cgContext , false ) ; #endif - if ( fill | stroke ) + if ( fill || stroke ) { // setup brushes m_mode = kCGPathFill ; // just a default @@ -1057,8 +1092,7 @@ void wxMacCGContext::GetPartialTextExtents(const wxString& text, wxArrayInt& wid #endif #endif - OSStatus status; - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , + ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; for ( int pos = 0; pos < (int)chars; pos ++ ) @@ -1180,7 +1214,18 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxCoord ww = XLOG2DEVREL(w); wxCoord hh = YLOG2DEVREL(h); - m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ; + if ( bmp.GetDepth()==1 ) + { + wxGraphicPath* path = m_graphicContext->CreatePath() ; + path->AddRectangle( xx , yy , ww , hh ) ; + m_graphicContext->FillPath( path , m_textBackgroundColour, wxODDEVEN_RULE) ; + delete path; + m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ; + } + else + { + m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ; + } } void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) @@ -1320,7 +1365,9 @@ void wxDC::SetTextForeground( const wxColour &col ) if ( col != m_textForegroundColour ) { m_textForegroundColour = col; - m_graphicContext->SetTextColor( col ) ; + m_graphicContext->SetTextColor( col ); + // in the current implementation the font contains the text color + m_graphicContext->SetFont(m_font); } } @@ -1453,7 +1500,7 @@ void wxDC::SetPen( const wxPen &pen ) { if ( m_pen == pen ) return ; - + m_pen = pen; if ( m_graphicContext ) { @@ -1539,14 +1586,14 @@ bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const { wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") ); - wxMacPortSaver helper((CGrafPtr)m_macPort) ; RGBColor colour; - +#ifndef __LP64__ + wxMacPortSaver helper((CGrafPtr)m_macPort) ; // NB: GetCPixel is a deprecated QD call, and a slow one at that GetCPixel( XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x, YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour ); - +#endif // convert from Mac colour to wx col->Set( colour.red >> 8, colour.green >> 8, colour.blue >> 8 ); @@ -1858,8 +1905,21 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) yy = yy - hh; } + int penwidth = m_pen.GetWidth(); + if ( penwidth == 0 ) + penwidth = 1 ; + if ( m_pen.GetStyle() == wxTRANSPARENT ) + penwidth = 0 ; + + bool offset = ( penwidth % 2 ) == 1 ; + wxGraphicPath* path = m_graphicContext->CreatePath() ; - path->AddRectangle( xx , yy , ww , hh ) ; + // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1 + if ( offset ) + path->AddRectangle( xx , yy , ww-1 , hh-1 ) ; + else + path->AddRectangle( xx , yy , ww , hh ) ; + m_graphicContext->DrawPath( path ) ; delete path ; } @@ -1904,19 +1964,13 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, } else { - m_graphicContext->PushState() ; - m_graphicContext->Translate( xx , yy ) ; - m_graphicContext->Scale( radius , radius ) ; - double fw = ww / radius ; - double fh = hh / radius; - path->MoveToPoint(fw, fh / 2); - path->AddArcToPoint(fw, fh, fw / 2, fh, 1); - path->AddArcToPoint(0, fh, 0, fh / 2, 1); - path->AddArcToPoint(0, 0, fw / 2, 0, 1); - path->AddArcToPoint(fw, 0, fw, fh / 2, 1); + path->MoveToPoint( xx + ww, yy + hh / 2); + path->AddArcToPoint(xx + ww, yy + hh, xx + ww / 2,yy + hh, radius); + path->AddArcToPoint(xx , yy + hh, xx , yy + hh / 2, radius); + path->AddArcToPoint(xx , yy , xx + ww / 2, yy , radius); + path->AddArcToPoint(xx + ww, yy , xx + ww, yy + hh / 2, radius); path->CloseSubpath(); m_graphicContext->DrawPath( path ) ; - m_graphicContext->PopState() ; } delete path ; } @@ -2077,7 +2131,6 @@ void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height { wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") ); - wxFont formerFont = m_font ; if ( theFont ) { m_graphicContext->SetFont( *theFont ) ;