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