blob: fa910e3bf68ebad19e6efeeee5e8b07c4c5c06a3 [file] [log] [blame]
Jack Jansenf57a4a22001-05-17 22:11:44 +00001/*
2** mactoolboxglue.c - Glue together the toolbox objects.
3**
4** Because toolbox modules interdepend on each other, they use each others
5** object types, on MacOSX/MachO this leads to the situation that they
6** cannot be dynamically loaded (or they would all have to be lumped into
7** a single .so, but this would be bad for extensibility).
8**
9** This file defines wrappers for all the _New and _Convert functions,
10** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers
11** check an indirection function pointer, and if it isn't filled in yet
12** they import the appropriate module, whose init routine should fill in
13** the pointer.
14*/
15
16#ifdef USE_TOOLBOX_OBJECT_GLUE
17
18#include "python.h"
19#include "pymactoolbox.h"
20
21#define GLUE_NEW(object, routinename, module) \
22PyObject *(*PyMacGluePtr_##routinename)(object); \
23\
24PyObject *routinename(object cobj) { \
25 if (!PyMacGluePtr_##routinename) { \
26 if (!PyImport_ImportModule(module)) return NULL; \
27 if (!PyMacGluePtr_##routinename) { \
28 PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
29 return NULL; \
30 } \
31 } \
32 return (*PyMacGluePtr_##routinename)(cobj); \
33}
34
35#define GLUE_CONVERT(object, routinename, module) \
36int (*PyMacGluePtr_##routinename)(PyObject *, object *); \
37\
38int routinename(PyObject *pyobj, object *cobj) { \
39 if (!PyMacGluePtr_##routinename) { \
40 if (!PyImport_ImportModule(module)) return NULL; \
41 if (!PyMacGluePtr_##routinename) { \
42 PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
43 return NULL; \
44 } \
45 } \
46 return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
47}
48
49GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */
50GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE")
51
52GLUE_NEW(Component, CmpObj_New, "Cm")
53GLUE_CONVERT(Component, CmpObj_Convert, "Cm")
54GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm")
55GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm")
56
57GLUE_NEW(ControlHandle, CtlObj_New, "Ctl")
58GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl")
59
60GLUE_NEW(DialogPtr, DlgObj_New, "Dlg")
61GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg")
62GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg")
63
64GLUE_NEW(DragReference, DragObj_New, "Drag")
65GLUE_CONVERT(DragReference, DragObj_Convert, "Drag")
66
67GLUE_NEW(ListHandle, ListObj_New, "List")
68GLUE_CONVERT(ListHandle, ListObj_Convert, "List")
69
70GLUE_NEW(MenuHandle, MenuObj_New, "Menu")
71GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu")
72
73GLUE_NEW(GrafPtr, GrafObj_New, "Qd")
74GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd")
75GLUE_NEW(BitMapPtr, BMObj_New, "Qd")
76GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd")
77GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */
78GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd")
79
80GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs")
81GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs")
82
83GLUE_NEW(Track, TrackObj_New, "Qt")
84GLUE_CONVERT(Track, TrackObj_Convert, "Qt")
85GLUE_NEW(Movie, MovieObj_New, "Qt")
86GLUE_CONVERT(Movie, MovieObj_Convert, "Qt")
87GLUE_NEW(MovieController, MovieCtlObj_New, "Qt")
88GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt")
89GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt")
90GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt")
91GLUE_NEW(UserData, UserDataObj_New, "Qt")
92GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt")
93GLUE_NEW(Media, MediaObj_New, "Qt")
94GLUE_CONVERT(Media, MediaObj_Convert, "Qt")
95
96GLUE_NEW(Handle, ResObj_New, "Res")
97GLUE_CONVERT(Handle, ResObj_Convert, "Res")
98GLUE_NEW(Handle, OptResObj_New, "Res")
99GLUE_CONVERT(Handle, OptResObj_Convert, "Res")
100
101GLUE_NEW(TEHandle, TEObj_New, "TE")
102GLUE_CONVERT(TEHandle, TEObj_Convert, "TE")
103
104GLUE_NEW(WindowPtr, WinObj_New, "Win")
105GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win")
106GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win")
107
108#endif /* USE_TOOLBOX_OBJECT_GLUE */