1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 45*7c478bd9Sstevel@tonic-gate #include <string.h> 46*7c478bd9Sstevel@tonic-gate #include "curses_inc.h" 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate /* 49*7c478bd9Sstevel@tonic-gate * Insert/delete lines 50*7c478bd9Sstevel@tonic-gate * id < 0 : number of lines to delete 51*7c478bd9Sstevel@tonic-gate * id > 0 : number of lines to insert 52*7c478bd9Sstevel@tonic-gate */ 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate int 55*7c478bd9Sstevel@tonic-gate winsdelln(WINDOW *win, int id) 56*7c478bd9Sstevel@tonic-gate { 57*7c478bd9Sstevel@tonic-gate int endy, endx, to, fr, num_lines, dir; 58*7c478bd9Sstevel@tonic-gate chtype *sw; 59*7c478bd9Sstevel@tonic-gate char *mk; 60*7c478bd9Sstevel@tonic-gate bool savimmed, savesync; 61*7c478bd9Sstevel@tonic-gate short x, y, quick, *begch, *endch; 62*7c478bd9Sstevel@tonic-gate #ifdef _VR3_COMPAT_CODE 63*7c478bd9Sstevel@tonic-gate /* LINTED */ 64*7c478bd9Sstevel@tonic-gate void (*update_ptr)(); 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate /* 67*7c478bd9Sstevel@tonic-gate * Null out the update pointer so that in wclrtoeol we do not 68*7c478bd9Sstevel@tonic-gate * update the _y16 area but we wait till the bottom of this 69*7c478bd9Sstevel@tonic-gate * function to do it in one fell swoop. 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate if (_y16update) { 73*7c478bd9Sstevel@tonic-gate update_ptr = _y16update; 74*7c478bd9Sstevel@tonic-gate _y16update = NULL; 75*7c478bd9Sstevel@tonic-gate } else 76*7c478bd9Sstevel@tonic-gate update_ptr = NULL; 77*7c478bd9Sstevel@tonic-gate #endif /* _VR3_COMPAT_CODE */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate if ((win->_cury >= win->_tmarg) && (win->_cury <= win->_bmarg)) 80*7c478bd9Sstevel@tonic-gate endy = win->_bmarg + 1; 81*7c478bd9Sstevel@tonic-gate else 82*7c478bd9Sstevel@tonic-gate endy = win->_maxy; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate if (id < 0) { 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * Check that the amount of lines to delete aren't larger 87*7c478bd9Sstevel@tonic-gate * than the window. We save num_lines only so that we 88*7c478bd9Sstevel@tonic-gate * don't have to re-compute if the if comes out true. 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate if ((num_lines = win->_cury - endy) > id) 92*7c478bd9Sstevel@tonic-gate id = num_lines; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * "fr" is the line that we are coming "fr"om and 96*7c478bd9Sstevel@tonic-gate * moving "to" the new place. This is the offset which 97*7c478bd9Sstevel@tonic-gate * we have to re-align our pointers by. 98*7c478bd9Sstevel@tonic-gate * We want to start setting the current line's pointer 99*7c478bd9Sstevel@tonic-gate * to point to the offset's line. We want to move line "fr" 100*7c478bd9Sstevel@tonic-gate * to line "to". 101*7c478bd9Sstevel@tonic-gate */ 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate to = win->_cury; 104*7c478bd9Sstevel@tonic-gate fr = to - id; 105*7c478bd9Sstevel@tonic-gate num_lines = endy - fr; 106*7c478bd9Sstevel@tonic-gate dir = 1; 107*7c478bd9Sstevel@tonic-gate } else { 108*7c478bd9Sstevel@tonic-gate /* can't insert more lines than are in the region */ 109*7c478bd9Sstevel@tonic-gate if ((num_lines = endy - win->_cury) < id) 110*7c478bd9Sstevel@tonic-gate id = num_lines; 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate to = endy - 1; 113*7c478bd9Sstevel@tonic-gate fr = to - id; 114*7c478bd9Sstevel@tonic-gate num_lines = fr - (win->_cury - 1); 115*7c478bd9Sstevel@tonic-gate dir = -1; 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* 119*7c478bd9Sstevel@tonic-gate * If this window has no parents or children, then we can manipulate 120*7c478bd9Sstevel@tonic-gate * pointers to simulate insert/delete line. Otherwise, 121*7c478bd9Sstevel@tonic-gate * to propogate the changes to parents and siblings 122*7c478bd9Sstevel@tonic-gate * we have to memcpy the text around. 123*7c478bd9Sstevel@tonic-gate * 124*7c478bd9Sstevel@tonic-gate * Set quick to tell us which we have to do. 125*7c478bd9Sstevel@tonic-gate */ 126*7c478bd9Sstevel@tonic-gate quick = ((win->_ndescs <= 0) && (win->_parent == NULL)); 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate begch = win->_firstch; 129*7c478bd9Sstevel@tonic-gate endch = win->_lastch; 130*7c478bd9Sstevel@tonic-gate endx = win->_maxx; 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate for (; num_lines > 0; num_lines--, to += dir, fr += dir) { 133*7c478bd9Sstevel@tonic-gate /* can be done quickly */ 134*7c478bd9Sstevel@tonic-gate if (quick) { 135*7c478bd9Sstevel@tonic-gate sw = win->_y[to]; 136*7c478bd9Sstevel@tonic-gate win->_y[to] = win->_y[fr]; 137*7c478bd9Sstevel@tonic-gate win->_y[fr] = sw; 138*7c478bd9Sstevel@tonic-gate if ((win == curscr) && _MARKS != NULL) { 139*7c478bd9Sstevel@tonic-gate mk = _MARKS[to]; 140*7c478bd9Sstevel@tonic-gate _MARKS[to] = _MARKS[fr]; 141*7c478bd9Sstevel@tonic-gate _MARKS[fr] = mk; 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate /* for color terminal do the same for */ 144*7c478bd9Sstevel@tonic-gate /* color marks */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate if (_COLOR_MARKS != NULL) { 147*7c478bd9Sstevel@tonic-gate mk = _COLOR_MARKS[to]; 148*7c478bd9Sstevel@tonic-gate _COLOR_MARKS[to] = _COLOR_MARKS[fr]; 149*7c478bd9Sstevel@tonic-gate _COLOR_MARKS[fr] = mk; 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate } else 153*7c478bd9Sstevel@tonic-gate /* slow update */ 154*7c478bd9Sstevel@tonic-gate (void) memcpy((char *) win->_y[to], (char *) 155*7c478bd9Sstevel@tonic-gate win->_y[fr], (endx * sizeof (chtype))); 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate /* 159*7c478bd9Sstevel@tonic-gate * If this is curscr, the firstch[] and lastch[] 160*7c478bd9Sstevel@tonic-gate * arrays contain blank information. 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate if (win == curscr) { 164*7c478bd9Sstevel@tonic-gate begch[to] = begch[fr]; 165*7c478bd9Sstevel@tonic-gate endch[to] = endch[fr]; 166*7c478bd9Sstevel@tonic-gate _CURHASH[to] = _CURHASH[fr]; 167*7c478bd9Sstevel@tonic-gate } else { 168*7c478bd9Sstevel@tonic-gate /* regular window, update the change structure */ 169*7c478bd9Sstevel@tonic-gate begch[to] = 0; 170*7c478bd9Sstevel@tonic-gate endch[to] = endx - 1; 171*7c478bd9Sstevel@tonic-gate } 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate /* clear the insert/delete lines */ 175*7c478bd9Sstevel@tonic-gate if (id < 0) 176*7c478bd9Sstevel@tonic-gate num_lines = endy - to; 177*7c478bd9Sstevel@tonic-gate else 178*7c478bd9Sstevel@tonic-gate num_lines = to - (win->_cury - 1); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate if (num_lines > 0) { /* Is this if needed ? */ 181*7c478bd9Sstevel@tonic-gate savimmed = win->_immed; 182*7c478bd9Sstevel@tonic-gate savesync = win->_sync; 183*7c478bd9Sstevel@tonic-gate win->_immed = win->_sync = FALSE; 184*7c478bd9Sstevel@tonic-gate x = win->_curx; 185*7c478bd9Sstevel@tonic-gate y = win->_cury; 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate win->_curx = 0; 188*7c478bd9Sstevel@tonic-gate for (; num_lines > 0; --num_lines, to += dir) { 189*7c478bd9Sstevel@tonic-gate /* LINTED */ 190*7c478bd9Sstevel@tonic-gate win->_cury = (short) to; 191*7c478bd9Sstevel@tonic-gate (void) wclrtoeol(win); 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate win->_curx = x; 195*7c478bd9Sstevel@tonic-gate win->_cury = y; 196*7c478bd9Sstevel@tonic-gate win->_immed = savimmed; 197*7c478bd9Sstevel@tonic-gate win->_sync = savesync; 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate win->_flags |= (_WINCHANGED|_WINSDEL); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate #ifdef _VR3_COMPAT_CODE 202*7c478bd9Sstevel@tonic-gate if (update_ptr) { 203*7c478bd9Sstevel@tonic-gate _y16update = update_ptr; 204*7c478bd9Sstevel@tonic-gate (*_y16update)(win, endy - y, endx, y, 0); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate #endif /* _VR3_COMPAT_CODE */ 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate if (win->_sync) 209*7c478bd9Sstevel@tonic-gate wsyncup(win); 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate return ((win != curscr && savimmed) ? wrefresh(win) : OK); 212*7c478bd9Sstevel@tonic-gate } 213