2 /* ========================== Module _Drag ========================== */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
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"); \
23 #ifdef WITHOUT_FRAMEWORKS
26 #include <Carbon/Carbon.h>
29 /* Callback glue routines */
30 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP
;
31 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP
;
32 DragSendDataUPP dragglue_SendDataUPP
;
34 DragInputUPP dragglue_InputUPP
;
35 DragDrawingUPP dragglue_DrawingUPP
;
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
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
{
60 PyObject
*DragObj_New(DragRef itself
)
64 PyErr_SetString(Drag_Error
,"Cannot create null Drag");
67 it
= PyObject_NEW(DragObjObject
, &DragObj_Type
);
68 if (it
== NULL
) return NULL
;
69 it
->ob_itself
= itself
;
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");
80 *p_itself
= ((DragObjObject
*)v
)->ob_itself
;
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
;
95 PyMac_PRECHECK(DisposeDrag
);
97 if (!PyArg_ParseTuple(_args
, ""))
99 _err
= DisposeDrag(_self
->ob_itself
);
100 if (_err
!= noErr
) return PyMac_Error(_err
);
106 static PyObject
*DragObj_AddDragItemFlavor(DragObjObject
*_self
, PyObject
*_args
)
108 PyObject
*_res
= NULL
;
110 ItemReference theItemRef
;
114 int dataPtr__in_len__
;
115 FlavorFlags theFlags
;
116 #ifndef AddDragItemFlavor
117 PyMac_PRECHECK(AddDragItemFlavor
);
119 if (!PyArg_ParseTuple(_args
, "lO&z#l",
121 PyMac_GetOSType
, &theType
,
122 &dataPtr__in__
, &dataPtr__in_len__
,
125 dataPtr__len__
= dataPtr__in_len__
;
126 _err
= AddDragItemFlavor(_self
->ob_itself
,
129 dataPtr__in__
, dataPtr__len__
,
131 if (_err
!= noErr
) return PyMac_Error(_err
);
137 static PyObject
*DragObj_SetDragItemFlavorData(DragObjObject
*_self
, PyObject
*_args
)
139 PyObject
*_res
= NULL
;
141 ItemReference theItemRef
;
145 int dataPtr__in_len__
;
147 #ifndef SetDragItemFlavorData
148 PyMac_PRECHECK(SetDragItemFlavorData
);
150 if (!PyArg_ParseTuple(_args
, "lO&z#l",
152 PyMac_GetOSType
, &theType
,
153 &dataPtr__in__
, &dataPtr__in_len__
,
156 dataPtr__len__
= dataPtr__in_len__
;
157 _err
= SetDragItemFlavorData(_self
->ob_itself
,
160 dataPtr__in__
, dataPtr__len__
,
162 if (_err
!= noErr
) return PyMac_Error(_err
);
168 static PyObject
*DragObj_SetDragImage(DragObjObject
*_self
, PyObject
*_args
)
170 PyObject
*_res
= NULL
;
172 PixMapHandle imagePixMap
;
175 DragImageFlags theImageFlags
;
177 PyMac_PRECHECK(SetDragImage
);
179 if (!PyArg_ParseTuple(_args
, "O&O&O&l",
180 ResObj_Convert
, &imagePixMap
,
181 ResObj_Convert
, &imageRgn
,
182 PyMac_GetPoint
, &imageOffsetPt
,
185 _err
= SetDragImage(_self
->ob_itself
,
190 if (_err
!= noErr
) return PyMac_Error(_err
);
196 static PyObject
*DragObj_ChangeDragBehaviors(DragObjObject
*_self
, PyObject
*_args
)
198 PyObject
*_res
= NULL
;
200 DragBehaviors inBehaviorsToSet
;
201 DragBehaviors inBehaviorsToClear
;
202 #ifndef ChangeDragBehaviors
203 PyMac_PRECHECK(ChangeDragBehaviors
);
205 if (!PyArg_ParseTuple(_args
, "ll",
207 &inBehaviorsToClear
))
209 _err
= ChangeDragBehaviors(_self
->ob_itself
,
212 if (_err
!= noErr
) return PyMac_Error(_err
);
218 static PyObject
*DragObj_TrackDrag(DragObjObject
*_self
, PyObject
*_args
)
220 PyObject
*_res
= NULL
;
222 EventRecord theEvent
;
225 PyMac_PRECHECK(TrackDrag
);
227 if (!PyArg_ParseTuple(_args
, "O&O&",
228 PyMac_GetEventRecord
, &theEvent
,
229 ResObj_Convert
, &theRegion
))
231 _err
= TrackDrag(_self
->ob_itself
,
234 if (_err
!= noErr
) return PyMac_Error(_err
);
240 static PyObject
*DragObj_CountDragItems(DragObjObject
*_self
, PyObject
*_args
)
242 PyObject
*_res
= NULL
;
245 #ifndef CountDragItems
246 PyMac_PRECHECK(CountDragItems
);
248 if (!PyArg_ParseTuple(_args
, ""))
250 _err
= CountDragItems(_self
->ob_itself
,
252 if (_err
!= noErr
) return PyMac_Error(_err
);
253 _res
= Py_BuildValue("H",
258 static PyObject
*DragObj_GetDragItemReferenceNumber(DragObjObject
*_self
, PyObject
*_args
)
260 PyObject
*_res
= NULL
;
263 ItemReference theItemRef
;
264 #ifndef GetDragItemReferenceNumber
265 PyMac_PRECHECK(GetDragItemReferenceNumber
);
267 if (!PyArg_ParseTuple(_args
, "H",
270 _err
= GetDragItemReferenceNumber(_self
->ob_itself
,
273 if (_err
!= noErr
) return PyMac_Error(_err
);
274 _res
= Py_BuildValue("l",
279 static PyObject
*DragObj_CountDragItemFlavors(DragObjObject
*_self
, PyObject
*_args
)
281 PyObject
*_res
= NULL
;
283 ItemReference theItemRef
;
285 #ifndef CountDragItemFlavors
286 PyMac_PRECHECK(CountDragItemFlavors
);
288 if (!PyArg_ParseTuple(_args
, "l",
291 _err
= CountDragItemFlavors(_self
->ob_itself
,
294 if (_err
!= noErr
) return PyMac_Error(_err
);
295 _res
= Py_BuildValue("H",
300 static PyObject
*DragObj_GetFlavorType(DragObjObject
*_self
, PyObject
*_args
)
302 PyObject
*_res
= NULL
;
304 ItemReference theItemRef
;
307 #ifndef GetFlavorType
308 PyMac_PRECHECK(GetFlavorType
);
310 if (!PyArg_ParseTuple(_args
, "lH",
314 _err
= GetFlavorType(_self
->ob_itself
,
318 if (_err
!= noErr
) return PyMac_Error(_err
);
319 _res
= Py_BuildValue("O&",
320 PyMac_BuildOSType
, theType
);
324 static PyObject
*DragObj_GetFlavorFlags(DragObjObject
*_self
, PyObject
*_args
)
326 PyObject
*_res
= NULL
;
328 ItemReference theItemRef
;
330 FlavorFlags theFlags
;
331 #ifndef GetFlavorFlags
332 PyMac_PRECHECK(GetFlavorFlags
);
334 if (!PyArg_ParseTuple(_args
, "lO&",
336 PyMac_GetOSType
, &theType
))
338 _err
= GetFlavorFlags(_self
->ob_itself
,
342 if (_err
!= noErr
) return PyMac_Error(_err
);
343 _res
= Py_BuildValue("l",
348 static PyObject
*DragObj_GetFlavorDataSize(DragObjObject
*_self
, PyObject
*_args
)
350 PyObject
*_res
= NULL
;
352 ItemReference theItemRef
;
355 #ifndef GetFlavorDataSize
356 PyMac_PRECHECK(GetFlavorDataSize
);
358 if (!PyArg_ParseTuple(_args
, "lO&",
360 PyMac_GetOSType
, &theType
))
362 _err
= GetFlavorDataSize(_self
->ob_itself
,
366 if (_err
!= noErr
) return PyMac_Error(_err
);
367 _res
= Py_BuildValue("l",
372 static PyObject
*DragObj_GetFlavorData(DragObjObject
*_self
, PyObject
*_args
)
374 PyObject
*_res
= NULL
;
376 ItemReference theItemRef
;
378 char *dataPtr__out__
;
380 int dataPtr__in_len__
;
382 #ifndef GetFlavorData
383 PyMac_PRECHECK(GetFlavorData
);
385 if (!PyArg_ParseTuple(_args
, "lO&il",
387 PyMac_GetOSType
, &theType
,
391 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
394 goto dataPtr__error__
;
396 dataPtr__len__
= dataPtr__in_len__
;
397 _err
= GetFlavorData(_self
->ob_itself
,
400 dataPtr__out__
, &dataPtr__len__
,
402 if (_err
!= noErr
) return PyMac_Error(_err
);
403 _res
= Py_BuildValue("s#",
404 dataPtr__out__
, (int)dataPtr__len__
);
405 free(dataPtr__out__
);
410 static PyObject
*DragObj_GetDragItemBounds(DragObjObject
*_self
, PyObject
*_args
)
412 PyObject
*_res
= NULL
;
414 ItemReference theItemRef
;
416 #ifndef GetDragItemBounds
417 PyMac_PRECHECK(GetDragItemBounds
);
419 if (!PyArg_ParseTuple(_args
, "l",
422 _err
= GetDragItemBounds(_self
->ob_itself
,
425 if (_err
!= noErr
) return PyMac_Error(_err
);
426 _res
= Py_BuildValue("O&",
427 PyMac_BuildRect
, &itemBounds
);
431 static PyObject
*DragObj_SetDragItemBounds(DragObjObject
*_self
, PyObject
*_args
)
433 PyObject
*_res
= NULL
;
435 ItemReference theItemRef
;
437 #ifndef SetDragItemBounds
438 PyMac_PRECHECK(SetDragItemBounds
);
440 if (!PyArg_ParseTuple(_args
, "lO&",
442 PyMac_GetRect
, &itemBounds
))
444 _err
= SetDragItemBounds(_self
->ob_itself
,
447 if (_err
!= noErr
) return PyMac_Error(_err
);
453 static PyObject
*DragObj_GetDropLocation(DragObjObject
*_self
, PyObject
*_args
)
455 PyObject
*_res
= NULL
;
458 #ifndef GetDropLocation
459 PyMac_PRECHECK(GetDropLocation
);
461 if (!PyArg_ParseTuple(_args
, ""))
463 _err
= GetDropLocation(_self
->ob_itself
,
465 if (_err
!= noErr
) return PyMac_Error(_err
);
466 _res
= Py_BuildValue("O&",
467 AEDesc_New
, &dropLocation
);
471 static PyObject
*DragObj_SetDropLocation(DragObjObject
*_self
, PyObject
*_args
)
473 PyObject
*_res
= NULL
;
476 #ifndef SetDropLocation
477 PyMac_PRECHECK(SetDropLocation
);
479 if (!PyArg_ParseTuple(_args
, "O&",
480 AEDesc_Convert
, &dropLocation
))
482 _err
= SetDropLocation(_self
->ob_itself
,
484 if (_err
!= noErr
) return PyMac_Error(_err
);
490 static PyObject
*DragObj_GetDragAttributes(DragObjObject
*_self
, PyObject
*_args
)
492 PyObject
*_res
= NULL
;
494 DragAttributes flags
;
495 #ifndef GetDragAttributes
496 PyMac_PRECHECK(GetDragAttributes
);
498 if (!PyArg_ParseTuple(_args
, ""))
500 _err
= GetDragAttributes(_self
->ob_itself
,
502 if (_err
!= noErr
) return PyMac_Error(_err
);
503 _res
= Py_BuildValue("l",
508 static PyObject
*DragObj_GetDragMouse(DragObjObject
*_self
, PyObject
*_args
)
510 PyObject
*_res
= NULL
;
513 Point globalPinnedMouse
;
515 PyMac_PRECHECK(GetDragMouse
);
517 if (!PyArg_ParseTuple(_args
, ""))
519 _err
= GetDragMouse(_self
->ob_itself
,
522 if (_err
!= noErr
) return PyMac_Error(_err
);
523 _res
= Py_BuildValue("O&O&",
524 PyMac_BuildPoint
, mouse
,
525 PyMac_BuildPoint
, globalPinnedMouse
);
529 static PyObject
*DragObj_SetDragMouse(DragObjObject
*_self
, PyObject
*_args
)
531 PyObject
*_res
= NULL
;
533 Point globalPinnedMouse
;
535 PyMac_PRECHECK(SetDragMouse
);
537 if (!PyArg_ParseTuple(_args
, "O&",
538 PyMac_GetPoint
, &globalPinnedMouse
))
540 _err
= SetDragMouse(_self
->ob_itself
,
542 if (_err
!= noErr
) return PyMac_Error(_err
);
548 static PyObject
*DragObj_GetDragOrigin(DragObjObject
*_self
, PyObject
*_args
)
550 PyObject
*_res
= NULL
;
552 Point globalInitialMouse
;
553 #ifndef GetDragOrigin
554 PyMac_PRECHECK(GetDragOrigin
);
556 if (!PyArg_ParseTuple(_args
, ""))
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
);
566 static PyObject
*DragObj_GetDragModifiers(DragObjObject
*_self
, PyObject
*_args
)
568 PyObject
*_res
= NULL
;
571 SInt16 mouseDownModifiers
;
572 SInt16 mouseUpModifiers
;
573 #ifndef GetDragModifiers
574 PyMac_PRECHECK(GetDragModifiers
);
576 if (!PyArg_ParseTuple(_args
, ""))
578 _err
= GetDragModifiers(_self
->ob_itself
,
582 if (_err
!= noErr
) return PyMac_Error(_err
);
583 _res
= Py_BuildValue("hhh",
590 static PyObject
*DragObj_ShowDragHilite(DragObjObject
*_self
, PyObject
*_args
)
592 PyObject
*_res
= NULL
;
594 RgnHandle hiliteFrame
;
596 #ifndef ShowDragHilite
597 PyMac_PRECHECK(ShowDragHilite
);
599 if (!PyArg_ParseTuple(_args
, "O&b",
600 ResObj_Convert
, &hiliteFrame
,
603 _err
= ShowDragHilite(_self
->ob_itself
,
606 if (_err
!= noErr
) return PyMac_Error(_err
);
612 static PyObject
*DragObj_HideDragHilite(DragObjObject
*_self
, PyObject
*_args
)
614 PyObject
*_res
= NULL
;
616 #ifndef HideDragHilite
617 PyMac_PRECHECK(HideDragHilite
);
619 if (!PyArg_ParseTuple(_args
, ""))
621 _err
= HideDragHilite(_self
->ob_itself
);
622 if (_err
!= noErr
) return PyMac_Error(_err
);
628 static PyObject
*DragObj_DragPreScroll(DragObjObject
*_self
, PyObject
*_args
)
630 PyObject
*_res
= NULL
;
634 #ifndef DragPreScroll
635 PyMac_PRECHECK(DragPreScroll
);
637 if (!PyArg_ParseTuple(_args
, "hh",
641 _err
= DragPreScroll(_self
->ob_itself
,
644 if (_err
!= noErr
) return PyMac_Error(_err
);
650 static PyObject
*DragObj_DragPostScroll(DragObjObject
*_self
, PyObject
*_args
)
652 PyObject
*_res
= NULL
;
654 #ifndef DragPostScroll
655 PyMac_PRECHECK(DragPostScroll
);
657 if (!PyArg_ParseTuple(_args
, ""))
659 _err
= DragPostScroll(_self
->ob_itself
);
660 if (_err
!= noErr
) return PyMac_Error(_err
);
666 static PyObject
*DragObj_UpdateDragHilite(DragObjObject
*_self
, PyObject
*_args
)
668 PyObject
*_res
= NULL
;
671 #ifndef UpdateDragHilite
672 PyMac_PRECHECK(UpdateDragHilite
);
674 if (!PyArg_ParseTuple(_args
, "O&",
675 ResObj_Convert
, &updateRgn
))
677 _err
= UpdateDragHilite(_self
->ob_itself
,
679 if (_err
!= noErr
) return PyMac_Error(_err
);
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")},
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
)
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
;
767 #define DragObj_tp_free PyObject_Del
770 PyTypeObject DragObj_Type
= {
771 PyObject_HEAD_INIT(NULL
)
773 "_Drag.DragObj", /*tp_name*/
774 sizeof(DragObjObject
), /*tp_basicsize*/
777 (destructor
) DragObj_dealloc
, /*tp_dealloc*/
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*/
789 PyObject_GenericGetAttr
, /*tp_getattro*/
790 PyObject_GenericSetAttr
, /*tp_setattro */
792 Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
, /* tp_flags */
796 0, /*tp_richcompare*/
797 0, /*tp_weaklistoffset*/
800 DragObj_methods
, /* tp_methods */
802 DragObj_getsetlist
, /*tp_getset*/
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
;
823 PyMac_PRECHECK(NewDrag
);
825 if (!PyArg_ParseTuple(_args
, ""))
827 _err
= NewDrag(&theDrag
);
828 if (_err
!= noErr
) return PyMac_Error(_err
);
829 _res
= Py_BuildValue("O&",
830 DragObj_New
, theDrag
);
834 static PyObject
*Drag_GetDragHiliteColor(PyObject
*_self
, PyObject
*_args
)
836 PyObject
*_res
= NULL
;
840 #ifndef GetDragHiliteColor
841 PyMac_PRECHECK(GetDragHiliteColor
);
843 if (!PyArg_ParseTuple(_args
, "O&",
844 WinObj_Convert
, &window
))
846 _err
= GetDragHiliteColor(window
,
848 if (_err
!= noErr
) return PyMac_Error(_err
);
849 _res
= Py_BuildValue("O&",
854 static PyObject
*Drag_WaitMouseMoved(PyObject
*_self
, PyObject
*_args
)
856 PyObject
*_res
= NULL
;
859 #ifndef WaitMouseMoved
860 PyMac_PRECHECK(WaitMouseMoved
);
862 if (!PyArg_ParseTuple(_args
, "O&",
863 PyMac_GetPoint
, &initialMouse
))
865 _rv
= WaitMouseMoved(initialMouse
);
866 _res
= Py_BuildValue("b",
871 static PyObject
*Drag_ZoomRects(PyObject
*_self
, PyObject
*_args
)
873 PyObject
*_res
= NULL
;
878 ZoomAcceleration acceleration
;
880 PyMac_PRECHECK(ZoomRects
);
882 if (!PyArg_ParseTuple(_args
, "O&O&hh",
883 PyMac_GetRect
, &fromRect
,
884 PyMac_GetRect
, &toRect
,
888 _err
= ZoomRects(&fromRect
,
892 if (_err
!= noErr
) return PyMac_Error(_err
);
898 static PyObject
*Drag_ZoomRegion(PyObject
*_self
, PyObject
*_args
)
900 PyObject
*_res
= NULL
;
905 ZoomAcceleration acceleration
;
907 PyMac_PRECHECK(ZoomRegion
);
909 if (!PyArg_ParseTuple(_args
, "O&O&hh",
910 ResObj_Convert
, ®ion
,
911 PyMac_GetPoint
, &zoomDistance
,
915 _err
= ZoomRegion(region
,
919 if (_err
!= noErr
) return PyMac_Error(_err
);
925 static PyObject
*Drag_InstallTrackingHandler(PyObject
*_self
, PyObject
*_args
)
927 PyObject
*_res
= NULL
;
930 WindowPtr theWindow
= NULL
;
933 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
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
);
944 static PyObject
*Drag_InstallReceiveHandler(PyObject
*_self
, PyObject
*_args
)
946 PyObject
*_res
= NULL
;
949 WindowPtr theWindow
= NULL
;
952 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
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
);
963 static PyObject
*Drag_RemoveTrackingHandler(PyObject
*_self
, PyObject
*_args
)
965 PyObject
*_res
= NULL
;
967 WindowPtr theWindow
= NULL
;
970 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
972 _err
= RemoveTrackingHandler(dragglue_TrackingHandlerUPP
, theWindow
);
973 if (_err
!= noErr
) return PyMac_Error(_err
);
980 static PyObject
*Drag_RemoveReceiveHandler(PyObject
*_self
, PyObject
*_args
)
982 PyObject
*_res
= NULL
;
984 WindowPtr theWindow
= NULL
;
987 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
989 _err
= RemoveReceiveHandler(dragglue_ReceiveHandlerUPP
, theWindow
);
990 if (_err
!= noErr
) return PyMac_Error(_err
);
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,
1010 {"InstallReceiveHandler", (PyCFunction
)Drag_InstallReceiveHandler
, 1,
1012 {"RemoveTrackingHandler", (PyCFunction
)Drag_RemoveTrackingHandler
, 1,
1014 {"RemoveReceiveHandler", (PyCFunction
)Drag_RemoveReceiveHandler
, 1,
1022 dragglue_TrackingHandler(DragTrackingMessage theMessage
, WindowPtr theWindow
,
1023 void *handlerRefCon
, DragReference theDrag
)
1025 PyObject
*args
, *rv
;
1028 args
= Py_BuildValue("hO&O&", theMessage
, DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
1031 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
1034 PySys_WriteStderr("Drag: Exception in TrackingHandler\n");
1039 if ( rv
== Py_None
)
1042 PyArg_Parse(rv
, "l", &i
);
1048 dragglue_ReceiveHandler(WindowPtr theWindow
, void *handlerRefCon
,
1049 DragReference theDrag
)
1051 PyObject
*args
, *rv
;
1054 args
= Py_BuildValue("O&O&", DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
1057 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
1060 PySys_WriteStderr("Drag: Exception in ReceiveHandler\n");
1065 if ( rv
== Py_None
)
1068 PyArg_Parse(rv
, "l", &i
);
1074 dragglue_SendData(FlavorType theType
, void *dragSendRefCon
,
1075 ItemReference theItem
, DragReference theDrag
)
1077 DragObjObject
*self
= (DragObjObject
*)dragSendRefCon
;
1078 PyObject
*args
, *rv
;
1081 if ( self
->sendproc
== NULL
)
1083 args
= Py_BuildValue("O&l", PyMac_BuildOSType
, theType
, theItem
);
1086 rv
= PyEval_CallObject(self
->sendproc
, args
);
1089 PySys_WriteStderr("Drag: Exception in SendDataHandler\n");
1094 if ( rv
== Py_None
)
1097 PyArg_Parse(rv
, "l", &i
);
1104 dragglue_Input(Point
*mouse
, short *modifiers
,
1105 void *dragSendRefCon
, DragReference theDrag
)
1111 dragglue_Drawing(xxxx
1112 void *dragSendRefCon
, DragReference theDrag
)
1120 void init_Drag(void)
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)
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
);
1149 dragglue_InputUPP
= NewDragInputUPP(dragglue_Input
);
1150 dragglue_DrawingUPP
= NewDragDrawingUPP(dragglue_Drawing
);
1156 /* ======================== End module _Drag ======================== */