2 /* ========================== Module Drag =========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
14 #include <Carbon/Carbon.h>
17 /* Callback glue routines */
18 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP
;
19 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP
;
20 DragSendDataUPP dragglue_SendDataUPP
;
22 DragInputUPP dragglue_InputUPP
;
23 DragDrawingUPP dragglue_DrawingUPP
;
26 #ifdef USE_TOOLBOX_OBJECT_GLUE
27 extern PyObject
*_DragObj_New(DragRef
);
28 extern int _DragObj_Convert(PyObject
*, DragRef
*);
30 #define DragObj_New _DragObj_New
31 #define DragObj_Convert _DragObj_Convert
34 static PyObject
*Drag_Error
;
36 /* ---------------------- Object type DragObj ----------------------- */
38 PyTypeObject DragObj_Type
;
40 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
42 typedef struct DragObjObject
{
48 PyObject
*DragObj_New(DragRef itself
)
52 PyErr_SetString(Drag_Error
,"Cannot create null Drag");
55 it
= PyObject_NEW(DragObjObject
, &DragObj_Type
);
56 if (it
== NULL
) return NULL
;
57 it
->ob_itself
= itself
;
59 return (PyObject
*)it
;
61 DragObj_Convert(PyObject
*v
, DragRef
*p_itself
)
63 if (!DragObj_Check(v
))
65 PyErr_SetString(PyExc_TypeError
, "DragObj required");
68 *p_itself
= ((DragObjObject
*)v
)->ob_itself
;
72 static void DragObj_dealloc(DragObjObject
*self
)
74 Py_XDECREF(self
->sendproc
);
78 static PyObject
*DragObj_DisposeDrag(DragObjObject
*_self
, PyObject
*_args
)
80 PyObject
*_res
= NULL
;
82 if (!PyArg_ParseTuple(_args
, ""))
84 _err
= DisposeDrag(_self
->ob_itself
);
85 if (_err
!= noErr
) return PyMac_Error(_err
);
91 static PyObject
*DragObj_AddDragItemFlavor(DragObjObject
*_self
, PyObject
*_args
)
93 PyObject
*_res
= NULL
;
95 ItemReference theItemRef
;
99 int dataPtr__in_len__
;
100 FlavorFlags theFlags
;
101 if (!PyArg_ParseTuple(_args
, "lO&z#l",
103 PyMac_GetOSType
, &theType
,
104 &dataPtr__in__
, &dataPtr__in_len__
,
107 dataPtr__len__
= dataPtr__in_len__
;
108 _err
= AddDragItemFlavor(_self
->ob_itself
,
111 dataPtr__in__
, dataPtr__len__
,
113 if (_err
!= noErr
) return PyMac_Error(_err
);
120 static PyObject
*DragObj_SetDragItemFlavorData(DragObjObject
*_self
, PyObject
*_args
)
122 PyObject
*_res
= NULL
;
124 ItemReference theItemRef
;
128 int dataPtr__in_len__
;
130 if (!PyArg_ParseTuple(_args
, "lO&z#l",
132 PyMac_GetOSType
, &theType
,
133 &dataPtr__in__
, &dataPtr__in_len__
,
136 dataPtr__len__
= dataPtr__in_len__
;
137 _err
= SetDragItemFlavorData(_self
->ob_itself
,
140 dataPtr__in__
, dataPtr__len__
,
142 if (_err
!= noErr
) return PyMac_Error(_err
);
149 static PyObject
*DragObj_SetDragImage(DragObjObject
*_self
, PyObject
*_args
)
151 PyObject
*_res
= NULL
;
153 PixMapHandle imagePixMap
;
156 DragImageFlags theImageFlags
;
157 if (!PyArg_ParseTuple(_args
, "O&O&O&l",
158 ResObj_Convert
, &imagePixMap
,
159 ResObj_Convert
, &imageRgn
,
160 PyMac_GetPoint
, &imageOffsetPt
,
163 _err
= SetDragImage(_self
->ob_itself
,
168 if (_err
!= noErr
) return PyMac_Error(_err
);
174 static PyObject
*DragObj_ChangeDragBehaviors(DragObjObject
*_self
, PyObject
*_args
)
176 PyObject
*_res
= NULL
;
178 DragBehaviors inBehaviorsToSet
;
179 DragBehaviors inBehaviorsToClear
;
180 if (!PyArg_ParseTuple(_args
, "ll",
182 &inBehaviorsToClear
))
184 _err
= ChangeDragBehaviors(_self
->ob_itself
,
187 if (_err
!= noErr
) return PyMac_Error(_err
);
193 static PyObject
*DragObj_TrackDrag(DragObjObject
*_self
, PyObject
*_args
)
195 PyObject
*_res
= NULL
;
197 EventRecord theEvent
;
199 if (!PyArg_ParseTuple(_args
, "O&O&",
200 PyMac_GetEventRecord
, &theEvent
,
201 ResObj_Convert
, &theRegion
))
203 _err
= TrackDrag(_self
->ob_itself
,
206 if (_err
!= noErr
) return PyMac_Error(_err
);
212 static PyObject
*DragObj_CountDragItems(DragObjObject
*_self
, PyObject
*_args
)
214 PyObject
*_res
= NULL
;
217 if (!PyArg_ParseTuple(_args
, ""))
219 _err
= CountDragItems(_self
->ob_itself
,
221 if (_err
!= noErr
) return PyMac_Error(_err
);
222 _res
= Py_BuildValue("H",
227 static PyObject
*DragObj_GetDragItemReferenceNumber(DragObjObject
*_self
, PyObject
*_args
)
229 PyObject
*_res
= NULL
;
232 ItemReference theItemRef
;
233 if (!PyArg_ParseTuple(_args
, "H",
236 _err
= GetDragItemReferenceNumber(_self
->ob_itself
,
239 if (_err
!= noErr
) return PyMac_Error(_err
);
240 _res
= Py_BuildValue("l",
245 static PyObject
*DragObj_CountDragItemFlavors(DragObjObject
*_self
, PyObject
*_args
)
247 PyObject
*_res
= NULL
;
249 ItemReference theItemRef
;
251 if (!PyArg_ParseTuple(_args
, "l",
254 _err
= CountDragItemFlavors(_self
->ob_itself
,
257 if (_err
!= noErr
) return PyMac_Error(_err
);
258 _res
= Py_BuildValue("H",
263 static PyObject
*DragObj_GetFlavorType(DragObjObject
*_self
, PyObject
*_args
)
265 PyObject
*_res
= NULL
;
267 ItemReference theItemRef
;
270 if (!PyArg_ParseTuple(_args
, "lH",
274 _err
= GetFlavorType(_self
->ob_itself
,
278 if (_err
!= noErr
) return PyMac_Error(_err
);
279 _res
= Py_BuildValue("O&",
280 PyMac_BuildOSType
, theType
);
284 static PyObject
*DragObj_GetFlavorFlags(DragObjObject
*_self
, PyObject
*_args
)
286 PyObject
*_res
= NULL
;
288 ItemReference theItemRef
;
290 FlavorFlags theFlags
;
291 if (!PyArg_ParseTuple(_args
, "lO&",
293 PyMac_GetOSType
, &theType
))
295 _err
= GetFlavorFlags(_self
->ob_itself
,
299 if (_err
!= noErr
) return PyMac_Error(_err
);
300 _res
= Py_BuildValue("l",
305 static PyObject
*DragObj_GetFlavorDataSize(DragObjObject
*_self
, PyObject
*_args
)
307 PyObject
*_res
= NULL
;
309 ItemReference theItemRef
;
312 if (!PyArg_ParseTuple(_args
, "lO&",
314 PyMac_GetOSType
, &theType
))
316 _err
= GetFlavorDataSize(_self
->ob_itself
,
320 if (_err
!= noErr
) return PyMac_Error(_err
);
321 _res
= Py_BuildValue("l",
326 static PyObject
*DragObj_GetFlavorData(DragObjObject
*_self
, PyObject
*_args
)
328 PyObject
*_res
= NULL
;
330 ItemReference theItemRef
;
332 char *dataPtr__out__
;
334 int dataPtr__in_len__
;
336 if (!PyArg_ParseTuple(_args
, "lO&il",
338 PyMac_GetOSType
, &theType
,
342 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
345 goto dataPtr__error__
;
347 dataPtr__len__
= dataPtr__in_len__
;
348 _err
= GetFlavorData(_self
->ob_itself
,
351 dataPtr__out__
, &dataPtr__len__
,
353 if (_err
!= noErr
) return PyMac_Error(_err
);
354 _res
= Py_BuildValue("s#",
355 dataPtr__out__
, (int)dataPtr__len__
);
356 free(dataPtr__out__
);
361 static PyObject
*DragObj_GetDragItemBounds(DragObjObject
*_self
, PyObject
*_args
)
363 PyObject
*_res
= NULL
;
365 ItemReference theItemRef
;
367 if (!PyArg_ParseTuple(_args
, "l",
370 _err
= GetDragItemBounds(_self
->ob_itself
,
373 if (_err
!= noErr
) return PyMac_Error(_err
);
374 _res
= Py_BuildValue("O&",
375 PyMac_BuildRect
, &itemBounds
);
379 static PyObject
*DragObj_SetDragItemBounds(DragObjObject
*_self
, PyObject
*_args
)
381 PyObject
*_res
= NULL
;
383 ItemReference theItemRef
;
385 if (!PyArg_ParseTuple(_args
, "lO&",
387 PyMac_GetRect
, &itemBounds
))
389 _err
= SetDragItemBounds(_self
->ob_itself
,
392 if (_err
!= noErr
) return PyMac_Error(_err
);
398 static PyObject
*DragObj_GetDropLocation(DragObjObject
*_self
, PyObject
*_args
)
400 PyObject
*_res
= NULL
;
403 if (!PyArg_ParseTuple(_args
, ""))
405 _err
= GetDropLocation(_self
->ob_itself
,
407 if (_err
!= noErr
) return PyMac_Error(_err
);
408 _res
= Py_BuildValue("O&",
409 AEDesc_New
, &dropLocation
);
413 static PyObject
*DragObj_SetDropLocation(DragObjObject
*_self
, PyObject
*_args
)
415 PyObject
*_res
= NULL
;
418 if (!PyArg_ParseTuple(_args
, "O&",
419 AEDesc_Convert
, &dropLocation
))
421 _err
= SetDropLocation(_self
->ob_itself
,
423 if (_err
!= noErr
) return PyMac_Error(_err
);
429 static PyObject
*DragObj_GetDragAttributes(DragObjObject
*_self
, PyObject
*_args
)
431 PyObject
*_res
= NULL
;
433 DragAttributes flags
;
434 if (!PyArg_ParseTuple(_args
, ""))
436 _err
= GetDragAttributes(_self
->ob_itself
,
438 if (_err
!= noErr
) return PyMac_Error(_err
);
439 _res
= Py_BuildValue("l",
444 static PyObject
*DragObj_GetDragMouse(DragObjObject
*_self
, PyObject
*_args
)
446 PyObject
*_res
= NULL
;
449 Point globalPinnedMouse
;
450 if (!PyArg_ParseTuple(_args
, ""))
452 _err
= GetDragMouse(_self
->ob_itself
,
455 if (_err
!= noErr
) return PyMac_Error(_err
);
456 _res
= Py_BuildValue("O&O&",
457 PyMac_BuildPoint
, mouse
,
458 PyMac_BuildPoint
, globalPinnedMouse
);
462 static PyObject
*DragObj_SetDragMouse(DragObjObject
*_self
, PyObject
*_args
)
464 PyObject
*_res
= NULL
;
466 Point globalPinnedMouse
;
467 if (!PyArg_ParseTuple(_args
, "O&",
468 PyMac_GetPoint
, &globalPinnedMouse
))
470 _err
= SetDragMouse(_self
->ob_itself
,
472 if (_err
!= noErr
) return PyMac_Error(_err
);
478 static PyObject
*DragObj_GetDragOrigin(DragObjObject
*_self
, PyObject
*_args
)
480 PyObject
*_res
= NULL
;
482 Point globalInitialMouse
;
483 if (!PyArg_ParseTuple(_args
, ""))
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
);
493 static PyObject
*DragObj_GetDragModifiers(DragObjObject
*_self
, PyObject
*_args
)
495 PyObject
*_res
= NULL
;
498 SInt16 mouseDownModifiers
;
499 SInt16 mouseUpModifiers
;
500 if (!PyArg_ParseTuple(_args
, ""))
502 _err
= GetDragModifiers(_self
->ob_itself
,
506 if (_err
!= noErr
) return PyMac_Error(_err
);
507 _res
= Py_BuildValue("hhh",
514 static PyObject
*DragObj_ShowDragHilite(DragObjObject
*_self
, PyObject
*_args
)
516 PyObject
*_res
= NULL
;
518 RgnHandle hiliteFrame
;
520 if (!PyArg_ParseTuple(_args
, "O&b",
521 ResObj_Convert
, &hiliteFrame
,
524 _err
= ShowDragHilite(_self
->ob_itself
,
527 if (_err
!= noErr
) return PyMac_Error(_err
);
533 static PyObject
*DragObj_HideDragHilite(DragObjObject
*_self
, PyObject
*_args
)
535 PyObject
*_res
= NULL
;
537 if (!PyArg_ParseTuple(_args
, ""))
539 _err
= HideDragHilite(_self
->ob_itself
);
540 if (_err
!= noErr
) return PyMac_Error(_err
);
546 static PyObject
*DragObj_DragPreScroll(DragObjObject
*_self
, PyObject
*_args
)
548 PyObject
*_res
= NULL
;
552 if (!PyArg_ParseTuple(_args
, "hh",
556 _err
= DragPreScroll(_self
->ob_itself
,
559 if (_err
!= noErr
) return PyMac_Error(_err
);
565 static PyObject
*DragObj_DragPostScroll(DragObjObject
*_self
, PyObject
*_args
)
567 PyObject
*_res
= NULL
;
569 if (!PyArg_ParseTuple(_args
, ""))
571 _err
= DragPostScroll(_self
->ob_itself
);
572 if (_err
!= noErr
) return PyMac_Error(_err
);
578 static PyObject
*DragObj_UpdateDragHilite(DragObjObject
*_self
, PyObject
*_args
)
580 PyObject
*_res
= NULL
;
583 if (!PyArg_ParseTuple(_args
, "O&",
584 ResObj_Convert
, &updateRgn
))
586 _err
= UpdateDragHilite(_self
->ob_itself
,
588 if (_err
!= noErr
) return PyMac_Error(_err
);
594 static PyMethodDef DragObj_methods
[] = {
595 {"DisposeDrag", (PyCFunction
)DragObj_DisposeDrag
, 1,
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,
643 {"DragPreScroll", (PyCFunction
)DragObj_DragPreScroll
, 1,
644 "(SInt16 dH, SInt16 dV) -> None"},
645 {"DragPostScroll", (PyCFunction
)DragObj_DragPostScroll
, 1,
647 {"UpdateDragHilite", (PyCFunction
)DragObj_UpdateDragHilite
, 1,
648 "(RgnHandle updateRgn) -> None"},
652 PyMethodChain DragObj_chain
= { DragObj_methods
, NULL
};
654 static PyObject
*DragObj_getattr(DragObjObject
*self
, char *name
)
656 return Py_FindMethodInChain(&DragObj_chain
, (PyObject
*)self
, name
);
659 #define DragObj_setattr NULL
661 #define DragObj_compare NULL
663 #define DragObj_repr NULL
665 #define DragObj_hash NULL
667 PyTypeObject DragObj_Type
= {
668 PyObject_HEAD_INIT(&PyType_Type
)
670 "DragObj", /*tp_name*/
671 sizeof(DragObjObject
), /*tp_basicsize*/
674 (destructor
) DragObj_dealloc
, /*tp_dealloc*/
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*/
686 /* -------------------- End object type DragObj --------------------- */
689 static PyObject
*Drag_NewDrag(PyObject
*_self
, PyObject
*_args
)
691 PyObject
*_res
= NULL
;
694 if (!PyArg_ParseTuple(_args
, ""))
696 _err
= NewDrag(&theDrag
);
697 if (_err
!= noErr
) return PyMac_Error(_err
);
698 _res
= Py_BuildValue("O&",
699 DragObj_New
, theDrag
);
703 static PyObject
*Drag_GetDragHiliteColor(PyObject
*_self
, PyObject
*_args
)
705 PyObject
*_res
= NULL
;
709 if (!PyArg_ParseTuple(_args
, "O&",
710 WinObj_Convert
, &window
))
712 _err
= GetDragHiliteColor(window
,
714 if (_err
!= noErr
) return PyMac_Error(_err
);
715 _res
= Py_BuildValue("O&",
720 static PyObject
*Drag_WaitMouseMoved(PyObject
*_self
, PyObject
*_args
)
722 PyObject
*_res
= NULL
;
725 if (!PyArg_ParseTuple(_args
, "O&",
726 PyMac_GetPoint
, &initialMouse
))
728 _rv
= WaitMouseMoved(initialMouse
);
729 _res
= Py_BuildValue("b",
734 static PyObject
*Drag_ZoomRects(PyObject
*_self
, PyObject
*_args
)
736 PyObject
*_res
= NULL
;
741 ZoomAcceleration acceleration
;
742 if (!PyArg_ParseTuple(_args
, "O&O&hh",
743 PyMac_GetRect
, &fromRect
,
744 PyMac_GetRect
, &toRect
,
748 _err
= ZoomRects(&fromRect
,
752 if (_err
!= noErr
) return PyMac_Error(_err
);
758 static PyObject
*Drag_ZoomRegion(PyObject
*_self
, PyObject
*_args
)
760 PyObject
*_res
= NULL
;
765 ZoomAcceleration acceleration
;
766 if (!PyArg_ParseTuple(_args
, "O&O&hh",
767 ResObj_Convert
, ®ion
,
768 PyMac_GetPoint
, &zoomDistance
,
772 _err
= ZoomRegion(region
,
776 if (_err
!= noErr
) return PyMac_Error(_err
);
782 static PyObject
*Drag_InstallTrackingHandler(PyObject
*_self
, PyObject
*_args
)
784 PyObject
*_res
= NULL
;
787 WindowPtr theWindow
= NULL
;
790 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
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
);
800 static PyObject
*Drag_InstallReceiveHandler(PyObject
*_self
, PyObject
*_args
)
802 PyObject
*_res
= NULL
;
805 WindowPtr theWindow
= NULL
;
808 if ( !PyArg_ParseTuple(_args
, "O|O&", &callback
, WinObj_Convert
, &theWindow
) )
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
);
818 static PyObject
*Drag_RemoveTrackingHandler(PyObject
*_self
, PyObject
*_args
)
820 PyObject
*_res
= NULL
;
822 WindowPtr theWindow
= NULL
;
825 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
827 _err
= RemoveTrackingHandler(dragglue_TrackingHandlerUPP
, theWindow
);
828 if (_err
!= noErr
) return PyMac_Error(_err
);
834 static PyObject
*Drag_RemoveReceiveHandler(PyObject
*_self
, PyObject
*_args
)
836 PyObject
*_res
= NULL
;
838 WindowPtr theWindow
= NULL
;
841 if ( !PyArg_ParseTuple(_args
, "|O&", WinObj_Convert
, &theWindow
) )
843 _err
= RemoveReceiveHandler(dragglue_ReceiveHandlerUPP
, theWindow
);
844 if (_err
!= noErr
) return PyMac_Error(_err
);
850 static PyMethodDef Drag_methods
[] = {
851 {"NewDrag", (PyCFunction
)Drag_NewDrag
, 1,
852 "() -> (DragRef theDrag)"},
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,
863 {"InstallReceiveHandler", (PyCFunction
)Drag_InstallReceiveHandler
, 1,
865 {"RemoveTrackingHandler", (PyCFunction
)Drag_RemoveTrackingHandler
, 1,
867 {"RemoveReceiveHandler", (PyCFunction
)Drag_RemoveReceiveHandler
, 1,
875 dragglue_TrackingHandler(DragTrackingMessage theMessage
, WindowPtr theWindow
,
876 void *handlerRefCon
, DragReference theDrag
)
881 args
= Py_BuildValue("hO&O&", theMessage
, DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
884 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
887 fprintf(stderr
, "Drag: Exception in TrackingHandler\n");
894 PyArg_Parse(rv
, "l", &i
);
900 dragglue_ReceiveHandler(WindowPtr theWindow
, void *handlerRefCon
,
901 DragReference theDrag
)
906 args
= Py_BuildValue("O&O&", DragObj_New
, theDrag
, WinObj_WhichWindow
, theWindow
);
909 rv
= PyEval_CallObject((PyObject
*)handlerRefCon
, args
);
912 fprintf(stderr
, "Drag: Exception in ReceiveHandler\n");
919 PyArg_Parse(rv
, "l", &i
);
925 dragglue_SendData(FlavorType theType
, void *dragSendRefCon
,
926 ItemReference theItem
, DragReference theDrag
)
928 DragObjObject
*self
= (DragObjObject
*)dragSendRefCon
;
932 if ( self
->sendproc
== NULL
)
934 args
= Py_BuildValue("O&l", PyMac_BuildOSType
, theType
, theItem
);
937 rv
= PyEval_CallObject(self
->sendproc
, args
);
940 fprintf(stderr
, "Drag: Exception in SendDataHandler\n");
947 PyArg_Parse(rv
, "l", &i
);
954 dragglue_Input(Point
*mouse
, short *modifiers
,
955 void *dragSendRefCon
, DragReference theDrag
)
961 dragglue_Drawing(xxxx
962 void *dragSendRefCon
, DragReference theDrag
)
977 PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef
, DragObj_New
);
978 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef
, DragObj_Convert
);
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)
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");
992 dragglue_TrackingHandlerUPP
= NewDragTrackingHandlerUPP(dragglue_TrackingHandler
);
993 dragglue_ReceiveHandlerUPP
= NewDragReceiveHandlerUPP(dragglue_ReceiveHandler
);
994 dragglue_SendDataUPP
= NewDragSendDataUPP(dragglue_SendData
);
996 dragglue_InputUPP
= NewDragInputUPP(dragglue_Input
);
997 dragglue_DrawingUPP
= NewDragDrawingUPP(dragglue_Drawing
);
1003 /* ======================== End module Drag ========================= */