Commits

Ronald Oussoren committed e415be1

- AppKit wrappers now compile on GNUstep (but don't work yet)
- Use PyObjC.*CArray.* API's in NSBezierPath (needs more work)

Comments (0)

Files changed (14)

Modules/AppKit/_AppKit.m

  * Mapping of static items in the AppKit kit and helper functions for mapping
  * "difficult" methods.
  */
-#import <AppKit/AppKit.h>
-#import <AppKit/NSGraphics.h>
-#import <CoreFoundation/CoreFoundation.h>
-
 #include <Python.h>
 #include "pyobjc-api.h"
 #include "wrapper-const-table.h"
 
-#ifndef GNUSTEP
+#import <AppKit/AppKit.h>
+#import <AppKit/NSGraphics.h>
+
+#ifdef MACOSX
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
 #import <AppKit/NSNib.h>
 #endif
 
 #import <AppKit/NSTypesetter.h>
+
+#else /* GNUSTEP  */
+
+#import <AppKit/NSOpenGL.h>
+#import <AppKit/AppKitExceptions.h>
+#import <AppKit/NSHelpManager.h>
+
 #endif
 
 
 		return;
 	}
 
+#ifdef MACOSX
 	bundle = CFBundleCreate(NULL,
 		(CFURLRef)[NSURL fileURLWithPath:@"/System/Library/Frameworks/AppKit.framework"]);
+#else
+	bundle = NULL;
+#endif
 
 	if (register_ints(d, enum_table) < 0) return;
 	if (register_variableList(d, bundle, string_table, (sizeof(string_table)/sizeof(string_table[0]))-1) < 0) return;
 	 * directory
 	 */
 
-#ifndef GNUSTEP
+#ifdef MACOSX
 	/* NSOpenGL.h */
 	add_int(d, "NSOPENGL_CURRENT_VERSION", NSOPENGL_CURRENT_VERSION);
 
 	add_int(d, "NSPopUpMenuWindowLevel", NSPopUpMenuWindowLevel);
 	add_int(d, "NSScreenSaverWindowLevel", NSScreenSaverWindowLevel);
 
+#ifdef GNU_RUNTIME
+	add_int(d, "NSOutlineViewDropOnItemIndex", 
+			NSOutlineViewDropOnItemIndex);
+#endif
+
 	{
 	  struct uchar_table*  cur = g_unicode_characters;
 	  int       res;
 	}
 
 	/* Some special constants */
+#ifdef GNU_RUNTIME
+	/* ARGH, when I look at it in the debugger, NSFontIdentityMatrix 
+	 * seems to have the value of the first entry in the matrix,
+	 * instead of being the address of the array...
+	 */
+	fontMatrix(d, "NSFontIdentityMatrix", &NSFontIdentityMatrix);
+
+#else
+
 	fontMatrix(d, "NSFontIdentityMatrix", NSFontIdentityMatrix);
