Source

pyobjc / pyobjc / Modules / AppKit / _AppKit.m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/*
 * Mapping of static items in the AppKit kit:
 * 
 * - constants  (mostly done)
 * - data types (TODO)
 * - enumerations
 * - exceptions 
 * - global functions (TODO)
 */
#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

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
#import <AppKit/NSNib.h>
#endif

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
#import <AppKit/NSAccessibility.h>
#endif

#import <AppKit/NSTypesetter.h>
#endif


/** Functions */

/* The headings below refer to the reference pages on developer.apple.com */

/* 'Applications' */

static PyObject* 
objc_NSApplicationMain(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static	char* keywords[] = { "argv", NULL };
	char** argv = NULL;
	int    argc;
	PyObject* arglist;
	int       i;
	PyObject* v;
	int       res;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:NSApplicationMain",
			keywords, &arglist)) {
		return NULL;
	}

	if (!PySequence_Check(arglist)) {
		PyErr_SetString(PyExc_TypeError, 
			"NSApplicationMain: need list of strings as argument");
		return NULL;
	}

	argc = PySequence_Size(arglist);
	argv = calloc((argc + 1), sizeof(char**));
	if (argv == NULL) {
		PyErr_SetString(PyExc_MemoryError,
			"Out of memory");
		return NULL;
	}

	for  (i = 0; i < argc; i++) {
		v = PySequence_GetItem(arglist, i);
		if (v == NULL) {
			goto error_cleanup;
		}
		if (!PyString_Check(v)) {
			PyErr_SetString(PyExc_TypeError, 
				"NSApplicationMain: need list of strings "
				"as argument");
			goto error_cleanup;
		}

		argv[i] = strdup(PyString_AsString(v));
		if (argv[i] == NULL) {
			PyErr_SetString(PyExc_MemoryError,
				"Out of memory");
			goto error_cleanup;
		}
	}

	argv[argc] = NULL;

#ifdef MACOSX
	/*
	 * NSApplicationMain on MacOS X completely ignores its arguments and 
	 * reads the argv from the shared NSProcessInfo. We *HACK* around this 
	 * by setting a (private) instance variable of the object.
	 *
	 * This code is evil. Look away if you're easily scared.
	 */
	{
		typedef struct {
			@defs(NSProcessInfo)
		} NSProcessInfoStruct;
	  
		NSMutableArray *newarglist = [[NSMutableArray alloc] init];
		NSProcessInfo *processInfo = [NSProcessInfo processInfo];
		char **anArg = argv;

		while(*anArg) {
			[newarglist addObject: 
				[NSString stringWithUTF8String: *anArg]];
			anArg++;
		}

		// Don't release the orignal arguments, unknown whether this 
		// list is owned by the object.
		//[((NSProcessInfoStruct *)processInfo)->arguments release]; 
		((NSProcessInfoStruct *)processInfo)->arguments = newarglist;
	}
#endif /* MACOSX */

	NS_DURING
		res = NSApplicationMain(argc, (const char**)argv);
	NS_HANDLER
		PyObjCErr_FromObjC(localException);
		res = -1;
	NS_ENDHANDLER

	for (i = 0; i < argc; i++) {
		free(argv[i]);
	}
	free(argv);

	if (res == -1 && PyErr_Occurred())
		return NULL;
	return PyInt_FromLong(res);

error_cleanup:
	if (argv != NULL) {
		for (i = 0; i < argc; i++) {\
			if (argv[i] != NULL) {
				free(argv[i]);
				argv[i] = NULL;
			}
		}
		free(argv);
		argv = NULL;
	}

	return NULL;
}


static PyObject*
objc_NSApp(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static  char* keywords[] = { NULL };
        PyObject* result;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NSApp", keywords)) {
		return NULL;
	}

	result = PyObjC_IdToPython(NSApp);

	return result;                               
}

