Another batch of updates...
[python/dscho.git] / Mac / Modules / menu / Menumodule.c
blob07e1b8803ea433bdba985c92338c115a13af584c
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 <Desk.h> /* Defines OpenDeskAcc in old headers */
47 #include <Menus.h>
49 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
51 static PyObject *Menu_Error;
53 /* ------------------------ Object type Menu ------------------------ */
55 PyTypeObject Menu_Type;
57 #define MenuObj_Check(x) ((x)->ob_type == &Menu_Type)
59 typedef struct MenuObject {
60 PyObject_HEAD
61 MenuHandle ob_itself;
62 } MenuObject;
64 PyObject *MenuObj_New(itself)
65 MenuHandle itself;
67 MenuObject *it;
68 it = PyObject_NEW(MenuObject, &Menu_Type);
69 if (it == NULL) return NULL;
70 it->ob_itself = itself;
71 return (PyObject *)it;
73 MenuObj_Convert(v, p_itself)
74 PyObject *v;
75 MenuHandle *p_itself;
77 if (!MenuObj_Check(v))
79 PyErr_SetString(PyExc_TypeError, "Menu required");
80 return 0;
82 *p_itself = ((MenuObject *)v)->ob_itself;
83 return 1;
86 static void MenuObj_dealloc(self)
87 MenuObject *self;
89 /* Cleanup of self->ob_itself goes here */
90 PyMem_DEL(self);
93 static PyObject *MenuObj_DisposeMenu(_self, _args)
94 MenuObject *_self;
95 PyObject *_args;
97 PyObject *_res = NULL;
98 if (!PyArg_ParseTuple(_args, ""))
99 return NULL;
100 DisposeMenu(_self->ob_itself);
101 Py_INCREF(Py_None);
102 _res = Py_None;
103 return _res;
106 static PyObject *MenuObj_AppendMenu(_self, _args)
107 MenuObject *_self;
108 PyObject *_args;
110 PyObject *_res = NULL;
111 Str255 data;
112 if (!PyArg_ParseTuple(_args, "O&",
113 PyMac_GetStr255, data))
114 return NULL;
115 AppendMenu(_self->ob_itself,
116 data);
117 Py_INCREF(Py_None);
118 _res = Py_None;
119 return _res;
122 static PyObject *MenuObj_AppendResMenu(_self, _args)
123 MenuObject *_self;
124 PyObject *_args;
126 PyObject *_res = NULL;
127 ResType theType;
128 if (!PyArg_ParseTuple(_args, "O&",
129 PyMac_GetOSType, &theType))
130 return NULL;
131 AppendResMenu(_self->ob_itself,
132 theType);
133 Py_INCREF(Py_None);
134 _res = Py_None;
135 return _res;
138 static PyObject *MenuObj_InsertResMenu(_self, _args)
139 MenuObject *_self;
140 PyObject *_args;
142 PyObject *_res = NULL;
143 ResType theType;
144 short afterItem;
145 if (!PyArg_ParseTuple(_args, "O&h",
146 PyMac_GetOSType, &theType,
147 &afterItem))
148 return NULL;
149 InsertResMenu(_self->ob_itself,
150 theType,
151 afterItem);
152 Py_INCREF(Py_None);
153 _res = Py_None;
154 return _res;
157 static PyObject *MenuObj_InsertMenu(_self, _args)
158 MenuObject *_self;
159 PyObject *_args;
161 PyObject *_res = NULL;
162 short beforeID;
163 if (!PyArg_ParseTuple(_args, "h",
164 &beforeID))
165 return NULL;
166 InsertMenu(_self->ob_itself,
167 beforeID);
168 Py_INCREF(Py_None);
169 _res = Py_None;
170 return _res;
173 static PyObject *MenuObj_InsertMenuItem(_self, _args)
174 MenuObject *_self;
175 PyObject *_args;
177 PyObject *_res = NULL;
178 Str255 itemString;
179 short afterItem;
180 if (!PyArg_ParseTuple(_args, "O&h",
181 PyMac_GetStr255, itemString,
182 &afterItem))
183 return NULL;
184 InsertMenuItem(_self->ob_itself,
185 itemString,
186 afterItem);
187 Py_INCREF(Py_None);
188 _res = Py_None;
189 return _res;
192 static PyObject *MenuObj_DeleteMenuItem(_self, _args)
193 MenuObject *_self;
194 PyObject *_args;
196 PyObject *_res = NULL;
197 short item;
198 if (!PyArg_ParseTuple(_args, "h",
199 &item))
200 return NULL;
201 DeleteMenuItem(_self->ob_itself,
202 item);
203 Py_INCREF(Py_None);
204 _res = Py_None;
205 return _res;
208 static PyObject *MenuObj_SetMenuItemText(_self, _args)
209 MenuObject *_self;
210 PyObject *_args;
212 PyObject *_res = NULL;
213 short item;
214 Str255 itemString;
215 if (!PyArg_ParseTuple(_args, "hO&",
216 &item,
217 PyMac_GetStr255, itemString))
218 return NULL;
219 SetMenuItemText(_self->ob_itself,
220 item,
221 itemString);
222 Py_INCREF(Py_None);
223 _res = Py_None;
224 return _res;
227 static PyObject *MenuObj_GetMenuItemText(_self, _args)
228 MenuObject *_self;
229 PyObject *_args;
231 PyObject *_res = NULL;
232 short item;
233 Str255 itemString;
234 if (!PyArg_ParseTuple(_args, "h",
235 &item))
236 return NULL;
237 GetMenuItemText(_self->ob_itself,
238 item,
239 itemString);
240 _res = Py_BuildValue("O&",
241 PyMac_BuildStr255, itemString);
242 return _res;
245 static PyObject *MenuObj_DisableItem(_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 DisableItem(_self->ob_itself,
255 item);
256 Py_INCREF(Py_None);
257 _res = Py_None;
258 return _res;
261 static PyObject *MenuObj_EnableItem(_self, _args)
262 MenuObject *_self;
263 PyObject *_args;
265 PyObject *_res = NULL;
266 short item;
267 if (!PyArg_ParseTuple(_args, "h",
268 &item))
269 return NULL;
270 EnableItem(_self->ob_itself,
271 item);
272 Py_INCREF(Py_None);
273 _res = Py_None;
274 return _res;
277 static PyObject *MenuObj_CheckItem(_self, _args)
278 MenuObject *_self;
279 PyObject *_args;
281 PyObject *_res = NULL;
282 short item;
283 Boolean checked;
284 if (!PyArg_ParseTuple(_args, "hb",
285 &item,
286 &checked))
287 return NULL;
288 CheckItem(_self->ob_itself,
289 item,
290 checked);
291 Py_INCREF(Py_None);
292 _res = Py_None;
293 return _res;
296 static PyObject *MenuObj_SetItemMark(_self, _args)
297 MenuObject *_self;
298 PyObject *_args;
300 PyObject *_res = NULL;
301 short item;
302 short markChar;
303 if (!PyArg_ParseTuple(_args, "hh",
304 &item,
305 &markChar))
306 return NULL;
307 SetItemMark(_self->ob_itself,
308 item,
309 markChar);
310 Py_INCREF(Py_None);
311 _res = Py_None;
312 return _res;
315 static PyObject *MenuObj_GetItemMark(_self, _args)
316 MenuObject *_self;
317 PyObject *_args;
319 PyObject *_res = NULL;
320 short item;
321 short markChar;
322 if (!PyArg_ParseTuple(_args, "h",
323 &item))
324 return NULL;
325 GetItemMark(_self->ob_itself,
326 item,
327 &markChar);
328 _res = Py_BuildValue("h",
329 markChar);
330 return _res;
333 static PyObject *MenuObj_SetItemIcon(_self, _args)
334 MenuObject *_self;
335 PyObject *_args;
337 PyObject *_res = NULL;
338 short item;
339 short iconIndex;
340 if (!PyArg_ParseTuple(_args, "hh",
341 &item,
342 &iconIndex))
343 return NULL;
344 SetItemIcon(_self->ob_itself,
345 item,
346 iconIndex);
347 Py_INCREF(Py_None);
348 _res = Py_None;
349 return _res;
352 static PyObject *MenuObj_GetItemIcon(_self, _args)
353 MenuObject *_self;
354 PyObject *_args;
356 PyObject *_res = NULL;
357 short item;
358 short iconIndex;
359 if (!PyArg_ParseTuple(_args, "h",
360 &item))
361 return NULL;
362 GetItemIcon(_self->ob_itself,
363 item,
364 &iconIndex);
365 _res = Py_BuildValue("h",
366 iconIndex);
367 return _res;
370 static PyObject *MenuObj_SetItemStyle(_self, _args)
371 MenuObject *_self;
372 PyObject *_args;
374 PyObject *_res = NULL;
375 short item;
376 short chStyle;
377 if (!PyArg_ParseTuple(_args, "hh",
378 &item,
379 &chStyle))
380 return NULL;
381 SetItemStyle(_self->ob_itself,
382 item,
383 chStyle);
384 Py_INCREF(Py_None);
385 _res = Py_None;
386 return _res;
389 static PyObject *MenuObj_GetItemStyle(_self, _args)
390 MenuObject *_self;
391 PyObject *_args;
393 PyObject *_res = NULL;
394 short item;
395 Style chStyle;
396 if (!PyArg_ParseTuple(_args, "h",
397 &item))
398 return NULL;
399 GetItemStyle(_self->ob_itself,
400 item,
401 &chStyle);
402 _res = Py_BuildValue("b",
403 chStyle);
404 return _res;
407 static PyObject *MenuObj_CalcMenuSize(_self, _args)
408 MenuObject *_self;
409 PyObject *_args;
411 PyObject *_res = NULL;
412 if (!PyArg_ParseTuple(_args, ""))
413 return NULL;
414 CalcMenuSize(_self->ob_itself);
415 Py_INCREF(Py_None);
416 _res = Py_None;
417 return _res;
420 static PyObject *MenuObj_CountMItems(_self, _args)
421 MenuObject *_self;
422 PyObject *_args;
424 PyObject *_res = NULL;
425 short _rv;
426 if (!PyArg_ParseTuple(_args, ""))
427 return NULL;
428 _rv = CountMItems(_self->ob_itself);
429 _res = Py_BuildValue("h",
430 _rv);
431 return _res;
434 static PyObject *MenuObj_GetItemCmd(_self, _args)
435 MenuObject *_self;
436 PyObject *_args;
438 PyObject *_res = NULL;
439 short item;
440 short cmdChar;
441 if (!PyArg_ParseTuple(_args, "h",
442 &item))
443 return NULL;
444 GetItemCmd(_self->ob_itself,
445 item,
446 &cmdChar);
447 _res = Py_BuildValue("h",
448 cmdChar);
449 return _res;
452 static PyObject *MenuObj_SetItemCmd(_self, _args)
453 MenuObject *_self;
454 PyObject *_args;
456 PyObject *_res = NULL;
457 short item;
458 short cmdChar;
459 if (!PyArg_ParseTuple(_args, "hh",
460 &item,
461 &cmdChar))
462 return NULL;
463 SetItemCmd(_self->ob_itself,
464 item,
465 cmdChar);
466 Py_INCREF(Py_None);
467 _res = Py_None;
468 return _res;
471 static PyObject *MenuObj_PopUpMenuSelect(_self, _args)
472 MenuObject *_self;
473 PyObject *_args;
475 PyObject *_res = NULL;
476 long _rv;
477 short top;
478 short left;
479 short popUpItem;
480 if (!PyArg_ParseTuple(_args, "hhh",
481 &top,
482 &left,
483 &popUpItem))
484 return NULL;
485 _rv = PopUpMenuSelect(_self->ob_itself,
486 top,
487 left,
488 popUpItem);
489 _res = Py_BuildValue("l",
490 _rv);
491 return _res;
494 static PyObject *MenuObj_InsertFontResMenu(_self, _args)
495 MenuObject *_self;
496 PyObject *_args;
498 PyObject *_res = NULL;
499 short afterItem;
500 short scriptFilter;
501 if (!PyArg_ParseTuple(_args, "hh",
502 &afterItem,
503 &scriptFilter))
504 return NULL;
505 InsertFontResMenu(_self->ob_itself,
506 afterItem,
507 scriptFilter);
508 Py_INCREF(Py_None);
509 _res = Py_None;
510 return _res;
513 static PyObject *MenuObj_InsertIntlResMenu(_self, _args)
514 MenuObject *_self;
515 PyObject *_args;
517 PyObject *_res = NULL;
518 ResType theType;
519 short afterItem;
520 short scriptFilter;
521 if (!PyArg_ParseTuple(_args, "O&hh",
522 PyMac_GetOSType, &theType,
523 &afterItem,
524 &scriptFilter))
525 return NULL;
526 InsertIntlResMenu(_self->ob_itself,
527 theType,
528 afterItem,
529 scriptFilter);
530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
535 static PyObject *MenuObj_as_Resource(_self, _args)
536 MenuObject *_self;
537 PyObject *_args;
539 PyObject *_res = NULL;
541 return ResObj_New((Handle)_self->ob_itself);
545 static PyMethodDef MenuObj_methods[] = {
546 {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1,
547 "() -> None"},
548 {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1,
549 "(Str255 data) -> None"},
550 {"AppendResMenu", (PyCFunction)MenuObj_AppendResMenu, 1,
551 "(ResType theType) -> None"},
552 {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1,
553 "(ResType theType, short afterItem) -> None"},
554 {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1,
555 "(short beforeID) -> None"},
556 {"InsertMenuItem", (PyCFunction)MenuObj_InsertMenuItem, 1,
557 "(Str255 itemString, short afterItem) -> None"},
558 {"DeleteMenuItem", (PyCFunction)MenuObj_DeleteMenuItem, 1,
559 "(short item) -> None"},
560 {"SetMenuItemText", (PyCFunction)MenuObj_SetMenuItemText, 1,
561 "(short item, Str255 itemString) -> None"},
562 {"GetMenuItemText", (PyCFunction)MenuObj_GetMenuItemText, 1,
563 "(short item) -> (Str255 itemString)"},
564 {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1,
565 "(short item) -> None"},
566 {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1,
567 "(short item) -> None"},
568 {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1,
569 "(short item, Boolean checked) -> None"},
570 {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1,
571 "(short item, short markChar) -> None"},
572 {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1,
573 "(short item) -> (short markChar)"},
574 {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1,
575 "(short item, short iconIndex) -> None"},
576 {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1,
577 "(short item) -> (short iconIndex)"},
578 {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1,
579 "(short item, short chStyle) -> None"},
580 {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1,
581 "(short item) -> (Style chStyle)"},
582 {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1,
583 "() -> None"},
584 {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1,
585 "() -> (short _rv)"},
586 {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1,
587 "(short item) -> (short cmdChar)"},
588 {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1,
589 "(short item, short cmdChar) -> None"},
590 {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1,
591 "(short top, short left, short popUpItem) -> (long _rv)"},
592 {"InsertFontResMenu", (PyCFunction)MenuObj_InsertFontResMenu, 1,
593 "(short afterItem, short scriptFilter) -> None"},
594 {"InsertIntlResMenu", (PyCFunction)MenuObj_InsertIntlResMenu, 1,
595 "(ResType theType, short afterItem, short scriptFilter) -> None"},
596 {"as_Resource", (PyCFunction)MenuObj_as_Resource, 1,
597 "Return this Menu as a Resource"},
598 {NULL, NULL, 0}
601 PyMethodChain MenuObj_chain = { MenuObj_methods, NULL };
603 static PyObject *MenuObj_getattr(self, name)
604 MenuObject *self;
605 char *name;
607 return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name);
610 #define MenuObj_setattr NULL
612 PyTypeObject Menu_Type = {
613 PyObject_HEAD_INIT(&PyType_Type)
614 0, /*ob_size*/
615 "Menu", /*tp_name*/
616 sizeof(MenuObject), /*tp_basicsize*/
617 0, /*tp_itemsize*/
618 /* methods */
619 (destructor) MenuObj_dealloc, /*tp_dealloc*/
620 0, /*tp_print*/
621 (getattrfunc) MenuObj_getattr, /*tp_getattr*/
622 (setattrfunc) MenuObj_setattr, /*tp_setattr*/
625 /* ---------------------- End object type Menu ---------------------- */
628 static PyObject *Menu_GetMBarHeight(_self, _args)
629 PyObject *_self;
630 PyObject *_args;
632 PyObject *_res = NULL;
633 short _rv;
634 if (!PyArg_ParseTuple(_args, ""))
635 return NULL;
636 _rv = GetMBarHeight();
637 _res = Py_BuildValue("h",
638 _rv);
639 return _res;
642 static PyObject *Menu_InitMenus(_self, _args)
643 PyObject *_self;
644 PyObject *_args;
646 PyObject *_res = NULL;
647 if (!PyArg_ParseTuple(_args, ""))
648 return NULL;
649 InitMenus();
650 Py_INCREF(Py_None);
651 _res = Py_None;
652 return _res;
655 static PyObject *Menu_NewMenu(_self, _args)
656 PyObject *_self;
657 PyObject *_args;
659 PyObject *_res = NULL;
660 MenuHandle _rv;
661 short menuID;
662 Str255 menuTitle;
663 if (!PyArg_ParseTuple(_args, "hO&",
664 &menuID,
665 PyMac_GetStr255, menuTitle))
666 return NULL;
667 _rv = NewMenu(menuID,
668 menuTitle);
669 _res = Py_BuildValue("O&",
670 MenuObj_New, _rv);
671 return _res;
674 static PyObject *Menu_GetMenu(_self, _args)
675 PyObject *_self;
676 PyObject *_args;
678 PyObject *_res = NULL;
679 MenuHandle _rv;
680 short resourceID;
681 if (!PyArg_ParseTuple(_args, "h",
682 &resourceID))
683 return NULL;
684 _rv = GetMenu(resourceID);
685 _res = Py_BuildValue("O&",
686 MenuObj_New, _rv);
687 return _res;
690 static PyObject *Menu_DrawMenuBar(_self, _args)
691 PyObject *_self;
692 PyObject *_args;
694 PyObject *_res = NULL;
695 if (!PyArg_ParseTuple(_args, ""))
696 return NULL;
697 DrawMenuBar();
698 Py_INCREF(Py_None);
699 _res = Py_None;
700 return _res;
703 static PyObject *Menu_InvalMenuBar(_self, _args)
704 PyObject *_self;
705 PyObject *_args;
707 PyObject *_res = NULL;
708 if (!PyArg_ParseTuple(_args, ""))
709 return NULL;
710 InvalMenuBar();
711 Py_INCREF(Py_None);
712 _res = Py_None;
713 return _res;
716 static PyObject *Menu_DeleteMenu(_self, _args)
717 PyObject *_self;
718 PyObject *_args;
720 PyObject *_res = NULL;
721 short menuID;
722 if (!PyArg_ParseTuple(_args, "h",
723 &menuID))
724 return NULL;
725 DeleteMenu(menuID);
726 Py_INCREF(Py_None);
727 _res = Py_None;
728 return _res;
731 static PyObject *Menu_ClearMenuBar(_self, _args)
732 PyObject *_self;
733 PyObject *_args;
735 PyObject *_res = NULL;
736 if (!PyArg_ParseTuple(_args, ""))
737 return NULL;
738 ClearMenuBar();
739 Py_INCREF(Py_None);
740 _res = Py_None;
741 return _res;
744 static PyObject *Menu_GetNewMBar(_self, _args)
745 PyObject *_self;
746 PyObject *_args;
748 PyObject *_res = NULL;
749 Handle _rv;
750 short menuBarID;
751 if (!PyArg_ParseTuple(_args, "h",
752 &menuBarID))
753 return NULL;
754 _rv = GetNewMBar(menuBarID);
755 _res = Py_BuildValue("O&",
756 ResObj_New, _rv);
757 return _res;
760 static PyObject *Menu_GetMenuBar(_self, _args)
761 PyObject *_self;
762 PyObject *_args;
764 PyObject *_res = NULL;
765 Handle _rv;
766 if (!PyArg_ParseTuple(_args, ""))
767 return NULL;
768 _rv = GetMenuBar();
769 _res = Py_BuildValue("O&",
770 ResObj_New, _rv);
771 return _res;
774 static PyObject *Menu_SetMenuBar(_self, _args)
775 PyObject *_self;
776 PyObject *_args;
778 PyObject *_res = NULL;
779 Handle menuList;
780 if (!PyArg_ParseTuple(_args, "O&",
781 ResObj_Convert, &menuList))
782 return NULL;
783 SetMenuBar(menuList);
784 Py_INCREF(Py_None);
785 _res = Py_None;
786 return _res;
789 static PyObject *Menu_MenuKey(_self, _args)
790 PyObject *_self;
791 PyObject *_args;
793 PyObject *_res = NULL;
794 long _rv;
795 short ch;
796 if (!PyArg_ParseTuple(_args, "h",
797 &ch))
798 return NULL;
799 _rv = MenuKey(ch);
800 _res = Py_BuildValue("l",
801 _rv);
802 return _res;
805 static PyObject *Menu_HiliteMenu(_self, _args)
806 PyObject *_self;
807 PyObject *_args;
809 PyObject *_res = NULL;
810 short menuID;
811 if (!PyArg_ParseTuple(_args, "h",
812 &menuID))
813 return NULL;
814 HiliteMenu(menuID);
815 Py_INCREF(Py_None);
816 _res = Py_None;
817 return _res;
820 static PyObject *Menu_GetMenuHandle(_self, _args)
821 PyObject *_self;
822 PyObject *_args;
824 PyObject *_res = NULL;
825 MenuHandle _rv;
826 short menuID;
827 if (!PyArg_ParseTuple(_args, "h",
828 &menuID))
829 return NULL;
830 _rv = GetMenuHandle(menuID);
831 _res = Py_BuildValue("O&",
832 MenuObj_New, _rv);
833 return _res;
836 static PyObject *Menu_FlashMenuBar(_self, _args)
837 PyObject *_self;
838 PyObject *_args;
840 PyObject *_res = NULL;
841 short menuID;
842 if (!PyArg_ParseTuple(_args, "h",
843 &menuID))
844 return NULL;
845 FlashMenuBar(menuID);
846 Py_INCREF(Py_None);
847 _res = Py_None;
848 return _res;
851 static PyObject *Menu_SetMenuFlash(_self, _args)
852 PyObject *_self;
853 PyObject *_args;
855 PyObject *_res = NULL;
856 short count;
857 if (!PyArg_ParseTuple(_args, "h",
858 &count))
859 return NULL;
860 SetMenuFlash(count);
861 Py_INCREF(Py_None);
862 _res = Py_None;
863 return _res;
866 static PyObject *Menu_MenuSelect(_self, _args)
867 PyObject *_self;
868 PyObject *_args;
870 PyObject *_res = NULL;
871 long _rv;
872 Point startPt;
873 if (!PyArg_ParseTuple(_args, "O&",
874 PyMac_GetPoint, &startPt))
875 return NULL;
876 _rv = MenuSelect(startPt);
877 _res = Py_BuildValue("l",
878 _rv);
879 return _res;
882 static PyObject *Menu_InitProcMenu(_self, _args)
883 PyObject *_self;
884 PyObject *_args;
886 PyObject *_res = NULL;
887 short resID;
888 if (!PyArg_ParseTuple(_args, "h",
889 &resID))
890 return NULL;
891 InitProcMenu(resID);
892 Py_INCREF(Py_None);
893 _res = Py_None;
894 return _res;
897 static PyObject *Menu_MenuChoice(_self, _args)
898 PyObject *_self;
899 PyObject *_args;
901 PyObject *_res = NULL;
902 long _rv;
903 if (!PyArg_ParseTuple(_args, ""))
904 return NULL;
905 _rv = MenuChoice();
906 _res = Py_BuildValue("l",
907 _rv);
908 return _res;
911 static PyObject *Menu_DeleteMCEntries(_self, _args)
912 PyObject *_self;
913 PyObject *_args;
915 PyObject *_res = NULL;
916 short menuID;
917 short menuItem;
918 if (!PyArg_ParseTuple(_args, "hh",
919 &menuID,
920 &menuItem))
921 return NULL;
922 DeleteMCEntries(menuID,
923 menuItem);
924 Py_INCREF(Py_None);
925 _res = Py_None;
926 return _res;
929 static PyObject *Menu_SystemEdit(_self, _args)
930 PyObject *_self;
931 PyObject *_args;
933 PyObject *_res = NULL;
934 Boolean _rv;
935 short editCmd;
936 if (!PyArg_ParseTuple(_args, "h",
937 &editCmd))
938 return NULL;
939 _rv = SystemEdit(editCmd);
940 _res = Py_BuildValue("b",
941 _rv);
942 return _res;
945 static PyObject *Menu_SystemMenu(_self, _args)
946 PyObject *_self;
947 PyObject *_args;
949 PyObject *_res = NULL;
950 long menuResult;
951 if (!PyArg_ParseTuple(_args, "l",
952 &menuResult))
953 return NULL;
954 SystemMenu(menuResult);
955 Py_INCREF(Py_None);
956 _res = Py_None;
957 return _res;
960 static PyObject *Menu_OpenDeskAcc(_self, _args)
961 PyObject *_self;
962 PyObject *_args;
964 PyObject *_res = NULL;
965 Str255 name;
966 if (!PyArg_ParseTuple(_args, "O&",
967 PyMac_GetStr255, name))
968 return NULL;
969 OpenDeskAcc(name);
970 Py_INCREF(Py_None);
971 _res = Py_None;
972 return _res;
975 static PyMethodDef Menu_methods[] = {
976 {"GetMBarHeight", (PyCFunction)Menu_GetMBarHeight, 1,
977 "() -> (short _rv)"},
978 {"InitMenus", (PyCFunction)Menu_InitMenus, 1,
979 "() -> None"},
980 {"NewMenu", (PyCFunction)Menu_NewMenu, 1,
981 "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"},
982 {"GetMenu", (PyCFunction)Menu_GetMenu, 1,
983 "(short resourceID) -> (MenuHandle _rv)"},
984 {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1,
985 "() -> None"},
986 {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1,
987 "() -> None"},
988 {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1,
989 "(short menuID) -> None"},
990 {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1,
991 "() -> None"},
992 {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1,
993 "(short menuBarID) -> (Handle _rv)"},
994 {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1,
995 "() -> (Handle _rv)"},
996 {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1,
997 "(Handle menuList) -> None"},
998 {"MenuKey", (PyCFunction)Menu_MenuKey, 1,
999 "(short ch) -> (long _rv)"},
1000 {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1,
1001 "(short menuID) -> None"},
1002 {"GetMenuHandle", (PyCFunction)Menu_GetMenuHandle, 1,
1003 "(short menuID) -> (MenuHandle _rv)"},
1004 {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1,
1005 "(short menuID) -> None"},
1006 {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1,
1007 "(short count) -> None"},
1008 {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1,
1009 "(Point startPt) -> (long _rv)"},
1010 {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1,
1011 "(short resID) -> None"},
1012 {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1,
1013 "() -> (long _rv)"},
1014 {"DeleteMCEntries", (PyCFunction)Menu_DeleteMCEntries, 1,
1015 "(short menuID, short menuItem) -> None"},
1016 {"SystemEdit", (PyCFunction)Menu_SystemEdit, 1,
1017 "(short editCmd) -> (Boolean _rv)"},
1018 {"SystemMenu", (PyCFunction)Menu_SystemMenu, 1,
1019 "(long menuResult) -> None"},
1020 {"OpenDeskAcc", (PyCFunction)Menu_OpenDeskAcc, 1,
1021 "(Str255 name) -> None"},
1022 {NULL, NULL, 0}
1028 void initMenu()
1030 PyObject *m;
1031 PyObject *d;
1036 m = Py_InitModule("Menu", Menu_methods);
1037 d = PyModule_GetDict(m);
1038 Menu_Error = PyMac_GetOSErrException();
1039 if (Menu_Error == NULL ||
1040 PyDict_SetItemString(d, "Error", Menu_Error) != 0)
1041 Py_FatalError("can't initialize Menu.Error");
1044 /* ======================== End module Menu ========================= */