1/*
2 * Support code for dealing with Carbon types (at least those
3 * used in AppKit and wrapped in the python core).
4 */
5
6#if PY_MAJOR_VERSION == 2
7
8#ifndef __LP64__
9
10#include "pymactoolbox.h"
11
12#else
13	/* FIXME: the bits of pymactoolbox.h that we need,
14	 * because said header doesn't work in 64-bit mode
15	 */
16extern PyObject *WinObj_New(WindowPtr);
17extern int WinObj_Convert(PyObject *, WindowPtr *);
18extern PyObject *WinObj_WhichWindow(WindowPtr);
19
20#endif
21
22static int
23py2window(PyObject* obj, void* output)
24{
25	return WinObj_Convert(obj, (WindowPtr*)output);
26}
27
28static PyObject*
29window2py(void* value)
30{
31	return WinObj_New((WindowPtr)value);
32}
33
34#endif /* PY_MAJOR_VERSION == 2 */
35
36static int setup_carbon(PyObject* m __attribute__((__unused__)))
37{
38#if PY_MAJOR_VERSION == 2
39	if (PyObjCPointerWrapper_Register(@encode(WindowRef),
40	                &window2py, &py2window) < 0)
41		return -1;
42#endif
43
44	return 0;
45}
46