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