]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Don't suppress wsetfont("");
authorGuido van Rossum <guido@python.org>
Mon, 3 Jun 1991 10:55:14 +0000 (10:55 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 3 Jun 1991 10:55:14 +0000 (10:55 +0000)
Don't report WE_MENU events with None as menu pointer;
Added stdwin.getactie() function;
Moved code to turn WINDOW* into windowobject* to a separate function.

Modules/stdwinmodule.c

index 32f5f2272d5c61e87bc16c0a84424d4c3d8d67d6..494b15ea3015a93f7f30438d3ce999364b62944a 100644 (file)
@@ -628,8 +628,7 @@ drawing_setfont(self, args)
                err_badarg();
                return NULL;
        }
-       if (getstringsize(font) != 0)
-               wsetfont(getstringvalue(font));
+       wsetfont(getstringvalue(font));
        if (style != NULL) {
                switch (*getstringvalue(style)) {
                case 'b':
@@ -1639,6 +1638,33 @@ stdwin_open(sw, args)
        return (object *)wp;
 }
 
+static object *
+window2object(win)
+       WINDOW *win;
+{
+       object *w;
+       if (win == NULL)
+               w = None;
+       else {
+               int tag = wgettag(win);
+               if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL ||
+                       windowlist[tag]->w_win != win)
+                       w = None;
+               else
+                       w = (object *)windowlist[tag];
+#ifdef sgi
+               /* XXX Trap for unexplained weird bug */
+               if ((long)w == (long)0x80000001) {
+                       err_setstr(SystemError,
+                               "bad pointer in stdwin.getevent()");
+                       return NULL;
+               }
+#endif
+       }
+       INCREF(w);
+       return w;
+}
+
 static object *
 stdwin_get_poll_event(poll, args)
        int poll;
@@ -1652,7 +1678,7 @@ stdwin_get_poll_event(poll, args)
                err_setstr(RuntimeError, "cannot getevent() while drawing");
                return NULL;
        }
-/* again: */
+ again:
        if (poll) {
                if (!wpollevent(&e)) {
                        INCREF(None);
@@ -1666,10 +1692,6 @@ stdwin_get_poll_event(poll, args)
                err_set(KeyboardInterrupt);
                return NULL;
        }
-/*
-       if (e.window == NULL && (e.type == WE_COMMAND || e.type == WE_CHAR))
-               goto again;
-*/
        if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
                /* Turn WC_CLOSE commands into WE_CLOSE events */
                e.type = WE_CLOSE;
@@ -1682,25 +1704,7 @@ stdwin_get_poll_event(poll, args)
                return NULL;
        }
        settupleitem(v, 0, w);
-       if (e.window == NULL)
-               w = None;
-       else {
-               int tag = wgettag(e.window);
-               if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL)
-                       w = None;
-               else
-                       w = (object *)windowlist[tag];
-#ifdef sgi
-               /* XXX Trap for unexplained weird bug */
-               if ((long)w == (long)0x80000001) {
-                       err_setstr(SystemError,
-                               "bad pointer in stdwin.getevent()");
-                       return NULL;
-               }
-#endif
-       }
-       INCREF(w);
-       settupleitem(v, 1, w);
+       settupleitem(v, 1, window2object(e.window));
        switch (e.type) {
        case WE_CHAR:
                {
@@ -1728,8 +1732,14 @@ stdwin_get_poll_event(poll, args)
                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;
+               else {
+                       /* Ghost menu event.
+                          Can occur only on the Mac if another part
+                          of the aplication has installed a menu;
+                          like the THINK C console library. */
+                       DECREF(v);
+                       goto again;
+               }
                w = makemenu(w, e.u.m.item);
                break;
        case WE_LOST_SEL:
@@ -1947,6 +1957,14 @@ stdwin_setcutbuffer(self, args)
        return None;
 }
 
+static object *
+stdwin_getactive(self, args)
+       object *self;
+       object *args;
+{
+       return window2object(wgetactive());
+}
+
 static object *
 stdwin_getcutbuffer(self, args)
        object *self;
@@ -2050,6 +2068,7 @@ static struct methodlist stdwin_methods[] = {
        {"askync",              stdwin_askync},
        {"fetchcolor",          stdwin_fetchcolor},
        {"fleep",               stdwin_fleep},
+       {"getactive",           stdwin_getactive},
        {"getcutbuffer",        stdwin_getcutbuffer},
        {"getdefscrollbars",    stdwin_getdefscrollbars},
        {"getdefwinpos",        stdwin_getdefwinpos},