2 /* ========================== Module Drag =========================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
18 extern PyObject
*OptResObj_New(Handle
);
19 extern int OptResObj_Convert(PyObject
*, Handle
*);
21 extern PyObject
*WinObj_New(WindowPtr
);
22 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyTypeObject Window_Type
;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject
*DlgObj_New(DialogPtr
);
27 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
28 extern PyTypeObject Dialog_Type
;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
47 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48 /* Exported by Qdmodule.c: */
49 extern PyObject
*QdRGB_New(RGBColor
*);
50 extern int QdRGB_Convert(PyObject
*, RGBColor
*);
53 /* Exported by AEModule.c: */
54 extern PyObject
*AEDesc_New(AppleEvent
*);
55 extern int AEDesc_Convert(PyObject
*, AppleEvent
*);
57 /* Callback glue routines */
58 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP
;
59 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP
;
60 DragSendDataUPP dragglue_SendDataUPP
;
62 DragInputUPP dragglue_InputUPP
;
63 DragDrawingUPP dragglue_DrawingUPP
;
66 static PyObject
*Drag_Error
;
68 /* ---------------------- Object type DragObj ----------------------- */
70 PyTypeObject DragObj_Type
;
72 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
74 typedef struct DragObjObject
{
76 DragReference ob_itself
;
80 PyObject
*DragObj_New(itself
)
85 PyErr_SetString(Drag_Error
,"Cannot create null Drag");
88 it
= PyObject_NEW(DragObjObject
, &DragObj_Type
);
89 if (it
== NULL
) return NULL
;
90 it
->ob_itself
= itself
;
92 return (PyObject
*)it
;
94 DragObj_Convert(v
, p_itself
)
96 DragReference
*p_itself
;
98 if (!DragObj_Check(v
))
100 PyErr_SetString(PyExc_TypeError
, "DragObj required");
103 *p_itself
= ((DragObjObject
*)v
)->ob_itself
;
107 static void DragObj_dealloc(self
)
110 Py_XDECREF(self
->sendproc
);
114 static PyObject
*DragObj_DisposeDrag(_self
, _args
)
115 DragObjObject
*_self
;
118 PyObject
*_res
= NULL
;
120 if (!PyArg_ParseTuple(_args
, ""))
122 _err
= DisposeDrag(_self
->ob_itself
);
123 if (_err
!= noErr
) return PyMac_Error(_err
);
129 static PyObject
*DragObj_AddDragItemFlavor(_self
, _args
)
130 DragObjObject
*_self
;
133 PyObject
*_res
= NULL
;
135 ItemReference theItemRef
;
139 int dataPtr__in_len__
;
140 FlavorFlags theFlags
;
141 if (!PyArg_ParseTuple(_args
, "lO&z#l",
143 PyMac_GetOSType
, &theType
,
144 &dataPtr__in__
, &dataPtr__in_len__
,
147 dataPtr__len__
= dataPtr__in_len__
;
148 _err
= AddDragItemFlavor(_self
->ob_itself
,
151 dataPtr__in__
, dataPtr__len__
,
153 if (_err
!= noErr
) return PyMac_Error(_err
);
160 static PyObject
*DragObj_SetDragItemFlavorData(_self
, _args
)
161 DragObjObject
*_self
;
164 PyObject
*_res
= NULL
;
166 ItemReference theItemRef
;
170 int dataPtr__in_len__
;
172 if (!PyArg_ParseTuple(_args
, "lO&z#l",
174 PyMac_GetOSType
, &theType
,
175 &dataPtr__in__
, &dataPtr__in_len__
,
178 dataPtr__len__
= dataPtr__in_len__
;
179 _err
= SetDragItemFlavorData(_self
->ob_itself
,
182 dataPtr__in__
, dataPtr__len__
,
184 if (_err
!= noErr
) return PyMac_Error(_err
);
191 static PyObject
*DragObj_SetDragImage(_self
, _args
)
192 DragObjObject
*_self
;
195 PyObject
*_res
= NULL
;
197 PixMapHandle imagePixMap
;
200 DragImageFlags theImageFlags
;
201 if (!PyArg_ParseTuple(_args
, "O&O&O&l",
202 ResObj_Convert
, &imagePixMap
,
203 ResObj_Convert
, &imageRgn
,
204 PyMac_GetPoint
, &imageOffsetPt
,
207 _err
= SetDragImage(_self
->ob_itself
,
212 if (_err
!= noErr
) return PyMac_Error(_err
);
218 static PyObject
*DragObj_TrackDrag(_self
, _args
)
219 DragObjObject
*_self
;
222 PyObject
*_res
= NULL
;
224 EventRecord theEvent
;
226 if (!PyArg_ParseTuple(_args
, "O&O&",
227 PyMac_GetEventRecord
, &theEvent
,
228 ResObj_Convert
, &theRegion
))
230 _err
= TrackDrag(_self
->ob_itself
,
233 if (_err
!= noErr
) return PyMac_Error(_err
);
239 static PyObject
*DragObj_CountDragItems(_self
, _args
)
240 DragObjObject
*_self
;
243 PyObject
*_res
= NULL
;
246 if (!PyArg_ParseTuple(_args
, ""))
248 _err
= CountDragItems(_self
->ob_itself
,
250 if (_err
!= noErr
) return PyMac_Error(_err
);
251 _res
= Py_BuildValue("h",
256 static PyObject
*DragObj_GetDragItemReferenceNumber(_self
, _args
)
257 DragObjObject
*_self
;
260 PyObject
*_res
= NULL
;
263 ItemReference theItemRef
;
264 if (!PyArg_ParseTuple(_args
, "h",
267 _err
= GetDragItemReferenceNumber(_self
->ob_itself
,
270 if (_err
!= noErr
) return PyMac_Error(_err
);
271 _res
= Py_BuildValue("l",
276 static PyObject
*DragObj_CountDragItemFlavors(_self
, _args
)
277 DragObjObject
*_self
;
280 PyObject
*_res
= NULL
;
282 ItemReference theItemRef
;
284 if (!PyArg_ParseTuple(_args
, "l",
287 _err
= CountDragItemFlavors(_self
->ob_itself
,
290 if (_err
!= noErr
) return PyMac_Error(_err
);
291 _res
= Py_BuildValue("h",
296 static PyObject
*DragObj_GetFlavorType(_self
, _args
)
297 DragObjObject
*_self
;
300 PyObject
*_res
= NULL
;
302 ItemReference theItemRef
;
305 if (!PyArg_ParseTuple(_args
, "lh",
309 _err
= GetFlavorType(_self
->ob_itself
,
313 if (_err
!= noErr
) return PyMac_Error(_err
);
314 _res
= Py_BuildValue("O&",
315 PyMac_BuildOSType
, theType
);
319 static PyObject
*DragObj_GetFlavorFlags(_self
, _args
)
320 DragObjObject
*_self
;
323 PyObject
*_res
= NULL
;
325 ItemReference theItemRef
;
327 FlavorFlags theFlags
;
328 if (!PyArg_ParseTuple(_args
, "lO&",
330 PyMac_GetOSType
, &theType
))
332 _err
= GetFlavorFlags(_self
->ob_itself
,
336 if (_err
!= noErr
) return PyMac_Error(_err
);
337 _res
= Py_BuildValue("l",
342 static PyObject
*DragObj_GetFlavorDataSize(_self
, _args
)
343 DragObjObject
*_self
;
346 PyObject
*_res
= NULL
;
348 ItemReference theItemRef
;
351 if (!PyArg_ParseTuple(_args
, "lO&",
353 PyMac_GetOSType
, &theType
))
355 _err
= GetFlavorDataSize(_self
->ob_itself
,
359 if (_err
!= noErr
) return PyMac_Error(_err
);
360 _res
= Py_BuildValue("l",
365 static PyObject
*DragObj_GetFlavorData(_self
, _args
)
366 DragObjObject
*_self
;
369 PyObject
*_res
= NULL
;
371 ItemReference theItemRef
;
373 char *dataPtr__out__
;
375 int dataPtr__in_len__
;
377 if (!PyArg_ParseTuple(_args
, "lO&il",
379 PyMac_GetOSType
, &theType
,
383 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
386 goto dataPtr__error__
;
388 dataPtr__len__
= dataPtr__in_len__
;
389 _err
= GetFlavorData(_self
->ob_itself
,
392 dataPtr__out__
, &dataPtr__len__
,
394 if (_err
!= noErr
) return PyMac_Error(_err
);
395 _res
= Py_BuildValue("s#",
396 dataPtr__out__
, (int)dataPtr__len__
);
397 free(dataPtr__out__
);
402 static PyObject
*DragObj_GetDragItemBounds(_self
, _args
)
403 DragObjObject
*_self
;
406 PyObject
*_res
= NULL
;
408 ItemReference theItemRef
;
410 if (!PyArg_ParseTuple(_args
, "l",
413 _err
= GetDragItemBounds(_self
->ob_itself
,
416 if (_err
!= noErr
) return PyMac_Error(_err
);
417 _res
= Py_BuildValue("O&",
418 PyMac_BuildRect
, &itemBounds
);
422 static PyObject
*DragObj_SetDragItemBounds(_self
, _args
)
423 DragObjObject
*_self
;
426 PyObject
*_res
= NULL
;
428 ItemReference theItemRef
;
430 if (!PyArg_ParseTuple(_args
, "lO&",
432 PyMac_GetRect
, &itemBounds
))
434 _err
= SetDragItemBounds(_self
->ob_itself
,
437 if (_err
!= noErr
) return PyMac_Error(_err
);
443 static PyObject
*DragObj_GetDropLocation(_self
, _args
)
444 DragObjObject
*_self
;
447 PyObject
*_res
= NULL
;
450 if (!PyArg_ParseTuple(_args
, ""))
452 _err
= GetDropLocation(_self
->ob_itself
,
454 if (_err
!= noErr
) return PyMac_Error(_err
);
455 _res
= Py_BuildValue("O&",
456 AEDesc_New
, &dropLocation
);
460 static PyObject
*DragObj_SetDropLocation(_self
, _args
)
461 DragObjObject
*_self
;
464 PyObject
*_res
= NULL
;
467 if (!PyArg_ParseTuple(_args
, "O&",
468 AEDesc_Convert
, &dropLocation
))
470 _err
= SetDropLocation(_self
->ob_itself
,
472 if (_err
!= noErr
) return PyMac_Error(_err
);
478 static PyObject
*DragObj_GetDragAttributes(_self
, _args
)
479 DragObjObject
*_self
;
482 PyObject
*_res
= NULL
;
484 DragAttributes flags
;
485 if (!PyArg_ParseTuple(_args
, ""))
487 _err
= GetDragAttributes(_self
->ob_itself
,
489 if (_err
!= noErr
) return PyMac_Error(_err
);
490 _res
= Py_BuildValue("l",
495 static PyObject
*DragObj_GetDragMouse(_self
, _args
)
496 DragObjObject
*_self
;
499 PyObject
*_res
= NULL
;
502 Point globalPinnedMouse
;
503 if (!PyArg_ParseTuple(_args
, ""))
505 _err
= GetDragMouse(_self
->ob_itself
,
508 if (_err
!= noErr
) return PyMac_Error(_err
);
509 _res
= Py_BuildValue("O&O&",
510 PyMac_BuildPoint
, mouse
,
511 PyMac_BuildPoint
, globalPinnedMouse
);
515 static PyObject
*DragObj_SetDragMouse(_self
, _args
)
516 DragObjObject
*_self
;
519 PyObject
*_res
= NULL
;
521 Point globalPinnedMouse
;
522 if (!PyArg_ParseTuple(_args
, "O&",
523 PyMac_GetPoint
, &globalPinnedMouse
))
525 _err
= SetDragMouse(_self
->ob_itself
,
527 if (_err
!= noErr
) return PyMac_Error(_err
);
533 static PyObject
*DragObj_GetDragOrigin(_self
, _args
)
534 DragObjObject
*_self
;
537 PyObject
*_res
= NULL
;
539 Point globalInitialMouse
;
540 if (!PyArg_ParseTuple(_args
, ""))
542 _err
= GetDragOrigin(_self
->ob_itself
,
543 &globalInitialMouse
);
544 if (_err
!= noErr
) return PyMac_Error(_err
);
545 _res
= Py_BuildValue("O&",
546 PyMac_BuildPoint
, globalInitialMouse
);
550 static PyObject
*DragObj_GetDragModifiers(_self
, _args
)
551 DragObjObject
*_self
;
554 PyObject
*_res
= NULL
;
557 SInt16 mouseDownModifiers
;
558 SInt16 mouseUpModifiers
;
559 if (!PyArg_ParseTuple(_args
, ""))
561 _err
= GetDragModifiers(_self
->ob_itself
,
565 if (_err
!= noErr
) return PyMac_Error(_err
);
566 _res
= Py_BuildValue("hhh",
573 static PyObject
*DragObj_ShowDragHilite(_self
, _args
)
574 DragObjObject
*_self
;
577 PyObject
*_res
= NULL
;
579 RgnHandle hiliteFrame
;
581 if (!PyArg_ParseTuple(_args
, "O&b",
582 ResObj_Convert
, &hiliteFrame
,
585 _err
= ShowDragHilite(_self
->ob_itself
,
588 if (_err
!= noErr
) return PyMac_Error(_err
);
594 static PyObject
*DragObj_HideDragHilite(_self
, _args
)
595 DragObjObject
*_self
;
598 PyObject
*_res
= NULL
;
600 if (!PyArg_ParseTuple(_args
, ""))
602 _err
= HideDragHilite(_self
->ob_itself
);
603 if (_err
!= noErr
) return PyMac_Error(_err
);
609 static PyObject
*DragObj_DragPreScroll(_self
, _args
)
610 DragObjObject
*_self
;
613 PyObject
*_res
= NULL
;
617 if (!PyArg_ParseTuple(_args
, "hh",
621 _err
= DragPreScroll(_self
->ob_itself
,
624 if (_err
!= noErr
) return PyMac_Error(_err
);
630 static PyObject
*DragObj_DragPostScroll(_self
, _args
)
631 DragObjObject
*_self
;
634 PyObject
*_res
= NULL
;
636 if (!PyArg_ParseTuple(_args
, ""))
638 _err
= DragPostScroll(_self
->ob_itself
);
639 if (_err
!= noErr
) return PyMac_Error(_err
);
645 static PyObject
*DragObj_UpdateDragHilite(_self
, _args
)
646 DragObjObject
*_self
;
649 PyObject
*_res
= NULL
;
652 if (!PyArg_ParseTuple(_args
, "O&",
653 ResObj_Convert
, &updateRgn
))
655 _err
= UpdateDragHilite(_self
->ob_itself
,
657 if (_err
!= noErr
) return PyMac_Error(_err
);
663 static PyMethodDef DragObj_methods
[] = {
664 {"DisposeDrag", (PyCFunction
)DragObj_DisposeDrag
, 1,
666 {"AddDragItemFlavor", (PyCFunction
)DragObj_AddDragItemFlavor
, 1,
667 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"},
668 {"SetDragItemFlavorData", (PyCFunction
)DragObj_SetDragItemFlavorData
, 1,
669 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"},
670 {"SetDragImage", (PyCFunction
)DragObj_SetDragImage
, 1,
671 "(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"},
672 {"TrackDrag", (PyCFunction
)DragObj_TrackDrag
, 1,
673 "(EventRecord theEvent, RgnHandle theRegion) -> None"},
674 {"CountDragItems", (PyCFunction
)DragObj_CountDragItems
, 1,
675 "() -> (UInt16 numItems)"},
676 {"GetDragItemReferenceNumber", (PyCFunction
)DragObj_GetDragItemReferenceNumber
, 1,
677 "(UInt16 index) -> (ItemReference theItemRef)"},
678 {"CountDragItemFlavors", (PyCFunction
)DragObj_CountDragItemFlavors
, 1,
679 "(ItemReference theItemRef) -> (UInt16 numFlavors)"},
680 {"GetFlavorType", (PyCFunction
)DragObj_GetFlavorType
, 1,
681 "(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"},
682 {"GetFlavorFlags", (PyCFunction
)DragObj_GetFlavorFlags
, 1,
683 "(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"},
684 {"GetFlavorDataSize", (PyCFunction
)DragObj_GetFlavorDataSize
, 1,
685 "(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"},
686 {"GetFlavorData", (PyCFunction
)DragObj_GetFlavorData
, 1,
687 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"},
688 {"GetDragItemBounds", (PyCFunction
)DragObj_GetDragItemBounds
, 1,
689 "(ItemReference theItemRef) -> (Rect itemBounds)"},
690 {"SetDragItemBounds", (PyCFunction
)DragObj_SetDragItemBounds
, 1,
691 "(ItemReference theItemRef, Rect itemBounds) -> None"},
692 {"GetDropLocation", (PyCFunction
)DragObj_GetDropLocation
, 1,
693 "() -> (AEDesc dropLocation)"},
694 {"SetDropLocation", (PyCFunction
)DragObj_SetDropLocation
, 1,
695 "(AEDesc dropLocation) -> None"},
696 {"GetDragAttributes", (PyCFunction
)DragObj_GetDragAttributes
, 1,
697 "() -> (DragAttributes flags)"},
698 {"GetDragMouse", (PyCFunction
)DragObj_GetDragMouse
, 1,
699 "() -> (Point mouse, Point globalPinnedMouse)"},
700 {"SetDragMouse", (PyCFunction
)DragObj_SetDragMouse
, 1,
701 "(Point globalPinnedMouse) -> None"},
702 {"GetDragOrigin", (PyCFunction
)DragObj_GetDragOrigin
, 1,
703 "() -> (Point globalInitialMouse)"},
704 {"GetDragModifiers", (PyCFunction
)DragObj_GetDragModifiers
, 1,
705 "() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"},
706 {"ShowDragHilite", (PyCFunction
)DragObj_ShowDragHilite
, 1,
707 "(RgnHandle hiliteFrame, Boolean inside) -> None"},
708 {"HideDragHilite", (PyCFunction
)DragObj_HideDragHilite
, 1,
710 {"DragPreScroll", (PyCFunction
)DragObj_DragPreScroll
, 1,
711 "(SInt16 dH, SInt16 dV) -> None"},
712 {"DragPostScroll", (PyCFunction
)DragObj_DragPostScroll
, 1,
714 {"UpdateDragHilite", (PyCFunction
)DragObj_UpdateDragHilite
, 1,
715 "(RgnHandle updateRgn) -> None"},
719 PyMethodChain DragObj_chain
= { DragObj_methods
, NULL
};
721 static PyObject
*DragObj_getattr(self
, name
)
725 return Py_FindMethodInChain(&DragObj_chain
, (PyObject
*)self
, name
);
728 #define DragObj_setattr NULL
730 #define DragObj_compare NULL
732 #define DragObj_repr NULL
734 #define DragObj_hash NULL
736 PyTypeObject DragObj_Type
= {
737 PyObject_HEAD_INIT(&PyType_Type
)
739 "DragObj", /*tp_name*/
740 sizeof(DragObjObject
), /*tp_basicsize*/
743 (destructor
) DragObj_dealloc
, /*tp_dealloc*/
745 (getattrfunc
) DragObj_getattr
, /*tp_getattr*/
746 (setattrfunc
) DragObj_setattr
, /*tp_setattr*/
747 (cmpfunc
) DragObj_compare
, /*tp_compare*/
748 (reprfunc
) DragObj_repr
, /*tp_repr*/
749 (PyNumberMethods
*)0, /* tp_as_number */
750 (PySequenceMethods
*)0, /* tp_as_sequence */
751 (PyMappingMethods
*)0, /* tp_as_mapping */
752 (hashfunc
) DragObj_hash
, /*tp_hash*/
755 /* -------------------- End object type DragObj --------------------- */
758 static PyObject
*Drag_NewDrag(_self
, _args
)
762 PyObject
*_res
= NULL
;
764 DragReference theDrag
;
765 if (!PyArg_ParseTuple(_args
, ""))
767 _err
= NewDrag(&theDrag
);
768 if (_err
!= noErr
) return PyMac_Error(_err
);
769 _res
= Py_BuildValue("O&",
770 DragObj_New
, theDrag
);
774 static PyObject
*Drag_GetDragHiliteColor(_self
, _args
)
778 PyObject
*_res
= NULL
;
782 if (!PyArg_ParseTuple(_args
, "O&",
783 WinObj_Convert
, &window
))
785 _err
= GetDragHiliteColor(window
,
787 if (_err
!= noErr
) return PyMac_Error(_err
);
788 _res
= Py_BuildValue("O&",
793 static PyObject
*Drag_WaitMouseMoved(_self
, _args
)
797 PyObject
*_res
= NULL
;
800 if (!PyArg_ParseTuple(_args
, "O&",
801 PyMac_GetPoint
, &initialMouse
))
803 _rv
= WaitMouseMoved(initialMouse
);
804 _res
= Py_BuildValue("b",
809 static PyObject
*Drag_ZoomRects(_self
, _args
)
813 PyObject
*_res
= NULL
;
818 ZoomAcceleration acceleration
;
819 if (!PyArg_ParseTuple(_args
, "O&O&hh",
820 PyMac_GetRect
, &fromRect
,
821 PyMac_GetRect
, &toRect
,
825 _err
= ZoomRects(&fromRect
,
829 if (_err
!= noErr
) return PyMac_Error(_err
);
835 static PyObject
*Drag_ZoomRegion(_self
, _args
)
839 PyObject
*_res
= NULL
;
844 ZoomAcceleration acceleration
;
845 if (!PyArg_ParseTuple(_args
, "O&O&hh",
846 ResObj_Convert
, ®ion
,
847 PyMac_GetPoint
, &zoomDistance
,
851 _err
= ZoomRegion(region
,
855 if (_err
!= noErr
) return PyMac_Error(_err
);
861 static PyObject
*Drag_InstallTrackingHandler(_self
, _args
)
865 PyObject
*_res
= NULL
;
868 WindowPtr theWindow
= NULL
;
871 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
873 Py_INCREF(callback
); /* Cannot decref later, too bad */
874 _err
= InstallTrackingHandler(dragglue_TrackingHandlerUPP
, theWindow
, (void *)callback
);
875 if (_err
!= noErr
) return PyMac_Error(_err
);
881 static PyObject
*Drag_InstallReceiveHandler(_self
, _args
)
885 PyObject
*_res
= NULL
;
888 WindowPtr theWindow
= NULL
;
891 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
893 Py_INCREF(callback
); /* Cannot decref later, too bad */
894 _err
= InstallReceiveHandler(dragglue_ReceiveHandlerUPP
, theWindow
, (void *)callback
);
895 if (_err
!= noErr
) return PyMac_Error(_err
);
901 static PyObject
*Drag_RemoveTrackingHandler(_self
, _args
)
905 PyObject
*_res
= NULL
;
907 WindowPtr theWindow
= NULL
;
910 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
912 _err
= RemoveTrackingHandler(dragglue_TrackingHandlerUPP
, theWindow
);
913 if (_err
!= noErr
) return PyMac_Error(_err
);
919 static PyObject
*Drag_RemoveReceiveHandler(_self
, _args
)
923 PyObject
*_res
= NULL
;
925 WindowPtr theWindow
= NULL
;
928 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
930 _err
= RemoveReceiveHandler(dragglue_ReceiveHandlerUPP
, theWindow
);
931 if (_err
!= noErr
) return PyMac_Error(_err
);
937 static PyMethodDef Drag_methods
[] = {
938 {"NewDrag", (PyCFunction
)Drag_NewDrag
, 1,
939 "() -> (DragReference theDrag)"},
940 {"GetDragHiliteColor", (PyCFunction
)Drag_GetDragHiliteColor
, 1,
941 "(WindowPtr window) -> (RGBColor color)"},
942 {"WaitMouseMoved", (PyCFunction
)Drag_WaitMouseMoved
, 1,
943 "(Point initialMouse) -> (Boolean _rv)"},
944 {"ZoomRects", (PyCFunction
)Drag_ZoomRects
, 1,
945 "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
946 {"ZoomRegion", (PyCFunction
)Drag_ZoomRegion
, 1,
947 "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
948 {"InstallTrackingHandler", (PyCFunction
)Drag_InstallTrackingHandler
, 1,
950 {"InstallReceiveHandler", (PyCFunction
)Drag_InstallReceiveHandler
, 1,
952 {"RemoveTrackingHandler", (PyCFunction
)Drag_RemoveTrackingHandler
, 1,
954 {"RemoveReceiveHandler", (PyCFunction
)Drag_RemoveReceiveHandler
, 1,
962 dragglue_TrackingHandler(DragTrackingMessage theMessage
, WindowPtr theWindow
,
963 void *handlerRefCon
, DragReference theDrag
)
968 args
= Py_BuildValue("hO&O&", theMessage
, DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
971 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
974 fprintf(stderr
, "Drag: Exception in TrackingHandler\n");
981 PyArg_Parse(rv
, "l", &i
);
987 dragglue_ReceiveHandler(WindowPtr theWindow
, void *handlerRefCon
,
988 DragReference theDrag
)
993 args
= Py_BuildValue("O&O&", DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
996 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
999 fprintf(stderr
, "Drag: Exception in ReceiveHandler\n");
1003 if ( rv
== Py_None
)
1006 PyArg_Parse(rv
, "l", &i
);
1012 dragglue_SendData(FlavorType theType
, void *dragSendRefCon
,
1013 ItemReference theItem
, DragReference theDrag
)
1015 DragObjObject
*self
= (DragObjObject
*)dragSendRefCon
;
1016 PyObject
*args
, *rv
;
1019 if ( self
->sendproc
== NULL
)
1021 args
= Py_BuildValue("O&l", PyMac_BuildOSType
, theType
, theItem
);
1024 rv
= PyEval_CallObject(self
->sendproc
, args
);
1027 fprintf(stderr
, "Drag: Exception in SendDataHandler\n");
1031 if ( rv
== Py_None
)
1034 PyArg_Parse(rv
, "l", &i
);
1041 dragglue_Input(Point
*mouse
, short *modifiers
,
1042 void *dragSendRefCon
, DragReference theDrag
)
1048 dragglue_Drawing(xxxx
1049 void *dragSendRefCon
, DragReference theDrag
)
1065 m
= Py_InitModule("Drag", Drag_methods
);
1066 d
= PyModule_GetDict(m
);
1067 Drag_Error
= PyMac_GetOSErrException();
1068 if (Drag_Error
== NULL
||
1069 PyDict_SetItemString(d
, "Error", Drag_Error
) != 0)
1070 Py_FatalError("can't initialize Drag.Error");
1071 DragObj_Type
.ob_type
= &PyType_Type
;
1072 Py_INCREF(&DragObj_Type
);
1073 if (PyDict_SetItemString(d
, "DragObjType", (PyObject
*)&DragObj_Type
) != 0)
1074 Py_FatalError("can't initialize DragObjType");
1076 dragglue_TrackingHandlerUPP
= NewDragTrackingHandlerProc(dragglue_TrackingHandler
);
1077 dragglue_ReceiveHandlerUPP
= NewDragReceiveHandlerProc(dragglue_ReceiveHandler
);
1078 dragglue_SendDataUPP
= NewDragSendDataProc(dragglue_SendData
);
1080 dragglue_InputUPP
= NewDragInputProc(dragglue_Input
);
1081 dragglue_DrawingUPP
= NewDragDrawingProc(dragglue_Drawing
);
1087 /* ======================== End module Drag ========================= */