static PyObject*
objc_NSCountWindows(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static  char* keywords[] = { NULL };
	int       count;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NSCountWindows", keywords)) {
		return NULL;
	}

	NS_DURING
		NSCountWindows(&count);
	NS_HANDLER
		PyObjCErr_FromObjC(localException);
	NS_ENDHANDLER
	if (PyErr_Occurred()) return NULL;

	return PyInt_FromLong(count);
}

static PyObject*
objc_NSCountWindowsForContext(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static  char* keywords[] = { "context", NULL };
	int       count;
	int	  context;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NSCountWindows", keywords, &context)) {
		return NULL;
	}

	NS_DURING
		NSCountWindowsForContext(context, &count);
	NS_HANDLER
		PyObjCErr_FromObjC(localException);
	NS_ENDHANDLER
	if (PyErr_Occurred()) return NULL;

	return PyInt_FromLong(count);
}

static PyObject*
objc_NSAvailableWindowDepths(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static  char* keywords[] = { NULL };
	const NSWindowDepth*	  depths;
	PyObject *result, *tmp;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NSAvailableWindowDepts", keywords)) {
		return NULL;
	}

	NS_DURING
		depths = NSAvailableWindowDepths();
	NS_HANDLER
		depths = NULL;
		PyObjCErr_FromObjC(localException);
	NS_ENDHANDLER
	if (PyErr_Occurred()) return NULL;

	result = PyList_New(0);
	if (result == NULL) return NULL;

	while (*depths != 0) {
		PyObject* v = PyInt_FromLong(*depths);
		if (v == NULL) {
			Py_DECREF(result);
			return NULL;
		}

		if (PyList_Append(result, v) == -1) {
			Py_DECREF(result);
			return NULL;
		}

		depths++;
	}

	tmp = PyList_AsTuple(result);
	Py_XDECREF(result);
	return tmp;
}


static PyObject*
compat_NSRectFillList(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static char* keywords[] = { "bytes", "count", 0 };
	unsigned char *rectBytes;
	int rectByteLength;
	int rectCount = -1;
	if  (!PyArg_ParseTupleAndKeywords(args, kwds, "s#i", keywords, &rectBytes, &rectByteLength, &rectCount)) {
		return NULL;
	}

	if ( (rectByteLength == 0) || (rectCount == 0) ) {
		Py_INCREF(Py_None);
		return Py_None; 
	}

	if ( rectByteLength % sizeof(NSRect) ) {
		PyErr_SetString(PyExc_ValueError, "length of array of packed floats is not a multiple of a length of array of NSRect (float * 4).");
		return NULL;
	}

	if (rectCount < -1 ) {
		PyErr_SetString(PyExc_ValueError, "RectCount was less than zero.");
		return NULL;
	}
        

	if (rectCount >= 0 ) {
		if ((size_t)rectCount > (rectByteLength / sizeof(NSRect))) {
                    PyErr_SetString(PyExc_ValueError, 
				"Rect count specified, but was longer than supplied array of rectangles.");
			return NULL;
		}
	} else {
		rectCount = rectByteLength / sizeof(NSRect);
	}

	NSRectFillList((NSRect *) rectBytes, rectCount);

	Py_INCREF(Py_None);
	return Py_None; 
}

