+/*static*/ WX_NSAffineTransform wxDC::CocoaGetWxToBoundsTransform(bool isFlipped, float height)
+{
+ NSAffineTransform *transform = nil;
+ // This transform flips the graphics since wxDC uses top-left origin
+ if(!isFlipped)
+ {
+ // The transform is auto released
+ transform = [NSAffineTransform transform];
+ /* x' = 1x + 0y + 0
+ y' = 0x + -1y + window's height
+ */
+ NSAffineTransformStruct matrix = {
+ 1, 0
+ , 0, -1
+ , 0, height
+ };
+ [transform setTransformStruct: matrix];
+ }
+ return transform;
+}
+
+void wxDC::CocoaApplyTransformations()
+{
+ [m_cocoaWxToBoundsTransform concat];
+ // TODO: Apply device/logical/user position/scaling transformations
+}
+
+void wxDC::CocoaUnapplyTransformations()
+{
+ // NOTE: You *must* call this with focus held.
+ // Undo all transforms so we're back in true Cocoa coords with
+ // no scaling or flipping.
+ NSAffineTransform *invertTransform;
+ invertTransform = [m_cocoaWxToBoundsTransform copy];
+ [invertTransform invert];
+ [invertTransform concat];
+ [invertTransform release];
+}
+
+bool wxDC::CocoaGetBounds(void *rectData)
+{
+ // We don't know what we are so we can't return anything.
+ return false;
+}
+
+void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+{
+ wxAutoNSAutoreleasePool pool;
+ if(!CocoaTakeFocus()) return;