Bump version to 0.9.1.
[python/dscho.git] / Mac / Modules / menu / Menumodule.c
bloba47c88a594a191225c3e3d792c62773379c641bc
2 /* ========================== Module Menu =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Devices.h> /* Defines OpenDeskAcc in universal headers */
12 #include <Menus.h>
14 #define as_Menu(h) ((MenuHandle)h)
15 #define as_Resource(h) ((Handle)h)
17 static PyObject *Menu_Error;
19 /* ------------------------ Object type Menu ------------------------ */
21 PyTypeObject Menu_Type;
23 #define MenuObj_Check(x) ((x)->ob_type == &Menu_Type)
25 typedef struct MenuObject {
26 PyObject_HEAD
27 MenuHandle ob_itself;
28 } MenuObject;
30 PyObject *MenuObj_New(itself)
31 MenuHandle itself;
33 MenuObject *it;
34 it = PyObject_NEW(MenuObject, &Menu_Type);
35 if (it == NULL) return NULL;
36 it->ob_itself = itself;
37 return (PyObject *)it;
39 MenuObj_Convert(v, p_itself)
40 PyObject *v;
41 MenuHandle *p_itself;
43 if (!MenuObj_Check(v))
45 PyErr_SetString(PyExc_TypeError, "Menu required");
46 return 0;
48 *p_itself = ((MenuObject *)v)->ob_itself;
49 return 1;
52 static void MenuObj_dealloc(self)
53 MenuObject *self;
55 /* Cleanup of self->ob_itself goes here */
56 PyMem_DEL(self);
59 static PyObject *MenuObj_DisposeMenu(_self, _args)
60 MenuObject *_self;
61 PyObject *_args;
63 PyObject *_res = NULL;
64 if (!PyArg_ParseTuple(_args, ""))
65 return NULL;
66 DisposeMenu(_self->ob_itself);
67 Py_INCREF(Py_None);
68 _res = Py_None;
69 return _res;
72 static PyObject *MenuObj_CalcMenuSize(_self, _args)
73 MenuObject *_self;
74 PyObject *_args;
76 PyObject *_res = NULL;
77 if (!PyArg_ParseTuple(_args, ""))
78 return NULL;
79 CalcMenuSize(_self->ob_itself);
80 Py_INCREF(Py_None);
81 _res = Py_None;
82 return _res;
85 #if !TARGET_API_MAC_CARBON
87 static PyObject *MenuObj_CountMItems(_self, _args)
88 MenuObject *_self;
89 PyObject *_args;
91 PyObject *_res = NULL;
92 short _rv;
93 if (!PyArg_ParseTuple(_args, ""))
94 return NULL;
95 _rv = CountMItems(_self->ob_itself);
96 _res = Py_BuildValue("h",
97 _rv);
98 return _res;
100 #endif
102 static PyObject *MenuObj_GetMenuFont(_self, _args)
103 MenuObject *_self;
104 PyObject *_args;
106 PyObject *_res = NULL;
107 OSStatus _err;
108 SInt16 outFontID;
109 UInt16 outFontSize;
110 if (!PyArg_ParseTuple(_args, ""))
111 return NULL;
112 _err = GetMenuFont(_self->ob_itself,
113 &outFontID,
114 &outFontSize);
115 if (_err != noErr) return PyMac_Error(_err);
116 _res = Py_BuildValue("hH",
117 outFontID,
118 outFontSize);
119 return _res;
122 static PyObject *MenuObj_SetMenuFont(_self, _args)
123 MenuObject *_self;
124 PyObject *_args;
126 PyObject *_res = NULL;
127 OSStatus _err;
128 SInt16 inFontID;
129 UInt16 inFontSize;
130 if (!PyArg_ParseTuple(_args, "hH",
131 &inFontID,
132 &inFontSize))
133 return NULL;
134 _err = SetMenuFont(_self->ob_itself,
135 inFontID,
136 inFontSize);
137 if (_err != noErr) return PyMac_Error(_err);
138 Py_INCREF(Py_None);
139 _res = Py_None;
140 return _res;
143 static PyObject *MenuObj_GetMenuExcludesMarkColumn(_self, _args)
144 MenuObject *_self;
145 PyObject *_args;
147 PyObject *_res = NULL;
148 Boolean _rv;
149 if (!PyArg_ParseTuple(_args, ""))
150 return NULL;
151 _rv = GetMenuExcludesMarkColumn(_self->ob_itself);
152 _res = Py_BuildValue("b",
153 _rv);
154 return _res;
157 static PyObject *MenuObj_SetMenuExcludesMarkColumn(_self, _args)
158 MenuObject *_self;
159 PyObject *_args;
161 PyObject *_res = NULL;
162 OSStatus _err;
163 Boolean excludesMark;
164 if (!PyArg_ParseTuple(_args, "b",
165 &excludesMark))
166 return NULL;
167 _err = SetMenuExcludesMarkColumn(_self->ob_itself,
168 excludesMark);
169 if (_err != noErr) return PyMac_Error(_err);
170 Py_INCREF(Py_None);
171 _res = Py_None;
172 return _res;
175 static PyObject *MenuObj_MacAppendMenu(_self, _args)
176 MenuObject *_self;
177 PyObject *_args;
179 PyObject *_res = NULL;
180 Str255 data;
181 if (!PyArg_ParseTuple(_args, "O&",
182 PyMac_GetStr255, data))
183 return NULL;
184 MacAppendMenu(_self->ob_itself,
185 data);
186 Py_INCREF(Py_None);
187 _res = Py_None;
188 return _res;
191 static PyObject *MenuObj_InsertResMenu(_self, _args)
192 MenuObject *_self;
193 PyObject *_args;
195 PyObject *_res = NULL;
196 ResType theType;
197 short afterItem;
198 if (!PyArg_ParseTuple(_args, "O&h",
199 PyMac_GetOSType, &theType,
200 &afterItem))
201 return NULL;
202 InsertResMenu(_self->ob_itself,
203 theType,
204 afterItem);
205 Py_INCREF(Py_None);
206 _res = Py_None;
207 return _res;
210 static PyObject *MenuObj_AppendResMenu(_self, _args)
211 MenuObject *_self;
212 PyObject *_args;
214 PyObject *_res = NULL;
215 ResType theType;
216 if (!PyArg_ParseTuple(_args, "O&",
217 PyMac_GetOSType, &theType))
218 return NULL;
219 AppendResMenu(_self->ob_itself,
220 theType);
221 Py_INCREF(Py_None);
222 _res = Py_None;
223 return _res;
226 static PyObject *MenuObj_MacInsertMenuItem(_self, _args)
227 MenuObject *_self;
228 PyObject *_args;
230 PyObject *_res = NULL;
231 Str255 itemString;
232 short afterItem;
233 if (!PyArg_ParseTuple(_args, "O&h",
234 PyMac_GetStr255, itemString,
235 &afterItem))
236 return NULL;
237 MacInsertMenuItem(_self->ob_itself,
238 itemString,
239 afterItem);
240 Py_INCREF(Py_None);
241 _res = Py_None;
242 return _res;
245 static PyObject *MenuObj_DeleteMenuItem(_self, _args)
246 MenuObject *_self;
247 PyObject *_args;
249 PyObject *_res = NULL;
250 short item;
251 if (!PyArg_ParseTuple(_args, "h",
252 &item))
253 return NULL;
254 DeleteMenuItem(_self->ob_itself,
255 item);
256 Py_INCREF(Py_None);
257 _res = Py_None;
258 return _res;
261 static PyObject *MenuObj_InsertFontResMenu(_self, _args)
262 MenuObject *_self;
263 PyObject *_args;
265 PyObject *_res = NULL;
266 short afterItem;
267 short scriptFilter;
268 if (!PyArg_ParseTuple(_args, "hh",
269 &afterItem,
270 &scriptFilter))
271 return NULL;
272 InsertFontResMenu(_self->ob_itself,
273 afterItem,
274 scriptFilter);
275 Py_INCREF(Py_None);
276 _res = Py_None;
277 return _res;
280 static PyObject *MenuObj_InsertIntlResMenu(_self, _args)
281 MenuObject *_self;
282 PyObject *_args;
284 PyObject *_res = NULL;
285 ResType theType;
286 short afterItem;
287 short scriptFilter;
288 if (!PyArg_ParseTuple(_args, "O&hh",
289 PyMac_GetOSType, &theType,
290 &afterItem,
291 &scriptFilter))
292 return NULL;
293 InsertIntlResMenu(_self->ob_itself,
294 theType,
295 afterItem,
296 scriptFilter);
297 Py_INCREF(Py_None);
298 _res = Py_None;
299 return _res;
302 static PyObject *MenuObj_AppendMenuItemText(_self, _args)
303 MenuObject *_self;
304 PyObject *_args;
306 PyObject *_res = NULL;
307 OSStatus _err;
308 Str255 inString;
309 if (!PyArg_ParseTuple(_args, "O&",
310 PyMac_GetStr255, inString))
311 return NULL;
312 _err = AppendMenuItemText(_self->ob_itself,
313 inString);
314 if (_err != noErr) return PyMac_Error(_err);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
320 static PyObject *MenuObj_InsertMenuItemText(_self, _args)
321 MenuObject *_self;
322 PyObject *_args;
324 PyObject *_res = NULL;
325 OSStatus _err;
326 Str255 inString;
327 UInt16 afterItem;
328 if (!PyArg_ParseTuple(_args, "O&H",
329 PyMac_GetStr255, inString,
330 &afterItem))
331 return NULL;
332 _err = InsertMenuItemText(_self->ob_itself,
333 inString,
334 afterItem);
335 if (_err != noErr) return PyMac_Error(_err);
336 Py_INCREF(Py_None);
337 _res = Py_None;
338 return _res;
341 static PyObject *MenuObj_PopUpMenuSelect(_self, _args)
342 MenuObject *_self;
343 PyObject *_args;
345 PyObject *_res = NULL;
346 long _rv;
347 short top;
348 short left;
349 short popUpItem;
350 if (!PyArg_ParseTuple(_args, "hhh",
351 &top,
352 &left,
353 &popUpItem))
354 return NULL;
355 _rv = PopUpMenuSelect(_self->ob_itself,
356 top,
357 left,
358 popUpItem);
359 _res = Py_BuildValue("l",
360 _rv);
361 return _res;
364 static PyObject *MenuObj_MacInsertMenu(_self, _args)
365 MenuObject *_self;
366 PyObject *_args;
368 PyObject *_res = NULL;
369 short beforeID;
370 if (!PyArg_ParseTuple(_args, "h",
371 &beforeID))
372 return NULL;
373 MacInsertMenu(_self->ob_itself,
374 beforeID);
375 Py_INCREF(Py_None);
376 _res = Py_None;
377 return _res;
380 #if !TARGET_API_MAC_CARBON
382 static PyObject *MenuObj_CheckItem(_self, _args)
383 MenuObject *_self;
384 PyObject *_args;
386 PyObject *_res = NULL;
387 short item;
388 Boolean checked;
389 if (!PyArg_ParseTuple(_args, "hb",
390 &item,
391 &checked))
392 return NULL;
393 CheckItem(_self->ob_itself,
394 item,
395 checked);
396 Py_INCREF(Py_None);
397 _res = Py_None;
398 return _res;
400 #endif
402 static PyObject *MenuObj_SetMenuItemText(_self, _args)
403 MenuObject *_self;
404 PyObject *_args;
406 PyObject *_res = NULL;
407 short item;
408 Str255 itemString;
409 if (!PyArg_ParseTuple(_args, "hO&",
410 &item,
411 PyMac_GetStr255, itemString))
412 return NULL;
413 SetMenuItemText(_self->ob_itself,
414 item,
415 itemString);
416 Py_INCREF(Py_None);
417 _res = Py_None;
418 return _res;
421 static PyObject *MenuObj_GetMenuItemText(_self, _args)
422 MenuObject *_self;
423 PyObject *_args;
425 PyObject *_res = NULL;
426 short item;
427 Str255 itemString;
428 if (!PyArg_ParseTuple(_args, "h",
429 &item))
430 return NULL;
431 GetMenuItemText(_self->ob_itself,
432 item,
433 itemString);
434 _res = Py_BuildValue("O&",
435 PyMac_BuildStr255, itemString);
436 return _res;
439 static PyObject *MenuObj_SetItemMark(_self, _args)
440 MenuObject *_self;
441 PyObject *_args;
443 PyObject *_res = NULL;
444 short item;
445 CharParameter markChar;
446 if (!PyArg_ParseTuple(_args, "hh",
447 &item,
448 &markChar))
449 return NULL;
450 SetItemMark(_self->ob_itself,
451 item,
452 markChar);
453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
458 static PyObject *MenuObj_GetItemMark(_self, _args)
459 MenuObject *_self;
460 PyObject *_args;
462 PyObject *_res = NULL;
463 short item;
464 CharParameter markChar;
465 if (!PyArg_ParseTuple(_args, "h",
466 &item))
467 return NULL;
468 GetItemMark(_self->ob_itself,
469 item,
470 &markChar);
471 _res = Py_BuildValue("h",
472 markChar);
473 return _res;
476 static PyObject *MenuObj_SetItemCmd(_self, _args)
477 MenuObject *_self;
478 PyObject *_args;
480 PyObject *_res = NULL;
481 short item;
482 CharParameter cmdChar;
483 if (!PyArg_ParseTuple(_args, "hh",
484 &item,
485 &cmdChar))
486 return NULL;
487 SetItemCmd(_self->ob_itself,
488 item,
489 cmdChar);
490 Py_INCREF(Py_None);
491 _res = Py_None;
492 return _res;
495 static PyObject *MenuObj_GetItemCmd(_self, _args)
496 MenuObject *_self;
497 PyObject *_args;
499 PyObject *_res = NULL;
500 short item;
501 CharParameter cmdChar;
502 if (!PyArg_ParseTuple(_args, "h",
503 &item))
504 return NULL;
505 GetItemCmd(_self->ob_itself,
506 item,
507 &cmdChar);
508 _res = Py_BuildValue("h",
509 cmdChar);
510 return _res;
513 static PyObject *MenuObj_SetItemIcon(_self, _args)
514 MenuObject *_self;
515 PyObject *_args;
517 PyObject *_res = NULL;
518 short item;
519 short iconIndex;
520 if (!PyArg_ParseTuple(_args, "hh",
521 &item,
522 &iconIndex))
523 return NULL;
524 SetItemIcon(_self->ob_itself,
525 item,
526 iconIndex);
527 Py_INCREF(Py_None);
528 _res = Py_None;
529 return _res;
532 static PyObject *MenuObj_GetItemIcon(_self, _args)
533 MenuObject *_self;
534 PyObject *_args;
536 PyObject *_res = NULL;
537 short item;
538 short iconIndex;
539 if (!PyArg_ParseTuple(_args, "h",
540 &item))
541 return NULL;
542 GetItemIcon(_self->ob_itself,
543 item,
544 &iconIndex);
545 _res = Py_BuildValue("h",
546 iconIndex);
547 return _res;
550 static PyObject *MenuObj_SetItemStyle(_self, _args)
551 MenuObject *_self;
552 PyObject *_args;
554 PyObject *_res = NULL;
555 short item;
556 StyleParameter chStyle;
557 if (!PyArg_ParseTuple(_args, "hh",
558 &item,
559 &chStyle))
560 return NULL;
561 SetItemStyle(_self->ob_itself,
562 item,
563 chStyle);
564 Py_INCREF(Py_None);
565 _res = Py_None;
566 return _res;
569 static PyObject *MenuObj_GetItemStyle(_self, _args)
570 MenuObject *_self;
571 PyObject *_args;
573 PyObject *_res = NULL;
574 short item;
575 Style chStyle;
576 if (!PyArg_ParseTuple(_args, "h",
577 &item))
578 return NULL;
579 GetItemStyle(_self->ob_itself,
580 item,
581 &chStyle);
582 _res = Py_BuildValue("b",
583 chStyle);
584 return _res;
587 #if !TARGET_API_MAC_CARBON
589 static PyObject *MenuObj_DisableItem(_self, _args)
590 MenuObject *_self;
591 PyObject *_args;
593 PyObject *_res = NULL;
594 short item;
595 if (!PyArg_ParseTuple(_args, "h",
596 &item))
597 return NULL;
598 DisableItem(_self->ob_itself,
599 item);
600 Py_INCREF(Py_None);
601 _res = Py_None;
602 return _res;
604 #endif
606 #if !TARGET_API_MAC_CARBON
608 static PyObject *MenuObj_EnableItem(_self, _args)
609 MenuObject *_self;
610 PyObject *_args;
612 PyObject *_res = NULL;
613 short item;
614 if (!PyArg_ParseTuple(_args, "h",
615 &item))
616 return NULL;
617 EnableItem(_self->ob_itself,
618 item);
619 Py_INCREF(Py_None);
620 _res = Py_None;
621 return _res;
623 #endif
625 static PyObject *MenuObj_SetMenuItemCommandID(_self, _args)
626 MenuObject *_self;
627 PyObject *_args;
629 PyObject *_res = NULL;
630 OSErr _err;
631 SInt16 inItem;
632 UInt32 inCommandID;
633 if (!PyArg_ParseTuple(_args, "hl",
634 &inItem,
635 &inCommandID))
636 return NULL;
637 _err = SetMenuItemCommandID(_self->ob_itself,
638 inItem,
639 inCommandID);
640 if (_err != noErr) return PyMac_Error(_err);
641 Py_INCREF(Py_None);
642 _res = Py_None;
643 return _res;
646 static PyObject *MenuObj_GetMenuItemCommandID(_self, _args)
647 MenuObject *_self;
648 PyObject *_args;
650 PyObject *_res = NULL;
651 OSErr _err;
652 SInt16 inItem;
653 UInt32 outCommandID;
654 if (!PyArg_ParseTuple(_args, "h",
655 &inItem))
656 return NULL;
657 _err = GetMenuItemCommandID(_self->ob_itself,
658 inItem,
659 &outCommandID);
660 if (_err != noErr) return PyMac_Error(_err);
661 _res = Py_BuildValue("l",
662 outCommandID);
663 return _res;
666 static PyObject *MenuObj_SetMenuItemModifiers(_self, _args)
667 MenuObject *_self;
668 PyObject *_args;
670 PyObject *_res = NULL;
671 OSErr _err;
672 SInt16 inItem;
673 UInt8 inModifiers;
674 if (!PyArg_ParseTuple(_args, "hb",
675 &inItem,
676 &inModifiers))
677 return NULL;
678 _err = SetMenuItemModifiers(_self->ob_itself,
679 inItem,
680 inModifiers);
681 if (_err != noErr) return PyMac_Error(_err);
682 Py_INCREF(Py_None);
683 _res = Py_None;
684 return _res;
687 static PyObject *MenuObj_GetMenuItemModifiers(_self, _args)
688 MenuObject *_self;
689 PyObject *_args;
691 PyObject *_res = NULL;
692 OSErr _err;
693 SInt16 inItem;
694 UInt8 outModifiers;
695 if (!PyArg_ParseTuple(_args, "h",
696 &inItem))
697 return NULL;
698 _err = GetMenuItemModifiers(_self->ob_itself,
699 inItem,
700 &outModifiers);
701 if (_err != noErr) return PyMac_Error(_err);
702 _res = Py_BuildValue("b",
703 outModifiers);
704 return _res;
707 static PyObject *MenuObj_SetMenuItemIconHandle(_self, _args)
708 MenuObject *_self;
709 PyObject *_args;
711 PyObject *_res = NULL;
712 OSErr _err;
713 SInt16 inItem;
714 UInt8 inIconType;
715 Handle inIconHandle;
716 if (!PyArg_ParseTuple(_args, "hbO&",
717 &inItem,
718 &inIconType,
719 ResObj_Convert, &inIconHandle))
720 return NULL;
721 _err = SetMenuItemIconHandle(_self->ob_itself,
722 inItem,
723 inIconType,
724 inIconHandle);
725 if (_err != noErr) return PyMac_Error(_err);
726 Py_INCREF(Py_None);
727 _res = Py_None;
728 return _res;
731 static PyObject *MenuObj_GetMenuItemIconHandle(_self, _args)
732 MenuObject *_self;
733 PyObject *_args;
735 PyObject *_res = NULL;
736 OSErr _err;
737 SInt16 inItem;
738 UInt8 outIconType;
739 Handle outIconHandle;
740 if (!PyArg_ParseTuple(_args, "h",
741 &inItem))
742 return NULL;
743 _err = GetMenuItemIconHandle(_self->ob_itself,
744 inItem,
745 &outIconType,
746 &outIconHandle);
747 if (_err != noErr) return PyMac_Error(_err);
748 _res = Py_BuildValue("bO&",
749 outIconType,
750 ResObj_New, outIconHandle);
751 return _res;
754 static PyObject *MenuObj_SetMenuItemTextEncoding(_self, _args)
755 MenuObject *_self;
756 PyObject *_args;
758 PyObject *_res = NULL;
759 OSErr _err;
760 SInt16 inItem;
761 TextEncoding inScriptID;
762 if (!PyArg_ParseTuple(_args, "hl",
763 &inItem,
764 &inScriptID))
765 return NULL;
766 _err = SetMenuItemTextEncoding(_self->ob_itself,
767 inItem,
768 inScriptID);
769 if (_err != noErr) return PyMac_Error(_err);
770 Py_INCREF(Py_None);
771 _res = Py_None;
772 return _res;
775 static PyObject *MenuObj_GetMenuItemTextEncoding(_self, _args)
776 MenuObject *_self;
777 PyObject *_args;
779 PyObject *_res = NULL;
780 OSErr _err;
781 SInt16 inItem;
782 TextEncoding outScriptID;
783 if (!PyArg_ParseTuple(_args, "h",
784 &inItem))
785 return NULL;
786 _err = GetMenuItemTextEncoding(_self->ob_itself,
787 inItem,
788 &outScriptID);
789 if (_err != noErr) return PyMac_Error(_err);
790 _res = Py_BuildValue("l",
791 outScriptID);
792 return _res;
795 static PyObject *MenuObj_SetMenuItemHierarchicalID(_self, _args)
796 MenuObject *_self;
797 PyObject *_args;
799 PyObject *_res = NULL;
800 OSErr _err;
801 SInt16 inItem;
802 SInt16 inHierID;
803 if (!PyArg_ParseTuple(_args, "hh",
804 &inItem,
805 &inHierID))
806 return NULL;
807 _err = SetMenuItemHierarchicalID(_self->ob_itself,
808 inItem,
809 inHierID);
810 if (_err != noErr) return PyMac_Error(_err);
811 Py_INCREF(Py_None);
812 _res = Py_None;
813 return _res;
816 static PyObject *MenuObj_GetMenuItemHierarchicalID(_self, _args)
817 MenuObject *_self;
818 PyObject *_args;
820 PyObject *_res = NULL;
821 OSErr _err;
822 SInt16 inItem;
823 SInt16 outHierID;
824 if (!PyArg_ParseTuple(_args, "h",
825 &inItem))
826 return NULL;
827 _err = GetMenuItemHierarchicalID(_self->ob_itself,
828 inItem,
829 &outHierID);
830 if (_err != noErr) return PyMac_Error(_err);
831 _res = Py_BuildValue("h",
832 outHierID);
833 return _res;
836 static PyObject *MenuObj_SetMenuItemFontID(_self, _args)
837 MenuObject *_self;
838 PyObject *_args;
840 PyObject *_res = NULL;
841 OSErr _err;
842 SInt16 inItem;
843 SInt16 inFontID;
844 if (!PyArg_ParseTuple(_args, "hh",
845 &inItem,
846 &inFontID))
847 return NULL;
848 _err = SetMenuItemFontID(_self->ob_itself,
849 inItem,
850 inFontID);
851 if (_err != noErr) return PyMac_Error(_err);
852 Py_INCREF(Py_None);
853 _res = Py_None;
854 return _res;
857 static PyObject *MenuObj_GetMenuItemFontID(_self, _args)
858 MenuObject *_self;
859 PyObject *_args;
861 PyObject *_res = NULL;
862 OSErr _err;
863 SInt16 inItem;
864 SInt16 outFontID;
865 if (!PyArg_ParseTuple(_args, "h",
866 &inItem))
867 return NULL;
868 _err = GetMenuItemFontID(_self->ob_itself,
869 inItem,
870 &outFontID);
871 if (_err != noErr) return PyMac_Error(_err);
872 _res = Py_BuildValue("h",
873 outFontID);
874 return _res;
877 static PyObject *MenuObj_SetMenuItemRefCon(_self, _args)
878 MenuObject *_self;
879 PyObject *_args;
881 PyObject *_res = NULL;
882 OSErr _err;
883 SInt16 inItem;
884 UInt32 inRefCon;
885 if (!PyArg_ParseTuple(_args, "hl",
886 &inItem,
887 &inRefCon))
888 return NULL;
889 _err = SetMenuItemRefCon(_self->ob_itself,
890 inItem,
891 inRefCon);
892 if (_err != noErr) return PyMac_Error(_err);
893 Py_INCREF(Py_None);
894 _res = Py_None;
895 return _res;
898 static PyObject *MenuObj_GetMenuItemRefCon(_self, _args)
899 MenuObject *_self;
900 PyObject *_args;
902 PyObject *_res = NULL;
903 OSErr _err;
904 SInt16 inItem;
905 UInt32 outRefCon;
906 if (!PyArg_ParseTuple(_args, "h",
907 &inItem))
908 return NULL;
909 _err = GetMenuItemRefCon(_self->ob_itself,
910 inItem,
911 &outRefCon);
912 if (_err != noErr) return PyMac_Error(_err);
913 _res = Py_BuildValue("l",
914 outRefCon);
915 return _res;
918 #if !TARGET_API_MAC_CARBON
920 static PyObject *MenuObj_SetMenuItemRefCon2(_self, _args)
921 MenuObject *_self;
922 PyObject *_args;
924 PyObject *_res = NULL;
925 OSErr _err;
926 SInt16 inItem;
927 UInt32 inRefCon2;
928 if (!PyArg_ParseTuple(_args, "hl",
929 &inItem,
930 &inRefCon2))
931 return NULL;
932 _err = SetMenuItemRefCon2(_self->ob_itself,
933 inItem,
934 inRefCon2);
935 if (_err != noErr) return PyMac_Error(_err);
936 Py_INCREF(Py_None);
937 _res = Py_None;
938 return _res;
940 #endif
942 #if !TARGET_API_MAC_CARBON
944 static PyObject *MenuObj_GetMenuItemRefCon2(_self, _args)
945 MenuObject *_self;
946 PyObject *_args;
948 PyObject *_res = NULL;
949 OSErr _err;
950 SInt16 inItem;
951 UInt32 outRefCon2;
952 if (!PyArg_ParseTuple(_args, "h",
953 &inItem))
954 return NULL;
955 _err = GetMenuItemRefCon2(_self->ob_itself,
956 inItem,
957 &outRefCon2);
958 if (_err != noErr) return PyMac_Error(_err);
959 _res = Py_BuildValue("l",
960 outRefCon2);
961 return _res;
963 #endif
965 static PyObject *MenuObj_SetMenuItemKeyGlyph(_self, _args)
966 MenuObject *_self;
967 PyObject *_args;
969 PyObject *_res = NULL;
970 OSErr _err;
971 SInt16 inItem;
972 SInt16 inGlyph;
973 if (!PyArg_ParseTuple(_args, "hh",
974 &inItem,
975 &inGlyph))
976 return NULL;
977 _err = SetMenuItemKeyGlyph(_self->ob_itself,
978 inItem,
979 inGlyph);
980 if (_err != noErr) return PyMac_Error(_err);
981 Py_INCREF(Py_None);
982 _res = Py_None;
983 return _res;
986 static PyObject *MenuObj_GetMenuItemKeyGlyph(_self, _args)
987 MenuObject *_self;
988 PyObject *_args;
990 PyObject *_res = NULL;
991 OSErr _err;
992 SInt16 inItem;
993 SInt16 outGlyph;
994 if (!PyArg_ParseTuple(_args, "h",
995 &inItem))
996 return NULL;
997 _err = GetMenuItemKeyGlyph(_self->ob_itself,
998 inItem,
999 &outGlyph);
1000 if (_err != noErr) return PyMac_Error(_err);
1001 _res = Py_BuildValue("h",
1002 outGlyph);
1003 return _res;
1006 static PyObject *MenuObj_MacEnableMenuItem(_self, _args)
1007 MenuObject *_self;
1008 PyObject *_args;
1010 PyObject *_res = NULL;
1011 UInt16 item;
1012 if (!PyArg_ParseTuple(_args, "H",
1013 &item))
1014 return NULL;
1015 MacEnableMenuItem(_self->ob_itself,
1016 item);
1017 Py_INCREF(Py_None);
1018 _res = Py_None;
1019 return _res;
1022 static PyObject *MenuObj_DisableMenuItem(_self, _args)
1023 MenuObject *_self;
1024 PyObject *_args;
1026 PyObject *_res = NULL;
1027 UInt16 item;
1028 if (!PyArg_ParseTuple(_args, "H",
1029 &item))
1030 return NULL;
1031 DisableMenuItem(_self->ob_itself,
1032 item);
1033 Py_INCREF(Py_None);
1034 _res = Py_None;
1035 return _res;
1038 static PyObject *MenuObj_IsMenuItemEnabled(_self, _args)
1039 MenuObject *_self;
1040 PyObject *_args;
1042 PyObject *_res = NULL;
1043 Boolean _rv;
1044 UInt16 item;
1045 if (!PyArg_ParseTuple(_args, "H",
1046 &item))
1047 return NULL;
1048 _rv = IsMenuItemEnabled(_self->ob_itself,
1049 item);
1050 _res = Py_BuildValue("b",
1051 _rv);
1052 return _res;
1055 static PyObject *MenuObj_EnableMenuItemIcon(_self, _args)
1056 MenuObject *_self;
1057 PyObject *_args;
1059 PyObject *_res = NULL;
1060 UInt16 item;
1061 if (!PyArg_ParseTuple(_args, "H",
1062 &item))
1063 return NULL;
1064 EnableMenuItemIcon(_self->ob_itself,
1065 item);
1066 Py_INCREF(Py_None);
1067 _res = Py_None;
1068 return _res;
1071 static PyObject *MenuObj_DisableMenuItemIcon(_self, _args)
1072 MenuObject *_self;
1073 PyObject *_args;
1075 PyObject *_res = NULL;
1076 UInt16 item;
1077 if (!PyArg_ParseTuple(_args, "H",
1078 &item))
1079 return NULL;
1080 DisableMenuItemIcon(_self->ob_itself,
1081 item);
1082 Py_INCREF(Py_None);
1083 _res = Py_None;
1084 return _res;
1087 static PyObject *MenuObj_IsMenuItemIconEnabled(_self, _args)
1088 MenuObject *_self;
1089 PyObject *_args;
1091 PyObject *_res = NULL;
1092 Boolean _rv;
1093 UInt16 item;
1094 if (!PyArg_ParseTuple(_args, "H",
1095 &item))
1096 return NULL;
1097 _rv = IsMenuItemIconEnabled(_self->ob_itself,
1098 item);
1099 _res = Py_BuildValue("b",
1100 _rv);
1101 return _res;
1104 static PyObject *MenuObj_as_Resource(_self, _args)
1105 MenuObject *_self;
1106 PyObject *_args;
1108 PyObject *_res = NULL;
1109 Handle _rv;
1110 if (!PyArg_ParseTuple(_args, ""))
1111 return NULL;
1112 _rv = as_Resource(_self->ob_itself);
1113 _res = Py_BuildValue("O&",
1114 ResObj_New, _rv);
1115 return _res;
1118 static PyObject *MenuObj_AppendMenu(_self, _args)
1119 MenuObject *_self;
1120 PyObject *_args;
1122 PyObject *_res = NULL;
1123 Str255 data;
1124 if (!PyArg_ParseTuple(_args, "O&",
1125 PyMac_GetStr255, data))
1126 return NULL;
1127 AppendMenu(_self->ob_itself,
1128 data);
1129 Py_INCREF(Py_None);
1130 _res = Py_None;
1131 return _res;
1134 static PyObject *MenuObj_InsertMenu(_self, _args)
1135 MenuObject *_self;
1136 PyObject *_args;
1138 PyObject *_res = NULL;
1139 short beforeID;
1140 if (!PyArg_ParseTuple(_args, "h",
1141 &beforeID))
1142 return NULL;
1143 InsertMenu(_self->ob_itself,
1144 beforeID);
1145 Py_INCREF(Py_None);
1146 _res = Py_None;
1147 return _res;
1150 static PyObject *MenuObj_InsertMenuItem(_self, _args)
1151 MenuObject *_self;
1152 PyObject *_args;
1154 PyObject *_res = NULL;
1155 Str255 itemString;
1156 short afterItem;
1157 if (!PyArg_ParseTuple(_args, "O&h",
1158 PyMac_GetStr255, itemString,
1159 &afterItem))
1160 return NULL;
1161 InsertMenuItem(_self->ob_itself,
1162 itemString,
1163 afterItem);
1164 Py_INCREF(Py_None);
1165 _res = Py_None;
1166 return _res;
1169 static PyMethodDef MenuObj_methods[] = {
1170 {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1,
1171 "() -> None"},
1172 {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1,
1173 "() -> None"},
1175 #if !TARGET_API_MAC_CARBON
1176 {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1,
1177 "() -> (short _rv)"},
1178 #endif
1179 {"GetMenuFont", (PyCFunction)MenuObj_GetMenuFont, 1,
1180 "() -> (SInt16 outFontID, UInt16 outFontSize)"},
1181 {"SetMenuFont", (PyCFunction)MenuObj_SetMenuFont, 1,
1182 "(SInt16 inFontID, UInt16 inFontSize) -> None"},
1183 {"GetMenuExcludesMarkColumn", (PyCFunction)MenuObj_GetMenuExcludesMarkColumn, 1,
1184 "() -> (Boolean _rv)"},
1185 {"SetMenuExcludesMarkColumn", (PyCFunction)MenuObj_SetMenuExcludesMarkColumn, 1,
1186 "(Boolean excludesMark) -> None"},
1187 {"MacAppendMenu", (PyCFunction)MenuObj_MacAppendMenu, 1,
1188 "(Str255 data) -> None"},
1189 {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1,
1190 "(ResType theType, short afterItem) -> None"},
1191 {"AppendResMenu", (PyCFunction)MenuObj_AppendResMenu, 1,
1192 "(ResType theType) -> None"},
1193 {"MacInsertMenuItem", (PyCFunction)MenuObj_MacInsertMenuItem, 1,
1194 "(Str255 itemString, short afterItem) -> None"},
1195 {"DeleteMenuItem", (PyCFunction)MenuObj_DeleteMenuItem, 1,
1196 "(short item) -> None"},
1197 {"InsertFontResMenu", (PyCFunction)MenuObj_InsertFontResMenu, 1,
1198 "(short afterItem, short scriptFilter) -> None"},
1199 {"InsertIntlResMenu", (PyCFunction)MenuObj_InsertIntlResMenu, 1,
1200 "(ResType theType, short afterItem, short scriptFilter) -> None"},
1201 {"AppendMenuItemText", (PyCFunction)MenuObj_AppendMenuItemText, 1,
1202 "(Str255 inString) -> None"},
1203 {"InsertMenuItemText", (PyCFunction)MenuObj_InsertMenuItemText, 1,
1204 "(Str255 inString, UInt16 afterItem) -> None"},
1205 {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1,
1206 "(short top, short left, short popUpItem) -> (long _rv)"},
1207 {"MacInsertMenu", (PyCFunction)MenuObj_MacInsertMenu, 1,
1208 "(short beforeID) -> None"},
1210 #if !TARGET_API_MAC_CARBON
1211 {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1,
1212 "(short item, Boolean checked) -> None"},
1213 #endif
1214 {"SetMenuItemText", (PyCFunction)MenuObj_SetMenuItemText, 1,
1215 "(short item, Str255 itemString) -> None"},
1216 {"GetMenuItemText", (PyCFunction)MenuObj_GetMenuItemText, 1,
1217 "(short item) -> (Str255 itemString)"},
1218 {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1,
1219 "(short item, CharParameter markChar) -> None"},
1220 {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1,
1221 "(short item) -> (CharParameter markChar)"},
1222 {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1,
1223 "(short item, CharParameter cmdChar) -> None"},
1224 {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1,
1225 "(short item) -> (CharParameter cmdChar)"},
1226 {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1,
1227 "(short item, short iconIndex) -> None"},
1228 {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1,
1229 "(short item) -> (short iconIndex)"},
1230 {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1,
1231 "(short item, StyleParameter chStyle) -> None"},
1232 {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1,
1233 "(short item) -> (Style chStyle)"},
1235 #if !TARGET_API_MAC_CARBON
1236 {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1,
1237 "(short item) -> None"},
1238 #endif
1240 #if !TARGET_API_MAC_CARBON
1241 {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1,
1242 "(short item) -> None"},
1243 #endif
1244 {"SetMenuItemCommandID", (PyCFunction)MenuObj_SetMenuItemCommandID, 1,
1245 "(SInt16 inItem, UInt32 inCommandID) -> None"},
1246 {"GetMenuItemCommandID", (PyCFunction)MenuObj_GetMenuItemCommandID, 1,
1247 "(SInt16 inItem) -> (UInt32 outCommandID)"},
1248 {"SetMenuItemModifiers", (PyCFunction)MenuObj_SetMenuItemModifiers, 1,
1249 "(SInt16 inItem, UInt8 inModifiers) -> None"},
1250 {"GetMenuItemModifiers", (PyCFunction)MenuObj_GetMenuItemModifiers, 1,
1251 "(SInt16 inItem) -> (UInt8 outModifiers)"},
1252 {"SetMenuItemIconHandle", (PyCFunction)MenuObj_SetMenuItemIconHandle, 1,
1253 "(SInt16 inItem, UInt8 inIconType, Handle inIconHandle) -> None"},
1254 {"GetMenuItemIconHandle", (PyCFunction)MenuObj_GetMenuItemIconHandle, 1,
1255 "(SInt16 inItem) -> (UInt8 outIconType, Handle outIconHandle)"},
1256 {"SetMenuItemTextEncoding", (PyCFunction)MenuObj_SetMenuItemTextEncoding, 1,
1257 "(SInt16 inItem, TextEncoding inScriptID) -> None"},
1258 {"GetMenuItemTextEncoding", (PyCFunction)MenuObj_GetMenuItemTextEncoding, 1,
1259 "(SInt16 inItem) -> (TextEncoding outScriptID)"},
1260 {"SetMenuItemHierarchicalID", (PyCFunction)MenuObj_SetMenuItemHierarchicalID, 1,
1261 "(SInt16 inItem, SInt16 inHierID) -> None"},
1262 {"GetMenuItemHierarchicalID", (PyCFunction)MenuObj_GetMenuItemHierarchicalID, 1,
1263 "(SInt16 inItem) -> (SInt16 outHierID)"},
1264 {"SetMenuItemFontID", (PyCFunction)MenuObj_SetMenuItemFontID, 1,
1265 "(SInt16 inItem, SInt16 inFontID) -> None"},
1266 {"GetMenuItemFontID", (PyCFunction)MenuObj_GetMenuItemFontID, 1,
1267 "(SInt16 inItem) -> (SInt16 outFontID)"},
1268 {"SetMenuItemRefCon", (PyCFunction)MenuObj_SetMenuItemRefCon, 1,
1269 "(SInt16 inItem, UInt32 inRefCon) -> None"},
1270 {"GetMenuItemRefCon", (PyCFunction)MenuObj_GetMenuItemRefCon, 1,
1271 "(SInt16 inItem) -> (UInt32 outRefCon)"},
1273 #if !TARGET_API_MAC_CARBON
1274 {"SetMenuItemRefCon2", (PyCFunction)MenuObj_SetMenuItemRefCon2, 1,
1275 "(SInt16 inItem, UInt32 inRefCon2) -> None"},
1276 #endif
1278 #if !TARGET_API_MAC_CARBON
1279 {"GetMenuItemRefCon2", (PyCFunction)MenuObj_GetMenuItemRefCon2, 1,
1280 "(SInt16 inItem) -> (UInt32 outRefCon2)"},
1281 #endif
1282 {"SetMenuItemKeyGlyph", (PyCFunction)MenuObj_SetMenuItemKeyGlyph, 1,
1283 "(SInt16 inItem, SInt16 inGlyph) -> None"},
1284 {"GetMenuItemKeyGlyph", (PyCFunction)MenuObj_GetMenuItemKeyGlyph, 1,
1285 "(SInt16 inItem) -> (SInt16 outGlyph)"},
1286 {"MacEnableMenuItem", (PyCFunction)MenuObj_MacEnableMenuItem, 1,
1287 "(UInt16 item) -> None"},
1288 {"DisableMenuItem", (PyCFunction)MenuObj_DisableMenuItem, 1,
1289 "(UInt16 item) -> None"},
1290 {"IsMenuItemEnabled", (PyCFunction)MenuObj_IsMenuItemEnabled, 1,
1291 "(UInt16 item) -> (Boolean _rv)"},
1292 {"EnableMenuItemIcon", (PyCFunction)MenuObj_EnableMenuItemIcon, 1,
1293 "(UInt16 item) -> None"},
1294 {"DisableMenuItemIcon", (PyCFunction)MenuObj_DisableMenuItemIcon, 1,
1295 "(UInt16 item) -> None"},
1296 {"IsMenuItemIconEnabled", (PyCFunction)MenuObj_IsMenuItemIconEnabled, 1,
1297 "(UInt16 item) -> (Boolean _rv)"},
1298 {"as_Resource", (PyCFunction)MenuObj_as_Resource, 1,
1299 "() -> (Handle _rv)"},
1300 {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1,
1301 "(Str255 data) -> None"},
1302 {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1,
1303 "(short beforeID) -> None"},
1304 {"InsertMenuItem", (PyCFunction)MenuObj_InsertMenuItem, 1,
1305 "(Str255 itemString, short afterItem) -> None"},
1306 {NULL, NULL, 0}
1309 PyMethodChain MenuObj_chain = { MenuObj_methods, NULL };
1311 static PyObject *MenuObj_getattr(self, name)
1312 MenuObject *self;
1313 char *name;
1315 return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name);
1318 #define MenuObj_setattr NULL
1320 #define MenuObj_compare NULL
1322 #define MenuObj_repr NULL
1324 #define MenuObj_hash NULL
1326 PyTypeObject Menu_Type = {
1327 PyObject_HEAD_INIT(&PyType_Type)
1328 0, /*ob_size*/
1329 "Menu", /*tp_name*/
1330 sizeof(MenuObject), /*tp_basicsize*/
1331 0, /*tp_itemsize*/
1332 /* methods */
1333 (destructor) MenuObj_dealloc, /*tp_dealloc*/
1334 0, /*tp_print*/
1335 (getattrfunc) MenuObj_getattr, /*tp_getattr*/
1336 (setattrfunc) MenuObj_setattr, /*tp_setattr*/
1337 (cmpfunc) MenuObj_compare, /*tp_compare*/
1338 (reprfunc) MenuObj_repr, /*tp_repr*/
1339 (PyNumberMethods *)0, /* tp_as_number */
1340 (PySequenceMethods *)0, /* tp_as_sequence */
1341 (PyMappingMethods *)0, /* tp_as_mapping */
1342 (hashfunc) MenuObj_hash, /*tp_hash*/
1345 /* ---------------------- End object type Menu ---------------------- */
1348 #if !TARGET_API_MAC_CARBON
1350 static PyObject *Menu_InitProcMenu(_self, _args)
1351 PyObject *_self;
1352 PyObject *_args;
1354 PyObject *_res = NULL;
1355 short resID;
1356 if (!PyArg_ParseTuple(_args, "h",
1357 &resID))
1358 return NULL;
1359 InitProcMenu(resID);
1360 Py_INCREF(Py_None);
1361 _res = Py_None;
1362 return _res;
1364 #endif
1366 #if !TARGET_API_MAC_CARBON
1368 static PyObject *Menu_InitMenus(_self, _args)
1369 PyObject *_self;
1370 PyObject *_args;
1372 PyObject *_res = NULL;
1373 if (!PyArg_ParseTuple(_args, ""))
1374 return NULL;
1375 InitMenus();
1376 Py_INCREF(Py_None);
1377 _res = Py_None;
1378 return _res;
1380 #endif
1382 static PyObject *Menu_NewMenu(_self, _args)
1383 PyObject *_self;
1384 PyObject *_args;
1386 PyObject *_res = NULL;
1387 MenuHandle _rv;
1388 short menuID;
1389 Str255 menuTitle;
1390 if (!PyArg_ParseTuple(_args, "hO&",
1391 &menuID,
1392 PyMac_GetStr255, menuTitle))
1393 return NULL;
1394 _rv = NewMenu(menuID,
1395 menuTitle);
1396 _res = Py_BuildValue("O&",
1397 MenuObj_New, _rv);
1398 return _res;
1401 static PyObject *Menu_MacGetMenu(_self, _args)
1402 PyObject *_self;
1403 PyObject *_args;
1405 PyObject *_res = NULL;
1406 MenuHandle _rv;
1407 short resourceID;
1408 if (!PyArg_ParseTuple(_args, "h",
1409 &resourceID))
1410 return NULL;
1411 _rv = MacGetMenu(resourceID);
1412 _res = Py_BuildValue("O&",
1413 MenuObj_New, _rv);
1414 return _res;
1417 static PyObject *Menu_MenuKey(_self, _args)
1418 PyObject *_self;
1419 PyObject *_args;
1421 PyObject *_res = NULL;
1422 long _rv;
1423 CharParameter ch;
1424 if (!PyArg_ParseTuple(_args, "h",
1425 &ch))
1426 return NULL;
1427 _rv = MenuKey(ch);
1428 _res = Py_BuildValue("l",
1429 _rv);
1430 return _res;
1433 static PyObject *Menu_MenuSelect(_self, _args)
1434 PyObject *_self;
1435 PyObject *_args;
1437 PyObject *_res = NULL;
1438 long _rv;
1439 Point startPt;
1440 if (!PyArg_ParseTuple(_args, "O&",
1441 PyMac_GetPoint, &startPt))
1442 return NULL;
1443 _rv = MenuSelect(startPt);
1444 _res = Py_BuildValue("l",
1445 _rv);
1446 return _res;
1449 static PyObject *Menu_MenuChoice(_self, _args)
1450 PyObject *_self;
1451 PyObject *_args;
1453 PyObject *_res = NULL;
1454 long _rv;
1455 if (!PyArg_ParseTuple(_args, ""))
1456 return NULL;
1457 _rv = MenuChoice();
1458 _res = Py_BuildValue("l",
1459 _rv);
1460 return _res;
1463 static PyObject *Menu_MenuEvent(_self, _args)
1464 PyObject *_self;
1465 PyObject *_args;
1467 PyObject *_res = NULL;
1468 UInt32 _rv;
1469 EventRecord inEvent;
1470 if (!PyArg_ParseTuple(_args, "O&",
1471 PyMac_GetEventRecord, &inEvent))
1472 return NULL;
1473 _rv = MenuEvent(&inEvent);
1474 _res = Py_BuildValue("l",
1475 _rv);
1476 return _res;
1479 static PyObject *Menu_GetMBarHeight(_self, _args)
1480 PyObject *_self;
1481 PyObject *_args;
1483 PyObject *_res = NULL;
1484 short _rv;
1485 if (!PyArg_ParseTuple(_args, ""))
1486 return NULL;
1487 _rv = GetMBarHeight();
1488 _res = Py_BuildValue("h",
1489 _rv);
1490 return _res;
1493 static PyObject *Menu_MacDrawMenuBar(_self, _args)
1494 PyObject *_self;
1495 PyObject *_args;
1497 PyObject *_res = NULL;
1498 if (!PyArg_ParseTuple(_args, ""))
1499 return NULL;
1500 MacDrawMenuBar();
1501 Py_INCREF(Py_None);
1502 _res = Py_None;
1503 return _res;
1506 static PyObject *Menu_InvalMenuBar(_self, _args)
1507 PyObject *_self;
1508 PyObject *_args;
1510 PyObject *_res = NULL;
1511 if (!PyArg_ParseTuple(_args, ""))
1512 return NULL;
1513 InvalMenuBar();
1514 Py_INCREF(Py_None);
1515 _res = Py_None;
1516 return _res;
1519 static PyObject *Menu_HiliteMenu(_self, _args)
1520 PyObject *_self;
1521 PyObject *_args;
1523 PyObject *_res = NULL;
1524 short menuID;
1525 if (!PyArg_ParseTuple(_args, "h",
1526 &menuID))
1527 return NULL;
1528 HiliteMenu(menuID);
1529 Py_INCREF(Py_None);
1530 _res = Py_None;
1531 return _res;
1534 static PyObject *Menu_GetNewMBar(_self, _args)
1535 PyObject *_self;
1536 PyObject *_args;
1538 PyObject *_res = NULL;
1539 Handle _rv;
1540 short menuBarID;
1541 if (!PyArg_ParseTuple(_args, "h",
1542 &menuBarID))
1543 return NULL;
1544 _rv = GetNewMBar(menuBarID);
1545 _res = Py_BuildValue("O&",
1546 ResObj_New, _rv);
1547 return _res;
1550 static PyObject *Menu_GetMenuBar(_self, _args)
1551 PyObject *_self;
1552 PyObject *_args;
1554 PyObject *_res = NULL;
1555 Handle _rv;
1556 if (!PyArg_ParseTuple(_args, ""))
1557 return NULL;
1558 _rv = GetMenuBar();
1559 _res = Py_BuildValue("O&",
1560 ResObj_New, _rv);
1561 return _res;
1564 static PyObject *Menu_SetMenuBar(_self, _args)
1565 PyObject *_self;
1566 PyObject *_args;
1568 PyObject *_res = NULL;
1569 Handle menuList;
1570 if (!PyArg_ParseTuple(_args, "O&",
1571 ResObj_Convert, &menuList))
1572 return NULL;
1573 SetMenuBar(menuList);
1574 Py_INCREF(Py_None);
1575 _res = Py_None;
1576 return _res;
1579 static PyObject *Menu_GetMenuHandle(_self, _args)
1580 PyObject *_self;
1581 PyObject *_args;
1583 PyObject *_res = NULL;
1584 MenuHandle _rv;
1585 short menuID;
1586 if (!PyArg_ParseTuple(_args, "h",
1587 &menuID))
1588 return NULL;
1589 _rv = GetMenuHandle(menuID);
1590 _res = Py_BuildValue("O&",
1591 MenuObj_New, _rv);
1592 return _res;
1595 static PyObject *Menu_MacDeleteMenu(_self, _args)
1596 PyObject *_self;
1597 PyObject *_args;
1599 PyObject *_res = NULL;
1600 short menuID;
1601 if (!PyArg_ParseTuple(_args, "h",
1602 &menuID))
1603 return NULL;
1604 MacDeleteMenu(menuID);
1605 Py_INCREF(Py_None);
1606 _res = Py_None;
1607 return _res;
1610 static PyObject *Menu_ClearMenuBar(_self, _args)
1611 PyObject *_self;
1612 PyObject *_args;
1614 PyObject *_res = NULL;
1615 if (!PyArg_ParseTuple(_args, ""))
1616 return NULL;
1617 ClearMenuBar();
1618 Py_INCREF(Py_None);
1619 _res = Py_None;
1620 return _res;
1623 #if !TARGET_API_MAC_CARBON
1625 static PyObject *Menu_SetMenuFlash(_self, _args)
1626 PyObject *_self;
1627 PyObject *_args;
1629 PyObject *_res = NULL;
1630 short count;
1631 if (!PyArg_ParseTuple(_args, "h",
1632 &count))
1633 return NULL;
1634 SetMenuFlash(count);
1635 Py_INCREF(Py_None);
1636 _res = Py_None;
1637 return _res;
1639 #endif
1641 static PyObject *Menu_FlashMenuBar(_self, _args)
1642 PyObject *_self;
1643 PyObject *_args;
1645 PyObject *_res = NULL;
1646 short menuID;
1647 if (!PyArg_ParseTuple(_args, "h",
1648 &menuID))
1649 return NULL;
1650 FlashMenuBar(menuID);
1651 Py_INCREF(Py_None);
1652 _res = Py_None;
1653 return _res;
1656 #if !TARGET_API_MAC_CARBON
1658 static PyObject *Menu_SystemEdit(_self, _args)
1659 PyObject *_self;
1660 PyObject *_args;
1662 PyObject *_res = NULL;
1663 Boolean _rv;
1664 short editCmd;
1665 if (!PyArg_ParseTuple(_args, "h",
1666 &editCmd))
1667 return NULL;
1668 _rv = SystemEdit(editCmd);
1669 _res = Py_BuildValue("b",
1670 _rv);
1671 return _res;
1673 #endif
1675 #if !TARGET_API_MAC_CARBON
1677 static PyObject *Menu_SystemMenu(_self, _args)
1678 PyObject *_self;
1679 PyObject *_args;
1681 PyObject *_res = NULL;
1682 long menuResult;
1683 if (!PyArg_ParseTuple(_args, "l",
1684 &menuResult))
1685 return NULL;
1686 SystemMenu(menuResult);
1687 Py_INCREF(Py_None);
1688 _res = Py_None;
1689 return _res;
1691 #endif
1693 static PyObject *Menu_IsMenuBarVisible(_self, _args)
1694 PyObject *_self;
1695 PyObject *_args;
1697 PyObject *_res = NULL;
1698 Boolean _rv;
1699 if (!PyArg_ParseTuple(_args, ""))
1700 return NULL;
1701 _rv = IsMenuBarVisible();
1702 _res = Py_BuildValue("b",
1703 _rv);
1704 return _res;
1707 static PyObject *Menu_ShowMenuBar(_self, _args)
1708 PyObject *_self;
1709 PyObject *_args;
1711 PyObject *_res = NULL;
1712 if (!PyArg_ParseTuple(_args, ""))
1713 return NULL;
1714 ShowMenuBar();
1715 Py_INCREF(Py_None);
1716 _res = Py_None;
1717 return _res;
1720 static PyObject *Menu_HideMenuBar(_self, _args)
1721 PyObject *_self;
1722 PyObject *_args;
1724 PyObject *_res = NULL;
1725 if (!PyArg_ParseTuple(_args, ""))
1726 return NULL;
1727 HideMenuBar();
1728 Py_INCREF(Py_None);
1729 _res = Py_None;
1730 return _res;
1733 static PyObject *Menu_DeleteMCEntries(_self, _args)
1734 PyObject *_self;
1735 PyObject *_args;
1737 PyObject *_res = NULL;
1738 short menuID;
1739 short menuItem;
1740 if (!PyArg_ParseTuple(_args, "hh",
1741 &menuID,
1742 &menuItem))
1743 return NULL;
1744 DeleteMCEntries(menuID,
1745 menuItem);
1746 Py_INCREF(Py_None);
1747 _res = Py_None;
1748 return _res;
1751 static PyObject *Menu_InitContextualMenus(_self, _args)
1752 PyObject *_self;
1753 PyObject *_args;
1755 PyObject *_res = NULL;
1756 OSStatus _err;
1757 if (!PyArg_ParseTuple(_args, ""))
1758 return NULL;
1759 _err = InitContextualMenus();
1760 if (_err != noErr) return PyMac_Error(_err);
1761 Py_INCREF(Py_None);
1762 _res = Py_None;
1763 return _res;
1766 static PyObject *Menu_IsShowContextualMenuClick(_self, _args)
1767 PyObject *_self;
1768 PyObject *_args;
1770 PyObject *_res = NULL;
1771 Boolean _rv;
1772 EventRecord inEvent;
1773 if (!PyArg_ParseTuple(_args, "O&",
1774 PyMac_GetEventRecord, &inEvent))
1775 return NULL;
1776 _rv = IsShowContextualMenuClick(&inEvent);
1777 _res = Py_BuildValue("b",
1778 _rv);
1779 return _res;
1782 #if !TARGET_API_MAC_CARBON
1784 static PyObject *Menu_OpenDeskAcc(_self, _args)
1785 PyObject *_self;
1786 PyObject *_args;
1788 PyObject *_res = NULL;
1789 Str255 name;
1790 if (!PyArg_ParseTuple(_args, "O&",
1791 PyMac_GetStr255, name))
1792 return NULL;
1793 OpenDeskAcc(name);
1794 Py_INCREF(Py_None);
1795 _res = Py_None;
1796 return _res;
1798 #endif
1800 static PyObject *Menu_as_Menu(_self, _args)
1801 PyObject *_self;
1802 PyObject *_args;
1804 PyObject *_res = NULL;
1805 MenuHandle _rv;
1806 Handle h;
1807 if (!PyArg_ParseTuple(_args, "O&",
1808 ResObj_Convert, &h))
1809 return NULL;
1810 _rv = as_Menu(h);
1811 _res = Py_BuildValue("O&",
1812 MenuObj_New, _rv);
1813 return _res;
1816 static PyObject *Menu_GetMenu(_self, _args)
1817 PyObject *_self;
1818 PyObject *_args;
1820 PyObject *_res = NULL;
1821 MenuHandle _rv;
1822 short resourceID;
1823 if (!PyArg_ParseTuple(_args, "h",
1824 &resourceID))
1825 return NULL;
1826 _rv = GetMenu(resourceID);
1827 _res = Py_BuildValue("O&",
1828 MenuObj_New, _rv);
1829 return _res;
1832 static PyObject *Menu_DeleteMenu(_self, _args)
1833 PyObject *_self;
1834 PyObject *_args;
1836 PyObject *_res = NULL;
1837 short menuID;
1838 if (!PyArg_ParseTuple(_args, "h",
1839 &menuID))
1840 return NULL;
1841 DeleteMenu(menuID);
1842 Py_INCREF(Py_None);
1843 _res = Py_None;
1844 return _res;
1847 static PyObject *Menu_DrawMenuBar(_self, _args)
1848 PyObject *_self;
1849 PyObject *_args;
1851 PyObject *_res = NULL;
1852 if (!PyArg_ParseTuple(_args, ""))
1853 return NULL;
1854 DrawMenuBar();
1855 Py_INCREF(Py_None);
1856 _res = Py_None;
1857 return _res;
1860 static PyMethodDef Menu_methods[] = {
1862 #if !TARGET_API_MAC_CARBON
1863 {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1,
1864 "(short resID) -> None"},
1865 #endif
1867 #if !TARGET_API_MAC_CARBON
1868 {"InitMenus", (PyCFunction)Menu_InitMenus, 1,
1869 "() -> None"},
1870 #endif
1871 {"NewMenu", (PyCFunction)Menu_NewMenu, 1,
1872 "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"},
1873 {"MacGetMenu", (PyCFunction)Menu_MacGetMenu, 1,
1874 "(short resourceID) -> (MenuHandle _rv)"},
1875 {"MenuKey", (PyCFunction)Menu_MenuKey, 1,
1876 "(CharParameter ch) -> (long _rv)"},
1877 {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1,
1878 "(Point startPt) -> (long _rv)"},
1879 {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1,
1880 "() -> (long _rv)"},
1881 {"MenuEvent", (PyCFunction)Menu_MenuEvent, 1,
1882 "(EventRecord inEvent) -> (UInt32 _rv)"},
1883 {"GetMBarHeight", (PyCFunction)Menu_GetMBarHeight, 1,
1884 "() -> (short _rv)"},
1885 {"MacDrawMenuBar", (PyCFunction)Menu_MacDrawMenuBar, 1,
1886 "() -> None"},
1887 {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1,
1888 "() -> None"},
1889 {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1,
1890 "(short menuID) -> None"},
1891 {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1,
1892 "(short menuBarID) -> (Handle _rv)"},
1893 {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1,
1894 "() -> (Handle _rv)"},
1895 {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1,
1896 "(Handle menuList) -> None"},
1897 {"GetMenuHandle", (PyCFunction)Menu_GetMenuHandle, 1,
1898 "(short menuID) -> (MenuHandle _rv)"},
1899 {"MacDeleteMenu", (PyCFunction)Menu_MacDeleteMenu, 1,
1900 "(short menuID) -> None"},
1901 {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1,
1902 "() -> None"},
1904 #if !TARGET_API_MAC_CARBON
1905 {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1,
1906 "(short count) -> None"},
1907 #endif
1908 {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1,
1909 "(short menuID) -> None"},
1911 #if !TARGET_API_MAC_CARBON
1912 {"SystemEdit", (PyCFunction)Menu_SystemEdit, 1,
1913 "(short editCmd) -> (Boolean _rv)"},
1914 #endif
1916 #if !TARGET_API_MAC_CARBON
1917 {"SystemMenu", (PyCFunction)Menu_SystemMenu, 1,
1918 "(long menuResult) -> None"},
1919 #endif
1920 {"IsMenuBarVisible", (PyCFunction)Menu_IsMenuBarVisible, 1,
1921 "() -> (Boolean _rv)"},
1922 {"ShowMenuBar", (PyCFunction)Menu_ShowMenuBar, 1,
1923 "() -> None"},
1924 {"HideMenuBar", (PyCFunction)Menu_HideMenuBar, 1,
1925 "() -> None"},
1926 {"DeleteMCEntries", (PyCFunction)Menu_DeleteMCEntries, 1,
1927 "(short menuID, short menuItem) -> None"},
1928 {"InitContextualMenus", (PyCFunction)Menu_InitContextualMenus, 1,
1929 "() -> None"},
1930 {"IsShowContextualMenuClick", (PyCFunction)Menu_IsShowContextualMenuClick, 1,
1931 "(EventRecord inEvent) -> (Boolean _rv)"},
1933 #if !TARGET_API_MAC_CARBON
1934 {"OpenDeskAcc", (PyCFunction)Menu_OpenDeskAcc, 1,
1935 "(Str255 name) -> None"},
1936 #endif
1937 {"as_Menu", (PyCFunction)Menu_as_Menu, 1,
1938 "(Handle h) -> (MenuHandle _rv)"},
1939 {"GetMenu", (PyCFunction)Menu_GetMenu, 1,
1940 "(short resourceID) -> (MenuHandle _rv)"},
1941 {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1,
1942 "(short menuID) -> None"},
1943 {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1,
1944 "() -> None"},
1945 {NULL, NULL, 0}
1951 void initMenu()
1953 PyObject *m;
1954 PyObject *d;
1959 m = Py_InitModule("Menu", Menu_methods);
1960 d = PyModule_GetDict(m);
1961 Menu_Error = PyMac_GetOSErrException();
1962 if (Menu_Error == NULL ||
1963 PyDict_SetItemString(d, "Error", Menu_Error) != 0)
1964 Py_FatalError("can't initialize Menu.Error");
1965 Menu_Type.ob_type = &PyType_Type;
1966 Py_INCREF(&Menu_Type);
1967 if (PyDict_SetItemString(d, "MenuType", (PyObject *)&Menu_Type) != 0)
1968 Py_FatalError("can't initialize MenuType");
1971 /* ======================== End module Menu ========================= */