Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Mac / Modules / menu / Menumodule.c
blobc5d90ee7fd8e841ea60c913741ad96f049802b5f
2 /* ========================== Module Menu =========================== */
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 <Devices.h> /* Defines OpenDeskAcc in universal headers */
46 #include <Menus.h>
48 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
50 static PyObject *Menu_Error;
52 /* ------------------------ Object type Menu ------------------------ */
54 PyTypeObject Menu_Type;
56 #define MenuObj_Check(x) ((x)->ob_type == &Menu_Type)
58 typedef struct MenuObject {
59 PyObject_HEAD
60 MenuHandle ob_itself;
61 } MenuObject;
63 PyObject *MenuObj_New(itself)
64 MenuHandle itself;
66 MenuObject *it;
67 it = PyObject_NEW(MenuObject, &Menu_Type);
68 if (it == NULL) return NULL;
69 it->ob_itself = itself;
70 return (PyObject *)it;
72 MenuObj_Convert(v, p_itself)
73 PyObject *v;
74 MenuHandle *p_itself;
76 if (!MenuObj_Check(v))
78 PyErr_SetString(PyExc_TypeError, "Menu required");
79 return 0;
81 *p_itself = ((MenuObject *)v)->ob_itself;
82 return 1;
85 static void MenuObj_dealloc(self)
86 MenuObject *self;
88 /* Cleanup of self->ob_itself goes here */
89 PyMem_DEL(self);
92 static PyObject *MenuObj_DisposeMenu(_self, _args)
93 MenuObject *_self;
94 PyObject *_args;
96 PyObject *_res = NULL;
97 if (!PyArg_ParseTuple(_args, ""))
98 return NULL;
99 DisposeMenu(_self->ob_itself);
100 Py_INCREF(Py_None);
101 _res = Py_None;
102 return _res;
105 static PyObject *MenuObj_AppendMenu(_self, _args)
106 MenuObject *_self;
107 PyObject *_args;
109 PyObject *_res = NULL;
110 Str255 data;
111 if (!PyArg_ParseTuple(_args, "O&",
112 PyMac_GetStr255, data))
113 return NULL;
114 AppendMenu(_self->ob_itself,
115 data);
116 Py_INCREF(Py_None);
117 _res = Py_None;
118 return _res;
121 static PyObject *MenuObj_InsertResMenu(_self, _args)
122 MenuObject *_self;
123 PyObject *_args;
125 PyObject *_res = NULL;
126 ResType theType;
127 short afterItem;
128 if (!PyArg_ParseTuple(_args, "O&h",
129 PyMac_GetOSType, &theType,
130 &afterItem))
131 return NULL;
132 InsertResMenu(_self->ob_itself,
133 theType,
134 afterItem);
135 Py_INCREF(Py_None);
136 _res = Py_None;
137 return _res;
140 static PyObject *MenuObj_InsertMenu(_self, _args)
141 MenuObject *_self;
142 PyObject *_args;
144 PyObject *_res = NULL;
145 short beforeID;
146 if (!PyArg_ParseTuple(_args, "h",
147 &beforeID))
148 return NULL;
149 InsertMenu(_self->ob_itself,
150 beforeID);
151 Py_INCREF(Py_None);
152 _res = Py_None;
153 return _res;
156 static PyObject *MenuObj_AppendResMenu(_self, _args)
157 MenuObject *_self;
158 PyObject *_args;
160 PyObject *_res = NULL;
161 ResType theType;
162 if (!PyArg_ParseTuple(_args, "O&",
163 PyMac_GetOSType, &theType))
164 return NULL;
165 AppendResMenu(_self->ob_itself,
166 theType);
167 Py_INCREF(Py_None);
168 _res = Py_None;
169 return _res;
172 static PyObject *MenuObj_InsertMenuItem(_self, _args)
173 MenuObject *_self;
174 PyObject *_args;
176 PyObject *_res = NULL;
177 Str255 itemString;
178 short afterItem;
179 if (!PyArg_ParseTuple(_args, "O&h",
180 PyMac_GetStr255, itemString,
181 &afterItem))
182 return NULL;
183 InsertMenuItem(_self->ob_itself,
184 itemString,
185 afterItem);
186 Py_INCREF(Py_None);
187 _res = Py_None;
188 return _res;
191 static PyObject *MenuObj_DeleteMenuItem(_self, _args)
192 MenuObject *_self;
193 PyObject *_args;
195 PyObject *_res = NULL;
196 short item;
197 if (!PyArg_ParseTuple(_args, "h",
198 &item))
199 return NULL;
200 DeleteMenuItem(_self->ob_itself,
201 item);
202 Py_INCREF(Py_None);
203 _res = Py_None;
204 return _res;
207 static PyObject *MenuObj_SetMenuItemText(_self, _args)
208 MenuObject *_self;
209 PyObject *_args;
211 PyObject *_res = NULL;
212 short item;
213 Str255 itemString;
214 if (!PyArg_ParseTuple(_args, "hO&",
215 &item,
216 PyMac_GetStr255, itemString))
217 return NULL;
218 SetMenuItemText(_self->ob_itself,
219 item,
220 itemString);
221 Py_INCREF(Py_None);
222 _res = Py_None;
223 return _res;
226 static PyObject *MenuObj_GetMenuItemText(_self, _args)
227 MenuObject *_self;
228 PyObject *_args;
230 PyObject *_res = NULL;
231 short item;
232 Str255 itemString;
233 if (!PyArg_ParseTuple(_args, "h",
234 &item))
235 return NULL;
236 GetMenuItemText(_self->ob_itself,
237 item,
238 itemString);
239 _res = Py_BuildValue("O&",
240 PyMac_BuildStr255, itemString);
241 return _res;
244 static PyObject *MenuObj_SetItemMark(_self, _args)
245 MenuObject *_self;
246 PyObject *_args;
248 PyObject *_res = NULL;
249 short item;
250 CharParameter markChar;
251 if (!PyArg_ParseTuple(_args, "hh",
252 &item,
253 &markChar))
254 return NULL;
255 SetItemMark(_self->ob_itself,
256 item,
257 markChar);
258 Py_INCREF(Py_None);
259 _res = Py_None;
260 return _res;
263 static PyObject *MenuObj_GetItemMark(_self, _args)
264 MenuObject *_self;
265 PyObject *_args;
267 PyObject *_res = NULL;
268 short item;
269 CharParameter markChar;
270 if (!PyArg_ParseTuple(_args, "h",
271 &item))
272 return NULL;
273 GetItemMark(_self->ob_itself,
274 item,
275 &markChar);
276 _res = Py_BuildValue("h",
277 markChar);
278 return _res;
281 static PyObject *MenuObj_SetItemCmd(_self, _args)
282 MenuObject *_self;
283 PyObject *_args;
285 PyObject *_res = NULL;
286 short item;
287 CharParameter cmdChar;
288 if (!PyArg_ParseTuple(_args, "hh",
289 &item,
290 &cmdChar))
291 return NULL;
292 SetItemCmd(_self->ob_itself,
293 item,
294 cmdChar);
295 Py_INCREF(Py_None);
296 _res = Py_None;
297 return _res;
300 static PyObject *MenuObj_GetItemCmd(_self, _args)
301 MenuObject *_self;
302 PyObject *_args;
304 PyObject *_res = NULL;
305 short item;
306 CharParameter cmdChar;
307 if (!PyArg_ParseTuple(_args, "h",
308 &item))
309 return NULL;
310 GetItemCmd(_self->ob_itself,
311 item,
312 &cmdChar);
313 _res = Py_BuildValue("h",
314 cmdChar);
315 return _res;
318 static PyObject *MenuObj_SetItemIcon(_self, _args)
319 MenuObject *_self;
320 PyObject *_args;
322 PyObject *_res = NULL;
323 short item;
324 short iconIndex;
325 if (!PyArg_ParseTuple(_args, "hh",
326 &item,
327 &iconIndex))
328 return NULL;
329 SetItemIcon(_self->ob_itself,
330 item,
331 iconIndex);
332 Py_INCREF(Py_None);
333 _res = Py_None;
334 return _res;
337 static PyObject *MenuObj_GetItemIcon(_self, _args)
338 MenuObject *_self;
339 PyObject *_args;
341 PyObject *_res = NULL;
342 short item;
343 short iconIndex;
344 if (!PyArg_ParseTuple(_args, "h",
345 &item))
346 return NULL;
347 GetItemIcon(_self->ob_itself,
348 item,
349 &iconIndex);
350 _res = Py_BuildValue("h",
351 iconIndex);
352 return _res;
355 static PyObject *MenuObj_SetItemStyle(_self, _args)
356 MenuObject *_self;
357 PyObject *_args;
359 PyObject *_res = NULL;
360 short item;
361 StyleParameter chStyle;
362 if (!PyArg_ParseTuple(_args, "hh",
363 &item,
364 &chStyle))
365 return NULL;
366 SetItemStyle(_self->ob_itself,
367 item,
368 chStyle);
369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
374 static PyObject *MenuObj_GetItemStyle(_self, _args)
375 MenuObject *_self;
376 PyObject *_args;
378 PyObject *_res = NULL;
379 short item;
380 Style chStyle;
381 if (!PyArg_ParseTuple(_args, "h",
382 &item))
383 return NULL;
384 GetItemStyle(_self->ob_itself,
385 item,
386 &chStyle);
387 _res = Py_BuildValue("b",
388 chStyle);
389 return _res;
392 static PyObject *MenuObj_CalcMenuSize(_self, _args)
393 MenuObject *_self;
394 PyObject *_args;
396 PyObject *_res = NULL;
397 if (!PyArg_ParseTuple(_args, ""))
398 return NULL;
399 CalcMenuSize(_self->ob_itself);
400 Py_INCREF(Py_None);
401 _res = Py_None;
402 return _res;
405 static PyObject *MenuObj_DisableItem(_self, _args)
406 MenuObject *_self;
407 PyObject *_args;
409 PyObject *_res = NULL;
410 short item;
411 if (!PyArg_ParseTuple(_args, "h",
412 &item))
413 return NULL;
414 DisableItem(_self->ob_itself,
415 item);
416 Py_INCREF(Py_None);
417 _res = Py_None;
418 return _res;
421 static PyObject *MenuObj_EnableItem(_self, _args)
422 MenuObject *_self;
423 PyObject *_args;
425 PyObject *_res = NULL;
426 short item;
427 if (!PyArg_ParseTuple(_args, "h",
428 &item))
429 return NULL;
430 EnableItem(_self->ob_itself,
431 item);
432 Py_INCREF(Py_None);
433 _res = Py_None;
434 return _res;
437 static PyObject *MenuObj_PopUpMenuSelect(_self, _args)
438 MenuObject *_self;
439 PyObject *_args;
441 PyObject *_res = NULL;
442 long _rv;
443 short top;
444 short left;
445 short popUpItem;
446 if (!PyArg_ParseTuple(_args, "hhh",
447 &top,
448 &left,
449 &popUpItem))
450 return NULL;
451 _rv = PopUpMenuSelect(_self->ob_itself,
452 top,
453 left,
454 popUpItem);
455 _res = Py_BuildValue("l",
456 _rv);
457 return _res;
460 static PyObject *MenuObj_CheckItem(_self, _args)
461 MenuObject *_self;
462 PyObject *_args;
464 PyObject *_res = NULL;
465 short item;
466 Boolean checked;
467 if (!PyArg_ParseTuple(_args, "hb",
468 &item,
469 &checked))
470 return NULL;
471 CheckItem(_self->ob_itself,
472 item,
473 checked);
474 Py_INCREF(Py_None);
475 _res = Py_None;
476 return _res;
479 static PyObject *MenuObj_CountMItems(_self, _args)
480 MenuObject *_self;
481 PyObject *_args;
483 PyObject *_res = NULL;
484 short _rv;
485 if (!PyArg_ParseTuple(_args, ""))
486 return NULL;
487 _rv = CountMItems(_self->ob_itself);
488 _res = Py_BuildValue("h",
489 _rv);
490 return _res;
493 static PyObject *MenuObj_InsertFontResMenu(_self, _args)
494 MenuObject *_self;
495 PyObject *_args;
497 PyObject *_res = NULL;
498 short afterItem;
499 short scriptFilter;
500 if (!PyArg_ParseTuple(_args, "hh",
501 &afterItem,
502 &scriptFilter))
503 return NULL;
504 InsertFontResMenu(_self->ob_itself,
505 afterItem,
506 scriptFilter);
507 Py_INCREF(Py_None);
508 _res = Py_None;
509 return _res;
512 static PyObject *MenuObj_InsertIntlResMenu(_self, _args)
513 MenuObject *_self;
514 PyObject *_args;
516 PyObject *_res = NULL;
517 ResType theType;
518 short afterItem;
519 short scriptFilter;
520 if (!PyArg_ParseTuple(_args, "O&hh",
521 PyMac_GetOSType, &theType,
522 &afterItem,
523 &scriptFilter))
524 return NULL;
525 InsertIntlResMenu(_self->ob_itself,
526 theType,
527 afterItem,
528 scriptFilter);
529 Py_INCREF(Py_None);
530 _res = Py_None;
531 return _res;
534 static PyObject *MenuObj_SetMenuItemCommandID(_self, _args)
535 MenuObject *_self;
536 PyObject *_args;
538 PyObject *_res = NULL;
539 OSErr _err;
540 SInt16 inItem;
541 UInt32 inCommandID;
542 if (!PyArg_ParseTuple(_args, "hl",
543 &inItem,
544 &inCommandID))
545 return NULL;
546 _err = SetMenuItemCommandID(_self->ob_itself,
547 inItem,
548 inCommandID);
549 if (_err != noErr) return PyMac_Error(_err);
550 Py_INCREF(Py_None);
551 _res = Py_None;
552 return _res;
555 static PyObject *MenuObj_GetMenuItemCommandID(_self, _args)
556 MenuObject *_self;
557 PyObject *_args;
559 PyObject *_res = NULL;
560 OSErr _err;
561 SInt16 inItem;
562 UInt32 outCommandID;
563 if (!PyArg_ParseTuple(_args, "h",
564 &inItem))
565 return NULL;
566 _err = GetMenuItemCommandID(_self->ob_itself,
567 inItem,
568 &outCommandID);
569 if (_err != noErr) return PyMac_Error(_err);
570 _res = Py_BuildValue("l",
571 outCommandID);
572 return _res;
575 static PyObject *MenuObj_SetMenuItemModifiers(_self, _args)
576 MenuObject *_self;
577 PyObject *_args;
579 PyObject *_res = NULL;
580 OSErr _err;
581 SInt16 inItem;
582 UInt8 inModifiers;
583 if (!PyArg_ParseTuple(_args, "hb",
584 &inItem,
585 &inModifiers))
586 return NULL;
587 _err = SetMenuItemModifiers(_self->ob_itself,
588 inItem,
589 inModifiers);
590 if (_err != noErr) return PyMac_Error(_err);
591 Py_INCREF(Py_None);
592 _res = Py_None;
593 return _res;
596 static PyObject *MenuObj_GetMenuItemModifiers(_self, _args)
597 MenuObject *_self;
598 PyObject *_args;
600 PyObject *_res = NULL;
601 OSErr _err;
602 SInt16 inItem;
603 UInt8 outModifiers;
604 if (!PyArg_ParseTuple(_args, "h",
605 &inItem))
606 return NULL;
607 _err = GetMenuItemModifiers(_self->ob_itself,
608 inItem,
609 &outModifiers);
610 if (_err != noErr) return PyMac_Error(_err);
611 _res = Py_BuildValue("b",
612 outModifiers);
613 return _res;
616 static PyObject *MenuObj_SetMenuItemIconHandle(_self, _args)
617 MenuObject *_self;
618 PyObject *_args;
620 PyObject *_res = NULL;
621 OSErr _err;
622 SInt16 inItem;
623 UInt8 inIconType;
624 Handle inIconHandle;
625 if (!PyArg_ParseTuple(_args, "hbO&",
626 &inItem,
627 &inIconType,
628 ResObj_Convert, &inIconHandle))
629 return NULL;
630 _err = SetMenuItemIconHandle(_self->ob_itself,
631 inItem,
632 inIconType,
633 inIconHandle);
634 if (_err != noErr) return PyMac_Error(_err);
635 Py_INCREF(Py_None);
636 _res = Py_None;
637 return _res;
640 static PyObject *MenuObj_GetMenuItemIconHandle(_self, _args)
641 MenuObject *_self;
642 PyObject *_args;
644 PyObject *_res = NULL;
645 OSErr _err;
646 SInt16 inItem;
647 UInt8 outIconType;
648 Handle outIconHandle;
649 if (!PyArg_ParseTuple(_args, "h",
650 &inItem))
651 return NULL;
652 _err = GetMenuItemIconHandle(_self->ob_itself,
653 inItem,
654 &outIconType,
655 &outIconHandle);
656 if (_err != noErr) return PyMac_Error(_err);
657 _res = Py_BuildValue("bO&",
658 outIconType,
659 ResObj_New, outIconHandle);
660 return _res;
663 static PyObject *MenuObj_SetMenuItemTextEncoding(_self, _args)
664 MenuObject *_self;
665 PyObject *_args;
667 PyObject *_res = NULL;
668 OSErr _err;
669 SInt16 inItem;
670 TextEncoding inScriptID;
671 if (!PyArg_ParseTuple(_args, "hl",
672 &inItem,
673 &inScriptID))
674 return NULL;
675 _err = SetMenuItemTextEncoding(_self->ob_itself,
676 inItem,
677 inScriptID);
678 if (_err != noErr) return PyMac_Error(_err);
679 Py_INCREF(Py_None);
680 _res = Py_None;
681 return _res;
684 static PyObject *MenuObj_GetMenuItemTextEncoding(_self, _args)
685 MenuObject *_self;
686 PyObject *_args;
688 PyObject *_res = NULL;
689 OSErr _err;
690 SInt16 inItem;
691 TextEncoding outScriptID;
692 if (!PyArg_ParseTuple(_args, "h",
693 &inItem))
694 return NULL;
695 _err = GetMenuItemTextEncoding(_self->ob_itself,
696 inItem,
697 &outScriptID);
698 if (_err != noErr) return PyMac_Error(_err);
699 _res = Py_BuildValue("l",
700 outScriptID);
701 return _res;
704 static PyObject *MenuObj_SetMenuItemHierarchicalID(_self, _args)
705 MenuObject *_self;
706 PyObject *_args;
708 PyObject *_res = NULL;
709 OSErr _err;
710 SInt16 inItem;
711 SInt16 inHierID;
712 if (!PyArg_ParseTuple(_args, "hh",
713 &inItem,
714 &inHierID))
715 return NULL;
716 _err = SetMenuItemHierarchicalID(_self->ob_itself,
717 inItem,
718 inHierID);
719 if (_err != noErr) return PyMac_Error(_err);
720 Py_INCREF(Py_None);
721 _res = Py_None;
722 return _res;
725 static PyObject *MenuObj_GetMenuItemHierarchicalID(_self, _args)
726 MenuObject *_self;
727 PyObject *_args;
729 PyObject *_res = NULL;
730 OSErr _err;
731 SInt16 inItem;
732 SInt16 outHierID;
733 if (!PyArg_ParseTuple(_args, "h",
734 &inItem))
735 return NULL;
736 _err = GetMenuItemHierarchicalID(_self->ob_itself,
737 inItem,
738 &outHierID);
739 if (_err != noErr) return PyMac_Error(_err);
740 _res = Py_BuildValue("h",
741 outHierID);
742 return _res;
745 static PyObject *MenuObj_SetMenuItemFontID(_self, _args)
746 MenuObject *_self;
747 PyObject *_args;
749 PyObject *_res = NULL;
750 OSErr _err;
751 SInt16 inItem;
752 SInt16 inFontID;
753 if (!PyArg_ParseTuple(_args, "hh",
754 &inItem,
755 &inFontID))
756 return NULL;
757 _err = SetMenuItemFontID(_self->ob_itself,
758 inItem,
759 inFontID);
760 if (_err != noErr) return PyMac_Error(_err);
761 Py_INCREF(Py_None);
762 _res = Py_None;
763 return _res;
766 static PyObject *MenuObj_GetMenuItemFontID(_self, _args)
767 MenuObject *_self;
768 PyObject *_args;
770 PyObject *_res = NULL;
771 OSErr _err;
772 SInt16 inItem;
773 SInt16 outFontID;
774 if (!PyArg_ParseTuple(_args, "h",
775 &inItem))
776 return NULL;
777 _err = GetMenuItemFontID(_self->ob_itself,
778 inItem,
779 &outFontID);
780 if (_err != noErr) return PyMac_Error(_err);
781 _res = Py_BuildValue("h",
782 outFontID);
783 return _res;
786 static PyObject *MenuObj_SetMenuItemRefCon(_self, _args)
787 MenuObject *_self;
788 PyObject *_args;
790 PyObject *_res = NULL;
791 OSErr _err;
792 SInt16 inItem;
793 UInt32 inRefCon;
794 if (!PyArg_ParseTuple(_args, "hl",
795 &inItem,
796 &inRefCon))
797 return NULL;
798 _err = SetMenuItemRefCon(_self->ob_itself,
799 inItem,
800 inRefCon);
801 if (_err != noErr) return PyMac_Error(_err);
802 Py_INCREF(Py_None);
803 _res = Py_None;
804 return _res;
807 static PyObject *MenuObj_GetMenuItemRefCon(_self, _args)
808 MenuObject *_self;
809 PyObject *_args;
811 PyObject *_res = NULL;
812 OSErr _err;
813 SInt16 inItem;
814 UInt32 outRefCon;
815 if (!PyArg_ParseTuple(_args, "h",
816 &inItem))
817 return NULL;
818 _err = GetMenuItemRefCon(_self->ob_itself,
819 inItem,
820 &outRefCon);
821 if (_err != noErr) return PyMac_Error(_err);
822 _res = Py_BuildValue("l",
823 outRefCon);
824 return _res;
827 static PyObject *MenuObj_SetMenuItemRefCon2(_self, _args)
828 MenuObject *_self;
829 PyObject *_args;
831 PyObject *_res = NULL;
832 OSErr _err;
833 SInt16 inItem;
834 UInt32 inRefCon2;
835 if (!PyArg_ParseTuple(_args, "hl",
836 &inItem,
837 &inRefCon2))
838 return NULL;
839 _err = SetMenuItemRefCon2(_self->ob_itself,
840 inItem,
841 inRefCon2);
842 if (_err != noErr) return PyMac_Error(_err);
843 Py_INCREF(Py_None);
844 _res = Py_None;
845 return _res;
848 static PyObject *MenuObj_GetMenuItemRefCon2(_self, _args)
849 MenuObject *_self;
850 PyObject *_args;
852 PyObject *_res = NULL;
853 OSErr _err;
854 SInt16 inItem;
855 UInt32 outRefCon2;
856 if (!PyArg_ParseTuple(_args, "h",
857 &inItem))
858 return NULL;
859 _err = GetMenuItemRefCon2(_self->ob_itself,
860 inItem,
861 &outRefCon2);
862 if (_err != noErr) return PyMac_Error(_err);
863 _res = Py_BuildValue("l",
864 outRefCon2);
865 return _res;
868 static PyObject *MenuObj_SetMenuItemKeyGlyph(_self, _args)
869 MenuObject *_self;
870 PyObject *_args;
872 PyObject *_res = NULL;
873 OSErr _err;
874 SInt16 inItem;
875 SInt16 inGlyph;
876 if (!PyArg_ParseTuple(_args, "hh",
877 &inItem,
878 &inGlyph))
879 return NULL;
880 _err = SetMenuItemKeyGlyph(_self->ob_itself,
881 inItem,
882 inGlyph);
883 if (_err != noErr) return PyMac_Error(_err);
884 Py_INCREF(Py_None);
885 _res = Py_None;
886 return _res;
889 static PyObject *MenuObj_GetMenuItemKeyGlyph(_self, _args)
890 MenuObject *_self;
891 PyObject *_args;
893 PyObject *_res = NULL;
894 OSErr _err;
895 SInt16 inItem;
896 SInt16 outGlyph;
897 if (!PyArg_ParseTuple(_args, "h",
898 &inItem))
899 return NULL;
900 _err = GetMenuItemKeyGlyph(_self->ob_itself,
901 inItem,
902 &outGlyph);
903 if (_err != noErr) return PyMac_Error(_err);
904 _res = Py_BuildValue("h",
905 outGlyph);
906 return _res;
909 static PyObject *MenuObj_as_Resource(_self, _args)
910 MenuObject *_self;
911 PyObject *_args;
913 PyObject *_res = NULL;
915 return ResObj_New((Handle)_self->ob_itself);
919 static PyMethodDef MenuObj_methods[] = {
920 {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1,
921 "() -> None"},
922 {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1,
923 "(Str255 data) -> None"},
924 {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1,
925 "(ResType theType, short afterItem) -> None"},
926 {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1,
927 "(short beforeID) -> None"},
928 {"AppendResMenu", (PyCFunction)MenuObj_AppendResMenu, 1,
929 "(ResType theType) -> None"},
930 {"InsertMenuItem", (PyCFunction)MenuObj_InsertMenuItem, 1,
931 "(Str255 itemString, short afterItem) -> None"},
932 {"DeleteMenuItem", (PyCFunction)MenuObj_DeleteMenuItem, 1,
933 "(short item) -> None"},
934 {"SetMenuItemText", (PyCFunction)MenuObj_SetMenuItemText, 1,
935 "(short item, Str255 itemString) -> None"},
936 {"GetMenuItemText", (PyCFunction)MenuObj_GetMenuItemText, 1,
937 "(short item) -> (Str255 itemString)"},
938 {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1,
939 "(short item, CharParameter markChar) -> None"},
940 {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1,
941 "(short item) -> (CharParameter markChar)"},
942 {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1,
943 "(short item, CharParameter cmdChar) -> None"},
944 {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1,
945 "(short item) -> (CharParameter cmdChar)"},
946 {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1,
947 "(short item, short iconIndex) -> None"},
948 {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1,
949 "(short item) -> (short iconIndex)"},
950 {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1,
951 "(short item, StyleParameter chStyle) -> None"},
952 {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1,
953 "(short item) -> (Style chStyle)"},
954 {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1,
955 "() -> None"},
956 {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1,
957 "(short item) -> None"},
958 {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1,
959 "(short item) -> None"},
960 {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1,
961 "(short top, short left, short popUpItem) -> (long _rv)"},
962 {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1,
963 "(short item, Boolean checked) -> None"},
964 {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1,
965 "() -> (short _rv)"},
966 {"InsertFontResMenu", (PyCFunction)MenuObj_InsertFontResMenu, 1,
967 "(short afterItem, short scriptFilter) -> None"},
968 {"InsertIntlResMenu", (PyCFunction)MenuObj_InsertIntlResMenu, 1,
969 "(ResType theType, short afterItem, short scriptFilter) -> None"},
970 {"SetMenuItemCommandID", (PyCFunction)MenuObj_SetMenuItemCommandID, 1,
971 "(SInt16 inItem, UInt32 inCommandID) -> None"},
972 {"GetMenuItemCommandID", (PyCFunction)MenuObj_GetMenuItemCommandID, 1,
973 "(SInt16 inItem) -> (UInt32 outCommandID)"},
974 {"SetMenuItemModifiers", (PyCFunction)MenuObj_SetMenuItemModifiers, 1,
975 "(SInt16 inItem, UInt8 inModifiers) -> None"},
976 {"GetMenuItemModifiers", (PyCFunction)MenuObj_GetMenuItemModifiers, 1,
977 "(SInt16 inItem) -> (UInt8 outModifiers)"},
978 {"SetMenuItemIconHandle", (PyCFunction)MenuObj_SetMenuItemIconHandle, 1,
979 "(SInt16 inItem, UInt8 inIconType, Handle inIconHandle) -> None"},
980 {"GetMenuItemIconHandle", (PyCFunction)MenuObj_GetMenuItemIconHandle, 1,
981 "(SInt16 inItem) -> (UInt8 outIconType, Handle outIconHandle)"},
982 {"SetMenuItemTextEncoding", (PyCFunction)MenuObj_SetMenuItemTextEncoding, 1,
983 "(SInt16 inItem, TextEncoding inScriptID) -> None"},
984 {"GetMenuItemTextEncoding", (PyCFunction)MenuObj_GetMenuItemTextEncoding, 1,
985 "(SInt16 inItem) -> (TextEncoding outScriptID)"},
986 {"SetMenuItemHierarchicalID", (PyCFunction)MenuObj_SetMenuItemHierarchicalID, 1,
987 "(SInt16 inItem, SInt16 inHierID) -> None"},
988 {"GetMenuItemHierarchicalID", (PyCFunction)MenuObj_GetMenuItemHierarchicalID, 1,
989 "(SInt16 inItem) -> (SInt16 outHierID)"},
990 {"SetMenuItemFontID", (PyCFunction)MenuObj_SetMenuItemFontID, 1,
991 "(SInt16 inItem, SInt16 inFontID) -> None"},
992 {"GetMenuItemFontID", (PyCFunction)MenuObj_GetMenuItemFontID, 1,
993 "(SInt16 inItem) -> (SInt16 outFontID)"},
994 {"SetMenuItemRefCon", (PyCFunction)MenuObj_SetMenuItemRefCon, 1,
995 "(SInt16 inItem, UInt32 inRefCon) -> None"},
996 {"GetMenuItemRefCon", (PyCFunction)MenuObj_GetMenuItemRefCon, 1,
997 "(SInt16 inItem) -> (UInt32 outRefCon)"},
998 {"SetMenuItemRefCon2", (PyCFunction)MenuObj_SetMenuItemRefCon2, 1,
999 "(SInt16 inItem, UInt32 inRefCon2) -> None"},
1000 {"GetMenuItemRefCon2", (PyCFunction)MenuObj_GetMenuItemRefCon2, 1,
1001 "(SInt16 inItem) -> (UInt32 outRefCon2)"},
1002 {"SetMenuItemKeyGlyph", (PyCFunction)MenuObj_SetMenuItemKeyGlyph, 1,
1003 "(SInt16 inItem, SInt16 inGlyph) -> None"},
1004 {"GetMenuItemKeyGlyph", (PyCFunction)MenuObj_GetMenuItemKeyGlyph, 1,
1005 "(SInt16 inItem) -> (SInt16 outGlyph)"},
1006 {"as_Resource", (PyCFunction)MenuObj_as_Resource, 1,
1007 "Return this Menu as a Resource"},
1008 {NULL, NULL, 0}
1011 PyMethodChain MenuObj_chain = { MenuObj_methods, NULL };
1013 static PyObject *MenuObj_getattr(self, name)
1014 MenuObject *self;
1015 char *name;
1017 return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name);
1020 #define MenuObj_setattr NULL
1022 PyTypeObject Menu_Type = {
1023 PyObject_HEAD_INIT(&PyType_Type)
1024 0, /*ob_size*/
1025 "Menu", /*tp_name*/
1026 sizeof(MenuObject), /*tp_basicsize*/
1027 0, /*tp_itemsize*/
1028 /* methods */
1029 (destructor) MenuObj_dealloc, /*tp_dealloc*/
1030 0, /*tp_print*/
1031 (getattrfunc) MenuObj_getattr, /*tp_getattr*/
1032 (setattrfunc) MenuObj_setattr, /*tp_setattr*/
1035 /* ---------------------- End object type Menu ---------------------- */
1038 static PyObject *Menu_GetMBarHeight(_self, _args)
1039 PyObject *_self;
1040 PyObject *_args;
1042 PyObject *_res = NULL;
1043 short _rv;
1044 if (!PyArg_ParseTuple(_args, ""))
1045 return NULL;
1046 _rv = GetMBarHeight();
1047 _res = Py_BuildValue("h",
1048 _rv);
1049 return _res;
1052 static PyObject *Menu_InitMenus(_self, _args)
1053 PyObject *_self;
1054 PyObject *_args;
1056 PyObject *_res = NULL;
1057 if (!PyArg_ParseTuple(_args, ""))
1058 return NULL;
1059 InitMenus();
1060 Py_INCREF(Py_None);
1061 _res = Py_None;
1062 return _res;
1065 static PyObject *Menu_NewMenu(_self, _args)
1066 PyObject *_self;
1067 PyObject *_args;
1069 PyObject *_res = NULL;
1070 MenuHandle _rv;
1071 short menuID;
1072 Str255 menuTitle;
1073 if (!PyArg_ParseTuple(_args, "hO&",
1074 &menuID,
1075 PyMac_GetStr255, menuTitle))
1076 return NULL;
1077 _rv = NewMenu(menuID,
1078 menuTitle);
1079 _res = Py_BuildValue("O&",
1080 MenuObj_New, _rv);
1081 return _res;
1084 static PyObject *Menu_GetMenu(_self, _args)
1085 PyObject *_self;
1086 PyObject *_args;
1088 PyObject *_res = NULL;
1089 MenuHandle _rv;
1090 short resourceID;
1091 if (!PyArg_ParseTuple(_args, "h",
1092 &resourceID))
1093 return NULL;
1094 _rv = GetMenu(resourceID);
1095 _res = Py_BuildValue("O&",
1096 MenuObj_New, _rv);
1097 return _res;
1100 static PyObject *Menu_DeleteMenu(_self, _args)
1101 PyObject *_self;
1102 PyObject *_args;
1104 PyObject *_res = NULL;
1105 short menuID;
1106 if (!PyArg_ParseTuple(_args, "h",
1107 &menuID))
1108 return NULL;
1109 DeleteMenu(menuID);
1110 Py_INCREF(Py_None);
1111 _res = Py_None;
1112 return _res;
1115 static PyObject *Menu_MenuKey(_self, _args)
1116 PyObject *_self;
1117 PyObject *_args;
1119 PyObject *_res = NULL;
1120 long _rv;
1121 CharParameter ch;
1122 if (!PyArg_ParseTuple(_args, "h",
1123 &ch))
1124 return NULL;
1125 _rv = MenuKey(ch);
1126 _res = Py_BuildValue("l",
1127 _rv);
1128 return _res;
1131 static PyObject *Menu_HiliteMenu(_self, _args)
1132 PyObject *_self;
1133 PyObject *_args;
1135 PyObject *_res = NULL;
1136 short menuID;
1137 if (!PyArg_ParseTuple(_args, "h",
1138 &menuID))
1139 return NULL;
1140 HiliteMenu(menuID);
1141 Py_INCREF(Py_None);
1142 _res = Py_None;
1143 return _res;
1146 static PyObject *Menu_GetMenuHandle(_self, _args)
1147 PyObject *_self;
1148 PyObject *_args;
1150 PyObject *_res = NULL;
1151 MenuHandle _rv;
1152 short menuID;
1153 if (!PyArg_ParseTuple(_args, "h",
1154 &menuID))
1155 return NULL;
1156 _rv = GetMenuHandle(menuID);
1157 _res = Py_BuildValue("O&",
1158 MenuObj_New, _rv);
1159 return _res;
1162 static PyObject *Menu_FlashMenuBar(_self, _args)
1163 PyObject *_self;
1164 PyObject *_args;
1166 PyObject *_res = NULL;
1167 short menuID;
1168 if (!PyArg_ParseTuple(_args, "h",
1169 &menuID))
1170 return NULL;
1171 FlashMenuBar(menuID);
1172 Py_INCREF(Py_None);
1173 _res = Py_None;
1174 return _res;
1177 static PyObject *Menu_MenuChoice(_self, _args)
1178 PyObject *_self;
1179 PyObject *_args;
1181 PyObject *_res = NULL;
1182 long _rv;
1183 if (!PyArg_ParseTuple(_args, ""))
1184 return NULL;
1185 _rv = MenuChoice();
1186 _res = Py_BuildValue("l",
1187 _rv);
1188 return _res;
1191 static PyObject *Menu_DeleteMCEntries(_self, _args)
1192 PyObject *_self;
1193 PyObject *_args;
1195 PyObject *_res = NULL;
1196 short menuID;
1197 short menuItem;
1198 if (!PyArg_ParseTuple(_args, "hh",
1199 &menuID,
1200 &menuItem))
1201 return NULL;
1202 DeleteMCEntries(menuID,
1203 menuItem);
1204 Py_INCREF(Py_None);
1205 _res = Py_None;
1206 return _res;
1209 static PyObject *Menu_DrawMenuBar(_self, _args)
1210 PyObject *_self;
1211 PyObject *_args;
1213 PyObject *_res = NULL;
1214 if (!PyArg_ParseTuple(_args, ""))
1215 return NULL;
1216 DrawMenuBar();
1217 Py_INCREF(Py_None);
1218 _res = Py_None;
1219 return _res;
1222 static PyObject *Menu_InvalMenuBar(_self, _args)
1223 PyObject *_self;
1224 PyObject *_args;
1226 PyObject *_res = NULL;
1227 if (!PyArg_ParseTuple(_args, ""))
1228 return NULL;
1229 InvalMenuBar();
1230 Py_INCREF(Py_None);
1231 _res = Py_None;
1232 return _res;
1235 static PyObject *Menu_InitProcMenu(_self, _args)
1236 PyObject *_self;
1237 PyObject *_args;
1239 PyObject *_res = NULL;
1240 short resID;
1241 if (!PyArg_ParseTuple(_args, "h",
1242 &resID))
1243 return NULL;
1244 InitProcMenu(resID);
1245 Py_INCREF(Py_None);
1246 _res = Py_None;
1247 return _res;
1250 static PyObject *Menu_GetMenuBar(_self, _args)
1251 PyObject *_self;
1252 PyObject *_args;
1254 PyObject *_res = NULL;
1255 Handle _rv;
1256 if (!PyArg_ParseTuple(_args, ""))
1257 return NULL;
1258 _rv = GetMenuBar();
1259 _res = Py_BuildValue("O&",
1260 ResObj_New, _rv);
1261 return _res;
1264 static PyObject *Menu_SetMenuBar(_self, _args)
1265 PyObject *_self;
1266 PyObject *_args;
1268 PyObject *_res = NULL;
1269 Handle menuList;
1270 if (!PyArg_ParseTuple(_args, "O&",
1271 ResObj_Convert, &menuList))
1272 return NULL;
1273 SetMenuBar(menuList);
1274 Py_INCREF(Py_None);
1275 _res = Py_None;
1276 return _res;
1279 static PyObject *Menu_SystemEdit(_self, _args)
1280 PyObject *_self;
1281 PyObject *_args;
1283 PyObject *_res = NULL;
1284 Boolean _rv;
1285 short editCmd;
1286 if (!PyArg_ParseTuple(_args, "h",
1287 &editCmd))
1288 return NULL;
1289 _rv = SystemEdit(editCmd);
1290 _res = Py_BuildValue("b",
1291 _rv);
1292 return _res;
1295 static PyObject *Menu_SystemMenu(_self, _args)
1296 PyObject *_self;
1297 PyObject *_args;
1299 PyObject *_res = NULL;
1300 long menuResult;
1301 if (!PyArg_ParseTuple(_args, "l",
1302 &menuResult))
1303 return NULL;
1304 SystemMenu(menuResult);
1305 Py_INCREF(Py_None);
1306 _res = Py_None;
1307 return _res;
1310 static PyObject *Menu_GetNewMBar(_self, _args)
1311 PyObject *_self;
1312 PyObject *_args;
1314 PyObject *_res = NULL;
1315 Handle _rv;
1316 short menuBarID;
1317 if (!PyArg_ParseTuple(_args, "h",
1318 &menuBarID))
1319 return NULL;
1320 _rv = GetNewMBar(menuBarID);
1321 _res = Py_BuildValue("O&",
1322 ResObj_New, _rv);
1323 return _res;
1326 static PyObject *Menu_ClearMenuBar(_self, _args)
1327 PyObject *_self;
1328 PyObject *_args;
1330 PyObject *_res = NULL;
1331 if (!PyArg_ParseTuple(_args, ""))
1332 return NULL;
1333 ClearMenuBar();
1334 Py_INCREF(Py_None);
1335 _res = Py_None;
1336 return _res;
1339 static PyObject *Menu_SetMenuFlash(_self, _args)
1340 PyObject *_self;
1341 PyObject *_args;
1343 PyObject *_res = NULL;
1344 short count;
1345 if (!PyArg_ParseTuple(_args, "h",
1346 &count))
1347 return NULL;
1348 SetMenuFlash(count);
1349 Py_INCREF(Py_None);
1350 _res = Py_None;
1351 return _res;
1354 static PyObject *Menu_MenuSelect(_self, _args)
1355 PyObject *_self;
1356 PyObject *_args;
1358 PyObject *_res = NULL;
1359 long _rv;
1360 Point startPt;
1361 if (!PyArg_ParseTuple(_args, "O&",
1362 PyMac_GetPoint, &startPt))
1363 return NULL;
1364 _rv = MenuSelect(startPt);
1365 _res = Py_BuildValue("l",
1366 _rv);
1367 return _res;
1370 static PyObject *Menu_MenuEvent(_self, _args)
1371 PyObject *_self;
1372 PyObject *_args;
1374 PyObject *_res = NULL;
1375 UInt32 _rv;
1376 EventRecord inEvent;
1377 if (!PyArg_ParseTuple(_args, "O&",
1378 PyMac_GetEventRecord, &inEvent))
1379 return NULL;
1380 _rv = MenuEvent(&inEvent);
1381 _res = Py_BuildValue("l",
1382 _rv);
1383 return _res;
1386 static PyObject *Menu_OpenDeskAcc(_self, _args)
1387 PyObject *_self;
1388 PyObject *_args;
1390 PyObject *_res = NULL;
1391 Str255 name;
1392 if (!PyArg_ParseTuple(_args, "O&",
1393 PyMac_GetStr255, name))
1394 return NULL;
1395 OpenDeskAcc(name);
1396 Py_INCREF(Py_None);
1397 _res = Py_None;
1398 return _res;
1401 static PyMethodDef Menu_methods[] = {
1402 {"GetMBarHeight", (PyCFunction)Menu_GetMBarHeight, 1,
1403 "() -> (short _rv)"},
1404 {"InitMenus", (PyCFunction)Menu_InitMenus, 1,
1405 "() -> None"},
1406 {"NewMenu", (PyCFunction)Menu_NewMenu, 1,
1407 "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"},
1408 {"GetMenu", (PyCFunction)Menu_GetMenu, 1,
1409 "(short resourceID) -> (MenuHandle _rv)"},
1410 {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1,
1411 "(short menuID) -> None"},
1412 {"MenuKey", (PyCFunction)Menu_MenuKey, 1,
1413 "(CharParameter ch) -> (long _rv)"},
1414 {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1,
1415 "(short menuID) -> None"},
1416 {"GetMenuHandle", (PyCFunction)Menu_GetMenuHandle, 1,
1417 "(short menuID) -> (MenuHandle _rv)"},
1418 {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1,
1419 "(short menuID) -> None"},
1420 {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1,
1421 "() -> (long _rv)"},
1422 {"DeleteMCEntries", (PyCFunction)Menu_DeleteMCEntries, 1,
1423 "(short menuID, short menuItem) -> None"},
1424 {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1,
1425 "() -> None"},
1426 {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1,
1427 "() -> None"},
1428 {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1,
1429 "(short resID) -> None"},
1430 {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1,
1431 "() -> (Handle _rv)"},
1432 {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1,
1433 "(Handle menuList) -> None"},
1434 {"SystemEdit", (PyCFunction)Menu_SystemEdit, 1,
1435 "(short editCmd) -> (Boolean _rv)"},
1436 {"SystemMenu", (PyCFunction)Menu_SystemMenu, 1,
1437 "(long menuResult) -> None"},
1438 {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1,
1439 "(short menuBarID) -> (Handle _rv)"},
1440 {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1,
1441 "() -> None"},
1442 {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1,
1443 "(short count) -> None"},
1444 {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1,
1445 "(Point startPt) -> (long _rv)"},
1446 {"MenuEvent", (PyCFunction)Menu_MenuEvent, 1,
1447 "(EventRecord inEvent) -> (UInt32 _rv)"},
1448 {"OpenDeskAcc", (PyCFunction)Menu_OpenDeskAcc, 1,
1449 "(Str255 name) -> None"},
1450 {NULL, NULL, 0}
1456 void initMenu()
1458 PyObject *m;
1459 PyObject *d;
1464 m = Py_InitModule("Menu", Menu_methods);
1465 d = PyModule_GetDict(m);
1466 Menu_Error = PyMac_GetOSErrException();
1467 if (Menu_Error == NULL ||
1468 PyDict_SetItemString(d, "Error", Menu_Error) != 0)
1469 Py_FatalError("can't initialize Menu.Error");
1470 Menu_Type.ob_type = &PyType_Type;
1471 Py_INCREF(&Menu_Type);
1472 if (PyDict_SetItemString(d, "MenuType", (PyObject *)&Menu_Type) != 0)
1473 Py_FatalError("can't initialize MenuType");
1476 /* ======================== End module Menu ========================= */