+bool wxMemoryDCImpl::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
+ wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
+ int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask)
+{
+ if(!m_selectedBitmap.IsOk())
+ return false;
+
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ [transform translateXBy:xdest yBy:ydest];
+
+ NSAffineTransform *flipTransform = [NSAffineTransform transform];
+ /* x' = 1x + 0y + 0
+ y' = 0x + -1y + window's height
+ */
+ NSAffineTransformStruct matrix = {
+ 1, 0
+ , 0, -1
+ , 0, height
+ };
+ [flipTransform setTransformStruct: matrix];
+
+ NSGraphicsContext *context = [NSGraphicsContext currentContext];
+ [context saveGraphicsState];
+ [transform concat];
+ [flipTransform concat];
+
+ NSImage *sourceImage;
+ if(useMask)
+ {
+ sourceImage = [m_cocoaNSImage copy];
+ // Apply the mask to the copied image
+ NSBitmapImageRep *maskRep = m_selectedBitmap.GetMask()->GetNSBitmapImageRep();
+ NSImage *maskImage = [[NSImage alloc] initWithSize:[maskRep size]];
+ [maskImage addRepresentation:maskRep];
+ [sourceImage lockFocus];
+ [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn];
+ [sourceImage unlockFocus];
+ [maskImage release];
+ }
+ else
+ { // retain the m_cocoaNSImage so it has the same ownership as the copy done in the other case.
+ sourceImage = [m_cocoaNSImage retain];
+ }
+ NSCompositingOperation drawingOp;
+ switch(logicalFunc)
+ {
+ case wxCOPY:
+ // Even if not using the mask, the image might have an alpha channel
+ // so always use NSCompositeSourceOver. If the image is fully opaque
+ // it works out the same as NSCompositeCopy.
+ drawingOp = NSCompositeSourceOver;
+ break;
+ // FIXME: implement more raster ops
+ default:
+ wxLogDebug(wxT("wxCocoa does not support blitting with raster operation %d."), logicalFunc);
+ // Just use the default operation.
+ drawingOp = NSCompositeCopy;
+ }
+
+ wxLogTrace(wxTRACE_COCOA,wxT("[m_cocoaNSImage isFlipped]=%d"), [m_cocoaNSImage isFlipped]);
+ [sourceImage drawAtPoint: NSMakePoint(0,0)
+ fromRect: NSMakeRect(xsrc,
+ m_selectedBitmap.GetHeight()-height-ysrc,
+ width, height)
+ operation: drawingOp
+ fraction: 1.0];
+
+ [sourceImage release]; // It was either retained, copied, or allocated.
+ [context restoreGraphicsState];
+ return false;
+}
+
+bool wxMemoryDCImpl::CocoaGetBounds(void *rectData)
+{
+ if(!rectData)
+ return false;
+ if(!m_cocoaNSImage)
+ return false;
+ NSRect *pRect = (NSRect*)rectData;
+ pRect->origin.x = 0.0;
+ pRect->origin.y = 0.0;
+ pRect->size = [m_cocoaNSImage size];
+ return true;
+}
+