This is (hopefully) last checkin before releasing 2.1c2 -- get rid of
[python/dscho.git] / Mac / Modules / drag / Dragmodule.c
blobfa6c2d9dbcdb8b847dd422ceddea3604e436bb2d
2 /* ========================== Module Drag =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Drag.h>
13 /* Callback glue routines */
14 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
15 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
16 DragSendDataUPP dragglue_SendDataUPP;
17 #if 0
18 DragInputUPP dragglue_InputUPP;
19 DragDrawingUPP dragglue_DrawingUPP;
20 #endif
22 static PyObject *Drag_Error;
24 /* ---------------------- Object type DragObj ----------------------- */
26 PyTypeObject DragObj_Type;
28 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
30 typedef struct DragObjObject {
31 PyObject_HEAD
32 DragRef ob_itself;
33 PyObject *sendproc;
34 } DragObjObject;
36 PyObject *DragObj_New(itself)
37 DragRef itself;
39 DragObjObject *it;
40 if (itself == NULL) {
41 PyErr_SetString(Drag_Error,"Cannot create null Drag");
42 return NULL;
44 it = PyObject_NEW(DragObjObject, &DragObj_Type);
45 if (it == NULL) return NULL;
46 it->ob_itself = itself;
47 it->sendproc = NULL;
48 return (PyObject *)it;
50 DragObj_Convert(v, p_itself)
51 PyObject *v;
52 DragRef *p_itself;
54 if (!DragObj_Check(v))
56 PyErr_SetString(PyExc_TypeError, "DragObj required");
57 return 0;
59 *p_itself = ((DragObjObject *)v)->ob_itself;
60 return 1;
63 static void DragObj_dealloc(self)
64 DragObjObject *self;
66 Py_XDECREF(self->sendproc);
67 PyMem_DEL(self);
70 static PyObject *DragObj_DisposeDrag(_self, _args)
71 DragObjObject *_self;
72 PyObject *_args;
74 PyObject *_res = NULL;
75 OSErr _err;
76 if (!PyArg_ParseTuple(_args, ""))
77 return NULL;
78 _err = DisposeDrag(_self->ob_itself);
79 if (_err != noErr) return PyMac_Error(_err);
80 Py_INCREF(Py_None);
81 _res = Py_None;
82 return _res;
85 static PyObject *DragObj_AddDragItemFlavor(_self, _args)
86 DragObjObject *_self;
87 PyObject *_args;
89 PyObject *_res = NULL;
90 OSErr _err;
91 ItemReference theItemRef;
92 FlavorType theType;
93 char *dataPtr__in__;
94 long dataPtr__len__;
95 int dataPtr__in_len__;
96 FlavorFlags theFlags;
97 if (!PyArg_ParseTuple(_args, "lO&z#l",
98 &theItemRef,
99 PyMac_GetOSType, &theType,
100 &dataPtr__in__, &dataPtr__in_len__,
101 &theFlags))
102 return NULL;
103 dataPtr__len__ = dataPtr__in_len__;
104 _err = AddDragItemFlavor(_self->ob_itself,
105 theItemRef,
106 theType,
107 dataPtr__in__, dataPtr__len__,
108 theFlags);
109 if (_err != noErr) return PyMac_Error(_err);
110 Py_INCREF(Py_None);
111 _res = Py_None;
112 dataPtr__error__: ;
113 return _res;
116 static PyObject *DragObj_SetDragItemFlavorData(_self, _args)
117 DragObjObject *_self;
118 PyObject *_args;
120 PyObject *_res = NULL;
121 OSErr _err;
122 ItemReference theItemRef;
123 FlavorType theType;
124 char *dataPtr__in__;
125 long dataPtr__len__;
126 int dataPtr__in_len__;
127 UInt32 dataOffset;
128 if (!PyArg_ParseTuple(_args, "lO&z#l",
129 &theItemRef,
130 PyMac_GetOSType, &theType,
131 &dataPtr__in__, &dataPtr__in_len__,
132 &dataOffset))
133 return NULL;
134 dataPtr__len__ = dataPtr__in_len__;
135 _err = SetDragItemFlavorData(_self->ob_itself,
136 theItemRef,
137 theType,
138 dataPtr__in__, dataPtr__len__,
139 dataOffset);
140 if (_err != noErr) return PyMac_Error(_err);
141 Py_INCREF(Py_None);
142 _res = Py_None;
143 dataPtr__error__: ;
144 return _res;
147 static PyObject *DragObj_SetDragImage(_self, _args)
148 DragObjObject *_self;
149 PyObject *_args;
151 PyObject *_res = NULL;
152 OSErr _err;
153 PixMapHandle imagePixMap;
154 RgnHandle imageRgn;
155 Point imageOffsetPt;
156 DragImageFlags theImageFlags;
157 if (!PyArg_ParseTuple(_args, "O&O&O&l",
158 ResObj_Convert, &imagePixMap,
159 ResObj_Convert, &imageRgn,
160 PyMac_GetPoint, &imageOffsetPt,
161 &theImageFlags))
162 return NULL;
163 _err = SetDragImage(_self->ob_itself,
164 imagePixMap,
165 imageRgn,
166 imageOffsetPt,
167 theImageFlags);
168 if (_err != noErr) return PyMac_Error(_err);
169 Py_INCREF(Py_None);
170 _res = Py_None;
171 return _res;
174 static PyObject *DragObj_ChangeDragBehaviors(_self, _args)
175 DragObjObject *_self;
176 PyObject *_args;
178 PyObject *_res = NULL;
179 OSErr _err;
180 DragBehaviors inBehaviorsToSet;
181 DragBehaviors inBehaviorsToClear;
182 if (!PyArg_ParseTuple(_args, "ll",
183 &inBehaviorsToSet,
184 &inBehaviorsToClear))
185 return NULL;
186 _err = ChangeDragBehaviors(_self->ob_itself,
187 inBehaviorsToSet,
188 inBehaviorsToClear);
189 if (_err != noErr) return PyMac_Error(_err);
190 Py_INCREF(Py_None);
191 _res = Py_None;
192 return _res;
195 static PyObject *DragObj_TrackDrag(_self, _args)
196 DragObjObject *_self;
197 PyObject *_args;
199 PyObject *_res = NULL;
200 OSErr _err;
201 EventRecord theEvent;
202 RgnHandle theRegion;
203 if (!PyArg_ParseTuple(_args, "O&O&",
204 PyMac_GetEventRecord, &theEvent,
205 ResObj_Convert, &theRegion))
206 return NULL;
207 _err = TrackDrag(_self->ob_itself,
208 &theEvent,
209 theRegion);
210 if (_err != noErr) return PyMac_Error(_err);
211 Py_INCREF(Py_None);
212 _res = Py_None;
213 return _res;
216 static PyObject *DragObj_CountDragItems(_self, _args)
217 DragObjObject *_self;
218 PyObject *_args;
220 PyObject *_res = NULL;
221 OSErr _err;
222 UInt16 numItems;
223 if (!PyArg_ParseTuple(_args, ""))
224 return NULL;
225 _err = CountDragItems(_self->ob_itself,
226 &numItems);
227 if (_err != noErr) return PyMac_Error(_err);
228 _res = Py_BuildValue("H",
229 numItems);
230 return _res;
233 static PyObject *DragObj_GetDragItemReferenceNumber(_self, _args)
234 DragObjObject *_self;
235 PyObject *_args;
237 PyObject *_res = NULL;
238 OSErr _err;
239 UInt16 index;
240 ItemReference theItemRef;
241 if (!PyArg_ParseTuple(_args, "H",
242 &index))
243 return NULL;
244 _err = GetDragItemReferenceNumber(_self->ob_itself,
245 index,
246 &theItemRef);
247 if (_err != noErr) return PyMac_Error(_err);
248 _res = Py_BuildValue("l",
249 theItemRef);
250 return _res;
253 static PyObject *DragObj_CountDragItemFlavors(_self, _args)
254 DragObjObject *_self;
255 PyObject *_args;
257 PyObject *_res = NULL;
258 OSErr _err;
259 ItemReference theItemRef;
260 UInt16 numFlavors;
261 if (!PyArg_ParseTuple(_args, "l",
262 &theItemRef))
263 return NULL;
264 _err = CountDragItemFlavors(_self->ob_itself,
265 theItemRef,
266 &numFlavors);
267 if (_err != noErr) return PyMac_Error(_err);
268 _res = Py_BuildValue("H",
269 numFlavors);
270 return _res;
273 static PyObject *DragObj_GetFlavorType(_self, _args)
274 DragObjObject *_self;
275 PyObject *_args;
277 PyObject *_res = NULL;
278 OSErr _err;
279 ItemReference theItemRef;
280 UInt16 index;
281 FlavorType theType;
282 if (!PyArg_ParseTuple(_args, "lH",
283 &theItemRef,
284 &index))
285 return NULL;
286 _err = GetFlavorType(_self->ob_itself,
287 theItemRef,
288 index,
289 &theType);
290 if (_err != noErr) return PyMac_Error(_err);
291 _res = Py_BuildValue("O&",
292 PyMac_BuildOSType, theType);
293 return _res;
296 static PyObject *DragObj_GetFlavorFlags(_self, _args)
297 DragObjObject *_self;
298 PyObject *_args;
300 PyObject *_res = NULL;
301 OSErr _err;
302 ItemReference theItemRef;
303 FlavorType theType;
304 FlavorFlags theFlags;
305 if (!PyArg_ParseTuple(_args, "lO&",
306 &theItemRef,
307 PyMac_GetOSType, &theType))
308 return NULL;
309 _err = GetFlavorFlags(_self->ob_itself,
310 theItemRef,
311 theType,
312 &theFlags);
313 if (_err != noErr) return PyMac_Error(_err);
314 _res = Py_BuildValue("l",
315 theFlags);
316 return _res;
319 static PyObject *DragObj_GetFlavorDataSize(_self, _args)
320 DragObjObject *_self;
321 PyObject *_args;
323 PyObject *_res = NULL;
324 OSErr _err;
325 ItemReference theItemRef;
326 FlavorType theType;
327 Size dataSize;
328 if (!PyArg_ParseTuple(_args, "lO&",
329 &theItemRef,
330 PyMac_GetOSType, &theType))
331 return NULL;
332 _err = GetFlavorDataSize(_self->ob_itself,
333 theItemRef,
334 theType,
335 &dataSize);
336 if (_err != noErr) return PyMac_Error(_err);
337 _res = Py_BuildValue("l",
338 dataSize);
339 return _res;
342 static PyObject *DragObj_GetFlavorData(_self, _args)
343 DragObjObject *_self;
344 PyObject *_args;
346 PyObject *_res = NULL;
347 OSErr _err;
348 ItemReference theItemRef;
349 FlavorType theType;
350 char *dataPtr__out__;
351 long dataPtr__len__;
352 int dataPtr__in_len__;
353 UInt32 dataOffset;
354 if (!PyArg_ParseTuple(_args, "lO&il",
355 &theItemRef,
356 PyMac_GetOSType, &theType,
357 &dataPtr__in_len__,
358 &dataOffset))
359 return NULL;
360 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
362 PyErr_NoMemory();
363 goto dataPtr__error__;
365 dataPtr__len__ = dataPtr__in_len__;
366 _err = GetFlavorData(_self->ob_itself,
367 theItemRef,
368 theType,
369 dataPtr__out__, &dataPtr__len__,
370 dataOffset);
371 if (_err != noErr) return PyMac_Error(_err);
372 _res = Py_BuildValue("s#",
373 dataPtr__out__, (int)dataPtr__len__);
374 free(dataPtr__out__);
375 dataPtr__error__: ;
376 return _res;
379 static PyObject *DragObj_GetDragItemBounds(_self, _args)
380 DragObjObject *_self;
381 PyObject *_args;
383 PyObject *_res = NULL;
384 OSErr _err;
385 ItemReference theItemRef;
386 Rect itemBounds;
387 if (!PyArg_ParseTuple(_args, "l",
388 &theItemRef))
389 return NULL;
390 _err = GetDragItemBounds(_self->ob_itself,
391 theItemRef,
392 &itemBounds);
393 if (_err != noErr) return PyMac_Error(_err);
394 _res = Py_BuildValue("O&",
395 PyMac_BuildRect, &itemBounds);
396 return _res;
399 static PyObject *DragObj_SetDragItemBounds(_self, _args)
400 DragObjObject *_self;
401 PyObject *_args;
403 PyObject *_res = NULL;
404 OSErr _err;
405 ItemReference theItemRef;
406 Rect itemBounds;
407 if (!PyArg_ParseTuple(_args, "lO&",
408 &theItemRef,
409 PyMac_GetRect, &itemBounds))
410 return NULL;
411 _err = SetDragItemBounds(_self->ob_itself,
412 theItemRef,
413 &itemBounds);
414 if (_err != noErr) return PyMac_Error(_err);
415 Py_INCREF(Py_None);
416 _res = Py_None;
417 return _res;
420 static PyObject *DragObj_GetDropLocation(_self, _args)
421 DragObjObject *_self;
422 PyObject *_args;
424 PyObject *_res = NULL;
425 OSErr _err;
426 AEDesc dropLocation;
427 if (!PyArg_ParseTuple(_args, ""))
428 return NULL;
429 _err = GetDropLocation(_self->ob_itself,
430 &dropLocation);
431 if (_err != noErr) return PyMac_Error(_err);
432 _res = Py_BuildValue("O&",
433 AEDesc_New, &dropLocation);
434 return _res;
437 static PyObject *DragObj_SetDropLocation(_self, _args)
438 DragObjObject *_self;
439 PyObject *_args;
441 PyObject *_res = NULL;
442 OSErr _err;
443 AEDesc dropLocation;
444 if (!PyArg_ParseTuple(_args, "O&",
445 AEDesc_Convert, &dropLocation))
446 return NULL;
447 _err = SetDropLocation(_self->ob_itself,
448 &dropLocation);
449 if (_err != noErr) return PyMac_Error(_err);
450 Py_INCREF(Py_None);
451 _res = Py_None;
452 return _res;
455 static PyObject *DragObj_GetDragAttributes(_self, _args)
456 DragObjObject *_self;
457 PyObject *_args;
459 PyObject *_res = NULL;
460 OSErr _err;
461 DragAttributes flags;
462 if (!PyArg_ParseTuple(_args, ""))
463 return NULL;
464 _err = GetDragAttributes(_self->ob_itself,
465 &flags);
466 if (_err != noErr) return PyMac_Error(_err);
467 _res = Py_BuildValue("l",
468 flags);
469 return _res;
472 static PyObject *DragObj_GetDragMouse(_self, _args)
473 DragObjObject *_self;
474 PyObject *_args;
476 PyObject *_res = NULL;
477 OSErr _err;
478 Point mouse;
479 Point globalPinnedMouse;
480 if (!PyArg_ParseTuple(_args, ""))
481 return NULL;
482 _err = GetDragMouse(_self->ob_itself,
483 &mouse,
484 &globalPinnedMouse);
485 if (_err != noErr) return PyMac_Error(_err);
486 _res = Py_BuildValue("O&O&",
487 PyMac_BuildPoint, mouse,
488 PyMac_BuildPoint, globalPinnedMouse);
489 return _res;
492 static PyObject *DragObj_SetDragMouse(_self, _args)
493 DragObjObject *_self;
494 PyObject *_args;
496 PyObject *_res = NULL;
497 OSErr _err;
498 Point globalPinnedMouse;
499 if (!PyArg_ParseTuple(_args, "O&",
500 PyMac_GetPoint, &globalPinnedMouse))
501 return NULL;
502 _err = SetDragMouse(_self->ob_itself,
503 globalPinnedMouse);
504 if (_err != noErr) return PyMac_Error(_err);
505 Py_INCREF(Py_None);
506 _res = Py_None;
507 return _res;
510 static PyObject *DragObj_GetDragOrigin(_self, _args)
511 DragObjObject *_self;
512 PyObject *_args;
514 PyObject *_res = NULL;
515 OSErr _err;
516 Point globalInitialMouse;
517 if (!PyArg_ParseTuple(_args, ""))
518 return NULL;
519 _err = GetDragOrigin(_self->ob_itself,
520 &globalInitialMouse);
521 if (_err != noErr) return PyMac_Error(_err);
522 _res = Py_BuildValue("O&",
523 PyMac_BuildPoint, globalInitialMouse);
524 return _res;
527 static PyObject *DragObj_GetDragModifiers(_self, _args)
528 DragObjObject *_self;
529 PyObject *_args;
531 PyObject *_res = NULL;
532 OSErr _err;
533 SInt16 modifiers;
534 SInt16 mouseDownModifiers;
535 SInt16 mouseUpModifiers;
536 if (!PyArg_ParseTuple(_args, ""))
537 return NULL;
538 _err = GetDragModifiers(_self->ob_itself,
539 &modifiers,
540 &mouseDownModifiers,
541 &mouseUpModifiers);
542 if (_err != noErr) return PyMac_Error(_err);
543 _res = Py_BuildValue("hhh",
544 modifiers,
545 mouseDownModifiers,
546 mouseUpModifiers);
547 return _res;
550 static PyObject *DragObj_ShowDragHilite(_self, _args)
551 DragObjObject *_self;
552 PyObject *_args;
554 PyObject *_res = NULL;
555 OSErr _err;
556 RgnHandle hiliteFrame;
557 Boolean inside;
558 if (!PyArg_ParseTuple(_args, "O&b",
559 ResObj_Convert, &hiliteFrame,
560 &inside))
561 return NULL;
562 _err = ShowDragHilite(_self->ob_itself,
563 hiliteFrame,
564 inside);
565 if (_err != noErr) return PyMac_Error(_err);
566 Py_INCREF(Py_None);
567 _res = Py_None;
568 return _res;
571 static PyObject *DragObj_HideDragHilite(_self, _args)
572 DragObjObject *_self;
573 PyObject *_args;
575 PyObject *_res = NULL;
576 OSErr _err;
577 if (!PyArg_ParseTuple(_args, ""))
578 return NULL;
579 _err = HideDragHilite(_self->ob_itself);
580 if (_err != noErr) return PyMac_Error(_err);
581 Py_INCREF(Py_None);
582 _res = Py_None;
583 return _res;
586 static PyObject *DragObj_DragPreScroll(_self, _args)
587 DragObjObject *_self;
588 PyObject *_args;
590 PyObject *_res = NULL;
591 OSErr _err;
592 SInt16 dH;
593 SInt16 dV;
594 if (!PyArg_ParseTuple(_args, "hh",
595 &dH,
596 &dV))
597 return NULL;
598 _err = DragPreScroll(_self->ob_itself,
600 dV);
601 if (_err != noErr) return PyMac_Error(_err);
602 Py_INCREF(Py_None);
603 _res = Py_None;
604 return _res;
607 static PyObject *DragObj_DragPostScroll(_self, _args)
608 DragObjObject *_self;
609 PyObject *_args;
611 PyObject *_res = NULL;
612 OSErr _err;
613 if (!PyArg_ParseTuple(_args, ""))
614 return NULL;
615 _err = DragPostScroll(_self->ob_itself);
616 if (_err != noErr) return PyMac_Error(_err);
617 Py_INCREF(Py_None);
618 _res = Py_None;
619 return _res;
622 static PyObject *DragObj_UpdateDragHilite(_self, _args)
623 DragObjObject *_self;
624 PyObject *_args;
626 PyObject *_res = NULL;
627 OSErr _err;
628 RgnHandle updateRgn;
629 if (!PyArg_ParseTuple(_args, "O&",
630 ResObj_Convert, &updateRgn))
631 return NULL;
632 _err = UpdateDragHilite(_self->ob_itself,
633 updateRgn);
634 if (_err != noErr) return PyMac_Error(_err);
635 Py_INCREF(Py_None);
636 _res = Py_None;
637 return _res;
640 static PyMethodDef DragObj_methods[] = {
641 {"DisposeDrag", (PyCFunction)DragObj_DisposeDrag, 1,
642 "() -> None"},
643 {"AddDragItemFlavor", (PyCFunction)DragObj_AddDragItemFlavor, 1,
644 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"},
645 {"SetDragItemFlavorData", (PyCFunction)DragObj_SetDragItemFlavorData, 1,
646 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"},
647 {"SetDragImage", (PyCFunction)DragObj_SetDragImage, 1,
648 "(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"},
649 {"ChangeDragBehaviors", (PyCFunction)DragObj_ChangeDragBehaviors, 1,
650 "(DragBehaviors inBehaviorsToSet, DragBehaviors inBehaviorsToClear) -> None"},
651 {"TrackDrag", (PyCFunction)DragObj_TrackDrag, 1,
652 "(EventRecord theEvent, RgnHandle theRegion) -> None"},
653 {"CountDragItems", (PyCFunction)DragObj_CountDragItems, 1,
654 "() -> (UInt16 numItems)"},
655 {"GetDragItemReferenceNumber", (PyCFunction)DragObj_GetDragItemReferenceNumber, 1,
656 "(UInt16 index) -> (ItemReference theItemRef)"},
657 {"CountDragItemFlavors", (PyCFunction)DragObj_CountDragItemFlavors, 1,
658 "(ItemReference theItemRef) -> (UInt16 numFlavors)"},
659 {"GetFlavorType", (PyCFunction)DragObj_GetFlavorType, 1,
660 "(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"},
661 {"GetFlavorFlags", (PyCFunction)DragObj_GetFlavorFlags, 1,
662 "(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"},
663 {"GetFlavorDataSize", (PyCFunction)DragObj_GetFlavorDataSize, 1,
664 "(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"},
665 {"GetFlavorData", (PyCFunction)DragObj_GetFlavorData, 1,
666 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"},
667 {"GetDragItemBounds", (PyCFunction)DragObj_GetDragItemBounds, 1,
668 "(ItemReference theItemRef) -> (Rect itemBounds)"},
669 {"SetDragItemBounds", (PyCFunction)DragObj_SetDragItemBounds, 1,
670 "(ItemReference theItemRef, Rect itemBounds) -> None"},
671 {"GetDropLocation", (PyCFunction)DragObj_GetDropLocation, 1,
672 "() -> (AEDesc dropLocation)"},
673 {"SetDropLocation", (PyCFunction)DragObj_SetDropLocation, 1,
674 "(AEDesc dropLocation) -> None"},
675 {"GetDragAttributes", (PyCFunction)DragObj_GetDragAttributes, 1,
676 "() -> (DragAttributes flags)"},
677 {"GetDragMouse", (PyCFunction)DragObj_GetDragMouse, 1,
678 "() -> (Point mouse, Point globalPinnedMouse)"},
679 {"SetDragMouse", (PyCFunction)DragObj_SetDragMouse, 1,
680 "(Point globalPinnedMouse) -> None"},
681 {"GetDragOrigin", (PyCFunction)DragObj_GetDragOrigin, 1,
682 "() -> (Point globalInitialMouse)"},
683 {"GetDragModifiers", (PyCFunction)DragObj_GetDragModifiers, 1,
684 "() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"},
685 {"ShowDragHilite", (PyCFunction)DragObj_ShowDragHilite, 1,
686 "(RgnHandle hiliteFrame, Boolean inside) -> None"},
687 {"HideDragHilite", (PyCFunction)DragObj_HideDragHilite, 1,
688 "() -> None"},
689 {"DragPreScroll", (PyCFunction)DragObj_DragPreScroll, 1,
690 "(SInt16 dH, SInt16 dV) -> None"},
691 {"DragPostScroll", (PyCFunction)DragObj_DragPostScroll, 1,
692 "() -> None"},
693 {"UpdateDragHilite", (PyCFunction)DragObj_UpdateDragHilite, 1,
694 "(RgnHandle updateRgn) -> None"},
695 {NULL, NULL, 0}
698 PyMethodChain DragObj_chain = { DragObj_methods, NULL };
700 static PyObject *DragObj_getattr(self, name)
701 DragObjObject *self;
702 char *name;
704 return Py_FindMethodInChain(&DragObj_chain, (PyObject *)self, name);
707 #define DragObj_setattr NULL
709 #define DragObj_compare NULL
711 #define DragObj_repr NULL
713 #define DragObj_hash NULL
715 PyTypeObject DragObj_Type = {
716 PyObject_HEAD_INIT(&PyType_Type)
717 0, /*ob_size*/
718 "DragObj", /*tp_name*/
719 sizeof(DragObjObject), /*tp_basicsize*/
720 0, /*tp_itemsize*/
721 /* methods */
722 (destructor) DragObj_dealloc, /*tp_dealloc*/
723 0, /*tp_print*/
724 (getattrfunc) DragObj_getattr, /*tp_getattr*/
725 (setattrfunc) DragObj_setattr, /*tp_setattr*/
726 (cmpfunc) DragObj_compare, /*tp_compare*/
727 (reprfunc) DragObj_repr, /*tp_repr*/
728 (PyNumberMethods *)0, /* tp_as_number */
729 (PySequenceMethods *)0, /* tp_as_sequence */
730 (PyMappingMethods *)0, /* tp_as_mapping */
731 (hashfunc) DragObj_hash, /*tp_hash*/
734 /* -------------------- End object type DragObj --------------------- */
737 static PyObject *Drag_NewDrag(_self, _args)
738 PyObject *_self;
739 PyObject *_args;
741 PyObject *_res = NULL;
742 OSErr _err;
743 DragRef theDrag;
744 if (!PyArg_ParseTuple(_args, ""))
745 return NULL;
746 _err = NewDrag(&theDrag);
747 if (_err != noErr) return PyMac_Error(_err);
748 _res = Py_BuildValue("O&",
749 DragObj_New, theDrag);
750 return _res;
753 static PyObject *Drag_GetDragHiliteColor(_self, _args)
754 PyObject *_self;
755 PyObject *_args;
757 PyObject *_res = NULL;
758 OSErr _err;
759 WindowPtr window;
760 RGBColor color;
761 if (!PyArg_ParseTuple(_args, "O&",
762 WinObj_Convert, &window))
763 return NULL;
764 _err = GetDragHiliteColor(window,
765 &color);
766 if (_err != noErr) return PyMac_Error(_err);
767 _res = Py_BuildValue("O&",
768 QdRGB_New, &color);
769 return _res;
772 static PyObject *Drag_WaitMouseMoved(_self, _args)
773 PyObject *_self;
774 PyObject *_args;
776 PyObject *_res = NULL;
777 Boolean _rv;
778 Point initialMouse;
779 if (!PyArg_ParseTuple(_args, "O&",
780 PyMac_GetPoint, &initialMouse))
781 return NULL;
782 _rv = WaitMouseMoved(initialMouse);
783 _res = Py_BuildValue("b",
784 _rv);
785 return _res;
788 static PyObject *Drag_ZoomRects(_self, _args)
789 PyObject *_self;
790 PyObject *_args;
792 PyObject *_res = NULL;
793 OSErr _err;
794 Rect fromRect;
795 Rect toRect;
796 SInt16 zoomSteps;
797 ZoomAcceleration acceleration;
798 if (!PyArg_ParseTuple(_args, "O&O&hh",
799 PyMac_GetRect, &fromRect,
800 PyMac_GetRect, &toRect,
801 &zoomSteps,
802 &acceleration))
803 return NULL;
804 _err = ZoomRects(&fromRect,
805 &toRect,
806 zoomSteps,
807 acceleration);
808 if (_err != noErr) return PyMac_Error(_err);
809 Py_INCREF(Py_None);
810 _res = Py_None;
811 return _res;
814 static PyObject *Drag_ZoomRegion(_self, _args)
815 PyObject *_self;
816 PyObject *_args;
818 PyObject *_res = NULL;
819 OSErr _err;
820 RgnHandle region;
821 Point zoomDistance;
822 SInt16 zoomSteps;
823 ZoomAcceleration acceleration;
824 if (!PyArg_ParseTuple(_args, "O&O&hh",
825 ResObj_Convert, &region,
826 PyMac_GetPoint, &zoomDistance,
827 &zoomSteps,
828 &acceleration))
829 return NULL;
830 _err = ZoomRegion(region,
831 zoomDistance,
832 zoomSteps,
833 acceleration);
834 if (_err != noErr) return PyMac_Error(_err);
835 Py_INCREF(Py_None);
836 _res = Py_None;
837 return _res;
840 static PyObject *Drag_InstallTrackingHandler(_self, _args)
841 PyObject *_self;
842 PyObject *_args;
844 PyObject *_res = NULL;
846 PyObject *callback;
847 WindowPtr theWindow = NULL;
848 OSErr _err;
850 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
851 return NULL;
852 Py_INCREF(callback); /* Cannot decref later, too bad */
853 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
854 if (_err != noErr) return PyMac_Error(_err);
855 Py_INCREF(Py_None);
856 return Py_None;
860 static PyObject *Drag_InstallReceiveHandler(_self, _args)
861 PyObject *_self;
862 PyObject *_args;
864 PyObject *_res = NULL;
866 PyObject *callback;
867 WindowPtr theWindow = NULL;
868 OSErr _err;
870 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
871 return NULL;
872 Py_INCREF(callback); /* Cannot decref later, too bad */
873 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
874 if (_err != noErr) return PyMac_Error(_err);
875 Py_INCREF(Py_None);
876 return Py_None;
880 static PyObject *Drag_RemoveTrackingHandler(_self, _args)
881 PyObject *_self;
882 PyObject *_args;
884 PyObject *_res = NULL;
886 WindowPtr theWindow = NULL;
887 OSErr _err;
889 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
890 return NULL;
891 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
892 if (_err != noErr) return PyMac_Error(_err);
893 Py_INCREF(Py_None);
894 return Py_None;
898 static PyObject *Drag_RemoveReceiveHandler(_self, _args)
899 PyObject *_self;
900 PyObject *_args;
902 PyObject *_res = NULL;
904 WindowPtr theWindow = NULL;
905 OSErr _err;
907 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
908 return NULL;
909 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
910 if (_err != noErr) return PyMac_Error(_err);
911 Py_INCREF(Py_None);
912 return Py_None;
916 static PyMethodDef Drag_methods[] = {
917 {"NewDrag", (PyCFunction)Drag_NewDrag, 1,
918 "() -> (DragRef theDrag)"},
919 {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1,
920 "(WindowPtr window) -> (RGBColor color)"},
921 {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1,
922 "(Point initialMouse) -> (Boolean _rv)"},
923 {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1,
924 "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
925 {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1,
926 "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
927 {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1,
928 NULL},
929 {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1,
930 NULL},
931 {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1,
932 NULL},
933 {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1,
934 NULL},
935 {NULL, NULL, 0}
940 static pascal OSErr
941 dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
942 void *handlerRefCon, DragReference theDrag)
944 PyObject *args, *rv;
945 int i;
947 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
948 if ( args == NULL )
949 return -1;
950 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
951 Py_DECREF(args);
952 if ( rv == NULL ) {
953 fprintf(stderr, "Drag: Exception in TrackingHandler\n");
954 return -1;
956 i = -1;
957 if ( rv == Py_None )
958 i = 0;
959 else
960 PyArg_Parse(rv, "l", &i);
961 Py_DECREF(rv);
962 return i;
965 static pascal OSErr
966 dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
967 DragReference theDrag)
969 PyObject *args, *rv;
970 int i;
972 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
973 if ( args == NULL )
974 return -1;
975 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
976 Py_DECREF(args);
977 if ( rv == NULL ) {
978 fprintf(stderr, "Drag: Exception in ReceiveHandler\n");
979 return -1;
981 i = -1;
982 if ( rv == Py_None )
983 i = 0;
984 else
985 PyArg_Parse(rv, "l", &i);
986 Py_DECREF(rv);
987 return i;
990 static pascal OSErr
991 dragglue_SendData(FlavorType theType, void *dragSendRefCon,
992 ItemReference theItem, DragReference theDrag)
994 DragObjObject *self = (DragObjObject *)dragSendRefCon;
995 PyObject *args, *rv;
996 int i;
998 if ( self->sendproc == NULL )
999 return -1;
1000 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
1001 if ( args == NULL )
1002 return -1;
1003 rv = PyEval_CallObject(self->sendproc, args);
1004 Py_DECREF(args);
1005 if ( rv == NULL ) {
1006 fprintf(stderr, "Drag: Exception in SendDataHandler\n");
1007 return -1;
1009 i = -1;
1010 if ( rv == Py_None )
1011 i = 0;
1012 else
1013 PyArg_Parse(rv, "l", &i);
1014 Py_DECREF(rv);
1015 return i;
1018 #if 0
1019 static pascal OSErr
1020 dragglue_Input(Point *mouse, short *modifiers,
1021 void *dragSendRefCon, DragReference theDrag)
1023 return 0;
1026 static pascal OSErr
1027 dragglue_Drawing(xxxx
1028 void *dragSendRefCon, DragReference theDrag)
1030 return 0;
1032 #endif
1036 void initDrag()
1038 PyObject *m;
1039 PyObject *d;
1044 m = Py_InitModule("Drag", Drag_methods);
1045 d = PyModule_GetDict(m);
1046 Drag_Error = PyMac_GetOSErrException();
1047 if (Drag_Error == NULL ||
1048 PyDict_SetItemString(d, "Error", Drag_Error) != 0)
1049 return;
1050 DragObj_Type.ob_type = &PyType_Type;
1051 Py_INCREF(&DragObj_Type);
1052 if (PyDict_SetItemString(d, "DragObjType", (PyObject *)&DragObj_Type) != 0)
1053 Py_FatalError("can't initialize DragObjType");
1055 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler);
1056 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler);
1057 dragglue_SendDataUPP = NewDragSendDataProc(dragglue_SendData);
1058 #if 0
1059 dragglue_InputUPP = NewDragInputProc(dragglue_Input);
1060 dragglue_DrawingUPP = NewDragDrawingProc(dragglue_Drawing);
1061 #endif
1066 /* ======================== End module Drag ========================= */