blob: 716d2d5ff7c38a44ec3f1e4ae94d398443b3f96b [file] [log] [blame]
Jack Jansenc4f63311999-06-21 15:14:26 +00001
2/* ========================== Module Drag =========================== */
3
4#include "Python.h"
5
6
7
Jack Jansenc4f63311999-06-21 15:14:26 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Jack Jansenc4f63311999-06-21 15:14:26 +000010
11#include <Drag.h>
12
Jack Jansenc4f63311999-06-21 15:14:26 +000013/* Callback glue routines */
14DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
15DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
16DragSendDataUPP dragglue_SendDataUPP;
17#if 0
18DragInputUPP dragglue_InputUPP;
19DragDrawingUPP dragglue_DrawingUPP;
20#endif
21
22static PyObject *Drag_Error;
23
24/* ---------------------- Object type DragObj ----------------------- */
25
26PyTypeObject DragObj_Type;
27
28#define DragObj_Check(x) ((x)->ob_type == &DragObj_Type)
29
30typedef struct DragObjObject {
31 PyObject_HEAD
32 DragReference ob_itself;
33 PyObject *sendproc;
34} DragObjObject;
35
36PyObject *DragObj_New(itself)
37 DragReference itself;
38{
39 DragObjObject *it;
40 if (itself == NULL) {
41 PyErr_SetString(Drag_Error,"Cannot create null Drag");
42 return NULL;
43 }
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;
49}
50DragObj_Convert(v, p_itself)
51 PyObject *v;
52 DragReference *p_itself;
53{
54 if (!DragObj_Check(v))
55 {
56 PyErr_SetString(PyExc_TypeError, "DragObj required");
57 return 0;
58 }
59 *p_itself = ((DragObjObject *)v)->ob_itself;
60 return 1;
61}
62
63static void DragObj_dealloc(self)
64 DragObjObject *self;
65{
66 Py_XDECREF(self->sendproc);
67 PyMem_DEL(self);
68}
69
70static PyObject *DragObj_DisposeDrag(_self, _args)
71 DragObjObject *_self;
72 PyObject *_args;
73{
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;
83}
84
85static PyObject *DragObj_AddDragItemFlavor(_self, _args)
86 DragObjObject *_self;
87 PyObject *_args;
88{
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;
114}
115
116static PyObject *DragObj_SetDragItemFlavorData(_self, _args)
117 DragObjObject *_self;
118 PyObject *_args;
119{
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;
145}
146
147static PyObject *DragObj_SetDragImage(_self, _args)
148 DragObjObject *_self;
149 PyObject *_args;
150{
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;
172}
173
174static PyObject *DragObj_TrackDrag(_self, _args)
175 DragObjObject *_self;
176 PyObject *_args;
177{
178 PyObject *_res = NULL;
179 OSErr _err;
180 EventRecord theEvent;
181 RgnHandle theRegion;
182 if (!PyArg_ParseTuple(_args, "O&O&",
183 PyMac_GetEventRecord, &theEvent,
184 ResObj_Convert, &theRegion))
185 return NULL;
186 _err = TrackDrag(_self->ob_itself,
187 &theEvent,
188 theRegion);
189 if (_err != noErr) return PyMac_Error(_err);
190 Py_INCREF(Py_None);
191 _res = Py_None;
192 return _res;
193}
194
195static PyObject *DragObj_CountDragItems(_self, _args)
196 DragObjObject *_self;
197 PyObject *_args;
198{
199 PyObject *_res = NULL;
200 OSErr _err;
201 UInt16 numItems;
202 if (!PyArg_ParseTuple(_args, ""))
203 return NULL;
204 _err = CountDragItems(_self->ob_itself,
205 &numItems);
206 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000207 _res = Py_BuildValue("H",
Jack Jansenc4f63311999-06-21 15:14:26 +0000208 numItems);
209 return _res;
210}
211
212static PyObject *DragObj_GetDragItemReferenceNumber(_self, _args)
213 DragObjObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
217 OSErr _err;
218 UInt16 index;
219 ItemReference theItemRef;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000220 if (!PyArg_ParseTuple(_args, "H",
Jack Jansenc4f63311999-06-21 15:14:26 +0000221 &index))
222 return NULL;
223 _err = GetDragItemReferenceNumber(_self->ob_itself,
224 index,
225 &theItemRef);
226 if (_err != noErr) return PyMac_Error(_err);
227 _res = Py_BuildValue("l",
228 theItemRef);
229 return _res;
230}
231
232static PyObject *DragObj_CountDragItemFlavors(_self, _args)
233 DragObjObject *_self;
234 PyObject *_args;
235{
236 PyObject *_res = NULL;
237 OSErr _err;
238 ItemReference theItemRef;
239 UInt16 numFlavors;
240 if (!PyArg_ParseTuple(_args, "l",
241 &theItemRef))
242 return NULL;
243 _err = CountDragItemFlavors(_self->ob_itself,
244 theItemRef,
245 &numFlavors);
246 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000247 _res = Py_BuildValue("H",
Jack Jansenc4f63311999-06-21 15:14:26 +0000248 numFlavors);
249 return _res;
250}
251
252static PyObject *DragObj_GetFlavorType(_self, _args)
253 DragObjObject *_self;
254 PyObject *_args;
255{
256 PyObject *_res = NULL;
257 OSErr _err;
258 ItemReference theItemRef;
259 UInt16 index;
260 FlavorType theType;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000261 if (!PyArg_ParseTuple(_args, "lH",
Jack Jansenc4f63311999-06-21 15:14:26 +0000262 &theItemRef,
263 &index))
264 return NULL;
265 _err = GetFlavorType(_self->ob_itself,
266 theItemRef,
267 index,
268 &theType);
269 if (_err != noErr) return PyMac_Error(_err);
270 _res = Py_BuildValue("O&",
271 PyMac_BuildOSType, theType);
272 return _res;
273}
274
275static PyObject *DragObj_GetFlavorFlags(_self, _args)
276 DragObjObject *_self;
277 PyObject *_args;
278{
279 PyObject *_res = NULL;
280 OSErr _err;
281 ItemReference theItemRef;
282 FlavorType theType;
283 FlavorFlags theFlags;
284 if (!PyArg_ParseTuple(_args, "lO&",
285 &theItemRef,
286 PyMac_GetOSType, &theType))
287 return NULL;
288 _err = GetFlavorFlags(_self->ob_itself,
289 theItemRef,
290 theType,
291 &theFlags);
292 if (_err != noErr) return PyMac_Error(_err);
293 _res = Py_BuildValue("l",
294 theFlags);
295 return _res;
296}
297
298static PyObject *DragObj_GetFlavorDataSize(_self, _args)
299 DragObjObject *_self;
300 PyObject *_args;
301{
302 PyObject *_res = NULL;
303 OSErr _err;
304 ItemReference theItemRef;
305 FlavorType theType;
306 Size dataSize;
307 if (!PyArg_ParseTuple(_args, "lO&",
308 &theItemRef,
309 PyMac_GetOSType, &theType))
310 return NULL;
311 _err = GetFlavorDataSize(_self->ob_itself,
312 theItemRef,
313 theType,
314 &dataSize);
315 if (_err != noErr) return PyMac_Error(_err);
316 _res = Py_BuildValue("l",
317 dataSize);
318 return _res;
319}
320
321static PyObject *DragObj_GetFlavorData(_self, _args)
322 DragObjObject *_self;
323 PyObject *_args;
324{
325 PyObject *_res = NULL;
326 OSErr _err;
327 ItemReference theItemRef;
328 FlavorType theType;
329 char *dataPtr__out__;
330 long dataPtr__len__;
331 int dataPtr__in_len__;
332 UInt32 dataOffset;
333 if (!PyArg_ParseTuple(_args, "lO&il",
334 &theItemRef,
335 PyMac_GetOSType, &theType,
336 &dataPtr__in_len__,
337 &dataOffset))
338 return NULL;
339 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
340 {
341 PyErr_NoMemory();
342 goto dataPtr__error__;
343 }
344 dataPtr__len__ = dataPtr__in_len__;
345 _err = GetFlavorData(_self->ob_itself,
346 theItemRef,
347 theType,
348 dataPtr__out__, &dataPtr__len__,
349 dataOffset);
350 if (_err != noErr) return PyMac_Error(_err);
351 _res = Py_BuildValue("s#",
352 dataPtr__out__, (int)dataPtr__len__);
353 free(dataPtr__out__);
354 dataPtr__error__: ;
355 return _res;
356}
357
358static PyObject *DragObj_GetDragItemBounds(_self, _args)
359 DragObjObject *_self;
360 PyObject *_args;
361{
362 PyObject *_res = NULL;
363 OSErr _err;
364 ItemReference theItemRef;
365 Rect itemBounds;
366 if (!PyArg_ParseTuple(_args, "l",
367 &theItemRef))
368 return NULL;
369 _err = GetDragItemBounds(_self->ob_itself,
370 theItemRef,
371 &itemBounds);
372 if (_err != noErr) return PyMac_Error(_err);
373 _res = Py_BuildValue("O&",
374 PyMac_BuildRect, &itemBounds);
375 return _res;
376}
377
378static PyObject *DragObj_SetDragItemBounds(_self, _args)
379 DragObjObject *_self;
380 PyObject *_args;
381{
382 PyObject *_res = NULL;
383 OSErr _err;
384 ItemReference theItemRef;
385 Rect itemBounds;
386 if (!PyArg_ParseTuple(_args, "lO&",
387 &theItemRef,
388 PyMac_GetRect, &itemBounds))
389 return NULL;
390 _err = SetDragItemBounds(_self->ob_itself,
391 theItemRef,
392 &itemBounds);
393 if (_err != noErr) return PyMac_Error(_err);
394 Py_INCREF(Py_None);
395 _res = Py_None;
396 return _res;
397}
398
399static PyObject *DragObj_GetDropLocation(_self, _args)
400 DragObjObject *_self;
401 PyObject *_args;
402{
403 PyObject *_res = NULL;
404 OSErr _err;
405 AEDesc dropLocation;
406 if (!PyArg_ParseTuple(_args, ""))
407 return NULL;
408 _err = GetDropLocation(_self->ob_itself,
409 &dropLocation);
410 if (_err != noErr) return PyMac_Error(_err);
411 _res = Py_BuildValue("O&",
412 AEDesc_New, &dropLocation);
413 return _res;
414}
415
416static PyObject *DragObj_SetDropLocation(_self, _args)
417 DragObjObject *_self;
418 PyObject *_args;
419{
420 PyObject *_res = NULL;
421 OSErr _err;
422 AEDesc dropLocation;
423 if (!PyArg_ParseTuple(_args, "O&",
424 AEDesc_Convert, &dropLocation))
425 return NULL;
426 _err = SetDropLocation(_self->ob_itself,
427 &dropLocation);
428 if (_err != noErr) return PyMac_Error(_err);
429 Py_INCREF(Py_None);
430 _res = Py_None;
431 return _res;
432}
433
434static PyObject *DragObj_GetDragAttributes(_self, _args)
435 DragObjObject *_self;
436 PyObject *_args;
437{
438 PyObject *_res = NULL;
439 OSErr _err;
440 DragAttributes flags;
441 if (!PyArg_ParseTuple(_args, ""))
442 return NULL;
443 _err = GetDragAttributes(_self->ob_itself,
444 &flags);
445 if (_err != noErr) return PyMac_Error(_err);
446 _res = Py_BuildValue("l",
447 flags);
448 return _res;
449}
450
451static PyObject *DragObj_GetDragMouse(_self, _args)
452 DragObjObject *_self;
453 PyObject *_args;
454{
455 PyObject *_res = NULL;
456 OSErr _err;
457 Point mouse;
458 Point globalPinnedMouse;
459 if (!PyArg_ParseTuple(_args, ""))
460 return NULL;
461 _err = GetDragMouse(_self->ob_itself,
462 &mouse,
463 &globalPinnedMouse);
464 if (_err != noErr) return PyMac_Error(_err);
465 _res = Py_BuildValue("O&O&",
466 PyMac_BuildPoint, mouse,
467 PyMac_BuildPoint, globalPinnedMouse);
468 return _res;
469}
470
471static PyObject *DragObj_SetDragMouse(_self, _args)
472 DragObjObject *_self;
473 PyObject *_args;
474{
475 PyObject *_res = NULL;
476 OSErr _err;
477 Point globalPinnedMouse;
478 if (!PyArg_ParseTuple(_args, "O&",
479 PyMac_GetPoint, &globalPinnedMouse))
480 return NULL;
481 _err = SetDragMouse(_self->ob_itself,
482 globalPinnedMouse);
483 if (_err != noErr) return PyMac_Error(_err);
484 Py_INCREF(Py_None);
485 _res = Py_None;
486 return _res;
487}
488
489static PyObject *DragObj_GetDragOrigin(_self, _args)
490 DragObjObject *_self;
491 PyObject *_args;
492{
493 PyObject *_res = NULL;
494 OSErr _err;
495 Point globalInitialMouse;
496 if (!PyArg_ParseTuple(_args, ""))
497 return NULL;
498 _err = GetDragOrigin(_self->ob_itself,
499 &globalInitialMouse);
500 if (_err != noErr) return PyMac_Error(_err);
501 _res = Py_BuildValue("O&",
502 PyMac_BuildPoint, globalInitialMouse);
503 return _res;
504}
505
506static PyObject *DragObj_GetDragModifiers(_self, _args)
507 DragObjObject *_self;
508 PyObject *_args;
509{
510 PyObject *_res = NULL;
511 OSErr _err;
512 SInt16 modifiers;
513 SInt16 mouseDownModifiers;
514 SInt16 mouseUpModifiers;
515 if (!PyArg_ParseTuple(_args, ""))
516 return NULL;
517 _err = GetDragModifiers(_self->ob_itself,
518 &modifiers,
519 &mouseDownModifiers,
520 &mouseUpModifiers);
521 if (_err != noErr) return PyMac_Error(_err);
522 _res = Py_BuildValue("hhh",
523 modifiers,
524 mouseDownModifiers,
525 mouseUpModifiers);
526 return _res;
527}
528
529static PyObject *DragObj_ShowDragHilite(_self, _args)
530 DragObjObject *_self;
531 PyObject *_args;
532{
533 PyObject *_res = NULL;
534 OSErr _err;
535 RgnHandle hiliteFrame;
536 Boolean inside;
537 if (!PyArg_ParseTuple(_args, "O&b",
538 ResObj_Convert, &hiliteFrame,
539 &inside))
540 return NULL;
541 _err = ShowDragHilite(_self->ob_itself,
542 hiliteFrame,
543 inside);
544 if (_err != noErr) return PyMac_Error(_err);
545 Py_INCREF(Py_None);
546 _res = Py_None;
547 return _res;
548}
549
550static PyObject *DragObj_HideDragHilite(_self, _args)
551 DragObjObject *_self;
552 PyObject *_args;
553{
554 PyObject *_res = NULL;
555 OSErr _err;
556 if (!PyArg_ParseTuple(_args, ""))
557 return NULL;
558 _err = HideDragHilite(_self->ob_itself);
559 if (_err != noErr) return PyMac_Error(_err);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
563}
564
565static PyObject *DragObj_DragPreScroll(_self, _args)
566 DragObjObject *_self;
567 PyObject *_args;
568{
569 PyObject *_res = NULL;
570 OSErr _err;
571 SInt16 dH;
572 SInt16 dV;
573 if (!PyArg_ParseTuple(_args, "hh",
574 &dH,
575 &dV))
576 return NULL;
577 _err = DragPreScroll(_self->ob_itself,
578 dH,
579 dV);
580 if (_err != noErr) return PyMac_Error(_err);
581 Py_INCREF(Py_None);
582 _res = Py_None;
583 return _res;
584}
585
586static PyObject *DragObj_DragPostScroll(_self, _args)
587 DragObjObject *_self;
588 PyObject *_args;
589{
590 PyObject *_res = NULL;
591 OSErr _err;
592 if (!PyArg_ParseTuple(_args, ""))
593 return NULL;
594 _err = DragPostScroll(_self->ob_itself);
595 if (_err != noErr) return PyMac_Error(_err);
596 Py_INCREF(Py_None);
597 _res = Py_None;
598 return _res;
599}
600
601static PyObject *DragObj_UpdateDragHilite(_self, _args)
602 DragObjObject *_self;
603 PyObject *_args;
604{
605 PyObject *_res = NULL;
606 OSErr _err;
607 RgnHandle updateRgn;
608 if (!PyArg_ParseTuple(_args, "O&",
609 ResObj_Convert, &updateRgn))
610 return NULL;
611 _err = UpdateDragHilite(_self->ob_itself,
612 updateRgn);
613 if (_err != noErr) return PyMac_Error(_err);
614 Py_INCREF(Py_None);
615 _res = Py_None;
616 return _res;
617}
618
619static PyMethodDef DragObj_methods[] = {
620 {"DisposeDrag", (PyCFunction)DragObj_DisposeDrag, 1,
621 "() -> None"},
622 {"AddDragItemFlavor", (PyCFunction)DragObj_AddDragItemFlavor, 1,
623 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, FlavorFlags theFlags) -> None"},
624 {"SetDragItemFlavorData", (PyCFunction)DragObj_SetDragItemFlavorData, 1,
625 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> None"},
626 {"SetDragImage", (PyCFunction)DragObj_SetDragImage, 1,
627 "(PixMapHandle imagePixMap, RgnHandle imageRgn, Point imageOffsetPt, DragImageFlags theImageFlags) -> None"},
628 {"TrackDrag", (PyCFunction)DragObj_TrackDrag, 1,
629 "(EventRecord theEvent, RgnHandle theRegion) -> None"},
630 {"CountDragItems", (PyCFunction)DragObj_CountDragItems, 1,
631 "() -> (UInt16 numItems)"},
632 {"GetDragItemReferenceNumber", (PyCFunction)DragObj_GetDragItemReferenceNumber, 1,
633 "(UInt16 index) -> (ItemReference theItemRef)"},
634 {"CountDragItemFlavors", (PyCFunction)DragObj_CountDragItemFlavors, 1,
635 "(ItemReference theItemRef) -> (UInt16 numFlavors)"},
636 {"GetFlavorType", (PyCFunction)DragObj_GetFlavorType, 1,
637 "(ItemReference theItemRef, UInt16 index) -> (FlavorType theType)"},
638 {"GetFlavorFlags", (PyCFunction)DragObj_GetFlavorFlags, 1,
639 "(ItemReference theItemRef, FlavorType theType) -> (FlavorFlags theFlags)"},
640 {"GetFlavorDataSize", (PyCFunction)DragObj_GetFlavorDataSize, 1,
641 "(ItemReference theItemRef, FlavorType theType) -> (Size dataSize)"},
642 {"GetFlavorData", (PyCFunction)DragObj_GetFlavorData, 1,
643 "(ItemReference theItemRef, FlavorType theType, Buffer dataPtr, UInt32 dataOffset) -> (Buffer dataPtr)"},
644 {"GetDragItemBounds", (PyCFunction)DragObj_GetDragItemBounds, 1,
645 "(ItemReference theItemRef) -> (Rect itemBounds)"},
646 {"SetDragItemBounds", (PyCFunction)DragObj_SetDragItemBounds, 1,
647 "(ItemReference theItemRef, Rect itemBounds) -> None"},
648 {"GetDropLocation", (PyCFunction)DragObj_GetDropLocation, 1,
649 "() -> (AEDesc dropLocation)"},
650 {"SetDropLocation", (PyCFunction)DragObj_SetDropLocation, 1,
651 "(AEDesc dropLocation) -> None"},
652 {"GetDragAttributes", (PyCFunction)DragObj_GetDragAttributes, 1,
653 "() -> (DragAttributes flags)"},
654 {"GetDragMouse", (PyCFunction)DragObj_GetDragMouse, 1,
655 "() -> (Point mouse, Point globalPinnedMouse)"},
656 {"SetDragMouse", (PyCFunction)DragObj_SetDragMouse, 1,
657 "(Point globalPinnedMouse) -> None"},
658 {"GetDragOrigin", (PyCFunction)DragObj_GetDragOrigin, 1,
659 "() -> (Point globalInitialMouse)"},
660 {"GetDragModifiers", (PyCFunction)DragObj_GetDragModifiers, 1,
661 "() -> (SInt16 modifiers, SInt16 mouseDownModifiers, SInt16 mouseUpModifiers)"},
662 {"ShowDragHilite", (PyCFunction)DragObj_ShowDragHilite, 1,
663 "(RgnHandle hiliteFrame, Boolean inside) -> None"},
664 {"HideDragHilite", (PyCFunction)DragObj_HideDragHilite, 1,
665 "() -> None"},
666 {"DragPreScroll", (PyCFunction)DragObj_DragPreScroll, 1,
667 "(SInt16 dH, SInt16 dV) -> None"},
668 {"DragPostScroll", (PyCFunction)DragObj_DragPostScroll, 1,
669 "() -> None"},
670 {"UpdateDragHilite", (PyCFunction)DragObj_UpdateDragHilite, 1,
671 "(RgnHandle updateRgn) -> None"},
672 {NULL, NULL, 0}
673};
674
675PyMethodChain DragObj_chain = { DragObj_methods, NULL };
676
677static PyObject *DragObj_getattr(self, name)
678 DragObjObject *self;
679 char *name;
680{
681 return Py_FindMethodInChain(&DragObj_chain, (PyObject *)self, name);
682}
683
684#define DragObj_setattr NULL
685
686#define DragObj_compare NULL
687
688#define DragObj_repr NULL
689
690#define DragObj_hash NULL
691
692PyTypeObject DragObj_Type = {
693 PyObject_HEAD_INIT(&PyType_Type)
694 0, /*ob_size*/
695 "DragObj", /*tp_name*/
696 sizeof(DragObjObject), /*tp_basicsize*/
697 0, /*tp_itemsize*/
698 /* methods */
699 (destructor) DragObj_dealloc, /*tp_dealloc*/
700 0, /*tp_print*/
701 (getattrfunc) DragObj_getattr, /*tp_getattr*/
702 (setattrfunc) DragObj_setattr, /*tp_setattr*/
703 (cmpfunc) DragObj_compare, /*tp_compare*/
704 (reprfunc) DragObj_repr, /*tp_repr*/
705 (PyNumberMethods *)0, /* tp_as_number */
706 (PySequenceMethods *)0, /* tp_as_sequence */
707 (PyMappingMethods *)0, /* tp_as_mapping */
708 (hashfunc) DragObj_hash, /*tp_hash*/
709};
710
711/* -------------------- End object type DragObj --------------------- */
712
713
714static PyObject *Drag_NewDrag(_self, _args)
715 PyObject *_self;
716 PyObject *_args;
717{
718 PyObject *_res = NULL;
719 OSErr _err;
720 DragReference theDrag;
721 if (!PyArg_ParseTuple(_args, ""))
722 return NULL;
723 _err = NewDrag(&theDrag);
724 if (_err != noErr) return PyMac_Error(_err);
725 _res = Py_BuildValue("O&",
726 DragObj_New, theDrag);
727 return _res;
728}
729
730static PyObject *Drag_GetDragHiliteColor(_self, _args)
731 PyObject *_self;
732 PyObject *_args;
733{
734 PyObject *_res = NULL;
735 OSErr _err;
736 WindowPtr window;
737 RGBColor color;
738 if (!PyArg_ParseTuple(_args, "O&",
739 WinObj_Convert, &window))
740 return NULL;
741 _err = GetDragHiliteColor(window,
742 &color);
743 if (_err != noErr) return PyMac_Error(_err);
744 _res = Py_BuildValue("O&",
745 QdRGB_New, &color);
746 return _res;
747}
748
749static PyObject *Drag_WaitMouseMoved(_self, _args)
750 PyObject *_self;
751 PyObject *_args;
752{
753 PyObject *_res = NULL;
754 Boolean _rv;
755 Point initialMouse;
756 if (!PyArg_ParseTuple(_args, "O&",
757 PyMac_GetPoint, &initialMouse))
758 return NULL;
759 _rv = WaitMouseMoved(initialMouse);
760 _res = Py_BuildValue("b",
761 _rv);
762 return _res;
763}
764
765static PyObject *Drag_ZoomRects(_self, _args)
766 PyObject *_self;
767 PyObject *_args;
768{
769 PyObject *_res = NULL;
770 OSErr _err;
771 Rect fromRect;
772 Rect toRect;
773 SInt16 zoomSteps;
774 ZoomAcceleration acceleration;
775 if (!PyArg_ParseTuple(_args, "O&O&hh",
776 PyMac_GetRect, &fromRect,
777 PyMac_GetRect, &toRect,
778 &zoomSteps,
779 &acceleration))
780 return NULL;
781 _err = ZoomRects(&fromRect,
782 &toRect,
783 zoomSteps,
784 acceleration);
785 if (_err != noErr) return PyMac_Error(_err);
786 Py_INCREF(Py_None);
787 _res = Py_None;
788 return _res;
789}
790
791static PyObject *Drag_ZoomRegion(_self, _args)
792 PyObject *_self;
793 PyObject *_args;
794{
795 PyObject *_res = NULL;
796 OSErr _err;
797 RgnHandle region;
798 Point zoomDistance;
799 SInt16 zoomSteps;
800 ZoomAcceleration acceleration;
801 if (!PyArg_ParseTuple(_args, "O&O&hh",
802 ResObj_Convert, &region,
803 PyMac_GetPoint, &zoomDistance,
804 &zoomSteps,
805 &acceleration))
806 return NULL;
807 _err = ZoomRegion(region,
808 zoomDistance,
809 zoomSteps,
810 acceleration);
811 if (_err != noErr) return PyMac_Error(_err);
812 Py_INCREF(Py_None);
813 _res = Py_None;
814 return _res;
815}
816
817static PyObject *Drag_InstallTrackingHandler(_self, _args)
818 PyObject *_self;
819 PyObject *_args;
820{
821 PyObject *_res = NULL;
822
823 PyObject *callback;
824 WindowPtr theWindow = NULL;
825 OSErr _err;
826
827 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
828 return NULL;
829 Py_INCREF(callback); /* Cannot decref later, too bad */
830 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
831 if (_err != noErr) return PyMac_Error(_err);
832 Py_INCREF(Py_None);
833 return Py_None;
834
835}
836
837static PyObject *Drag_InstallReceiveHandler(_self, _args)
838 PyObject *_self;
839 PyObject *_args;
840{
841 PyObject *_res = NULL;
842
843 PyObject *callback;
844 WindowPtr theWindow = NULL;
845 OSErr _err;
846
847 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
848 return NULL;
849 Py_INCREF(callback); /* Cannot decref later, too bad */
850 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
851 if (_err != noErr) return PyMac_Error(_err);
852 Py_INCREF(Py_None);
853 return Py_None;
854
855}
856
857static PyObject *Drag_RemoveTrackingHandler(_self, _args)
858 PyObject *_self;
859 PyObject *_args;
860{
861 PyObject *_res = NULL;
862
863 WindowPtr theWindow = NULL;
864 OSErr _err;
865
866 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
867 return NULL;
868 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
869 if (_err != noErr) return PyMac_Error(_err);
870 Py_INCREF(Py_None);
871 return Py_None;
872
873}
874
875static PyObject *Drag_RemoveReceiveHandler(_self, _args)
876 PyObject *_self;
877 PyObject *_args;
878{
879 PyObject *_res = NULL;
880
881 WindowPtr theWindow = NULL;
882 OSErr _err;
883
884 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
885 return NULL;
886 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
887 if (_err != noErr) return PyMac_Error(_err);
888 Py_INCREF(Py_None);
889 return Py_None;
890
891}
892
893static PyMethodDef Drag_methods[] = {
894 {"NewDrag", (PyCFunction)Drag_NewDrag, 1,
895 "() -> (DragReference theDrag)"},
896 {"GetDragHiliteColor", (PyCFunction)Drag_GetDragHiliteColor, 1,
897 "(WindowPtr window) -> (RGBColor color)"},
898 {"WaitMouseMoved", (PyCFunction)Drag_WaitMouseMoved, 1,
899 "(Point initialMouse) -> (Boolean _rv)"},
900 {"ZoomRects", (PyCFunction)Drag_ZoomRects, 1,
901 "(Rect fromRect, Rect toRect, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
902 {"ZoomRegion", (PyCFunction)Drag_ZoomRegion, 1,
903 "(RgnHandle region, Point zoomDistance, SInt16 zoomSteps, ZoomAcceleration acceleration) -> None"},
904 {"InstallTrackingHandler", (PyCFunction)Drag_InstallTrackingHandler, 1,
905 NULL},
906 {"InstallReceiveHandler", (PyCFunction)Drag_InstallReceiveHandler, 1,
907 NULL},
908 {"RemoveTrackingHandler", (PyCFunction)Drag_RemoveTrackingHandler, 1,
909 NULL},
910 {"RemoveReceiveHandler", (PyCFunction)Drag_RemoveReceiveHandler, 1,
911 NULL},
912 {NULL, NULL, 0}
913};
914
915
916
917static pascal OSErr
918dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
919 void *handlerRefCon, DragReference theDrag)
920{
921 PyObject *args, *rv;
922 int i;
923
924 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
925 if ( args == NULL )
926 return -1;
927 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
928 Py_DECREF(args);
Jack Jansen58b2eac1999-06-21 16:18:51 +0000929 if ( rv == NULL ) {
930 fprintf(stderr, "Drag: Exception in TrackingHandler\n");
Jack Jansenc4f63311999-06-21 15:14:26 +0000931 return -1;
Jack Jansen58b2eac1999-06-21 16:18:51 +0000932 }
Jack Jansenc4f63311999-06-21 15:14:26 +0000933 i = -1;
934 if ( rv == Py_None )
935 i = 0;
936 else
937 PyArg_Parse(rv, "l", &i);
938 Py_DECREF(rv);
939 return i;
940}
941
942static pascal OSErr
943dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
944 DragReference theDrag)
945{
946 PyObject *args, *rv;
947 int i;
948
949 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
950 if ( args == NULL )
951 return -1;
952 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
953 Py_DECREF(args);
Jack Jansen58b2eac1999-06-21 16:18:51 +0000954 if ( rv == NULL ) {
955 fprintf(stderr, "Drag: Exception in ReceiveHandler\n");
Jack Jansenc4f63311999-06-21 15:14:26 +0000956 return -1;
Jack Jansen58b2eac1999-06-21 16:18:51 +0000957 }
Jack Jansenc4f63311999-06-21 15:14:26 +0000958 i = -1;
959 if ( rv == Py_None )
960 i = 0;
961 else
962 PyArg_Parse(rv, "l", &i);
963 Py_DECREF(rv);
964 return i;
965}
966
967static pascal OSErr
968dragglue_SendData(FlavorType theType, void *dragSendRefCon,
969 ItemReference theItem, DragReference theDrag)
970{
971 DragObjObject *self = (DragObjObject *)dragSendRefCon;
972 PyObject *args, *rv;
973 int i;
974
975 if ( self->sendproc == NULL )
976 return -1;
977 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
978 if ( args == NULL )
979 return -1;
980 rv = PyEval_CallObject(self->sendproc, args);
981 Py_DECREF(args);
Jack Jansen58b2eac1999-06-21 16:18:51 +0000982 if ( rv == NULL ) {
983 fprintf(stderr, "Drag: Exception in SendDataHandler\n");
Jack Jansenc4f63311999-06-21 15:14:26 +0000984 return -1;
Jack Jansen58b2eac1999-06-21 16:18:51 +0000985 }
Jack Jansenc4f63311999-06-21 15:14:26 +0000986 i = -1;
987 if ( rv == Py_None )
988 i = 0;
989 else
990 PyArg_Parse(rv, "l", &i);
991 Py_DECREF(rv);
992 return i;
993}
994
995#if 0
996static pascal OSErr
997dragglue_Input(Point *mouse, short *modifiers,
998 void *dragSendRefCon, DragReference theDrag)
999{
1000 return 0;
1001}
1002
1003static pascal OSErr
1004dragglue_Drawing(xxxx
1005 void *dragSendRefCon, DragReference theDrag)
1006{
1007 return 0;
1008}
1009#endif
1010
1011
1012
1013void initDrag()
1014{
1015 PyObject *m;
1016 PyObject *d;
1017
1018
1019
1020
1021 m = Py_InitModule("Drag", Drag_methods);
1022 d = PyModule_GetDict(m);
1023 Drag_Error = PyMac_GetOSErrException();
1024 if (Drag_Error == NULL ||
1025 PyDict_SetItemString(d, "Error", Drag_Error) != 0)
1026 Py_FatalError("can't initialize Drag.Error");
1027 DragObj_Type.ob_type = &PyType_Type;
1028 Py_INCREF(&DragObj_Type);
1029 if (PyDict_SetItemString(d, "DragObjType", (PyObject *)&DragObj_Type) != 0)
1030 Py_FatalError("can't initialize DragObjType");
1031
1032 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler);
1033 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler);
1034 dragglue_SendDataUPP = NewDragSendDataProc(dragglue_SendData);
1035#if 0
1036 dragglue_InputUPP = NewDragInputProc(dragglue_Input);
1037 dragglue_DrawingUPP = NewDragDrawingProc(dragglue_Drawing);
1038#endif
1039
1040
1041}
1042
1043/* ======================== End module Drag ========================= */
1044