]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_window.c
ncurses 6.0 - patch 20160528
[ncurses.git] / ncurses / base / lib_window.c
index bb20f4faf2a2eb2bad27b7f68409f1520bb8b8f9..d755e88d66a38a6bb6c6c93a8b41c53966606b30 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2016 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_window.c,v 1.22 2006/05/27 19:21:19 tom Exp $")
+MODULE_ID("$Id: lib_window.c,v 1.30 2016/05/28 23:11:26 tom Exp $")
 
 NCURSES_EXPORT(void)
 _nc_synchook(WINDOW *win)
@@ -56,33 +56,32 @@ mvderwin(WINDOW *win, int y, int x)
 /* move a derived window */
 {
     WINDOW *orig;
-    int i;
-
-    T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
-
-    if (win && (orig = win->_parent)) {
-       if (win->_parx == x && win->_pary == y)
-           returnCode(OK);
-       if (x < 0 || y < 0)
-           returnCode(ERR);
-       if ((x + getmaxx(win) > getmaxx(orig)) ||
-           (y + getmaxy(win) > getmaxy(orig)))
-           returnCode(ERR);
-    } else
-       returnCode(ERR);
-    wsyncup(win);
-    win->_parx = x;
-    win->_pary = y;
-    for (i = 0; i < getmaxy(win); i++)
-       win->_line[i].text = &(orig->_line[y++].text[x]);
-    returnCode(OK);
+    int rc = ERR;
+
+    T((T_CALLED("mvderwin(%p,%d,%d)"), (void *) win, y, x));
+
+    if (win != 0
+       && (orig = win->_parent) != 0
+       && (x >= 0 && y >= 0)
+       && (x + getmaxx(win) <= getmaxx(orig))
+       && (y + getmaxy(win) <= getmaxy(orig))) {
+       int i;
+
+       wsyncup(win);
+       win->_parx = x;
+       win->_pary = y;
+       for (i = 0; i < getmaxy(win); i++)
+           win->_line[i].text = &(orig->_line[y++].text[x]);
+       rc = OK;
+    }
+    returnCode(rc);
 }
 
 NCURSES_EXPORT(int)
 syncok(WINDOW *win, bool bf)
 /* enable/disable automatic wsyncup() on each change to window */
 {
-    T((T_CALLED("syncok(%p,%d)"), win, bf));
+    T((T_CALLED("syncok(%p,%d)"), (void *) win, bf));
 
     if (win) {
        win->_sync = bf;
@@ -98,7 +97,7 @@ wsyncup(WINDOW *win)
 {
     WINDOW *wp;
 
-    T((T_CALLED("wsyncup(%p)"), win));
+    T((T_CALLED("wsyncup(%p)"), (void *) win));
     if (win && win->_parent) {
        for (wp = win; wp->_parent; wp = wp->_parent) {
            int y;
@@ -128,7 +127,7 @@ wsyncdown(WINDOW *win)
 /* mark changed every cell in win that is changed in any of its ancestors */
 /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...)           */
 {
-    T((T_CALLED("wsyncdown(%p)"), win));
+    T((T_CALLED("wsyncdown(%p)"), (void *) win));
 
     if (win && win->_parent) {
        WINDOW *pp = win->_parent;
@@ -149,7 +148,7 @@ wsyncdown(WINDOW *win)
                /* left and right character in child coordinates */
                int left = pp->_line[win->_pary + y].firstchar - win->_parx;
                int right = pp->_line[win->_pary + y].lastchar - win->_parx;
-               /* The change maybe outside the childs range */
+               /* The change may be outside the child's range */
                if (left < 0)
                    left = 0;
                if (right > win->_maxx)
@@ -167,7 +166,7 @@ wcursyncup(WINDOW *win)
 {
     WINDOW *wp;
 
-    T((T_CALLED("wcursyncup(%p)"), win));
+    T((T_CALLED("wcursyncup(%p)"), (void *) win));
     for (wp = win; wp && wp->_parent; wp = wp->_parent) {
        wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
     }
@@ -179,24 +178,29 @@ dupwin(WINDOW *win)
 /* make an exact duplicate of the given window */
 {
     WINDOW *nwin = 0;
-    size_t linesize;
-    int i;
 
-    T((T_CALLED("dupwin(%p)"), win));
+    T((T_CALLED("dupwin(%p)"), (void *) win));
 
     if (win != 0) {
-
+#if NCURSES_SP_FUNCS
+       SCREEN *sp = _nc_screen_of(win);
+#endif
+       _nc_lock_global(curses);
        if (win->_flags & _ISPAD) {
-           nwin = newpad(win->_maxy + 1,
-                         win->_maxx + 1);
+           nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
+                                           win->_maxy + 1,
+                                           win->_maxx + 1);
        } else {
-           nwin = newwin(win->_maxy + 1,
-                         win->_maxx + 1,
-                         win->_begy,
-                         win->_begx);
+           nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+                                           win->_maxy + 1,
+                                           win->_maxx + 1,
+                                           win->_begy,
+                                           win->_begx);
        }
 
        if (nwin != 0) {
+           int i;
+           size_t linesize;
 
            nwin->_curx = win->_curx;
            nwin->_cury = win->_cury;
@@ -236,13 +240,14 @@ dupwin(WINDOW *win)
            if (win->_flags & _ISPAD)
                nwin->_pad = win->_pad;
 
-           linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
+           linesize = (unsigned) (win->_maxx + 1) * sizeof(NCURSES_CH_T);
            for (i = 0; i <= nwin->_maxy; i++) {
                memcpy(nwin->_line[i].text, win->_line[i].text, linesize);
                nwin->_line[i].firstchar = win->_line[i].firstchar;
                nwin->_line[i].lastchar = win->_line[i].lastchar;
            }
        }
+       _nc_unlock_global(curses);
     }
     returnWin(nwin);
 }