summaryrefslogtreecommitdiffstats
path: root/Modules/stdwinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-02-19 12:26:49 (GMT)
committerGuido van Rossum <guido@python.org>1991-02-19 12:26:49 (GMT)
commit2d14e21382fe28d4fbb390254ad27d04555fac3b (patch)
tree9b151579b591843b38dfaac2feff08a9380eb5c8 /Modules/stdwinmodule.c
parent7f133ed0732d216e00eda8456911f08a10bbc493 (diff)
downloadcpython-2d14e21382fe28d4fbb390254ad27d04555fac3b.zip
cpython-2d14e21382fe28d4fbb390254ad27d04555fac3b.tar.gz
cpython-2d14e21382fe28d4fbb390254ad27d04555fac3b.tar.bz2
Call winit() here instead of in main initialization.
Diffstat (limited to 'Modules/stdwinmodule.c')
-rw-r--r--Modules/stdwinmodule.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Modules/stdwinmodule.c b/Modules/stdwinmodule.c
index 4d28f97..1b27b71 100644
--- a/Modules/stdwinmodule.c
+++ b/Modules/stdwinmodule.c
@@ -751,8 +751,9 @@ static typeobject Texttype = {
/* Menu objects */
-#define MAXNMENU 50
-static menuobject *menulist[MAXNMENU]; /* Slot 0 unused */
+#define IDOFFSET 10 /* Menu IDs we use start here */
+#define MAXNMENU 20 /* Max #menus we allow */
+static menuobject *menulist[MAXNMENU];
static menuobject *
newmenuobject(title)
@@ -761,19 +762,19 @@ newmenuobject(title)
int id;
MENU *menu;
menuobject *mp;
- for (id = 1; id < MAXNMENU; id++) {
+ for (id = 0; id < MAXNMENU; id++) {
if (menulist[id] == NULL)
break;
}
if (id >= MAXNMENU)
return (menuobject *) err_nomem();
- menu = wmenucreate(id, getstringvalue(title));
+ menu = wmenucreate(id + IDOFFSET, getstringvalue(title));
if (menu == NULL)
return (menuobject *) err_nomem();
mp = NEWOBJ(menuobject, &Menutype);
if (mp != NULL) {
mp->m_menu = menu;
- mp->m_id = id;
+ mp->m_id = id + IDOFFSET;
mp->m_attr = NULL;
menulist[id] = mp;
}
@@ -789,8 +790,8 @@ menu_dealloc(mp)
menuobject *mp;
{
- int id = mp->m_id;
- if (id >= 0 && id < MAXNMENU) {
+ int id = mp->m_id - IDOFFSET;
+ if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
menulist[id] = NULL;
}
wmenudelete(mp->m_menu);
@@ -1373,9 +1374,9 @@ stdwin_get_poll_event(poll, args)
e.u.where.mask);
break;
case WE_MENU:
- if (e.u.m.id >= 0 && e.u.m.id < MAXNMENU &&
- menulist[e.u.m.id] != NULL)
- w = (object *)menulist[e.u.m.id];
+ if (e.u.m.id >= IDOFFSET && e.u.m.id < IDOFFSET+MAXNMENU &&
+ menulist[e.u.m.id - IDOFFSET] != NULL)
+ w = (object *)menulist[e.u.m.id - IDOFFSET];
else
w = None;
w = makemenu(w, e.u.m.item);
@@ -1663,5 +1664,10 @@ static struct methodlist stdwin_methods[] = {
void
initstdwin()
{
+ static int inited;
+ if (!inited) {
+ winit();
+ inited = 1;
+ }
initmodule("stdwin", stdwin_methods);
}