+#endif
 
 	/* Struct definitions */
 	v = PyObjC_RegisterStructType(@encode(NSAffineTransformStruct),

Modules/AppKit/_AppKitMapping_NSBezierPath.m

 	PyObject* result;
 	struct objc_super super;
 	PyObject* glyphList;
-	PyObject* seq;
+	PyObject* pyCount;
 	NSGlyph* glyphs;
 	int count;
 	id fontObj;
-	int i;
+	int token;
 	
-	if  (!PyArg_ParseTuple(arguments, "OiO&", &glyphList, &count, 
+	if  (!PyArg_ParseTuple(arguments, "OOO&", &glyphList, &pyCount, 
 			PyObjCObject_Convert, &fontObj)) {
 		return NULL;
 	}
 
-	seq = PySequence_Fast(glyphList, "glyphs must be a sequence");
-	if (count > PySequence_Fast_GET_SIZE(seq)) {
-		Py_DECREF(seq);
-		PyErr_SetString(PyExc_ValueError, "Count larger than sequence");
+	token = PyObjC_PythonToCArray(@encode(NSGlyph), glyphList, pyCount, 
+		(void**)&glyphs, &count);
+	if (token == -1) {
 		return NULL;
 	}
 
-	glyphs = malloc (sizeof(NSGlyph) * count);
-	if (glyphs == NULL) {
-		Py_DECREF(seq);
-		PyErr_NoMemory();
-		return NULL;
-	}
-
-	for (i = 0; i < count; i++) {
-		int err;
-
-		err = PyObjC_PythonToObjC(@encode(NSGlyph), 
-			PySequence_Fast_GET_ITEM(seq, i),
-			glyphs + i);
-		if (err == -1) {
-			Py_DECREF(seq);
-			free(glyphs);
-			return NULL;
-		}
-	} 
-
 	PyObjC_DURING
 		if (PyObjCIMP_Check(method)) {
 			((void(*)(id, SEL, NSGlyph*, int, id))
 				fontObj);
 		}
 
-		free(glyphs);
 	PyObjC_HANDLER
-		free(glyphs);
 		PyObjCErr_FromObjC(localException);
 		result = NULL;
 	PyObjC_ENDHANDLER
 
+	PyObjC_FreeCArray(token, glyphs);
+
 	if (PyErr_Occurred()) return NULL;
 	
 	result = Py_None;
 	PyObject* result;
 	struct objc_super super;
 	PyObject* pointList;
-	PyObject* seq;
+	PyObject* pyCount = NULL;
 	NSPoint* points;
 	int count;
-	int i;
+	int token;
 	
-	if  (!PyArg_ParseTuple(arguments, "Oi", &pointList, &count)) {
+	if  (!PyArg_ParseTuple(arguments, "O|O", &pointList, &pyCount)) {
 		return NULL;
 	}
 
-	seq = PySequence_Fast(pointList, "points must be a sequence");
-	if (count > PySequence_Fast_GET_SIZE(seq)) {
-		Py_DECREF(seq);
-		PyErr_SetString(PyExc_ValueError, "Count larger than sequence");
+	token = PyObjC_PythonToCArray(@encode(NSPoint), pointList, pyCount,
+		(void**)&points, &count);	
+	if (token == -1) {
 		return NULL;
 	}
 
-	points = malloc (sizeof(NSPoint) * count);
-	if (points == NULL) {
-		Py_DECREF(seq);
-		PyErr_NoMemory();
-		return NULL;
-	}
-
-	for (i = 0; i < count; i++) {
-		int err;
-
-		err = PyObjC_PythonToObjC(@encode(NSPoint), 
-			PySequence_Fast_GET_ITEM(seq, i),
-			points + i);
-		if (err == -1) {
-			Py_DECREF(seq);
-			free(points);
-			return NULL;
-		}
-	} 
-
 	PyObjC_DURING
 		if (PyObjCIMP_Check(method)) {
 			((void(*)(id,SEL,NSPoint*,int))
 				points,
 				count);
 		}
-		free(points);
 	PyObjC_HANDLER
-		free(points);
 		PyObjCErr_FromObjC(localException);
 		result = NULL;
 	PyObjC_ENDHANDLER
 
+	PyObjC_FreeCArray(token, points);
+
 	if (PyErr_Occurred()) return NULL;
 
 	result = Py_None;

Modules/AppKit/_AppKitMapping_NSBitmap.m

 		(void)objc_msgSendSuper(&super, 
 			PyObjCSelector_GetSelector(method),
 			&dataPlanes);
-		bytesPerPlane = (int) objc_msgSend(
-			PyObjCObject_GetObject(self), @selector(bytesPerPlane));
+
+		bytesPerPlane = [
+			(NSBitmapImageRep*)PyObjCObject_GetObject(self) 
+			bytesPerPlane];
 
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);
     
 		bitmapData = (unsigned char *) objc_msgSendSuper(&super, 
 				PyObjCSelector_GetSelector(method));
-		bytesPerPlane = (int) objc_msgSend(
-			PyObjCObject_GetObject(self), @selector(bytesPerPlane));
+
+			
+		bytesPerPlane = [
+			(NSBitmapImageRep*)PyObjCObject_GetObject(self) 
+			bytesPerPlane];
 
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);

Modules/AppKit/_AppKitMapping_NSFont.m

 		}
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);
-		matrix = nil;
+		matrix = NULL;
 	PyObjC_ENDHANDLER
 
-	if (matrix == nil && PyErr_Occurred()) {
+	if (matrix == NULL && PyErr_Occurred()) {
 		return NULL;
 	}
 

Modules/AppKit/_AppKitMapping_NSGraphicsContext.m

 #include <Python.h>
 #include <Foundation/Foundation.h>
 #include "pyobjc-api.h"
+
+#ifdef MACOSX
+
 #include <ApplicationServices/ApplicationServices.h>
 
-#ifdef MACOSX
 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;
+	PyObject* pyCoreGraphicsModule;
+	PyObject* pyCGContextPtr;
+	PyObject* sillySwigThing;
+	CGContextRef res;
+	char ptrString[9];
+	struct objc_super super;
+	PyObject* retVal;
 
-    if (!PyArg_ParseTuple(arguments, "")) {
-        return NULL;
-    }
+	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;
-    }
+	if ((pyCoreGraphicsModule = PyImport_ImportModule("CoreGraphics")) == NULL ) {
+		return 0;
+	}
+	pyCGContextPtr = PyObject_GetAttrString(pyCoreGraphicsModule, "CGContextPtr");
+	Py_DECREF(pyCoreGraphicsModule);
+	if (pyCGContextPtr == NULL) {
+		return 0;
+	}
 
-    PyObjC_DURING
-        PyObjC_InitSuper(&super,
-            PyObjCSelector_GetClass(method),
-            PyObjCObject_GetObject(self));
+	PyObjC_DURING
+		PyObjC_InitSuper(&super,
+		    PyObjCSelector_GetClass(method),
+		    PyObjCObject_GetObject(self));
 
-        res = (CGContextRef)objc_msgSendSuper(&super,
-            @selector(graphicsPort));
-    PyObjC_HANDLER
-        PyObjCErr_FromObjC(localException);
-        res = NULL;
-    PyObjC_ENDHANDLER
+		res = (CGContextRef)objc_msgSendSuper(&super,
+		    @selector(graphicsPort));
+	PyObjC_HANDLER
+		PyObjCErr_FromObjC(localException);
+		res = NULL;
+	PyObjC_ENDHANDLER
 
-    if (res == NULL && PyErr_Occurred()) {
-        Py_DECREF(pyCGContextPtr);
-        return NULL;
-    }
+	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;
+	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;
 }
 #endif
 

Modules/AppKit/_AppKitMapping_NSMatrix.m

 	return result;
 }
 
