]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_refresh.c
ncurses 6.2 - patch 20200523
[ncurses.git] / ncurses / base / lib_refresh.c
index a16dc8e64eb611d385ac3616410ade729ee70a7e..d8444289c1528efc5ea2934b9a3c127c34e320f7 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 1998-2010,2011 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +31,7 @@
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-on                 *
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
  ****************************************************************************/
 
 /*
 
 #include <curses.priv.h>
 
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_refresh.c,v 1.37 2007/06/30 23:35:43 tom Exp $")
+MODULE_ID("$Id: lib_refresh.c,v 1.46 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 wrefresh(WINDOW *win)
 {
     int code;
 
 NCURSES_EXPORT(int)
 wrefresh(WINDOW *win)
 {
     int code;
+#if NCURSES_SP_FUNCS
+    SCREEN *SP_PARM = _nc_screen_of(win);
+#endif
 
 
-    T((T_CALLED("wrefresh(%p)"), win));
+    T((T_CALLED("wrefresh(%p)"), (void *) win));
 
     if (win == 0) {
        code = ERR;
 
     if (win == 0) {
        code = ERR;
-    } else if (win == curscr) {
-       curscr->_clear = TRUE;
-       code = doupdate();
+    } else if (win == CurScreen(SP_PARM)) {
+       CurScreen(SP_PARM)->_clear = TRUE;
+       code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
     } else if ((code = wnoutrefresh(win)) == OK) {
        if (win->_clear)
     } else if ((code = wnoutrefresh(win)) == OK) {
        if (win->_clear)
-           newscr->_clear = TRUE;
-       code = doupdate();
+           NewScreen(SP_PARM)->_clear = TRUE;
+       code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
        /*
         * Reset the clearok() flag in case it was set for the special
         * case in hardscroll.c (if we don't reset it here, we'll get 2
        /*
         * Reset the clearok() flag in case it was set for the special
         * case in hardscroll.c (if we don't reset it here, we'll get 2
@@ -73,20 +78,19 @@ wrefresh(WINDOW *win)
 NCURSES_EXPORT(int)
 wnoutrefresh(WINDOW *win)
 {
 NCURSES_EXPORT(int)
 wnoutrefresh(WINDOW *win)
 {
-    NCURSES_SIZE_T limit_x;
-    NCURSES_SIZE_T src_row, src_col;
-    NCURSES_SIZE_T begx;
-    NCURSES_SIZE_T begy;
-    NCURSES_SIZE_T dst_row, dst_col;
+    int limit_x;
+    int src_row, src_col;
+    int begx;
+    int begy;
+    int dst_row, dst_col;
 #if USE_SCROLL_HINTS
     bool wide;
 #endif
 #if USE_SCROLL_HINTS
     bool wide;
 #endif
+#if NCURSES_SP_FUNCS
+    SCREEN *SP_PARM = _nc_screen_of(win);
+#endif
 
 
-    T((T_CALLED("wnoutrefresh(%p)"), win));
-#ifdef TRACE
-    if (_nc_tracing & TRACE_UPDATE)
-       _tracedump("...win", win);
-#endif /* TRACE */
+    T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
 
     /*
      * This function will break badly if we try to refresh a pad.
 
     /*
      * This function will break badly if we try to refresh a pad.
@@ -95,12 +99,19 @@ wnoutrefresh(WINDOW *win)
        || (win->_flags & _ISPAD))
        returnCode(ERR);
 
        || (win->_flags & _ISPAD))
        returnCode(ERR);
 
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE)) {
+       _tracedump("...win", win);
+       _nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
     /* put them here so "win == 0" won't break our code */
     begx = win->_begx;
     begy = win->_begy;
 
     /* put them here so "win == 0" won't break our code */
     begx = win->_begx;
     begy = win->_begy;
 
-    newscr->_nc_bkgd = win->_nc_bkgd;
-    WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win);
+    NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
+    WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
 
     /* merge in change information from all subwindows of this window */
     wsyncdown(win);
 
     /* merge in change information from all subwindows of this window */
     wsyncdown(win);
@@ -120,7 +131,7 @@ wnoutrefresh(WINDOW *win)
      * windows).  Note that changing this formula will not break any code,
      * merely change the costs of various update cases.
      */
      * windows).  Note that changing this formula will not break any code,
      * merely change the costs of various update cases.
      */
-    wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
+    wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
 #endif
 
     win->_flags &= ~_HASMOVED;
 #endif
 
     win->_flags &= ~_HASMOVED;
@@ -135,32 +146,67 @@ wnoutrefresh(WINDOW *win)
     /* limit(dst_col) */
     limit_x = win->_maxx;
     /* limit(src_col) */
     /* limit(dst_col) */
     limit_x = win->_maxx;
     /* limit(src_col) */
