Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module AE ============================ */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 18 | extern PyObject *OptResObj_New(Handle); |
| 19 | extern int OptResObj_Convert(PyObject *, Handle *); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 20 | |
| 21 | extern PyObject *WinObj_New(WindowPtr); |
| 22 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 23 | extern PyTypeObject Window_Type; |
| 24 | #define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 25 | |
| 26 | extern PyObject *DlgObj_New(DialogPtr); |
| 27 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 28 | extern PyTypeObject Dialog_Type; |
| 29 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 30 | |
| 31 | extern PyObject *MenuObj_New(MenuHandle); |
| 32 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 33 | |
| 34 | extern PyObject *CtlObj_New(ControlHandle); |
| 35 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 36 | |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 37 | extern PyObject *GrafObj_New(GrafPtr); |
| 38 | extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 39 | |
| 40 | extern PyObject *BMObj_New(BitMapPtr); |
| 41 | extern int BMObj_Convert(PyObject *, BitMapPtr *); |
| 42 | |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame^] | 43 | extern PyObject *PMObj_New(PixMapHandle); |
| 44 | extern int PMObj_Convert(PyObject *, PixMapHandle *); |
| 45 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 46 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 47 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 48 | #include <AppleEvents.h> |
| 49 | |
Guido van Rossum | 3075b32 | 1995-02-14 09:48:02 +0000 | [diff] [blame] | 50 | #ifndef HAVE_UNIVERSAL_HEADERS |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 51 | #define AEIdleProcPtr IdleProcPtr |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 52 | #define AEFilterProcPtr EventFilterProcPtr |
| 53 | #define AEEventHandlerProcPtr EventHandlerProcPtr |
| 54 | #endif |
| 55 | |
Guido van Rossum | 3075b32 | 1995-02-14 09:48:02 +0000 | [diff] [blame] | 56 | #ifndef HAVE_UNIVERSAL_HEADERS |
| 57 | /* I'm trying to setup the code here so that is easily automated, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 58 | ** as follows: |
| 59 | ** - Use the UPP in the source |
| 60 | ** - for pre-universal headers, #define each UPP as the corresponding ProcPtr |
| 61 | ** - for each routine we pass we declare a upp_xxx that |
| 62 | ** we initialize to the correct value in the init routine. |
| 63 | */ |
| 64 | #define AEIdleUPP AEIdleProcPtr |
| 65 | #define AEFilterUPP AEFilterProcPtr |
| 66 | #define AEEventHandlerUPP AEEventHandlerProcPtr |
| 67 | #define NewAEIdleProc(x) (x) |
| 68 | #define NewAEFilterProc(x) (x) |
| 69 | #define NewAEEventHandlerProc(x) (x) |
| 70 | #endif |
| 71 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 72 | static pascal OSErr GenericEventHandler(); /* Forward */ |
| 73 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 74 | AEEventHandlerUPP upp_GenericEventHandler; |
| 75 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 76 | static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) |
| 77 | { |
Jack Jansen | c7cfb95 | 1995-06-05 22:34:12 +0000 | [diff] [blame] | 78 | PyMac_Yield(); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 82 | AEIdleUPP upp_AEIdleProc; |
| 83 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 84 | static PyObject *AE_Error; |
| 85 | |
| 86 | /* ----------------------- Object type AEDesc ----------------------- */ |
| 87 | |
| 88 | staticforward PyTypeObject AEDesc_Type; |
| 89 | |
| 90 | #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type) |
| 91 | |
| 92 | typedef struct AEDescObject { |
| 93 | PyObject_HEAD |
| 94 | AEDesc ob_itself; |
| 95 | } AEDescObject; |
| 96 | |
| 97 | static PyObject *AEDesc_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 98 | AEDesc *itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 99 | { |
| 100 | AEDescObject *it; |
| 101 | it = PyObject_NEW(AEDescObject, &AEDesc_Type); |
| 102 | if (it == NULL) return NULL; |
| 103 | it->ob_itself = *itself; |
| 104 | return (PyObject *)it; |
| 105 | } |
| 106 | static AEDesc_Convert(v, p_itself) |
| 107 | PyObject *v; |
| 108 | AEDesc *p_itself; |
| 109 | { |
| 110 | if (!AEDesc_Check(v)) |
| 111 | { |
| 112 | PyErr_SetString(PyExc_TypeError, "AEDesc required"); |
| 113 | return 0; |
| 114 | } |
| 115 | *p_itself = ((AEDescObject *)v)->ob_itself; |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | static void AEDesc_dealloc(self) |
| 120 | AEDescObject *self; |
| 121 | { |
| 122 | AEDisposeDesc(&self->ob_itself); |
| 123 | PyMem_DEL(self); |
| 124 | } |
| 125 | |
| 126 | static PyObject *AEDesc_AECoerceDesc(_self, _args) |
| 127 | AEDescObject *_self; |
| 128 | PyObject *_args; |
| 129 | { |
| 130 | PyObject *_res = NULL; |
| 131 | OSErr _err; |
| 132 | DescType toType; |
| 133 | AEDesc result; |
| 134 | if (!PyArg_ParseTuple(_args, "O&", |
| 135 | PyMac_GetOSType, &toType)) |
| 136 | return NULL; |
| 137 | _err = AECoerceDesc(&_self->ob_itself, |
| 138 | toType, |
| 139 | &result); |
| 140 | if (_err != noErr) return PyMac_Error(_err); |
| 141 | _res = Py_BuildValue("O&", |
| 142 | AEDesc_New, &result); |
| 143 | return _res; |
| 144 | } |
| 145 | |
| 146 | static PyObject *AEDesc_AEDuplicateDesc(_self, _args) |
| 147 | AEDescObject *_self; |
| 148 | PyObject *_args; |
| 149 | { |
| 150 | PyObject *_res = NULL; |
| 151 | OSErr _err; |
| 152 | AEDesc result; |
| 153 | if (!PyArg_ParseTuple(_args, "")) |
| 154 | return NULL; |
| 155 | _err = AEDuplicateDesc(&_self->ob_itself, |
| 156 | &result); |
| 157 | if (_err != noErr) return PyMac_Error(_err); |
| 158 | _res = Py_BuildValue("O&", |
| 159 | AEDesc_New, &result); |
| 160 | return _res; |
| 161 | } |
| 162 | |
| 163 | static PyObject *AEDesc_AECountItems(_self, _args) |
| 164 | AEDescObject *_self; |
| 165 | PyObject *_args; |
| 166 | { |
| 167 | PyObject *_res = NULL; |
| 168 | OSErr _err; |
| 169 | long theCount; |
| 170 | if (!PyArg_ParseTuple(_args, "")) |
| 171 | return NULL; |
| 172 | _err = AECountItems(&_self->ob_itself, |
| 173 | &theCount); |
| 174 | if (_err != noErr) return PyMac_Error(_err); |
| 175 | _res = Py_BuildValue("l", |
| 176 | theCount); |
| 177 | return _res; |
| 178 | } |
| 179 | |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 180 | static PyObject *AEDesc_AEPutPtr(_self, _args) |
| 181 | AEDescObject *_self; |
| 182 | PyObject *_args; |
| 183 | { |
| 184 | PyObject *_res = NULL; |
| 185 | OSErr _err; |
| 186 | long index; |
| 187 | DescType typeCode; |
| 188 | char *dataPtr__in__; |
| 189 | long dataPtr__len__; |
| 190 | int dataPtr__in_len__; |
| 191 | if (!PyArg_ParseTuple(_args, "lO&s#", |
| 192 | &index, |
| 193 | PyMac_GetOSType, &typeCode, |
| 194 | &dataPtr__in__, &dataPtr__in_len__)) |
| 195 | return NULL; |
| 196 | dataPtr__len__ = dataPtr__in_len__; |
| 197 | _err = AEPutPtr(&_self->ob_itself, |
| 198 | index, |
| 199 | typeCode, |
| 200 | dataPtr__in__, dataPtr__len__); |
| 201 | if (_err != noErr) return PyMac_Error(_err); |
| 202 | Py_INCREF(Py_None); |
| 203 | _res = Py_None; |
| 204 | dataPtr__error__: ; |
| 205 | return _res; |
| 206 | } |
| 207 | |
| 208 | static PyObject *AEDesc_AEPutDesc(_self, _args) |
| 209 | AEDescObject *_self; |
| 210 | PyObject *_args; |
| 211 | { |
| 212 | PyObject *_res = NULL; |
| 213 | OSErr _err; |
| 214 | long index; |
| 215 | AEDesc theAEDesc; |
| 216 | if (!PyArg_ParseTuple(_args, "lO&", |
| 217 | &index, |
| 218 | AEDesc_Convert, &theAEDesc)) |
| 219 | return NULL; |
| 220 | _err = AEPutDesc(&_self->ob_itself, |
| 221 | index, |
| 222 | &theAEDesc); |
| 223 | if (_err != noErr) return PyMac_Error(_err); |
| 224 | Py_INCREF(Py_None); |
| 225 | _res = Py_None; |
| 226 | return _res; |
| 227 | } |
| 228 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 229 | static PyObject *AEDesc_AEGetNthPtr(_self, _args) |
| 230 | AEDescObject *_self; |
| 231 | PyObject *_args; |
| 232 | { |
| 233 | PyObject *_res = NULL; |
| 234 | OSErr _err; |
| 235 | long index; |
| 236 | DescType desiredType; |
| 237 | AEKeyword theAEKeyword; |
| 238 | DescType typeCode; |
| 239 | char *dataPtr__out__; |
| 240 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 241 | int dataPtr__in_len__; |
| 242 | if (!PyArg_ParseTuple(_args, "lO&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 243 | &index, |
| 244 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 245 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 246 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 247 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 248 | { |
| 249 | PyErr_NoMemory(); |
| 250 | goto dataPtr__error__; |
| 251 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 252 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 253 | _err = AEGetNthPtr(&_self->ob_itself, |
| 254 | index, |
| 255 | desiredType, |
| 256 | &theAEKeyword, |
| 257 | &typeCode, |
| 258 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 259 | if (_err != noErr) return PyMac_Error(_err); |
| 260 | _res = Py_BuildValue("O&O&s#", |
| 261 | PyMac_BuildOSType, theAEKeyword, |
| 262 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 263 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 264 | free(dataPtr__out__); |
| 265 | dataPtr__error__: ; |
| 266 | return _res; |
| 267 | } |
| 268 | |
| 269 | static PyObject *AEDesc_AEGetNthDesc(_self, _args) |
| 270 | AEDescObject *_self; |
| 271 | PyObject *_args; |
| 272 | { |
| 273 | PyObject *_res = NULL; |
| 274 | OSErr _err; |
| 275 | long index; |
| 276 | DescType desiredType; |
| 277 | AEKeyword theAEKeyword; |
| 278 | AEDesc result; |
| 279 | if (!PyArg_ParseTuple(_args, "lO&", |
| 280 | &index, |
| 281 | PyMac_GetOSType, &desiredType)) |
| 282 | return NULL; |
| 283 | _err = AEGetNthDesc(&_self->ob_itself, |
| 284 | index, |
| 285 | desiredType, |
| 286 | &theAEKeyword, |
| 287 | &result); |
| 288 | if (_err != noErr) return PyMac_Error(_err); |
| 289 | _res = Py_BuildValue("O&O&", |
| 290 | PyMac_BuildOSType, theAEKeyword, |
| 291 | AEDesc_New, &result); |
| 292 | return _res; |
| 293 | } |
| 294 | |
| 295 | static PyObject *AEDesc_AESizeOfNthItem(_self, _args) |
| 296 | AEDescObject *_self; |
| 297 | PyObject *_args; |
| 298 | { |
| 299 | PyObject *_res = NULL; |
| 300 | OSErr _err; |
| 301 | long index; |
| 302 | DescType typeCode; |
| 303 | Size dataSize; |
| 304 | if (!PyArg_ParseTuple(_args, "l", |
| 305 | &index)) |
| 306 | return NULL; |
| 307 | _err = AESizeOfNthItem(&_self->ob_itself, |
| 308 | index, |
| 309 | &typeCode, |
| 310 | &dataSize); |
| 311 | if (_err != noErr) return PyMac_Error(_err); |
| 312 | _res = Py_BuildValue("O&l", |
| 313 | PyMac_BuildOSType, typeCode, |
| 314 | dataSize); |
| 315 | return _res; |
| 316 | } |
| 317 | |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 318 | static PyObject *AEDesc_AEDeleteItem(_self, _args) |
| 319 | AEDescObject *_self; |
| 320 | PyObject *_args; |
| 321 | { |
| 322 | PyObject *_res = NULL; |
| 323 | OSErr _err; |
| 324 | long index; |
| 325 | if (!PyArg_ParseTuple(_args, "l", |
| 326 | &index)) |
| 327 | return NULL; |
| 328 | _err = AEDeleteItem(&_self->ob_itself, |
| 329 | index); |
| 330 | if (_err != noErr) return PyMac_Error(_err); |
| 331 | Py_INCREF(Py_None); |
| 332 | _res = Py_None; |
| 333 | return _res; |
| 334 | } |
| 335 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 336 | static PyObject *AEDesc_AEPutParamPtr(_self, _args) |
| 337 | AEDescObject *_self; |
| 338 | PyObject *_args; |
| 339 | { |
| 340 | PyObject *_res = NULL; |
| 341 | OSErr _err; |
| 342 | AEKeyword theAEKeyword; |
| 343 | DescType typeCode; |
| 344 | char *dataPtr__in__; |
| 345 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 346 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 347 | if (!PyArg_ParseTuple(_args, "O&O&s#", |
| 348 | PyMac_GetOSType, &theAEKeyword, |
| 349 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 350 | &dataPtr__in__, &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 351 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 352 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 353 | _err = AEPutParamPtr(&_self->ob_itself, |
| 354 | theAEKeyword, |
| 355 | typeCode, |
| 356 | dataPtr__in__, dataPtr__len__); |
| 357 | if (_err != noErr) return PyMac_Error(_err); |
| 358 | Py_INCREF(Py_None); |
| 359 | _res = Py_None; |
| 360 | dataPtr__error__: ; |
| 361 | return _res; |
| 362 | } |
| 363 | |
| 364 | static PyObject *AEDesc_AEPutParamDesc(_self, _args) |
| 365 | AEDescObject *_self; |
| 366 | PyObject *_args; |
| 367 | { |
| 368 | PyObject *_res = NULL; |
| 369 | OSErr _err; |
| 370 | AEKeyword theAEKeyword; |
| 371 | AEDesc theAEDesc; |
| 372 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 373 | PyMac_GetOSType, &theAEKeyword, |
| 374 | AEDesc_Convert, &theAEDesc)) |
| 375 | return NULL; |
| 376 | _err = AEPutParamDesc(&_self->ob_itself, |
| 377 | theAEKeyword, |
| 378 | &theAEDesc); |
| 379 | if (_err != noErr) return PyMac_Error(_err); |
| 380 | Py_INCREF(Py_None); |
| 381 | _res = Py_None; |
| 382 | return _res; |
| 383 | } |
| 384 | |
| 385 | static PyObject *AEDesc_AEGetParamPtr(_self, _args) |
| 386 | AEDescObject *_self; |
| 387 | PyObject *_args; |
| 388 | { |
| 389 | PyObject *_res = NULL; |
| 390 | OSErr _err; |
| 391 | AEKeyword theAEKeyword; |
| 392 | DescType desiredType; |
| 393 | DescType typeCode; |
| 394 | char *dataPtr__out__; |
| 395 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 396 | int dataPtr__in_len__; |
| 397 | if (!PyArg_ParseTuple(_args, "O&O&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 398 | PyMac_GetOSType, &theAEKeyword, |
| 399 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 400 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 401 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 402 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 403 | { |
| 404 | PyErr_NoMemory(); |
| 405 | goto dataPtr__error__; |
| 406 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 407 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 408 | _err = AEGetParamPtr(&_self->ob_itself, |
| 409 | theAEKeyword, |
| 410 | desiredType, |
| 411 | &typeCode, |
| 412 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 413 | if (_err != noErr) return PyMac_Error(_err); |
| 414 | _res = Py_BuildValue("O&s#", |
| 415 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 416 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 417 | free(dataPtr__out__); |
| 418 | dataPtr__error__: ; |
| 419 | return _res; |
| 420 | } |
| 421 | |
| 422 | static PyObject *AEDesc_AEGetParamDesc(_self, _args) |
| 423 | AEDescObject *_self; |
| 424 | PyObject *_args; |
| 425 | { |
| 426 | PyObject *_res = NULL; |
| 427 | OSErr _err; |
| 428 | AEKeyword theAEKeyword; |
| 429 | DescType desiredType; |
| 430 | AEDesc result; |
| 431 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 432 | PyMac_GetOSType, &theAEKeyword, |
| 433 | PyMac_GetOSType, &desiredType)) |
| 434 | return NULL; |
| 435 | _err = AEGetParamDesc(&_self->ob_itself, |
| 436 | theAEKeyword, |
| 437 | desiredType, |
| 438 | &result); |
| 439 | if (_err != noErr) return PyMac_Error(_err); |
| 440 | _res = Py_BuildValue("O&", |
| 441 | AEDesc_New, &result); |
| 442 | return _res; |
| 443 | } |
| 444 | |
| 445 | static PyObject *AEDesc_AESizeOfParam(_self, _args) |
| 446 | AEDescObject *_self; |
| 447 | PyObject *_args; |
| 448 | { |
| 449 | PyObject *_res = NULL; |
| 450 | OSErr _err; |
| 451 | AEKeyword theAEKeyword; |
| 452 | DescType typeCode; |
| 453 | Size dataSize; |
| 454 | if (!PyArg_ParseTuple(_args, "O&", |
| 455 | PyMac_GetOSType, &theAEKeyword)) |
| 456 | return NULL; |
| 457 | _err = AESizeOfParam(&_self->ob_itself, |
| 458 | theAEKeyword, |
| 459 | &typeCode, |
| 460 | &dataSize); |
| 461 | if (_err != noErr) return PyMac_Error(_err); |
| 462 | _res = Py_BuildValue("O&l", |
| 463 | PyMac_BuildOSType, typeCode, |
| 464 | dataSize); |
| 465 | return _res; |
| 466 | } |
| 467 | |
| 468 | static PyObject *AEDesc_AEDeleteParam(_self, _args) |
| 469 | AEDescObject *_self; |
| 470 | PyObject *_args; |
| 471 | { |
| 472 | PyObject *_res = NULL; |
| 473 | OSErr _err; |
| 474 | AEKeyword theAEKeyword; |
| 475 | if (!PyArg_ParseTuple(_args, "O&", |
| 476 | PyMac_GetOSType, &theAEKeyword)) |
| 477 | return NULL; |
| 478 | _err = AEDeleteParam(&_self->ob_itself, |
| 479 | theAEKeyword); |
| 480 | if (_err != noErr) return PyMac_Error(_err); |
| 481 | Py_INCREF(Py_None); |
| 482 | _res = Py_None; |
| 483 | return _res; |
| 484 | } |
| 485 | |
| 486 | static PyObject *AEDesc_AEGetAttributePtr(_self, _args) |
| 487 | AEDescObject *_self; |
| 488 | PyObject *_args; |
| 489 | { |
| 490 | PyObject *_res = NULL; |
| 491 | OSErr _err; |
| 492 | AEKeyword theAEKeyword; |
| 493 | DescType desiredType; |
| 494 | DescType typeCode; |
| 495 | char *dataPtr__out__; |
| 496 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 497 | int dataPtr__in_len__; |
| 498 | if (!PyArg_ParseTuple(_args, "O&O&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 499 | PyMac_GetOSType, &theAEKeyword, |
| 500 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 501 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 502 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 503 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 504 | { |
| 505 | PyErr_NoMemory(); |
| 506 | goto dataPtr__error__; |
| 507 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 508 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 509 | _err = AEGetAttributePtr(&_self->ob_itself, |
| 510 | theAEKeyword, |
| 511 | desiredType, |
| 512 | &typeCode, |
| 513 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 514 | if (_err != noErr) return PyMac_Error(_err); |
| 515 | _res = Py_BuildValue("O&s#", |
| 516 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 517 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 518 | free(dataPtr__out__); |
| 519 | dataPtr__error__: ; |
| 520 | return _res; |
| 521 | } |
| 522 | |
| 523 | static PyObject *AEDesc_AEGetAttributeDesc(_self, _args) |
| 524 | AEDescObject *_self; |
| 525 | PyObject *_args; |
| 526 | { |
| 527 | PyObject *_res = NULL; |
| 528 | OSErr _err; |
| 529 | AEKeyword theAEKeyword; |
| 530 | DescType desiredType; |
| 531 | AEDesc result; |
| 532 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 533 | PyMac_GetOSType, &theAEKeyword, |
| 534 | PyMac_GetOSType, &desiredType)) |
| 535 | return NULL; |
| 536 | _err = AEGetAttributeDesc(&_self->ob_itself, |
| 537 | theAEKeyword, |
| 538 | desiredType, |
| 539 | &result); |
| 540 | if (_err != noErr) return PyMac_Error(_err); |
| 541 | _res = Py_BuildValue("O&", |
| 542 | AEDesc_New, &result); |
| 543 | return _res; |
| 544 | } |
| 545 | |
| 546 | static PyObject *AEDesc_AESizeOfAttribute(_self, _args) |
| 547 | AEDescObject *_self; |
| 548 | PyObject *_args; |
| 549 | { |
| 550 | PyObject *_res = NULL; |
| 551 | OSErr _err; |
| 552 | AEKeyword theAEKeyword; |
| 553 | DescType typeCode; |
| 554 | Size dataSize; |
| 555 | if (!PyArg_ParseTuple(_args, "O&", |
| 556 | PyMac_GetOSType, &theAEKeyword)) |
| 557 | return NULL; |
| 558 | _err = AESizeOfAttribute(&_self->ob_itself, |
| 559 | theAEKeyword, |
| 560 | &typeCode, |
| 561 | &dataSize); |
| 562 | if (_err != noErr) return PyMac_Error(_err); |
| 563 | _res = Py_BuildValue("O&l", |
| 564 | PyMac_BuildOSType, typeCode, |
| 565 | dataSize); |
| 566 | return _res; |
| 567 | } |
| 568 | |
| 569 | static PyObject *AEDesc_AEPutAttributePtr(_self, _args) |
| 570 | AEDescObject *_self; |
| 571 | PyObject *_args; |
| 572 | { |
| 573 | PyObject *_res = NULL; |
| 574 | OSErr _err; |
| 575 | AEKeyword theAEKeyword; |
| 576 | DescType typeCode; |
| 577 | char *dataPtr__in__; |
| 578 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 579 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 580 | if (!PyArg_ParseTuple(_args, "O&O&s#", |
| 581 | PyMac_GetOSType, &theAEKeyword, |
| 582 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 583 | &dataPtr__in__, &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 584 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 585 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 586 | _err = AEPutAttributePtr(&_self->ob_itself, |
| 587 | theAEKeyword, |
| 588 | typeCode, |
| 589 | dataPtr__in__, dataPtr__len__); |
| 590 | if (_err != noErr) return PyMac_Error(_err); |
| 591 | Py_INCREF(Py_None); |
| 592 | _res = Py_None; |
| 593 | dataPtr__error__: ; |
| 594 | return _res; |
| 595 | } |
| 596 | |
| 597 | static PyObject *AEDesc_AEPutAttributeDesc(_self, _args) |
| 598 | AEDescObject *_self; |
| 599 | PyObject *_args; |
| 600 | { |
| 601 | PyObject *_res = NULL; |
| 602 | OSErr _err; |
| 603 | AEKeyword theAEKeyword; |
| 604 | AEDesc theAEDesc; |
| 605 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 606 | PyMac_GetOSType, &theAEKeyword, |
| 607 | AEDesc_Convert, &theAEDesc)) |
| 608 | return NULL; |
| 609 | _err = AEPutAttributeDesc(&_self->ob_itself, |
| 610 | theAEKeyword, |
| 611 | &theAEDesc); |
| 612 | if (_err != noErr) return PyMac_Error(_err); |
| 613 | Py_INCREF(Py_None); |
| 614 | _res = Py_None; |
| 615 | return _res; |
| 616 | } |
| 617 | |
| 618 | static PyObject *AEDesc_AESend(_self, _args) |
| 619 | AEDescObject *_self; |
| 620 | PyObject *_args; |
| 621 | { |
| 622 | PyObject *_res = NULL; |
| 623 | OSErr _err; |
| 624 | AppleEvent reply; |
| 625 | AESendMode sendMode; |
| 626 | AESendPriority sendPriority; |
| 627 | long timeOutInTicks; |
| 628 | if (!PyArg_ParseTuple(_args, "lhl", |
| 629 | &sendMode, |
| 630 | &sendPriority, |
| 631 | &timeOutInTicks)) |
| 632 | return NULL; |
| 633 | _err = AESend(&_self->ob_itself, |
| 634 | &reply, |
| 635 | sendMode, |
| 636 | sendPriority, |
| 637 | timeOutInTicks, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 638 | upp_AEIdleProc, |
| 639 | (AEFilterUPP)0); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 640 | if (_err != noErr) return PyMac_Error(_err); |
| 641 | _res = Py_BuildValue("O&", |
| 642 | AEDesc_New, &reply); |
| 643 | return _res; |
| 644 | } |
| 645 | |
| 646 | static PyObject *AEDesc_AEResetTimer(_self, _args) |
| 647 | AEDescObject *_self; |
| 648 | PyObject *_args; |
| 649 | { |
| 650 | PyObject *_res = NULL; |
| 651 | OSErr _err; |
| 652 | if (!PyArg_ParseTuple(_args, "")) |
| 653 | return NULL; |
| 654 | _err = AEResetTimer(&_self->ob_itself); |
| 655 | if (_err != noErr) return PyMac_Error(_err); |
| 656 | Py_INCREF(Py_None); |
| 657 | _res = Py_None; |
| 658 | return _res; |
| 659 | } |
| 660 | |
| 661 | static PyObject *AEDesc_AESuspendTheCurrentEvent(_self, _args) |
| 662 | AEDescObject *_self; |
| 663 | PyObject *_args; |
| 664 | { |
| 665 | PyObject *_res = NULL; |
| 666 | OSErr _err; |
| 667 | if (!PyArg_ParseTuple(_args, "")) |
| 668 | return NULL; |
| 669 | _err = AESuspendTheCurrentEvent(&_self->ob_itself); |
| 670 | if (_err != noErr) return PyMac_Error(_err); |
| 671 | Py_INCREF(Py_None); |
| 672 | _res = Py_None; |
| 673 | return _res; |
| 674 | } |
| 675 | |
| 676 | static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args) |
| 677 | AEDescObject *_self; |
| 678 | PyObject *_args; |
| 679 | { |
| 680 | PyObject *_res = NULL; |
| 681 | OSErr _err; |
| 682 | AppleEvent reply; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 683 | AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler; |
| 684 | PyObject *dispatcher; |
| 685 | if (!PyArg_ParseTuple(_args, "O&O", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 686 | AEDesc_Convert, &reply, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 687 | &dispatcher)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 688 | return NULL; |
| 689 | _err = AEResumeTheCurrentEvent(&_self->ob_itself, |
| 690 | &reply, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 691 | dispatcher__proc__, (long)dispatcher); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 692 | if (_err != noErr) return PyMac_Error(_err); |
| 693 | Py_INCREF(Py_None); |
| 694 | _res = Py_None; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 695 | Py_INCREF(dispatcher); /* XXX leak, but needed */ |
Jack Jansen | c7cfb95 | 1995-06-05 22:34:12 +0000 | [diff] [blame] | 696 | return _res; |
| 697 | } |
| 698 | |
| 699 | static PyObject *AEDesc_AEGetTheCurrentEvent(_self, _args) |
| 700 | AEDescObject *_self; |
| 701 | PyObject *_args; |
| 702 | { |
| 703 | PyObject *_res = NULL; |
| 704 | OSErr _err; |
| 705 | if (!PyArg_ParseTuple(_args, "")) |
| 706 | return NULL; |
| 707 | _err = AEGetTheCurrentEvent(&_self->ob_itself); |
| 708 | if (_err != noErr) return PyMac_Error(_err); |
| 709 | Py_INCREF(Py_None); |
| 710 | _res = Py_None; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 711 | return _res; |
| 712 | } |
| 713 | |
| 714 | static PyObject *AEDesc_AESetTheCurrentEvent(_self, _args) |
| 715 | AEDescObject *_self; |
| 716 | PyObject *_args; |
| 717 | { |
| 718 | PyObject *_res = NULL; |
| 719 | OSErr _err; |
| 720 | if (!PyArg_ParseTuple(_args, "")) |
| 721 | return NULL; |
| 722 | _err = AESetTheCurrentEvent(&_self->ob_itself); |
| 723 | if (_err != noErr) return PyMac_Error(_err); |
| 724 | Py_INCREF(Py_None); |
| 725 | _res = Py_None; |
| 726 | return _res; |
| 727 | } |
| 728 | |
| 729 | static PyMethodDef AEDesc_methods[] = { |
| 730 | {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, |
| 731 | "(DescType toType) -> (AEDesc result)"}, |
| 732 | {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1, |
| 733 | "() -> (AEDesc result)"}, |
| 734 | {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1, |
| 735 | "() -> (long theCount)"}, |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 736 | {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1, |
| 737 | "(long index, DescType typeCode, Buffer dataPtr) -> None"}, |
| 738 | {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1, |
| 739 | "(long index, AEDesc theAEDesc) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 740 | {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1, |
| 741 | "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"}, |
| 742 | {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1, |
| 743 | "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"}, |
| 744 | {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1, |
| 745 | "(long index) -> (DescType typeCode, Size dataSize)"}, |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 746 | {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1, |
| 747 | "(long index) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 748 | {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1, |
| 749 | "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, |
| 750 | {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1, |
| 751 | "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, |
| 752 | {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1, |
| 753 | "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, |
| 754 | {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1, |
| 755 | "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, |
| 756 | {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1, |
| 757 | "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, |
| 758 | {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1, |
| 759 | "(AEKeyword theAEKeyword) -> None"}, |
| 760 | {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1, |
| 761 | "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, |
| 762 | {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1, |
| 763 | "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, |
| 764 | {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1, |
| 765 | "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, |
| 766 | {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1, |
| 767 | "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, |
| 768 | {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1, |
| 769 | "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, |
| 770 | {"AESend", (PyCFunction)AEDesc_AESend, 1, |
| 771 | "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"}, |
| 772 | {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1, |
| 773 | "() -> None"}, |
| 774 | {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1, |
| 775 | "() -> None"}, |
| 776 | {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 777 | "(AppleEvent reply, EventHandler dispatcher) -> None"}, |
Jack Jansen | c7cfb95 | 1995-06-05 22:34:12 +0000 | [diff] [blame] | 778 | {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1, |
| 779 | "() -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 780 | {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1, |
| 781 | "() -> None"}, |
| 782 | {NULL, NULL, 0} |
| 783 | }; |
| 784 | |
| 785 | static PyMethodChain AEDesc_chain = { AEDesc_methods, NULL }; |
| 786 | |
| 787 | static PyObject *AEDesc_getattr(self, name) |
| 788 | AEDescObject *self; |
| 789 | char *name; |
| 790 | { |
| 791 | |
| 792 | if (strcmp(name, "type") == 0) |
| 793 | return PyMac_BuildOSType(self->ob_itself.descriptorType); |
| 794 | if (strcmp(name, "data") == 0) { |
| 795 | PyObject *res; |
| 796 | char state; |
| 797 | state = HGetState(self->ob_itself.dataHandle); |
| 798 | HLock(self->ob_itself.dataHandle); |
| 799 | res = PyString_FromStringAndSize( |
| 800 | *self->ob_itself.dataHandle, |
| 801 | GetHandleSize(self->ob_itself.dataHandle)); |
| 802 | HUnlock(self->ob_itself.dataHandle); |
| 803 | HSetState(self->ob_itself.dataHandle, state); |
| 804 | return res; |
| 805 | } |
| 806 | if (strcmp(name, "__members__") == 0) |
| 807 | return Py_BuildValue("[ss]", "data", "type"); |
| 808 | |
| 809 | return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name); |
| 810 | } |
| 811 | |
| 812 | #define AEDesc_setattr NULL |
| 813 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 814 | staticforward PyTypeObject AEDesc_Type = { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 815 | PyObject_HEAD_INIT(&PyType_Type) |
| 816 | 0, /*ob_size*/ |
| 817 | "AEDesc", /*tp_name*/ |
| 818 | sizeof(AEDescObject), /*tp_basicsize*/ |
| 819 | 0, /*tp_itemsize*/ |
| 820 | /* methods */ |
| 821 | (destructor) AEDesc_dealloc, /*tp_dealloc*/ |
| 822 | 0, /*tp_print*/ |
| 823 | (getattrfunc) AEDesc_getattr, /*tp_getattr*/ |
| 824 | (setattrfunc) AEDesc_setattr, /*tp_setattr*/ |
| 825 | }; |
| 826 | |
| 827 | /* --------------------- End object type AEDesc --------------------- */ |
| 828 | |
| 829 | |
| 830 | static PyObject *AE_AECreateDesc(_self, _args) |
| 831 | PyObject *_self; |
| 832 | PyObject *_args; |
| 833 | { |
| 834 | PyObject *_res = NULL; |
| 835 | OSErr _err; |
| 836 | DescType typeCode; |
| 837 | char *dataPtr__in__; |
| 838 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 839 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 840 | AEDesc result; |
| 841 | if (!PyArg_ParseTuple(_args, "O&s#", |
| 842 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 843 | &dataPtr__in__, &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 844 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 845 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 846 | _err = AECreateDesc(typeCode, |
| 847 | dataPtr__in__, dataPtr__len__, |
| 848 | &result); |
| 849 | if (_err != noErr) return PyMac_Error(_err); |
| 850 | _res = Py_BuildValue("O&", |
| 851 | AEDesc_New, &result); |
| 852 | dataPtr__error__: ; |
| 853 | return _res; |
| 854 | } |
| 855 | |
| 856 | static PyObject *AE_AECoercePtr(_self, _args) |
| 857 | PyObject *_self; |
| 858 | PyObject *_args; |
| 859 | { |
| 860 | PyObject *_res = NULL; |
| 861 | OSErr _err; |
| 862 | DescType typeCode; |
| 863 | char *dataPtr__in__; |
| 864 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 865 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 866 | DescType toType; |
| 867 | AEDesc result; |
| 868 | if (!PyArg_ParseTuple(_args, "O&s#O&", |
| 869 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 870 | &dataPtr__in__, &dataPtr__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 871 | PyMac_GetOSType, &toType)) |
| 872 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 873 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 874 | _err = AECoercePtr(typeCode, |
| 875 | dataPtr__in__, dataPtr__len__, |
| 876 | toType, |
| 877 | &result); |
| 878 | if (_err != noErr) return PyMac_Error(_err); |
| 879 | _res = Py_BuildValue("O&", |
| 880 | AEDesc_New, &result); |
| 881 | dataPtr__error__: ; |
| 882 | return _res; |
| 883 | } |
| 884 | |
| 885 | static PyObject *AE_AECreateList(_self, _args) |
| 886 | PyObject *_self; |
| 887 | PyObject *_args; |
| 888 | { |
| 889 | PyObject *_res = NULL; |
| 890 | OSErr _err; |
| 891 | char *factoringPtr__in__; |
| 892 | long factoringPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 893 | int factoringPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 894 | Boolean isRecord; |
| 895 | AEDescList resultList; |
| 896 | if (!PyArg_ParseTuple(_args, "s#b", |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 897 | &factoringPtr__in__, &factoringPtr__in_len__, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 898 | &isRecord)) |
| 899 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 900 | factoringPtr__len__ = factoringPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 901 | _err = AECreateList(factoringPtr__in__, factoringPtr__len__, |
| 902 | isRecord, |
| 903 | &resultList); |
| 904 | if (_err != noErr) return PyMac_Error(_err); |
| 905 | _res = Py_BuildValue("O&", |
| 906 | AEDesc_New, &resultList); |
| 907 | factoringPtr__error__: ; |
| 908 | return _res; |
| 909 | } |
| 910 | |
| 911 | static PyObject *AE_AECreateAppleEvent(_self, _args) |
| 912 | PyObject *_self; |
| 913 | PyObject *_args; |
| 914 | { |
| 915 | PyObject *_res = NULL; |
| 916 | OSErr _err; |
| 917 | AEEventClass theAEEventClass; |
| 918 | AEEventID theAEEventID; |
| 919 | AEAddressDesc target; |
| 920 | short returnID; |
| 921 | long transactionID; |
| 922 | AppleEvent result; |
| 923 | if (!PyArg_ParseTuple(_args, "O&O&O&hl", |
| 924 | PyMac_GetOSType, &theAEEventClass, |
| 925 | PyMac_GetOSType, &theAEEventID, |
| 926 | AEDesc_Convert, &target, |
| 927 | &returnID, |
| 928 | &transactionID)) |
| 929 | return NULL; |
| 930 | _err = AECreateAppleEvent(theAEEventClass, |
| 931 | theAEEventID, |
| 932 | &target, |
| 933 | returnID, |
| 934 | transactionID, |
| 935 | &result); |
| 936 | if (_err != noErr) return PyMac_Error(_err); |
| 937 | _res = Py_BuildValue("O&", |
| 938 | AEDesc_New, &result); |
| 939 | return _res; |
| 940 | } |
| 941 | |
| 942 | static PyObject *AE_AEProcessAppleEvent(_self, _args) |
| 943 | PyObject *_self; |
| 944 | PyObject *_args; |
| 945 | { |
| 946 | PyObject *_res = NULL; |
| 947 | OSErr _err; |
| 948 | EventRecord theEventRecord; |
| 949 | if (!PyArg_ParseTuple(_args, "O&", |
| 950 | PyMac_GetEventRecord, &theEventRecord)) |
| 951 | return NULL; |
| 952 | _err = AEProcessAppleEvent(&theEventRecord); |
| 953 | if (_err != noErr) return PyMac_Error(_err); |
| 954 | Py_INCREF(Py_None); |
| 955 | _res = Py_None; |
| 956 | return _res; |
| 957 | } |
| 958 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 959 | static PyObject *AE_AEGetInteractionAllowed(_self, _args) |
| 960 | PyObject *_self; |
| 961 | PyObject *_args; |
| 962 | { |
| 963 | PyObject *_res = NULL; |
| 964 | OSErr _err; |
| 965 | AEInteractAllowed level; |
| 966 | if (!PyArg_ParseTuple(_args, "")) |
| 967 | return NULL; |
| 968 | _err = AEGetInteractionAllowed(&level); |
| 969 | if (_err != noErr) return PyMac_Error(_err); |
| 970 | _res = Py_BuildValue("b", |
| 971 | level); |
| 972 | return _res; |
| 973 | } |
| 974 | |
| 975 | static PyObject *AE_AESetInteractionAllowed(_self, _args) |
| 976 | PyObject *_self; |
| 977 | PyObject *_args; |
| 978 | { |
| 979 | PyObject *_res = NULL; |
| 980 | OSErr _err; |
| 981 | AEInteractAllowed level; |
| 982 | if (!PyArg_ParseTuple(_args, "b", |
| 983 | &level)) |
| 984 | return NULL; |
| 985 | _err = AESetInteractionAllowed(level); |
| 986 | if (_err != noErr) return PyMac_Error(_err); |
| 987 | Py_INCREF(Py_None); |
| 988 | _res = Py_None; |
| 989 | return _res; |
| 990 | } |
| 991 | |
| 992 | static PyObject *AE_AEInteractWithUser(_self, _args) |
| 993 | PyObject *_self; |
| 994 | PyObject *_args; |
| 995 | { |
| 996 | PyObject *_res = NULL; |
| 997 | OSErr _err; |
| 998 | long timeOutInTicks; |
| 999 | if (!PyArg_ParseTuple(_args, "l", |
| 1000 | &timeOutInTicks)) |
| 1001 | return NULL; |
| 1002 | _err = AEInteractWithUser(timeOutInTicks, |
| 1003 | (NMRecPtr)0, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1004 | upp_AEIdleProc); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1005 | if (_err != noErr) return PyMac_Error(_err); |
| 1006 | Py_INCREF(Py_None); |
| 1007 | _res = Py_None; |
| 1008 | return _res; |
| 1009 | } |
| 1010 | |
| 1011 | static PyObject *AE_AEInstallEventHandler(_self, _args) |
| 1012 | PyObject *_self; |
| 1013 | PyObject *_args; |
| 1014 | { |
| 1015 | PyObject *_res = NULL; |
| 1016 | OSErr _err; |
| 1017 | AEEventClass theAEEventClass; |
| 1018 | AEEventID theAEEventID; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1019 | AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; |
| 1020 | PyObject *handler; |
| 1021 | if (!PyArg_ParseTuple(_args, "O&O&O", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1022 | PyMac_GetOSType, &theAEEventClass, |
| 1023 | PyMac_GetOSType, &theAEEventID, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1024 | &handler)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1025 | return NULL; |
| 1026 | _err = AEInstallEventHandler(theAEEventClass, |
| 1027 | theAEEventID, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1028 | handler__proc__, (long)handler, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1029 | 0); |
| 1030 | if (_err != noErr) return PyMac_Error(_err); |
| 1031 | Py_INCREF(Py_None); |
| 1032 | _res = Py_None; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1033 | Py_INCREF(handler); /* XXX leak, but needed */ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1034 | return _res; |
| 1035 | } |
| 1036 | |
| 1037 | static PyObject *AE_AERemoveEventHandler(_self, _args) |
| 1038 | PyObject *_self; |
| 1039 | PyObject *_args; |
| 1040 | { |
| 1041 | PyObject *_res = NULL; |
| 1042 | OSErr _err; |
| 1043 | AEEventClass theAEEventClass; |
| 1044 | AEEventID theAEEventID; |
| 1045 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1046 | PyMac_GetOSType, &theAEEventClass, |
| 1047 | PyMac_GetOSType, &theAEEventID)) |
| 1048 | return NULL; |
| 1049 | _err = AERemoveEventHandler(theAEEventClass, |
| 1050 | theAEEventID, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1051 | upp_GenericEventHandler, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1052 | 0); |
| 1053 | if (_err != noErr) return PyMac_Error(_err); |
| 1054 | Py_INCREF(Py_None); |
| 1055 | _res = Py_None; |
| 1056 | return _res; |
| 1057 | } |
| 1058 | |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1059 | static PyObject *AE_AEGetEventHandler(_self, _args) |
| 1060 | PyObject *_self; |
| 1061 | PyObject *_args; |
| 1062 | { |
| 1063 | PyObject *_res = NULL; |
| 1064 | OSErr _err; |
| 1065 | AEEventClass theAEEventClass; |
| 1066 | AEEventID theAEEventID; |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1067 | AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; |
| 1068 | PyObject *handler; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1069 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1070 | PyMac_GetOSType, &theAEEventClass, |
| 1071 | PyMac_GetOSType, &theAEEventID)) |
| 1072 | return NULL; |
| 1073 | _err = AEGetEventHandler(theAEEventClass, |
| 1074 | theAEEventID, |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1075 | &handler__proc__, (long *)&handler, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1076 | 0); |
| 1077 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1078 | _res = Py_BuildValue("O", |
| 1079 | handler); |
| 1080 | Py_INCREF(handler); /* XXX leak, but needed */ |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1081 | return _res; |
| 1082 | } |
| 1083 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1084 | static PyObject *AE_AEManagerInfo(_self, _args) |
| 1085 | PyObject *_self; |
| 1086 | PyObject *_args; |
| 1087 | { |
| 1088 | PyObject *_res = NULL; |
| 1089 | OSErr _err; |
| 1090 | AEKeyword keyWord; |
| 1091 | long result; |
| 1092 | if (!PyArg_ParseTuple(_args, "O&", |
| 1093 | PyMac_GetOSType, &keyWord)) |
| 1094 | return NULL; |
| 1095 | _err = AEManagerInfo(keyWord, |
| 1096 | &result); |
| 1097 | if (_err != noErr) return PyMac_Error(_err); |
| 1098 | _res = Py_BuildValue("l", |
| 1099 | result); |
| 1100 | return _res; |
| 1101 | } |
| 1102 | |
| 1103 | static PyMethodDef AE_methods[] = { |
| 1104 | {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1, |
| 1105 | "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"}, |
| 1106 | {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1, |
| 1107 | "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"}, |
| 1108 | {"AECreateList", (PyCFunction)AE_AECreateList, 1, |
| 1109 | "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"}, |
| 1110 | {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, |
| 1111 | "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, short returnID, long transactionID) -> (AppleEvent result)"}, |
| 1112 | {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, |
| 1113 | "(EventRecord theEventRecord) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1114 | {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, |
| 1115 | "() -> (AEInteractAllowed level)"}, |
| 1116 | {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1, |
| 1117 | "(AEInteractAllowed level) -> None"}, |
| 1118 | {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1, |
| 1119 | "(long timeOutInTicks) -> None"}, |
| 1120 | {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1121 | "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1122 | {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1, |
| 1123 | "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"}, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1124 | {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1, |
| 1125 | "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1126 | {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1, |
| 1127 | "(AEKeyword keyWord) -> (long result)"}, |
| 1128 | {NULL, NULL, 0} |
| 1129 | }; |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | static pascal OSErr |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 1134 | GenericEventHandler(AppleEvent *request, AppleEvent *reply, long refcon) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1135 | { |
| 1136 | PyObject *handler = (PyObject *)refcon; |
| 1137 | AEDescObject *requestObject, *replyObject; |
| 1138 | PyObject *args, *res; |
| 1139 | if ((requestObject = (AEDescObject *)AEDesc_New(request)) == NULL) { |
| 1140 | return -1; |
| 1141 | } |
| 1142 | if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) { |
| 1143 | Py_DECREF(requestObject); |
| 1144 | return -1; |
| 1145 | } |
| 1146 | if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) { |
| 1147 | Py_DECREF(requestObject); |
| 1148 | Py_DECREF(replyObject); |
| 1149 | return -1; |
| 1150 | } |
| 1151 | res = PyEval_CallObject(handler, args); |
| 1152 | requestObject->ob_itself.descriptorType = 'null'; |
| 1153 | requestObject->ob_itself.dataHandle = NULL; |
| 1154 | replyObject->ob_itself.descriptorType = 'null'; |
| 1155 | replyObject->ob_itself.dataHandle = NULL; |
| 1156 | Py_DECREF(args); |
| 1157 | if (res == NULL) |
| 1158 | return -1; |
| 1159 | Py_DECREF(res); |
| 1160 | return noErr; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | void initAE() |
| 1165 | { |
| 1166 | PyObject *m; |
| 1167 | PyObject *d; |
| 1168 | |
| 1169 | |
| 1170 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1171 | upp_AEIdleProc = NewAEIdleProc(AEIdleProc); |
| 1172 | upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler); |
| 1173 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1174 | |
| 1175 | m = Py_InitModule("AE", AE_methods); |
| 1176 | d = PyModule_GetDict(m); |
| 1177 | AE_Error = PyMac_GetOSErrException(); |
| 1178 | if (AE_Error == NULL || |
| 1179 | PyDict_SetItemString(d, "Error", AE_Error) != 0) |
| 1180 | Py_FatalError("can't initialize AE.Error"); |
| 1181 | } |
| 1182 | |
| 1183 | /* ========================= End module AE ========================== */ |
| 1184 | |