py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Mac / Modules / drag / Dragmodule.c
blob2fd7cfe3ebfc52819df357ebc8c4c28cb8e6875f
2 /* ========================== Module Drag =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <Drag.h>
13 #else
14 #include <Carbon/Carbon.h>
15 #endif
17 /* Callback glue routines */
18 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
19 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
20 DragSendDataUPP dragglue_SendDataUPP;
21 #if 0
22 DragInputUPP dragglue_InputUPP;
23 DragDrawingUPP dragglue_DrawingUPP;
24 #endif
26 #ifdef USE_TOOLBOX_OBJECT_GLUE
27 extern PyObject *_DragObj_New(DragRef);
28 extern int _DragObj_Convert(PyObject *, DragRef *);
30 #define DragObj_New _DragObj_New
31 #define DragObj_Convert _DragObj_Convert
32 #endif
34 static PyObject *Drag_Error;
36 /* ---------------------- Object type DragObj ----------------------- */
38 PyTypeObject DragObj_Type;
40 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
42 typedef struct DragObjObject {
43 PyObject_HEAD
44 DragRef ob_itself;
45 PyObject *sendproc;
46 } DragObjObject;
48 PyObject *DragObj_New(DragRef itself)
50 DragObjObject *it;
51 if (itself == NULL) {
52 PyErr_SetString(Drag_Error,"Cannot create null Drag");
53 return NULL;
55 it = PyObject_NEW(DragObjObject, &DragObj_Type);
56 if (it == NULL) return NULL;
57 it->ob_itself = itself;
58 it->sendproc = NULL;
59 return (PyObject *)it;
61 DragObj_Convert(PyObject *v, DragRef *p_itself)
63 if (!DragObj_Check(v))
65 PyErr_SetString(PyExc_TypeError, "DragObj required");
66 return 0;
68 *p_itself = ((DragObjObject *)v)->ob_itself;
69 return 1;
72 static void DragObj_dealloc(DragObjObject *self)
74 Py_XDECREF(self->sendproc);
75 PyMem_DEL(self);
78 static PyObject *DragObj_DisposeDrag(DragObjObject *_self, PyObject *_args)
80 PyObject *_res = NULL;
81 OSErr _err;
82 if (!PyArg_ParseTuple(_args, ""))
83 return NULL;
84 _err = DisposeDrag(_self->ob_itself);
85 if (_err != noErr) return PyMac_Error(_err);
86 Py_INCREF(Py_None);
87 _res = Py_None;
88 return _res;
91 static PyObject *DragObj_AddDragItemFlavor(DragObjObject *_self, PyObject *_args)
93 PyObject *_res = NULL;
94 OSErr _err;
95 ItemReference theItemRef;
96 FlavorType theType;
97 char *dataPtr__in__;
98 long dataPtr__len__;
99 int dataPtr__in_len__;
100 FlavorFlags theFlags;
101 if (!PyArg_ParseTuple(_args, "lO&z#l",
102 &theItemRef,
103 PyMac_GetOSType, &theType,
104 &dataPtr__in__, &dataPtr__in_len__,
105 &theFlags))
106 return NULL;
107 dataPtr__len__ = dataPtr__in_len__;
108 _err = AddDragItemFlavor(_self->ob_itself,
109 theItemRef,
110 theType,
111 dataPtr__in__, dataPtr__len__,
112 theFlags);
113 if (_err != noErr) return PyMac_Error(_err);
114 Py_INCREF(Py_None);
115 _res = Py_None;
116 dataPtr__error__: ;
117 return _res;
120 static PyObject *DragObj_SetDragItemFlavorData(DragObjObject *_self, PyObject *_args)
122 PyObject *_res = NULL;
123 OSErr _err;
124 ItemReference theItemRef;
125 FlavorType theType;
126 char *dataPtr__in__;
127 long dataPtr__len__;
128 int dataPtr__in_len__;
129 UInt32 dataOffset;
130 if (!PyArg_ParseTuple(_args, "lO&z#l",
131 &theItemRef,
132 PyMac_GetOSType, &theType,
133 &dataPtr__in__, &dataPtr__in_len__,
134 &dataOffset))
135 return NULL;
136 dataPtr__len__ = dataPtr__in_len__;
137 _err = SetDragItemFlavorData(_self->ob_itself,
138 theItemRef,
139 theType,
140 dataPtr__in__, dataPtr__len__,
141 dataOffset);
142 if (_err != noErr) return PyMac_Error(_err);
143 Py_INCREF(Py_None);
144 _res = Py_None;
145 dataPtr__error__: ;
146 return _res;
149 static PyObject *DragObj_SetDragImage(DragObjObject *_self, 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(DragObjObject *_self, PyObject *_args)
176 PyObject *_res = NULL;
177 OSErr _err;
178 DragBehaviors inBehaviorsToSet;
179 DragBehaviors inBehaviorsToClear;
180 if (!PyArg_ParseTuple(_args, "ll",
181 &inBehaviorsToSet,
182 &inBehaviorsToClear))
183 return NULL;
184 _err = ChangeDragBehaviors(_self->ob_itself,
185 inBehaviorsToSet,
186 inBehaviorsToClear);
187 if (_err != noErr) return PyMac_Error(_err);
188 Py_INCREF(Py_None);
189 _res = Py_None;
190 return _res;
193 static PyObject *DragObj_TrackDrag(DragObjObject *_self, PyObject *_args)
195 PyObject *_res = NULL;
196 OSErr _err;
197 EventRecord theEvent;
198 RgnHandle theRegion;
199 if (!PyArg_ParseTuple(_args, "O&O&",
200 PyMac_GetEventRecord, &theEvent,
201 ResObj_Convert, &theRegion))
202 return NULL;
203 _err = TrackDrag(_self->ob_itself,
204 &theEvent,
205 theRegion);
206 if (_err != noErr) return PyMac_Error(_err);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
212 static PyObject *DragObj_CountDragItems(DragObjObject *_self, PyObject *_args)
214 PyObject *_res = NULL;
215 OSErr _err;
216 UInt16 numItems;
217 if (!PyArg_ParseTuple(_args, ""))
218 return NULL;
219 _err = CountDragItems(_self->ob_itself,
220 &numItems);
221 if (_err != noErr) return PyMac_Error(_err);
222 _res = Py_BuildValue("H",
223 numItems);
224 return _res;
227 static PyObject *DragObj_GetDragItemReferenceNumber(DragObjObject *_self, PyObject *_args)
229 PyObject *_res = NULL;
230 OSErr _err;
231 UInt16 index;
232 ItemReference theItemRef;
233 if (!PyArg_ParseTuple(_args, "H",
234 &index))
235 return NULL;
236 _err = GetDragItemReferenceNumber(_self->ob_itself,
237 index,
238 &theItemRef);
239 if (_err != noErr) return PyMac_Error(_err);
240 _res = Py_BuildValue("l",
241 theItemRef);
242 return _res;
245 static PyObject *DragObj_CountDragItemFlavors(DragObjObject *_self, PyObject *_args)
247 PyObject *_res = NULL;
248 OSErr _err;
249 ItemReference theItemRef;
250 UInt16 numFlavors;
251 if (!PyArg_ParseTuple(_args, "l",
252 &theItemRef))
253 return NULL;
254 _err = CountDragItemFlavors(_self->ob_itself,
255 theItemRef,
256 &numFlavors);
257 if (_err != noErr) return PyMac_Error(_err);
258 _res = Py_BuildValue("H",
259 numFlavors);
260 return _res;
263 static PyObject *DragObj_GetFlavorType(DragObjObject *_self, PyObject *_args)
265 PyObject *_res = NULL;
266 OSErr _err;
267 ItemReference theItemRef;
268 UInt16 index;
269 FlavorType theType;
270 if (!PyArg_ParseTuple(_args, "lH",
271 &theItemRef,
272 &index))
273 return NULL;
274 _err = GetFlavorType(_self->ob_itself,
275 theItemRef,
276 index,
277 &theType);
278 if (_err != noErr) return PyMac_Error(_err);
279 _res = Py_BuildValue("O&",
280 PyMac_BuildOSType, theType);
281 return _res;
284 static PyObject *DragObj_GetFlavorFlags(DragObjObject *_self, PyObject *_args)
286 PyObject *_res = NULL;
287 OSErr _err;
288 ItemReference theItemRef;
289 FlavorType theType;
290 FlavorFlags theFlags;
291 if (!PyArg_ParseTuple(_args, "lO&",
292 &theItemRef,
293 PyMac_GetOSType, &theType))
294 return NULL;
295 _err = GetFlavorFlags(_self->ob_itself,
296 theItemRef,
297 theType,
298 &theFlags);
299 if (_err != noErr) return PyMac_Error(_err);
300 _res = Py_BuildValue("l",
301 theFlags);
302 return _res;
305 static PyObject *DragObj_GetFlavorDataSize(DragObjObject *_self, PyObject *_args)
307 PyObject *_res = NULL;
308 OSErr _err;
309 ItemReference theItemRef;
310 FlavorType theType;
311 Size dataSize;
312 if (!PyArg_ParseTuple(_args, "lO&",
313 &theItemRef,
314 PyMac_GetOSType, &theType))
315 return NULL;
316 _err = GetFlavorDataSize(_self->ob_itself,
317 theItemRef,
318 theType,
319 &dataSize);
320 if (_err != noErr) return PyMac_Error(_err);
321 _res = Py_BuildValue("l",
322 dataSize);
323 return _res;
326 static PyObject *DragObj_GetFlavorData(DragObjObject *_self, PyObject *_args)
328 PyObject *_res = NULL;
329 OSErr _err;
330 ItemReference theItemRef;
331 FlavorType theType;
332 char *dataPtr__out__;
333 long dataPtr__len__;
334 int dataPtr__in_len__;
335 UInt32 dataOffset;
336 if (!PyArg_ParseTuple(_args, "lO&il",
337 &theItemRef,
338 PyMac_GetOSType, &theType,
339 &dataPtr__in_len__,
340 &dataOffset))
341 return NULL;
342 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
344 PyErr_NoMemory();
345 goto dataPtr__error__;
347 dataPtr__len__ = dataPtr__in_len__;
348 _err = GetFlavorData(_self->ob_itself,
349 theItemRef,
350 theType,
351 dataPtr__out__, &dataPtr__len__,
352 dataOffset);
353 if (_err != noErr) return PyMac_Error(_err);
354 _res = Py_BuildValue("s#",
355 dataPtr__out__, (int)dataPtr__len__);
356 free(dataPtr__out__);
357 dataPtr__error__: ;
358 return _res;
361 static PyObject *DragObj_GetDragItemBounds(DragObjObject *_self, PyObject *_args)
363 PyObject *_res = NULL;
364 OSErr _err;
365 ItemReference theItemRef;
366 Rect itemBounds;
367 if (!PyArg_ParseTuple(_args, "l",
368 &theItemRef))
369 return NULL;
370 _err = GetDragItemBounds(_self->ob_itself,
371 theItemRef,
372 &itemBounds);
373 if (_err != noErr) return PyMac_Error(_err);
374 _res = Py_BuildValue("O&",
375 PyMac_BuildRect, &itemBounds);
376 return _res;
379 static PyObject *DragObj_SetDragItemBounds(DragObjObject *_self, PyObject *_args)
381 PyObject *_res = NULL;
382 OSErr _err;
383 ItemReference theItemRef;
384 Rect itemBounds;
385 if (!PyArg_ParseTuple(_args, "lO&",
386 &theItemRef,
387 PyMac_GetRect, &itemBounds))
388 return NULL;
389 _err = SetDragItemBounds(_self->ob_itself,
390 theItemRef,
391 &itemBounds);
392 if (_err != noErr) return PyMac_Error(_err);
393 Py_INCREF(Py_None);
394 _res = Py_None;
395 return _res;
398 static PyObject *DragObj_GetDropLocation(DragObjObject *_self, PyObject *_args)
400 PyObject *_res = NULL;
401 OSErr _err;
402 AEDesc dropLocation;
403 if (!PyArg_ParseTuple(_args, ""))
404 return NULL;
405 _err = GetDropLocation(_self->ob_itself,
406 &dropLocation);
407 if (_err != noErr) return PyMac_Error(_err);
408 _res = Py_BuildValue("O&",
409 AEDesc_New, &dropLocation);
410 return _res;
413 static PyObject *DragObj_SetDropLocation(DragObjObject *_self, PyObject *_args)
415 PyObject *_res = NULL;
416 OSErr _err;
417 AEDesc dropLocation;
418 if (!PyArg_ParseTuple(_args, "O&",
419 AEDesc_Convert, &dropLocation))
420 return NULL;
421 _err = SetDropLocation(_self->ob_itself,
422 &dropLocation);
423 if (_err != noErr) return PyMac_Error(_err);
424 Py_INCREF(Py_None);
425 _res = Py_None;
426 return _res;
429 static PyObject *DragObj_GetDragAttributes(DragObjObject *_self, PyObject *_args)
431 PyObject *_res = NULL;
432 OSErr _err;
433 DragAttributes flags;
434 if (!PyArg_ParseTuple(_args, ""))
435 return NULL;
436 _err = GetDragAttributes(_self->ob_itself,
437 &flags);
438 if (_err != noErr) return PyMac_Error(_err);
439 _res = Py_BuildValue("l",
440 flags);
441 return _res;
444 static PyObject *DragObj_GetDragMouse(DragObjObject *_self, PyObject *_args)
446 PyObject *_res = NULL;
447 OSErr _err;
448 Point mouse;
449 Point globalPinnedMouse;
450 if (!PyArg_ParseTuple(_args, ""))
451 return NULL;
452 _err = GetDragMouse(_self->ob_itself,
453 &mouse,
454 &globalPinnedMouse);
455 if (_err != noErr) return PyMac_Error(_err);
456 _res = Py_BuildValue("O&O&",
457 PyMac_BuildPoint, mouse,
458 PyMac_BuildPoint, globalPinnedMouse);
459 return _res;
462 static PyObject *DragObj_SetDragMouse(DragObjObject *_self, PyObject *_args)
464 PyObject *_res = NULL;
465 OSErr _err;
466 Point globalPinnedMouse;
467 if (!PyArg_ParseTuple(_args, "O&",
468 PyMac_GetPoint, &globalPinnedMouse))
469 return NULL;
470 _err = SetDragMouse(_self->ob_itself,
471 globalPinnedMouse);
472 if (_err != noErr) return PyMac_Error(_err);
473 Py_INCREF(Py_None);
474 _res = Py_None;
475 return _res;
478 static PyObject *DragObj_GetDragOrigin(DragObjObject *_self, PyObject *_args)
480 PyObject *_res = NULL;
481 OSErr _err;
482 Point globalInitialMouse;
483 if (!PyArg_ParseTuple(_args, ""))
484 return NULL;
485 _err = GetDragOrigin(_self->ob_itself,
486 &globalInitialMouse);
487 if (_err != noErr) return PyMac_Error(_err);
488 _res = Py_BuildValue("O&",
489 PyMac_BuildPoint, globalInitialMouse);
490 return _res;
493 static PyObject *DragObj_GetDragModifiers(DragObjObject *_self, PyObject *_args)
495 PyObject *_res = NULL;
496 OSErr _err;
497 SInt16 modifiers;
498 SInt16 mouseDownModifiers;
499 SInt16 mouseUpModifiers;
500 if (!PyArg_ParseTuple(_args, ""))
501 return NULL;
502 _err = GetDragModifiers(_self->ob_itself,
503 &modifiers,
504 &mouseDownModifiers,
505 &mouseUpModifiers);
506 if (_err != noErr) return PyMac_Error(_err);
507 _res = Py_BuildValue("hhh",
508 modifiers,
509 mouseDownModifiers,
510 mouseUpModifiers);
511 return _res;
514 static PyObject *DragObj_ShowDragHilite(DragObjObject *_self, PyObject *_args)
516 PyObject *_res = NULL;
517 OSErr _err;
518 RgnHandle hiliteFrame;
519 Boolean inside;
520 if (!PyArg_ParseTuple(_args, "O&b",
521 ResObj_Convert, &hiliteFrame,
522 &inside))
523 return NULL;
524 _err = ShowDragHilite(_self->ob_itself,
525 hiliteFrame,
526 inside);
527 if (_err != noErr) return PyMac_Error(_err);
528 Py_INCREF(Py_None);
529 _res = Py_None;
530 return _res;
533 static PyObject *DragObj_HideDragHilite(DragObjObject *_self, PyObject *_args)
535 PyObject *_res = NULL;
536 OSErr _err;
537 if (!PyArg_ParseTuple(_args, ""))
538 return NULL;
539 _err = HideDragHilite(_self->ob_itself);
540 if (_err != noErr) return PyMac_Error(_err);
541 Py_INCREF(Py_None);
542 _res = Py_None;
543 return _res;
546 static PyObject *DragObj_DragPreScroll(DragObjObject *_self, PyObject *_args)
548 PyObject *_res = NULL;
549 OSErr _err;
550 SInt16 dH;
551 SInt16 dV;
552 if (!PyArg_ParseTuple(_args, "hh",
553 &dH,
554 &dV))
555 return NULL;
556 _err = DragPreScroll(_self->ob_itself,
558 dV);
559 if (_err != noErr) return PyMac_Error(_err);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
565 static PyObject *DragObj_DragPostScroll(DragObjObject *_self, PyObject *_args)
567 PyObject *_res = NULL;
568 OSErr _err;
569 if (!PyArg_ParseTuple(_args, ""))
570 return NULL;
571 _err = DragPostScroll(_self->ob_itself);
572 if (_err != noErr) return PyMac_Error(_err);
573 Py_INCREF(Py_None);
574 _res = Py_None;
575 return _res;
578 static PyObject *DragObj_UpdateDragHilite(DragObjObject *_self, PyObject *_args)
580 PyObject *_res = NULL;
581 OSErr _err;
582 RgnHandle updateRgn;
583 if (!PyArg_ParseTuple(_args, "O&",
584 ResObj_Convert, &updateRgn))
585 return NULL;
586 _err = UpdateDragHilite(_self->ob_itself,
587 updateRgn);
588 if (_err != noErr) return PyMac_Error(_err);
589 Py_INCREF(Py_None);
590 _res = Py_None;
591 return _res;
594 static PyMethodDef DragObj_methods[] = {
595 {"DisposeDrag", (PyCFunction)DragObj_DisposeDrag, 1,
596 "() -> None"},
597 {"AddDragItemFlavor", (PyCFunction)DragObj_AddDragItemFlavor, 1,
598 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"},
599 {"SetDragItemFlavorData", (PyCFunction)DragObj_SetDragItemFlavorData, 1,
600 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"},
601 {"SetDragImage", (PyCFunction)DragObj_SetDragImage, 1,
602 "(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"},
603 {"ChangeDragBehaviors", (PyCFunction)DragObj_ChangeDragBehaviors, 1,
604 "(DragBehaviors inBehaviorsToSet, DragBehaviors inBehaviorsToClear) -> None"},
605 {"TrackDrag", (PyCFunction)DragObj_TrackDrag, 1,
606 "(EventRecord theEvent, RgnHandle theRegion) -> None"},
607 {"CountDragItems", (PyCFunction)DragObj_CountDragItems, 1,
608 "() -> (UInt16 numItems)"},
609 {"GetDragItemReferenceNumber", (PyCFunction)DragObj_GetDragItemReferenceNumber, 1,
610 "(UInt16 index) -> (ItemReference theItemRef)"},
611 {"CountDragItemFlavors", (PyCFunction)DragObj_CountDragItemFlavors, 1,
612 "(ItemReference theItemRef) -> (UInt16 numFlavors)"},
613 {"GetFlavorType", (PyCFunction)DragObj_GetFlavorType, 1,
614 "(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"},
615 {"GetFlavorFlags", (PyCFunction)DragObj_GetFlavorFlags, 1,
616 "(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"},
617 {"GetFlavorDataSize", (PyCFunction)DragObj_GetFlavorDataSize, 1,
618 "(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"},
619 {"GetFlavorData", (PyCFunction)DragObj_GetFlavorData, 1,
620 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"},
621 {"GetDragItemBounds", (PyCFunction)DragObj_GetDragItemBounds, 1,
622 "(ItemReference theItemRef) -> (Rect itemBounds)"},
623 {"SetDragItemBounds", (PyCFunction)DragObj_SetDragItemBounds, 1,
624 "(ItemReference theItemRef, Rect itemBounds) -> None"},
625 {"GetDropLocation", (PyCFunction)DragObj_GetDropLocation, 1,
626 "() -> (AEDesc dropLocation)"},
627 {"SetDropLocation", (PyCFunction)DragObj_SetDropLocation, 1,
628 "(AEDesc dropLocation) -> None"},
629 {"GetDragAttributes", (PyCFunction)DragObj_GetDragAttributes, 1,
630 "() -> (DragAttributes flags)"},
631 {"GetDragMouse", (PyCFunction)DragObj_GetDragMouse, 1,
632 "() -> (Point mouse, Point globalPinnedMouse)"},
633 {"SetDragMouse", (PyCFunction)DragObj_SetDragMouse, 1,
634 "(Point globalPinnedMouse) -> None"},
635 {"GetDragOrigin", (PyCFunction)DragObj_GetDragOrigin, 1,
636 "() -> (Point globalInitialMouse)"},
637 {"GetDragModifiers", (PyCFunction)DragObj_GetDragModifiers, 1,
638 "() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"},
639 {"ShowDragHilite", (PyCFunction)DragObj_ShowDragHilite, 1,
640 "(RgnHandle hiliteFrame, Boolean inside) -> None"},
641 {"HideDragHilite", (PyCFunction)DragObj_HideDragHilite, 1,
642 "() -> None"},
643 {"DragPreScroll", (PyCFunction)DragObj_DragPreScroll, 1,
644 "(SInt16 dH, SInt16 dV) -> None"},
645 {"DragPostScroll", (PyCFunction)DragObj_DragPostScroll, 1,
646 "() -> None"},
647 {"UpdateDragHilite", (PyCFunction)DragObj_UpdateDragHilite, 1,
648 "(RgnHandle updateRgn) -> None"},
649 {NULL, NULL, 0}
652 PyMethodChain DragObj_chain = { DragObj_methods, NULL };
654 static PyObject *DragObj_getattr(DragObjObject *self, char *name)
656 return Py_FindMethodInChain(&DragObj_chain, (PyObject *)self, name);
659 #define DragObj_setattr NULL
661 #define DragObj_compare NULL
663 #define DragObj_repr NULL
665 #define DragObj_hash NULL
667 PyTypeObject DragObj_Type = {
668 PyObject_HEAD_INIT(&PyType_Type)
669 0, /*ob_size*/
670 "DragObj", /*tp_name*/
671 sizeof(DragObjObject), /*tp_basicsize*/
672 0, /*tp_itemsize*/
673 /* methods */
674 (destructor) DragObj_dealloc, /*tp_dealloc*/
675 0, /*tp_print*/
676 (getattrfunc) DragObj_getattr, /*tp_getattr*/
677 (setattrfunc) DragObj_setattr, /*tp_setattr*/
678 (cmpfunc) DragObj_compare, /*tp_compare*/
679 (reprfunc) DragObj_repr, /*tp_repr*/
680 (PyNumberMethods *)0, /* tp_as_number */
681 (PySequenceMethods *)0, /* tp_as_sequence */
682 (PyMappingMethods *)0, /* tp_as_mapping */
683 (hashfunc) DragObj_hash, /*tp_hash*/
686 /* -------------------- End object type DragObj --------------------- */
689 static PyObject *Drag_NewDrag(PyObject *_self, PyObject *_args)
691 PyObject *_res = NULL;
692 OSErr _err;
693 DragRef theDrag;
694 if (!PyArg_ParseTuple(_args, ""))
695 return NULL;
696 _err = NewDrag(&theDrag);
697 if (_err != noErr) return PyMac_Error(_err);
698 _res = Py_BuildValue("O&",
699 DragObj_New, theDrag);
700 return _res;
703 static PyObject *Drag_GetDragHiliteColor(PyObject *_self, PyObject *_args)
705 PyObject *_res = NULL;
706 OSErr _err;
707 WindowPtr window;
708 RGBColor color;
709 if (!PyArg_ParseTuple(_args, "O&",
710 WinObj_Convert, &window))
711 return NULL;
712 _err = GetDragHiliteColor(window,
713 &color);
714 if (_err != noErr) return PyMac_Error(_err);
715 _res = Py_BuildValue("O&",
716 QdRGB_New, &color);
717 return _res;
720 static PyObject *Drag_WaitMouseMoved(PyObject *_self, PyObject *_args)
722 PyObject *_res = NULL;
723 Boolean _rv;
724 Point initialMouse;
725 if (!PyArg_ParseTuple(_args, "O&",
726 PyMac_GetPoint, &initialMouse))
727 return NULL;
728 _rv = WaitMouseMoved(initialMouse);
729 _res = Py_BuildValue("b",
730 _rv);
731 return _res;
734 static PyObject *Drag_ZoomRects(PyObject *_self, PyObject *_args)
736 PyObject *_res = NULL;
737 OSErr _err;
738 Rect fromRect;
739 Rect toRect;
740 SInt16 zoomSteps;
741 ZoomAcceleration acceleration;
742 if (!PyArg_ParseTuple(_args, "O&O&hh",
743 PyMac_GetRect, &fromRect,
744 PyMac_GetRect, &toRect,
745 &zoomSteps,
746 &acceleration))
747 return NULL;
748 _err = ZoomRects(&fromRect,
749 &toRect,
750 zoomSteps,
751 acceleration);
752 if (_err != noErr) return PyMac_Error(_err);
753 Py_INCREF(Py_None);
754 _res = Py_None;
755 return _res;
758 static PyObject *Drag_ZoomRegion(PyObject *_self, PyObject *_args)
760 PyObject *_res = NULL;
761 OSErr _err;
762 RgnHandle region;
763 Point zoomDistance;
764 SInt16 zoomSteps;
765 ZoomAcceleration acceleration;
766 if (!PyArg_ParseTuple(_args, "O&O&hh",
767 ResObj_Convert, &region,
768 PyMac_GetPoint, &zoomDistance,
769 &zoomSteps,
770 &acceleration))
771 return NULL;
772 _err = ZoomRegion(region,
773 zoomDistance,
774 zoomSteps,
775 acceleration);
776 if (_err != noErr) return PyMac_Error(_err);
777 Py_INCREF(Py_None);
778 _res = Py_None;
779 return _res;
782 static PyObject *Drag_InstallTrackingHandler(PyObject *_self, PyObject *_args)
784 PyObject *_res = NULL;
786 PyObject *callback;
787 WindowPtr theWindow = NULL;
788 OSErr _err;
790 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
791 return NULL;
792 Py_INCREF(callback); /* Cannot decref later, too bad */
793 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
794 if (_err != noErr) return PyMac_Error(_err);
795 Py_INCREF(Py_None);
796 return Py_None;
800 static PyObject *Drag_InstallReceiveHandler(PyObject *_self, PyObject *_args)
802 PyObject *_res = NULL;
804 PyObject *callback;
805 WindowPtr theWindow = NULL;
806 OSErr _err;
808 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
809 return NULL;
810 Py_INCREF(callback); /* Cannot decref later, too bad */
811 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
812 if (_err != noErr) return PyMac_Error(_err);
813 Py_INCREF(Py_None);
814 return Py_None;
818 static PyObject *Drag_RemoveTrackingHandler(PyObject *_self, PyObject *_args)
820 PyObject *_res = NULL;
822 WindowPtr theWindow = NULL;
823 OSErr _err;
825 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
826 return NULL;
827 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
828 if (_err != noErr) return PyMac_Error(_err);
829 Py_INCREF(Py_None);
830 return Py_None;
834 static PyObject *Drag_RemoveReceiveHandler(PyObject *_self, PyObject *_args)
836 PyObject *_res = NULL;
838 WindowPtr theWindow = NULL;
839 OSErr _err;
841 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
842 return NULL;
843 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
844 if (_err != noErr) return PyMac_Error(_err);
845 Py_INCREF(Py_None);
846 return Py_None;
850 static PyMethodDef Drag_methods[] = {
851 {"NewDrag", (PyCFunction)Drag_NewDrag, 1,
852 "() -> (DragRef theDrag)"},
853 {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1,
854 "(WindowPtr window) -> (RGBColor color)"},
855 {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1,
856 "(Point initialMouse) -> (Boolean _rv)"},
857 {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1,
858 "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
859 {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1,
860 "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
861 {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1,
862 NULL},
863 {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1,
864 NULL},
865 {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1,
866 NULL},
867 {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1,
868 NULL},
869 {NULL, NULL, 0}
874 static pascal OSErr
875 dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
876 void *handlerRefCon, DragReference theDrag)
878 PyObject *args, *rv;
879 int i;
881 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
882 if ( args == NULL )
883 return -1;
884 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
885 Py_DECREF(args);
886 if ( rv == NULL ) {
887 fprintf(stderr, "Drag: Exception in TrackingHandler\n");
888 return -1;
890 i = -1;
891 if ( rv == Py_None )
892 i = 0;
893 else
894 PyArg_Parse(rv, "l", &i);
895 Py_DECREF(rv);
896 return i;
899 static pascal OSErr
900 dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
901 DragReference theDrag)
903 PyObject *args, *rv;
904 int i;
906 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
907 if ( args == NULL )
908 return -1;
909 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
910 Py_DECREF(args);
911 if ( rv == NULL ) {
912 fprintf(stderr, "Drag: Exception in ReceiveHandler\n");
913 return -1;
915 i = -1;
916 if ( rv == Py_None )
917 i = 0;
918 else
919 PyArg_Parse(rv, "l", &i);
920 Py_DECREF(rv);
921 return i;
924 static pascal OSErr
925 dragglue_SendData(FlavorType theType, void *dragSendRefCon,
926 ItemReference theItem, DragReference theDrag)
928 DragObjObject *self = (DragObjObject *)dragSendRefCon;
929 PyObject *args, *rv;
930 int i;
932 if ( self->sendproc == NULL )
933 return -1;
934 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
935 if ( args == NULL )
936 return -1;
937 rv = PyEval_CallObject(self->sendproc, args);
938 Py_DECREF(args);
939 if ( rv == NULL ) {
940 fprintf(stderr, "Drag: Exception in SendDataHandler\n");
941 return -1;
943 i = -1;
944 if ( rv == Py_None )
945 i = 0;
946 else
947 PyArg_Parse(rv, "l", &i);
948 Py_DECREF(rv);
949 return i;
952 #if 0
953 static pascal OSErr
954 dragglue_Input(Point *mouse, short *modifiers,
955 void *dragSendRefCon, DragReference theDrag)
957 return 0;
960 static pascal OSErr
961 dragglue_Drawing(xxxx
962 void *dragSendRefCon, DragReference theDrag)
964 return 0;
966 #endif
970 void initDrag(void)
972 PyObject *m;
973 PyObject *d;
977 PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
978 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
981 m = Py_InitModule("Drag", Drag_methods);
982 d = PyModule_GetDict(m);
983 Drag_Error = PyMac_GetOSErrException();
984 if (Drag_Error == NULL ||
985 PyDict_SetItemString(d, "Error", Drag_Error) != 0)
986 return;
987 DragObj_Type.ob_type = &PyType_Type;
988 Py_INCREF(&DragObj_Type);
989 if (PyDict_SetItemString(d, "DragObjType", (PyObject *)&DragObj_Type) != 0)
990 Py_FatalError("can't initialize DragObjType");
992 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerUPP(dragglue_TrackingHandler);
993 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerUPP(dragglue_ReceiveHandler);
994 dragglue_SendDataUPP = NewDragSendDataUPP(dragglue_SendData);
995 #if 0
996 dragglue_InputUPP = NewDragInputUPP(dragglue_Input);
997 dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
998 #endif
1003 /* ======================== End module Drag ========================= */