static PyObject*
objc_NSRectFillList(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static char* keywords[] = { "rects", "count", 0 };
	NSRect* rects;
	PyObject* rectList;
	PyObject* seq;
	int i, len;
	int rectCount;

	{
		/* Upto PyObjC 1.0b2 compat_NSRectFillList was the wrapper for NSRectFillList
		 * this implementation is not consistant w.r.t. the rest of the bridge and
		 * therefore depricated.
		 */
		char* s1; 
		int i1, i2;
                static char* klist[] = { "bytes", "count", 0 };

		if  (PyArg_ParseTupleAndKeywords(args, kwds, "s#i", klist, &s1, &i1, &i2)) {
			return compat_NSRectFillList(self, args, kwds);
		}
		PyErr_Clear();
	}

	if  (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi", keywords, &rectList, &rectCount)) {
		return NULL;
	}

	seq = PySequence_Fast(rectList, "expecting a list of NSRect objects");
	if (seq == NULL) {
		return NULL;
	}

	if (PySequence_Fast_GET_SIZE(seq) < rectCount) {
		Py_DECREF(seq);
		PyErr_SetString(PyExc_ValueError, "too few rects");
		return NULL;
	}


	if (rectCount < 0) {
		Py_DECREF(seq);
		PyErr_SetString(PyExc_ValueError, "RectCount was less than zero.");
		return NULL;
	}

	rects = malloc((rectCount * sizeof(NSRect)) * 4);
	if (rects == NULL) {
		PyErr_NoMemory();
		return NULL;
	}

	for (i = 0; i < rectCount; i++) {
		PyObject* v = PySequence_Fast_GET_ITEM(seq, i);
		int r  = PyObjC_PythonToObjC(@encode(NSRect), v, rects + i);
		if (r == -1) {
			Py_DECREF(seq);
			return NULL;
		}
	}
	Py_DECREF(seq);
	NSRectFillList(rects, rectCount);

	free(rects);

	Py_INCREF(Py_None);
	return Py_None; 
}

static PyObject*
objc_NSGetWindowServerMemory(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
{
static char* keywords[] = { "context", "windowDumpStream", NULL };
	int context;
	int virtualMemory = 0;
	int doDumpStream;
	int res;
	int windowBackingMemory = 0;
	NSString* windowDumpStream = NULL;
	PyObject* result;
	PyObject* v;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii:NSGetWindowServerMemory", keywords, &context, &doDumpStream)) {
		return NULL;
	}

	NS_DURING
		if (doDumpStream) {
			res = NSGetWindowServerMemory(
				context, &virtualMemory, &windowBackingMemory,
				&windowDumpStream);
		} else {
			res = NSGetWindowServerMemory(
				context, &virtualMemory, &windowBackingMemory,
				NULL);
		}
	NS_HANDLER
		res = 0;
		PyObjCErr_FromObjC(localException);
	NS_ENDHANDLER

	if (PyErr_Occurred()) {
		return NULL;
	}

	result = PyTuple_New(4);
	if (result == NULL) return NULL;

	v = PyInt_FromLong(res);
	if (v == NULL) {
		Py_DECREF(result);
		return NULL;
	}

	PyTuple_SET_ITEM(result, 0, v);

	v = PyInt_FromLong(virtualMemory);
	if (v == NULL) {
		Py_DECREF(result);
		return NULL;
	}

	PyTuple_SET_ITEM(result, 1, v);

	v = PyInt_FromLong(windowBackingMemory);
	if (v == NULL) {
		Py_DECREF(result);
		return NULL;
	}

	PyTuple_SET_ITEM(result, 2, v);

	v = PyObjC_IdToPython(windowDumpStream);
	if (v == NULL) {
		Py_DECREF(result);
		return NULL;
	}

	PyTuple_SET_ITEM(result, 3, v);

	return result;
}

	


#ifdef GNUSTEP
#include "_App_Functions.GNUstep.inc"

#else /* !GNUSTEP */

#include "_App_Functions.inc"

#endif /* !GNUSTEP */

static PyMethodDef appkit_methods[] = {
	{ 
		"NSApplicationMain", 
		(PyCFunction)objc_NSApplicationMain, 
		METH_VARARGS|METH_KEYWORDS, 
		NULL
	},
	{ 
		"NSApp", 
		(PyCFunction)objc_NSApp, 
		METH_VARARGS|METH_KEYWORDS, 
		NULL
	},
	{ 
		"NSCountWindows", 
		(PyCFunction)objc_NSCountWindows, 
		METH_VARARGS|METH_KEYWORDS, 
		NULL
	},
	{ 
		"NSCountWindowsForContext", 
		(PyCFunction)objc_NSCountWindowsForContext, 
		METH_VARARGS|METH_KEYWORDS, 
		NULL
	},
	{
	        "NSRectFillList",
		(PyCFunction)objc_NSRectFillList,
		METH_VARARGS,
		NULL
	},
	{
	        "NSAvailableWindowDepths",
		(PyCFunction)objc_NSAvailableWindowDepths,
		METH_VARARGS,
		NULL
	},
	{
		"NSGetWindowServerMemory",
		(PyCFunction)objc_NSGetWindowServerMemory,
		METH_VARARGS,
		NULL
	},

	METHOD_TABLE_ENTRIES

	{ 0, 0, 0, 0 } /* sentinel */
};

