Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1 | |
| 2 | /* ========================== Module Drag =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 10 | |
| 11 | #include <Drag.h> |
| 12 | |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 13 | /* Callback glue routines */ |
| 14 | DragTrackingHandlerUPP dragglue_TrackingHandlerUPP; |
| 15 | DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP; |
| 16 | DragSendDataUPP dragglue_SendDataUPP; |
| 17 | #if 0 |
| 18 | DragInputUPP dragglue_InputUPP; |
| 19 | DragDrawingUPP dragglue_DrawingUPP; |
| 20 | #endif |
| 21 | |
| 22 | static PyObject *Drag_Error; |
| 23 | |
| 24 | /* ---------------------- Object type DragObj ----------------------- */ |
| 25 | |
| 26 | PyTypeObject DragObj_Type; |
| 27 | |
| 28 | #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type) |
| 29 | |
| 30 | typedef struct DragObjObject { |
| 31 | PyObject_HEAD |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 32 | DragRef ob_itself; |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 33 | PyObject *sendproc; |
| 34 | } DragObjObject; |
| 35 | |
| 36 | PyObject *DragObj_New(itself) |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 37 | DragRef itself; |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 38 | { |
| 39 | DragObjObject *it; |
| 40 | if (itself == NULL) { |
| 41 | PyErr_SetString(Drag_Error,"Cannot create null Drag"); |
| 42 | return NULL; |
| 43 | } |
| 44 | it = PyObject_NEW(DragObjObject, &DragObj_Type); |
| 45 | if (it == NULL) return NULL; |
| 46 | it->ob_itself = itself; |
| 47 | it->sendproc = NULL; |
| 48 | return (PyObject *)it; |
| 49 | } |
| 50 | DragObj_Convert(v, p_itself) |
| 51 | PyObject *v; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 52 | DragRef *p_itself; |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 53 | { |
| 54 | if (!DragObj_Check(v)) |
| 55 | { |
| 56 | PyErr_SetString(PyExc_TypeError, "DragObj required"); |
| 57 | return 0; |
| 58 | } |
| 59 | *p_itself = ((DragObjObject *)v)->ob_itself; |
| 60 | return 1; |
| 61 | } |
| 62 | |
| 63 | static void DragObj_dealloc(self) |
| 64 | DragObjObject *self; |
| 65 | { |
| 66 | Py_XDECREF(self->sendproc); |
| 67 | PyMem_DEL(self); |
| 68 | } |
| 69 | |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 70 | static PyMethodDef DragObj_methods[] = { |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 71 | {NULL, NULL, 0} |
| 72 | }; |
| 73 | |
| 74 | PyMethodChain DragObj_chain = { DragObj_methods, NULL }; |
| 75 | |
| 76 | static PyObject *DragObj_getattr(self, name) |
| 77 | DragObjObject *self; |
| 78 | char *name; |
| 79 | { |
| 80 | return Py_FindMethodInChain(&DragObj_chain, (PyObject *)self, name); |
| 81 | } |
| 82 | |
| 83 | #define DragObj_setattr NULL |
| 84 | |
| 85 | #define DragObj_compare NULL |
| 86 | |
| 87 | #define DragObj_repr NULL |
| 88 | |
| 89 | #define DragObj_hash NULL |
| 90 | |
| 91 | PyTypeObject DragObj_Type = { |
| 92 | PyObject_HEAD_INIT(&PyType_Type) |
| 93 | 0, /*ob_size*/ |
| 94 | "DragObj", /*tp_name*/ |
| 95 | sizeof(DragObjObject), /*tp_basicsize*/ |
| 96 | 0, /*tp_itemsize*/ |
| 97 | /* methods */ |
| 98 | (destructor) DragObj_dealloc, /*tp_dealloc*/ |
| 99 | 0, /*tp_print*/ |
| 100 | (getattrfunc) DragObj_getattr, /*tp_getattr*/ |
| 101 | (setattrfunc) DragObj_setattr, /*tp_setattr*/ |
| 102 | (cmpfunc) DragObj_compare, /*tp_compare*/ |
| 103 | (reprfunc) DragObj_repr, /*tp_repr*/ |
| 104 | (PyNumberMethods *)0, /* tp_as_number */ |
| 105 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 106 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 107 | (hashfunc) DragObj_hash, /*tp_hash*/ |
| 108 | }; |
| 109 | |
| 110 | /* -------------------- End object type DragObj --------------------- */ |
| 111 | |
| 112 | |
| 113 | static PyObject *Drag_NewDrag(_self, _args) |
| 114 | PyObject *_self; |
| 115 | PyObject *_args; |
| 116 | { |
| 117 | PyObject *_res = NULL; |
| 118 | OSErr _err; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 119 | DragRef theDrag; |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 120 | if (!PyArg_ParseTuple(_args, "")) |
| 121 | return NULL; |
| 122 | _err = NewDrag(&theDrag); |
| 123 | if (_err != noErr) return PyMac_Error(_err); |
| 124 | _res = Py_BuildValue("O&", |
| 125 | DragObj_New, theDrag); |
| 126 | return _res; |
| 127 | } |
| 128 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 129 | static PyObject *Drag_DisposeDrag(_self, _args) |
| 130 | PyObject *_self; |
| 131 | PyObject *_args; |
| 132 | { |
| 133 | PyObject *_res = NULL; |
| 134 | OSErr _err; |
| 135 | DragRef theDrag; |
| 136 | if (!PyArg_ParseTuple(_args, "O&", |
| 137 | DragObj_Convert, &theDrag)) |
| 138 | return NULL; |
| 139 | _err = DisposeDrag(theDrag); |
| 140 | if (_err != noErr) return PyMac_Error(_err); |
| 141 | Py_INCREF(Py_None); |
| 142 | _res = Py_None; |
| 143 | return _res; |
| 144 | } |
| 145 | |
| 146 | static PyObject *Drag_AddDragItemFlavor(_self, _args) |
| 147 | PyObject *_self; |
| 148 | PyObject *_args; |
| 149 | { |
| 150 | PyObject *_res = NULL; |
| 151 | OSErr _err; |
| 152 | DragRef theDrag; |
| 153 | ItemReference theItemRef; |
| 154 | FlavorType theType; |
| 155 | char *dataPtr__in__; |
| 156 | long dataPtr__len__; |
| 157 | int dataPtr__in_len__; |
| 158 | FlavorFlags theFlags; |
| 159 | if (!PyArg_ParseTuple(_args, "O&lO&z#l", |
| 160 | DragObj_Convert, &theDrag, |
| 161 | &theItemRef, |
| 162 | PyMac_GetOSType, &theType, |
| 163 | &dataPtr__in__, &dataPtr__in_len__, |
| 164 | &theFlags)) |
| 165 | return NULL; |
| 166 | dataPtr__len__ = dataPtr__in_len__; |
| 167 | _err = AddDragItemFlavor(theDrag, |
| 168 | theItemRef, |
| 169 | theType, |
| 170 | dataPtr__in__, dataPtr__len__, |
| 171 | theFlags); |
| 172 | if (_err != noErr) return PyMac_Error(_err); |
| 173 | Py_INCREF(Py_None); |
| 174 | _res = Py_None; |
| 175 | dataPtr__error__: ; |
| 176 | return _res; |
| 177 | } |
| 178 | |
| 179 | static PyObject *Drag_SetDragItemFlavorData(_self, _args) |
| 180 | PyObject *_self; |
| 181 | PyObject *_args; |
| 182 | { |
| 183 | PyObject *_res = NULL; |
| 184 | OSErr _err; |
| 185 | DragRef theDrag; |
| 186 | ItemReference theItemRef; |
| 187 | FlavorType theType; |
| 188 | char *dataPtr__in__; |
| 189 | long dataPtr__len__; |
| 190 | int dataPtr__in_len__; |
| 191 | UInt32 dataOffset; |
| 192 | if (!PyArg_ParseTuple(_args, "O&lO&z#l", |
| 193 | DragObj_Convert, &theDrag, |
| 194 | &theItemRef, |
| 195 | PyMac_GetOSType, &theType, |
| 196 | &dataPtr__in__, &dataPtr__in_len__, |
| 197 | &dataOffset)) |
| 198 | return NULL; |
| 199 | dataPtr__len__ = dataPtr__in_len__; |
| 200 | _err = SetDragItemFlavorData(theDrag, |
| 201 | theItemRef, |
| 202 | theType, |
| 203 | dataPtr__in__, dataPtr__len__, |
| 204 | dataOffset); |
| 205 | if (_err != noErr) return PyMac_Error(_err); |
| 206 | Py_INCREF(Py_None); |
| 207 | _res = Py_None; |
| 208 | dataPtr__error__: ; |
| 209 | return _res; |
| 210 | } |
| 211 | |
| 212 | static PyObject *Drag_SetDragImage(_self, _args) |
| 213 | PyObject *_self; |
| 214 | PyObject *_args; |
| 215 | { |
| 216 | PyObject *_res = NULL; |
| 217 | OSErr _err; |
| 218 | DragRef theDrag; |
| 219 | PixMapHandle imagePixMap; |
| 220 | RgnHandle imageRgn; |
| 221 | Point imageOffsetPt; |
| 222 | DragImageFlags theImageFlags; |
| 223 | if (!PyArg_ParseTuple(_args, "O&O&O&O&l", |
| 224 | DragObj_Convert, &theDrag, |
| 225 | ResObj_Convert, &imagePixMap, |
| 226 | ResObj_Convert, &imageRgn, |
| 227 | PyMac_GetPoint, &imageOffsetPt, |
| 228 | &theImageFlags)) |
| 229 | return NULL; |
| 230 | _err = SetDragImage(theDrag, |
| 231 | imagePixMap, |
| 232 | imageRgn, |
| 233 | imageOffsetPt, |
| 234 | theImageFlags); |
| 235 | if (_err != noErr) return PyMac_Error(_err); |
| 236 | Py_INCREF(Py_None); |
| 237 | _res = Py_None; |
| 238 | return _res; |
| 239 | } |
| 240 | |
| 241 | static PyObject *Drag_ChangeDragBehaviors(_self, _args) |
| 242 | PyObject *_self; |
| 243 | PyObject *_args; |
| 244 | { |
| 245 | PyObject *_res = NULL; |
| 246 | OSErr _err; |
| 247 | DragRef theDrag; |
| 248 | DragBehaviors inBehaviorsToSet; |
| 249 | DragBehaviors inBehaviorsToClear; |
| 250 | if (!PyArg_ParseTuple(_args, "O&ll", |
| 251 | DragObj_Convert, &theDrag, |
| 252 | &inBehaviorsToSet, |
| 253 | &inBehaviorsToClear)) |
| 254 | return NULL; |
| 255 | _err = ChangeDragBehaviors(theDrag, |
| 256 | inBehaviorsToSet, |
| 257 | inBehaviorsToClear); |
| 258 | if (_err != noErr) return PyMac_Error(_err); |
| 259 | Py_INCREF(Py_None); |
| 260 | _res = Py_None; |
| 261 | return _res; |
| 262 | } |
| 263 | |
| 264 | static PyObject *Drag_TrackDrag(_self, _args) |
| 265 | PyObject *_self; |
| 266 | PyObject *_args; |
| 267 | { |
| 268 | PyObject *_res = NULL; |
| 269 | OSErr _err; |
| 270 | DragRef theDrag; |
| 271 | EventRecord theEvent; |
| 272 | RgnHandle theRegion; |
| 273 | if (!PyArg_ParseTuple(_args, "O&O&O&", |
| 274 | DragObj_Convert, &theDrag, |
| 275 | PyMac_GetEventRecord, &theEvent, |
| 276 | ResObj_Convert, &theRegion)) |
| 277 | return NULL; |
| 278 | _err = TrackDrag(theDrag, |
| 279 | &theEvent, |
| 280 | theRegion); |
| 281 | if (_err != noErr) return PyMac_Error(_err); |
| 282 | Py_INCREF(Py_None); |
| 283 | _res = Py_None; |
| 284 | return _res; |
| 285 | } |
| 286 | |
| 287 | static PyObject *Drag_CountDragItems(_self, _args) |
| 288 | PyObject *_self; |
| 289 | PyObject *_args; |
| 290 | { |
| 291 | PyObject *_res = NULL; |
| 292 | OSErr _err; |
| 293 | DragRef theDrag; |
| 294 | UInt16 numItems; |
| 295 | if (!PyArg_ParseTuple(_args, "O&", |
| 296 | DragObj_Convert, &theDrag)) |
| 297 | return NULL; |
| 298 | _err = CountDragItems(theDrag, |
| 299 | &numItems); |
| 300 | if (_err != noErr) return PyMac_Error(_err); |
| 301 | _res = Py_BuildValue("H", |
| 302 | numItems); |
| 303 | return _res; |
| 304 | } |
| 305 | |
| 306 | static PyObject *Drag_GetDragItemReferenceNumber(_self, _args) |
| 307 | PyObject *_self; |
| 308 | PyObject *_args; |
| 309 | { |
| 310 | PyObject *_res = NULL; |
| 311 | OSErr _err; |
| 312 | DragRef theDrag; |
| 313 | UInt16 index; |
| 314 | ItemReference theItemRef; |
| 315 | if (!PyArg_ParseTuple(_args, "O&H", |
| 316 | DragObj_Convert, &theDrag, |
| 317 | &index)) |
| 318 | return NULL; |
| 319 | _err = GetDragItemReferenceNumber(theDrag, |
| 320 | index, |
| 321 | &theItemRef); |
| 322 | if (_err != noErr) return PyMac_Error(_err); |
| 323 | _res = Py_BuildValue("l", |
| 324 | theItemRef); |
| 325 | return _res; |
| 326 | } |
| 327 | |
| 328 | static PyObject *Drag_CountDragItemFlavors(_self, _args) |
| 329 | PyObject *_self; |
| 330 | PyObject *_args; |
| 331 | { |
| 332 | PyObject *_res = NULL; |
| 333 | OSErr _err; |
| 334 | DragRef theDrag; |
| 335 | ItemReference theItemRef; |
| 336 | UInt16 numFlavors; |
| 337 | if (!PyArg_ParseTuple(_args, "O&l", |
| 338 | DragObj_Convert, &theDrag, |
| 339 | &theItemRef)) |
| 340 | return NULL; |
| 341 | _err = CountDragItemFlavors(theDrag, |
| 342 | theItemRef, |
| 343 | &numFlavors); |
| 344 | if (_err != noErr) return PyMac_Error(_err); |
| 345 | _res = Py_BuildValue("H", |
| 346 | numFlavors); |
| 347 | return _res; |
| 348 | } |
| 349 | |
| 350 | static PyObject *Drag_GetFlavorType(_self, _args) |
| 351 | PyObject *_self; |
| 352 | PyObject *_args; |
| 353 | { |
| 354 | PyObject *_res = NULL; |
| 355 | OSErr _err; |
| 356 | DragRef theDrag; |
| 357 | ItemReference theItemRef; |
| 358 | UInt16 index; |
| 359 | FlavorType theType; |
| 360 | if (!PyArg_ParseTuple(_args, "O&lH", |
| 361 | DragObj_Convert, &theDrag, |
| 362 | &theItemRef, |
| 363 | &index)) |
| 364 | return NULL; |
| 365 | _err = GetFlavorType(theDrag, |
| 366 | theItemRef, |
| 367 | index, |
| 368 | &theType); |
| 369 | if (_err != noErr) return PyMac_Error(_err); |
| 370 | _res = Py_BuildValue("O&", |
| 371 | PyMac_BuildOSType, theType); |
| 372 | return _res; |
| 373 | } |
| 374 | |
| 375 | static PyObject *Drag_GetFlavorFlags(_self, _args) |
| 376 | PyObject *_self; |
| 377 | PyObject *_args; |
| 378 | { |
| 379 | PyObject *_res = NULL; |
| 380 | OSErr _err; |
| 381 | DragRef theDrag; |
| 382 | ItemReference theItemRef; |
| 383 | FlavorType theType; |
| 384 | FlavorFlags theFlags; |
| 385 | if (!PyArg_ParseTuple(_args, "O&lO&", |
| 386 | DragObj_Convert, &theDrag, |
| 387 | &theItemRef, |
| 388 | PyMac_GetOSType, &theType)) |
| 389 | return NULL; |
| 390 | _err = GetFlavorFlags(theDrag, |
| 391 | theItemRef, |
| 392 | theType, |
| 393 | &theFlags); |
| 394 | if (_err != noErr) return PyMac_Error(_err); |
| 395 | _res = Py_BuildValue("l", |
| 396 | theFlags); |
| 397 | return _res; |
| 398 | } |
| 399 | |
| 400 | static PyObject *Drag_GetFlavorDataSize(_self, _args) |
| 401 | PyObject *_self; |
| 402 | PyObject *_args; |
| 403 | { |
| 404 | PyObject *_res = NULL; |
| 405 | OSErr _err; |
| 406 | DragRef theDrag; |
| 407 | ItemReference theItemRef; |
| 408 | FlavorType theType; |
| 409 | Size dataSize; |
| 410 | if (!PyArg_ParseTuple(_args, "O&lO&", |
| 411 | DragObj_Convert, &theDrag, |
| 412 | &theItemRef, |
| 413 | PyMac_GetOSType, &theType)) |
| 414 | return NULL; |
| 415 | _err = GetFlavorDataSize(theDrag, |
| 416 | theItemRef, |
| 417 | theType, |
| 418 | &dataSize); |
| 419 | if (_err != noErr) return PyMac_Error(_err); |
| 420 | _res = Py_BuildValue("l", |
| 421 | dataSize); |
| 422 | return _res; |
| 423 | } |
| 424 | |
| 425 | static PyObject *Drag_GetFlavorData(_self, _args) |
| 426 | PyObject *_self; |
| 427 | PyObject *_args; |
| 428 | { |
| 429 | PyObject *_res = NULL; |
| 430 | OSErr _err; |
| 431 | DragRef theDrag; |
| 432 | ItemReference theItemRef; |
| 433 | FlavorType theType; |
| 434 | char *dataPtr__out__; |
| 435 | long dataPtr__len__; |
| 436 | int dataPtr__in_len__; |
| 437 | UInt32 dataOffset; |
| 438 | if (!PyArg_ParseTuple(_args, "O&lO&il", |
| 439 | DragObj_Convert, &theDrag, |
| 440 | &theItemRef, |
| 441 | PyMac_GetOSType, &theType, |
| 442 | &dataPtr__in_len__, |
| 443 | &dataOffset)) |
| 444 | return NULL; |
| 445 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
| 446 | { |
| 447 | PyErr_NoMemory(); |
| 448 | goto dataPtr__error__; |
| 449 | } |
| 450 | dataPtr__len__ = dataPtr__in_len__; |
| 451 | _err = GetFlavorData(theDrag, |
| 452 | theItemRef, |
| 453 | theType, |
| 454 | dataPtr__out__, &dataPtr__len__, |
| 455 | dataOffset); |
| 456 | if (_err != noErr) return PyMac_Error(_err); |
| 457 | _res = Py_BuildValue("s#", |
| 458 | dataPtr__out__, (int)dataPtr__len__); |
| 459 | free(dataPtr__out__); |
| 460 | dataPtr__error__: ; |
| 461 | return _res; |
| 462 | } |
| 463 | |
| 464 | static PyObject *Drag_GetDragItemBounds(_self, _args) |
| 465 | PyObject *_self; |
| 466 | PyObject *_args; |
| 467 | { |
| 468 | PyObject *_res = NULL; |
| 469 | OSErr _err; |
| 470 | DragRef theDrag; |
| 471 | ItemReference theItemRef; |
| 472 | Rect itemBounds; |
| 473 | if (!PyArg_ParseTuple(_args, "O&l", |
| 474 | DragObj_Convert, &theDrag, |
| 475 | &theItemRef)) |
| 476 | return NULL; |
| 477 | _err = GetDragItemBounds(theDrag, |
| 478 | theItemRef, |
| 479 | &itemBounds); |
| 480 | if (_err != noErr) return PyMac_Error(_err); |
| 481 | _res = Py_BuildValue("O&", |
| 482 | PyMac_BuildRect, &itemBounds); |
| 483 | return _res; |
| 484 | } |
| 485 | |
| 486 | static PyObject *Drag_SetDragItemBounds(_self, _args) |
| 487 | PyObject *_self; |
| 488 | PyObject *_args; |
| 489 | { |
| 490 | PyObject *_res = NULL; |
| 491 | OSErr _err; |
| 492 | DragRef theDrag; |
| 493 | ItemReference theItemRef; |
| 494 | Rect itemBounds; |
| 495 | if (!PyArg_ParseTuple(_args, "O&lO&", |
| 496 | DragObj_Convert, &theDrag, |
| 497 | &theItemRef, |
| 498 | PyMac_GetRect, &itemBounds)) |
| 499 | return NULL; |
| 500 | _err = SetDragItemBounds(theDrag, |
| 501 | theItemRef, |
| 502 | &itemBounds); |
| 503 | if (_err != noErr) return PyMac_Error(_err); |
| 504 | Py_INCREF(Py_None); |
| 505 | _res = Py_None; |
| 506 | return _res; |
| 507 | } |
| 508 | |
| 509 | static PyObject *Drag_GetDropLocation(_self, _args) |
| 510 | PyObject *_self; |
| 511 | PyObject *_args; |
| 512 | { |
| 513 | PyObject *_res = NULL; |
| 514 | OSErr _err; |
| 515 | DragRef theDrag; |
| 516 | AEDesc dropLocation; |
| 517 | if (!PyArg_ParseTuple(_args, "O&", |
| 518 | DragObj_Convert, &theDrag)) |
| 519 | return NULL; |
| 520 | _err = GetDropLocation(theDrag, |
| 521 | &dropLocation); |
| 522 | if (_err != noErr) return PyMac_Error(_err); |
| 523 | _res = Py_BuildValue("O&", |
| 524 | AEDesc_New, &dropLocation); |
| 525 | return _res; |
| 526 | } |
| 527 | |
| 528 | static PyObject *Drag_SetDropLocation(_self, _args) |
| 529 | PyObject *_self; |
| 530 | PyObject *_args; |
| 531 | { |
| 532 | PyObject *_res = NULL; |
| 533 | OSErr _err; |
| 534 | DragRef theDrag; |
| 535 | AEDesc dropLocation; |
| 536 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 537 | DragObj_Convert, &theDrag, |
| 538 | AEDesc_Convert, &dropLocation)) |
| 539 | return NULL; |
| 540 | _err = SetDropLocation(theDrag, |
| 541 | &dropLocation); |
| 542 | if (_err != noErr) return PyMac_Error(_err); |
| 543 | Py_INCREF(Py_None); |
| 544 | _res = Py_None; |
| 545 | return _res; |
| 546 | } |
| 547 | |
| 548 | static PyObject *Drag_GetDragAttributes(_self, _args) |
| 549 | PyObject *_self; |
| 550 | PyObject *_args; |
| 551 | { |
| 552 | PyObject *_res = NULL; |
| 553 | OSErr _err; |
| 554 | DragRef theDrag; |
| 555 | DragAttributes flags; |
| 556 | if (!PyArg_ParseTuple(_args, "O&", |
| 557 | DragObj_Convert, &theDrag)) |
| 558 | return NULL; |
| 559 | _err = GetDragAttributes(theDrag, |
| 560 | &flags); |
| 561 | if (_err != noErr) return PyMac_Error(_err); |
| 562 | _res = Py_BuildValue("l", |
| 563 | flags); |
| 564 | return _res; |
| 565 | } |
| 566 | |
| 567 | static PyObject *Drag_GetDragMouse(_self, _args) |
| 568 | PyObject *_self; |
| 569 | PyObject *_args; |
| 570 | { |
| 571 | PyObject *_res = NULL; |
| 572 | OSErr _err; |
| 573 | DragRef theDrag; |
| 574 | Point mouse; |
| 575 | Point globalPinnedMouse; |
| 576 | if (!PyArg_ParseTuple(_args, "O&", |
| 577 | DragObj_Convert, &theDrag)) |
| 578 | return NULL; |
| 579 | _err = GetDragMouse(theDrag, |
| 580 | &mouse, |
| 581 | &globalPinnedMouse); |
| 582 | if (_err != noErr) return PyMac_Error(_err); |
| 583 | _res = Py_BuildValue("O&O&", |
| 584 | PyMac_BuildPoint, mouse, |
| 585 | PyMac_BuildPoint, globalPinnedMouse); |
| 586 | return _res; |
| 587 | } |
| 588 | |
| 589 | static PyObject *Drag_SetDragMouse(_self, _args) |
| 590 | PyObject *_self; |
| 591 | PyObject *_args; |
| 592 | { |
| 593 | PyObject *_res = NULL; |
| 594 | OSErr _err; |
| 595 | DragRef theDrag; |
| 596 | Point globalPinnedMouse; |
| 597 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 598 | DragObj_Convert, &theDrag, |
| 599 | PyMac_GetPoint, &globalPinnedMouse)) |
| 600 | return NULL; |
| 601 | _err = SetDragMouse(theDrag, |
| 602 | globalPinnedMouse); |
| 603 | if (_err != noErr) return PyMac_Error(_err); |
| 604 | Py_INCREF(Py_None); |
| 605 | _res = Py_None; |
| 606 | return _res; |
| 607 | } |
| 608 | |
| 609 | static PyObject *Drag_GetDragOrigin(_self, _args) |
| 610 | PyObject *_self; |
| 611 | PyObject *_args; |
| 612 | { |
| 613 | PyObject *_res = NULL; |
| 614 | OSErr _err; |
| 615 | DragRef theDrag; |
| 616 | Point globalInitialMouse; |
| 617 | if (!PyArg_ParseTuple(_args, "O&", |
| 618 | DragObj_Convert, &theDrag)) |
| 619 | return NULL; |
| 620 | _err = GetDragOrigin(theDrag, |
| 621 | &globalInitialMouse); |
| 622 | if (_err != noErr) return PyMac_Error(_err); |
| 623 | _res = Py_BuildValue("O&", |
| 624 | PyMac_BuildPoint, globalInitialMouse); |
| 625 | return _res; |
| 626 | } |
| 627 | |
| 628 | static PyObject *Drag_GetDragModifiers(_self, _args) |
| 629 | PyObject *_self; |
| 630 | PyObject *_args; |
| 631 | { |
| 632 | PyObject *_res = NULL; |
| 633 | OSErr _err; |
| 634 | DragRef theDrag; |
| 635 | SInt16 modifiers; |
| 636 | SInt16 mouseDownModifiers; |
| 637 | SInt16 mouseUpModifiers; |
| 638 | if (!PyArg_ParseTuple(_args, "O&", |
| 639 | DragObj_Convert, &theDrag)) |
| 640 | return NULL; |
| 641 | _err = GetDragModifiers(theDrag, |
| 642 | &modifiers, |
| 643 | &mouseDownModifiers, |
| 644 | &mouseUpModifiers); |
| 645 | if (_err != noErr) return PyMac_Error(_err); |
| 646 | _res = Py_BuildValue("hhh", |
| 647 | modifiers, |
| 648 | mouseDownModifiers, |
| 649 | mouseUpModifiers); |
| 650 | return _res; |
| 651 | } |
| 652 | |
| 653 | static PyObject *Drag_ShowDragHilite(_self, _args) |
| 654 | PyObject *_self; |
| 655 | PyObject *_args; |
| 656 | { |
| 657 | PyObject *_res = NULL; |
| 658 | OSErr _err; |
| 659 | DragRef theDrag; |
| 660 | RgnHandle hiliteFrame; |
| 661 | Boolean inside; |
| 662 | if (!PyArg_ParseTuple(_args, "O&O&b", |
| 663 | DragObj_Convert, &theDrag, |
| 664 | ResObj_Convert, &hiliteFrame, |
| 665 | &inside)) |
| 666 | return NULL; |
| 667 | _err = ShowDragHilite(theDrag, |
| 668 | hiliteFrame, |
| 669 | inside); |
| 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 *Drag_HideDragHilite(_self, _args) |
| 677 | PyObject *_self; |
| 678 | PyObject *_args; |
| 679 | { |
| 680 | PyObject *_res = NULL; |
| 681 | OSErr _err; |
| 682 | DragRef theDrag; |
| 683 | if (!PyArg_ParseTuple(_args, "O&", |
| 684 | DragObj_Convert, &theDrag)) |
| 685 | return NULL; |
| 686 | _err = HideDragHilite(theDrag); |
| 687 | if (_err != noErr) return PyMac_Error(_err); |
| 688 | Py_INCREF(Py_None); |
| 689 | _res = Py_None; |
| 690 | return _res; |
| 691 | } |
| 692 | |
| 693 | static PyObject *Drag_DragPreScroll(_self, _args) |
| 694 | PyObject *_self; |
| 695 | PyObject *_args; |
| 696 | { |
| 697 | PyObject *_res = NULL; |
| 698 | OSErr _err; |
| 699 | DragRef theDrag; |
| 700 | SInt16 dH; |
| 701 | SInt16 dV; |
| 702 | if (!PyArg_ParseTuple(_args, "O&hh", |
| 703 | DragObj_Convert, &theDrag, |
| 704 | &dH, |
| 705 | &dV)) |
| 706 | return NULL; |
| 707 | _err = DragPreScroll(theDrag, |
| 708 | dH, |
| 709 | dV); |
| 710 | if (_err != noErr) return PyMac_Error(_err); |
| 711 | Py_INCREF(Py_None); |
| 712 | _res = Py_None; |
| 713 | return _res; |
| 714 | } |
| 715 | |
| 716 | static PyObject *Drag_DragPostScroll(_self, _args) |
| 717 | PyObject *_self; |
| 718 | PyObject *_args; |
| 719 | { |
| 720 | PyObject *_res = NULL; |
| 721 | OSErr _err; |
| 722 | DragRef theDrag; |
| 723 | if (!PyArg_ParseTuple(_args, "O&", |
| 724 | DragObj_Convert, &theDrag)) |
| 725 | return NULL; |
| 726 | _err = DragPostScroll(theDrag); |
| 727 | if (_err != noErr) return PyMac_Error(_err); |
| 728 | Py_INCREF(Py_None); |
| 729 | _res = Py_None; |
| 730 | return _res; |
| 731 | } |
| 732 | |
| 733 | static PyObject *Drag_UpdateDragHilite(_self, _args) |
| 734 | PyObject *_self; |
| 735 | PyObject *_args; |
| 736 | { |
| 737 | PyObject *_res = NULL; |
| 738 | OSErr _err; |
| 739 | DragRef theDrag; |
| 740 | RgnHandle updateRgn; |
| 741 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 742 | DragObj_Convert, &theDrag, |
| 743 | ResObj_Convert, &updateRgn)) |
| 744 | return NULL; |
| 745 | _err = UpdateDragHilite(theDrag, |
| 746 | updateRgn); |
| 747 | if (_err != noErr) return PyMac_Error(_err); |
| 748 | Py_INCREF(Py_None); |
| 749 | _res = Py_None; |
| 750 | return _res; |
| 751 | } |
| 752 | |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 753 | static PyObject *Drag_GetDragHiliteColor(_self, _args) |
| 754 | PyObject *_self; |
| 755 | PyObject *_args; |
| 756 | { |
| 757 | PyObject *_res = NULL; |
| 758 | OSErr _err; |
| 759 | WindowPtr window; |
| 760 | RGBColor color; |
| 761 | if (!PyArg_ParseTuple(_args, "O&", |
| 762 | WinObj_Convert, &window)) |
| 763 | return NULL; |
| 764 | _err = GetDragHiliteColor(window, |
| 765 | &color); |
| 766 | if (_err != noErr) return PyMac_Error(_err); |
| 767 | _res = Py_BuildValue("O&", |
| 768 | QdRGB_New, &color); |
| 769 | return _res; |
| 770 | } |
| 771 | |
| 772 | static PyObject *Drag_WaitMouseMoved(_self, _args) |
| 773 | PyObject *_self; |
| 774 | PyObject *_args; |
| 775 | { |
| 776 | PyObject *_res = NULL; |
| 777 | Boolean _rv; |
| 778 | Point initialMouse; |
| 779 | if (!PyArg_ParseTuple(_args, "O&", |
| 780 | PyMac_GetPoint, &initialMouse)) |
| 781 | return NULL; |
| 782 | _rv = WaitMouseMoved(initialMouse); |
| 783 | _res = Py_BuildValue("b", |
| 784 | _rv); |
| 785 | return _res; |
| 786 | } |
| 787 | |
| 788 | static PyObject *Drag_ZoomRects(_self, _args) |
| 789 | PyObject *_self; |
| 790 | PyObject *_args; |
| 791 | { |
| 792 | PyObject *_res = NULL; |
| 793 | OSErr _err; |
| 794 | Rect fromRect; |
| 795 | Rect toRect; |
| 796 | SInt16 zoomSteps; |
| 797 | ZoomAcceleration acceleration; |
| 798 | if (!PyArg_ParseTuple(_args, "O&O&hh", |
| 799 | PyMac_GetRect, &fromRect, |
| 800 | PyMac_GetRect, &toRect, |
| 801 | &zoomSteps, |
| 802 | &acceleration)) |
| 803 | return NULL; |
| 804 | _err = ZoomRects(&fromRect, |
| 805 | &toRect, |
| 806 | zoomSteps, |
| 807 | acceleration); |
| 808 | if (_err != noErr) return PyMac_Error(_err); |
| 809 | Py_INCREF(Py_None); |
| 810 | _res = Py_None; |
| 811 | return _res; |
| 812 | } |
| 813 | |
| 814 | static PyObject *Drag_ZoomRegion(_self, _args) |
| 815 | PyObject *_self; |
| 816 | PyObject *_args; |
| 817 | { |
| 818 | PyObject *_res = NULL; |
| 819 | OSErr _err; |
| 820 | RgnHandle region; |
| 821 | Point zoomDistance; |
| 822 | SInt16 zoomSteps; |
| 823 | ZoomAcceleration acceleration; |
| 824 | if (!PyArg_ParseTuple(_args, "O&O&hh", |
| 825 | ResObj_Convert, ®ion, |
| 826 | PyMac_GetPoint, &zoomDistance, |
| 827 | &zoomSteps, |
| 828 | &acceleration)) |
| 829 | return NULL; |
| 830 | _err = ZoomRegion(region, |
| 831 | zoomDistance, |
| 832 | zoomSteps, |
| 833 | acceleration); |
| 834 | if (_err != noErr) return PyMac_Error(_err); |
| 835 | Py_INCREF(Py_None); |
| 836 | _res = Py_None; |
| 837 | return _res; |
| 838 | } |
| 839 | |
| 840 | static PyObject *Drag_InstallTrackingHandler(_self, _args) |
| 841 | PyObject *_self; |
| 842 | PyObject *_args; |
| 843 | { |
| 844 | PyObject *_res = NULL; |
| 845 | |
| 846 | PyObject *callback; |
| 847 | WindowPtr theWindow = NULL; |
| 848 | OSErr _err; |
| 849 | |
| 850 | if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) ) |
| 851 | return NULL; |
| 852 | Py_INCREF(callback); /* Cannot decref later, too bad */ |
| 853 | _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback); |
| 854 | if (_err != noErr) return PyMac_Error(_err); |
| 855 | Py_INCREF(Py_None); |
| 856 | return Py_None; |
| 857 | |
| 858 | } |
| 859 | |
| 860 | static PyObject *Drag_InstallReceiveHandler(_self, _args) |
| 861 | PyObject *_self; |
| 862 | PyObject *_args; |
| 863 | { |
| 864 | PyObject *_res = NULL; |
| 865 | |
| 866 | PyObject *callback; |
| 867 | WindowPtr theWindow = NULL; |
| 868 | OSErr _err; |
| 869 | |
| 870 | if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) ) |
| 871 | return NULL; |
| 872 | Py_INCREF(callback); /* Cannot decref later, too bad */ |
| 873 | _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback); |
| 874 | if (_err != noErr) return PyMac_Error(_err); |
| 875 | Py_INCREF(Py_None); |
| 876 | return Py_None; |
| 877 | |
| 878 | } |
| 879 | |
| 880 | static PyObject *Drag_RemoveTrackingHandler(_self, _args) |
| 881 | PyObject *_self; |
| 882 | PyObject *_args; |
| 883 | { |
| 884 | PyObject *_res = NULL; |
| 885 | |
| 886 | WindowPtr theWindow = NULL; |
| 887 | OSErr _err; |
| 888 | |
| 889 | if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) ) |
| 890 | return NULL; |
| 891 | _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow); |
| 892 | if (_err != noErr) return PyMac_Error(_err); |
| 893 | Py_INCREF(Py_None); |
| 894 | return Py_None; |
| 895 | |
| 896 | } |
| 897 | |
| 898 | static PyObject *Drag_RemoveReceiveHandler(_self, _args) |
| 899 | PyObject *_self; |
| 900 | PyObject *_args; |
| 901 | { |
| 902 | PyObject *_res = NULL; |
| 903 | |
| 904 | WindowPtr theWindow = NULL; |
| 905 | OSErr _err; |
| 906 | |
| 907 | if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) ) |
| 908 | return NULL; |
| 909 | _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow); |
| 910 | if (_err != noErr) return PyMac_Error(_err); |
| 911 | Py_INCREF(Py_None); |
| 912 | return Py_None; |
| 913 | |
| 914 | } |
| 915 | |
| 916 | static PyMethodDef Drag_methods[] = { |
| 917 | {"NewDrag", (PyCFunction)Drag_NewDrag, 1, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 918 | "() -> (DragRef theDrag)"}, |
| 919 | {"DisposeDrag", (PyCFunction)Drag_DisposeDrag, 1, |
| 920 | "(DragRef theDrag) -> None"}, |
| 921 | {"AddDragItemFlavor", (PyCFunction)Drag_AddDragItemFlavor, 1, |
| 922 | "(DragRef theDrag, ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"}, |
| 923 | {"SetDragItemFlavorData", (PyCFunction)Drag_SetDragItemFlavorData, 1, |
| 924 | "(DragRef theDrag, ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"}, |
| 925 | {"SetDragImage", (PyCFunction)Drag_SetDragImage, 1, |
| 926 | "(DragRef theDrag, PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"}, |
| 927 | {"ChangeDragBehaviors", (PyCFunction)Drag_ChangeDragBehaviors, 1, |
| 928 | "(DragRef theDrag, DragBehaviors inBehaviorsToSet, DragBehaviors inBehaviorsToClear) -> None"}, |
| 929 | {"TrackDrag", (PyCFunction)Drag_TrackDrag, 1, |
| 930 | "(DragRef theDrag, EventRecord theEvent, RgnHandle theRegion) -> None"}, |
| 931 | {"CountDragItems", (PyCFunction)Drag_CountDragItems, 1, |
| 932 | "(DragRef theDrag) -> (UInt16 numItems)"}, |
| 933 | {"GetDragItemReferenceNumber", (PyCFunction)Drag_GetDragItemReferenceNumber, 1, |
| 934 | "(DragRef theDrag, UInt16 index) -> (ItemReference theItemRef)"}, |
| 935 | {"CountDragItemFlavors", (PyCFunction)Drag_CountDragItemFlavors, 1, |
| 936 | "(DragRef theDrag, ItemReference theItemRef) -> (UInt16 numFlavors)"}, |
| 937 | {"GetFlavorType", (PyCFunction)Drag_GetFlavorType, 1, |
| 938 | "(DragRef theDrag, ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"}, |
| 939 | {"GetFlavorFlags", (PyCFunction)Drag_GetFlavorFlags, 1, |
| 940 | "(DragRef theDrag, ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"}, |
| 941 | {"GetFlavorDataSize", (PyCFunction)Drag_GetFlavorDataSize, 1, |
| 942 | "(DragRef theDrag, ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"}, |
| 943 | {"GetFlavorData", (PyCFunction)Drag_GetFlavorData, 1, |
| 944 | "(DragRef theDrag, ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"}, |
| 945 | {"GetDragItemBounds", (PyCFunction)Drag_GetDragItemBounds, 1, |
| 946 | "(DragRef theDrag, ItemReference theItemRef) -> (Rect itemBounds)"}, |
| 947 | {"SetDragItemBounds", (PyCFunction)Drag_SetDragItemBounds, 1, |
| 948 | "(DragRef theDrag, ItemReference theItemRef, Rect itemBounds) -> None"}, |
| 949 | {"GetDropLocation", (PyCFunction)Drag_GetDropLocation, 1, |
| 950 | "(DragRef theDrag) -> (AEDesc dropLocation)"}, |
| 951 | {"SetDropLocation", (PyCFunction)Drag_SetDropLocation, 1, |
| 952 | "(DragRef theDrag, AEDesc dropLocation) -> None"}, |
| 953 | {"GetDragAttributes", (PyCFunction)Drag_GetDragAttributes, 1, |
| 954 | "(DragRef theDrag) -> (DragAttributes flags)"}, |
| 955 | {"GetDragMouse", (PyCFunction)Drag_GetDragMouse, 1, |
| 956 | "(DragRef theDrag) -> (Point mouse, Point globalPinnedMouse)"}, |
| 957 | {"SetDragMouse", (PyCFunction)Drag_SetDragMouse, 1, |
| 958 | "(DragRef theDrag, Point globalPinnedMouse) -> None"}, |
| 959 | {"GetDragOrigin", (PyCFunction)Drag_GetDragOrigin, 1, |
| 960 | "(DragRef theDrag) -> (Point globalInitialMouse)"}, |
| 961 | {"GetDragModifiers", (PyCFunction)Drag_GetDragModifiers, 1, |
| 962 | "(DragRef theDrag) -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"}, |
| 963 | {"ShowDragHilite", (PyCFunction)Drag_ShowDragHilite, 1, |
| 964 | "(DragRef theDrag, RgnHandle hiliteFrame, Boolean inside) -> None"}, |
| 965 | {"HideDragHilite", (PyCFunction)Drag_HideDragHilite, 1, |
| 966 | "(DragRef theDrag) -> None"}, |
| 967 | {"DragPreScroll", (PyCFunction)Drag_DragPreScroll, 1, |
| 968 | "(DragRef theDrag, SInt16 dH, SInt16 dV) -> None"}, |
| 969 | {"DragPostScroll", (PyCFunction)Drag_DragPostScroll, 1, |
| 970 | "(DragRef theDrag) -> None"}, |
| 971 | {"UpdateDragHilite", (PyCFunction)Drag_UpdateDragHilite, 1, |
| 972 | "(DragRef theDrag, RgnHandle updateRgn) -> None"}, |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 973 | {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1, |
| 974 | "(WindowPtr window) -> (RGBColor color)"}, |
| 975 | {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1, |
| 976 | "(Point initialMouse) -> (Boolean _rv)"}, |
| 977 | {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1, |
| 978 | "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"}, |
| 979 | {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1, |
| 980 | "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"}, |
| 981 | {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1, |
| 982 | NULL}, |
| 983 | {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1, |
| 984 | NULL}, |
| 985 | {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1, |
| 986 | NULL}, |
| 987 | {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1, |
| 988 | NULL}, |
| 989 | {NULL, NULL, 0} |
| 990 | }; |
| 991 | |
| 992 | |
| 993 | |
| 994 | static pascal OSErr |
| 995 | dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow, |
| 996 | void *handlerRefCon, DragReference theDrag) |
| 997 | { |
| 998 | PyObject *args, *rv; |
| 999 | int i; |
| 1000 | |
| 1001 | args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow); |
| 1002 | if ( args == NULL ) |
| 1003 | return -1; |
| 1004 | rv = PyEval_CallObject((PyObject *)handlerRefCon, args); |
| 1005 | Py_DECREF(args); |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1006 | if ( rv == NULL ) { |
| 1007 | fprintf(stderr, "Drag: Exception in TrackingHandler\n"); |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1008 | return -1; |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1009 | } |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1010 | i = -1; |
| 1011 | if ( rv == Py_None ) |
| 1012 | i = 0; |
| 1013 | else |
| 1014 | PyArg_Parse(rv, "l", &i); |
| 1015 | Py_DECREF(rv); |
| 1016 | return i; |
| 1017 | } |
| 1018 | |
| 1019 | static pascal OSErr |
| 1020 | dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon, |
| 1021 | DragReference theDrag) |
| 1022 | { |
| 1023 | PyObject *args, *rv; |
| 1024 | int i; |
| 1025 | |
| 1026 | args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow); |
| 1027 | if ( args == NULL ) |
| 1028 | return -1; |
| 1029 | rv = PyEval_CallObject((PyObject *)handlerRefCon, args); |
| 1030 | Py_DECREF(args); |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1031 | if ( rv == NULL ) { |
| 1032 | fprintf(stderr, "Drag: Exception in ReceiveHandler\n"); |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1033 | return -1; |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1034 | } |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1035 | i = -1; |
| 1036 | if ( rv == Py_None ) |
| 1037 | i = 0; |
| 1038 | else |
| 1039 | PyArg_Parse(rv, "l", &i); |
| 1040 | Py_DECREF(rv); |
| 1041 | return i; |
| 1042 | } |
| 1043 | |
| 1044 | static pascal OSErr |
| 1045 | dragglue_SendData(FlavorType theType, void *dragSendRefCon, |
| 1046 | ItemReference theItem, DragReference theDrag) |
| 1047 | { |
| 1048 | DragObjObject *self = (DragObjObject *)dragSendRefCon; |
| 1049 | PyObject *args, *rv; |
| 1050 | int i; |
| 1051 | |
| 1052 | if ( self->sendproc == NULL ) |
| 1053 | return -1; |
| 1054 | args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem); |
| 1055 | if ( args == NULL ) |
| 1056 | return -1; |
| 1057 | rv = PyEval_CallObject(self->sendproc, args); |
| 1058 | Py_DECREF(args); |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1059 | if ( rv == NULL ) { |
| 1060 | fprintf(stderr, "Drag: Exception in SendDataHandler\n"); |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1061 | return -1; |
Jack Jansen | 58b2eac | 1999-06-21 16:18:51 +0000 | [diff] [blame] | 1062 | } |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1063 | i = -1; |
| 1064 | if ( rv == Py_None ) |
| 1065 | i = 0; |
| 1066 | else |
| 1067 | PyArg_Parse(rv, "l", &i); |
| 1068 | Py_DECREF(rv); |
| 1069 | return i; |
| 1070 | } |
| 1071 | |
| 1072 | #if 0 |
| 1073 | static pascal OSErr |
| 1074 | dragglue_Input(Point *mouse, short *modifiers, |
| 1075 | void *dragSendRefCon, DragReference theDrag) |
| 1076 | { |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
| 1080 | static pascal OSErr |
| 1081 | dragglue_Drawing(xxxx |
| 1082 | void *dragSendRefCon, DragReference theDrag) |
| 1083 | { |
| 1084 | return 0; |
| 1085 | } |
| 1086 | #endif |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | void initDrag() |
| 1091 | { |
| 1092 | PyObject *m; |
| 1093 | PyObject *d; |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | m = Py_InitModule("Drag", Drag_methods); |
| 1099 | d = PyModule_GetDict(m); |
| 1100 | Drag_Error = PyMac_GetOSErrException(); |
| 1101 | if (Drag_Error == NULL || |
| 1102 | PyDict_SetItemString(d, "Error", Drag_Error) != 0) |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 1103 | return; |
Jack Jansen | c4f6331 | 1999-06-21 15:14:26 +0000 | [diff] [blame] | 1104 | DragObj_Type.ob_type = &PyType_Type; |
| 1105 | Py_INCREF(&DragObj_Type); |
| 1106 | if (PyDict_SetItemString(d, "DragObjType", (PyObject *)&DragObj_Type) != 0) |
| 1107 | Py_FatalError("can't initialize DragObjType"); |
| 1108 | |
| 1109 | dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler); |
| 1110 | dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler); |
| 1111 | dragglue_SendDataUPP = NewDragSendDataProc(dragglue_SendData); |
| 1112 | #if 0 |
| 1113 | dragglue_InputUPP = NewDragInputProc(dragglue_Input); |
| 1114 | dragglue_DrawingUPP = NewDragDrawingProc(dragglue_Drawing); |
| 1115 | #endif |
| 1116 | |
| 1117 | |
| 1118 | } |
| 1119 | |
| 1120 | /* ======================== End module Drag ========================= */ |
| 1121 | |