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