/Mac/Modules/icn/_Icnmodule.c

http://unladen-swallow.googlecode.com/ · C · 1607 lines · 1521 code · 83 blank · 3 comment · 162 complexity · 71481573c2e486028080280a7be03bd8 MD5 · raw file

  1. /* ========================== Module _Icn =========================== */
  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. static PyObject *Icn_Error;
  13. static PyObject *Icn_GetCIcon(PyObject *_self, PyObject *_args)
  14. {
  15. PyObject *_res = NULL;
  16. CIconHandle _rv;
  17. SInt16 iconID;
  18. #ifndef GetCIcon
  19. PyMac_PRECHECK(GetCIcon);
  20. #endif
  21. if (!PyArg_ParseTuple(_args, "h",
  22. &iconID))
  23. return NULL;
  24. _rv = GetCIcon(iconID);
  25. _res = Py_BuildValue("O&",
  26. ResObj_New, _rv);
  27. return _res;
  28. }
  29. static PyObject *Icn_PlotCIcon(PyObject *_self, PyObject *_args)
  30. {
  31. PyObject *_res = NULL;
  32. Rect theRect;
  33. CIconHandle theIcon;
  34. #ifndef PlotCIcon
  35. PyMac_PRECHECK(PlotCIcon);
  36. #endif
  37. if (!PyArg_ParseTuple(_args, "O&O&",
  38. PyMac_GetRect, &theRect,
  39. ResObj_Convert, &theIcon))
  40. return NULL;
  41. PlotCIcon(&theRect,
  42. theIcon);
  43. Py_INCREF(Py_None);
  44. _res = Py_None;
  45. return _res;
  46. }
  47. static PyObject *Icn_DisposeCIcon(PyObject *_self, PyObject *_args)
  48. {
  49. PyObject *_res = NULL;
  50. CIconHandle theIcon;
  51. #ifndef DisposeCIcon
  52. PyMac_PRECHECK(DisposeCIcon);
  53. #endif
  54. if (!PyArg_ParseTuple(_args, "O&",
  55. ResObj_Convert, &theIcon))
  56. return NULL;
  57. DisposeCIcon(theIcon);
  58. Py_INCREF(Py_None);
  59. _res = Py_None;
  60. return _res;
  61. }
  62. static PyObject *Icn_GetIcon(PyObject *_self, PyObject *_args)
  63. {
  64. PyObject *_res = NULL;
  65. Handle _rv;
  66. SInt16 iconID;
  67. #ifndef GetIcon
  68. PyMac_PRECHECK(GetIcon);
  69. #endif
  70. if (!PyArg_ParseTuple(_args, "h",
  71. &iconID))
  72. return NULL;
  73. _rv = GetIcon(iconID);
  74. _res = Py_BuildValue("O&",
  75. ResObj_New, _rv);
  76. return _res;
  77. }
  78. static PyObject *Icn_PlotIcon(PyObject *_self, PyObject *_args)
  79. {
  80. PyObject *_res = NULL;
  81. Rect theRect;
  82. Handle theIcon;
  83. #ifndef PlotIcon
  84. PyMac_PRECHECK(PlotIcon);
  85. #endif
  86. if (!PyArg_ParseTuple(_args, "O&O&",
  87. PyMac_GetRect, &theRect,
  88. ResObj_Convert, &theIcon))
  89. return NULL;
  90. PlotIcon(&theRect,
  91. theIcon);
  92. Py_INCREF(Py_None);
  93. _res = Py_None;
  94. return _res;
  95. }
  96. static PyObject *Icn_PlotIconID(PyObject *_self, PyObject *_args)
  97. {
  98. PyObject *_res = NULL;
  99. OSErr _err;
  100. Rect theRect;
  101. IconAlignmentType align;
  102. IconTransformType transform;
  103. SInt16 theResID;
  104. #ifndef PlotIconID
  105. PyMac_PRECHECK(PlotIconID);
  106. #endif
  107. if (!PyArg_ParseTuple(_args, "O&hhh",
  108. PyMac_GetRect, &theRect,
  109. &align,
  110. &transform,
  111. &theResID))
  112. return NULL;
  113. _err = PlotIconID(&theRect,
  114. align,
  115. transform,
  116. theResID);
  117. if (_err != noErr) return PyMac_Error(_err);
  118. Py_INCREF(Py_None);
  119. _res = Py_None;
  120. return _res;
  121. }
  122. static PyObject *Icn_NewIconSuite(PyObject *_self, PyObject *_args)
  123. {
  124. PyObject *_res = NULL;
  125. OSErr _err;
  126. IconSuiteRef theIconSuite;
  127. #ifndef NewIconSuite
  128. PyMac_PRECHECK(NewIconSuite);
  129. #endif
  130. if (!PyArg_ParseTuple(_args, ""))
  131. return NULL;
  132. _err = NewIconSuite(&theIconSuite);
  133. if (_err != noErr) return PyMac_Error(_err);
  134. _res = Py_BuildValue("O&",
  135. ResObj_New, theIconSuite);
  136. return _res;
  137. }
  138. static PyObject *Icn_AddIconToSuite(PyObject *_self, PyObject *_args)
  139. {
  140. PyObject *_res = NULL;
  141. OSErr _err;
  142. Handle theIconData;
  143. IconSuiteRef theSuite;
  144. ResType theType;
  145. #ifndef AddIconToSuite
  146. PyMac_PRECHECK(AddIconToSuite);
  147. #endif
  148. if (!PyArg_ParseTuple(_args, "O&O&O&",
  149. ResObj_Convert, &theIconData,
  150. ResObj_Convert, &theSuite,
  151. PyMac_GetOSType, &theType))
  152. return NULL;
  153. _err = AddIconToSuite(theIconData,
  154. theSuite,
  155. theType);
  156. if (_err != noErr) return PyMac_Error(_err);
  157. Py_INCREF(Py_None);
  158. _res = Py_None;
  159. return _res;
  160. }
  161. static PyObject *Icn_GetIconFromSuite(PyObject *_self, PyObject *_args)
  162. {
  163. PyObject *_res = NULL;
  164. OSErr _err;
  165. Handle theIconData;
  166. IconSuiteRef theSuite;
  167. ResType theType;
  168. #ifndef GetIconFromSuite
  169. PyMac_PRECHECK(GetIconFromSuite);
  170. #endif
  171. if (!PyArg_ParseTuple(_args, "O&O&",
  172. ResObj_Convert, &theSuite,
  173. PyMac_GetOSType, &theType))
  174. return NULL;
  175. _err = GetIconFromSuite(&theIconData,
  176. theSuite,
  177. theType);
  178. if (_err != noErr) return PyMac_Error(_err);
  179. _res = Py_BuildValue("O&",
  180. ResObj_New, theIconData);
  181. return _res;
  182. }
  183. static PyObject *Icn_GetIconSuite(PyObject *_self, PyObject *_args)
  184. {
  185. PyObject *_res = NULL;
  186. OSErr _err;
  187. IconSuiteRef theIconSuite;
  188. SInt16 theResID;
  189. IconSelectorValue selector;
  190. #ifndef GetIconSuite
  191. PyMac_PRECHECK(GetIconSuite);
  192. #endif
  193. if (!PyArg_ParseTuple(_args, "hl",
  194. &theResID,
  195. &selector))
  196. return NULL;
  197. _err = GetIconSuite(&theIconSuite,
  198. theResID,
  199. selector);
  200. if (_err != noErr) return PyMac_Error(_err);
  201. _res = Py_BuildValue("O&",
  202. ResObj_New, theIconSuite);
  203. return _res;
  204. }
  205. static PyObject *Icn_DisposeIconSuite(PyObject *_self, PyObject *_args)
  206. {
  207. PyObject *_res = NULL;
  208. OSErr _err;
  209. IconSuiteRef theIconSuite;
  210. Boolean disposeData;
  211. #ifndef DisposeIconSuite
  212. PyMac_PRECHECK(DisposeIconSuite);
  213. #endif
  214. if (!PyArg_ParseTuple(_args, "O&b",
  215. ResObj_Convert, &theIconSuite,
  216. &disposeData))
  217. return NULL;
  218. _err = DisposeIconSuite(theIconSuite,
  219. disposeData);
  220. if (_err != noErr) return PyMac_Error(_err);
  221. Py_INCREF(Py_None);
  222. _res = Py_None;
  223. return _res;
  224. }
  225. static PyObject *Icn_PlotIconSuite(PyObject *_self, PyObject *_args)
  226. {
  227. PyObject *_res = NULL;
  228. OSErr _err;
  229. Rect theRect;
  230. IconAlignmentType align;
  231. IconTransformType transform;
  232. IconSuiteRef theIconSuite;
  233. #ifndef PlotIconSuite
  234. PyMac_PRECHECK(PlotIconSuite);
  235. #endif
  236. if (!PyArg_ParseTuple(_args, "O&hhO&",
  237. PyMac_GetRect, &theRect,
  238. &align,
  239. &transform,
  240. ResObj_Convert, &theIconSuite))
  241. return NULL;
  242. _err = PlotIconSuite(&theRect,
  243. align,
  244. transform,
  245. theIconSuite);
  246. if (_err != noErr) return PyMac_Error(_err);
  247. Py_INCREF(Py_None);
  248. _res = Py_None;
  249. return _res;
  250. }
  251. static PyObject *Icn_LoadIconCache(PyObject *_self, PyObject *_args)
  252. {
  253. PyObject *_res = NULL;
  254. OSErr _err;
  255. Rect theRect;
  256. IconAlignmentType align;
  257. IconTransformType transform;
  258. IconCacheRef theIconCache;
  259. #ifndef LoadIconCache
  260. PyMac_PRECHECK(LoadIconCache);
  261. #endif
  262. if (!PyArg_ParseTuple(_args, "O&hhO&",
  263. PyMac_GetRect, &theRect,
  264. &align,
  265. &transform,
  266. ResObj_Convert, &theIconCache))
  267. return NULL;
  268. _err = LoadIconCache(&theRect,
  269. align,
  270. transform,
  271. theIconCache);
  272. if (_err != noErr) return PyMac_Error(_err);
  273. Py_INCREF(Py_None);
  274. _res = Py_None;
  275. return _res;
  276. }
  277. static PyObject *Icn_GetLabel(PyObject *_self, PyObject *_args)
  278. {
  279. PyObject *_res = NULL;
  280. OSErr _err;
  281. SInt16 labelNumber;
  282. RGBColor labelColor;
  283. Str255 labelString;
  284. #ifndef GetLabel
  285. PyMac_PRECHECK(GetLabel);
  286. #endif
  287. if (!PyArg_ParseTuple(_args, "hO&",
  288. &labelNumber,
  289. PyMac_GetStr255, labelString))
  290. return NULL;
  291. _err = GetLabel(labelNumber,
  292. &labelColor,
  293. labelString);
  294. if (_err != noErr) return PyMac_Error(_err);
  295. _res = Py_BuildValue("O&",
  296. QdRGB_New, &labelColor);
  297. return _res;
  298. }
  299. static PyObject *Icn_PtInIconID(PyObject *_self, PyObject *_args)
  300. {
  301. PyObject *_res = NULL;
  302. Boolean _rv;
  303. Point testPt;
  304. Rect iconRect;
  305. IconAlignmentType align;
  306. SInt16 iconID;
  307. #ifndef PtInIconID
  308. PyMac_PRECHECK(PtInIconID);
  309. #endif
  310. if (!PyArg_ParseTuple(_args, "O&O&hh",
  311. PyMac_GetPoint, &testPt,
  312. PyMac_GetRect, &iconRect,
  313. &align,
  314. &iconID))
  315. return NULL;
  316. _rv = PtInIconID(testPt,
  317. &iconRect,
  318. align,
  319. iconID);
  320. _res = Py_BuildValue("b",
  321. _rv);
  322. return _res;
  323. }
  324. static PyObject *Icn_PtInIconSuite(PyObject *_self, PyObject *_args)
  325. {
  326. PyObject *_res = NULL;
  327. Boolean _rv;
  328. Point testPt;
  329. Rect iconRect;
  330. IconAlignmentType align;
  331. IconSuiteRef theIconSuite;
  332. #ifndef PtInIconSuite
  333. PyMac_PRECHECK(PtInIconSuite);
  334. #endif
  335. if (!PyArg_ParseTuple(_args, "O&O&hO&",
  336. PyMac_GetPoint, &testPt,
  337. PyMac_GetRect, &iconRect,
  338. &align,
  339. ResObj_Convert, &theIconSuite))
  340. return NULL;
  341. _rv = PtInIconSuite(testPt,
  342. &iconRect,
  343. align,
  344. theIconSuite);
  345. _res = Py_BuildValue("b",
  346. _rv);
  347. return _res;
  348. }
  349. static PyObject *Icn_RectInIconID(PyObject *_self, PyObject *_args)
  350. {
  351. PyObject *_res = NULL;
  352. Boolean _rv;
  353. Rect testRect;
  354. Rect iconRect;
  355. IconAlignmentType align;
  356. SInt16 iconID;
  357. #ifndef RectInIconID
  358. PyMac_PRECHECK(RectInIconID);
  359. #endif
  360. if (!PyArg_ParseTuple(_args, "O&O&hh",
  361. PyMac_GetRect, &testRect,
  362. PyMac_GetRect, &iconRect,
  363. &align,
  364. &iconID))
  365. return NULL;
  366. _rv = RectInIconID(&testRect,
  367. &iconRect,
  368. align,
  369. iconID);
  370. _res = Py_BuildValue("b",
  371. _rv);
  372. return _res;
  373. }
  374. static PyObject *Icn_RectInIconSuite(PyObject *_self, PyObject *_args)
  375. {
  376. PyObject *_res = NULL;
  377. Boolean _rv;
  378. Rect testRect;
  379. Rect iconRect;
  380. IconAlignmentType align;
  381. IconSuiteRef theIconSuite;
  382. #ifndef RectInIconSuite
  383. PyMac_PRECHECK(RectInIconSuite);
  384. #endif
  385. if (!PyArg_ParseTuple(_args, "O&O&hO&",
  386. PyMac_GetRect, &testRect,
  387. PyMac_GetRect, &iconRect,
  388. &align,
  389. ResObj_Convert, &theIconSuite))
  390. return NULL;
  391. _rv = RectInIconSuite(&testRect,
  392. &iconRect,
  393. align,
  394. theIconSuite);
  395. _res = Py_BuildValue("b",
  396. _rv);
  397. return _res;
  398. }
  399. static PyObject *Icn_IconIDToRgn(PyObject *_self, PyObject *_args)
  400. {
  401. PyObject *_res = NULL;
  402. OSErr _err;
  403. RgnHandle theRgn;
  404. Rect iconRect;
  405. IconAlignmentType align;
  406. SInt16 iconID;
  407. #ifndef IconIDToRgn
  408. PyMac_PRECHECK(IconIDToRgn);
  409. #endif
  410. if (!PyArg_ParseTuple(_args, "O&O&hh",
  411. ResObj_Convert, &theRgn,
  412. PyMac_GetRect, &iconRect,
  413. &align,
  414. &iconID))
  415. return NULL;
  416. _err = IconIDToRgn(theRgn,
  417. &iconRect,
  418. align,
  419. iconID);
  420. if (_err != noErr) return PyMac_Error(_err);
  421. Py_INCREF(Py_None);
  422. _res = Py_None;
  423. return _res;
  424. }
  425. static PyObject *Icn_IconSuiteToRgn(PyObject *_self, PyObject *_args)
  426. {
  427. PyObject *_res = NULL;
  428. OSErr _err;
  429. RgnHandle theRgn;
  430. Rect iconRect;
  431. IconAlignmentType align;
  432. IconSuiteRef theIconSuite;
  433. #ifndef IconSuiteToRgn
  434. PyMac_PRECHECK(IconSuiteToRgn);
  435. #endif
  436. if (!PyArg_ParseTuple(_args, "O&O&hO&",
  437. ResObj_Convert, &theRgn,
  438. PyMac_GetRect, &iconRect,
  439. &align,
  440. ResObj_Convert, &theIconSuite))
  441. return NULL;
  442. _err = IconSuiteToRgn(theRgn,
  443. &iconRect,
  444. align,
  445. theIconSuite);
  446. if (_err != noErr) return PyMac_Error(_err);
  447. Py_INCREF(Py_None);
  448. _res = Py_None;
  449. return _res;
  450. }
  451. static PyObject *Icn_SetSuiteLabel(PyObject *_self, PyObject *_args)
  452. {
  453. PyObject *_res = NULL;
  454. OSErr _err;
  455. IconSuiteRef theSuite;
  456. SInt16 theLabel;
  457. #ifndef SetSuiteLabel
  458. PyMac_PRECHECK(SetSuiteLabel);
  459. #endif
  460. if (!PyArg_ParseTuple(_args, "O&h",
  461. ResObj_Convert, &theSuite,
  462. &theLabel))
  463. return NULL;
  464. _err = SetSuiteLabel(theSuite,
  465. theLabel);
  466. if (_err != noErr) return PyMac_Error(_err);
  467. Py_INCREF(Py_None);
  468. _res = Py_None;
  469. return _res;
  470. }
  471. static PyObject *Icn_GetSuiteLabel(PyObject *_self, PyObject *_args)
  472. {
  473. PyObject *_res = NULL;
  474. SInt16 _rv;
  475. IconSuiteRef theSuite;
  476. #ifndef GetSuiteLabel
  477. PyMac_PRECHECK(GetSuiteLabel);
  478. #endif
  479. if (!PyArg_ParseTuple(_args, "O&",
  480. ResObj_Convert, &theSuite))
  481. return NULL;
  482. _rv = GetSuiteLabel(theSuite);
  483. _res = Py_BuildValue("h",
  484. _rv);
  485. return _res;
  486. }
  487. static PyObject *Icn_PlotIconHandle(PyObject *_self, PyObject *_args)
  488. {
  489. PyObject *_res = NULL;
  490. OSErr _err;
  491. Rect theRect;
  492. IconAlignmentType align;
  493. IconTransformType transform;
  494. Handle theIcon;
  495. #ifndef PlotIconHandle
  496. PyMac_PRECHECK(PlotIconHandle);
  497. #endif
  498. if (!PyArg_ParseTuple(_args, "O&hhO&",
  499. PyMac_GetRect, &theRect,
  500. &align,
  501. &transform,
  502. ResObj_Convert, &theIcon))
  503. return NULL;
  504. _err = PlotIconHandle(&theRect,
  505. align,
  506. transform,
  507. theIcon);
  508. if (_err != noErr) return PyMac_Error(_err);
  509. Py_INCREF(Py_None);
  510. _res = Py_None;
  511. return _res;
  512. }
  513. static PyObject *Icn_PlotSICNHandle(PyObject *_self, PyObject *_args)
  514. {
  515. PyObject *_res = NULL;
  516. OSErr _err;
  517. Rect theRect;
  518. IconAlignmentType align;
  519. IconTransformType transform;
  520. Handle theSICN;
  521. #ifndef PlotSICNHandle
  522. PyMac_PRECHECK(PlotSICNHandle);
  523. #endif
  524. if (!PyArg_ParseTuple(_args, "O&hhO&",
  525. PyMac_GetRect, &theRect,
  526. &align,
  527. &transform,
  528. ResObj_Convert, &theSICN))
  529. return NULL;
  530. _err = PlotSICNHandle(&theRect,
  531. align,
  532. transform,
  533. theSICN);
  534. if (_err != noErr) return PyMac_Error(_err);
  535. Py_INCREF(Py_None);
  536. _res = Py_None;
  537. return _res;
  538. }
  539. static PyObject *Icn_PlotCIconHandle(PyObject *_self, PyObject *_args)
  540. {
  541. PyObject *_res = NULL;
  542. OSErr _err;
  543. Rect theRect;
  544. IconAlignmentType align;
  545. IconTransformType transform;
  546. CIconHandle theCIcon;
  547. #ifndef PlotCIconHandle
  548. PyMac_PRECHECK(PlotCIconHandle);
  549. #endif
  550. if (!PyArg_ParseTuple(_args, "O&hhO&",
  551. PyMac_GetRect, &theRect,
  552. &align,
  553. &transform,
  554. ResObj_Convert, &theCIcon))
  555. return NULL;
  556. _err = PlotCIconHandle(&theRect,
  557. align,
  558. transform,
  559. theCIcon);
  560. if (_err != noErr) return PyMac_Error(_err);
  561. Py_INCREF(Py_None);
  562. _res = Py_None;
  563. return _res;
  564. }
  565. static PyObject *Icn_IconRefToIconFamily(PyObject *_self, PyObject *_args)
  566. {
  567. PyObject *_res = NULL;
  568. OSErr _err;
  569. IconRef theIconRef;
  570. IconSelectorValue whichIcons;
  571. IconFamilyHandle iconFamily;
  572. #ifndef IconRefToIconFamily
  573. PyMac_PRECHECK(IconRefToIconFamily);
  574. #endif
  575. if (!PyArg_ParseTuple(_args, "O&l",
  576. ResObj_Convert, &theIconRef,
  577. &whichIcons))
  578. return NULL;
  579. _err = IconRefToIconFamily(theIconRef,
  580. whichIcons,
  581. &iconFamily);
  582. if (_err != noErr) return PyMac_Error(_err);
  583. _res = Py_BuildValue("O&",
  584. ResObj_New, iconFamily);
  585. return _res;
  586. }
  587. static PyObject *Icn_IconFamilyToIconSuite(PyObject *_self, PyObject *_args)
  588. {
  589. PyObject *_res = NULL;
  590. OSErr _err;
  591. IconFamilyHandle iconFamily;
  592. IconSelectorValue whichIcons;
  593. IconSuiteRef iconSuite;
  594. #ifndef IconFamilyToIconSuite
  595. PyMac_PRECHECK(IconFamilyToIconSuite);
  596. #endif
  597. if (!PyArg_ParseTuple(_args, "O&l",
  598. ResObj_Convert, &iconFamily,
  599. &whichIcons))
  600. return NULL;
  601. _err = IconFamilyToIconSuite(iconFamily,
  602. whichIcons,
  603. &iconSuite);
  604. if (_err != noErr) return PyMac_Error(_err);
  605. _res = Py_BuildValue("O&",
  606. ResObj_New, iconSuite);
  607. return _res;
  608. }
  609. static PyObject *Icn_IconSuiteToIconFamily(PyObject *_self, PyObject *_args)
  610. {
  611. PyObject *_res = NULL;
  612. OSErr _err;
  613. IconSuiteRef iconSuite;
  614. IconSelectorValue whichIcons;
  615. IconFamilyHandle iconFamily;
  616. #ifndef IconSuiteToIconFamily
  617. PyMac_PRECHECK(IconSuiteToIconFamily);
  618. #endif
  619. if (!PyArg_ParseTuple(_args, "O&l",
  620. ResObj_Convert, &iconSuite,
  621. &whichIcons))
  622. return NULL;
  623. _err = IconSuiteToIconFamily(iconSuite,
  624. whichIcons,
  625. &iconFamily);
  626. if (_err != noErr) return PyMac_Error(_err);
  627. _res = Py_BuildValue("O&",
  628. ResObj_New, iconFamily);
  629. return _res;
  630. }
  631. static PyObject *Icn_SetIconFamilyData(PyObject *_self, PyObject *_args)
  632. {
  633. PyObject *_res = NULL;
  634. OSErr _err;
  635. IconFamilyHandle iconFamily;
  636. OSType iconType;
  637. Handle h;
  638. #ifndef SetIconFamilyData
  639. PyMac_PRECHECK(SetIconFamilyData);
  640. #endif
  641. if (!PyArg_ParseTuple(_args, "O&O&O&",
  642. ResObj_Convert, &iconFamily,
  643. PyMac_GetOSType, &iconType,
  644. ResObj_Convert, &h))
  645. return NULL;
  646. _err = SetIconFamilyData(iconFamily,
  647. iconType,
  648. h);
  649. if (_err != noErr) return PyMac_Error(_err);
  650. Py_INCREF(Py_None);
  651. _res = Py_None;
  652. return _res;
  653. }
  654. static PyObject *Icn_GetIconFamilyData(PyObject *_self, PyObject *_args)
  655. {
  656. PyObject *_res = NULL;
  657. OSErr _err;
  658. IconFamilyHandle iconFamily;
  659. OSType iconType;
  660. Handle h;
  661. #ifndef GetIconFamilyData
  662. PyMac_PRECHECK(GetIconFamilyData);
  663. #endif
  664. if (!PyArg_ParseTuple(_args, "O&O&O&",
  665. ResObj_Convert, &iconFamily,
  666. PyMac_GetOSType, &iconType,
  667. ResObj_Convert, &h))
  668. return NULL;
  669. _err = GetIconFamilyData(iconFamily,
  670. iconType,
  671. h);
  672. if (_err != noErr) return PyMac_Error(_err);
  673. Py_INCREF(Py_None);
  674. _res = Py_None;
  675. return _res;
  676. }
  677. static PyObject *Icn_GetIconRefOwners(PyObject *_self, PyObject *_args)
  678. {
  679. PyObject *_res = NULL;
  680. OSErr _err;
  681. IconRef theIconRef;
  682. UInt16 owners;
  683. #ifndef GetIconRefOwners
  684. PyMac_PRECHECK(GetIconRefOwners);
  685. #endif
  686. if (!PyArg_ParseTuple(_args, "O&",
  687. ResObj_Convert, &theIconRef))
  688. return NULL;
  689. _err = GetIconRefOwners(theIconRef,
  690. &owners);
  691. if (_err != noErr) return PyMac_Error(_err);
  692. _res = Py_BuildValue("H",
  693. owners);
  694. return _res;
  695. }
  696. static PyObject *Icn_AcquireIconRef(PyObject *_self, PyObject *_args)
  697. {
  698. PyObject *_res = NULL;
  699. OSErr _err;
  700. IconRef theIconRef;
  701. #ifndef AcquireIconRef
  702. PyMac_PRECHECK(AcquireIconRef);
  703. #endif
  704. if (!PyArg_ParseTuple(_args, "O&",
  705. ResObj_Convert, &theIconRef))
  706. return NULL;
  707. _err = AcquireIconRef(theIconRef);
  708. if (_err != noErr) return PyMac_Error(_err);
  709. Py_INCREF(Py_None);
  710. _res = Py_None;
  711. return _res;
  712. }
  713. static PyObject *Icn_ReleaseIconRef(PyObject *_self, PyObject *_args)
  714. {
  715. PyObject *_res = NULL;
  716. OSErr _err;
  717. IconRef theIconRef;
  718. #ifndef ReleaseIconRef
  719. PyMac_PRECHECK(ReleaseIconRef);
  720. #endif
  721. if (!PyArg_ParseTuple(_args, "O&",
  722. ResObj_Convert, &theIconRef))
  723. return NULL;
  724. _err = ReleaseIconRef(theIconRef);
  725. if (_err != noErr) return PyMac_Error(_err);
  726. Py_INCREF(Py_None);
  727. _res = Py_None;
  728. return _res;
  729. }
  730. static PyObject *Icn_GetIconRefFromFile(PyObject *_self, PyObject *_args)
  731. {
  732. PyObject *_res = NULL;
  733. OSErr _err;
  734. FSSpec theFile;
  735. IconRef theIconRef;
  736. SInt16 theLabel;
  737. #ifndef GetIconRefFromFile
  738. PyMac_PRECHECK(GetIconRefFromFile);
  739. #endif
  740. if (!PyArg_ParseTuple(_args, "O&",
  741. PyMac_GetFSSpec, &theFile))
  742. return NULL;
  743. _err = GetIconRefFromFile(&theFile,
  744. &theIconRef,
  745. &theLabel);
  746. if (_err != noErr) return PyMac_Error(_err);
  747. _res = Py_BuildValue("O&h",
  748. ResObj_New, theIconRef,
  749. theLabel);
  750. return _res;
  751. }
  752. static PyObject *Icn_GetIconRef(PyObject *_self, PyObject *_args)
  753. {
  754. PyObject *_res = NULL;
  755. OSErr _err;
  756. SInt16 vRefNum;
  757. OSType creator;
  758. OSType iconType;
  759. IconRef theIconRef;
  760. #ifndef GetIconRef
  761. PyMac_PRECHECK(GetIconRef);
  762. #endif
  763. if (!PyArg_ParseTuple(_args, "hO&O&",
  764. &vRefNum,
  765. PyMac_GetOSType, &creator,
  766. PyMac_GetOSType, &iconType))
  767. return NULL;
  768. _err = GetIconRef(vRefNum,
  769. creator,
  770. iconType,
  771. &theIconRef);
  772. if (_err != noErr) return PyMac_Error(_err);
  773. _res = Py_BuildValue("O&",
  774. ResObj_New, theIconRef);
  775. return _res;
  776. }
  777. static PyObject *Icn_GetIconRefFromFolder(PyObject *_self, PyObject *_args)
  778. {
  779. PyObject *_res = NULL;
  780. OSErr _err;
  781. SInt16 vRefNum;
  782. SInt32 parentFolderID;
  783. SInt32 folderID;
  784. SInt8 attributes;
  785. SInt8 accessPrivileges;
  786. IconRef theIconRef;
  787. #ifndef GetIconRefFromFolder
  788. PyMac_PRECHECK(GetIconRefFromFolder);
  789. #endif
  790. if (!PyArg_ParseTuple(_args, "hllbb",
  791. &vRefNum,
  792. &parentFolderID,
  793. &folderID,
  794. &attributes,
  795. &accessPrivileges))
  796. return NULL;
  797. _err = GetIconRefFromFolder(vRefNum,
  798. parentFolderID,
  799. folderID,
  800. attributes,
  801. accessPrivileges,
  802. &theIconRef);
  803. if (_err != noErr) return PyMac_Error(_err);
  804. _res = Py_BuildValue("O&",
  805. ResObj_New, theIconRef);
  806. return _res;
  807. }
  808. static PyObject *Icn_RegisterIconRefFromIconFamily(PyObject *_self, PyObject *_args)
  809. {
  810. PyObject *_res = NULL;
  811. OSErr _err;
  812. OSType creator;
  813. OSType iconType;
  814. IconFamilyHandle iconFamily;
  815. IconRef theIconRef;
  816. #ifndef RegisterIconRefFromIconFamily
  817. PyMac_PRECHECK(RegisterIconRefFromIconFamily);
  818. #endif
  819. if (!PyArg_ParseTuple(_args, "O&O&O&",
  820. PyMac_GetOSType, &creator,
  821. PyMac_GetOSType, &iconType,
  822. ResObj_Convert, &iconFamily))
  823. return NULL;
  824. _err = RegisterIconRefFromIconFamily(creator,
  825. iconType,
  826. iconFamily,
  827. &theIconRef);
  828. if (_err != noErr) return PyMac_Error(_err);
  829. _res = Py_BuildValue("O&",
  830. ResObj_New, theIconRef);
  831. return _res;
  832. }
  833. static PyObject *Icn_RegisterIconRefFromResource(PyObject *_self, PyObject *_args)
  834. {
  835. PyObject *_res = NULL;
  836. OSErr _err;
  837. OSType creator;
  838. OSType iconType;
  839. FSSpec resourceFile;
  840. SInt16 resourceID;
  841. IconRef theIconRef;
  842. #ifndef RegisterIconRefFromResource
  843. PyMac_PRECHECK(RegisterIconRefFromResource);
  844. #endif
  845. if (!PyArg_ParseTuple(_args, "O&O&O&h",
  846. PyMac_GetOSType, &creator,
  847. PyMac_GetOSType, &iconType,
  848. PyMac_GetFSSpec, &resourceFile,
  849. &resourceID))
  850. return NULL;
  851. _err = RegisterIconRefFromResource(creator,
  852. iconType,
  853. &resourceFile,
  854. resourceID,
  855. &theIconRef);
  856. if (_err != noErr) return PyMac_Error(_err);
  857. _res = Py_BuildValue("O&",
  858. ResObj_New, theIconRef);
  859. return _res;
  860. }
  861. static PyObject *Icn_RegisterIconRefFromFSRef(PyObject *_self, PyObject *_args)
  862. {
  863. PyObject *_res = NULL;
  864. OSStatus _err;
  865. OSType creator;
  866. OSType iconType;
  867. FSRef iconFile;
  868. IconRef theIconRef;
  869. #ifndef RegisterIconRefFromFSRef
  870. PyMac_PRECHECK(RegisterIconRefFromFSRef);
  871. #endif
  872. if (!PyArg_ParseTuple(_args, "O&O&O&",
  873. PyMac_GetOSType, &creator,
  874. PyMac_GetOSType, &iconType,
  875. PyMac_GetFSRef, &iconFile))
  876. return NULL;
  877. _err = RegisterIconRefFromFSRef(creator,
  878. iconType,
  879. &iconFile,
  880. &theIconRef);
  881. if (_err != noErr) return PyMac_Error(_err);
  882. _res = Py_BuildValue("O&",
  883. ResObj_New, theIconRef);
  884. return _res;
  885. }
  886. static PyObject *Icn_UnregisterIconRef(PyObject *_self, PyObject *_args)
  887. {
  888. PyObject *_res = NULL;
  889. OSErr _err;
  890. OSType creator;
  891. OSType iconType;
  892. #ifndef UnregisterIconRef
  893. PyMac_PRECHECK(UnregisterIconRef);
  894. #endif
  895. if (!PyArg_ParseTuple(_args, "O&O&",
  896. PyMac_GetOSType, &creator,
  897. PyMac_GetOSType, &iconType))
  898. return NULL;
  899. _err = UnregisterIconRef(creator,
  900. iconType);
  901. if (_err != noErr) return PyMac_Error(_err);
  902. Py_INCREF(Py_None);
  903. _res = Py_None;
  904. return _res;
  905. }
  906. static PyObject *Icn_UpdateIconRef(PyObject *_self, PyObject *_args)
  907. {
  908. PyObject *_res = NULL;
  909. OSErr _err;
  910. IconRef theIconRef;
  911. #ifndef UpdateIconRef
  912. PyMac_PRECHECK(UpdateIconRef);
  913. #endif
  914. if (!PyArg_ParseTuple(_args, "O&",
  915. ResObj_Convert, &theIconRef))
  916. return NULL;
  917. _err = UpdateIconRef(theIconRef);
  918. if (_err != noErr) return PyMac_Error(_err);
  919. Py_INCREF(Py_None);
  920. _res = Py_None;
  921. return _res;
  922. }
  923. static PyObject *Icn_OverrideIconRefFromResource(PyObject *_self, PyObject *_args)
  924. {
  925. PyObject *_res = NULL;
  926. OSErr _err;
  927. IconRef theIconRef;
  928. FSSpec resourceFile;
  929. SInt16 resourceID;
  930. #ifndef OverrideIconRefFromResource
  931. PyMac_PRECHECK(OverrideIconRefFromResource);
  932. #endif
  933. if (!PyArg_ParseTuple(_args, "O&O&h",
  934. ResObj_Convert, &theIconRef,
  935. PyMac_GetFSSpec, &resourceFile,
  936. &resourceID))
  937. return NULL;
  938. _err = OverrideIconRefFromResource(theIconRef,
  939. &resourceFile,
  940. resourceID);
  941. if (_err != noErr) return PyMac_Error(_err);
  942. Py_INCREF(Py_None);
  943. _res = Py_None;
  944. return _res;
  945. }
  946. static PyObject *Icn_OverrideIconRef(PyObject *_self, PyObject *_args)
  947. {
  948. PyObject *_res = NULL;
  949. OSErr _err;
  950. IconRef oldIconRef;
  951. IconRef newIconRef;
  952. #ifndef OverrideIconRef
  953. PyMac_PRECHECK(OverrideIconRef);
  954. #endif
  955. if (!PyArg_ParseTuple(_args, "O&O&",
  956. ResObj_Convert, &oldIconRef,
  957. ResObj_Convert, &newIconRef))
  958. return NULL;
  959. _err = OverrideIconRef(oldIconRef,
  960. newIconRef);
  961. if (_err != noErr) return PyMac_Error(_err);
  962. Py_INCREF(Py_None);
  963. _res = Py_None;
  964. return _res;
  965. }
  966. static PyObject *Icn_RemoveIconRefOverride(PyObject *_self, PyObject *_args)
  967. {
  968. PyObject *_res = NULL;
  969. OSErr _err;
  970. IconRef theIconRef;
  971. #ifndef RemoveIconRefOverride
  972. PyMac_PRECHECK(RemoveIconRefOverride);
  973. #endif
  974. if (!PyArg_ParseTuple(_args, "O&",
  975. ResObj_Convert, &theIconRef))
  976. return NULL;
  977. _err = RemoveIconRefOverride(theIconRef);
  978. if (_err != noErr) return PyMac_Error(_err);
  979. Py_INCREF(Py_None);
  980. _res = Py_None;
  981. return _res;
  982. }
  983. static PyObject *Icn_CompositeIconRef(PyObject *_self, PyObject *_args)
  984. {
  985. PyObject *_res = NULL;
  986. OSErr _err;
  987. IconRef backgroundIconRef;
  988. IconRef foregroundIconRef;
  989. IconRef compositeIconRef;
  990. #ifndef CompositeIconRef
  991. PyMac_PRECHECK(CompositeIconRef);
  992. #endif
  993. if (!PyArg_ParseTuple(_args, "O&O&",
  994. ResObj_Convert, &backgroundIconRef,
  995. ResObj_Convert, &foregroundIconRef))
  996. return NULL;
  997. _err = CompositeIconRef(backgroundIconRef,
  998. foregroundIconRef,
  999. &compositeIconRef);
  1000. if (_err != noErr) return PyMac_Error(_err);
  1001. _res = Py_BuildValue("O&",
  1002. ResObj_New, compositeIconRef);
  1003. return _res;
  1004. }
  1005. static PyObject *Icn_IsIconRefComposite(PyObject *_self, PyObject *_args)
  1006. {
  1007. PyObject *_res = NULL;
  1008. OSErr _err;
  1009. IconRef compositeIconRef;
  1010. IconRef backgroundIconRef;
  1011. IconRef foregroundIconRef;
  1012. #ifndef IsIconRefComposite
  1013. PyMac_PRECHECK(IsIconRefComposite);
  1014. #endif
  1015. if (!PyArg_ParseTuple(_args, "O&",
  1016. ResObj_Convert, &compositeIconRef))
  1017. return NULL;
  1018. _err = IsIconRefComposite(compositeIconRef,
  1019. &backgroundIconRef,
  1020. &foregroundIconRef);
  1021. if (_err != noErr) return PyMac_Error(_err);
  1022. _res = Py_BuildValue("O&O&",
  1023. ResObj_New, backgroundIconRef,
  1024. ResObj_New, foregroundIconRef);
  1025. return _res;
  1026. }
  1027. static PyObject *Icn_IsValidIconRef(PyObject *_self, PyObject *_args)
  1028. {
  1029. PyObject *_res = NULL;
  1030. Boolean _rv;
  1031. IconRef theIconRef;
  1032. #ifndef IsValidIconRef
  1033. PyMac_PRECHECK(IsValidIconRef);
  1034. #endif
  1035. if (!PyArg_ParseTuple(_args, "O&",
  1036. ResObj_Convert, &theIconRef))
  1037. return NULL;
  1038. _rv = IsValidIconRef(theIconRef);
  1039. _res = Py_BuildValue("b",
  1040. _rv);
  1041. return _res;
  1042. }
  1043. static PyObject *Icn_PlotIconRef(PyObject *_self, PyObject *_args)
  1044. {
  1045. PyObject *_res = NULL;
  1046. OSErr _err;
  1047. Rect theRect;
  1048. IconAlignmentType align;
  1049. IconTransformType transform;
  1050. IconServicesUsageFlags theIconServicesUsageFlags;
  1051. IconRef theIconRef;
  1052. #ifndef PlotIconRef
  1053. PyMac_PRECHECK(PlotIconRef);
  1054. #endif
  1055. if (!PyArg_ParseTuple(_args, "O&hhlO&",
  1056. PyMac_GetRect, &theRect,
  1057. &align,
  1058. &transform,
  1059. &theIconServicesUsageFlags,
  1060. ResObj_Convert, &theIconRef))
  1061. return NULL;
  1062. _err = PlotIconRef(&theRect,
  1063. align,
  1064. transform,
  1065. theIconServicesUsageFlags,
  1066. theIconRef);
  1067. if (_err != noErr) return PyMac_Error(_err);
  1068. Py_INCREF(Py_None);
  1069. _res = Py_None;
  1070. return _res;
  1071. }
  1072. static PyObject *Icn_PtInIconRef(PyObject *_self, PyObject *_args)
  1073. {
  1074. PyObject *_res = NULL;
  1075. Boolean _rv;
  1076. Point testPt;
  1077. Rect iconRect;
  1078. IconAlignmentType align;
  1079. IconServicesUsageFlags theIconServicesUsageFlags;
  1080. IconRef theIconRef;
  1081. #ifndef PtInIconRef
  1082. PyMac_PRECHECK(PtInIconRef);
  1083. #endif
  1084. if (!PyArg_ParseTuple(_args, "O&O&hlO&",
  1085. PyMac_GetPoint, &testPt,
  1086. PyMac_GetRect, &iconRect,
  1087. &align,
  1088. &theIconServicesUsageFlags,
  1089. ResObj_Convert, &theIconRef))
  1090. return NULL;
  1091. _rv = PtInIconRef(&testPt,
  1092. &iconRect,
  1093. align,
  1094. theIconServicesUsageFlags,
  1095. theIconRef);
  1096. _res = Py_BuildValue("b",
  1097. _rv);
  1098. return _res;
  1099. }
  1100. static PyObject *Icn_RectInIconRef(PyObject *_self, PyObject *_args)
  1101. {
  1102. PyObject *_res = NULL;
  1103. Boolean _rv;
  1104. Rect testRect;
  1105. Rect iconRect;
  1106. IconAlignmentType align;
  1107. IconServicesUsageFlags iconServicesUsageFlags;
  1108. IconRef theIconRef;
  1109. #ifndef RectInIconRef
  1110. PyMac_PRECHECK(RectInIconRef);
  1111. #endif
  1112. if (!PyArg_ParseTuple(_args, "O&O&hlO&",
  1113. PyMac_GetRect, &testRect,
  1114. PyMac_GetRect, &iconRect,
  1115. &align,
  1116. &iconServicesUsageFlags,
  1117. ResObj_Convert, &theIconRef))
  1118. return NULL;
  1119. _rv = RectInIconRef(&testRect,
  1120. &iconRect,
  1121. align,
  1122. iconServicesUsageFlags,
  1123. theIconRef);
  1124. _res = Py_BuildValue("b",
  1125. _rv);
  1126. return _res;
  1127. }
  1128. static PyObject *Icn_IconRefToRgn(PyObject *_self, PyObject *_args)
  1129. {
  1130. PyObject *_res = NULL;
  1131. OSErr _err;
  1132. RgnHandle theRgn;
  1133. Rect iconRect;
  1134. IconAlignmentType align;
  1135. IconServicesUsageFlags iconServicesUsageFlags;
  1136. IconRef theIconRef;
  1137. #ifndef IconRefToRgn
  1138. PyMac_PRECHECK(IconRefToRgn);
  1139. #endif
  1140. if (!PyArg_ParseTuple(_args, "O&O&hlO&",
  1141. ResObj_Convert, &theRgn,
  1142. PyMac_GetRect, &iconRect,
  1143. &align,
  1144. &iconServicesUsageFlags,
  1145. ResObj_Convert, &theIconRef))
  1146. return NULL;
  1147. _err = IconRefToRgn(theRgn,
  1148. &iconRect,
  1149. align,
  1150. iconServicesUsageFlags,
  1151. theIconRef);
  1152. if (_err != noErr) return PyMac_Error(_err);
  1153. Py_INCREF(Py_None);
  1154. _res = Py_None;
  1155. return _res;
  1156. }
  1157. static PyObject *Icn_GetIconSizesFromIconRef(PyObject *_self, PyObject *_args)
  1158. {
  1159. PyObject *_res = NULL;
  1160. OSErr _err;
  1161. IconSelectorValue iconSelectorInput;
  1162. IconSelectorValue iconSelectorOutputPtr;
  1163. IconServicesUsageFlags iconServicesUsageFlags;
  1164. IconRef theIconRef;
  1165. #ifndef GetIconSizesFromIconRef
  1166. PyMac_PRECHECK(GetIconSizesFromIconRef);
  1167. #endif
  1168. if (!PyArg_ParseTuple(_args, "llO&",
  1169. &iconSelectorInput,
  1170. &iconServicesUsageFlags,
  1171. ResObj_Convert, &theIconRef))
  1172. return NULL;
  1173. _err = GetIconSizesFromIconRef(iconSelectorInput,
  1174. &iconSelectorOutputPtr,
  1175. iconServicesUsageFlags,
  1176. theIconRef);
  1177. if (_err != noErr) return PyMac_Error(_err);
  1178. _res = Py_BuildValue("l",
  1179. iconSelectorOutputPtr);
  1180. return _res;
  1181. }
  1182. static PyObject *Icn_FlushIconRefs(PyObject *_self, PyObject *_args)
  1183. {
  1184. PyObject *_res = NULL;
  1185. OSErr _err;
  1186. OSType creator;
  1187. OSType iconType;
  1188. #ifndef FlushIconRefs
  1189. PyMac_PRECHECK(FlushIconRefs);
  1190. #endif
  1191. if (!PyArg_ParseTuple(_args, "O&O&",
  1192. PyMac_GetOSType, &creator,
  1193. PyMac_GetOSType, &iconType))
  1194. return NULL;
  1195. _err = FlushIconRefs(creator,
  1196. iconType);
  1197. if (_err != noErr) return PyMac_Error(_err);
  1198. Py_INCREF(Py_None);
  1199. _res = Py_None;
  1200. return _res;
  1201. }
  1202. static PyObject *Icn_FlushIconRefsByVolume(PyObject *_self, PyObject *_args)
  1203. {
  1204. PyObject *_res = NULL;
  1205. OSErr _err;
  1206. SInt16 vRefNum;
  1207. #ifndef FlushIconRefsByVolume
  1208. PyMac_PRECHECK(FlushIconRefsByVolume);
  1209. #endif
  1210. if (!PyArg_ParseTuple(_args, "h",
  1211. &vRefNum))
  1212. return NULL;
  1213. _err = FlushIconRefsByVolume(vRefNum);
  1214. if (_err != noErr) return PyMac_Error(_err);
  1215. Py_INCREF(Py_None);
  1216. _res = Py_None;
  1217. return _res;
  1218. }
  1219. static PyObject *Icn_SetCustomIconsEnabled(PyObject *_self, PyObject *_args)
  1220. {
  1221. PyObject *_res = NULL;
  1222. OSErr _err;
  1223. SInt16 vRefNum;
  1224. Boolean enableCustomIcons;
  1225. #ifndef SetCustomIconsEnabled
  1226. PyMac_PRECHECK(SetCustomIconsEnabled);
  1227. #endif
  1228. if (!PyArg_ParseTuple(_args, "hb",
  1229. &vRefNum,
  1230. &enableCustomIcons))
  1231. return NULL;
  1232. _err = SetCustomIconsEnabled(vRefNum,
  1233. enableCustomIcons);
  1234. if (_err != noErr) return PyMac_Error(_err);
  1235. Py_INCREF(Py_None);
  1236. _res = Py_None;
  1237. return _res;
  1238. }
  1239. static PyObject *Icn_GetCustomIconsEnabled(PyObject *_self, PyObject *_args)
  1240. {
  1241. PyObject *_res = NULL;
  1242. OSErr _err;
  1243. SInt16 vRefNum;
  1244. Boolean customIconsEnabled;
  1245. #ifndef GetCustomIconsEnabled
  1246. PyMac_PRECHECK(GetCustomIconsEnabled);
  1247. #endif
  1248. if (!PyArg_ParseTuple(_args, "h",
  1249. &vRefNum))
  1250. return NULL;
  1251. _err = GetCustomIconsEnabled(vRefNum,
  1252. &customIconsEnabled);
  1253. if (_err != noErr) return PyMac_Error(_err);
  1254. _res = Py_BuildValue("b",
  1255. customIconsEnabled);
  1256. return _res;
  1257. }
  1258. static PyObject *Icn_IsIconRefMaskEmpty(PyObject *_self, PyObject *_args)
  1259. {
  1260. PyObject *_res = NULL;
  1261. Boolean _rv;
  1262. IconRef iconRef;
  1263. #ifndef IsIconRefMaskEmpty
  1264. PyMac_PRECHECK(IsIconRefMaskEmpty);
  1265. #endif
  1266. if (!PyArg_ParseTuple(_args, "O&",
  1267. ResObj_Convert, &iconRef))
  1268. return NULL;
  1269. _rv = IsIconRefMaskEmpty(iconRef);
  1270. _res = Py_BuildValue("b",
  1271. _rv);
  1272. return _res;
  1273. }
  1274. static PyObject *Icn_GetIconRefVariant(PyObject *_self, PyObject *_args)
  1275. {
  1276. PyObject *_res = NULL;
  1277. IconRef _rv;
  1278. IconRef inIconRef;
  1279. OSType inVariant;
  1280. IconTransformType outTransform;
  1281. #ifndef GetIconRefVariant
  1282. PyMac_PRECHECK(GetIconRefVariant);
  1283. #endif
  1284. if (!PyArg_ParseTuple(_args, "O&O&",
  1285. ResObj_Convert, &inIconRef,
  1286. PyMac_GetOSType, &inVariant))
  1287. return NULL;
  1288. _rv = GetIconRefVariant(inIconRef,
  1289. inVariant,
  1290. &outTransform);
  1291. _res = Py_BuildValue("O&h",
  1292. ResObj_New, _rv,
  1293. outTransform);
  1294. return _res;
  1295. }
  1296. static PyObject *Icn_RegisterIconRefFromIconFile(PyObject *_self, PyObject *_args)
  1297. {
  1298. PyObject *_res = NULL;
  1299. OSErr _err;
  1300. OSType creator;
  1301. OSType iconType;
  1302. FSSpec iconFile;
  1303. IconRef theIconRef;
  1304. #ifndef RegisterIconRefFromIconFile
  1305. PyMac_PRECHECK(RegisterIconRefFromIconFile);
  1306. #endif
  1307. if (!PyArg_ParseTuple(_args, "O&O&O&",
  1308. PyMac_GetOSType, &creator,
  1309. PyMac_GetOSType, &iconType,
  1310. PyMac_GetFSSpec, &iconFile))
  1311. return NULL;
  1312. _err = RegisterIconRefFromIconFile(creator,
  1313. iconType,
  1314. &iconFile,
  1315. &theIconRef);
  1316. if (_err != noErr) return PyMac_Error(_err);
  1317. _res = Py_BuildValue("O&",
  1318. ResObj_New, theIconRef);
  1319. return _res;
  1320. }
  1321. static PyObject *Icn_ReadIconFile(PyObject *_self, PyObject *_args)
  1322. {
  1323. PyObject *_res = NULL;
  1324. OSErr _err;
  1325. FSSpec iconFile;
  1326. IconFamilyHandle iconFamily;
  1327. #ifndef ReadIconFile
  1328. PyMac_PRECHECK(ReadIconFile);
  1329. #endif
  1330. if (!PyArg_ParseTuple(_args, "O&",
  1331. PyMac_GetFSSpec, &iconFile))
  1332. return NULL;
  1333. _err = ReadIconFile(&iconFile,
  1334. &iconFamily);
  1335. if (_err != noErr) return PyMac_Error(_err);
  1336. _res = Py_BuildValue("O&",
  1337. ResObj_New, iconFamily);
  1338. return _res;
  1339. }
  1340. static PyObject *Icn_ReadIconFromFSRef(PyObject *_self, PyObject *_args)
  1341. {
  1342. PyObject *_res = NULL;
  1343. OSStatus _err;
  1344. FSRef ref;
  1345. IconFamilyHandle iconFamily;
  1346. #ifndef ReadIconFromFSRef
  1347. PyMac_PRECHECK(ReadIconFromFSRef);
  1348. #endif
  1349. if (!PyArg_ParseTuple(_args, "O&",
  1350. PyMac_GetFSRef, &ref))
  1351. return NULL;
  1352. _err = ReadIconFromFSRef(&ref,
  1353. &iconFamily);
  1354. if (_err != noErr) return PyMac_Error(_err);
  1355. _res = Py_BuildValue("O&",
  1356. ResObj_New, iconFamily);
  1357. return _res;
  1358. }
  1359. static PyObject *Icn_WriteIconFile(PyObject *_self, PyObject *_args)
  1360. {
  1361. PyObject *_res = NULL;
  1362. OSErr _err;
  1363. IconFamilyHandle iconFamily;
  1364. FSSpec iconFile;
  1365. #ifndef WriteIconFile
  1366. PyMac_PRECHECK(WriteIconFile);
  1367. #endif
  1368. if (!PyArg_ParseTuple(_args, "O&O&",
  1369. ResObj_Convert, &iconFamily,
  1370. PyMac_GetFSSpec, &iconFile))
  1371. return NULL;
  1372. _err = WriteIconFile(iconFamily,
  1373. &iconFile);
  1374. if (_err != noErr) return PyMac_Error(_err);
  1375. Py_INCREF(Py_None);
  1376. _res = Py_None;
  1377. return _res;
  1378. }
  1379. #endif /* __LP64__ */
  1380. static PyMethodDef Icn_methods[] = {
  1381. #ifndef __LP64__
  1382. {"GetCIcon", (PyCFunction)Icn_GetCIcon, 1,
  1383. PyDoc_STR("(SInt16 iconID) -> (CIconHandle _rv)")},
  1384. {"PlotCIcon", (PyCFunction)Icn_PlotCIcon, 1,
  1385. PyDoc_STR("(Rect theRect, CIconHandle theIcon) -> None")},
  1386. {"DisposeCIcon", (PyCFunction)Icn_DisposeCIcon, 1,
  1387. PyDoc_STR("(CIconHandle theIcon) -> None")},
  1388. {"GetIcon", (PyCFunction)Icn_GetIcon, 1,
  1389. PyDoc_STR("(SInt16 iconID) -> (Handle _rv)")},
  1390. {"PlotIcon", (PyCFunction)Icn_PlotIcon, 1,
  1391. PyDoc_STR("(Rect theRect, Handle theIcon) -> None")},
  1392. {"PlotIconID", (PyCFunction)Icn_PlotIconID, 1,
  1393. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, SInt16 theResID) -> None")},
  1394. {"NewIconSuite", (PyCFunction)Icn_NewIconSuite, 1,
  1395. PyDoc_STR("() -> (IconSuiteRef theIconSuite)")},
  1396. {"AddIconToSuite", (PyCFunction)Icn_AddIconToSuite, 1,
  1397. PyDoc_STR("(Handle theIconData, IconSuiteRef theSuite, ResType theType) -> None")},
  1398. {"GetIconFromSuite", (PyCFunction)Icn_GetIconFromSuite, 1,
  1399. PyDoc_STR("(IconSuiteRef theSuite, ResType theType) -> (Handle theIconData)")},
  1400. {"GetIconSuite", (PyCFunction)Icn_GetIconSuite, 1,
  1401. PyDoc_STR("(SInt16 theResID, IconSelectorValue selector) -> (IconSuiteRef theIconSuite)")},
  1402. {"DisposeIconSuite", (PyCFunction)Icn_DisposeIconSuite, 1,
  1403. PyDoc_STR("(IconSuiteRef theIconSuite, Boolean disposeData) -> None")},
  1404. {"PlotIconSuite", (PyCFunction)Icn_PlotIconSuite, 1,
  1405. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, IconSuiteRef theIconSuite) -> None")},
  1406. {"LoadIconCache", (PyCFunction)Icn_LoadIconCache, 1,
  1407. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, IconCacheRef theIconCache) -> None")},
  1408. {"GetLabel", (PyCFunction)Icn_GetLabel, 1,
  1409. PyDoc_STR("(SInt16 labelNumber, Str255 labelString) -> (RGBColor labelColor)")},
  1410. {"PtInIconID", (PyCFunction)Icn_PtInIconID, 1,
  1411. PyDoc_STR("(Point testPt, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> (Boolean _rv)")},
  1412. {"PtInIconSuite", (PyCFunction)Icn_PtInIconSuite, 1,
  1413. PyDoc_STR("(Point testPt, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> (Boolean _rv)")},
  1414. {"RectInIconID", (PyCFunction)Icn_RectInIconID, 1,
  1415. PyDoc_STR("(Rect testRect, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> (Boolean _rv)")},
  1416. {"RectInIconSuite", (PyCFunction)Icn_RectInIconSuite, 1,
  1417. PyDoc_STR("(Rect testRect, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> (Boolean _rv)")},
  1418. {"IconIDToRgn", (PyCFunction)Icn_IconIDToRgn, 1,
  1419. PyDoc_STR("(RgnHandle theRgn, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> None")},
  1420. {"IconSuiteToRgn", (PyCFunction)Icn_IconSuiteToRgn, 1,
  1421. PyDoc_STR("(RgnHandle theRgn, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> None")},
  1422. {"SetSuiteLabel", (PyCFunction)Icn_SetSuiteLabel, 1,
  1423. PyDoc_STR("(IconSuiteRef theSuite, SInt16 theLabel) -> None")},
  1424. {"GetSuiteLabel", (PyCFunction)Icn_GetSuiteLabel, 1,
  1425. PyDoc_STR("(IconSuiteRef theSuite) -> (SInt16 _rv)")},
  1426. {"PlotIconHandle", (PyCFunction)Icn_PlotIconHandle, 1,
  1427. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, Handle theIcon) -> None")},
  1428. {"PlotSICNHandle", (PyCFunction)Icn_PlotSICNHandle, 1,
  1429. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, Handle theSICN) -> None")},
  1430. {"PlotCIconHandle", (PyCFunction)Icn_PlotCIconHandle, 1,
  1431. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, CIconHandle theCIcon) -> None")},
  1432. {"IconRefToIconFamily", (PyCFunction)Icn_IconRefToIconFamily, 1,
  1433. PyDoc_STR("(IconRef theIconRef, IconSelectorValue whichIcons) -> (IconFamilyHandle iconFamily)")},
  1434. {"IconFamilyToIconSuite", (PyCFunction)Icn_IconFamilyToIconSuite, 1,
  1435. PyDoc_STR("(IconFamilyHandle iconFamily, IconSelectorValue whichIcons) -> (IconSuiteRef iconSuite)")},
  1436. {"IconSuiteToIconFamily", (PyCFunction)Icn_IconSuiteToIconFamily, 1,
  1437. PyDoc_STR("(IconSuiteRef iconSuite, IconSelectorValue whichIcons) -> (IconFamilyHandle iconFamily)")},
  1438. {"SetIconFamilyData", (PyCFunction)Icn_SetIconFamilyData, 1,
  1439. PyDoc_STR("(IconFamilyHandle iconFamily, OSType iconType, Handle h) -> None")},
  1440. {"GetIconFamilyData", (PyCFunction)Icn_GetIconFamilyData, 1,
  1441. PyDoc_STR("(IconFamilyHandle iconFamily, OSType iconType, Handle h) -> None")},
  1442. {"GetIconRefOwners", (PyCFunction)Icn_GetIconRefOwners, 1,
  1443. PyDoc_STR("(IconRef theIconRef) -> (UInt16 owners)")},
  1444. {"AcquireIconRef", (PyCFunction)Icn_AcquireIconRef, 1,
  1445. PyDoc_STR("(IconRef theIconRef) -> None")},
  1446. {"ReleaseIconRef", (PyCFunction)Icn_ReleaseIconRef, 1,
  1447. PyDoc_STR("(IconRef theIconRef) -> None")},
  1448. {"GetIconRefFromFile", (PyCFunction)Icn_GetIconRefFromFile, 1,
  1449. PyDoc_STR("(FSSpec theFile) -> (IconRef theIconRef, SInt16 theLabel)")},
  1450. {"GetIconRef", (PyCFunction)Icn_GetIconRef, 1,
  1451. PyDoc_STR("(SInt16 vRefNum, OSType creator, OSType iconType) -> (IconRef theIconRef)")},
  1452. {"GetIconRefFromFolder", (PyCFunction)Icn_GetIconRefFromFolder, 1,
  1453. PyDoc_STR("(SInt16 vRefNum, SInt32 parentFolderID, SInt32 folderID, SInt8 attributes, SInt8 accessPrivileges) -> (IconRef theIconRef)")},
  1454. {"RegisterIconRefFromIconFamily", (PyCFunction)Icn_RegisterIconRefFromIconFamily, 1,
  1455. PyDoc_STR("(OSType creator, OSType iconType, IconFamilyHandle iconFamily) -> (IconRef theIconRef)")},
  1456. {"RegisterIconRefFromResource", (PyCFunction)Icn_RegisterIconRefFromResource, 1,
  1457. PyDoc_STR("(OSType creator, OSType iconType, FSSpec resourceFile, SInt16 resourceID) -> (IconRef theIconRef)")},
  1458. {"RegisterIconRefFromFSRef", (PyCFunction)Icn_RegisterIconRefFromFSRef, 1,
  1459. PyDoc_STR("(OSType creator, OSType iconType, FSRef iconFile) -> (IconRef theIconRef)")},
  1460. {"UnregisterIconRef", (PyCFunction)Icn_UnregisterIconRef, 1,
  1461. PyDoc_STR("(OSType creator, OSType iconType) -> None")},
  1462. {"UpdateIconRef", (PyCFunction)Icn_UpdateIconRef, 1,
  1463. PyDoc_STR("(IconRef theIconRef) -> None")},
  1464. {"OverrideIconRefFromResource", (PyCFunction)Icn_OverrideIconRefFromResource, 1,
  1465. PyDoc_STR("(IconRef theIconRef, FSSpec resourceFile, SInt16 resourceID) -> None")},
  1466. {"OverrideIconRef", (PyCFunction)Icn_OverrideIconRef, 1,
  1467. PyDoc_STR("(IconRef oldIconRef, IconRef newIconRef) -> None")},
  1468. {"RemoveIconRefOverride", (PyCFunction)Icn_RemoveIconRefOverride, 1,
  1469. PyDoc_STR("(IconRef theIconRef) -> None")},
  1470. {"CompositeIconRef", (PyCFunction)Icn_CompositeIconRef, 1,
  1471. PyDoc_STR("(IconRef backgroundIconRef, IconRef foregroundIconRef) -> (IconRef compositeIconRef)")},
  1472. {"IsIconRefComposite", (PyCFunction)Icn_IsIconRefComposite, 1,
  1473. PyDoc_STR("(IconRef compositeIconRef) -> (IconRef backgroundIconRef, IconRef foregroundIconRef)")},
  1474. {"IsValidIconRef", (PyCFunction)Icn_IsValidIconRef, 1,
  1475. PyDoc_STR("(IconRef theIconRef) -> (Boolean _rv)")},
  1476. {"PlotIconRef", (PyCFunction)Icn_PlotIconRef, 1,
  1477. PyDoc_STR("(Rect theRect, IconAlignmentType align, IconTransformType transform, IconServicesUsageFlags theIconServicesUsageFlags, IconRef theIconRef) -> None")},
  1478. {"PtInIconRef", (PyCFunction)Icn_PtInIconRef, 1,
  1479. PyDoc_STR("(Point testPt, Rect iconRect, IconAlignmentType align, IconServicesUsageFlags theIconServicesUsageFlags, IconRef theIconRef) -> (Boolean _rv)")},
  1480. {"RectInIconRef", (PyCFunction)Icn_RectInIconRef, 1,
  1481. PyDoc_STR("(Rect testRect, Rect iconRect, IconAlignmentType align, IconServicesUsageFlags iconServicesUsageFlags, IconRef theIconRef) -> (Boolean _rv)")},
  1482. {"IconRefToRgn", (PyCFunction)Icn_IconRefToRgn, 1,
  1483. PyDoc_STR("(RgnHandle theRgn, Rect iconRect, IconAlignmentType align, IconServicesUsageFlags iconServicesUsageFlags, IconRef theIconRef) -> None")},
  1484. {"GetIconSizesFromIconRef", (PyCFunction)Icn_GetIconSizesFromIconRef, 1,
  1485. PyDoc_STR("(IconSelectorValue iconSelectorInput, IconServicesUsageFlags iconServicesUsageFlags, IconRef theIconRef) -> (IconSelectorValue iconSelectorOutputPtr)")},
  1486. {"FlushIconRefs", (PyCFunction)Icn_FlushIconRefs, 1,
  1487. PyDoc_STR("(OSType creator, OSType iconType) -> None")},
  1488. {"FlushIconRefsByVolume", (PyCFunction)Icn_FlushIconRefsByVolume, 1,
  1489. PyDoc_STR("(SInt16 vRefNum) -> None")},
  1490. {"SetCustomIconsEnabled", (PyCFunction)Icn_SetCustomIconsEnabled, 1,
  1491. PyDoc_STR("(SInt16 vRefNum, Boolean enableCustomIcons) -> None")},
  1492. {"GetCustomIconsEnabled", (PyCFunction)Icn_GetCustomIconsEnabled, 1,
  1493. PyDoc_STR("(SInt16 vRefNum) -> (Boolean customIconsEnabled)")},
  1494. {"IsIconRefMaskEmpty", (PyCFunction)Icn_IsIconRefMaskEmpty, 1,
  1495. PyDoc_STR("(IconRef iconRef) -> (Boolean _rv)")},
  1496. {"GetIconRefVariant", (PyCFunction)Icn_GetIconRefVariant, 1,
  1497. PyDoc_STR("(IconRef inIconRef, OSType inVariant) -> (IconRef _rv, IconTransformType outTransform)")},
  1498. {"RegisterIconRefFromIconFile", (PyCFunction)Icn_RegisterIconRefFromIconFile, 1,
  1499. PyDoc_STR("(OSType creator, OSType iconType, FSSpec iconFile) -> (IconRef theIconRef)")},
  1500. {"ReadIconFile", (PyCFunction)Icn_ReadIconFile, 1,
  1501. PyDoc_STR("(FSSpec iconFile) -> (IconFamilyHandle iconFamily)")},
  1502. {"ReadIconFromFSRef", (PyCFunction)Icn_ReadIconFromFSRef, 1,
  1503. PyDoc_STR("(FSRef ref) -> (IconFamilyHandle iconFamily)")},
  1504. {"WriteIconFile", (PyCFunction)Icn_WriteIconFile, 1,
  1505. PyDoc_STR("(IconFamilyHandle iconFamily, FSSpec iconFile) -> None")},
  1506. #endif /* __LP64__ */
  1507. {NULL, NULL, 0}
  1508. };
  1509. void init_Icn(void)
  1510. {
  1511. PyObject *m;
  1512. #ifndef __LP64__
  1513. PyObject *d;
  1514. #endif /* __LP64__ */
  1515. m = Py_InitModule("_Icn", Icn_methods);
  1516. #ifndef __LP64__
  1517. d = PyModule_GetDict(m);
  1518. Icn_Error = PyMac_GetOSErrException();
  1519. if (Icn_Error == NULL ||
  1520. PyDict_SetItemString(d, "Error", Icn_Error) != 0)
  1521. return;
  1522. #endif /* __LP64__ */
  1523. }
  1524. /* ======================== End module _Icn ========================= */