]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_refresh.c
ncurses 5.6 - patch 20070901
[ncurses.git] / ncurses / base / lib_refresh.c
index 88e3b75a56a1ac195af5f9b5a4b57d7ac2d16028..bc4d21e80136ff3a06616655ff3bb76362e1d184 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1998-2006,2007 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            *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
-
-
 /*
  *     lib_refresh.c
  *
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_refresh.c,v 1.24 1999/07/31 11:36:37 juergen Exp $")
+MODULE_ID("$Id: lib_refresh.c,v 1.40 2007/07/07 22:08:38 tom Exp $")
 
-int wrefresh(WINDOW *win)
+NCURSES_EXPORT(int)
+wrefresh(WINDOW *win)
 {
-int code;
+    int code;
 
-       T((T_CALLED("wrefresh(%p)"), win));
+    T((T_CALLED("wrefresh(%p)"), win));
 
-       if (win == curscr) {
-               curscr->_clear = TRUE;
-               code = doupdate();
-       } else if ((code = wnoutrefresh(win)) == OK) {
-               if (win->_clear)
-                       newscr->_clear = TRUE;
-               code = doupdate();
-               /*
-                * 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
-                * refreshes because the flag is copied from stdscr to newscr).
-                * Resetting the flag shouldn't do any harm, anyway.
-                */
-               win->_clear = FALSE;
-       }
-       returnCode(code);
+    if (win == 0) {
+       code = ERR;
+    } else if (win == curscr) {
+       curscr->_clear = TRUE;
+       code = doupdate();
+    } else if ((code = wnoutrefresh(win)) == OK) {
+       if (win->_clear)
+           newscr->_clear = TRUE;
+       code = doupdate();
+       /*
+        * 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
+        * refreshes because the flag is copied from stdscr to newscr).
+        * Resetting the flag shouldn't do any harm, anyway.
+        */
+       win->_clear = FALSE;
+    }
+    returnCode(code);
 }
 