-    if (limit_x > newscr->_maxx - begx)
-       limit_x = newscr->_maxx - begx;
+    if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
+       limit_x = NewScreen(SP_PARM)->_maxx - begx;
 
     for (src_row = 0, dst_row = begy + win->_yoffset;
 
     for (src_row = 0, dst_row = begy + win->_yoffset;
-        src_row <= win->_maxy && dst_row <= newscr->_maxy;
+        src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
         src_row++, dst_row++) {
         src_row++, dst_row++) {
-       register struct ldat *nline = &newscr->_line[dst_row];
-       register struct ldat *oline = &win->_line[src_row];
+       struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
+       struct ldat *oline = &win->_line[src_row];
 
        if (oline->firstchar != _NOCHANGE) {
 
        if (oline->firstchar != _NOCHANGE) {
-           int last = oline->lastchar;
+           int last_src = oline->lastchar;
 
 
-           if (last > limit_x)
-               last = limit_x;
+           if (last_src > limit_x)
+               last_src = limit_x;
 
            src_col = oline->firstchar;
            dst_col = src_col + begx;
 
 
            src_col = oline->firstchar;
            dst_col = src_col + begx;
 
+           if_WIDEC({
+               int j;
+
+               /*
+                * Ensure that we will copy complete multi-column characters
+                * on the left-boundary.
+                */
+               if (isWidecExt(oline->text[src_col])) {
+                   j = 1 + dst_col - WidecExt(oline->text[src_col]);
+                   if (j < 0)
+                       j = 0;
+                   if (dst_col > j) {
+                       src_col -= (dst_col - j);
+                       dst_col = j;
+                   }
+               }
+
+               /*
+                * Ensure that we will copy complete multi-column characters
+                * on the right-boundary.
+                */
+               j = last_src;
+               if (WidecExt(oline->text[j])) {
+                   ++j;
+                   while (j <= limit_x) {
+                       if (isWidecBase(oline->text[j])) {
+                           break;
+                       } else {
+                           last_src = j;
+                       }
+                       ++j;
+                   }
+               }
+           });
+
            if_WIDEC({
                static cchar_t blank = BLANK;
            if_WIDEC({
                static cchar_t blank = BLANK;
-               int last_col = begx + ((last < win->_maxx)
-                                      ? last
+               int last_dst = begx + ((last_src < win->_maxx)
+                                      ? last_src
                                       : win->_maxx);
                int fix_left = dst_col;
                                       : win->_maxx);
                int fix_left = dst_col;
-               int fix_right = last_col;
-               register int j;
+               int fix_right = last_dst;
+               int j;
 
                /*
                 * Check for boundary cases where we may overwrite part of a
 
                /*
                 * Check for boundary cases where we may overwrite part of a
@@ -178,7 +224,7 @@ wnoutrefresh(WINDOW *win)
                        fix_left = 0;   /* only if cell is corrupt */
                }
 
                        fix_left = 0;   /* only if cell is corrupt */
                }
 
-               j = last_col;
+               j = last_dst;
                if (WidecExt(nline->text[j]) != 0) {
                    /*
                     * On the right, any multi-column character is a problem,
                if (WidecExt(nline->text[j]) != 0) {
                    /*
                     * On the right, any multi-column character is a problem,
@@ -187,8 +233,9 @@ wnoutrefresh(WINDOW *win)
                     * computation for 'fix_left' accounts for the left-side of
                     * this character.  Find the end of the character.
                     */
                     * computation for 'fix_left' accounts for the left-side of
                     * this character.  Find the end of the character.
                     */
-                   fix_right = ++j;
-                   while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
+                   ++j;
+                   while (j <= NewScreen(SP_PARM)->_maxx &&
+                          isWidecExt(nline->text[j])) {
                        fix_right = j++;
                    }
                }
                        fix_right = j++;
                    }
                }
@@ -197,20 +244,18 @@ wnoutrefresh(WINDOW *win)
                 * The analysis is simpler if we do the clearing afterwards.
                 * Do that now.
                 */
                 * The analysis is simpler if we do the clearing afterwards.
                 * Do that now.
                 */
-               for (j = fix_left; j < dst_col; ++j) {
-                   nline->text[j] = blank;
-                   CHANGED_CELL(nline, j);
-               }
-               for (j = last_col + 1; j <= fix_right; ++j) {
-                   nline->text[j] = blank;
-                   CHANGED_CELL(nline, j);
+               if (fix_left < dst_col || fix_right > last_dst) {
+                   for (j = fix_left; j <= fix_right; ++j) {
+                       nline->text[j] = blank;
+                       CHANGED_CELL(nline, j);
+                   }
                }
            });
 
            /*
             * Copy the changed text.
             */
                }
            });
 
            /*
             * Copy the changed text.
             */
-           for (; src_col <= last; src_col++, dst_col++) {
+           for (; src_col <= last_src; src_col++, dst_col++) {
                if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
                    nline->text[dst_col] = oline->text[src_col];
                    CHANGED_CELL(nline, dst_col);
                if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
                    nline->text[dst_col] = oline->text[src_col];
                    CHANGED_CELL(nline, dst_col);
@@ -234,18 +279,21 @@ wnoutrefresh(WINDOW *win)
 
     if (win->_clear) {
        win->_clear = FALSE;
 
     if (win->_clear) {
        win->_clear = FALSE;
-       newscr->_clear = TRUE;
+       NewScreen(SP_PARM)->_clear = TRUE;
     }
 
     if (!win->_leaveok) {
     }
 
     if (!win->_leaveok) {
-       newscr->_cury = win->_cury + win->_begy + win->_yoffset;
-       newscr->_curx = win->_curx + win->_begx;
+       NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
+                                                     win->_begy + win->_yoffset);
+       NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
     }
     }
-    newscr->_leaveok = win->_leaveok;
+    NewScreen(SP_PARM)->_leaveok = win->_leaveok;
 
 #ifdef TRACE
 
 #ifdef TRACE
-    if (_nc_tracing & TRACE_UPDATE)
-       _tracedump("newscr", newscr);
+    if (USE_TRACEF(TRACE_UPDATE)) {
+       _tracedump("newscr", NewScreen(SP_PARM));
+       _nc_unlock_global(tracef);
+    }
 #endif /* TRACE */
     returnCode(OK);
 }
 #endif /* TRACE */
     returnCode(OK);
 }