| 1 | n/a | |
|---|
| 2 | n/a | /* ======================== Module _IBCarbon ======================== */ |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | #include "Python.h" |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | #ifndef __LP64__ |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | #include <Carbon/Carbon.h> |
|---|
| 10 | n/a | #include "pymactoolbox.h" |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 13 | n/a | extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *); |
|---|
| 14 | n/a | #endif |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | static PyObject *IBCarbon_Error; |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | /* ---------------------- Object type IBNibRef ---------------------- */ |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | PyTypeObject IBNibRef_Type; |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | #define IBNibRefObj_Check(x) ((x)->ob_type == &IBNibRef_Type || PyObject_TypeCheck((x), &IBNibRef_Type)) |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | typedef struct IBNibRefObject { |
|---|
| 26 | n/a | PyObject_HEAD |
|---|
| 27 | n/a | IBNibRef ob_itself; |
|---|
| 28 | n/a | } IBNibRefObject; |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | PyObject *IBNibRefObj_New(IBNibRef itself) |
|---|
| 31 | n/a | { |
|---|
| 32 | n/a | IBNibRefObject *it; |
|---|
| 33 | n/a | it = PyObject_NEW(IBNibRefObject, &IBNibRef_Type); |
|---|
| 34 | n/a | if (it == NULL) return NULL; |
|---|
| 35 | n/a | it->ob_itself = itself; |
|---|
| 36 | n/a | return (PyObject *)it; |
|---|
| 37 | n/a | } |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | int IBNibRefObj_Convert(PyObject *v, IBNibRef *p_itself) |
|---|
| 40 | n/a | { |
|---|
| 41 | n/a | if (!IBNibRefObj_Check(v)) |
|---|
| 42 | n/a | { |
|---|
| 43 | n/a | PyErr_SetString(PyExc_TypeError, "IBNibRef required"); |
|---|
| 44 | n/a | return 0; |
|---|
| 45 | n/a | } |
|---|
| 46 | n/a | *p_itself = ((IBNibRefObject *)v)->ob_itself; |
|---|
| 47 | n/a | return 1; |
|---|
| 48 | n/a | } |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | static void IBNibRefObj_dealloc(IBNibRefObject *self) |
|---|
| 51 | n/a | { |
|---|
| 52 | n/a | DisposeNibReference(self->ob_itself); |
|---|
| 53 | n/a | self->ob_type->tp_free((PyObject *)self); |
|---|
| 54 | n/a | } |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | static PyObject *IBNibRefObj_CreateWindowFromNib(IBNibRefObject *_self, PyObject *_args) |
|---|
| 57 | n/a | { |
|---|
| 58 | n/a | PyObject *_res = NULL; |
|---|
| 59 | n/a | OSStatus _err; |
|---|
| 60 | n/a | CFStringRef inName; |
|---|
| 61 | n/a | WindowPtr outWindow; |
|---|
| 62 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 63 | n/a | CFStringRefObj_Convert, &inName)) |
|---|
| 64 | n/a | return NULL; |
|---|
| 65 | n/a | _err = CreateWindowFromNib(_self->ob_itself, |
|---|
| 66 | n/a | inName, |
|---|
| 67 | n/a | &outWindow); |
|---|
| 68 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 69 | n/a | _res = Py_BuildValue("O&", |
|---|
| 70 | n/a | WinObj_New, outWindow); |
|---|
| 71 | n/a | return _res; |
|---|
| 72 | n/a | } |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | static PyObject *IBNibRefObj_CreateMenuFromNib(IBNibRefObject *_self, PyObject *_args) |
|---|
| 75 | n/a | { |
|---|
| 76 | n/a | PyObject *_res = NULL; |
|---|
| 77 | n/a | OSStatus _err; |
|---|
| 78 | n/a | CFStringRef inName; |
|---|
| 79 | n/a | MenuHandle outMenuRef; |
|---|
| 80 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 81 | n/a | CFStringRefObj_Convert, &inName)) |
|---|
| 82 | n/a | return NULL; |
|---|
| 83 | n/a | _err = CreateMenuFromNib(_self->ob_itself, |
|---|
| 84 | n/a | inName, |
|---|
| 85 | n/a | &outMenuRef); |
|---|
| 86 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 87 | n/a | _res = Py_BuildValue("O&", |
|---|
| 88 | n/a | MenuObj_New, outMenuRef); |
|---|
| 89 | n/a | return _res; |
|---|
| 90 | n/a | } |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | static PyObject *IBNibRefObj_CreateMenuBarFromNib(IBNibRefObject *_self, PyObject *_args) |
|---|
| 93 | n/a | { |
|---|
| 94 | n/a | PyObject *_res = NULL; |
|---|
| 95 | n/a | OSStatus _err; |
|---|
| 96 | n/a | CFStringRef inName; |
|---|
| 97 | n/a | Handle outMenuBar; |
|---|
| 98 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 99 | n/a | CFStringRefObj_Convert, &inName)) |
|---|
| 100 | n/a | return NULL; |
|---|
| 101 | n/a | _err = CreateMenuBarFromNib(_self->ob_itself, |
|---|
| 102 | n/a | inName, |
|---|
| 103 | n/a | &outMenuBar); |
|---|
| 104 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 105 | n/a | _res = Py_BuildValue("O&", |
|---|
| 106 | n/a | ResObj_New, outMenuBar); |
|---|
| 107 | n/a | return _res; |
|---|
| 108 | n/a | } |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | static PyObject *IBNibRefObj_SetMenuBarFromNib(IBNibRefObject *_self, PyObject *_args) |
|---|
| 111 | n/a | { |
|---|
| 112 | n/a | PyObject *_res = NULL; |
|---|
| 113 | n/a | OSStatus _err; |
|---|
| 114 | n/a | CFStringRef inName; |
|---|
| 115 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 116 | n/a | CFStringRefObj_Convert, &inName)) |
|---|
| 117 | n/a | return NULL; |
|---|
| 118 | n/a | _err = SetMenuBarFromNib(_self->ob_itself, |
|---|
| 119 | n/a | inName); |
|---|
| 120 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 121 | n/a | Py_INCREF(Py_None); |
|---|
| 122 | n/a | _res = Py_None; |
|---|
| 123 | n/a | return _res; |
|---|
| 124 | n/a | } |
|---|
| 125 | n/a | |
|---|
| 126 | n/a | static PyMethodDef IBNibRefObj_methods[] = { |
|---|
| 127 | n/a | {"CreateWindowFromNib", (PyCFunction)IBNibRefObj_CreateWindowFromNib, 1, |
|---|
| 128 | n/a | PyDoc_STR("(CFStringRef inName) -> (WindowPtr outWindow)")}, |
|---|
| 129 | n/a | {"CreateMenuFromNib", (PyCFunction)IBNibRefObj_CreateMenuFromNib, 1, |
|---|
| 130 | n/a | PyDoc_STR("(CFStringRef inName) -> (MenuHandle outMenuRef)")}, |
|---|
| 131 | n/a | {"CreateMenuBarFromNib", (PyCFunction)IBNibRefObj_CreateMenuBarFromNib, 1, |
|---|
| 132 | n/a | PyDoc_STR("(CFStringRef inName) -> (Handle outMenuBar)")}, |
|---|
| 133 | n/a | {"SetMenuBarFromNib", (PyCFunction)IBNibRefObj_SetMenuBarFromNib, 1, |
|---|
| 134 | n/a | PyDoc_STR("(CFStringRef inName) -> None")}, |
|---|
| 135 | n/a | {NULL, NULL, 0} |
|---|
| 136 | n/a | }; |
|---|
| 137 | n/a | |
|---|
| 138 | n/a | #define IBNibRefObj_getsetlist NULL |
|---|
| 139 | n/a | |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | #define IBNibRefObj_compare NULL |
|---|
| 142 | n/a | |
|---|
| 143 | n/a | #define IBNibRefObj_repr NULL |
|---|
| 144 | n/a | |
|---|
| 145 | n/a | #define IBNibRefObj_hash NULL |
|---|
| 146 | n/a | #define IBNibRefObj_tp_init 0 |
|---|
| 147 | n/a | |
|---|
| 148 | n/a | #define IBNibRefObj_tp_alloc PyType_GenericAlloc |
|---|
| 149 | n/a | |
|---|
| 150 | n/a | static PyObject *IBNibRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) |
|---|
| 151 | n/a | { |
|---|
| 152 | n/a | PyObject *_self; |
|---|
| 153 | n/a | IBNibRef itself; |
|---|
| 154 | n/a | char *kw[] = {"itself", 0}; |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, IBNibRefObj_Convert, &itself)) return NULL; |
|---|
| 157 | n/a | if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; |
|---|
| 158 | n/a | ((IBNibRefObject *)_self)->ob_itself = itself; |
|---|
| 159 | n/a | return _self; |
|---|
| 160 | n/a | } |
|---|
| 161 | n/a | |
|---|
| 162 | n/a | #define IBNibRefObj_tp_free PyObject_Del |
|---|
| 163 | n/a | |
|---|
| 164 | n/a | |
|---|
| 165 | n/a | PyTypeObject IBNibRef_Type = { |
|---|
| 166 | n/a | PyObject_HEAD_INIT(NULL) |
|---|
| 167 | n/a | 0, /*ob_size*/ |
|---|
| 168 | n/a | "_IBCarbon.IBNibRef", /*tp_name*/ |
|---|
| 169 | n/a | sizeof(IBNibRefObject), /*tp_basicsize*/ |
|---|
| 170 | n/a | 0, /*tp_itemsize*/ |
|---|
| 171 | n/a | /* methods */ |
|---|
| 172 | n/a | (destructor) IBNibRefObj_dealloc, /*tp_dealloc*/ |
|---|
| 173 | n/a | 0, /*tp_print*/ |
|---|
| 174 | n/a | (getattrfunc)0, /*tp_getattr*/ |
|---|
| 175 | n/a | (setattrfunc)0, /*tp_setattr*/ |
|---|
| 176 | n/a | (cmpfunc) IBNibRefObj_compare, /*tp_compare*/ |
|---|
| 177 | n/a | (reprfunc) IBNibRefObj_repr, /*tp_repr*/ |
|---|
| 178 | n/a | (PyNumberMethods *)0, /* tp_as_number */ |
|---|
| 179 | n/a | (PySequenceMethods *)0, /* tp_as_sequence */ |
|---|
| 180 | n/a | (PyMappingMethods *)0, /* tp_as_mapping */ |
|---|
| 181 | n/a | (hashfunc) IBNibRefObj_hash, /*tp_hash*/ |
|---|
| 182 | n/a | 0, /*tp_call*/ |
|---|
| 183 | n/a | 0, /*tp_str*/ |
|---|
| 184 | n/a | PyObject_GenericGetAttr, /*tp_getattro*/ |
|---|
| 185 | n/a | PyObject_GenericSetAttr, /*tp_setattro */ |
|---|
| 186 | n/a | 0, /*tp_as_buffer*/ |
|---|
| 187 | n/a | Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|---|
| 188 | n/a | 0, /*tp_doc*/ |
|---|
| 189 | n/a | 0, /*tp_traverse*/ |
|---|
| 190 | n/a | 0, /*tp_clear*/ |
|---|
| 191 | n/a | 0, /*tp_richcompare*/ |
|---|
| 192 | n/a | 0, /*tp_weaklistoffset*/ |
|---|
| 193 | n/a | 0, /*tp_iter*/ |
|---|
| 194 | n/a | 0, /*tp_iternext*/ |
|---|
| 195 | n/a | IBNibRefObj_methods, /* tp_methods */ |
|---|
| 196 | n/a | 0, /*tp_members*/ |
|---|
| 197 | n/a | IBNibRefObj_getsetlist, /*tp_getset*/ |
|---|
| 198 | n/a | 0, /*tp_base*/ |
|---|
| 199 | n/a | 0, /*tp_dict*/ |
|---|
| 200 | n/a | 0, /*tp_descr_get*/ |
|---|
| 201 | n/a | 0, /*tp_descr_set*/ |
|---|
| 202 | n/a | 0, /*tp_dictoffset*/ |
|---|
| 203 | n/a | IBNibRefObj_tp_init, /* tp_init */ |
|---|
| 204 | n/a | IBNibRefObj_tp_alloc, /* tp_alloc */ |
|---|
| 205 | n/a | IBNibRefObj_tp_new, /* tp_new */ |
|---|
| 206 | n/a | IBNibRefObj_tp_free, /* tp_free */ |
|---|
| 207 | n/a | }; |
|---|
| 208 | n/a | |
|---|
| 209 | n/a | /* -------------------- End object type IBNibRef -------------------- */ |
|---|
| 210 | n/a | |
|---|
| 211 | n/a | |
|---|
| 212 | n/a | static PyObject *IBCarbon_CreateNibReference(PyObject *_self, PyObject *_args) |
|---|
| 213 | n/a | { |
|---|
| 214 | n/a | PyObject *_res = NULL; |
|---|
| 215 | n/a | OSStatus _err; |
|---|
| 216 | n/a | CFStringRef inNibName; |
|---|
| 217 | n/a | IBNibRef outNibRef; |
|---|
| 218 | n/a | if (!PyArg_ParseTuple(_args, "O&", |
|---|
| 219 | n/a | CFStringRefObj_Convert, &inNibName)) |
|---|
| 220 | n/a | return NULL; |
|---|
| 221 | n/a | _err = CreateNibReference(inNibName, |
|---|
| 222 | n/a | &outNibRef); |
|---|
| 223 | n/a | if (_err != noErr) return PyMac_Error(_err); |
|---|
| 224 | n/a | _res = Py_BuildValue("O&", |
|---|
| 225 | n/a | IBNibRefObj_New, outNibRef); |
|---|
| 226 | n/a | return _res; |
|---|
| 227 | n/a | } |
|---|
| 228 | n/a | #endif /* __LP64__ */ |
|---|
| 229 | n/a | |
|---|
| 230 | n/a | static PyMethodDef IBCarbon_methods[] = { |
|---|
| 231 | n/a | #ifndef __LP64__ |
|---|
| 232 | n/a | {"CreateNibReference", (PyCFunction)IBCarbon_CreateNibReference, 1, |
|---|
| 233 | n/a | PyDoc_STR("(CFStringRef inNibName) -> (IBNibRef outNibRef)")}, |
|---|
| 234 | n/a | #endif /* __LP64__ */ |
|---|
| 235 | n/a | {NULL, NULL, 0} |
|---|
| 236 | n/a | }; |
|---|
| 237 | n/a | |
|---|
| 238 | n/a | |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | |
|---|
| 241 | n/a | void init_IBCarbon(void) |
|---|
| 242 | n/a | { |
|---|
| 243 | n/a | PyObject *m; |
|---|
| 244 | n/a | #ifndef __LP64__ |
|---|
| 245 | n/a | PyObject *d; |
|---|
| 246 | n/a | #endif /* __LP64__ */ |
|---|
| 247 | n/a | |
|---|
| 248 | n/a | |
|---|
| 249 | n/a | |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | |
|---|
| 252 | n/a | m = Py_InitModule("_IBCarbon", IBCarbon_methods); |
|---|
| 253 | n/a | #ifndef __LP64__ |
|---|
| 254 | n/a | d = PyModule_GetDict(m); |
|---|
| 255 | n/a | IBCarbon_Error = PyMac_GetOSErrException(); |
|---|
| 256 | n/a | if (IBCarbon_Error == NULL || |
|---|
| 257 | n/a | PyDict_SetItemString(d, "Error", IBCarbon_Error) != 0) |
|---|
| 258 | n/a | return; |
|---|
| 259 | n/a | IBNibRef_Type.ob_type = &PyType_Type; |
|---|
| 260 | n/a | if (PyType_Ready(&IBNibRef_Type) < 0) return; |
|---|
| 261 | n/a | Py_INCREF(&IBNibRef_Type); |
|---|
| 262 | n/a | PyModule_AddObject(m, "IBNibRef", (PyObject *)&IBNibRef_Type); |
|---|
| 263 | n/a | /* Backward-compatible name */ |
|---|
| 264 | n/a | Py_INCREF(&IBNibRef_Type); |
|---|
| 265 | n/a | PyModule_AddObject(m, "IBNibRefType", (PyObject *)&IBNibRef_Type); |
|---|
| 266 | n/a | #endif /* __LP64__ */ |
|---|
| 267 | n/a | } |
|---|
| 268 | n/a | |
|---|
| 269 | n/a | /* ====================== End module _IBCarbon ====================== */ |
|---|
| 270 | n/a | |
|---|