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