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