blob: 6c855cd4563d81a9829fd00a51b3f56fe743b559 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* ========================== Module Menu =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
Jack Jansend4c26461995-08-17 14:35:56 +000017extern PyObject *ResObj_OptNew(Handle);
Guido van Rossum17448e21995-01-30 11:53:55 +000018extern int ResObj_Convert(PyObject *, Handle *);
19
20extern PyObject *WinObj_New(WindowPtr);
21extern int WinObj_Convert(PyObject *, WindowPtr *);
22
23extern PyObject *DlgObj_New(DialogPtr);
24extern int DlgObj_Convert(PyObject *, DialogPtr *);
25extern PyTypeObject Dialog_Type;
26#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
27
28extern PyObject *MenuObj_New(MenuHandle);
29extern int MenuObj_Convert(PyObject *, MenuHandle *);
30
31extern PyObject *CtlObj_New(ControlHandle);
32extern int CtlObj_Convert(PyObject *, ControlHandle *);
33
34extern PyObject *WinObj_WhichWindow(WindowPtr);
35
Guido van Rossum86c3af71995-03-19 22:42:51 +000036#include <Devices.h> /* Defines OpenDeskAcc in universal headers */
37#include <Desk.h> /* Defines OpenDeskAcc in old headers */
Guido van Rossum17448e21995-01-30 11:53:55 +000038#include <Menus.h>
39
40#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41
42static PyObject *Menu_Error;
43
44/* ------------------------ Object type Menu ------------------------ */
45
46PyTypeObject Menu_Type;
47
48#define MenuObj_Check(x) ((x)->ob_type == &Menu_Type)
49
50typedef struct MenuObject {
51 PyObject_HEAD
52 MenuHandle ob_itself;
53} MenuObject;
54
55PyObject *MenuObj_New(itself)
Guido van Rossum227a4231995-03-10 14:42:57 +000056 MenuHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000057{
58 MenuObject *it;
59 it = PyObject_NEW(MenuObject, &Menu_Type);
60 if (it == NULL) return NULL;
61 it->ob_itself = itself;
62 return (PyObject *)it;
63}
64MenuObj_Convert(v, p_itself)
65 PyObject *v;
66 MenuHandle *p_itself;
67{
68 if (!MenuObj_Check(v))
69 {
70 PyErr_SetString(PyExc_TypeError, "Menu required");
71 return 0;
72 }
73 *p_itself = ((MenuObject *)v)->ob_itself;
74 return 1;
75}
76
77static void MenuObj_dealloc(self)
78 MenuObject *self;
79{
80 /* Cleanup of self->ob_itself goes here */
81 PyMem_DEL(self);
82}
83
84static PyObject *MenuObj_DisposeMenu(_self, _args)
85 MenuObject *_self;
86 PyObject *_args;
87{
88 PyObject *_res = NULL;
89 if (!PyArg_ParseTuple(_args, ""))
90 return NULL;
91 DisposeMenu(_self->ob_itself);
92 Py_INCREF(Py_None);
93 _res = Py_None;
94 return _res;
95}
96
97static PyObject *MenuObj_AppendMenu(_self, _args)
98 MenuObject *_self;
99 PyObject *_args;
100{
101 PyObject *_res = NULL;
102 Str255 data;
103 if (!PyArg_ParseTuple(_args, "O&",
104 PyMac_GetStr255, data))
105 return NULL;
106 AppendMenu(_self->ob_itself,
107 data);
108 Py_INCREF(Py_None);
109 _res = Py_None;
110 return _res;
111}
112
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000113static PyObject *MenuObj_AppendResMenu(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000114 MenuObject *_self;
115 PyObject *_args;
116{
117 PyObject *_res = NULL;
118 ResType theType;
119 if (!PyArg_ParseTuple(_args, "O&",
120 PyMac_GetOSType, &theType))
121 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000122 AppendResMenu(_self->ob_itself,
123 theType);
Guido van Rossum17448e21995-01-30 11:53:55 +0000124 Py_INCREF(Py_None);
125 _res = Py_None;
126 return _res;
127}
128
129static PyObject *MenuObj_InsertResMenu(_self, _args)
130 MenuObject *_self;
131 PyObject *_args;
132{
133 PyObject *_res = NULL;
134 ResType theType;
135 short afterItem;
136 if (!PyArg_ParseTuple(_args, "O&h",
137 PyMac_GetOSType, &theType,
138 &afterItem))
139 return NULL;
140 InsertResMenu(_self->ob_itself,
141 theType,
142 afterItem);
143 Py_INCREF(Py_None);
144 _res = Py_None;
145 return _res;
146}
147
148static PyObject *MenuObj_InsertMenu(_self, _args)
149 MenuObject *_self;
150 PyObject *_args;
151{
152 PyObject *_res = NULL;
153 short beforeID;
154 if (!PyArg_ParseTuple(_args, "h",
155 &beforeID))
156 return NULL;
157 InsertMenu(_self->ob_itself,
158 beforeID);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
162}
163
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000164static PyObject *MenuObj_InsertMenuItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000165 MenuObject *_self;
166 PyObject *_args;
167{
168 PyObject *_res = NULL;
169 Str255 itemString;
170 short afterItem;
171 if (!PyArg_ParseTuple(_args, "O&h",
172 PyMac_GetStr255, itemString,
173 &afterItem))
174 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000175 InsertMenuItem(_self->ob_itself,
176 itemString,
177 afterItem);
Guido van Rossum17448e21995-01-30 11:53:55 +0000178 Py_INCREF(Py_None);
179 _res = Py_None;
180 return _res;
181}
182
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000183static PyObject *MenuObj_DeleteMenuItem(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000184 MenuObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 short item;
189 if (!PyArg_ParseTuple(_args, "h",
190 &item))
191 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000192 DeleteMenuItem(_self->ob_itself,
193 item);
Guido van Rossum17448e21995-01-30 11:53:55 +0000194 Py_INCREF(Py_None);
195 _res = Py_None;
196 return _res;
197}
198
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000199static PyObject *MenuObj_SetMenuItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000200 MenuObject *_self;
201 PyObject *_args;
202{
203 PyObject *_res = NULL;
204 short item;
205 Str255 itemString;
206 if (!PyArg_ParseTuple(_args, "hO&",
207 &item,
208 PyMac_GetStr255, itemString))
209 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000210 SetMenuItemText(_self->ob_itself,
211 item,
212 itemString);
Guido van Rossum17448e21995-01-30 11:53:55 +0000213 Py_INCREF(Py_None);
214 _res = Py_None;
215 return _res;
216}
217
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000218static PyObject *MenuObj_GetMenuItemText(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000219 MenuObject *_self;
220 PyObject *_args;
221{
222 PyObject *_res = NULL;
223 short item;
224 Str255 itemString;
225 if (!PyArg_ParseTuple(_args, "h",
226 &item))
227 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000228 GetMenuItemText(_self->ob_itself,
229 item,
230 itemString);
Guido van Rossum17448e21995-01-30 11:53:55 +0000231 _res = Py_BuildValue("O&",
232 PyMac_BuildStr255, itemString);
233 return _res;
234}
235
236static PyObject *MenuObj_DisableItem(_self, _args)
237 MenuObject *_self;
238 PyObject *_args;
239{
240 PyObject *_res = NULL;
241 short item;
242 if (!PyArg_ParseTuple(_args, "h",
243 &item))
244 return NULL;
245 DisableItem(_self->ob_itself,
246 item);
247 Py_INCREF(Py_None);
248 _res = Py_None;
249 return _res;
250}
251
252static PyObject *MenuObj_EnableItem(_self, _args)
253 MenuObject *_self;
254 PyObject *_args;
255{
256 PyObject *_res = NULL;
257 short item;
258 if (!PyArg_ParseTuple(_args, "h",
259 &item))
260 return NULL;
261 EnableItem(_self->ob_itself,
262 item);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
268static PyObject *MenuObj_CheckItem(_self, _args)
269 MenuObject *_self;
270 PyObject *_args;
271{
272 PyObject *_res = NULL;
273 short item;
274 Boolean checked;
275 if (!PyArg_ParseTuple(_args, "hb",
276 &item,
277 &checked))
278 return NULL;
279 CheckItem(_self->ob_itself,
280 item,
281 checked);
282 Py_INCREF(Py_None);
283 _res = Py_None;
284 return _res;
285}
286
287static PyObject *MenuObj_SetItemMark(_self, _args)
288 MenuObject *_self;
289 PyObject *_args;
290{
291 PyObject *_res = NULL;
292 short item;
293 short markChar;
294 if (!PyArg_ParseTuple(_args, "hh",
295 &item,
296 &markChar))
297 return NULL;
298 SetItemMark(_self->ob_itself,
299 item,
300 markChar);
301 Py_INCREF(Py_None);
302 _res = Py_None;
303 return _res;
304}
305
306static PyObject *MenuObj_GetItemMark(_self, _args)
307 MenuObject *_self;
308 PyObject *_args;
309{
310 PyObject *_res = NULL;
311 short item;
312 short markChar;
313 if (!PyArg_ParseTuple(_args, "h",
314 &item))
315 return NULL;
316 GetItemMark(_self->ob_itself,
317 item,
318 &markChar);
319 _res = Py_BuildValue("h",
320 markChar);
321 return _res;
322}
323
324static PyObject *MenuObj_SetItemIcon(_self, _args)
325 MenuObject *_self;
326 PyObject *_args;
327{
328 PyObject *_res = NULL;
329 short item;
330 short iconIndex;
331 if (!PyArg_ParseTuple(_args, "hh",
332 &item,
333 &iconIndex))
334 return NULL;
335 SetItemIcon(_self->ob_itself,
336 item,
337 iconIndex);
338 Py_INCREF(Py_None);
339 _res = Py_None;
340 return _res;
341}
342
343static PyObject *MenuObj_GetItemIcon(_self, _args)
344 MenuObject *_self;
345 PyObject *_args;
346{
347 PyObject *_res = NULL;
348 short item;
349 short iconIndex;
350 if (!PyArg_ParseTuple(_args, "h",
351 &item))
352 return NULL;
353 GetItemIcon(_self->ob_itself,
354 item,
355 &iconIndex);
356 _res = Py_BuildValue("h",
357 iconIndex);
358 return _res;
359}
360
361static PyObject *MenuObj_SetItemStyle(_self, _args)
362 MenuObject *_self;
363 PyObject *_args;
364{
365 PyObject *_res = NULL;
366 short item;
367 short chStyle;
368 if (!PyArg_ParseTuple(_args, "hh",
369 &item,
370 &chStyle))
371 return NULL;
372 SetItemStyle(_self->ob_itself,
373 item,
374 chStyle);
375 Py_INCREF(Py_None);
376 _res = Py_None;
377 return _res;
378}
379
380static PyObject *MenuObj_GetItemStyle(_self, _args)
381 MenuObject *_self;
382 PyObject *_args;
383{
384 PyObject *_res = NULL;
385 short item;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000386 Style chStyle;
Guido van Rossum17448e21995-01-30 11:53:55 +0000387 if (!PyArg_ParseTuple(_args, "h",
388 &item))
389 return NULL;
390 GetItemStyle(_self->ob_itself,
391 item,
392 &chStyle);
393 _res = Py_BuildValue("b",
394 chStyle);
395 return _res;
396}
397
398static PyObject *MenuObj_CalcMenuSize(_self, _args)
399 MenuObject *_self;
400 PyObject *_args;
401{
402 PyObject *_res = NULL;
403 if (!PyArg_ParseTuple(_args, ""))
404 return NULL;
405 CalcMenuSize(_self->ob_itself);
406 Py_INCREF(Py_None);
407 _res = Py_None;
408 return _res;
409}
410
411static PyObject *MenuObj_CountMItems(_self, _args)
412 MenuObject *_self;
413 PyObject *_args;
414{
415 PyObject *_res = NULL;
416 short _rv;
417 if (!PyArg_ParseTuple(_args, ""))
418 return NULL;
419 _rv = CountMItems(_self->ob_itself);
420 _res = Py_BuildValue("h",
421 _rv);
422 return _res;
423}
424
425static PyObject *MenuObj_GetItemCmd(_self, _args)
426 MenuObject *_self;
427 PyObject *_args;
428{
429 PyObject *_res = NULL;
430 short item;
431 short cmdChar;
432 if (!PyArg_ParseTuple(_args, "h",
433 &item))
434 return NULL;
435 GetItemCmd(_self->ob_itself,
436 item,
437 &cmdChar);
438 _res = Py_BuildValue("h",
439 cmdChar);
440 return _res;
441}
442
443static PyObject *MenuObj_SetItemCmd(_self, _args)
444 MenuObject *_self;
445 PyObject *_args;
446{
447 PyObject *_res = NULL;
448 short item;
449 short cmdChar;
450 if (!PyArg_ParseTuple(_args, "hh",
451 &item,
452 &cmdChar))
453 return NULL;
454 SetItemCmd(_self->ob_itself,
455 item,
456 cmdChar);
457 Py_INCREF(Py_None);
458 _res = Py_None;
459 return _res;
460}
461
462static PyObject *MenuObj_PopUpMenuSelect(_self, _args)
463 MenuObject *_self;
464 PyObject *_args;
465{
466 PyObject *_res = NULL;
467 long _rv;
468 short top;
469 short left;
470 short popUpItem;
471 if (!PyArg_ParseTuple(_args, "hhh",
472 &top,
473 &left,
474 &popUpItem))
475 return NULL;
476 _rv = PopUpMenuSelect(_self->ob_itself,
477 top,
478 left,
479 popUpItem);
480 _res = Py_BuildValue("l",
481 _rv);
482 return _res;
483}
484
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000485static PyObject *MenuObj_InsertFontResMenu(_self, _args)
486 MenuObject *_self;
487 PyObject *_args;
488{
489 PyObject *_res = NULL;
490 short afterItem;
491 short scriptFilter;
492 if (!PyArg_ParseTuple(_args, "hh",
493 &afterItem,
494 &scriptFilter))
495 return NULL;
496 InsertFontResMenu(_self->ob_itself,
497 afterItem,
498 scriptFilter);
499 Py_INCREF(Py_None);
500 _res = Py_None;
501 return _res;
502}
503
504static PyObject *MenuObj_InsertIntlResMenu(_self, _args)
505 MenuObject *_self;
506 PyObject *_args;
507{
508 PyObject *_res = NULL;
509 ResType theType;
510 short afterItem;
511 short scriptFilter;
512 if (!PyArg_ParseTuple(_args, "O&hh",
513 PyMac_GetOSType, &theType,
514 &afterItem,
515 &scriptFilter))
516 return NULL;
517 InsertIntlResMenu(_self->ob_itself,
518 theType,
519 afterItem,
520 scriptFilter);
521 Py_INCREF(Py_None);
522 _res = Py_None;
523 return _res;
524}
525
Jack Jansena1772281995-06-18 20:17:27 +0000526static PyObject *MenuObj_as_Resource(_self, _args)
527 MenuObject *_self;
528 PyObject *_args;
529{
530 PyObject *_res = NULL;
531
532 return ResObj_New((Handle)_self->ob_itself);
533
534}
535
Guido van Rossum17448e21995-01-30 11:53:55 +0000536static PyMethodDef MenuObj_methods[] = {
537 {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1,
538 "() -> None"},
539 {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1,
540 "(Str255 data) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000541 {"AppendResMenu", (PyCFunction)MenuObj_AppendResMenu, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000542 "(ResType theType) -> None"},
543 {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1,
544 "(ResType theType, short afterItem) -> None"},
545 {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1,
546 "(short beforeID) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000547 {"InsertMenuItem", (PyCFunction)MenuObj_InsertMenuItem, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000548 "(Str255 itemString, short afterItem) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000549 {"DeleteMenuItem", (PyCFunction)MenuObj_DeleteMenuItem, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 "(short item) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000551 {"SetMenuItemText", (PyCFunction)MenuObj_SetMenuItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000552 "(short item, Str255 itemString) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000553 {"GetMenuItemText", (PyCFunction)MenuObj_GetMenuItemText, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000554 "(short item) -> (Str255 itemString)"},
555 {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1,
556 "(short item) -> None"},
557 {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1,
558 "(short item) -> None"},
559 {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1,
560 "(short item, Boolean checked) -> None"},
561 {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1,
562 "(short item, short markChar) -> None"},
563 {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1,
564 "(short item) -> (short markChar)"},
565 {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1,
566 "(short item, short iconIndex) -> None"},
567 {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1,
568 "(short item) -> (short iconIndex)"},
569 {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1,
570 "(short item, short chStyle) -> None"},
571 {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000572 "(short item) -> (Style chStyle)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000573 {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1,
574 "() -> None"},
575 {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1,
576 "() -> (short _rv)"},
577 {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1,
578 "(short item) -> (short cmdChar)"},
579 {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1,
580 "(short item, short cmdChar) -> None"},
581 {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1,
582 "(short top, short left, short popUpItem) -> (long _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000583 {"InsertFontResMenu", (PyCFunction)MenuObj_InsertFontResMenu, 1,
584 "(short afterItem, short scriptFilter) -> None"},
585 {"InsertIntlResMenu", (PyCFunction)MenuObj_InsertIntlResMenu, 1,
586 "(ResType theType, short afterItem, short scriptFilter) -> None"},
Jack Jansena1772281995-06-18 20:17:27 +0000587 {"as_Resource", (PyCFunction)MenuObj_as_Resource, 1,
588 "Return this Menu as a Resource"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000589 {NULL, NULL, 0}
590};
591
592PyMethodChain MenuObj_chain = { MenuObj_methods, NULL };
593
594static PyObject *MenuObj_getattr(self, name)
595 MenuObject *self;
596 char *name;
597{
598 return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name);
599}
600
601#define MenuObj_setattr NULL
602
603PyTypeObject Menu_Type = {
604 PyObject_HEAD_INIT(&PyType_Type)
605 0, /*ob_size*/
606 "Menu", /*tp_name*/
607 sizeof(MenuObject), /*tp_basicsize*/
608 0, /*tp_itemsize*/
609 /* methods */
610 (destructor) MenuObj_dealloc, /*tp_dealloc*/
611 0, /*tp_print*/
612 (getattrfunc) MenuObj_getattr, /*tp_getattr*/
613 (setattrfunc) MenuObj_setattr, /*tp_setattr*/
614};
615
616/* ---------------------- End object type Menu ---------------------- */
617
618
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000619static PyObject *Menu_GetMBarHeight(_self, _args)
620 PyObject *_self;
621 PyObject *_args;
622{
623 PyObject *_res = NULL;
624 short _rv;
625 if (!PyArg_ParseTuple(_args, ""))
626 return NULL;
627 _rv = GetMBarHeight();
628 _res = Py_BuildValue("h",
629 _rv);
630 return _res;
631}
632
Guido van Rossum17448e21995-01-30 11:53:55 +0000633static PyObject *Menu_InitMenus(_self, _args)
634 PyObject *_self;
635 PyObject *_args;
636{
637 PyObject *_res = NULL;
638 if (!PyArg_ParseTuple(_args, ""))
639 return NULL;
640 InitMenus();
641 Py_INCREF(Py_None);
642 _res = Py_None;
643 return _res;
644}
645
646static PyObject *Menu_NewMenu(_self, _args)
647 PyObject *_self;
648 PyObject *_args;
649{
650 PyObject *_res = NULL;
651 MenuHandle _rv;
652 short menuID;
653 Str255 menuTitle;
654 if (!PyArg_ParseTuple(_args, "hO&",
655 &menuID,
656 PyMac_GetStr255, menuTitle))
657 return NULL;
658 _rv = NewMenu(menuID,
659 menuTitle);
660 _res = Py_BuildValue("O&",
661 MenuObj_New, _rv);
662 return _res;
663}
664
665static PyObject *Menu_GetMenu(_self, _args)
666 PyObject *_self;
667 PyObject *_args;
668{
669 PyObject *_res = NULL;
670 MenuHandle _rv;
671 short resourceID;
672 if (!PyArg_ParseTuple(_args, "h",
673 &resourceID))
674 return NULL;
675 _rv = GetMenu(resourceID);
676 _res = Py_BuildValue("O&",
677 MenuObj_New, _rv);
678 return _res;
679}
680
681static PyObject *Menu_DrawMenuBar(_self, _args)
682 PyObject *_self;
683 PyObject *_args;
684{
685 PyObject *_res = NULL;
686 if (!PyArg_ParseTuple(_args, ""))
687 return NULL;
688 DrawMenuBar();
689 Py_INCREF(Py_None);
690 _res = Py_None;
691 return _res;
692}
693
694static PyObject *Menu_InvalMenuBar(_self, _args)
695 PyObject *_self;
696 PyObject *_args;
697{
698 PyObject *_res = NULL;
699 if (!PyArg_ParseTuple(_args, ""))
700 return NULL;
701 InvalMenuBar();
702 Py_INCREF(Py_None);
703 _res = Py_None;
704 return _res;
705}
706
707static PyObject *Menu_DeleteMenu(_self, _args)
708 PyObject *_self;
709 PyObject *_args;
710{
711 PyObject *_res = NULL;
712 short menuID;
713 if (!PyArg_ParseTuple(_args, "h",
714 &menuID))
715 return NULL;
716 DeleteMenu(menuID);
717 Py_INCREF(Py_None);
718 _res = Py_None;
719 return _res;
720}
721
722static PyObject *Menu_ClearMenuBar(_self, _args)
723 PyObject *_self;
724 PyObject *_args;
725{
726 PyObject *_res = NULL;
727 if (!PyArg_ParseTuple(_args, ""))
728 return NULL;
729 ClearMenuBar();
730 Py_INCREF(Py_None);
731 _res = Py_None;
732 return _res;
733}
734
735static PyObject *Menu_GetNewMBar(_self, _args)
736 PyObject *_self;
737 PyObject *_args;
738{
739 PyObject *_res = NULL;
740 Handle _rv;
741 short menuBarID;
742 if (!PyArg_ParseTuple(_args, "h",
743 &menuBarID))
744 return NULL;
745 _rv = GetNewMBar(menuBarID);
746 _res = Py_BuildValue("O&",
747 ResObj_New, _rv);
748 return _res;
749}
750
751static PyObject *Menu_GetMenuBar(_self, _args)
752 PyObject *_self;
753 PyObject *_args;
754{
755 PyObject *_res = NULL;
756 Handle _rv;
757 if (!PyArg_ParseTuple(_args, ""))
758 return NULL;
759 _rv = GetMenuBar();
760 _res = Py_BuildValue("O&",
761 ResObj_New, _rv);
762 return _res;
763}
764
765static PyObject *Menu_SetMenuBar(_self, _args)
766 PyObject *_self;
767 PyObject *_args;
768{
769 PyObject *_res = NULL;
770 Handle menuList;
771 if (!PyArg_ParseTuple(_args, "O&",
772 ResObj_Convert, &menuList))
773 return NULL;
774 SetMenuBar(menuList);
775 Py_INCREF(Py_None);
776 _res = Py_None;
777 return _res;
778}
779
780static PyObject *Menu_MenuKey(_self, _args)
781 PyObject *_self;
782 PyObject *_args;
783{
784 PyObject *_res = NULL;
785 long _rv;
786 short ch;
787 if (!PyArg_ParseTuple(_args, "h",
788 &ch))
789 return NULL;
790 _rv = MenuKey(ch);
791 _res = Py_BuildValue("l",
792 _rv);
793 return _res;
794}
795
796static PyObject *Menu_HiliteMenu(_self, _args)
797 PyObject *_self;
798 PyObject *_args;
799{
800 PyObject *_res = NULL;
801 short menuID;
802 if (!PyArg_ParseTuple(_args, "h",
803 &menuID))
804 return NULL;
805 HiliteMenu(menuID);
806 Py_INCREF(Py_None);
807 _res = Py_None;
808 return _res;
809}
810
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000811static PyObject *Menu_GetMenuHandle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000812 PyObject *_self;
813 PyObject *_args;
814{
815 PyObject *_res = NULL;
816 MenuHandle _rv;
817 short menuID;
818 if (!PyArg_ParseTuple(_args, "h",
819 &menuID))
820 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000821 _rv = GetMenuHandle(menuID);
Guido van Rossum17448e21995-01-30 11:53:55 +0000822 _res = Py_BuildValue("O&",
823 MenuObj_New, _rv);
824 return _res;
825}
826
827static PyObject *Menu_FlashMenuBar(_self, _args)
828 PyObject *_self;
829 PyObject *_args;
830{
831 PyObject *_res = NULL;
832 short menuID;
833 if (!PyArg_ParseTuple(_args, "h",
834 &menuID))
835 return NULL;
836 FlashMenuBar(menuID);
837 Py_INCREF(Py_None);
838 _res = Py_None;
839 return _res;
840}
841
842static PyObject *Menu_SetMenuFlash(_self, _args)
843 PyObject *_self;
844 PyObject *_args;
845{
846 PyObject *_res = NULL;
847 short count;
848 if (!PyArg_ParseTuple(_args, "h",
849 &count))
850 return NULL;
851 SetMenuFlash(count);
852 Py_INCREF(Py_None);
853 _res = Py_None;
854 return _res;
855}
856
857static PyObject *Menu_MenuSelect(_self, _args)
858 PyObject *_self;
859 PyObject *_args;
860{
861 PyObject *_res = NULL;
862 long _rv;
863 Point startPt;
864 if (!PyArg_ParseTuple(_args, "O&",
865 PyMac_GetPoint, &startPt))
866 return NULL;
867 _rv = MenuSelect(startPt);
868 _res = Py_BuildValue("l",
869 _rv);
870 return _res;
871}
872
873static PyObject *Menu_InitProcMenu(_self, _args)
874 PyObject *_self;
875 PyObject *_args;
876{
877 PyObject *_res = NULL;
878 short resID;
879 if (!PyArg_ParseTuple(_args, "h",
880 &resID))
881 return NULL;
882 InitProcMenu(resID);
883 Py_INCREF(Py_None);
884 _res = Py_None;
885 return _res;
886}
887
888static PyObject *Menu_MenuChoice(_self, _args)
889 PyObject *_self;
890 PyObject *_args;
891{
892 PyObject *_res = NULL;
893 long _rv;
894 if (!PyArg_ParseTuple(_args, ""))
895 return NULL;
896 _rv = MenuChoice();
897 _res = Py_BuildValue("l",
898 _rv);
899 return _res;
900}
901
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000902static PyObject *Menu_DeleteMCEntries(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000903 PyObject *_self;
904 PyObject *_args;
905{
906 PyObject *_res = NULL;
907 short menuID;
908 short menuItem;
909 if (!PyArg_ParseTuple(_args, "hh",
910 &menuID,
911 &menuItem))
912 return NULL;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000913 DeleteMCEntries(menuID,
914 menuItem);
915 Py_INCREF(Py_None);
916 _res = Py_None;
917 return _res;
918}
919
920static PyObject *Menu_SystemEdit(_self, _args)
921 PyObject *_self;
922 PyObject *_args;
923{
924 PyObject *_res = NULL;
925 Boolean _rv;
926 short editCmd;
927 if (!PyArg_ParseTuple(_args, "h",
928 &editCmd))
929 return NULL;
930 _rv = SystemEdit(editCmd);
931 _res = Py_BuildValue("b",
932 _rv);
933 return _res;
934}
935
936static PyObject *Menu_SystemMenu(_self, _args)
937 PyObject *_self;
938 PyObject *_args;
939{
940 PyObject *_res = NULL;
941 long menuResult;
942 if (!PyArg_ParseTuple(_args, "l",
943 &menuResult))
944 return NULL;
945 SystemMenu(menuResult);
Guido van Rossum17448e21995-01-30 11:53:55 +0000946 Py_INCREF(Py_None);
947 _res = Py_None;
948 return _res;
949}
950
Guido van Rossum86c3af71995-03-19 22:42:51 +0000951static PyObject *Menu_OpenDeskAcc(_self, _args)
952 PyObject *_self;
953 PyObject *_args;
954{
955 PyObject *_res = NULL;
956 Str255 name;
957 if (!PyArg_ParseTuple(_args, "O&",
958 PyMac_GetStr255, name))
959 return NULL;
960 OpenDeskAcc(name);
961 Py_INCREF(Py_None);
962 _res = Py_None;
963 return _res;
964}
965
Guido van Rossum17448e21995-01-30 11:53:55 +0000966static PyMethodDef Menu_methods[] = {
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000967 {"GetMBarHeight", (PyCFunction)Menu_GetMBarHeight, 1,
968 "() -> (short _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000969 {"InitMenus", (PyCFunction)Menu_InitMenus, 1,
970 "() -> None"},
971 {"NewMenu", (PyCFunction)Menu_NewMenu, 1,
972 "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"},
973 {"GetMenu", (PyCFunction)Menu_GetMenu, 1,
974 "(short resourceID) -> (MenuHandle _rv)"},
975 {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1,
976 "() -> None"},
977 {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1,
978 "() -> None"},
979 {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1,
980 "(short menuID) -> None"},
981 {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1,
982 "() -> None"},
983 {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1,
984 "(short menuBarID) -> (Handle _rv)"},
985 {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1,
986 "() -> (Handle _rv)"},
987 {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1,
988 "(Handle menuList) -> None"},
989 {"MenuKey", (PyCFunction)Menu_MenuKey, 1,
990 "(short ch) -> (long _rv)"},
991 {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1,
992 "(short menuID) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000993 {"GetMenuHandle", (PyCFunction)Menu_GetMenuHandle, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +0000994 "(short menuID) -> (MenuHandle _rv)"},
995 {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1,
996 "(short menuID) -> None"},
997 {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1,
998 "(short count) -> None"},
999 {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1,
1000 "(Point startPt) -> (long _rv)"},
1001 {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1,
1002 "(short resID) -> None"},
1003 {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1,
1004 "() -> (long _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +00001005 {"DeleteMCEntries", (PyCFunction)Menu_DeleteMCEntries, 1,
Guido van Rossum17448e21995-01-30 11:53:55 +00001006 "(short menuID, short menuItem) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +00001007 {"SystemEdit", (PyCFunction)Menu_SystemEdit, 1,
1008 "(short editCmd) -> (Boolean _rv)"},
1009 {"SystemMenu", (PyCFunction)Menu_SystemMenu, 1,
1010 "(long menuResult) -> None"},
Guido van Rossum86c3af71995-03-19 22:42:51 +00001011 {"OpenDeskAcc", (PyCFunction)Menu_OpenDeskAcc, 1,
1012 "(Str255 name) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001013 {NULL, NULL, 0}
1014};
1015
1016
1017
1018
1019void initMenu()
1020{
1021 PyObject *m;
1022 PyObject *d;
1023
1024
1025
1026
1027 m = Py_InitModule("Menu", Menu_methods);
1028 d = PyModule_GetDict(m);
1029 Menu_Error = PyMac_GetOSErrException();
1030 if (Menu_Error == NULL ||
1031 PyDict_SetItemString(d, "Error", Menu_Error) != 0)
1032 Py_FatalError("can't initialize Menu.Error");
1033}
1034
1035/* ======================== End module Menu ========================= */
1036