Commits

Bob Ippolito committed 42e0d75

Turn on NSGraphicsContext mappings
Added graphicsPort -> CoreGraphics code for OS X 10.3, not really tested
Fixed a compiler warning in NSOpenGLPixelFormat

  • Participants
  • Parent commits 1a221a0

Comments (0)

Files changed (3)

File pyobjc/Modules/AppKit/_AppKit.m

 #include "_AppKitMapping_NSBitmap.m"
 #include "_AppKitMapping_NSBitmapImageRep.m"
 #include "_AppKitMapping_NSFont.m"
+#include "_AppKitMapping_NSGraphicsContext.m"
+#include "_AppKitMapping_NSLayoutManager.m"
 #include "_AppKitMapping_NSMatrix.m"
-#include "_AppKitMapping_NSLayoutManager.m"
 #include "_AppKitMapping_NSMovie.m"
 #include "_AppKitMapping_NSOpenGLContext.m"
 #include "_AppKitMapping_NSOpenGLPixelFormat.m"
 	if (_pyobjc_install_NSBitmap() < 0) return;
 	if (_pyobjc_install_NSBitmapImageRep() < 0) return;
 	if (_pyobjc_install_NSFont() < 0) return;
+    if (_pyobjc_install_NSGraphicsContext() < 0) return;
 	if (_pyobjc_install_NSLayoutManager() < 0) return;
 	if (_pyobjc_install_NSMatrix() < 0) return;
 	if (_pyobjc_install_NSMovie() < 0) return;

File pyobjc/Modules/AppKit/_AppKitMapping_NSGraphicsContext.m

 /*
  * NSGraphicsContext mappings for difficult methods:
  *
- * TODO:
- * -graphicsPort, there doesn't seem to be a MacPython wrapper for this?
- *
  * Unsupported:
  * -focusStack
  * -setFocusStack
 #include <Python.h>
 #include <Foundation/Foundation.h>
 #include "pyobjc-api.h"
+#include <ApplicationServices/ApplicationServices.h>
+
+static PyObject*
+call_NSGraphicsContext_graphicsPort(
+    PyObject* method, PyObject* self, PyObject* arguments)
+{
+    PyObject* pyCoreGraphicsModule;
+    PyObject* pyCGContextPtr;
+    PyObject* sillySwigThing;
+    CGContextRef res;
+    char ptrString[9];
+    struct objc_super super;
+    PyObject* retVal;
+
+    if (!PyArg_ParseTuple(arguments, "")) {
+        return NULL;
+    }
+
+    if ((pyCoreGraphicsModule = PyImport_ImportModule("CoreGraphics")) == NULL ) {
+        return 0;
+    }
+    pyCGContextPtr = PyObject_GetAttrString(pyCoreGraphicsModule, "CGContextPtr");
+    Py_DECREF(pyCoreGraphicsModule);
+    if (pyCGContextPtr == NULL) {
+        return 0;
+    }
+
+    NS_DURING
+        PyObjC_InitSuper(&super,
+            PyObjCSelector_GetClass(method),
+            PyObjCObject_GetObject(self));
+
+        res = (CGContextRef)objc_msgSendSuper(&super,
+            @selector(graphicsPort));
+    NS_HANDLER
+        PyObjCErr_FromObjC(localException);
+        res = NULL;
+    NS_ENDHANDLER
+
+    if (res == NULL && PyErr_Occurred()) {
+        Py_DECREF(pyCGContextPtr);
+        return NULL;
+    }
+
+    sprintf(ptrString, "%08x", (unsigned int)res);
+    sillySwigThing = PyString_FromFormat("_%s_CGContextRef", ptrString);
+    retVal = PyObject_CallFunctionObjArgs(pyCGContextPtr, sillySwigThing, NULL);
+    Py_DECREF(sillySwigThing);
+    Py_DECREF(pyCGContextPtr);
+    return retVal;
+}
 
 static int 
 _pyobjc_install_NSGraphicsContext(void)
 	}
 
 	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSGraphicsContext"), 
-		@selector(setFocusStack),
+		@selector(setFocusStack:),
 		PyObjCUnsupportedMethod_Caller,
 		PyObjCUnsupportedMethod_IMP) < 0 ) {
 
 		return -1;
 	}
 
+#ifdef MACOSX
+	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSGraphicsContext"), 
+		@selector(graphicsPort),
+		call_NSGraphicsContext_graphicsPort,
+		PyObjCUnsupportedMethod_IMP) < 0 ) {
+
+		return -1;
+	}
+#else
 	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSGraphicsContext"), 
 		@selector(graphicsPort),
 		PyObjCUnsupportedMethod_Caller,
 
 		return -1;
 	}
+#endif
 
 	return 0;
 }

File pyobjc/Modules/AppKit/_AppKitMapping_NSOpenGLPixelFormat.m

 	}
     
 	for (i=0; i<count; ++i) {
-		int r;
 		PyObjC_PythonToObjC(
 			@encode(GLuint), 
 			PySequence_Fast_GET_ITEM(seq, i),