Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Implement wnoutrefresh() and doupdate(). wref...



details:   https://anonhg.NetBSD.org/src/rev/88a7c179c3a0
branches:  trunk
changeset: 485394:88a7c179c3a0
user:      jdc <jdc%NetBSD.org@localhost>
date:      Thu Apr 27 00:26:19 2000 +0000

description:
Implement wnoutrefresh() and doupdate().  wrefresh() now calls these functions
and the previous wrefresh() code is split between them.  Background character
and attribute handling is now done in wnoutrefresh(), thus simplifying the code
in doupdate(), makech() and quickch().
Refine xterm workround and test for it earlier - this cuts down the number of
lines we test when looking for a scrolled region.
Rename unsetattr() to __unsetattr(), so it can be used by __stopwin().

diffstat:

 lib/libcurses/refresh.c |  651 ++++++++++++++++++++++++-----------------------
 1 files changed, 336 insertions(+), 315 deletions(-)

diffs (truncated from 1152 to 300 lines):

diff -r 63736065ac21 -r 88a7c179c3a0 lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c   Thu Apr 27 00:24:16 2000 +0000
+++ b/lib/libcurses/refresh.c   Thu Apr 27 00:26:19 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refresh.c,v 1.22 2000/04/21 15:56:35 jdc Exp $ */
+/*     $NetBSD: refresh.c,v 1.23 2000/04/27 00:26:19 jdc Exp $ */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)refresh.c  8.7 (Berkeley) 8/13/94";
 #else
