1 /* $NetBSD: touchwin.c,v 1.17 2002/12/05 17:23:51 jdc 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.17 2002/12/05 17:23:51 jdc 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 #ifdef DEBUG 126 __CTRACE("wtouchln: (%0.2o) %d, %d, %d\n", win, line, n, changed); 127 #endif 128 for (y = line; y < line + n; y++) { 129 if (changed == 1) 130 __touchline(win, y, 0, (int) win->maxx - 1); 131 else { 132 wlp = win->lines[y]; 133 if (*wlp->firstchp >= win->ch_off && 134 *wlp->firstchp < win->maxx + win->ch_off) 135 *wlp->firstchp = win->maxx + win->ch_off; 136 if (*wlp->lastchp >= win->ch_off && 137 *wlp->lastchp < win->maxx + win->ch_off) 138 *wlp->lastchp = win->ch_off; 139 wlp->flags &= ~__ISDIRTY; 140 } 141 } 142 143 return OK; 144 } 145 146 147 int 148 __touchwin(WINDOW *win) 149 { 150 int y, maxy; 151 152 #ifdef DEBUG 153 __CTRACE("touchwin: (%0.2o)\n", win); 154 #endif 155 maxy = win->maxy; 156 for (y = 0; y < maxy; y++) 157 __touchline(win, y, 0, (int) win->maxx - 1); 158 return (OK); 159 } 160 161 int 162 __touchline(WINDOW *win, int y, int sx, int ex) 163 { 164 #ifdef DEBUG 165 __CTRACE("touchline: (%0.2o, %d, %d, %d)\n", win, y, sx, ex); 166 __CTRACE("touchline: first = %d, last = %d\n", 167 *win->lines[y]->firstchp, *win->lines[y]->lastchp); 168 #endif 169 sx += win->ch_off; 170 ex += win->ch_off; 171 if (!(win->lines[y]->flags & __ISDIRTY)) 172 win->lines[y]->flags |= __ISDIRTY; 173 /* firstchp/lastchp are shared between parent window and sub-window. */ 174 if (*win->lines[y]->firstchp > sx) 175 *win->lines[y]->firstchp = sx; 176 if (*win->lines[y]->lastchp < ex) 177 *win->lines[y]->lastchp = ex; 178 #ifdef DEBUG 179 __CTRACE("touchline: first = %d, last = %d\n", 180 *win->lines[y]->firstchp, *win->lines[y]->lastchp); 181 #endif 182 return (OK); 183 } 184