Ditched '_find_SET()', since it was a no-value-added wrapper around
[python/dscho.git] / Mac / Modules / drag / Dragmodule.c
blob0775286046b6d327ad19bae2e1bb441797153e88
2 /* ========================== Module Drag =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern int ResObj_Convert(PyObject *, Handle *);
18 extern PyObject *OptResObj_New(Handle);
19 extern int OptResObj_Convert(PyObject *, Handle *);
21 extern PyObject *WinObj_New(WindowPtr);
22 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyTypeObject Window_Type;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject *DlgObj_New(DialogPtr);
27 extern int DlgObj_Convert(PyObject *, DialogPtr *);
28 extern PyTypeObject Dialog_Type;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject *MenuObj_New(MenuHandle);
32 extern int MenuObj_Convert(PyObject *, MenuHandle *);
34 extern PyObject *CtlObj_New(ControlHandle);
35 extern int CtlObj_Convert(PyObject *, ControlHandle *);
37 extern PyObject *GrafObj_New(GrafPtr);
38 extern int GrafObj_Convert(PyObject *, GrafPtr *);
40 extern PyObject *BMObj_New(BitMapPtr);
41 extern int BMObj_Convert(PyObject *, BitMapPtr *);
43 extern PyObject *WinObj_WhichWindow(WindowPtr);
45 #include <Drag.h>
47 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48 /* Exported by Qdmodule.c: */
49 extern PyObject *QdRGB_New(RGBColor *);
50 extern int QdRGB_Convert(PyObject *, RGBColor *);
53 /* Exported by AEModule.c: */
54 extern PyObject *AEDesc_New(AppleEvent *);
55 extern int AEDesc_Convert(PyObject *, AppleEvent *);
57 /* Callback glue routines */
58 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
59 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
60 DragSendDataUPP dragglue_SendDataUPP;
61 #if 0
62 DragInputUPP dragglue_InputUPP;
63 DragDrawingUPP dragglue_DrawingUPP;
64 #endif
66 static PyObject *Drag_Error;
68 /* ---------------------- Object type DragObj ----------------------- */
70 PyTypeObject DragObj_Type;
72 #define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
74 typedef struct DragObjObject {
75 PyObject_HEAD
76 DragReference ob_itself;
77 PyObject *sendproc;
78 } DragObjObject;
80 PyObject *DragObj_New(itself)
81 DragReference itself;
83 DragObjObject *it;
84 if (itself == NULL) {
85 PyErr_SetString(Drag_Error,"Cannot create null Drag");
86 return NULL;
88 it = PyObject_NEW(DragObjObject, &DragObj_Type);
89 if (it == NULL) return NULL;
90 it->ob_itself = itself;
91 it->sendproc = NULL;
92 return (PyObject *)it;
94 DragObj_Convert(v, p_itself)
95 PyObject *v;
96 DragReference *p_itself;
98 if (!DragObj_Check(v))
100 PyErr_SetString(PyExc_TypeError, "DragObj required");
101 return 0;
103 *p_itself = ((DragObjObject *)v)->ob_itself;
104 return 1;
107 static void DragObj_dealloc(self)
108 DragObjObject *self;
110 Py_XDECREF(self->sendproc);
111 PyMem_DEL(self);
114 static PyObject *DragObj_DisposeDrag(_self, _args)
115 DragObjObject *_self;
116 PyObject *_args;
118 PyObject *_res = NULL;
119 OSErr _err;
120 if (!PyArg_ParseTuple(_args, ""))
121 return NULL;
122 _err = DisposeDrag(_self->ob_itself);
123 if (_err != noErr) return PyMac_Error(_err);
124 Py_INCREF(Py_None);
125 _res = Py_None;
126 return _res;
129 static PyObject *DragObj_AddDragItemFlavor(_self, _args)
130 DragObjObject *_self;
131 PyObject *_args;
133 PyObject *_res = NULL;
134 OSErr _err;
135 ItemReference theItemRef;
136 FlavorType theType;
137 char *dataPtr__in__;
138 long dataPtr__len__;
139 int dataPtr__in_len__;
140 FlavorFlags theFlags;
141 if (!PyArg_ParseTuple(_args, "lO&z#l",
142 &theItemRef,
143 PyMac_GetOSType, &theType,
144 &dataPtr__in__, &dataPtr__in_len__,
145 &theFlags))
146 return NULL;
147 dataPtr__len__ = dataPtr__in_len__;
148 _err = AddDragItemFlavor(_self->ob_itself,
149 theItemRef,
150 theType,
151 dataPtr__in__, dataPtr__len__,
152 theFlags);
153 if (_err != noErr) return PyMac_Error(_err);
154 Py_INCREF(Py_None);
155 _res = Py_None;
156 dataPtr__error__: ;
157 return _res;
160 static PyObject *DragObj_SetDragItemFlavorData(_self, _args)
161 DragObjObject *_self;
162 PyObject *_args;
164 PyObject *_res = NULL;
165 OSErr _err;
166 ItemReference theItemRef;
167 FlavorType theType;
168 char *dataPtr__in__;
169 long dataPtr__len__;
170 int dataPtr__in_len__;
171 UInt32 dataOffset;
172 if (!PyArg_ParseTuple(_args, "lO&z#l",
173 &theItemRef,
174 PyMac_GetOSType, &theType,
175 &dataPtr__in__, &dataPtr__in_len__,
176 &dataOffset))
177 return NULL;
178 dataPtr__len__ = dataPtr__in_len__;
179 _err = SetDragItemFlavorData(_self->ob_itself,
180 theItemRef,
181 theType,
182 dataPtr__in__, dataPtr__len__,
183 dataOffset);
184 if (_err != noErr) return PyMac_Error(_err);
185 Py_INCREF(Py_None);
186 _res = Py_None;
187 dataPtr__error__: ;
188 return _res;
191 static PyObject *DragObj_SetDragImage(_self, _args)
192 DragObjObject *_self;
193 PyObject *_args;
195 PyObject *_res = NULL;
196 OSErr _err;
197 PixMapHandle imagePixMap;
198 RgnHandle imageRgn;
199 Point imageOffsetPt;
200 DragImageFlags theImageFlags;
201 if (!PyArg_ParseTuple(_args, "O&O&O&l",
202 ResObj_Convert, &imagePixMap,
203 ResObj_Convert, &imageRgn,
204 PyMac_GetPoint, &imageOffsetPt,
205 &theImageFlags))
206 return NULL;
207 _err = SetDragImage(_self->ob_itself,
208 imagePixMap,
209 imageRgn,
210 imageOffsetPt,
211 theImageFlags);
212 if (_err != noErr) return PyMac_Error(_err);
213 Py_INCREF(Py_None);
214 _res = Py_None;
215 return _res;
218 static PyObject *DragObj_TrackDrag(_self, _args)
219 DragObjObject *_self;
220 PyObject *_args;
222 PyObject *_res = NULL;
223 OSErr _err;
224 EventRecord theEvent;
225 RgnHandle theRegion;
226 if (!PyArg_ParseTuple(_args, "O&O&",
227 PyMac_GetEventRecord, &theEvent,
228 ResObj_Convert, &theRegion))
229 return NULL;
230 _err = TrackDrag(_self->ob_itself,
231 &theEvent,
232 theRegion);
233 if (_err != noErr) return PyMac_Error(_err);
234 Py_INCREF(Py_None);
235 _res = Py_None;
236 return _res;
239 static PyObject *DragObj_CountDragItems(_self, _args)
240 DragObjObject *_self;
241 PyObject *_args;
243 PyObject *_res = NULL;
244 OSErr _err;
245 UInt16 numItems;
246 if (!PyArg_ParseTuple(_args, ""))
247 return NULL;
248 _err = CountDragItems(_self->ob_itself,
249 &numItems);
250 if (_err != noErr) return PyMac_Error(_err);
251 _res = Py_BuildValue("h",
252 numItems);
253 return _res;
256 static PyObject *DragObj_GetDragItemReferenceNumber(_self, _args)
257 DragObjObject *_self;
258 PyObject *_args;
260 PyObject *_res = NULL;
261 OSErr _err;
262 UInt16 index;
263 ItemReference theItemRef;
264 if (!PyArg_ParseTuple(_args, "h",
265 &index))
266 return NULL;
267 _err = GetDragItemReferenceNumber(_self->ob_itself,
268 index,
269 &theItemRef);
270 if (_err != noErr) return PyMac_Error(_err);
271 _res = Py_BuildValue("l",
272 theItemRef);
273 return _res;
276 static PyObject *DragObj_CountDragItemFlavors(_self, _args)
277 DragObjObject *_self;
278 PyObject *_args;
280 PyObject *_res = NULL;
281 OSErr _err;
282 ItemReference theItemRef;
283 UInt16 numFlavors;
284 if (!PyArg_ParseTuple(_args, "l",
285 &theItemRef))
286 return NULL;
287 _err = CountDragItemFlavors(_self->ob_itself,
288 theItemRef,
289 &numFlavors);
290 if (_err != noErr) return PyMac_Error(_err);
291 _res = Py_BuildValue("h",
292 numFlavors);
293 return _res;
296 static PyObject *DragObj_GetFlavorType(_self, _args)
297 DragObjObject *_self;
298 PyObject *_args;
300 PyObject *_res = NULL;
301 OSErr _err;
302 ItemReference theItemRef;
303 UInt16 index;
304 FlavorType theType;
305 if (!PyArg_ParseTuple(_args, "lh",
306 &theItemRef,
307 &index))
308 return NULL;
309 _err = GetFlavorType(_self->ob_itself,
310 theItemRef,
311 index,
312 &theType);
313 if (_err != noErr) return PyMac_Error(_err);
314 _res = Py_BuildValue("O&",
315 PyMac_BuildOSType, theType);
316 return _res;
319 static PyObject *DragObj_GetFlavorFlags(_self, _args)
320 DragObjObject *_self;
321 PyObject *_args;
323 PyObject *_res = NULL;
324 OSErr _err;
325 ItemReference theItemRef;
326 FlavorType theType;
327 FlavorFlags theFlags;
328 if (!PyArg_ParseTuple(_args, "lO&",
329 &theItemRef,
330 PyMac_GetOSType, &theType))
331 return NULL;
332 _err = GetFlavorFlags(_self->ob_itself,
333 theItemRef,
334 theType,
335 &theFlags);
336 if (_err != noErr) return PyMac_Error(_err);
337 _res = Py_BuildValue("l",
338 theFlags);
339 return _res;
342 static PyObject *DragObj_GetFlavorDataSize(_self, _args)
343 DragObjObject *_self;
344 PyObject *_args;
346 PyObject *_res = NULL;
347 OSErr _err;
348 ItemReference theItemRef;
349 FlavorType theType;
350 Size dataSize;
351 if (!PyArg_ParseTuple(_args, "lO&",
352 &theItemRef,
353 PyMac_GetOSType, &theType))
354 return NULL;
355 _err = GetFlavorDataSize(_self->ob_itself,
356 theItemRef,
357 theType,
358 &dataSize);
359 if (_err != noErr) return PyMac_Error(_err);
360 _res = Py_BuildValue("l",
361 dataSize);
362 return _res;
365 static PyObject *DragObj_GetFlavorData(_self, _args)
366 DragObjObject *_self;
367 PyObject *_args;
369 PyObject *_res = NULL;
370 OSErr _err;
371 ItemReference theItemRef;
372 FlavorType theType;
373 char *dataPtr__out__;
374 long dataPtr__len__;
375 int dataPtr__in_len__;
376 UInt32 dataOffset;
377 if (!PyArg_ParseTuple(_args, "lO&il",
378 &theItemRef,
379 PyMac_GetOSType, &theType,
380 &dataPtr__in_len__,
381 &dataOffset))
382 return NULL;
383 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
385 PyErr_NoMemory();
386 goto dataPtr__error__;
388 dataPtr__len__ = dataPtr__in_len__;
389 _err = GetFlavorData(_self->ob_itself,
390 theItemRef,
391 theType,
392 dataPtr__out__, &dataPtr__len__,
393 dataOffset);
394 if (_err != noErr) return PyMac_Error(_err);
395 _res = Py_BuildValue("s#",
396 dataPtr__out__, (int)dataPtr__len__);
397 free(dataPtr__out__);
398 dataPtr__error__: ;
399 return _res;
402 static PyObject *DragObj_GetDragItemBounds(_self, _args)
403 DragObjObject *_self;
404 PyObject *_args;
406 PyObject *_res = NULL;
407 OSErr _err;
408 ItemReference theItemRef;
409 Rect itemBounds;
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;
422 static PyObject *DragObj_SetDragItemBounds(_self, _args)
423 DragObjObject *_self;
424 PyObject *_args;
426 PyObject *_res = NULL;
427 OSErr _err;
428 ItemReference theItemRef;
429 Rect itemBounds;
430 if (!PyArg_ParseTuple(_args, "lO&",
431 &theItemRef,
432 PyMac_GetRect, &itemBounds))
433 return NULL;
434 _err = SetDragItemBounds(_self->ob_itself,
435 theItemRef,
436 &itemBounds);
437 if (_err != noErr) return PyMac_Error(_err);
438 Py_INCREF(Py_None);
439 _res = Py_None;
440 return _res;
443 static PyObject *DragObj_GetDropLocation(_self, _args)
444 DragObjObject *_self;
445 PyObject *_args;
447 PyObject *_res = NULL;
448 OSErr _err;
449 AEDesc dropLocation;
450 if (!PyArg_ParseTuple(_args, ""))
451 return NULL;
452 _err = GetDropLocation(_self->ob_itself,
453 &dropLocation);
454 if (_err != noErr) return PyMac_Error(_err);
455 _res = Py_BuildValue("O&",
456 AEDesc_New, &dropLocation);
457 return _res;
460 static PyObject *DragObj_SetDropLocation(_self, _args)
461 DragObjObject *_self;
462 PyObject *_args;
464 PyObject *_res = NULL;
465 OSErr _err;
466 AEDesc dropLocation;
467 if (!PyArg_ParseTuple(_args, "O&",
468 AEDesc_Convert, &dropLocation))
469 return NULL;
470 _err = SetDropLocation(_self->ob_itself,
471 &dropLocation);
472 if (_err != noErr) return PyMac_Error(_err);
473 Py_INCREF(Py_None);
474 _res = Py_None;
475 return _res;
478 static PyObject *DragObj_GetDragAttributes(_self, _args)
479 DragObjObject *_self;
480 PyObject *_args;
482 PyObject *_res = NULL;
483 OSErr _err;
484 DragAttributes flags;
485 if (!PyArg_ParseTuple(_args, ""))
486 return NULL;
487 _err = GetDragAttributes(_self->ob_itself,
488 &flags);
489 if (_err != noErr) return PyMac_Error(_err);
490 _res = Py_BuildValue("l",
491 flags);
492 return _res;
495 static PyObject *DragObj_GetDragMouse(_self, _args)
496 DragObjObject *_self;
497 PyObject *_args;
499 PyObject *_res = NULL;
500 OSErr _err;
501 Point mouse;
502 Point globalPinnedMouse;
503 if (!PyArg_ParseTuple(_args, ""))
504 return NULL;
505 _err = GetDragMouse(_self->ob_itself,
506 &mouse,
507 &globalPinnedMouse);
508 if (_err != noErr) return PyMac_Error(_err);
509 _res = Py_BuildValue("O&O&",
510 PyMac_BuildPoint, mouse,
511 PyMac_BuildPoint, globalPinnedMouse);
512 return _res;
515 static PyObject *DragObj_SetDragMouse(_self, _args)
516 DragObjObject *_self;
517 PyObject *_args;
519 PyObject *_res = NULL;
520 OSErr _err;
521 Point globalPinnedMouse;
522 if (!PyArg_ParseTuple(_args, "O&",
523 PyMac_GetPoint, &globalPinnedMouse))
524 return NULL;
525 _err = SetDragMouse(_self->ob_itself,
526 globalPinnedMouse);
527 if (_err != noErr) return PyMac_Error(_err);
528 Py_INCREF(Py_None);
529 _res = Py_None;
530 return _res;
533 static PyObject *DragObj_GetDragOrigin(_self, _args)
534 DragObjObject *_self;
535 PyObject *_args;
537 PyObject *_res = NULL;
538 OSErr _err;
539 Point globalInitialMouse;
540 if (!PyArg_ParseTuple(_args, ""))
541 return NULL;
542 _err = GetDragOrigin(_self->ob_itself,
543 &globalInitialMouse);
544 if (_err != noErr) return PyMac_Error(_err);
545 _res = Py_BuildValue("O&",
546 PyMac_BuildPoint, globalInitialMouse);
547 return _res;
550 static PyObject *DragObj_GetDragModifiers(_self, _args)
551 DragObjObject *_self;
552 PyObject *_args;
554 PyObject *_res = NULL;
555 OSErr _err;
556 SInt16 modifiers;
557 SInt16 mouseDownModifiers;
558 SInt16 mouseUpModifiers;
559 if (!PyArg_ParseTuple(_args, ""))
560 return NULL;
561 _err = GetDragModifiers(_self->ob_itself,
562 &modifiers,
563 &mouseDownModifiers,
564 &mouseUpModifiers);
565 if (_err != noErr) return PyMac_Error(_err);
566 _res = Py_BuildValue("hhh",
567 modifiers,
568 mouseDownModifiers,
569 mouseUpModifiers);
570 return _res;
573 static PyObject *DragObj_ShowDragHilite(_self, _args)
574 DragObjObject *_self;
575 PyObject *_args;
577 PyObject *_res = NULL;
578 OSErr _err;
579 RgnHandle hiliteFrame;
580 Boolean inside;
581 if (!PyArg_ParseTuple(_args, "O&b",
582 ResObj_Convert, &hiliteFrame,
583 &inside))
584 return NULL;
585 _err = ShowDragHilite(_self->ob_itself,
586 hiliteFrame,
587 inside);
588 if (_err != noErr) return PyMac_Error(_err);
589 Py_INCREF(Py_None);
590 _res = Py_None;
591 return _res;
594 static PyObject *DragObj_HideDragHilite(_self, _args)
595 DragObjObject *_self;
596 PyObject *_args;
598 PyObject *_res = NULL;
599 OSErr _err;
600 if (!PyArg_ParseTuple(_args, ""))
601 return NULL;
602 _err = HideDragHilite(_self->ob_itself);
603 if (_err != noErr) return PyMac_Error(_err);
604 Py_INCREF(Py_None);
605 _res = Py_None;
606 return _res;
609 static PyObject *DragObj_DragPreScroll(_self, _args)
610 DragObjObject *_self;
611 PyObject *_args;
613 PyObject *_res = NULL;
614 OSErr _err;
615 SInt16 dH;
616 SInt16 dV;
617 if (!PyArg_ParseTuple(_args, "hh",
618 &dH,
619 &dV))
620 return NULL;
621 _err = DragPreScroll(_self->ob_itself,
623 dV);
624 if (_err != noErr) return PyMac_Error(_err);
625 Py_INCREF(Py_None);
626 _res = Py_None;
627 return _res;
630 static PyObject *DragObj_DragPostScroll(_self, _args)
631 DragObjObject *_self;
632 PyObject *_args;
634 PyObject *_res = NULL;
635 OSErr _err;
636 if (!PyArg_ParseTuple(_args, ""))
637 return NULL;
638 _err = DragPostScroll(_self->ob_itself);
639 if (_err != noErr) return PyMac_Error(_err);
640 Py_INCREF(Py_None);
641 _res = Py_None;
642 return _res;
645 static PyObject *DragObj_UpdateDragHilite(_self, _args)
646 DragObjObject *_self;
647 PyObject *_args;
649 PyObject *_res = NULL;
650 OSErr _err;
651 RgnHandle updateRgn;
652 if (!PyArg_ParseTuple(_args, "O&",
653 ResObj_Convert, &updateRgn))
654 return NULL;
655 _err = UpdateDragHilite(_self->ob_itself,
656 updateRgn);
657 if (_err != noErr) return PyMac_Error(_err);
658 Py_INCREF(Py_None);
659 _res = Py_None;
660 return _res;
663 static PyMethodDef DragObj_methods[] = {
664 {"DisposeDrag", (PyCFunction)DragObj_DisposeDrag, 1,
665 "() -> None"},
666 {"AddDragItemFlavor", (PyCFunction)DragObj_AddDragItemFlavor, 1,
667 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"},
668 {"SetDragItemFlavorData", (PyCFunction)DragObj_SetDragItemFlavorData, 1,
669 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"},
670 {"SetDragImage", (PyCFunction)DragObj_SetDragImage, 1,
671 "(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"},
672 {"TrackDrag", (PyCFunction)DragObj_TrackDrag, 1,
673 "(EventRecord theEvent, RgnHandle theRegion) -> None"},
674 {"CountDragItems", (PyCFunction)DragObj_CountDragItems, 1,
675 "() -> (UInt16 numItems)"},
676 {"GetDragItemReferenceNumber", (PyCFunction)DragObj_GetDragItemReferenceNumber, 1,
677 "(UInt16 index) -> (ItemReference theItemRef)"},
678 {"CountDragItemFlavors", (PyCFunction)DragObj_CountDragItemFlavors, 1,
679 "(ItemReference theItemRef) -> (UInt16 numFlavors)"},
680 {"GetFlavorType", (PyCFunction)DragObj_GetFlavorType, 1,
681 "(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"},
682 {"GetFlavorFlags", (PyCFunction)DragObj_GetFlavorFlags, 1,
683 "(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"},
684 {"GetFlavorDataSize", (PyCFunction)DragObj_GetFlavorDataSize, 1,
685 "(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"},
686 {"GetFlavorData", (PyCFunction)DragObj_GetFlavorData, 1,
687 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"},
688 {"GetDragItemBounds", (PyCFunction)DragObj_GetDragItemBounds, 1,
689 "(ItemReference theItemRef) -> (Rect itemBounds)"},
690 {"SetDragItemBounds", (PyCFunction)DragObj_SetDragItemBounds, 1,
691 "(ItemReference theItemRef, Rect itemBounds) -> None"},
692 {"GetDropLocation", (PyCFunction)DragObj_GetDropLocation, 1,
693 "() -> (AEDesc dropLocation)"},
694 {"SetDropLocation", (PyCFunction)DragObj_SetDropLocation, 1,
695 "(AEDesc dropLocation) -> None"},
696 {"GetDragAttributes", (PyCFunction)DragObj_GetDragAttributes, 1,
697 "() -> (DragAttributes flags)"},
698 {"GetDragMouse", (PyCFunction)DragObj_GetDragMouse, 1,
699 "() -> (Point mouse, Point globalPinnedMouse)"},
700 {"SetDragMouse", (PyCFunction)DragObj_SetDragMouse, 1,
701 "(Point globalPinnedMouse) -> None"},
702 {"GetDragOrigin", (PyCFunction)DragObj_GetDragOrigin, 1,
703 "() -> (Point globalInitialMouse)"},
704 {"GetDragModifiers", (PyCFunction)DragObj_GetDragModifiers, 1,
705 "() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"},
706 {"ShowDragHilite", (PyCFunction)DragObj_ShowDragHilite, 1,
707 "(RgnHandle hiliteFrame, Boolean inside) -> None"},
708 {"HideDragHilite", (PyCFunction)DragObj_HideDragHilite, 1,
709 "() -> None"},
710 {"DragPreScroll", (PyCFunction)DragObj_DragPreScroll, 1,
711 "(SInt16 dH, SInt16 dV) -> None"},
712 {"DragPostScroll", (PyCFunction)DragObj_DragPostScroll, 1,
713 "() -> None"},
714 {"UpdateDragHilite", (PyCFunction)DragObj_UpdateDragHilite, 1,
715 "(RgnHandle updateRgn) -> None"},
716 {NULL, NULL, 0}
719 PyMethodChain DragObj_chain = { DragObj_methods, NULL };
721 static PyObject *DragObj_getattr(self, name)
722 DragObjObject *self;
723 char *name;
725 return Py_FindMethodInChain(&DragObj_chain, (PyObject *)self, name);
728 #define DragObj_setattr NULL
730 #define DragObj_compare NULL
732 #define DragObj_repr NULL
734 #define DragObj_hash NULL
736 PyTypeObject DragObj_Type = {
737 PyObject_HEAD_INIT(&PyType_Type)
738 0, /*ob_size*/
739 "DragObj", /*tp_name*/
740 sizeof(DragObjObject), /*tp_basicsize*/
741 0, /*tp_itemsize*/
742 /* methods */
743 (destructor) DragObj_dealloc, /*tp_dealloc*/
744 0, /*tp_print*/
745 (getattrfunc) DragObj_getattr, /*tp_getattr*/
746 (setattrfunc) DragObj_setattr, /*tp_setattr*/
747 (cmpfunc) DragObj_compare, /*tp_compare*/
748 (reprfunc) DragObj_repr, /*tp_repr*/
749 (PyNumberMethods *)0, /* tp_as_number */
750 (PySequenceMethods *)0, /* tp_as_sequence */
751 (PyMappingMethods *)0, /* tp_as_mapping */
752 (hashfunc) DragObj_hash, /*tp_hash*/
755 /* -------------------- End object type DragObj --------------------- */
758 static PyObject *Drag_NewDrag(_self, _args)
759 PyObject *_self;
760 PyObject *_args;
762 PyObject *_res = NULL;
763 OSErr _err;
764 DragReference theDrag;
765 if (!PyArg_ParseTuple(_args, ""))
766 return NULL;
767 _err = NewDrag(&theDrag);
768 if (_err != noErr) return PyMac_Error(_err);
769 _res = Py_BuildValue("O&",
770 DragObj_New, theDrag);
771 return _res;
774 static PyObject *Drag_GetDragHiliteColor(_self, _args)
775 PyObject *_self;
776 PyObject *_args;
778 PyObject *_res = NULL;
779 OSErr _err;
780 WindowPtr window;
781 RGBColor color;
782 if (!PyArg_ParseTuple(_args, "O&",
783 WinObj_Convert, &window))
784 return NULL;
785 _err = GetDragHiliteColor(window,
786 &color);
787 if (_err != noErr) return PyMac_Error(_err);
788 _res = Py_BuildValue("O&",
789 QdRGB_New, &color);
790 return _res;
793 static PyObject *Drag_WaitMouseMoved(_self, _args)
794 PyObject *_self;
795 PyObject *_args;
797 PyObject *_res = NULL;
798 Boolean _rv;
799 Point initialMouse;
800 if (!PyArg_ParseTuple(_args, "O&",
801 PyMac_GetPoint, &initialMouse))
802 return NULL;
803 _rv = WaitMouseMoved(initialMouse);
804 _res = Py_BuildValue("b",
805 _rv);
806 return _res;
809 static PyObject *Drag_ZoomRects(_self, _args)
810 PyObject *_self;
811 PyObject *_args;
813 PyObject *_res = NULL;
814 OSErr _err;
815 Rect fromRect;
816 Rect toRect;
817 SInt16 zoomSteps;
818 ZoomAcceleration acceleration;
819 if (!PyArg_ParseTuple(_args, "O&O&hh",
820 PyMac_GetRect, &fromRect,
821 PyMac_GetRect, &toRect,
822 &zoomSteps,
823 &acceleration))
824 return NULL;
825 _err = ZoomRects(&fromRect,
826 &toRect,
827 zoomSteps,
828 acceleration);
829 if (_err != noErr) return PyMac_Error(_err);
830 Py_INCREF(Py_None);
831 _res = Py_None;
832 return _res;
835 static PyObject *Drag_ZoomRegion(_self, _args)
836 PyObject *_self;
837 PyObject *_args;
839 PyObject *_res = NULL;
840 OSErr _err;
841 RgnHandle region;
842 Point zoomDistance;
843 SInt16 zoomSteps;
844 ZoomAcceleration acceleration;
845 if (!PyArg_ParseTuple(_args, "O&O&hh",
846 ResObj_Convert, &region,
847 PyMac_GetPoint, &zoomDistance,
848 &zoomSteps,
849 &acceleration))
850 return NULL;
851 _err = ZoomRegion(region,
852 zoomDistance,
853 zoomSteps,
854 acceleration);
855 if (_err != noErr) return PyMac_Error(_err);
856 Py_INCREF(Py_None);
857 _res = Py_None;
858 return _res;
861 static PyObject *Drag_InstallTrackingHandler(_self, _args)
862 PyObject *_self;
863 PyObject *_args;
865 PyObject *_res = NULL;
867 PyObject *callback;
868 WindowPtr theWindow = NULL;
869 OSErr _err;
871 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
872 return NULL;
873 Py_INCREF(callback); /* Cannot decref later, too bad */
874 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
875 if (_err != noErr) return PyMac_Error(_err);
876 Py_INCREF(Py_None);
877 return Py_None;
881 static PyObject *Drag_InstallReceiveHandler(_self, _args)
882 PyObject *_self;
883 PyObject *_args;
885 PyObject *_res = NULL;
887 PyObject *callback;
888 WindowPtr theWindow = NULL;
889 OSErr _err;
891 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
892 return NULL;
893 Py_INCREF(callback); /* Cannot decref later, too bad */
894 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
895 if (_err != noErr) return PyMac_Error(_err);
896 Py_INCREF(Py_None);
897 return Py_None;
901 static PyObject *Drag_RemoveTrackingHandler(_self, _args)
902 PyObject *_self;
903 PyObject *_args;
905 PyObject *_res = NULL;
907 WindowPtr theWindow = NULL;
908 OSErr _err;
910 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
911 return NULL;
912 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
913 if (_err != noErr) return PyMac_Error(_err);
914 Py_INCREF(Py_None);
915 return Py_None;
919 static PyObject *Drag_RemoveReceiveHandler(_self, _args)
920 PyObject *_self;
921 PyObject *_args;
923 PyObject *_res = NULL;
925 WindowPtr theWindow = NULL;
926 OSErr _err;
928 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
929 return NULL;
930 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
931 if (_err != noErr) return PyMac_Error(_err);
932 Py_INCREF(Py_None);
933 return Py_None;
937 static PyMethodDef Drag_methods[] = {
938 {"NewDrag", (PyCFunction)Drag_NewDrag, 1,
939 "() -> (DragReference theDrag)"},
940 {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1,
941 "(WindowPtr window) -> (RGBColor color)"},
942 {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1,
943 "(Point initialMouse) -> (Boolean _rv)"},
944 {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1,
945 "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
946 {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1,
947 "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
948 {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1,
949 NULL},
950 {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1,
951 NULL},
952 {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1,
953 NULL},
954 {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1,
955 NULL},
956 {NULL, NULL, 0}
961 static pascal OSErr
962 dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
963 void *handlerRefCon, DragReference theDrag)
965 PyObject *args, *rv;
966 int i;
968 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
969 if ( args == NULL )
970 return -1;
971 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
972 Py_DECREF(args);
973 if ( rv == NULL ) {
974 fprintf(stderr, "Drag: Exception in TrackingHandler\n");
975 return -1;
977 i = -1;
978 if ( rv == Py_None )
979 i = 0;
980 else
981 PyArg_Parse(rv, "l", &i);
982 Py_DECREF(rv);
983 return i;
986 static pascal OSErr
987 dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
988 DragReference theDrag)
990 PyObject *args, *rv;
991 int i;
993 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
994 if ( args == NULL )
995 return -1;
996 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
997 Py_DECREF(args);
998 if ( rv == NULL ) {
999 fprintf(stderr, "Drag: Exception in ReceiveHandler\n");
1000 return -1;
1002 i = -1;
1003 if ( rv == Py_None )
1004 i = 0;
1005 else
1006 PyArg_Parse(rv, "l", &i);
1007 Py_DECREF(rv);
1008 return i;
1011 static pascal OSErr
1012 dragglue_SendData(FlavorType theType, void *dragSendRefCon,
1013 ItemReference theItem, DragReference theDrag)
1015 DragObjObject *self = (DragObjObject *)dragSendRefCon;
1016 PyObject *args, *rv;
1017 int i;
1019 if ( self->sendproc == NULL )
1020 return -1;
1021 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
1022 if ( args == NULL )
1023 return -1;
1024 rv = PyEval_CallObject(self->sendproc, args);
1025 Py_DECREF(args);
1026 if ( rv == NULL ) {
1027 fprintf(stderr, "Drag: Exception in SendDataHandler\n");
1028 return -1;
1030 i = -1;
1031 if ( rv == Py_None )
1032 i = 0;
1033 else
1034 PyArg_Parse(rv, "l", &i);
1035 Py_DECREF(rv);
1036 return i;
1039 #if 0
1040 static pascal OSErr
1041 dragglue_Input(Point *mouse, short *modifiers,
1042 void *dragSendRefCon, DragReference theDrag)
1044 return 0;
1047 static pascal OSErr
1048 dragglue_Drawing(xxxx
1049 void *dragSendRefCon, DragReference theDrag)
1051 return 0;
1053 #endif
1057 void initDrag()
1059 PyObject *m;
1060 PyObject *d;
1065 m = Py_InitModule("Drag", Drag_methods);
1066 d = PyModule_GetDict(m);
1067 Drag_Error = PyMac_GetOSErrException();
1068 if (Drag_Error == NULL ||
1069 PyDict_SetItemString(d, "Error", Drag_Error) != 0)
1070 Py_FatalError("can't initialize Drag.Error");
1071 DragObj_Type.ob_type = &PyType_Type;
1072 Py_INCREF(&DragObj_Type);
1073 if (PyDict_SetItemString(d, "DragObjType", (PyObject *)&DragObj_Type) != 0)
1074 Py_FatalError("can't initialize DragObjType");
1076 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler);
1077 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler);
1078 dragglue_SendDataUPP = NewDragSendDataProc(dragglue_SendData);
1079 #if 0
1080 dragglue_InputUPP = NewDragInputProc(dragglue_Input);
1081 dragglue_DrawingUPP = NewDragDrawingProc(dragglue_Drawing);
1082 #endif
1087 /* ======================== End module Drag ========================= */