-#if 0
-
-static PyObject* 
-sortFuncWrapper(id (*func)(id, id, void*))
-{
-	/* Return an object that behaves like a callable and calls func */
-}
-
-static id 
-imp_NSMatrix_sortUsingFunction_context_(id self, SEL sel,
-		id (*func)(id, id, void*), void* context)
-{
-	PyObject* result;
-	PyObject* arglist;
-	PyObject* v;
-	int i;
-	id  returnValue;
-
-	arglist = PyTuple_New(3);
-	if (arglist == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	v = PyObjC_IdToPython(self);
-	if (v == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	PyTuple_SET_ITEM(arglist, 0, v);
-
-	v = sortFuncWrapper(func);
-	if (v == NULL ){
-		 Py_DECREF(arglist);
-		 PyObjCErr_ToObjC();
-		 return nil;
-	}
-	PyTuple_SET_ITEM(arglist, 1, v);
-
-	v = PyCObject_New(context, NULL);
-	if (v == NULL) {
-		Py_DECRF(arglist);
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-	PyTuple_SET_ITEM(arglist, 2, v);
-
-	result = PyObjC_CallPython(self, sel, arglist, NULL);
-	Py_DECREF(arglist);
-	if (result == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	returnValue = PyObjC_PythonToId(result);
-	Py_DECREF(result);
-	if (PyErr_Occurred()) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-	return returnValue;
-}
-
-#endif
 
 
 static int 

Modules/AppKit/_AppKitMapping_NSMovie.m

 #include <Foundation/Foundation.h>
 #include "pyobjc-api.h"
 
+#ifdef MACOSX
+
 #include "pymactoolbox.h"
 
 static PyObject* 
 
 	return 0;
 }
+
+#else /* GNUSTEP */
+
+static int 
+_pyobjc_install_NSMovie(void)
+{
+	return 0;
+}
+
+#endif

Modules/AppKit/_AppKitMapping_NSOpenGLContext.m

 #include <Python.h>
 #include <AppKit/AppKit.h>
 #include "pyobjc-api.h"
+
+#ifdef MACOSX 
+
+/* 1. I can't manage to get a working OpenGL on my develbox
+ * 2. Need to detect if OpenGL support is present
+ */
+
 #include <OpenGL/gl.h>
 
+#endif
+
 
 static int 
 _pyobjc_install_NSOpenGLContext(void)

Modules/AppKit/_AppKitMapping_NSOpenGLPixelFormat.m

 #include <Python.h>
 #include <AppKit/AppKit.h>
 #include "pyobjc-api.h"
+
+#ifdef MACOSX 
+
 #include <OpenGL/gl.h>
 
 static PyObject*
 
 	return 0;
 }
+
+#else
+
+static int 
+_pyobjc_install_NSOpenGLPixelFormat(void)
+{
+	return 0;
+}
+
+#endif

Modules/AppKit/_AppKitMapping_NSQuickDrawView.m

 #include <AppKit/AppKit.h>
 #include "pyobjc-api.h"
 
+#ifdef MACOSX
 
 static PyObject* 
 call_NSQuickDrawView_qdport(
 
 	return 0;
 }
+
+#else
+
+static int 
+_pyobjc_install_NSQuickDrawView(void)
+{
+	return 0;
+}
+
+#endif

Modules/AppKit/_AppKitMapping_NSView.m

 	return result;
 }
 
-#if 0
-
-static id 
-imp_NSView_sortSubviewsUsingFunction_context_(id self, SEL sel,
-		id (*func)(id, id, void*), void* context)
-{
-	PyObject* result;
-	PyObject* arglist;
-	PyObject* v;
-	int i;
-	id  returnValue;
-
-	arglist = PyTuple_New(3);
-	if (arglist == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	v = PyObjC_IdToPython(self);
-	if (v == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	PyTuple_SET_ITEM(arglist, 0, v);
-
-	v = sortFuncWrapper(func);
-	if (v == NULL ){
-		 Py_DECREF(arglist);
-		 PyObjCErr_ToObjC();
-		 return nil;
-	}
-	PyTuple_SET_ITEM(arglist, 1, v);
-
-	v = PyCObject_New(context, NULL);
-	if (v == NULL) {
-		Py_DECRF(arglist);
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-	PyTuple_SET_ITEM(arglist, 2, v);
-
-	result = PyObjC_CallPython(self, sel, arglist, NULL);
-	Py_DECREF(arglist);
-	if (result == NULL) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-
-	returnValue = PyObjC_PythonToId(result);
-	Py_DECREF(result);
-	if (PyErr_Occurred()) {
-		PyObjCErr_ToObjC();
-		return nil;
-	}
-	return returnValue;
-}
-
-#endif
 
 static PyObject* 
 call_NSView_getRectsBeingDrawn_count_(

Modules/AppKit/_AppKitMapping_NSWindow.m

 #include <AppKit/AppKit.h>
 #include "pyobjc-api.h"
 
+#ifdef MACOSX
+
 #include "pymactoolbox.h"
 
 static PyObject* 
 
 	return 0;
 }
+
+#else
+
+static int 
+_pyobjc_install_NSWindow(void)
+{
+	return 0;
+}
+
+#endif

Modules/Foundation/_Foundation.m

 #import <Foundation/NSDebug.h>
 
 #ifdef MACOSX
-#import <CoreFoundation/CoreFoundation.h>
 #include <pymactoolbox.h>
 
 #else

Modules/objc/wrapper-const-table.h

 
 #ifdef GNU_RUNTIME
 
+#import <Foundation/NSBundle.h>
+
 #define CFBundleRef NSBundle*
 
 static inline int
 
 #else /* !GNU_RUNTIME */
 
+#import <CoreFoundation/CoreFoundation.h>
+
 static inline int
 register_variableList(PyObject* d, CFBundleRef bundle __attribute__((__unused__)), struct vartable* table, size_t count)
 {