]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Call winit() here instead of in main initialization.
authorGuido van Rossum <guido@python.org>
Tue, 19 Feb 1991 12:26:49 +0000 (12:26 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 19 Feb 1991 12:26:49 +0000 (12:26 +0000)
Modules/stdwinmodule.c

index 4d28f9735824ca40e53f4e687f323a90ea475c36..1b27b71a77c08206d9f4ff95286983b9814e9afb 100644 (file)
@@ -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);
 }