+ if ( logical_func == wxNO_OP )
+ return TRUE ;
+ if (xsrcMask == -1 && ysrcMask == -1)
+ {
+ xsrcMask = xsrc; ysrcMask = ysrc;
+ }
+ // correct the parameter in case this dc does not have a mask at all
+ if ( useMask && !source->m_macMask )
+ useMask = false ;
+ Rect srcrect , dstrect ;
+ srcrect.top = source->YLOG2DEVMAC(ysrc) ;
+ srcrect.left = source->XLOG2DEVMAC(xsrc) ;
+ srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
+ srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
+ dstrect.top = YLOG2DEVMAC(ydest) ;
+ dstrect.left = XLOG2DEVMAC(xdest) ;
+ dstrect.bottom = YLOG2DEVMAC(ydest + height ) ;
+ dstrect.right = XLOG2DEVMAC(xdest + width ) ;
+ short mode = kUnsupportedMode ;
+ bool invertDestinationFirst = false ;
+ switch ( logical_func )
+ {
+ case wxAND: // src AND dst
+ mode = adMin ; // ok
+ break ;
+ case wxAND_INVERT: // (NOT src) AND dst
+ mode = notSrcOr ; // ok
+ break ;
+ case wxAND_REVERSE:// src AND (NOT dst)
+ invertDestinationFirst = true ;
+ mode = srcOr ;
+ break ;
+ case wxCLEAR: // 0
+ mode = kEmulatedMode ;
+ break ;
+ case wxCOPY: // src
+ mode = srcCopy ; // ok
+ break ;
+ case wxEQUIV: // (NOT src) XOR dst
+ mode = srcXor ; // ok
+ break ;
+ case wxINVERT: // NOT dst
+ mode = kEmulatedMode ; //or hilite ;
+ break ;
+ case wxNAND: // (NOT src) OR (NOT dst)
+ invertDestinationFirst = true ;
+ mode = srcBic ;
+ break ;
+ case wxNOR: // (NOT src) AND (NOT dst)
+ invertDestinationFirst = true ;
+ mode = notSrcOr ;
+ break ;
+ case wxNO_OP: // dst
+ mode = kEmulatedMode ; // this has already been handled upon entry
+ break ;
+ case wxOR: // src OR dst
+ mode = notSrcBic ;
+ break ;
+ case wxOR_INVERT: // (NOT src) OR dst
+ mode = srcBic ;
+ break ;
+ case wxOR_REVERSE: // src OR (NOT dst)
+ invertDestinationFirst = true ;
+ mode = notSrcBic ;
+ break ;
+ case wxSET: // 1
+ mode = kEmulatedMode ;
+ break ;
+ case wxSRC_INVERT: // (NOT src)
+ mode = notSrcCopy ; // ok
+ break ;
+ case wxXOR: // src XOR dst
+ mode = notSrcXor ; // ok
+ break ;
+ default :
+ break ;
+ }
+ if ( mode == kUnsupportedMode )
+ {
+ wxFAIL_MSG(wxT("unsupported blitting mode" ));
+ return FALSE ;
+ }
+ CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
+ PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
+ if ( LockPixels(bmappixels) )
+ {
+ wxMacPortSetter helper(this) ;
+ if ( source->GetDepth() == 1 )
+ {
+ RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
+ RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
+ }
+ else
+ {
+ // the modes need this, otherwise we'll end up having really nice colors...
+ RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
+ RGBColor black = { 0,0,0} ;
+ RGBForeColor( &black ) ;
+ RGBBackColor( &white ) ;
+ }
+ if ( useMask && source->m_macMask )
+ {
+ if ( mode == srcCopy )
+ {
+ if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
+ {
+ CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) ,
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+ &srcrect, &srcrect , &dstrect ) ;
+ UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+ }
+ }
+ else
+ {
+ RgnHandle clipRgn = NewRgn() ;
+ LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+ BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+ UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
+ OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ;
+ if ( mode == kEmulatedMode )
+ {
+ Pattern pat ;
+ ::PenPat(GetQDGlobalsBlack(&pat));
+ if ( logical_func == wxSET )
+ {
+ RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+ ::RGBForeColor( &col ) ;
+ ::PaintRgn( clipRgn ) ;
+ }
+ else if ( logical_func == wxCLEAR )
+ {
+ RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+ ::RGBForeColor( &col ) ;
+ ::PaintRgn( clipRgn ) ;
+ }
+ else if ( logical_func == wxINVERT )
+ {
+ MacInvertRgn( clipRgn ) ;
+ }
+ else
+ {
+ for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
+ {
+ for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
+ {
+ Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
+ Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
+ if ( PtInRgn( dstPoint , clipRgn ) )
+ {
+ RGBColor srcColor ;
+ RGBColor dstColor ;
+ SetPort( (GrafPtr) sourcePort ) ;
+ GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
+ SetPort( (GrafPtr) m_macPort ) ;
+ GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+ wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
+ SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if ( invertDestinationFirst )
+ {
+ MacInvertRgn( clipRgn ) ;
+ }
+ CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+ &srcrect, &dstrect, mode, clipRgn ) ;
+ }
+ DisposeRgn( clipRgn ) ;
+ }
+ }
+ else
+ {
+ RgnHandle clipRgn = NewRgn() ;
+ SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ;
+ if ( mode == kEmulatedMode )
+ {
+ Pattern pat ;
+ ::PenPat(GetQDGlobalsBlack(&pat));
+ if ( logical_func == wxSET )
+ {
+ RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
+ ::RGBForeColor( &col ) ;
+ ::PaintRgn( clipRgn ) ;
+ }
+ else if ( logical_func == wxCLEAR )
+ {
+ RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
+ ::RGBForeColor( &col ) ;
+ ::PaintRgn( clipRgn ) ;
+ }
+ else if ( logical_func == wxINVERT )
+ {
+ MacInvertRgn( clipRgn ) ;
+ }
+ else
+ {
+ for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
+ {
+ for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
+ {
+ Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
+ Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
+ {
+ RGBColor srcColor ;
+ RGBColor dstColor ;
+ SetPort( (GrafPtr) sourcePort ) ;
+ GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
+ SetPort( (GrafPtr) m_macPort ) ;
+ GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+ wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
+ SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if ( invertDestinationFirst )
+ {
+ MacInvertRgn( clipRgn ) ;
+ }
+ CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
+ &srcrect, &dstrect, mode, NULL ) ;
+ }
+ DisposeRgn( clipRgn ) ;
+ }
+ UnlockPixels( bmappixels ) ;
+ }
+ m_macPenInstalled = false ;
+ m_macBrushInstalled = false ;
+ m_macFontInstalled = false ;
+ return TRUE;
+}
+
+#ifndef FixedToInt
+// as macro in FixMath.h for 10.3
+inline Fixed IntToFixed( int inInt )
+{
+ return (((SInt32) inInt) << 16);
+}