PyDoc_STRVAR(appkit_doc,
"Cocoa._Foundation defines constants, types and global functions used by "
"Cocoa.Foundation."
);


/* TODO:
 * actual variables: 
 * - NSApp
 *
 * floats:
 NSColor-Grayscale Values

 const float NSWhite;
 const float NSLightGray;
 const float NSDarkGray;
 const float NSBlack;

 NSFont-PostScript Transformation Matrix

 const float *NSFontIdentityMatrix;

 Discussion

 NSFontIdentityMatrix is a transformation matrix useful as a parameter to the NSFont method fontWithName:matrix: .

 NSWindow-Sizes

 NSSize NSIconSize;
 NSSize NSTokenSize;


 */


#ifdef GNUSTEP

#include "_App_Enum.GNUstep.inc"
#include "_App_Str.GNUstep.inc"

#else /* !GNUSTEP */

#include "_App_Enum.inc"
#include "_App_Str.inc"

#endif /* !GNUSTEP */

/*
 * Manually added, will be automatic in next version of generator script
 */
struct uchar_table {
	char*       name;
	Py_UNICODE  value;
} g_unicode_characters[] = {
    { "NSUpArrowFunctionKey", NSUpArrowFunctionKey },
    { "NSDownArrowFunctionKey", NSDownArrowFunctionKey },
    { "NSLeftArrowFunctionKey", NSLeftArrowFunctionKey },
    { "NSRightArrowFunctionKey", NSRightArrowFunctionKey },
    { "NSF1FunctionKey", NSF1FunctionKey },
    { "NSF2FunctionKey", NSF2FunctionKey },
    { "NSF3FunctionKey", NSF3FunctionKey },
    { "NSF4FunctionKey", NSF4FunctionKey },
    { "NSF5FunctionKey", NSF5FunctionKey },
    { "NSF6FunctionKey", NSF6FunctionKey },
    { "NSF7FunctionKey", NSF7FunctionKey },
    { "NSF8FunctionKey", NSF8FunctionKey },
    { "NSF9FunctionKey", NSF9FunctionKey },
    { "NSF10FunctionKey", NSF10FunctionKey },
    { "NSF11FunctionKey", NSF11FunctionKey },
    { "NSF12FunctionKey", NSF12FunctionKey },
    { "NSF13FunctionKey", NSF13FunctionKey },
    { "NSF14FunctionKey", NSF14FunctionKey },
    { "NSF15FunctionKey", NSF15FunctionKey },
    { "NSF16FunctionKey", NSF16FunctionKey },
    { "NSF17FunctionKey", NSF17FunctionKey },
    { "NSF18FunctionKey", NSF18FunctionKey },
    { "NSF19FunctionKey", NSF19FunctionKey },
    { "NSF20FunctionKey", NSF20FunctionKey },
    { "NSF21FunctionKey", NSF21FunctionKey },
    { "NSF22FunctionKey", NSF22FunctionKey },
    { "NSF23FunctionKey", NSF23FunctionKey },
    { "NSF24FunctionKey", NSF24FunctionKey },
    { "NSF25FunctionKey", NSF25FunctionKey },
    { "NSF26FunctionKey", NSF26FunctionKey },
    { "NSF27FunctionKey", NSF27FunctionKey },
    { "NSF28FunctionKey", NSF28FunctionKey },
    { "NSF29FunctionKey", NSF29FunctionKey },
    { "NSF30FunctionKey", NSF30FunctionKey },
    { "NSF31FunctionKey", NSF31FunctionKey },
    { "NSF32FunctionKey", NSF32FunctionKey },
    { "NSF33FunctionKey", NSF33FunctionKey },
    { "NSF34FunctionKey", NSF34FunctionKey },
    { "NSF35FunctionKey", NSF35FunctionKey },
    { "NSInsertFunctionKey", NSInsertFunctionKey },
    { "NSDeleteFunctionKey", NSDeleteFunctionKey },
    { "NSHomeFunctionKey", NSHomeFunctionKey },
    { "NSBeginFunctionKey", NSBeginFunctionKey },
    { "NSEndFunctionKey", NSEndFunctionKey },
    { "NSPageUpFunctionKey", NSPageUpFunctionKey },
    { "NSPageDownFunctionKey", NSPageDownFunctionKey },
    { "NSPrintScreenFunctionKey", NSPrintScreenFunctionKey },
    { "NSScrollLockFunctionKey", NSScrollLockFunctionKey },
    { "NSPauseFunctionKey", NSPauseFunctionKey },
    { "NSSysReqFunctionKey", NSSysReqFunctionKey },
    { "NSBreakFunctionKey", NSBreakFunctionKey },
    { "NSResetFunctionKey", NSResetFunctionKey },
    { "NSStopFunctionKey", NSStopFunctionKey },
    { "NSMenuFunctionKey", NSMenuFunctionKey },
    { "NSUserFunctionKey", NSUserFunctionKey },
    { "NSSystemFunctionKey", NSSystemFunctionKey },
    { "NSPrintFunctionKey", NSPrintFunctionKey },
    { "NSClearLineFunctionKey", NSClearLineFunctionKey },
    { "NSClearDisplayFunctionKey", NSClearDisplayFunctionKey },
    { "NSInsertLineFunctionKey", NSInsertLineFunctionKey },
    { "NSDeleteLineFunctionKey", NSDeleteLineFunctionKey },
    { "NSInsertCharFunctionKey", NSInsertCharFunctionKey },
    { "NSDeleteCharFunctionKey", NSDeleteCharFunctionKey },
    { "NSPrevFunctionKey", NSPrevFunctionKey },
    { "NSNextFunctionKey", NSNextFunctionKey },
    { "NSSelectFunctionKey", NSSelectFunctionKey },
    { "NSExecuteFunctionKey", NSExecuteFunctionKey },
    { "NSUndoFunctionKey", NSUndoFunctionKey },
    { "NSRedoFunctionKey", NSRedoFunctionKey },
    { "NSFindFunctionKey", NSFindFunctionKey },
    { "NSHelpFunctionKey", NSHelpFunctionKey },
    { "NSModeSwitchFunctionKey", NSModeSwitchFunctionKey },
    { NULL, 0 }
};


