2 /* ========================== Module Menu =========================== */
8 #define SystemSevenOrLater 1
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 */
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
{
64 PyObject
*MenuObj_New(itself
)
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
)
77 if (!MenuObj_Check(v
))
79 PyErr_SetString(PyExc_TypeError
, "Menu required");
82 *p_itself
= ((MenuObject
*)v
)->ob_itself
;
86 static void MenuObj_dealloc(self
)
89 /* Cleanup of self->ob_itself goes here */
93 static PyObject
*MenuObj_DisposeMenu(_self
, _args
)
97 PyObject
*_res
= NULL
;
98 if (!PyArg_ParseTuple(_args
, ""))
100 DisposeMenu(_self
->ob_itself
);
106 static PyObject
*MenuObj_AppendMenu(_self
, _args
)
110 PyObject
*_res
= NULL
;
112 if (!PyArg_ParseTuple(_args
, "O&",
113 PyMac_GetStr255
, data
))
115 AppendMenu(_self
->ob_itself
,
122 static PyObject
*MenuObj_AppendResMenu(_self
, _args
)
126 PyObject
*_res
= NULL
;
128 if (!PyArg_ParseTuple(_args
, "O&",
129 PyMac_GetOSType
, &theType
))
131 AppendResMenu(_self
->ob_itself
,
138 static PyObject
*MenuObj_InsertResMenu(_self
, _args
)
142 PyObject
*_res
= NULL
;
145 if (!PyArg_ParseTuple(_args
, "O&h",
146 PyMac_GetOSType
, &theType
,
149 InsertResMenu(_self
->ob_itself
,
157 static PyObject
*MenuObj_InsertMenu(_self
, _args
)
161 PyObject
*_res
= NULL
;
163 if (!PyArg_ParseTuple(_args
, "h",
166 InsertMenu(_self
->ob_itself
,
173 static PyObject
*MenuObj_InsertMenuItem(_self
, _args
)
177 PyObject
*_res
= NULL
;
180 if (!PyArg_ParseTuple(_args
, "O&h",
181 PyMac_GetStr255
, itemString
,
184 InsertMenuItem(_self
->ob_itself
,
192 static PyObject
*MenuObj_DeleteMenuItem(_self
, _args
)
196 PyObject
*_res
= NULL
;
198 if (!PyArg_ParseTuple(_args
, "h",
201 DeleteMenuItem(_self
->ob_itself
,
208 static PyObject
*MenuObj_SetMenuItemText(_self
, _args
)
212 PyObject
*_res
= NULL
;
215 if (!PyArg_ParseTuple(_args
, "hO&",
217 PyMac_GetStr255
, itemString
))
219 SetMenuItemText(_self
->ob_itself
,
227 static PyObject
*MenuObj_GetMenuItemText(_self
, _args
)
231 PyObject
*_res
= NULL
;
234 if (!PyArg_ParseTuple(_args
, "h",
237 GetMenuItemText(_self
->ob_itself
,
240 _res
= Py_BuildValue("O&",
241 PyMac_BuildStr255
, itemString
);
245 static PyObject
*MenuObj_DisableItem(_self
, _args
)
249 PyObject
*_res
= NULL
;
251 if (!PyArg_ParseTuple(_args
, "h",
254 DisableItem(_self
->ob_itself
,
261 static PyObject
*MenuObj_EnableItem(_self
, _args
)
265 PyObject
*_res
= NULL
;
267 if (!PyArg_ParseTuple(_args
, "h",
270 EnableItem(_self
->ob_itself
,
277 static PyObject
*MenuObj_CheckItem(_self
, _args
)
281 PyObject
*_res
= NULL
;
284 if (!PyArg_ParseTuple(_args
, "hb",
288 CheckItem(_self
->ob_itself
,
296 static PyObject
*MenuObj_SetItemMark(_self
, _args
)
300 PyObject
*_res
= NULL
;
303 if (!PyArg_ParseTuple(_args
, "hh",
307 SetItemMark(_self
->ob_itself
,
315 static PyObject
*MenuObj_GetItemMark(_self
, _args
)
319 PyObject
*_res
= NULL
;
322 if (!PyArg_ParseTuple(_args
, "h",
325 GetItemMark(_self
->ob_itself
,
328 _res
= Py_BuildValue("h",
333 static PyObject
*MenuObj_SetItemIcon(_self
, _args
)
337 PyObject
*_res
= NULL
;
340 if (!PyArg_ParseTuple(_args
, "hh",
344 SetItemIcon(_self
->ob_itself
,
352 static PyObject
*MenuObj_GetItemIcon(_self
, _args
)
356 PyObject
*_res
= NULL
;
359 if (!PyArg_ParseTuple(_args
, "h",
362 GetItemIcon(_self
->ob_itself
,
365 _res
= Py_BuildValue("h",
370 static PyObject
*MenuObj_SetItemStyle(_self
, _args
)
374 PyObject
*_res
= NULL
;
377 if (!PyArg_ParseTuple(_args
, "hh",
381 SetItemStyle(_self
->ob_itself
,
389 static PyObject
*MenuObj_GetItemStyle(_self
, _args
)
393 PyObject
*_res
= NULL
;
396 if (!PyArg_ParseTuple(_args
, "h",
399 GetItemStyle(_self
->ob_itself
,
402 _res
= Py_BuildValue("b",
407 static PyObject
*MenuObj_CalcMenuSize(_self
, _args
)
411 PyObject
*_res
= NULL
;
412 if (!PyArg_ParseTuple(_args
, ""))
414 CalcMenuSize(_self
->ob_itself
);
420 static PyObject
*MenuObj_CountMItems(_self
, _args
)
424 PyObject
*_res
= NULL
;
426 if (!PyArg_ParseTuple(_args
, ""))
428 _rv
= CountMItems(_self
->ob_itself
);
429 _res
= Py_BuildValue("h",
434 static PyObject
*MenuObj_GetItemCmd(_self
, _args
)
438 PyObject
*_res
= NULL
;
441 if (!PyArg_ParseTuple(_args
, "h",
444 GetItemCmd(_self
->ob_itself
,
447 _res
= Py_BuildValue("h",
452 static PyObject
*MenuObj_SetItemCmd(_self
, _args
)
456 PyObject
*_res
= NULL
;
459 if (!PyArg_ParseTuple(_args
, "hh",
463 SetItemCmd(_self
->ob_itself
,
471 static PyObject
*MenuObj_PopUpMenuSelect(_self
, _args
)
475 PyObject
*_res
= NULL
;
480 if (!PyArg_ParseTuple(_args
, "hhh",
485 _rv
= PopUpMenuSelect(_self
->ob_itself
,
489 _res
= Py_BuildValue("l",
494 static PyObject
*MenuObj_InsertFontResMenu(_self
, _args
)
498 PyObject
*_res
= NULL
;
501 if (!PyArg_ParseTuple(_args
, "hh",
505 InsertFontResMenu(_self
->ob_itself
,
513 static PyObject
*MenuObj_InsertIntlResMenu(_self
, _args
)
517 PyObject
*_res
= NULL
;
521 if (!PyArg_ParseTuple(_args
, "O&hh",
522 PyMac_GetOSType
, &theType
,
526 InsertIntlResMenu(_self
->ob_itself
,
535 static PyObject
*MenuObj_as_Resource(_self
, _args
)
539 PyObject
*_res
= NULL
;
541 return ResObj_New((Handle
)_self
->ob_itself
);
545 static PyMethodDef MenuObj_methods
[] = {
546 {"DisposeMenu", (PyCFunction
)MenuObj_DisposeMenu
, 1,
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,
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"},
601 PyMethodChain MenuObj_chain
= { MenuObj_methods
, NULL
};
603 static PyObject
*MenuObj_getattr(self
, 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
)
616 sizeof(MenuObject
), /*tp_basicsize*/
619 (destructor
) MenuObj_dealloc
, /*tp_dealloc*/
621 (getattrfunc
) MenuObj_getattr
, /*tp_getattr*/
622 (setattrfunc
) MenuObj_setattr
, /*tp_setattr*/
625 /* ---------------------- End object type Menu ---------------------- */
628 static PyObject
*Menu_GetMBarHeight(_self
, _args
)
632 PyObject
*_res
= NULL
;
634 if (!PyArg_ParseTuple(_args
, ""))
636 _rv
= GetMBarHeight();
637 _res
= Py_BuildValue("h",
642 static PyObject
*Menu_InitMenus(_self
, _args
)
646 PyObject
*_res
= NULL
;
647 if (!PyArg_ParseTuple(_args
, ""))
655 static PyObject
*Menu_NewMenu(_self
, _args
)
659 PyObject
*_res
= NULL
;
663 if (!PyArg_ParseTuple(_args
, "hO&",
665 PyMac_GetStr255
, menuTitle
))
667 _rv
= NewMenu(menuID
,
669 _res
= Py_BuildValue("O&",
674 static PyObject
*Menu_GetMenu(_self
, _args
)
678 PyObject
*_res
= NULL
;
681 if (!PyArg_ParseTuple(_args
, "h",
684 _rv
= GetMenu(resourceID
);
685 _res
= Py_BuildValue("O&",
690 static PyObject
*Menu_DrawMenuBar(_self
, _args
)
694 PyObject
*_res
= NULL
;
695 if (!PyArg_ParseTuple(_args
, ""))
703 static PyObject
*Menu_InvalMenuBar(_self
, _args
)
707 PyObject
*_res
= NULL
;
708 if (!PyArg_ParseTuple(_args
, ""))
716 static PyObject
*Menu_DeleteMenu(_self
, _args
)
720 PyObject
*_res
= NULL
;
722 if (!PyArg_ParseTuple(_args
, "h",
731 static PyObject
*Menu_ClearMenuBar(_self
, _args
)
735 PyObject
*_res
= NULL
;
736 if (!PyArg_ParseTuple(_args
, ""))
744 static PyObject
*Menu_GetNewMBar(_self
, _args
)
748 PyObject
*_res
= NULL
;
751 if (!PyArg_ParseTuple(_args
, "h",
754 _rv
= GetNewMBar(menuBarID
);
755 _res
= Py_BuildValue("O&",
760 static PyObject
*Menu_GetMenuBar(_self
, _args
)
764 PyObject
*_res
= NULL
;
766 if (!PyArg_ParseTuple(_args
, ""))
769 _res
= Py_BuildValue("O&",
774 static PyObject
*Menu_SetMenuBar(_self
, _args
)
778 PyObject
*_res
= NULL
;
780 if (!PyArg_ParseTuple(_args
, "O&",
781 ResObj_Convert
, &menuList
))
783 SetMenuBar(menuList
);
789 static PyObject
*Menu_MenuKey(_self
, _args
)
793 PyObject
*_res
= NULL
;
796 if (!PyArg_ParseTuple(_args
, "h",
800 _res
= Py_BuildValue("l",
805 static PyObject
*Menu_HiliteMenu(_self
, _args
)
809 PyObject
*_res
= NULL
;
811 if (!PyArg_ParseTuple(_args
, "h",
820 static PyObject
*Menu_GetMenuHandle(_self
, _args
)
824 PyObject
*_res
= NULL
;
827 if (!PyArg_ParseTuple(_args
, "h",
830 _rv
= GetMenuHandle(menuID
);
831 _res
= Py_BuildValue("O&",
836 static PyObject
*Menu_FlashMenuBar(_self
, _args
)
840 PyObject
*_res
= NULL
;
842 if (!PyArg_ParseTuple(_args
, "h",
845 FlashMenuBar(menuID
);
851 static PyObject
*Menu_SetMenuFlash(_self
, _args
)
855 PyObject
*_res
= NULL
;
857 if (!PyArg_ParseTuple(_args
, "h",
866 static PyObject
*Menu_MenuSelect(_self
, _args
)
870 PyObject
*_res
= NULL
;
873 if (!PyArg_ParseTuple(_args
, "O&",
874 PyMac_GetPoint
, &startPt
))
876 _rv
= MenuSelect(startPt
);
877 _res
= Py_BuildValue("l",
882 static PyObject
*Menu_InitProcMenu(_self
, _args
)
886 PyObject
*_res
= NULL
;
888 if (!PyArg_ParseTuple(_args
, "h",
897 static PyObject
*Menu_MenuChoice(_self
, _args
)
901 PyObject
*_res
= NULL
;
903 if (!PyArg_ParseTuple(_args
, ""))
906 _res
= Py_BuildValue("l",
911 static PyObject
*Menu_DeleteMCEntries(_self
, _args
)
915 PyObject
*_res
= NULL
;
918 if (!PyArg_ParseTuple(_args
, "hh",
922 DeleteMCEntries(menuID
,
929 static PyObject
*Menu_SystemEdit(_self
, _args
)
933 PyObject
*_res
= NULL
;
936 if (!PyArg_ParseTuple(_args
, "h",
939 _rv
= SystemEdit(editCmd
);
940 _res
= Py_BuildValue("b",
945 static PyObject
*Menu_SystemMenu(_self
, _args
)
949 PyObject
*_res
= NULL
;
951 if (!PyArg_ParseTuple(_args
, "l",
954 SystemMenu(menuResult
);
960 static PyObject
*Menu_OpenDeskAcc(_self
, _args
)
964 PyObject
*_res
= NULL
;
966 if (!PyArg_ParseTuple(_args
, "O&",
967 PyMac_GetStr255
, name
))
975 static PyMethodDef Menu_methods
[] = {
976 {"GetMBarHeight", (PyCFunction
)Menu_GetMBarHeight
, 1,
977 "() -> (short _rv)"},
978 {"InitMenus", (PyCFunction
)Menu_InitMenus
, 1,
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,
986 {"InvalMenuBar", (PyCFunction
)Menu_InvalMenuBar
, 1,
988 {"DeleteMenu", (PyCFunction
)Menu_DeleteMenu
, 1,
989 "(short menuID) -> None"},
990 {"ClearMenuBar", (PyCFunction
)Menu_ClearMenuBar
, 1,
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"},
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 ========================= */