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