static int 
fontMatrix(PyObject* d, const char* name, const float* value)
{
	int i;

	if (value == NULL) {
		return PyDict_SetItemString(d, (char*)name, Py_None);
	}
	PyObject* v = PyTuple_New(6);
	if (v == NULL) {
		return -1;
	}

	for (i = 0; i < 6; i++) {
		PyObject* t;

		t = PyFloat_FromDouble(value[i]);
		if (t == NULL) {
			Py_DECREF(v);
			return -1;
		}
	}
	
	if (PyDict_SetItemString(d, (char*)name, v) == -1) {
		Py_DECREF(v);
		return -1;
	}
	Py_DECREF(v);
	return 0;
}


void init_AppKit(void);

void init_AppKit(void)
{
	PyObject *m, *d;
	CFBundleRef bundle;

	m = Py_InitModule4("_AppKit", appkit_methods, appkit_doc, 
		NULL, PYTHON_API_VERSION);
	if (!m) return;

	d = PyModule_GetDict(m);
	if (!d) return;

	if (PyObjC_ImportAPI(m) < 0) {
		return;
	}

	bundle = CFBundleCreate(NULL,
		(CFURLRef)[NSURL fileURLWithPath:@"/System/Library/Frameworks/AppKit.framework"]);

	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;

	//CFRelease(bundle);

#ifdef GNUSTEP

#	include "_App_Var.GNUstep.inc"

#else /* !GNUSTEP */

#	include "_App_Var.inc"

#endif /* !GNUSTEP */

	/* And some troublesome definitions 
	 * All of these found by 'grep #define *.h' in the AppKit header 
	 * directory
	 */

#ifndef GNUSTEP
	/* NSOpenGL.h */
	add_int(d, "NSOPENGL_CURRENT_VERSION", NSOPENGL_CURRENT_VERSION);

	/* NSStatusBar.h */
	add_int(d, "NSVariableStatusItemLength", NSVariableStatusItemLength);
	add_int(d, "NSSquareStatusItemLength", NSSquareStatusItemLength);

	/* NSTypesetter.h */
	add_int(d, "NSBaselineNotSet", NSBaselineNotSet);
	add_int(d, "NumGlyphsToGetEachTime", NumGlyphsToGetEachTime);
#endif

	/* NSWindow.h */
	add_int(d, "NSNormalWindowLevel", NSNormalWindowLevel);
	add_int(d, "NSFloatingWindowLevel", NSFloatingWindowLevel);
	add_int(d, "NSSubmenuWindowLevel", NSSubmenuWindowLevel);
	add_int(d, "NSTornOffMenuWindowLevel", NSTornOffMenuWindowLevel);
	add_int(d, "NSMainMenuWindowLevel", NSMainMenuWindowLevel);
	add_int(d, "NSStatusWindowLevel", NSStatusWindowLevel);
	add_int(d, "NSModalPanelWindowLevel", NSModalPanelWindowLevel);
	add_int(d, "NSPopUpMenuWindowLevel", NSPopUpMenuWindowLevel);
	add_int(d, "NSScreenSaverWindowLevel", NSScreenSaverWindowLevel);


	add_int(d, "NSNoCellMask", NSNoCellMask);
	add_int(d, "NSContentsCellMask", NSContentsCellMask);
	add_int(d, "NSPushInCellMask", NSPushInCellMask);
	add_int(d, "NSChangeGrayCellMask", NSChangeGrayCellMask);
	add_int(d, "NSChangeBackgroundCellMask", NSChangeBackgroundCellMask);
	add_int(d, "NSColorPanelGrayModeMask", NSColorPanelGrayModeMask);
	add_int(d, "NSColorPanelRGBModeMask", NSColorPanelRGBModeMask);
	add_int(d, "NSColorPanelCMYKModeMask", NSColorPanelCMYKModeMask);
	add_int(d, "NSColorPanelHSBModeMask", NSColorPanelHSBModeMask);
	add_int(d, "NSColorPanelCustomPaletteModeMask", NSColorPanelCustomPaletteModeMask);
	add_int(d, "NSColorPanelColorListModeMask", NSColorPanelColorListModeMask);
	add_int(d, "NSColorPanelWheelModeMask", NSColorPanelWheelModeMask);
#ifndef GNUSTEP
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
	add_int(d, "NSColorPanelCrayonModeMask", NSColorPanelCrayonModeMask);
#endif
#endif
	add_int(d, "NSColorPanelAllModesMask", NSColorPanelAllModesMask);
	add_int(d, "NSLeftMouseDownMask", NSLeftMouseDownMask);
	add_int(d, "NSLeftMouseUpMask", NSLeftMouseUpMask);
	add_int(d, "NSRightMouseDownMask", NSRightMouseDownMask);
	add_int(d, "NSRightMouseUpMask", NSRightMouseUpMask);
	add_int(d, "NSMouseMovedMask", NSMouseMovedMask);
	add_int(d, "NSLeftMouseDraggedMask", NSLeftMouseDraggedMask);
	add_int(d, "NSRightMouseDraggedMask", NSRightMouseDraggedMask);
	add_int(d, "NSMouseEnteredMask", NSMouseEnteredMask);
	add_int(d, "NSMouseExitedMask", NSMouseExitedMask);
	add_int(d, "NSKeyDownMask", NSKeyDownMask);
	add_int(d, "NSKeyUpMask", NSKeyUpMask);
	add_int(d, "NSFlagsChangedMask", NSFlagsChangedMask);
	add_int(d, "NSAppKitDefinedMask", NSAppKitDefinedMask);
	add_int(d, "NSSystemDefinedMask", NSSystemDefinedMask);
	add_int(d, "NSApplicationDefinedMask", NSApplicationDefinedMask);
	add_int(d, "NSPeriodicMask", NSPeriodicMask);
	add_int(d, "NSCursorUpdateMask", NSCursorUpdateMask);
	add_int(d, "NSScrollWheelMask", NSScrollWheelMask);
	add_int(d, "NSOtherMouseDownMask", NSOtherMouseDownMask);
	add_int(d, "NSOtherMouseUpMask", NSOtherMouseUpMask);
	add_int(d, "NSOtherMouseDraggedMask", NSOtherMouseDraggedMask);
	add_int(d, "NSAnyEventMask", NSAnyEventMask);
	add_int(d, "NSAlphaShiftKeyMask", NSAlphaShiftKeyMask);
	add_int(d, "NSShiftKeyMask", NSShiftKeyMask);
	add_int(d, "NSControlKeyMask", NSControlKeyMask);
	add_int(d, "NSAlternateKeyMask", NSAlternateKeyMask);
	add_int(d, "NSCommandKeyMask", NSCommandKeyMask);
	add_int(d, "NSNumericPadKeyMask", NSNumericPadKeyMask);
	add_int(d, "NSHelpKeyMask", NSHelpKeyMask);
	add_int(d, "NSFunctionKeyMask", NSFunctionKeyMask);
	add_int(d, "NSItalicFontMask", NSItalicFontMask);
	add_int(d, "NSBoldFontMask", NSBoldFontMask);
	add_int(d, "NSUnboldFontMask", NSUnboldFontMask);
	add_int(d, "NSNonStandardCharacterSetFontMask", NSNonStandardCharacterSetFontMask);
	add_int(d, "NSNarrowFontMask", NSNarrowFontMask);
	add_int(d, "NSExpandedFontMask", NSExpandedFontMask);
	add_int(d, "NSCondensedFontMask", NSCondensedFontMask);
	add_int(d, "NSSmallCapsFontMask", NSSmallCapsFontMask);
	add_int(d, "NSPosterFontMask", NSPosterFontMask);
	add_int(d, "NSCompressedFontMask", NSCompressedFontMask);
	add_int(d, "NSFixedPitchFontMask", NSFixedPitchFontMask);
	add_int(d, "NSUnitalicFontMask", NSUnitalicFontMask);
	add_int(d, "NSUtilityWindowMask", NSUtilityWindowMask);
	add_int(d, "NSDocModalWindowMask", NSDocModalWindowMask);
#ifndef GNUSTEP
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
	add_int(d, "NSNonactivatingPanelMask", NSNonactivatingPanelMask);
#endif
#endif
	add_int(d, "NSBorderlessWindowMask", NSBorderlessWindowMask);
	add_int(d, "NSTitledWindowMask", NSTitledWindowMask);
	add_int(d, "NSClosableWindowMask", NSClosableWindowMask);
	add_int(d, "NSMiniaturizableWindowMask", NSMiniaturizableWindowMask);
	add_int(d, "NSResizableWindowMask", NSResizableWindowMask);
#ifndef GNUSTEP
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
	add_int(d, "NSTexturedBackgroundWindowMask", NSTexturedBackgroundWindowMask);
#endif
#endif

	{
	  struct uchar_table*  cur = g_unicode_characters;
	  PyObject* v;
	  int       res;

	  for (; cur->name != NULL; cur++) {
		  v = PyUnicode_FromUnicode(&cur->value, 1);
		  if (v == NULL) return;

	          res = PyDict_SetItemString(d, cur->name, v);
	          if (res < 0) return;
	  }
	}


	/* Some special constants */
	fontMatrix(d, "NSFontIdentityMatrix", NSFontIdentityMatrix);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.