_Dragmodule.c revision f955784f0cfeecb94d3f2ade83a5ea548391f74b
1
2/* ========================== Module _Drag ========================== */
3
4#include "Python.h"
5
6
7
8#ifdef _WIN32
9#include "pywintoolbox.h"
10#else
11#include "macglue.h"
12#include "pymactoolbox.h"
13#endif
14
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)
21
22
23#ifdef WITHOUT_FRAMEWORKS
24#include <Drag.h>
25#else
26#include <Carbon/Carbon.h>
27#endif
28
29/* Callback glue routines */
30DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
31DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
32DragSendDataUPP dragglue_SendDataUPP;
33#if 0
34DragInputUPP dragglue_InputUPP;
35DragDrawingUPP dragglue_DrawingUPP;
36#endif
37
38#ifdef USE_TOOLBOX_OBJECT_GLUE
39extern PyObject *_DragObj_New(DragRef);
40extern int _DragObj_Convert(PyObject *, DragRef *);
41
42#define DragObj_New _DragObj_New
43#define DragObj_Convert _DragObj_Convert
44#endif
45
46static PyObject *Drag_Error;
47
48/* ---------------------- Object type DragObj ----------------------- */
49
50PyTypeObject DragObj_Type;
51
52#define DragObj_Check(x) ((x)->ob_type == &DragObj_Type || PyObject_TypeCheck((x), &DragObj_Type))
53
54typedef struct DragObjObject {
55	PyObject_HEAD
56	DragRef ob_itself;
57	PyObject *sendproc;
58} DragObjObject;
59
60PyObject *DragObj_New(DragRef itself)
61{
62	DragObjObject *it;
63	if (itself == NULL) {
64						PyErr_SetString(Drag_Error,"Cannot create null Drag");
65						return NULL;
66					}
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;
72}
73int DragObj_Convert(PyObject *v, DragRef *p_itself)
74{
75	if (!DragObj_Check(v))
76	{
77		PyErr_SetString(PyExc_TypeError, "DragObj required");
78		return 0;
79	}
80	*p_itself = ((DragObjObject *)v)->ob_itself;
81	return 1;
82}
83
84static void DragObj_dealloc(DragObjObject *self)
85{
86	Py_XDECREF(self->sendproc);
87	PyObject_Del(self);
88}
89
90static PyObject *DragObj_DisposeDrag(DragObjObject *_self, PyObject *_args)
91{
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;
104}
105
106static PyObject *DragObj_AddDragItemFlavor(DragObjObject *_self, PyObject *_args)
107{
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;
135}
136
137static PyObject *DragObj_SetDragItemFlavorData(DragObjObject *_self, PyObject *_args)
138{
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;
166}
167
168static PyObject *DragObj_SetDragImage(DragObjObject *_self, PyObject *_args)
169{
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;
194}
195
196static PyObject *DragObj_ChangeDragBehaviors(DragObjObject *_self, PyObject *_args)
197{
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;
216}
217
218static PyObject *DragObj_TrackDrag(DragObjObject *_self, PyObject *_args)
219{
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;
238}
239
240static PyObject *DragObj_CountDragItems(DragObjObject *_self, PyObject *_args)
241{
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;
256}
257
258static PyObject *DragObj_GetDragItemReferenceNumber(DragObjObject *_self, PyObject *_args)
259{
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;
277}
278
279static PyObject *DragObj_CountDragItemFlavors(DragObjObject *_self, PyObject *_args)
280{
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;
298}
299
300static PyObject *DragObj_GetFlavorType(DragObjObject *_self, PyObject *_args)
301{
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;
322}
323
324static PyObject *DragObj_GetFlavorFlags(DragObjObject *_self, PyObject *_args)
325{
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;
346}
347
348static PyObject *DragObj_GetFlavorDataSize(DragObjObject *_self, PyObject *_args)
349{
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;
370}
371
372static PyObject *DragObj_GetFlavorData(DragObjObject *_self, PyObject *_args)
373{
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)
392	{
393		PyErr_NoMemory();
394		goto dataPtr__error__;
395	}
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;
408}
409
410static PyObject *DragObj_GetDragItemBounds(DragObjObject *_self, PyObject *_args)
411{
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;
429}
430
431static PyObject *DragObj_SetDragItemBounds(DragObjObject *_self, PyObject *_args)
432{
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;
451}
452
453static PyObject *DragObj_GetDropLocation(DragObjObject *_self, PyObject *_args)
454{
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;
469}
470
471static PyObject *DragObj_SetDropLocation(DragObjObject *_self, PyObject *_args)
472{
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;
488}
489
490static PyObject *DragObj_GetDragAttributes(DragObjObject *_self, PyObject *_args)
491{
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;
506}
507
508static PyObject *DragObj_GetDragMouse(DragObjObject *_self, PyObject *_args)
509{
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;
527}
528
529static PyObject *DragObj_SetDragMouse(DragObjObject *_self, PyObject *_args)
530{
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;
546}
547
548static PyObject *DragObj_GetDragOrigin(DragObjObject *_self, PyObject *_args)
549{
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;
564}
565
566static PyObject *DragObj_GetDragModifiers(DragObjObject *_self, PyObject *_args)
567{
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;
588}
589
590static PyObject *DragObj_ShowDragHilite(DragObjObject *_self, PyObject *_args)
591{
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;
610}
611
612static PyObject *DragObj_HideDragHilite(DragObjObject *_self, PyObject *_args)
613{
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;
626}
627
628static PyObject *DragObj_DragPreScroll(DragObjObject *_self, PyObject *_args)
629{
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,
642	                     dH,
643	                     dV);
644	if (_err != noErr) return PyMac_Error(_err);
645	Py_INCREF(Py_None);
646	_res = Py_None;
647	return _res;
648}
649
650static PyObject *DragObj_DragPostScroll(DragObjObject *_self, PyObject *_args)
651{
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;
664}
665
666static PyObject *DragObj_UpdateDragHilite(DragObjObject *_self, PyObject *_args)
667{
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;
683}
684
685static 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}
741};
742
743#define DragObj_getsetlist NULL
744
745
746#define DragObj_compare NULL
747
748#define DragObj_repr NULL
749
750#define DragObj_hash NULL
751#define DragObj_tp_init 0
752
753#define DragObj_tp_alloc PyType_GenericAlloc
754
755static PyObject *DragObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
756{
757	PyObject *self;
758	DragRef itself;
759	char *kw[] = {"itself", 0};
760
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;
765}
766
767#define DragObj_tp_free PyObject_Del
768
769
770PyTypeObject 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 */
812};
813
814/* -------------------- End object type DragObj --------------------- */
815
816
817static PyObject *Drag_NewDrag(PyObject *_self, PyObject *_args)
818{
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;
832}
833
834static PyObject *Drag_GetDragHiliteColor(PyObject *_self, PyObject *_args)
835{
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;
852}
853
854static PyObject *Drag_WaitMouseMoved(PyObject *_self, PyObject *_args)
855{
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;
869}
870
871static PyObject *Drag_ZoomRects(PyObject *_self, PyObject *_args)
872{
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;
896}
897
898static PyObject *Drag_ZoomRegion(PyObject *_self, PyObject *_args)
899{
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;
923}
924
925static PyObject *Drag_InstallTrackingHandler(PyObject *_self, PyObject *_args)
926{
927	PyObject *_res = NULL;
928
929	    PyObject *callback;
930	    WindowPtr theWindow = NULL;
931	    OSErr _err;
932
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;
941
942}
943
944static PyObject *Drag_InstallReceiveHandler(PyObject *_self, PyObject *_args)
945{
946	PyObject *_res = NULL;
947
948	    PyObject *callback;
949	    WindowPtr theWindow = NULL;
950	    OSErr _err;
951
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;
960
961}
962
963static PyObject *Drag_RemoveTrackingHandler(PyObject *_self, PyObject *_args)
964{
965	PyObject *_res = NULL;
966
967	    WindowPtr theWindow = NULL;
968	    OSErr _err;
969
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;
977
978}
979
980static PyObject *Drag_RemoveReceiveHandler(PyObject *_self, PyObject *_args)
981{
982	PyObject *_res = NULL;
983
984	    WindowPtr theWindow = NULL;
985	    OSErr _err;
986
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;
994
995}
996
997static 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}
1017};
1018
1019
1020
1021static pascal OSErr
1022dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
1023                         void *handlerRefCon, DragReference theDrag)
1024{
1025	PyObject *args, *rv;
1026	int i;
1027
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;
1037	}
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;
1045}
1046
1047static pascal OSErr
1048dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
1049                        DragReference theDrag)
1050{
1051	PyObject *args, *rv;
1052	int i;
1053
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;
1063	}
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;
1071}
1072
1073static pascal OSErr
1074dragglue_SendData(FlavorType theType, void *dragSendRefCon,
1075                      ItemReference theItem, DragReference theDrag)
1076{
1077	DragObjObject *self = (DragObjObject *)dragSendRefCon;
1078	PyObject *args, *rv;
1079	int i;
1080
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;
1092	}
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;
1100}
1101
1102#if 0
1103static pascal OSErr
1104dragglue_Input(Point *mouse, short *modifiers,
1105                   void *dragSendRefCon, DragReference theDrag)
1106{
1107    return 0;
1108}
1109
1110static pascal OSErr
1111dragglue_Drawing(xxxx
1112                   void *dragSendRefCon, DragReference theDrag)
1113{
1114    return 0;
1115}
1116#endif
1117
1118
1119
1120void init_Drag(void)
1121{
1122	PyObject *m;
1123	PyObject *d;
1124
1125
1126
1127		PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
1128		PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
1129
1130
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	Py_INCREF(&DragObj_Type);
1139	PyModule_AddObject(m, "DragObj", (PyObject *)&DragObj_Type);
1140	/* Backward-compatible name */
1141	Py_INCREF(&DragObj_Type);
1142	PyModule_AddObject(m, "DragObjType", (PyObject *)&DragObj_Type);
1143
1144	dragglue_TrackingHandlerUPP = NewDragTrackingHandlerUPP(dragglue_TrackingHandler);
1145	dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerUPP(dragglue_ReceiveHandler);
1146	dragglue_SendDataUPP = NewDragSendDataUPP(dragglue_SendData);
1147#if 0
1148	dragglue_InputUPP = NewDragInputUPP(dragglue_Input);
1149	dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
1150#endif
1151
1152
1153}
1154
1155/* ======================== End module _Drag ======================== */
1156
1157