-int wnoutrefresh(WINDOW *win)
+NCURSES_EXPORT(int)
+wnoutrefresh(WINDOW *win)
 {
-short  limit_x;
-short  i, j;
-short  begx;
-short  begy;
-short  m, n;
-bool   wide;
-
-       T((T_CALLED("wnoutrefresh(%p)"), 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;
+#if USE_SCROLL_HINTS
+    bool wide;
+#endif
+
+    T((T_CALLED("wnoutrefresh(%p)"), win));
 #ifdef TRACE
-       if (_nc_tracing & TRACE_UPDATE)
-           _tracedump("...win", win);
+    if (_nc_tracing & TRACE_UPDATE)
+       _tracedump("...win", win);
 #endif /* TRACE */
 
-       /*
-        * This function will break badly if we try to refresh a pad.
-        */
-       if ((win == 0)
-        || (win->_flags & _ISPAD))
-               returnCode(ERR);
+    /*
+     * This function will break badly if we try to refresh a pad.
+     */
+    if ((win == 0)
+       || (win->_flags & _ISPAD))
+       returnCode(ERR);
 
-       /* 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->_bkgd  = win->_bkgd;
-       newscr->_attrs = win->_attrs;
+    newscr->_nc_bkgd = win->_nc_bkgd;
+    WINDOW_ATTRS(newscr) = 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);
 
-       /*
-        * For pure efficiency, we'd want to transfer scrolling information
-        * from the window to newscr whenever the window is wide enough that
-        * its update will dominate the cost of the update for the horizontal
-        * band of newscr that it occupies.  Unfortunately, this threshold
-        * tends to be complex to estimate, and in any case scrolling the
-        * whole band and rewriting the parts outside win's image would look
-        * really ugly.  So.  What we do is consider the window "wide" if it
-        * either (a) occupies the whole width of newscr, or (b) occupies
-        * all but at most one column on either vertical edge of the screen
-        * (this caters to fussy people who put boxes around full-screen
-        * 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));
+#if USE_SCROLL_HINTS
+    /*
+     * For pure efficiency, we'd want to transfer scrolling information
+     * from the window to newscr whenever the window is wide enough that
+     * its update will dominate the cost of the update for the horizontal
+     * band of newscr that it occupies.  Unfortunately, this threshold
+     * tends to be complex to estimate, and in any case scrolling the
+     * whole band and rewriting the parts outside win's image would look
+     * really ugly.  So.  What we do is consider the window "wide" if it
+     * either (a) occupies the whole width of newscr, or (b) occupies
+     * all but at most one column on either vertical edge of the screen
+     * (this caters to fussy people who put boxes around full-screen
+     * 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));
+#endif
 
-       win->_flags &= ~_HASMOVED;
+    win->_flags &= ~_HASMOVED;
 
-       /*
-        * Microtweaking alert!  This double loop is one of the genuine
-        * hot spots in the code.  Even gcc doesn't seem to do enough
-        * common-subexpression chunking to make it really tense,
-        * so we'll force the issue.
-        */
+    /*
+     * Microtweaking alert!  This double loop is one of the genuine
+     * hot spots in the code.  Even gcc doesn't seem to do enough
+     * common-subexpression chunking to make it really tense,
+     * so we'll force the issue.
+     */
+
+    /* limit(dst_col) */
+    limit_x = win->_maxx;
+    /* limit(src_col) */
+    if (limit_x > newscr->_maxx - begx)
+       limit_x = newscr->_maxx - begx;
+
+    for (src_row = 0, dst_row = begy + win->_yoffset;
+        src_row <= win->_maxy && dst_row <= newscr->_maxy;
+        src_row++, dst_row++) {
+       register struct ldat *nline = &newscr->_line[dst_row];
+       register struct ldat *oline = &win->_line[src_row];
 
-       /* limit(n) */
-       limit_x = win->_maxx;
-       /* limit(j) */
-       if (limit_x > win->_maxx)
-               limit_x = win->_maxx;
-
-       for (i = 0, m = begy + win->_yoffset;
-            i <= win->_maxy && m <= newscr->_maxy;
-            i++, m++) {
-               register struct ldat    *nline = &newscr->_line[m];
-               register struct ldat    *oline = &win->_line[i];
-
-               if (oline->firstchar != _NOCHANGE) {
-                       int last = oline->lastchar;
-
-                       if (last > limit_x)
-                               last = limit_x;
-
-                       for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) {
-                               if (oline->text[j] != nline->text[n]) {
-                                       nline->text[n] = oline->text[j];
-                                       CHANGED_CELL(nline, n);
-                               }
+       if (oline->firstchar != _NOCHANGE) {
+           int last_src = oline->lastchar;
+
+           if (last_src > limit_x)
+               last_src = limit_x;
+
+           src_col = oline->firstchar;
+           dst_col = src_col + begx;
+
+           if_WIDEC({
+               register 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;
+               int last_dst = begx + ((last_src < win->_maxx)
+                                      ? last_src
+                                      : win->_maxx);
+               int fix_left = dst_col;
+               int fix_right = last_dst;
+               register int j;
+
+               /*
+                * Check for boundary cases where we may overwrite part of a
+                * multi-column character.  For those, wipe the remainder of
+                * the character to blanks.
+                */
+               j = dst_col;
+               if (isWidecExt(nline->text[j])) {
+                   /*
+                    * On the left, we only care about multi-column characters
+                    * that extend into the changed region.
+                    */
+                   fix_left = 1 + j - WidecExt(nline->text[j]);
+                   if (fix_left < 0)
+                       fix_left = 0;   /* only if cell is corrupt */
                }
 
-#if USE_SCROLL_HINTS
-               if (wide) {
-                   int oind = oline->oldindex;
+               j = last_dst;
+               if (WidecExt(nline->text[j]) != 0) {
+                   /*
+                    * On the right, any multi-column character is a problem,
+                    * unless it happens to be contained in the change, and
+                    * ending at the right boundary of the change.  The
+                    * computation for 'fix_left' accounts for the left-side of
+                    * this character.  Find the end of the character.
+                    */
+                   ++j;
+                   while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
+                       fix_right = j++;
+                   }
+               }
 
-                   nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset;
+               /*
+                * The analysis is simpler if we do the clearing afterwards.
+                * Do that now.
+                */
+               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);
+                   }
                }
-#endif /* USE_SCROLL_HINTS */
+           });
 
-               oline->firstchar = oline->lastchar = _NOCHANGE;
-               if_USE_SCROLL_HINTS(oline->oldindex = i);
-       }
+           /*
+            * Copy the changed text.
+            */
+           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 (win->_clear) {
-               win->_clear = FALSE;
-               newscr->_clear = TRUE;
        }
+#if USE_SCROLL_HINTS
+       if (wide) {
+           int oind = oline->oldindex;
 
-       if (! win->_leaveok) {
-               newscr->_cury = win->_cury + win->_begy + win->_yoffset;
-               newscr->_curx = win->_curx + win->_begx;
+           nline->oldindex = ((oind == _NEWINDEX)
+                              ? _NEWINDEX
+                              : (begy + oind + win->_yoffset));
        }
-       newscr->_leaveok = win->_leaveok;
-       
+#endif /* USE_SCROLL_HINTS */
+
+       oline->firstchar = oline->lastchar = _NOCHANGE;
+       if_USE_SCROLL_HINTS(oline->oldindex = src_row);
+    }
+
+    if (win->_clear) {
+       win->_clear = FALSE;
+       newscr->_clear = TRUE;
+    }
+
+    if (!win->_leaveok) {
+       newscr->_cury = win->_cury + win->_begy + win->_yoffset;
+       newscr->_curx = win->_curx + win->_begx;
+    }
+    newscr->_leaveok = win->_leaveok;
+
 #ifdef TRACE
-       if (_nc_tracing & TRACE_UPDATE)
-           _tracedump("newscr", newscr);
+    if (_nc_tracing & TRACE_UPDATE)
+       _tracedump("newscr", newscr);
 #endif /* TRACE */
-       returnCode(OK);
+    returnCode(OK);
 }