1 /* $NetBSD: touchwin.c,v 1.16 2002/01/02 10:38:29 blymn Exp $ */ 2 3 /* 4 * Copyright (c) 1981, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)touchwin.c 8.2 (Berkeley) 5/4/94"; 40 #else 41 __RCSID("$NetBSD: touchwin.c,v 1.16 2002/01/02 10:38:29 blymn Exp $"); 42 #endif 43 #endif /* not lint */ 44 45 #include "curses.h" 46 #include "curses_private.h" 47 48 /* 49 * is_linetouched -- 50 * Indicate if line has been touched or not. 51 */ 52 bool 53 is_linetouched(WINDOW *win, int line) 54 { 55 if (line > win->maxy) 56 return FALSE; 57 58 return ((win->lines[line]->flags & __ISDIRTY) != 0); 59 } 60 61 62 /* 63 * Touch count lines starting at start. This is the SUS v2 compliant 64 * version. 65 */ 66 67 int 68 touchline(WINDOW *win, int start, int count) 69 { 70 return wtouchln(win, start, count, 1); 71 } 72 73 /* 74 * is_wintouched -- 75 * Check if the window has been touched. 76 */ 77 bool 78 is_wintouched(WINDOW *win) 79 { 80 int y, maxy; 81 82 maxy = win->maxy; 83 for (y = 0; y < maxy; y++) { 84 if (is_linetouched(win, y) == TRUE) 85 return TRUE; 86 } 87 88 return FALSE; 89 } 90 91 /* 92 * touchwin -- 93 * Make it look like the whole window has been changed. 94 */ 95 int 96 touchwin(WINDOW *win) 97 { 98 #ifdef DEBUG 99 __CTRACE("touchwin: (%0.2o)\n", win); 100 #endif 101 return wtouchln(win, 0, win->maxy, 1); 102 } 103 104 /* 105 * untouchwin -- 106 * Make it look like the window has not been changed. 107 */ 108 int 109 untouchwin(WINDOW *win) 110 { 111 return wtouchln(win, 0, win->maxy, 0); 112 } 113 114 /* 115 * wtouchln -- 116 * If changed is 1 then touch n lines starting at line. If changed 117 * is 0 then mark the lines as unchanged. 118 */ 119 int 120 wtouchln(WINDOW *win, int line, int n, int changed) 121 { 122 int y; 123 __LINE *wlp; 124 125 for (y = line; y < line + n; y++) { 126 if (changed == 1) 127 __touchline(win, y, 0, (int) win->maxx - 1); 128 else { 129 wlp = win->lines[y]; 130 if (*wlp->firstchp >= win->ch_off && 131 *wlp->firstchp < win->maxx + win->ch_off) 132 *wlp->firstchp = win->maxx + win->ch_off; 133 if (*wlp->lastchp >= win->ch_off && 134 *wlp->lastchp < win->maxx + win->ch_off) 135 *wlp->lastchp = win->ch_off; 136 wlp->flags &= ~__ISDIRTY; 137 } 138 } 139 140 return OK; 141 } 142 143 144 int 145 __touchwin(WINDOW *win) 146 { 147 int y, maxy; 148 149 #ifdef DEBUG 150 __CTRACE("touchwin: (%0.2o)\n", win); 151 #endif 152 maxy = win->maxy; 153 for (y = 0; y < maxy; y++) 154 __touchline(win, y, 0, (int) win->maxx - 1); 155 return (OK); 156 } 157 158 int 159 __touchline(WINDOW *win, int y, int sx, int ex) 160 { 161 #ifdef DEBUG 162 __CTRACE("touchline: (%0.2o, %d, %d, %d)\n", win, y, sx, ex); 163 __CTRACE("touchline: first = %d, last = %d\n", 164 *win->lines[y]->firstchp, *win->lines[y]->lastchp); 165 #endif 166 sx += win->ch_off; 167 ex += win->ch_off; 168 if (!(win->lines[y]->flags & __ISDIRTY)) 169 win->lines[y]->flags |= __ISDIRTY; 170 /* firstchp/lastchp are shared between parent window and sub-window. */ 171 if (*win->lines[y]->firstchp > sx) 172 *win->lines[y]->firstchp = sx; 173 if (*win->lines[y]->lastchp < ex) 174 *win->lines[y]->lastchp = ex; 175 #ifdef DEBUG 176 __CTRACE("touchline: first = %d, last = %d\n", 177 *win->lines[y]->firstchp, *win->lines[y]->lastchp); 178 #endif 179 return (OK); 180 } 181