-__RCSID("$NetBSD: refresh.c,v 1.22 2000/04/21 15:56:35 jdc Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.23 2000/04/27 00:26:19 jdc Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -50,14 +50,13 @@
 /* the following is defined and set up in setterm.c */
 extern struct tinfo *_cursesi_genbuf;
 
-static int curwin;
+static int curwin = 0;
 static short ly, lx;
 
 static void    domvcur __P((int, int, int, int));
-static int     makech __P((WINDOW *, int));
-static void    quickch __P((WINDOW *));
-static void    scrolln __P((WINDOW *, int, int, int, int, int));
-static void    unsetattr __P((int));
+static int     makech __P((int));
+static void    quickch __P((void));
+static void    scrolln __P((int, int, int, int, int));
 
 #ifndef _CURSES_USE_MACROS
 
@@ -75,6 +74,116 @@
 #endif
 
 /*
+ * wnoutrefresh --
+ *     Add the contents of "win" to the virtual window.
+ */
+int
+wnoutrefresh(WINDOW *win)
+{
+       short   wy, wx, y_off, x_off;
+
+#ifdef DEBUG
+       __CTRACE("wnoutrefresh: win %0.2o, flags 0x%08x\n", win, win->flags);
+#endif
+
+       if (curwin)
+               return(OK);
+       __virtscr->cury = win->cury + win->begy;
+       __virtscr->curx = win->curx + win->begx;
+
+       /* Copy the window flags from "win" to "__virtscr" */
+       if (!(win->flags & __FULLWIN) && (win->flags & __CLEAROK))
+               win->flags &= ~__CLEAROK;
+       __virtscr->flags |= win->flags;
+       if (win->flags & __CLEAROK)
+               win->flags &= ~__CLEAROK;
+
+       for (wy = 0; wy < win->maxy; wy++) {
+#ifdef DEBUG
+               __CTRACE("wnoutrefresh: wy %d\tf: %d\tl:%d\tflags %x\n", wy,
+                   *win->lines[wy]->firstchp,
+                   *win->lines[wy]->lastchp,
+                   win->lines[wy]->flags);
+#endif
+               y_off = wy + win->begy;
+               if (*win->lines[wy]->firstchp <= win->maxx + win->ch_off &&
+                   *win->lines[wy]->lastchp >= win->ch_off) {
+                       /* Copy line from "win" to "__virtscr". */
+                       for (wx = 0; wx < win->maxx; wx++) {
+                               x_off = wx + win->begx;
+                               __virtscr->lines[y_off]->line[x_off].attr =
+                                   win->lines[wy]->line[wx].attr;
+                               if (!(win->lines[wy]->line[wx].attr & __COLOR)
+                                   && (win->lines[wy]->line[wx].battr &
+                                   __COLOR))
+                                       __virtscr->lines[y_off]->line[x_off].
+                                           attr |=
+                                           win->lines[wy]->line[wx].battr &
+                                           __COLOR;
+                               if (win->lines[wy]->line[wx].ch == ' ' &&
+                                   win->lines[wy]->line[wx].bch != ' ')
+                                       __virtscr->lines[y_off]->line[x_off].ch
+                                           = win->lines[wy]->line[wx].bch;
+                               else
+                                       __virtscr->lines[y_off]->line[x_off].ch
+                                           = win->lines[wy]->line[wx].ch;
+                       }
+
+                       /* Set flags on "__virtscr" and unset on "win". */
+                       if (win->lines[wy]->flags & __FORCEPAINT) {
+                               __virtscr->lines[y_off]->flags |= __FORCEPAINT;
+                               win->lines[wy]->flags &= ~__FORCEPAINT;
+                       }
+                       if (win->lines[wy]->flags & __ISPASTEOL)
+                               __virtscr->lines[y_off]->flags |= __ISPASTEOL;
+                       else
+                               __virtscr->lines[y_off]->flags &= ~__ISPASTEOL;
+                       if (win->lines[wy]->flags & __ISDIRTY)
+                               __virtscr->lines[y_off]->flags |= __ISDIRTY;
+
+#ifdef DEBUG
+                       __CTRACE("win: firstch = %d, lastch = %d\n",
+                           *win->lines[wy]->firstchp,
+                           *win->lines[wy]->lastchp);
+#endif
+                       /* Set change pointers on "__virtscr". */
+                       if (*__virtscr->lines[y_off]->firstchp >
+                           *win->lines[wy]->firstchp + win->begx - win->ch_off)
+                               *__virtscr->lines[y_off]->firstchp =
+                                   *win->lines[wy]->firstchp + win->begx -
+                                   win->ch_off;
+                       if (*__virtscr->lines[y_off]->lastchp <
+                           *win->lines[wy]->lastchp + win->begx - win->ch_off)
+                               *__virtscr->lines[y_off]->lastchp =
+                                   *win->lines[wy]->lastchp + win->begx -
+                                   win->ch_off;
+#ifdef DEBUG
+                       __CTRACE("__virtscr: firstch = %d, lastch = %d\n",
+                           *__virtscr->lines[y_off]->firstchp,
+                           *__virtscr->lines[y_off]->lastchp);
+#endif
+
+                       /* Set change pointers on "win". */
+                       if (*win->lines[wy]->firstchp >= win->ch_off)
+                               *win->lines[wy]->firstchp = win->maxx +
+                                   win->ch_off;
+                       if (*win->lines[wy]->lastchp < win->maxx + win->ch_off)
+                       *win->lines[wy]->lastchp = win->ch_off;
+                       if (*win->lines[wy]->lastchp <
+                           *win->lines[wy]->firstchp) {
+#ifdef DEBUG
+                               __CTRACE("wnoutrefresh: line %d notdirty\n",
+                                   wy);
+#endif
+                               win->lines[wy]->flags &= ~__ISDIRTY;
+                       }
+               }
+       }
+
+       return (OK);
+}
+
+/*
  * wrefresh --
  *     Make the current screen look like "win" over the area coverd by
  *     win.
@@ -82,10 +191,34 @@
 int
 wrefresh(WINDOW *win)
 {
-       __LINE *wlp;
        int     retval;
-       short   wy;
-       int     dnum;
+
+       curwin = (win == curscr);
+       if (!curwin)
+               retval = wnoutrefresh(win);
+       else
+               retval = OK;
+       if (retval == OK) {
+               retval = doupdate();
+               win->cury = max(0, curscr->cury - win->begy);
+               win->curx = max(0, curscr->curx - win->begx);
+       }
+       curwin = 0;
+       return(retval);
+}
+
+/*
+ * doupdate --
+ *     Make the current screen look like the virtual window "__virtscr".
+ */
+int
+doupdate(void)
+{
+       WINDOW  *win;
+       __LINE  *wlp;
+       int      retval;
+       short    wy;
+       int      dnum;
 
        /* Check if we need to restart ... */
        if (__endwin) {
@@ -93,11 +226,15 @@
                __restartwin();
        }
 
+       if (curwin)
+               win = curscr;
+       else
+               win = __virtscr;
+
        /* Initialize loop parameters. */
        ly = curscr->cury;
        lx = curscr->curx;
        wy = 0;
-       curwin = (win == curscr);
 
        if (!curwin)
                for (wy = 0; wy < win->maxy; wy++) {
@@ -108,60 +245,18 @@
                }
 
        if ((win->flags & __CLEAROK) || (curscr->flags & __CLEAROK) || curwin) {
-               if ((win->flags & __FULLWIN) || curscr->flags & __CLEAROK) {
-                       short   wx;
-                       attr_t  bcolor;
-
-                       bcolor = win->lines[0]->line[0].battr & __COLOR;
-                       for (wy = 0; wy < win->maxy; wy++)
-                               for (wx = 0; wx < win->maxx; wx++)
-                                       if ((win->lines[wy]->line[wx].battr &
-                                           __COLOR) != bcolor)
-                                               goto colorchanged;
-                       if ((!bcolor || (bcolor && BE)) && win->bch == ' ') {
-                               if (bcolor) {
-                                       if (bcolor !=
-                                           (curscr->wattr & __COLOR)) {
-                                               __set_color(bcolor);
-                                               curscr->wattr &= ~__COLOR;
-                                               curscr->wattr |= bcolor;
-                                       }
-                               } else if (curscr->wattr & __COLOR) {
-                                       if (OC != NULL && CC == NULL)
-                                               tputs(OC, 0, __cputchar);
-                                       if (OP != NULL) {
-                                               tputs(OP, 0, __cputchar);
-                                               if (SE != NULL &&
-                                                   !strcmp(OP, SE))
-                                                       curscr->wattr &=
-                                                           ~__STANDOUT;
-                                               if (UE != NULL &&
-                                                   !strcmp(OP, UE))
-                                                       curscr->wattr &=
-                                                           ~__UNDERSCORE;
-                                               if (ME != NULL &&
-                                                   !strcmp(OP, ME))
-                                                       curscr->wattr &=
-                                                           ~__TERMATTR;
-                                       }
-                                       curscr->wattr &= ~__COLOR;
-                               }
-                               tputs(CL, 0, __cputchar);
-                               ly = 0;
-                               lx = 0;
-                               if (!curwin) {
-                                       curscr->flags &= ~__CLEAROK;
-                                       curscr->cury = 0;
-                                       curscr->curx = 0;
-                                       werase(curscr);
-                               }
-                               __touchwin(win);
-                       } else {
-colorchanged:                  if (!curwin)
-                                       curscr->flags &= ~__CLEAROK;
-                               touchwin(win);
-                       }
+               if (curscr->wattr & __COLOR)
+                       __unsetattr(0);
+               tputs(CL, 0, __cputchar);
+               ly = 0;
+               lx = 0;
+               if (!curwin) {
+                       curscr->flags &= ~__CLEAROK;
+                       curscr->cury = 0;
+                       curscr->curx = 0;
+                       werase(curscr);
                }
+               __touchwin(win);
                win->flags &= ~__CLEAROK;
        }
        if (!CA) {
@@ -171,20 +266,21 @@
                        werase(curscr);
        }
 #ifdef DEBUG
-       __CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin);
-       __CTRACE("wrefresh: \tfirstch\tlastch\n");
+       __CTRACE("doupdate: (%0.2o): curwin = %d\n", win, curwin);
+       __CTRACE("doupdate: \tfirstch\tlastch\n");
 #endif
 
-       if ((win->flags & __FULLWIN) && !curwin) {
+       if (!curwin) {
                /*
                 * Invoke quickch() only if more than a quarter of the lines
                 * in the window are dirty.
                 */
                for (wy = 0, dnum = 0; wy < win->maxy; wy++)
-                       if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT))
+                       if (win->lines[wy]->flags &



Home | Main Index | Thread Index | Old Index