/Mac/Modules/drag/_Dragmodule.c

http://unladen-swallow.googlecode.com/ · C · 1158 lines · 1046 code · 104 blank · 8 comment · 145 complexity · 1c23d26c5a6b30fc5c0238edee514ee4 MD5 · raw file

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