2 /* ======================== Module _IBCarbon ======================== */
8 #ifdef WITHOUT_FRAMEWORKS
9 #include <IBCarbonRuntime.h>
11 #include <Carbon/Carbon.h>
12 #endif /* WITHOUT_FRAMEWORKS */
15 #ifdef USE_TOOLBOX_OBJECT_GLUE
16 extern int _CFStringRefObj_Convert(PyObject
*, CFStringRef
*);
17 //#define CFStringRefObj_Convert _CFStringRefObj_Convert
20 //extern int CFBundleRefObj_Convert(PyObject *, CFBundleRef *); // need to wrap CFBundle
23 static PyObject
*IBCarbon_Error
;
25 /* ---------------------- Object type IBNibRef ---------------------- */
27 PyTypeObject IBNibRef_Type
;
29 #define IBNibRefObj_Check(x) ((x)->ob_type == &IBNibRef_Type || PyObject_TypeCheck((x), &IBNibRef_Type))
31 typedef struct IBNibRefObject
{
36 PyObject
*IBNibRefObj_New(IBNibRef itself
)
39 it
= PyObject_NEW(IBNibRefObject
, &IBNibRef_Type
);
40 if (it
== NULL
) return NULL
;
41 it
->ob_itself
= itself
;
42 return (PyObject
*)it
;
44 int IBNibRefObj_Convert(PyObject
*v
, IBNibRef
*p_itself
)
46 if (!IBNibRefObj_Check(v
))
48 PyErr_SetString(PyExc_TypeError
, "IBNibRef required");
51 *p_itself
= ((IBNibRefObject
*)v
)->ob_itself
;
55 static void IBNibRefObj_dealloc(IBNibRefObject
*self
)
57 DisposeNibReference(self
->ob_itself
);
58 self
->ob_type
->tp_free((PyObject
*)self
);
61 static PyObject
*IBNibRefObj_CreateWindowFromNib(IBNibRefObject
*_self
, PyObject
*_args
)
63 PyObject
*_res
= NULL
;
67 if (!PyArg_ParseTuple(_args
, "O&",
68 CFStringRefObj_Convert
, &inName
))
70 _err
= CreateWindowFromNib(_self
->ob_itself
,
73 if (_err
!= noErr
) return PyMac_Error(_err
);
74 _res
= Py_BuildValue("O&",
75 WinObj_New
, outWindow
);
79 static PyObject
*IBNibRefObj_CreateMenuFromNib(IBNibRefObject
*_self
, PyObject
*_args
)
81 PyObject
*_res
= NULL
;
84 MenuHandle outMenuRef
;
85 if (!PyArg_ParseTuple(_args
, "O&",
86 CFStringRefObj_Convert
, &inName
))
88 _err
= CreateMenuFromNib(_self
->ob_itself
,
91 if (_err
!= noErr
) return PyMac_Error(_err
);
92 _res
= Py_BuildValue("O&",
93 MenuObj_New
, outMenuRef
);
97 static PyObject
*IBNibRefObj_CreateMenuBarFromNib(IBNibRefObject
*_self
, PyObject
*_args
)
99 PyObject
*_res
= NULL
;
103 if (!PyArg_ParseTuple(_args
, "O&",
104 CFStringRefObj_Convert
, &inName
))
106 _err
= CreateMenuBarFromNib(_self
->ob_itself
,
109 if (_err
!= noErr
) return PyMac_Error(_err
);
110 _res
= Py_BuildValue("O&",
111 ResObj_New
, outMenuBar
);
115 static PyObject
*IBNibRefObj_SetMenuBarFromNib(IBNibRefObject
*_self
, PyObject
*_args
)
117 PyObject
*_res
= NULL
;
120 if (!PyArg_ParseTuple(_args
, "O&",
121 CFStringRefObj_Convert
, &inName
))
123 _err
= SetMenuBarFromNib(_self
->ob_itself
,
125 if (_err
!= noErr
) return PyMac_Error(_err
);
131 static PyMethodDef IBNibRefObj_methods
[] = {
132 {"CreateWindowFromNib", (PyCFunction
)IBNibRefObj_CreateWindowFromNib
, 1,
133 PyDoc_STR("(CFStringRef inName) -> (WindowPtr outWindow)")},
134 {"CreateMenuFromNib", (PyCFunction
)IBNibRefObj_CreateMenuFromNib
, 1,
135 PyDoc_STR("(CFStringRef inName) -> (MenuHandle outMenuRef)")},
136 {"CreateMenuBarFromNib", (PyCFunction
)IBNibRefObj_CreateMenuBarFromNib
, 1,
137 PyDoc_STR("(CFStringRef inName) -> (Handle outMenuBar)")},
138 {"SetMenuBarFromNib", (PyCFunction
)IBNibRefObj_SetMenuBarFromNib
, 1,
139 PyDoc_STR("(CFStringRef inName) -> None")},
143 #define IBNibRefObj_getsetlist NULL
146 #define IBNibRefObj_compare NULL
148 #define IBNibRefObj_repr NULL
150 #define IBNibRefObj_hash NULL
151 #define IBNibRefObj_tp_init 0
153 #define IBNibRefObj_tp_alloc PyType_GenericAlloc
155 static PyObject
*IBNibRefObj_tp_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
159 char *kw
[] = {"itself", 0};
161 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "O&", kw
, IBNibRefObj_Convert
, &itself
)) return NULL
;
162 if ((self
= type
->tp_alloc(type
, 0)) == NULL
) return NULL
;
163 ((IBNibRefObject
*)self
)->ob_itself
= itself
;
167 #define IBNibRefObj_tp_free PyObject_Del
170 PyTypeObject IBNibRef_Type
= {
171 PyObject_HEAD_INIT(NULL
)
173 "_IBCarbon.IBNibRef", /*tp_name*/
174 sizeof(IBNibRefObject
), /*tp_basicsize*/
177 (destructor
) IBNibRefObj_dealloc
, /*tp_dealloc*/
179 (getattrfunc
)0, /*tp_getattr*/
180 (setattrfunc
)0, /*tp_setattr*/
181 (cmpfunc
) IBNibRefObj_compare
, /*tp_compare*/
182 (reprfunc
) IBNibRefObj_repr
, /*tp_repr*/
183 (PyNumberMethods
*)0, /* tp_as_number */
184 (PySequenceMethods
*)0, /* tp_as_sequence */
185 (PyMappingMethods
*)0, /* tp_as_mapping */
186 (hashfunc
) IBNibRefObj_hash
, /*tp_hash*/
189 PyObject_GenericGetAttr
, /*tp_getattro*/
190 PyObject_GenericSetAttr
, /*tp_setattro */
192 Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
, /* tp_flags */
196 0, /*tp_richcompare*/
197 0, /*tp_weaklistoffset*/
200 IBNibRefObj_methods
, /* tp_methods */
202 IBNibRefObj_getsetlist
, /*tp_getset*/
208 IBNibRefObj_tp_init
, /* tp_init */
209 IBNibRefObj_tp_alloc
, /* tp_alloc */
210 IBNibRefObj_tp_new
, /* tp_new */
211 IBNibRefObj_tp_free
, /* tp_free */
214 /* -------------------- End object type IBNibRef -------------------- */
217 static PyObject
*IBCarbon_CreateNibReference(PyObject
*_self
, PyObject
*_args
)
219 PyObject
*_res
= NULL
;
221 CFStringRef inNibName
;
223 if (!PyArg_ParseTuple(_args
, "O&",
224 CFStringRefObj_Convert
, &inNibName
))
226 _err
= CreateNibReference(inNibName
,
228 if (_err
!= noErr
) return PyMac_Error(_err
);
229 _res
= Py_BuildValue("O&",
230 IBNibRefObj_New
, outNibRef
);
234 static PyMethodDef IBCarbon_methods
[] = {
235 {"CreateNibReference", (PyCFunction
)IBCarbon_CreateNibReference
, 1,
236 PyDoc_STR("(CFStringRef inNibName) -> (IBNibRef outNibRef)")},
243 void init_IBCarbon(void)
252 m
= Py_InitModule("_IBCarbon", IBCarbon_methods
);
253 d
= PyModule_GetDict(m
);
254 IBCarbon_Error
= PyMac_GetOSErrException();
255 if (IBCarbon_Error
== NULL
||
256 PyDict_SetItemString(d
, "Error", IBCarbon_Error
) != 0)
258 IBNibRef_Type
.ob_type
= &PyType_Type
;
259 if (PyType_Ready(&IBNibRef_Type
) < 0) return;
260 Py_INCREF(&IBNibRef_Type
);
261 PyModule_AddObject(m
, "IBNibRef", (PyObject
*)&IBNibRef_Type
);
262 /* Backward-compatible name */
263 Py_INCREF(&IBNibRef_Type
);
264 PyModule_AddObject(m
, "IBNibRefType", (PyObject
*)&IBNibRef_Type
);
267 /* ====================== End module _IBCarbon ====================== */