Home | History | Annotate | Line # | Download | only in libcurses
insdelln.c revision 1.3
      1  1.3  blymn /*	$NetBSD: insdelln.c,v 1.3 2000/04/15 13:17:04 blymn Exp $	*/
      2  1.2  blymn 
      3  1.2  blymn /*
      4  1.2  blymn  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.2  blymn  * All rights reserved.
      6  1.2  blymn  *
      7  1.2  blymn  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  blymn  * by Julian Coleman.
      9  1.2  blymn  *
     10  1.2  blymn  * Redistribution and use in source and binary forms, with or without
     11  1.2  blymn  * modification, are permitted provided that the following conditions
     12  1.2  blymn  * are met:
     13  1.2  blymn  * 1. Redistributions of source code must retain the above copyright
     14  1.2  blymn  *    notice, this list of conditions and the following disclaimer.
     15  1.2  blymn  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  blymn  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  blymn  *    documentation and/or other materials provided with the distribution.
     18  1.2  blymn  * 3. All advertising materials mentioning features or use of this software
     19  1.2  blymn  *    must display the following acknowledgement:
     20  1.2  blymn  *        This product includes software developed by the NetBSD
     21  1.2  blymn  *        Foundation, Inc. and its contributors.
     22  1.2  blymn  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  blymn  *    contributors may be used to endorse or promote products derived
     24  1.2  blymn  *    from this software without specific prior written permission.
     25  1.2  blymn  *
     26  1.2  blymn  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  blymn  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  blymn  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  blymn  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  blymn  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  blymn  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  blymn  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  blymn  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  blymn  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  blymn  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  blymn  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  blymn  */
     38  1.2  blymn 
     39  1.2  blymn /*
     40  1.2  blymn  * Based on deleteln.c and insertln.c -
     41  1.2  blymn  * Copyright (c) 1981, 1993, 1994
     42  1.2  blymn  *	The Regents of the University of California.  All rights reserved.
     43  1.2  blymn  */
     44  1.2  blymn 
     45  1.2  blymn #include <string.h>
     46  1.2  blymn 
     47  1.2  blymn #include "curses.h"
     48  1.2  blymn #include "curses_private.h"
     49  1.2  blymn 
     50  1.3  blymn #ifndef _CURSES_USE_MACROS
     51  1.3  blymn 
     52  1.3  blymn /*
     53  1.3  blymn  * insdelln --
     54  1.3  blymn  *	Insert or delete lines on stdscr, leaving (cury, curx) unchanged.
     55  1.3  blymn  */
     56  1.3  blymn int
     57  1.3  blymn insdelln(int lines)
     58  1.3  blymn {
     59  1.3  blymn 	return winsdelln(stdscr, lines);
     60  1.3  blymn }
     61  1.3  blymn 
     62  1.3  blymn #endif
     63  1.3  blymn 
     64  1.2  blymn /*
     65  1.2  blymn  * winsdelln --
     66  1.2  blymn  *	Insert or delete lines on the window, leaving (cury, curx) unchanged.
     67  1.2  blymn  */
     68  1.2  blymn int
     69  1.3  blymn winsdelln(WINDOW *win, int lines)
     70  1.2  blymn {
     71  1.2  blymn 	int     y, i;
     72  1.2  blymn 	__LINE *temp;
     73  1.2  blymn 
     74  1.2  blymn #ifdef DEBUG
     75  1.2  blymn 	__CTRACE("winsdelln: (%0.2o) cury=%d lines=%d\n", win, win->cury,
     76  1.2  blymn 	    lines);
     77  1.2  blymn #endif
     78  1.2  blymn 
     79  1.2  blymn 	if (!lines)
     80  1.2  blymn 		return(OK);
     81  1.2  blymn 
     82  1.2  blymn 	if (lines > 0) {
     83  1.2  blymn 		/* Insert lines */
     84  1.2  blymn 		if (lines > win->maxy - win->cury)
     85  1.2  blymn 			lines = win->maxy - win->cury;
     86  1.2  blymn 		for (y = win->maxy - lines - 1 ; y >= win->cury; --y) {
     87  1.2  blymn 			win->lines[y]->flags &= ~__ISPASTEOL;
     88  1.2  blymn 			win->lines[y + lines]->flags &= ~__ISPASTEOL;
     89  1.2  blymn 			if (win->orig == NULL) {
     90  1.2  blymn 				temp = win->lines[y + lines];
     91  1.2  blymn 				win->lines[y + lines] = win->lines[y];
     92  1.2  blymn 				win->lines[y] = temp;
     93  1.2  blymn 			} else {
     94  1.2  blymn 				(void) memcpy(win->lines[y + lines]->line,
     95  1.2  blymn 				    win->lines[y]->line,
     96  1.2  blymn 				    (size_t) win->maxx * __LDATASIZE * lines);
     97  1.2  blymn 				temp = win->lines[y];
     98  1.2  blymn 			}
     99  1.2  blymn 		}
    100  1.2  blymn 		for (y = win->cury - 1 + lines; y >= win->cury; --y)
    101  1.2  blymn 			for (i = 0; i < win->maxx; i++) {
    102  1.2  blymn 				win->lines[y]->line[i].ch = ' ';
    103  1.2  blymn 				win->lines[y]->line[i].attr = 0;
    104  1.2  blymn 			}
    105  1.2  blymn 		for (y = win->maxy - 1; y >= win->cury; --y)
    106  1.2  blymn 			__touchline(win, y, 0, (int) win->maxx - 1, 0);
    107  1.2  blymn 	} else {
    108  1.2  blymn 		/* Delete lines */
    109  1.2  blymn 		lines = 0 - lines;
    110  1.2  blymn 		if (lines > win->maxy - win->cury)
    111  1.2  blymn 			lines = win->maxy - win->cury;
    112  1.2  blymn 		for (y = win->cury; y < win->maxy - lines; y++) {
    113  1.2  blymn 			win->lines[y]->flags &= ~__ISPASTEOL;
    114  1.2  blymn 			win->lines[y + lines]->flags &= ~__ISPASTEOL;
    115  1.2  blymn 			if (win->orig == NULL) {
    116  1.2  blymn 				temp = win->lines[y];
    117  1.2  blymn 				win->lines[y] = win->lines[y + lines];
    118  1.2  blymn 				win->lines[y + lines] = temp;
    119  1.2  blymn 			} else {
    120  1.2  blymn 				(void) memcpy(win->lines[y]->line,
    121  1.2  blymn 				    win->lines[y + lines]->line,
    122  1.2  blymn 				    (size_t) win->maxx * __LDATASIZE * lines);
    123  1.2  blymn 				temp = win->lines[y + lines];
    124  1.2  blymn 			}
    125  1.2  blymn 		}
    126  1.2  blymn 		for (y = win->maxy - lines; y < win->maxy; y++)
    127  1.2  blymn 			for (i = 0; i < win->maxx; i++) {
    128  1.2  blymn 				win->lines[y]->line[i].ch = ' ';
    129  1.2  blymn 				win->lines[y]->line[i].attr = 0;
    130  1.2  blymn 			}
    131  1.2  blymn 		for (y = win->cury; y < win->maxy; y++)
    132  1.2  blymn 			__touchline(win, y, 0, (int) win->maxx - 1, 0);
    133  1.2  blymn 	}
    134  1.2  blymn 	if (win->orig != NULL)
    135  1.2  blymn 		__id_subwins(win);
    136  1.2  blymn 	return (OK);
    137  1.2  blymn }
    138