Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Mac / Modules / drag / _Dragmodule.c
blob3b00da81376335c21dcf3d18411bccbc8b19d411
2 /* ========================== Module _Drag ========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <Drag.h>
25 #else
26 #include <Carbon/Carbon.h>
27 #endif
29 /* Callback glue routines */
30 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
31 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
32 DragSendDataUPP dragglue_SendDataUPP;
33 #if 0
34 DragInputUPP dragglue_InputUPP;
35 DragDrawingUPP dragglue_DrawingUPP;
36 #endif
38 #ifdef USE_TOOLBOX_OBJECT_GLUE
39 extern PyObject *_DragObj_New(DragRef);
40 extern int _DragObj_Convert(PyObject *, DragRef *);
42 #define DragObj_New _DragObj_New
43 #define DragObj_Convert _DragObj_Convert
44 #endif
46 static PyObject *Drag_Error;
48 /* ---------------------- Object type DragObj ----------------------- */
50 PyTypeObject DragObj_Type;
52 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type || PyObject_TypeCheck((x), &DragObj_Type))
54 typedef struct DragObjObject {
55 PyObject_HEAD
56 DragRef ob_itself;
57 PyObject *sendproc;
58 } DragObjObject;
60 PyObject *DragObj_New(DragRef itself)
62 DragObjObject *it;
63 if (itself == NULL) {
64 PyErr_SetString(Drag_Error,"Cannot create null Drag");
65 return NULL;
67 it = PyObject_NEW(DragObjObject, &DragObj_Type);
68 if (it == NULL) return NULL;
69 it->ob_itself = itself;
70 it->sendproc = NULL;
71 return (PyObject *)it;
73 int DragObj_Convert(PyObject *v, DragRef *p_itself)
75 if (!DragObj_Check(v))
77 PyErr_SetString(PyExc_TypeError, "DragObj required");
78 return 0;
80 *p_itself = ((DragObjObject *)v)->ob_itself;
81 return 1;
84 static void DragObj_dealloc(DragObjObject *self)
86 Py_XDECREF(self->sendproc);
87 self->ob_type->tp_free((PyObject *)self);
90 static PyObject *DragObj_DisposeDrag(DragObjObject *_self, PyObject *_args)
92 PyObject *_res = NULL;
93 OSErr _err;
94 #ifndef DisposeDrag
95 PyMac_PRECHECK(DisposeDrag);
96 #endif
97 if (!PyArg_ParseTuple(_args, ""))
98 return NULL;
99 _err = DisposeDrag(_self->ob_itself);
100 if (_err != noErr) return PyMac_Error(_err);
101 Py_INCREF(Py_None);
102 _res = Py_None;
103 return _res;
106 static PyObject *DragObj_AddDragItemFlavor(DragObjObject *_self, PyObject *_args)
108 PyObject *_res = NULL;
109 OSErr _err;
110 ItemReference theItemRef;
111 FlavorType theType;
112 char *dataPtr__in__;
113 long dataPtr__len__;
114 int dataPtr__in_len__;
115 FlavorFlags theFlags;
116 #ifndef AddDragItemFlavor
117 PyMac_PRECHECK(AddDragItemFlavor);
118 #endif
119 if (!PyArg_ParseTuple(_args, "lO&z#l",
120 &theItemRef,
121 PyMac_GetOSType, &theType,
122 &dataPtr__in__, &dataPtr__in_len__,
123 &theFlags))
124 return NULL;
125 dataPtr__len__ = dataPtr__in_len__;
126 _err = AddDragItemFlavor(_self->ob_itself,
127 theItemRef,
128 theType,
129 dataPtr__in__, dataPtr__len__,
130 theFlags);
131 if (_err != noErr) return PyMac_Error(_err);
132 Py_INCREF(Py_None);
133 _res = Py_None;
134 return _res;
137 static PyObject *DragObj_SetDragItemFlavorData(DragObjObject *_self, PyObject *_args)
139 PyObject *_res = NULL;
140 OSErr _err;
141 ItemReference theItemRef;
142 FlavorType theType;
143 char *dataPtr__in__;
144 long dataPtr__len__;
145 int dataPtr__in_len__;
146 UInt32 dataOffset;
147 #ifndef SetDragItemFlavorData
148 PyMac_PRECHECK(SetDragItemFlavorData);
149 #endif
150 if (!PyArg_ParseTuple(_args, "lO&z#l",
151 &theItemRef,
152 PyMac_GetOSType, &theType,
153 &dataPtr__in__, &dataPtr__in_len__,
154 &dataOffset))
155 return NULL;
156 dataPtr__len__ = dataPtr__in_len__;
157 _err = SetDragItemFlavorData(_self->ob_itself,
158 theItemRef,
159 theType,
160 dataPtr__in__, dataPtr__len__,
161 dataOffset);
162 if (_err != noErr) return PyMac_Error(_err);
163 Py_INCREF(Py_None);
164 _res = Py_None;
165 return _res;
168 static PyObject *DragObj_SetDragImage(DragObjObject *_self, PyObject *_args)
170 PyObject *_res = NULL;
171 OSErr _err;
172 PixMapHandle imagePixMap;
173 RgnHandle imageRgn;
174 Point imageOffsetPt;
175 DragImageFlags theImageFlags;
176 #ifndef SetDragImage
177 PyMac_PRECHECK(SetDragImage);
178 #endif
179 if (!PyArg_ParseTuple(_args, "O&O&O&l",
180 ResObj_Convert, &imagePixMap,
181 ResObj_Convert, &imageRgn,
182 PyMac_GetPoint, &imageOffsetPt,
183 &theImageFlags))
184 return NULL;
185 _err = SetDragImage(_self->ob_itself,
186 imagePixMap,
187 imageRgn,
188 imageOffsetPt,
189 theImageFlags);
190 if (_err != noErr) return PyMac_Error(_err);
191 Py_INCREF(Py_None);
192 _res = Py_None;
193 return _res;
196 static PyObject *DragObj_ChangeDragBehaviors(DragObjObject *_self, PyObject *_args)
198 PyObject *_res = NULL;
199 OSErr _err;
200 DragBehaviors inBehaviorsToSet;
201 DragBehaviors inBehaviorsToClear;
202 #ifndef ChangeDragBehaviors
203 PyMac_PRECHECK(ChangeDragBehaviors);
204 #endif
205 if (!PyArg_ParseTuple(_args, "ll",
206 &inBehaviorsToSet,
207 &inBehaviorsToClear))
208 return NULL;
209 _err = ChangeDragBehaviors(_self->ob_itself,
210 inBehaviorsToSet,
211 inBehaviorsToClear);
212 if (_err != noErr) return PyMac_Error(_err);
213 Py_INCREF(Py_None);
214 _res = Py_None;
215 return _res;
218 static PyObject *DragObj_TrackDrag(DragObjObject *_self, PyObject *_args)
220 PyObject *_res = NULL;
221 OSErr _err;
222 EventRecord theEvent;
223 RgnHandle theRegion;
224 #ifndef TrackDrag
225 PyMac_PRECHECK(TrackDrag);
226 #endif
227 if (!PyArg_ParseTuple(_args, "O&O&",
228 PyMac_GetEventRecord, &theEvent,
229 ResObj_Convert, &theRegion))
230 return NULL;
231 _err = TrackDrag(_self->ob_itself,
232 &theEvent,
233 theRegion);
234 if (_err != noErr) return PyMac_Error(_err);
235 Py_INCREF(Py_None);
236 _res = Py_None;
237 return _res;
240 static PyObject *DragObj_CountDragItems(DragObjObject *_self, PyObject *_args)
242 PyObject *_res = NULL;
243 OSErr _err;
244 UInt16 numItems;
245 #ifndef CountDragItems
246 PyMac_PRECHECK(CountDragItems);
247 #endif
248 if (!PyArg_ParseTuple(_args, ""))
249 return NULL;
250 _err = CountDragItems(_self->ob_itself,
251 &numItems);
252 if (_err != noErr) return PyMac_Error(_err);
253 _res = Py_BuildValue("H",
254 numItems);
255 return _res;
258 static PyObject *DragObj_GetDragItemReferenceNumber(DragObjObject *_self, PyObject *_args)
260 PyObject *_res = NULL;
261 OSErr _err;
262 UInt16 index;
263 ItemReference theItemRef;
264 #ifndef GetDragItemReferenceNumber
265 PyMac_PRECHECK(GetDragItemReferenceNumber);
266 #endif
267 if (!PyArg_ParseTuple(_args, "H",
268 &index))
269 return NULL;
270 _err = GetDragItemReferenceNumber(_self->ob_itself,
271 index,
272 &theItemRef);
273 if (_err != noErr) return PyMac_Error(_err);
274 _res = Py_BuildValue("l",
275 theItemRef);
276 return _res;
279 static PyObject *DragObj_CountDragItemFlavors(DragObjObject *_self, PyObject *_args)
281 PyObject *_res = NULL;
282 OSErr _err;
283 ItemReference theItemRef;
284 UInt16 numFlavors;
285 #ifndef CountDragItemFlavors
286 PyMac_PRECHECK(CountDragItemFlavors);
287 #endif
288 if (!PyArg_ParseTuple(_args, "l",
289 &theItemRef))
290 return NULL;
291 _err = CountDragItemFlavors(_self->ob_itself,
292 theItemRef,
293 &numFlavors);
294 if (_err != noErr) return PyMac_Error(_err);
295 _res = Py_BuildValue("H",
296 numFlavors);
297 return _res;
300 static PyObject *DragObj_GetFlavorType(DragObjObject *_self, PyObject *_args)
302 PyObject *_res = NULL;
303 OSErr _err;
304 ItemReference theItemRef;
305 UInt16 index;
306 FlavorType theType;
307 #ifndef GetFlavorType
308 PyMac_PRECHECK(GetFlavorType);
309 #endif
310 if (!PyArg_ParseTuple(_args, "lH",
311 &theItemRef,
312 &index))
313 return NULL;
314 _err = GetFlavorType(_self->ob_itself,
315 theItemRef,
316 index,
317 &theType);
318 if (_err != noErr) return PyMac_Error(_err);
319 _res = Py_BuildValue("O&",
320 PyMac_BuildOSType, theType);
321 return _res;
324 static PyObject *DragObj_GetFlavorFlags(DragObjObject *_self, PyObject *_args)
326 PyObject *_res = NULL;
327 OSErr _err;
328 ItemReference theItemRef;
329 FlavorType theType;
330 FlavorFlags theFlags;
331 #ifndef GetFlavorFlags
332 PyMac_PRECHECK(GetFlavorFlags);
333 #endif
334 if (!PyArg_ParseTuple(_args, "lO&",
335 &theItemRef,
336 PyMac_GetOSType, &theType))
337 return NULL;
338 _err = GetFlavorFlags(_self->ob_itself,
339 theItemRef,
340 theType,
341 &theFlags);
342 if (_err != noErr) return PyMac_Error(_err);
343 _res = Py_BuildValue("l",
344 theFlags);
345 return _res;
348 static PyObject *DragObj_GetFlavorDataSize(DragObjObject *_self, PyObject *_args)
350 PyObject *_res = NULL;
351 OSErr _err;
352 ItemReference theItemRef;
353 FlavorType theType;
354 Size dataSize;
355 #ifndef GetFlavorDataSize
356 PyMac_PRECHECK(GetFlavorDataSize);
357 #endif
358 if (!PyArg_ParseTuple(_args, "lO&",
359 &theItemRef,
360 PyMac_GetOSType, &theType))
361 return NULL;
362 _err = GetFlavorDataSize(_self->ob_itself,
363 theItemRef,
364 theType,
365 &dataSize);
366 if (_err != noErr) return PyMac_Error(_err);
367 _res = Py_BuildValue("l",
368 dataSize);
369 return _res;
372 static PyObject *DragObj_GetFlavorData(DragObjObject *_self, PyObject *_args)
374 PyObject *_res = NULL;
375 OSErr _err;
376 ItemReference theItemRef;
377 FlavorType theType;
378 char *dataPtr__out__;
379 long dataPtr__len__;
380 int dataPtr__in_len__;
381 UInt32 dataOffset;
382 #ifndef GetFlavorData
383 PyMac_PRECHECK(GetFlavorData);
384 #endif
385 if (!PyArg_ParseTuple(_args, "lO&il",
386 &theItemRef,
387 PyMac_GetOSType, &theType,
388 &dataPtr__in_len__,
389 &dataOffset))
390 return NULL;
391 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
393 PyErr_NoMemory();
394 goto dataPtr__error__;
396 dataPtr__len__ = dataPtr__in_len__;
397 _err = GetFlavorData(_self->ob_itself,
398 theItemRef,
399 theType,
400 dataPtr__out__, &dataPtr__len__,
401 dataOffset);
402 if (_err != noErr) return PyMac_Error(_err);
403 _res = Py_BuildValue("s#",
404 dataPtr__out__, (int)dataPtr__len__);
405 free(dataPtr__out__);
406 dataPtr__error__: ;
407 return _res;
410 static PyObject *DragObj_GetDragItemBounds(DragObjObject *_self, PyObject *_args)
412 PyObject *_res = NULL;
413 OSErr _err;
414 ItemReference theItemRef;
415 Rect itemBounds;
416 #ifndef GetDragItemBounds
417 PyMac_PRECHECK(GetDragItemBounds);
418 #endif
419 if (!PyArg_ParseTuple(_args, "l",
420 &theItemRef))
421 return NULL;
422 _err = GetDragItemBounds(_self->ob_itself,
423 theItemRef,
424 &itemBounds);
425 if (_err != noErr) return PyMac_Error(_err);
426 _res = Py_BuildValue("O&",
427 PyMac_BuildRect, &itemBounds);
428 return _res;
431 static PyObject *DragObj_SetDragItemBounds(DragObjObject *_self, PyObject *_args)
433 PyObject *_res = NULL;
434 OSErr _err;
435 ItemReference theItemRef;
436 Rect itemBounds;
437 #ifndef SetDragItemBounds
438 PyMac_PRECHECK(SetDragItemBounds);
439 #endif
440 if (!PyArg_ParseTuple(_args, "lO&",
441 &theItemRef,
442 PyMac_GetRect, &itemBounds))
443 return NULL;
444 _err = SetDragItemBounds(_self->ob_itself,
445 theItemRef,
446 &itemBounds);
447 if (_err != noErr) return PyMac_Error(_err);
448 Py_INCREF(Py_None);
449 _res = Py_None;
450 return _res;
453 static PyObject *DragObj_GetDropLocation(DragObjObject *_self, PyObject *_args)
455 PyObject *_res = NULL;
456 OSErr _err;
457 AEDesc dropLocation;
458 #ifndef GetDropLocation
459 PyMac_PRECHECK(GetDropLocation);
460 #endif
461 if (!PyArg_ParseTuple(_args, ""))
462 return NULL;
463 _err = GetDropLocation(_self->ob_itself,
464 &dropLocation);
465 if (_err != noErr) return PyMac_Error(_err);
466 _res = Py_BuildValue("O&",
467 AEDesc_New, &dropLocation);
468 return _res;
471 static PyObject *DragObj_SetDropLocation(DragObjObject *_self, PyObject *_args)
473 PyObject *_res = NULL;
474 OSErr _err;
475 AEDesc dropLocation;
476 #ifndef SetDropLocation
477 PyMac_PRECHECK(SetDropLocation);
478 #endif
479 if (!PyArg_ParseTuple(_args, "O&",
480 AEDesc_Convert, &dropLocation))
481 return NULL;
482 _err = SetDropLocation(_self->ob_itself,
483 &dropLocation);
484 if (_err != noErr) return PyMac_Error(_err);
485 Py_INCREF(Py_None);
486 _res = Py_None;
487 return _res;
490 static PyObject *DragObj_GetDragAttributes(DragObjObject *_self, PyObject *_args)
492 PyObject *_res = NULL;
493 OSErr _err;
494 DragAttributes flags;
495 #ifndef GetDragAttributes
496 PyMac_PRECHECK(GetDragAttributes);
497 #endif
498 if (!PyArg_ParseTuple(_args, ""))
499 return NULL;
500 _err = GetDragAttributes(_self->ob_itself,
501 &flags);
502 if (_err != noErr) return PyMac_Error(_err);
503 _res = Py_BuildValue("l",
504 flags);
505 return _res;
508 static PyObject *DragObj_GetDragMouse(DragObjObject *_self, PyObject *_args)
510 PyObject *_res = NULL;
511 OSErr _err;
512 Point mouse;
513 Point globalPinnedMouse;
514 #ifndef GetDragMouse
515 PyMac_PRECHECK(GetDragMouse);
516 #endif
517 if (!PyArg_ParseTuple(_args, ""))
518 return NULL;
519 _err = GetDragMouse(_self->ob_itself,
520 &mouse,
521 &globalPinnedMouse);
522 if (_err != noErr) return PyMac_Error(_err);
523 _res = Py_BuildValue("O&O&",
524 PyMac_BuildPoint, mouse,
525 PyMac_BuildPoint, globalPinnedMouse);
526 return _res;
529 static PyObject *DragObj_SetDragMouse(DragObjObject *_self, PyObject *_args)
531 PyObject *_res = NULL;
532 OSErr _err;
533 Point globalPinnedMouse;
534 #ifndef SetDragMouse
535 PyMac_PRECHECK(SetDragMouse);
536 #endif
537 if (!PyArg_ParseTuple(_args, "O&",
538 PyMac_GetPoint, &globalPinnedMouse))
539 return NULL;
540 _err = SetDragMouse(_self->ob_itself,
541 globalPinnedMouse);
542 if (_err != noErr) return PyMac_Error(_err);
543 Py_INCREF(Py_None);
544 _res = Py_None;
545 return _res;
548 static PyObject *DragObj_GetDragOrigin(DragObjObject *_self, PyObject *_args)
550 PyObject *_res = NULL;
551 OSErr _err;
552 Point globalInitialMouse;
553 #ifndef GetDragOrigin
554 PyMac_PRECHECK(GetDragOrigin);
555 #endif
556 if (!PyArg_ParseTuple(_args, ""))
557 return NULL;
558 _err = GetDragOrigin(_self->ob_itself,
559 &globalInitialMouse);
560 if (_err != noErr) return PyMac_Error(_err);
561 _res = Py_BuildValue("O&",
562 PyMac_BuildPoint, globalInitialMouse);
563 return _res;
566 static PyObject *DragObj_GetDragModifiers(DragObjObject *_self, PyObject *_args)
568 PyObject *_res = NULL;
569 OSErr _err;
570 SInt16 modifiers;
571 SInt16 mouseDownModifiers;
572 SInt16 mouseUpModifiers;
573 #ifndef GetDragModifiers
574 PyMac_PRECHECK(GetDragModifiers);
575 #endif
576 if (!PyArg_ParseTuple(_args, ""))
577 return NULL;
578 _err = GetDragModifiers(_self->ob_itself,
579 &modifiers,
580 &mouseDownModifiers,
581 &mouseUpModifiers);
582 if (_err != noErr) return PyMac_Error(_err);
583 _res = Py_BuildValue("hhh",
584 modifiers,
585 mouseDownModifiers,
586 mouseUpModifiers);
587 return _res;
590 static PyObject *DragObj_ShowDragHilite(DragObjObject *_self, PyObject *_args)
592 PyObject *_res = NULL;
593 OSErr _err;
594 RgnHandle hiliteFrame;
595 Boolean inside;
596 #ifndef ShowDragHilite
597 PyMac_PRECHECK(ShowDragHilite);
598 #endif
599 if (!PyArg_ParseTuple(_args, "O&b",
600 ResObj_Convert, &hiliteFrame,
601 &inside))
602 return NULL;
603 _err = ShowDragHilite(_self->ob_itself,
604 hiliteFrame,
605 inside);
606 if (_err != noErr) return PyMac_Error(_err);
607 Py_INCREF(Py_None);
608 _res = Py_None;
609 return _res;
612 static PyObject *DragObj_HideDragHilite(DragObjObject *_self, PyObject *_args)
614 PyObject *_res = NULL;
615 OSErr _err;
616 #ifndef HideDragHilite
617 PyMac_PRECHECK(HideDragHilite);
618 #endif
619 if (!PyArg_ParseTuple(_args, ""))
620 return NULL;
621 _err = HideDragHilite(_self->ob_itself);
622 if (_err != noErr) return PyMac_Error(_err);
623 Py_INCREF(Py_None);
624 _res = Py_None;
625 return _res;
628 static PyObject *DragObj_DragPreScroll(DragObjObject *_self, PyObject *_args)
630 PyObject *_res = NULL;
631 OSErr _err;
632 SInt16 dH;
633 SInt16 dV;
634 #ifndef DragPreScroll
635 PyMac_PRECHECK(DragPreScroll);
636 #endif
637 if (!PyArg_ParseTuple(_args, "hh",
638 &dH,
639 &dV))
640 return NULL;
641 _err = DragPreScroll(_self->ob_itself,
643 dV);
644 if (_err != noErr) return PyMac_Error(_err);
645 Py_INCREF(Py_None);
646 _res = Py_None;
647 return _res;
650 static PyObject *DragObj_DragPostScroll(DragObjObject *_self, PyObject *_args)
652 PyObject *_res = NULL;
653 OSErr _err;
654 #ifndef DragPostScroll
655 PyMac_PRECHECK(DragPostScroll);
656 #endif
657 if (!PyArg_ParseTuple(_args, ""))
658 return NULL;
659 _err = DragPostScroll(_self->ob_itself);
660 if (_err != noErr) return PyMac_Error(_err);
661 Py_INCREF(Py_None);
662 _res = Py_None;
663 return _res;
666 static PyObject *DragObj_UpdateDragHilite(DragObjObject *_self, PyObject *_args)
668 PyObject *_res = NULL;
669 OSErr _err;
670 RgnHandle updateRgn;
671 #ifndef UpdateDragHilite
672 PyMac_PRECHECK(UpdateDragHilite);
673 #endif
674 if (!PyArg_ParseTuple(_args, "O&",
675 ResObj_Convert, &updateRgn))
676 return NULL;
677 _err = UpdateDragHilite(_self->ob_itself,
678 updateRgn);
679 if (_err != noErr) return PyMac_Error(_err);
680 Py_INCREF(Py_None);
681 _res = Py_None;
682 return _res;
685 static PyMethodDef DragObj_methods[] = {
686 {"DisposeDrag", (PyCFunction)DragObj_DisposeDrag, 1,
687 PyDoc_STR("() -> None")},
688 {"AddDragItemFlavor", (PyCFunction)DragObj_AddDragItemFlavor, 1,
689 PyDoc_STR("(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None")},
690 {"SetDragItemFlavorData", (PyCFunction)DragObj_SetDragItemFlavorData, 1,
691 PyDoc_STR("(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None")},
692 {"SetDragImage", (PyCFunction)DragObj_SetDragImage, 1,
693 PyDoc_STR("(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None")},
694 {"ChangeDragBehaviors", (PyCFunction)DragObj_ChangeDragBehaviors, 1,
695 PyDoc_STR("(DragBehaviors inBehaviorsToSet, DragBehaviors inBehaviorsToClear) -> None")},
696 {"TrackDrag", (PyCFunction)DragObj_TrackDrag, 1,
697 PyDoc_STR("(EventRecord theEvent, RgnHandle theRegion) -> None")},
698 {"CountDragItems", (PyCFunction)DragObj_CountDragItems, 1,
699 PyDoc_STR("() -> (UInt16 numItems)")},
700 {"GetDragItemReferenceNumber", (PyCFunction)DragObj_GetDragItemReferenceNumber, 1,
701 PyDoc_STR("(UInt16 index) -> (ItemReference theItemRef)")},
702 {"CountDragItemFlavors", (PyCFunction)DragObj_CountDragItemFlavors, 1,
703 PyDoc_STR("(ItemReference theItemRef) -> (UInt16 numFlavors)")},
704 {"GetFlavorType", (PyCFunction)DragObj_GetFlavorType, 1,
705 PyDoc_STR("(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)")},
706 {"GetFlavorFlags", (PyCFunction)DragObj_GetFlavorFlags, 1,
707 PyDoc_STR("(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)")},
708 {"GetFlavorDataSize", (PyCFunction)DragObj_GetFlavorDataSize, 1,
709 PyDoc_STR("(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)")},
710 {"GetFlavorData", (PyCFunction)DragObj_GetFlavorData, 1,
711 PyDoc_STR("(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)")},
712 {"GetDragItemBounds", (PyCFunction)DragObj_GetDragItemBounds, 1,
713 PyDoc_STR("(ItemReference theItemRef) -> (Rect itemBounds)")},
714 {"SetDragItemBounds", (PyCFunction)DragObj_SetDragItemBounds, 1,
715 PyDoc_STR("(ItemReference theItemRef, Rect itemBounds) -> None")},
716 {"GetDropLocation", (PyCFunction)DragObj_GetDropLocation, 1,
717 PyDoc_STR("() -> (AEDesc dropLocation)")},
718 {"SetDropLocation", (PyCFunction)DragObj_SetDropLocation, 1,
719 PyDoc_STR("(AEDesc dropLocation) -> None")},
720 {"GetDragAttributes", (PyCFunction)DragObj_GetDragAttributes, 1,
721 PyDoc_STR("() -> (DragAttributes flags)")},
722 {"GetDragMouse", (PyCFunction)DragObj_GetDragMouse, 1,
723 PyDoc_STR("() -> (Point mouse, Point globalPinnedMouse)")},
724 {"SetDragMouse", (PyCFunction)DragObj_SetDragMouse, 1,
725 PyDoc_STR("(Point globalPinnedMouse) -> None")},
726 {"GetDragOrigin", (PyCFunction)DragObj_GetDragOrigin, 1,
727 PyDoc_STR("() -> (Point globalInitialMouse)")},
728 {"GetDragModifiers", (PyCFunction)DragObj_GetDragModifiers, 1,
729 PyDoc_STR("() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)")},
730 {"ShowDragHilite", (PyCFunction)DragObj_ShowDragHilite, 1,
731 PyDoc_STR("(RgnHandle hiliteFrame, Boolean inside) -> None")},
732 {"HideDragHilite", (PyCFunction)DragObj_HideDragHilite, 1,
733 PyDoc_STR("() -> None")},
734 {"DragPreScroll", (PyCFunction)DragObj_DragPreScroll, 1,
735 PyDoc_STR("(SInt16 dH, SInt16 dV) -> None")},
736 {"DragPostScroll", (PyCFunction)DragObj_DragPostScroll, 1,
737 PyDoc_STR("() -> None")},
738 {"UpdateDragHilite", (PyCFunction)DragObj_UpdateDragHilite, 1,
739 PyDoc_STR("(RgnHandle updateRgn) -> None")},
740 {NULL, NULL, 0}
743 #define DragObj_getsetlist NULL
746 #define DragObj_compare NULL
748 #define DragObj_repr NULL
750 #define DragObj_hash NULL
751 #define DragObj_tp_init 0
753 #define DragObj_tp_alloc PyType_GenericAlloc
755 static PyObject *DragObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
757 PyObject *self;
758 DragRef itself;
759 char *kw[] = {"itself", 0};
761 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, DragObj_Convert, &itself)) return NULL;
762 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
763 ((DragObjObject *)self)->ob_itself = itself;
764 return self;
767 #define DragObj_tp_free PyObject_Del
770 PyTypeObject DragObj_Type = {
771 PyObject_HEAD_INIT(NULL)
772 0, /*ob_size*/
773 "_Drag.DragObj", /*tp_name*/
774 sizeof(DragObjObject), /*tp_basicsize*/
775 0, /*tp_itemsize*/
776 /* methods */
777 (destructor) DragObj_dealloc, /*tp_dealloc*/
778 0, /*tp_print*/
779 (getattrfunc)0, /*tp_getattr*/
780 (setattrfunc)0, /*tp_setattr*/
781 (cmpfunc) DragObj_compare, /*tp_compare*/
782 (reprfunc) DragObj_repr, /*tp_repr*/
783 (PyNumberMethods *)0, /* tp_as_number */
784 (PySequenceMethods *)0, /* tp_as_sequence */
785 (PyMappingMethods *)0, /* tp_as_mapping */
786 (hashfunc) DragObj_hash, /*tp_hash*/
787 0, /*tp_call*/
788 0, /*tp_str*/
789 PyObject_GenericGetAttr, /*tp_getattro*/
790 PyObject_GenericSetAttr, /*tp_setattro */
791 0, /*tp_as_buffer*/
792 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
793 0, /*tp_doc*/
794 0, /*tp_traverse*/
795 0, /*tp_clear*/
796 0, /*tp_richcompare*/
797 0, /*tp_weaklistoffset*/
798 0, /*tp_iter*/
799 0, /*tp_iternext*/
800 DragObj_methods, /* tp_methods */
801 0, /*tp_members*/
802 DragObj_getsetlist, /*tp_getset*/
803 0, /*tp_base*/
804 0, /*tp_dict*/
805 0, /*tp_descr_get*/
806 0, /*tp_descr_set*/
807 0, /*tp_dictoffset*/
808 DragObj_tp_init, /* tp_init */
809 DragObj_tp_alloc, /* tp_alloc */
810 DragObj_tp_new, /* tp_new */
811 DragObj_tp_free, /* tp_free */
814 /* -------------------- End object type DragObj --------------------- */
817 static PyObject *Drag_NewDrag(PyObject *_self, PyObject *_args)
819 PyObject *_res = NULL;
820 OSErr _err;
821 DragRef theDrag;
822 #ifndef NewDrag
823 PyMac_PRECHECK(NewDrag);
824 #endif
825 if (!PyArg_ParseTuple(_args, ""))
826 return NULL;
827 _err = NewDrag(&theDrag);
828 if (_err != noErr) return PyMac_Error(_err);
829 _res = Py_BuildValue("O&",
830 DragObj_New, theDrag);
831 return _res;
834 static PyObject *Drag_GetDragHiliteColor(PyObject *_self, PyObject *_args)
836 PyObject *_res = NULL;
837 OSErr _err;
838 WindowPtr window;
839 RGBColor color;
840 #ifndef GetDragHiliteColor
841 PyMac_PRECHECK(GetDragHiliteColor);
842 #endif
843 if (!PyArg_ParseTuple(_args, "O&",
844 WinObj_Convert, &window))
845 return NULL;
846 _err = GetDragHiliteColor(window,
847 &color);
848 if (_err != noErr) return PyMac_Error(_err);
849 _res = Py_BuildValue("O&",
850 QdRGB_New, &color);
851 return _res;
854 static PyObject *Drag_WaitMouseMoved(PyObject *_self, PyObject *_args)
856 PyObject *_res = NULL;
857 Boolean _rv;
858 Point initialMouse;
859 #ifndef WaitMouseMoved
860 PyMac_PRECHECK(WaitMouseMoved);
861 #endif
862 if (!PyArg_ParseTuple(_args, "O&",
863 PyMac_GetPoint, &initialMouse))
864 return NULL;
865 _rv = WaitMouseMoved(initialMouse);
866 _res = Py_BuildValue("b",
867 _rv);
868 return _res;
871 static PyObject *Drag_ZoomRects(PyObject *_self, PyObject *_args)
873 PyObject *_res = NULL;
874 OSErr _err;
875 Rect fromRect;
876 Rect toRect;
877 SInt16 zoomSteps;
878 ZoomAcceleration acceleration;
879 #ifndef ZoomRects
880 PyMac_PRECHECK(ZoomRects);
881 #endif
882 if (!PyArg_ParseTuple(_args, "O&O&hh",
883 PyMac_GetRect, &fromRect,
884 PyMac_GetRect, &toRect,
885 &zoomSteps,
886 &acceleration))
887 return NULL;
888 _err = ZoomRects(&fromRect,
889 &toRect,
890 zoomSteps,
891 acceleration);
892 if (_err != noErr) return PyMac_Error(_err);
893 Py_INCREF(Py_None);
894 _res = Py_None;
895 return _res;
898 static PyObject *Drag_ZoomRegion(PyObject *_self, PyObject *_args)
900 PyObject *_res = NULL;
901 OSErr _err;
902 RgnHandle region;
903 Point zoomDistance;
904 SInt16 zoomSteps;
905 ZoomAcceleration acceleration;
906 #ifndef ZoomRegion
907 PyMac_PRECHECK(ZoomRegion);
908 #endif
909 if (!PyArg_ParseTuple(_args, "O&O&hh",
910 ResObj_Convert, &region,
911 PyMac_GetPoint, &zoomDistance,
912 &zoomSteps,
913 &acceleration))
914 return NULL;
915 _err = ZoomRegion(region,
916 zoomDistance,
917 zoomSteps,
918 acceleration);
919 if (_err != noErr) return PyMac_Error(_err);
920 Py_INCREF(Py_None);
921 _res = Py_None;
922 return _res;
925 static PyObject *Drag_InstallTrackingHandler(PyObject *_self, PyObject *_args)
927 PyObject *_res = NULL;
929 PyObject *callback;
930 WindowPtr theWindow = NULL;
931 OSErr _err;
933 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
934 return NULL;
935 Py_INCREF(callback); /* Cannot decref later, too bad */
936 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
937 if (_err != noErr) return PyMac_Error(_err);
938 Py_INCREF(Py_None);
939 _res = Py_None;
940 return _res;
944 static PyObject *Drag_InstallReceiveHandler(PyObject *_self, PyObject *_args)
946 PyObject *_res = NULL;
948 PyObject *callback;
949 WindowPtr theWindow = NULL;
950 OSErr _err;
952 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
953 return NULL;
954 Py_INCREF(callback); /* Cannot decref later, too bad */
955 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
956 if (_err != noErr) return PyMac_Error(_err);
957 Py_INCREF(Py_None);
958 _res = Py_None;
959 return _res;
963 static PyObject *Drag_RemoveTrackingHandler(PyObject *_self, PyObject *_args)
965 PyObject *_res = NULL;
967 WindowPtr theWindow = NULL;
968 OSErr _err;
970 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
971 return NULL;
972 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
973 if (_err != noErr) return PyMac_Error(_err);
974 Py_INCREF(Py_None);
975 _res = Py_None;
976 return _res;
980 static PyObject *Drag_RemoveReceiveHandler(PyObject *_self, PyObject *_args)
982 PyObject *_res = NULL;
984 WindowPtr theWindow = NULL;
985 OSErr _err;
987 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
988 return NULL;
989 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
990 if (_err != noErr) return PyMac_Error(_err);
991 Py_INCREF(Py_None);
992 _res = Py_None;
993 return _res;
997 static PyMethodDef Drag_methods[] = {
998 {"NewDrag", (PyCFunction)Drag_NewDrag, 1,
999 PyDoc_STR("() -> (DragRef theDrag)")},
1000 {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1,
1001 PyDoc_STR("(WindowPtr window) -> (RGBColor color)")},
1002 {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1,
1003 PyDoc_STR("(Point initialMouse) -> (Boolean _rv)")},
1004 {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1,
1005 PyDoc_STR("(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None")},
1006 {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1,
1007 PyDoc_STR("(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None")},
1008 {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1,
1009 PyDoc_STR(NULL)},
1010 {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1,
1011 PyDoc_STR(NULL)},
1012 {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1,
1013 PyDoc_STR(NULL)},
1014 {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1,
1015 PyDoc_STR(NULL)},
1016 {NULL, NULL, 0}
1021 static pascal OSErr
1022 dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
1023 void *handlerRefCon, DragReference theDrag)
1025 PyObject *args, *rv;
1026 int i;
1028 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
1029 if ( args == NULL )
1030 return -1;
1031 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
1032 Py_DECREF(args);
1033 if ( rv == NULL ) {
1034 PySys_WriteStderr("Drag: Exception in TrackingHandler\n");
1035 PyErr_Print();
1036 return -1;
1038 i = -1;
1039 if ( rv == Py_None )
1040 i = 0;
1041 else
1042 PyArg_Parse(rv, "l", &i);
1043 Py_DECREF(rv);
1044 return i;
1047 static pascal OSErr
1048 dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
1049 DragReference theDrag)
1051 PyObject *args, *rv;
1052 int i;
1054 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
1055 if ( args == NULL )
1056 return -1;
1057 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
1058 Py_DECREF(args);
1059 if ( rv == NULL ) {
1060 PySys_WriteStderr("Drag: Exception in ReceiveHandler\n");
1061 PyErr_Print();
1062 return -1;
1064 i = -1;
1065 if ( rv == Py_None )
1066 i = 0;
1067 else
1068 PyArg_Parse(rv, "l", &i);
1069 Py_DECREF(rv);
1070 return i;
1073 static pascal OSErr
1074 dragglue_SendData(FlavorType theType, void *dragSendRefCon,
1075 ItemReference theItem, DragReference theDrag)
1077 DragObjObject *self = (DragObjObject *)dragSendRefCon;
1078 PyObject *args, *rv;
1079 int i;
1081 if ( self->sendproc == NULL )
1082 return -1;
1083 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
1084 if ( args == NULL )
1085 return -1;
1086 rv = PyEval_CallObject(self->sendproc, args);
1087 Py_DECREF(args);
1088 if ( rv == NULL ) {
1089 PySys_WriteStderr("Drag: Exception in SendDataHandler\n");
1090 PyErr_Print();
1091 return -1;
1093 i = -1;
1094 if ( rv == Py_None )
1095 i = 0;
1096 else
1097 PyArg_Parse(rv, "l", &i);
1098 Py_DECREF(rv);
1099 return i;
1102 #if 0
1103 static pascal OSErr
1104 dragglue_Input(Point *mouse, short *modifiers,
1105 void *dragSendRefCon, DragReference theDrag)
1107 return 0;
1110 static pascal OSErr
1111 dragglue_Drawing(xxxx
1112 void *dragSendRefCon, DragReference theDrag)
1114 return 0;
1116 #endif
1120 void init_Drag(void)
1122 PyObject *m;
1123 PyObject *d;
1127 PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
1128 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
1131 m = Py_InitModule("_Drag", Drag_methods);
1132 d = PyModule_GetDict(m);
1133 Drag_Error = PyMac_GetOSErrException();
1134 if (Drag_Error == NULL ||
1135 PyDict_SetItemString(d, "Error", Drag_Error) != 0)
1136 return;
1137 DragObj_Type.ob_type = &PyType_Type;
1138 if (PyType_Ready(&DragObj_Type) < 0) return;
1139 Py_INCREF(&DragObj_Type);
1140 PyModule_AddObject(m, "DragObj", (PyObject *)&DragObj_Type);
1141 /* Backward-compatible name */
1142 Py_INCREF(&DragObj_Type);
1143 PyModule_AddObject(m, "DragObjType", (PyObject *)&DragObj_Type);
1145 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerUPP(dragglue_TrackingHandler);
1146 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerUPP(dragglue_ReceiveHandler);
1147 dragglue_SendDataUPP = NewDragSendDataUPP(dragglue_SendData);
1148 #if 0
1149 dragglue_InputUPP = NewDragInputUPP(dragglue_Input);
1150 dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
1151 #endif
1156 /* ======================== End module _Drag ======================== */