Allow comment characters (#) to be escaped:
[python/dscho.git] / Mac / Modules / icn / Icnmodule.c
blob03e62036841a7904d5a0bf0fc2b638cb754c33d7
2 /* =========================== Module Icn =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern int ResObj_Convert(PyObject *, Handle *);
18 extern PyObject *OptResObj_New(Handle);
19 extern int OptResObj_Convert(PyObject *, Handle *);
21 extern PyObject *WinObj_New(WindowPtr);
22 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyTypeObject Window_Type;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject *DlgObj_New(DialogPtr);
27 extern int DlgObj_Convert(PyObject *, DialogPtr *);
28 extern PyTypeObject Dialog_Type;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject *MenuObj_New(MenuHandle);
32 extern int MenuObj_Convert(PyObject *, MenuHandle *);
34 extern PyObject *CtlObj_New(ControlHandle);
35 extern int CtlObj_Convert(PyObject *, ControlHandle *);
37 extern PyObject *GrafObj_New(GrafPtr);
38 extern int GrafObj_Convert(PyObject *, GrafPtr *);
40 extern PyObject *BMObj_New(BitMapPtr);
41 extern int BMObj_Convert(PyObject *, BitMapPtr *);
43 extern PyObject *WinObj_WhichWindow(WindowPtr);
45 #include <Icons.h>
47 /* Exported by Qdmodule.c: */
48 extern PyObject *QdRGB_New(RGBColor *);
49 extern int QdRGB_Convert(PyObject *, RGBColor *);
51 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
53 static PyObject *Icn_Error;
55 static PyObject *Icn_GetCIcon(_self, _args)
56 PyObject *_self;
57 PyObject *_args;
59 PyObject *_res = NULL;
60 CIconHandle _rv;
61 SInt16 iconID;
62 if (!PyArg_ParseTuple(_args, "h",
63 &iconID))
64 return NULL;
65 _rv = GetCIcon(iconID);
66 _res = Py_BuildValue("O&",
67 ResObj_New, _rv);
68 return _res;
71 static PyObject *Icn_PlotCIcon(_self, _args)
72 PyObject *_self;
73 PyObject *_args;
75 PyObject *_res = NULL;
76 Rect theRect;
77 CIconHandle theIcon;
78 if (!PyArg_ParseTuple(_args, "O&O&",
79 PyMac_GetRect, &theRect,
80 ResObj_Convert, &theIcon))
81 return NULL;
82 PlotCIcon(&theRect,
83 theIcon);
84 Py_INCREF(Py_None);
85 _res = Py_None;
86 return _res;
89 static PyObject *Icn_DisposeCIcon(_self, _args)
90 PyObject *_self;
91 PyObject *_args;
93 PyObject *_res = NULL;
94 CIconHandle theIcon;
95 if (!PyArg_ParseTuple(_args, "O&",
96 ResObj_Convert, &theIcon))
97 return NULL;
98 DisposeCIcon(theIcon);
99 Py_INCREF(Py_None);
100 _res = Py_None;
101 return _res;
104 static PyObject *Icn_GetIcon(_self, _args)
105 PyObject *_self;
106 PyObject *_args;
108 PyObject *_res = NULL;
109 Handle _rv;
110 SInt16 iconID;
111 if (!PyArg_ParseTuple(_args, "h",
112 &iconID))
113 return NULL;
114 _rv = GetIcon(iconID);
115 _res = Py_BuildValue("O&",
116 ResObj_New, _rv);
117 return _res;
120 static PyObject *Icn_PlotIcon(_self, _args)
121 PyObject *_self;
122 PyObject *_args;
124 PyObject *_res = NULL;
125 Rect theRect;
126 Handle theIcon;
127 if (!PyArg_ParseTuple(_args, "O&O&",
128 PyMac_GetRect, &theRect,
129 ResObj_Convert, &theIcon))
130 return NULL;
131 PlotIcon(&theRect,
132 theIcon);
133 Py_INCREF(Py_None);
134 _res = Py_None;
135 return _res;
138 static PyObject *Icn_PlotIconID(_self, _args)
139 PyObject *_self;
140 PyObject *_args;
142 PyObject *_res = NULL;
143 OSErr _err;
144 Rect theRect;
145 IconAlignmentType align;
146 IconTransformType transform;
147 SInt16 theResID;
148 if (!PyArg_ParseTuple(_args, "O&hhh",
149 PyMac_GetRect, &theRect,
150 &align,
151 &transform,
152 &theResID))
153 return NULL;
154 _err = PlotIconID(&theRect,
155 align,
156 transform,
157 theResID);
158 if (_err != noErr) return PyMac_Error(_err);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
164 static PyObject *Icn_NewIconSuite(_self, _args)
165 PyObject *_self;
166 PyObject *_args;
168 PyObject *_res = NULL;
169 OSErr _err;
170 IconSuiteRef theIconSuite;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _err = NewIconSuite(&theIconSuite);
174 if (_err != noErr) return PyMac_Error(_err);
175 _res = Py_BuildValue("O&",
176 ResObj_New, theIconSuite);
177 return _res;
180 static PyObject *Icn_AddIconToSuite(_self, _args)
181 PyObject *_self;
182 PyObject *_args;
184 PyObject *_res = NULL;
185 OSErr _err;
186 Handle theIconData;
187 IconSuiteRef theSuite;
188 ResType theType;
189 if (!PyArg_ParseTuple(_args, "O&O&O&",
190 ResObj_Convert, &theIconData,
191 ResObj_Convert, &theSuite,
192 PyMac_GetOSType, &theType))
193 return NULL;
194 _err = AddIconToSuite(theIconData,
195 theSuite,
196 theType);
197 if (_err != noErr) return PyMac_Error(_err);
198 Py_INCREF(Py_None);
199 _res = Py_None;
200 return _res;
203 static PyObject *Icn_GetIconFromSuite(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
207 PyObject *_res = NULL;
208 OSErr _err;
209 Handle theIconData;
210 IconSuiteRef theSuite;
211 ResType theType;
212 if (!PyArg_ParseTuple(_args, "O&O&",
213 ResObj_Convert, &theSuite,
214 PyMac_GetOSType, &theType))
215 return NULL;
216 _err = GetIconFromSuite(&theIconData,
217 theSuite,
218 theType);
219 if (_err != noErr) return PyMac_Error(_err);
220 _res = Py_BuildValue("O&",
221 ResObj_New, theIconData);
222 return _res;
225 static PyObject *Icn_GetIconSuite(_self, _args)
226 PyObject *_self;
227 PyObject *_args;
229 PyObject *_res = NULL;
230 OSErr _err;
231 IconSuiteRef theIconSuite;
232 SInt16 theResID;
233 IconSelectorValue selector;
234 if (!PyArg_ParseTuple(_args, "hl",
235 &theResID,
236 &selector))
237 return NULL;
238 _err = GetIconSuite(&theIconSuite,
239 theResID,
240 selector);
241 if (_err != noErr) return PyMac_Error(_err);
242 _res = Py_BuildValue("O&",
243 ResObj_New, theIconSuite);
244 return _res;
247 static PyObject *Icn_DisposeIconSuite(_self, _args)
248 PyObject *_self;
249 PyObject *_args;
251 PyObject *_res = NULL;
252 OSErr _err;
253 IconSuiteRef theIconSuite;
254 Boolean disposeData;
255 if (!PyArg_ParseTuple(_args, "O&b",
256 ResObj_Convert, &theIconSuite,
257 &disposeData))
258 return NULL;
259 _err = DisposeIconSuite(theIconSuite,
260 disposeData);
261 if (_err != noErr) return PyMac_Error(_err);
262 Py_INCREF(Py_None);
263 _res = Py_None;
264 return _res;
267 static PyObject *Icn_PlotIconSuite(_self, _args)
268 PyObject *_self;
269 PyObject *_args;
271 PyObject *_res = NULL;
272 OSErr _err;
273 Rect theRect;
274 IconAlignmentType align;
275 IconTransformType transform;
276 IconSuiteRef theIconSuite;
277 if (!PyArg_ParseTuple(_args, "O&hhO&",
278 PyMac_GetRect, &theRect,
279 &align,
280 &transform,
281 ResObj_Convert, &theIconSuite))
282 return NULL;
283 _err = PlotIconSuite(&theRect,
284 align,
285 transform,
286 theIconSuite);
287 if (_err != noErr) return PyMac_Error(_err);
288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
293 static PyObject *Icn_LoadIconCache(_self, _args)
294 PyObject *_self;
295 PyObject *_args;
297 PyObject *_res = NULL;
298 OSErr _err;
299 Rect theRect;
300 IconAlignmentType align;
301 IconTransformType transform;
302 IconCacheRef theIconCache;
303 if (!PyArg_ParseTuple(_args, "O&hhO&",
304 PyMac_GetRect, &theRect,
305 &align,
306 &transform,
307 ResObj_Convert, &theIconCache))
308 return NULL;
309 _err = LoadIconCache(&theRect,
310 align,
311 transform,
312 theIconCache);
313 if (_err != noErr) return PyMac_Error(_err);
314 Py_INCREF(Py_None);
315 _res = Py_None;
316 return _res;
319 static PyObject *Icn_GetLabel(_self, _args)
320 PyObject *_self;
321 PyObject *_args;
323 PyObject *_res = NULL;
324 OSErr _err;
325 SInt16 labelNumber;
326 RGBColor labelColor;
327 Str255 labelString;
328 if (!PyArg_ParseTuple(_args, "hO&",
329 &labelNumber,
330 PyMac_GetStr255, labelString))
331 return NULL;
332 _err = GetLabel(labelNumber,
333 &labelColor,
334 labelString);
335 if (_err != noErr) return PyMac_Error(_err);
336 _res = Py_BuildValue("O&",
337 QdRGB_New, &labelColor);
338 return _res;
341 static PyObject *Icn_PtInIconID(_self, _args)
342 PyObject *_self;
343 PyObject *_args;
345 PyObject *_res = NULL;
346 Boolean _rv;
347 Point testPt;
348 Rect iconRect;
349 IconAlignmentType align;
350 SInt16 iconID;
351 if (!PyArg_ParseTuple(_args, "O&O&hh",
352 PyMac_GetPoint, &testPt,
353 PyMac_GetRect, &iconRect,
354 &align,
355 &iconID))
356 return NULL;
357 _rv = PtInIconID(testPt,
358 &iconRect,
359 align,
360 iconID);
361 _res = Py_BuildValue("b",
362 _rv);
363 return _res;
366 static PyObject *Icn_PtInIconSuite(_self, _args)
367 PyObject *_self;
368 PyObject *_args;
370 PyObject *_res = NULL;
371 Boolean _rv;
372 Point testPt;
373 Rect iconRect;
374 IconAlignmentType align;
375 IconSuiteRef theIconSuite;
376 if (!PyArg_ParseTuple(_args, "O&O&hO&",
377 PyMac_GetPoint, &testPt,
378 PyMac_GetRect, &iconRect,
379 &align,
380 ResObj_Convert, &theIconSuite))
381 return NULL;
382 _rv = PtInIconSuite(testPt,
383 &iconRect,
384 align,
385 theIconSuite);
386 _res = Py_BuildValue("b",
387 _rv);
388 return _res;
391 static PyObject *Icn_RectInIconID(_self, _args)
392 PyObject *_self;
393 PyObject *_args;
395 PyObject *_res = NULL;
396 Boolean _rv;
397 Rect testRect;
398 Rect iconRect;
399 IconAlignmentType align;
400 SInt16 iconID;
401 if (!PyArg_ParseTuple(_args, "O&O&hh",
402 PyMac_GetRect, &testRect,
403 PyMac_GetRect, &iconRect,
404 &align,
405 &iconID))
406 return NULL;
407 _rv = RectInIconID(&testRect,
408 &iconRect,
409 align,
410 iconID);
411 _res = Py_BuildValue("b",
412 _rv);
413 return _res;
416 static PyObject *Icn_RectInIconSuite(_self, _args)
417 PyObject *_self;
418 PyObject *_args;
420 PyObject *_res = NULL;
421 Boolean _rv;
422 Rect testRect;
423 Rect iconRect;
424 IconAlignmentType align;
425 IconSuiteRef theIconSuite;
426 if (!PyArg_ParseTuple(_args, "O&O&hO&",
427 PyMac_GetRect, &testRect,
428 PyMac_GetRect, &iconRect,
429 &align,
430 ResObj_Convert, &theIconSuite))
431 return NULL;
432 _rv = RectInIconSuite(&testRect,
433 &iconRect,
434 align,
435 theIconSuite);
436 _res = Py_BuildValue("b",
437 _rv);
438 return _res;
441 static PyObject *Icn_IconIDToRgn(_self, _args)
442 PyObject *_self;
443 PyObject *_args;
445 PyObject *_res = NULL;
446 OSErr _err;
447 RgnHandle theRgn;
448 Rect iconRect;
449 IconAlignmentType align;
450 SInt16 iconID;
451 if (!PyArg_ParseTuple(_args, "O&O&hh",
452 ResObj_Convert, &theRgn,
453 PyMac_GetRect, &iconRect,
454 &align,
455 &iconID))
456 return NULL;
457 _err = IconIDToRgn(theRgn,
458 &iconRect,
459 align,
460 iconID);
461 if (_err != noErr) return PyMac_Error(_err);
462 Py_INCREF(Py_None);
463 _res = Py_None;
464 return _res;
467 static PyObject *Icn_IconSuiteToRgn(_self, _args)
468 PyObject *_self;
469 PyObject *_args;
471 PyObject *_res = NULL;
472 OSErr _err;
473 RgnHandle theRgn;
474 Rect iconRect;
475 IconAlignmentType align;
476 IconSuiteRef theIconSuite;
477 if (!PyArg_ParseTuple(_args, "O&O&hO&",
478 ResObj_Convert, &theRgn,
479 PyMac_GetRect, &iconRect,
480 &align,
481 ResObj_Convert, &theIconSuite))
482 return NULL;
483 _err = IconSuiteToRgn(theRgn,
484 &iconRect,
485 align,
486 theIconSuite);
487 if (_err != noErr) return PyMac_Error(_err);
488 Py_INCREF(Py_None);
489 _res = Py_None;
490 return _res;
493 static PyObject *Icn_SetSuiteLabel(_self, _args)
494 PyObject *_self;
495 PyObject *_args;
497 PyObject *_res = NULL;
498 OSErr _err;
499 IconSuiteRef theSuite;
500 SInt16 theLabel;
501 if (!PyArg_ParseTuple(_args, "O&h",
502 ResObj_Convert, &theSuite,
503 &theLabel))
504 return NULL;
505 _err = SetSuiteLabel(theSuite,
506 theLabel);
507 if (_err != noErr) return PyMac_Error(_err);
508 Py_INCREF(Py_None);
509 _res = Py_None;
510 return _res;
513 static PyObject *Icn_GetSuiteLabel(_self, _args)
514 PyObject *_self;
515 PyObject *_args;
517 PyObject *_res = NULL;
518 SInt16 _rv;
519 IconSuiteRef theSuite;
520 if (!PyArg_ParseTuple(_args, "O&",
521 ResObj_Convert, &theSuite))
522 return NULL;
523 _rv = GetSuiteLabel(theSuite);
524 _res = Py_BuildValue("h",
525 _rv);
526 return _res;
529 static PyObject *Icn_PlotIconHandle(_self, _args)
530 PyObject *_self;
531 PyObject *_args;
533 PyObject *_res = NULL;
534 OSErr _err;
535 Rect theRect;
536 IconAlignmentType align;
537 IconTransformType transform;
538 Handle theIcon;
539 if (!PyArg_ParseTuple(_args, "O&hhO&",
540 PyMac_GetRect, &theRect,
541 &align,
542 &transform,
543 ResObj_Convert, &theIcon))
544 return NULL;
545 _err = PlotIconHandle(&theRect,
546 align,
547 transform,
548 theIcon);
549 if (_err != noErr) return PyMac_Error(_err);
550 Py_INCREF(Py_None);
551 _res = Py_None;
552 return _res;
555 static PyObject *Icn_PlotSICNHandle(_self, _args)
556 PyObject *_self;
557 PyObject *_args;
559 PyObject *_res = NULL;
560 OSErr _err;
561 Rect theRect;
562 IconAlignmentType align;
563 IconTransformType transform;
564 Handle theSICN;
565 if (!PyArg_ParseTuple(_args, "O&hhO&",
566 PyMac_GetRect, &theRect,
567 &align,
568 &transform,
569 ResObj_Convert, &theSICN))
570 return NULL;
571 _err = PlotSICNHandle(&theRect,
572 align,
573 transform,
574 theSICN);
575 if (_err != noErr) return PyMac_Error(_err);
576 Py_INCREF(Py_None);
577 _res = Py_None;
578 return _res;
581 static PyObject *Icn_PlotCIconHandle(_self, _args)
582 PyObject *_self;
583 PyObject *_args;
585 PyObject *_res = NULL;
586 OSErr _err;
587 Rect theRect;
588 IconAlignmentType align;
589 IconTransformType transform;
590 CIconHandle theCIcon;
591 if (!PyArg_ParseTuple(_args, "O&hhO&",
592 PyMac_GetRect, &theRect,
593 &align,
594 &transform,
595 ResObj_Convert, &theCIcon))
596 return NULL;
597 _err = PlotCIconHandle(&theRect,
598 align,
599 transform,
600 theCIcon);
601 if (_err != noErr) return PyMac_Error(_err);
602 Py_INCREF(Py_None);
603 _res = Py_None;
604 return _res;
607 static PyMethodDef Icn_methods[] = {
608 {"GetCIcon", (PyCFunction)Icn_GetCIcon, 1,
609 "(SInt16 iconID) -> (CIconHandle _rv)"},
610 {"PlotCIcon", (PyCFunction)Icn_PlotCIcon, 1,
611 "(Rect theRect, CIconHandle theIcon) -> None"},
612 {"DisposeCIcon", (PyCFunction)Icn_DisposeCIcon, 1,
613 "(CIconHandle theIcon) -> None"},
614 {"GetIcon", (PyCFunction)Icn_GetIcon, 1,
615 "(SInt16 iconID) -> (Handle _rv)"},
616 {"PlotIcon", (PyCFunction)Icn_PlotIcon, 1,
617 "(Rect theRect, Handle theIcon) -> None"},
618 {"PlotIconID", (PyCFunction)Icn_PlotIconID, 1,
619 "(Rect theRect, IconAlignmentType align, IconTransformType transform, SInt16 theResID) -> None"},
620 {"NewIconSuite", (PyCFunction)Icn_NewIconSuite, 1,
621 "() -> (IconSuiteRef theIconSuite)"},
622 {"AddIconToSuite", (PyCFunction)Icn_AddIconToSuite, 1,
623 "(Handle theIconData, IconSuiteRef theSuite, ResType theType) -> None"},
624 {"GetIconFromSuite", (PyCFunction)Icn_GetIconFromSuite, 1,
625 "(IconSuiteRef theSuite, ResType theType) -> (Handle theIconData)"},
626 {"GetIconSuite", (PyCFunction)Icn_GetIconSuite, 1,
627 "(SInt16 theResID, IconSelectorValue selector) -> (IconSuiteRef theIconSuite)"},
628 {"DisposeIconSuite", (PyCFunction)Icn_DisposeIconSuite, 1,
629 "(IconSuiteRef theIconSuite, Boolean disposeData) -> None"},
630 {"PlotIconSuite", (PyCFunction)Icn_PlotIconSuite, 1,
631 "(Rect theRect, IconAlignmentType align, IconTransformType transform, IconSuiteRef theIconSuite) -> None"},
632 {"LoadIconCache", (PyCFunction)Icn_LoadIconCache, 1,
633 "(Rect theRect, IconAlignmentType align, IconTransformType transform, IconCacheRef theIconCache) -> None"},
634 {"GetLabel", (PyCFunction)Icn_GetLabel, 1,
635 "(SInt16 labelNumber, Str255 labelString) -> (RGBColor labelColor)"},
636 {"PtInIconID", (PyCFunction)Icn_PtInIconID, 1,
637 "(Point testPt, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> (Boolean _rv)"},
638 {"PtInIconSuite", (PyCFunction)Icn_PtInIconSuite, 1,
639 "(Point testPt, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> (Boolean _rv)"},
640 {"RectInIconID", (PyCFunction)Icn_RectInIconID, 1,
641 "(Rect testRect, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> (Boolean _rv)"},
642 {"RectInIconSuite", (PyCFunction)Icn_RectInIconSuite, 1,
643 "(Rect testRect, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> (Boolean _rv)"},
644 {"IconIDToRgn", (PyCFunction)Icn_IconIDToRgn, 1,
645 "(RgnHandle theRgn, Rect iconRect, IconAlignmentType align, SInt16 iconID) -> None"},
646 {"IconSuiteToRgn", (PyCFunction)Icn_IconSuiteToRgn, 1,
647 "(RgnHandle theRgn, Rect iconRect, IconAlignmentType align, IconSuiteRef theIconSuite) -> None"},
648 {"SetSuiteLabel", (PyCFunction)Icn_SetSuiteLabel, 1,
649 "(IconSuiteRef theSuite, SInt16 theLabel) -> None"},
650 {"GetSuiteLabel", (PyCFunction)Icn_GetSuiteLabel, 1,
651 "(IconSuiteRef theSuite) -> (SInt16 _rv)"},
652 {"PlotIconHandle", (PyCFunction)Icn_PlotIconHandle, 1,
653 "(Rect theRect, IconAlignmentType align, IconTransformType transform, Handle theIcon) -> None"},
654 {"PlotSICNHandle", (PyCFunction)Icn_PlotSICNHandle, 1,
655 "(Rect theRect, IconAlignmentType align, IconTransformType transform, Handle theSICN) -> None"},
656 {"PlotCIconHandle", (PyCFunction)Icn_PlotCIconHandle, 1,
657 "(Rect theRect, IconAlignmentType align, IconTransformType transform, CIconHandle theCIcon) -> None"},
658 {NULL, NULL, 0}
664 void initIcn()
666 PyObject *m;
667 PyObject *d;
672 m = Py_InitModule("Icn", Icn_methods);
673 d = PyModule_GetDict(m);
674 Icn_Error = PyMac_GetOSErrException();
675 if (Icn_Error == NULL ||
676 PyDict_SetItemString(d, "Error", Icn_Error) != 0)
677 Py_FatalError("can't initialize Icn.Error");
680 /* ========================= End module Icn ========================= */