2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <string.h>
2N/A#include "curses_inc.h"
2N/A
2N/A/*
2N/A * Insert/delete lines
2N/A * id < 0 : number of lines to delete
2N/A * id > 0 : number of lines to insert
2N/A */
2N/A
2N/Aint
2N/Awinsdelln(WINDOW *win, int id)
2N/A{
2N/A int endy, endx, to, fr, num_lines, dir;
2N/A chtype *sw;
2N/A char *mk;
2N/A bool savimmed, savesync;
2N/A short x, y, quick, *begch, *endch;
2N/A#ifdef _VR3_COMPAT_CODE
2N/A /* LINTED */
2N/A void (*update_ptr)();
2N/A
2N/A /*
2N/A * Null out the update pointer so that in wclrtoeol we do not
2N/A * update the _y16 area but we wait till the bottom of this
2N/A * function to do it in one fell swoop.
2N/A */
2N/A
2N/A if (_y16update) {
2N/A update_ptr = _y16update;
2N/A _y16update = NULL;
2N/A } else
2N/A update_ptr = NULL;
2N/A#endif /* _VR3_COMPAT_CODE */
2N/A
2N/A if ((win->_cury >= win->_tmarg) && (win->_cury <= win->_bmarg))
2N/A endy = win->_bmarg + 1;
2N/A else
2N/A endy = win->_maxy;
2N/A
2N/A if (id < 0) {
2N/A /*
2N/A * Check that the amount of lines to delete aren't larger
2N/A * than the window. We save num_lines only so that we
2N/A * don't have to re-compute if the if comes out true.
2N/A */
2N/A
2N/A if ((num_lines = win->_cury - endy) > id)
2N/A id = num_lines;
2N/A
2N/A /*
2N/A * "fr" is the line that we are coming "fr"om and
2N/A * moving "to" the new place. This is the offset which
2N/A * we have to re-align our pointers by.
2N/A * We want to start setting the current line's pointer
2N/A * to point to the offset's line. We want to move line "fr"
2N/A * to line "to".
2N/A */
2N/A
2N/A to = win->_cury;
2N/A fr = to - id;
2N/A num_lines = endy - fr;
2N/A dir = 1;
2N/A } else {
2N/A /* can't insert more lines than are in the region */
2N/A if ((num_lines = endy - win->_cury) < id)
2N/A id = num_lines;
2N/A
2N/A to = endy - 1;
2N/A fr = to - id;
2N/A num_lines = fr - (win->_cury - 1);
2N/A dir = -1;
2N/A }
2N/A
2N/A /*
2N/A * If this window has no parents or children, then we can manipulate
2N/A * pointers to simulate insert/delete line. Otherwise,
2N/A * to propogate the changes to parents and siblings
2N/A * we have to memcpy the text around.
2N/A *
2N/A * Set quick to tell us which we have to do.
2N/A */
2N/A quick = ((win->_ndescs <= 0) && (win->_parent == NULL));
2N/A
2N/A begch = win->_firstch;
2N/A endch = win->_lastch;
2N/A endx = win->_maxx;
2N/A
2N/A for (; num_lines > 0; num_lines--, to += dir, fr += dir) {
2N/A /* can be done quickly */
2N/A if (quick) {
2N/A sw = win->_y[to];
2N/A win->_y[to] = win->_y[fr];
2N/A win->_y[fr] = sw;
2N/A if ((win == curscr) && _MARKS != NULL) {
2N/A mk = _MARKS[to];
2N/A _MARKS[to] = _MARKS[fr];
2N/A _MARKS[fr] = mk;
2N/A
2N/A /* for color terminal do the same for */
2N/A /* color marks */
2N/A
2N/A if (_COLOR_MARKS != NULL) {
2N/A mk = _COLOR_MARKS[to];
2N/A _COLOR_MARKS[to] = _COLOR_MARKS[fr];
2N/A _COLOR_MARKS[fr] = mk;
2N/A }
2N/A }
2N/A } else
2N/A /* slow update */
2N/A (void) memcpy((char *) win->_y[to], (char *)
2N/A win->_y[fr], (endx * sizeof (chtype)));
2N/A
2N/A
2N/A /*
2N/A * If this is curscr, the firstch[] and lastch[]
2N/A * arrays contain blank information.
2N/A */
2N/A
2N/A if (win == curscr) {
2N/A begch[to] = begch[fr];
2N/A endch[to] = endch[fr];
2N/A _CURHASH[to] = _CURHASH[fr];
2N/A } else {
2N/A /* regular window, update the change structure */
2N/A begch[to] = 0;
2N/A endch[to] = endx - 1;
2N/A }
2N/A }
2N/A
2N/A /* clear the insert/delete lines */
2N/A if (id < 0)
2N/A num_lines = endy - to;
2N/A else
2N/A num_lines = to - (win->_cury - 1);
2N/A
2N/A if (num_lines > 0) { /* Is this if needed ? */
2N/A savimmed = win->_immed;
2N/A savesync = win->_sync;
2N/A win->_immed = win->_sync = FALSE;
2N/A x = win->_curx;
2N/A y = win->_cury;
2N/A
2N/A win->_curx = 0;
2N/A for (; num_lines > 0; --num_lines, to += dir) {
2N/A /* LINTED */
2N/A win->_cury = (short) to;
2N/A (void) wclrtoeol(win);
2N/A }
2N/A
2N/A win->_curx = x;
2N/A win->_cury = y;
2N/A win->_immed = savimmed;
2N/A win->_sync = savesync;
2N/A }
2N/A win->_flags |= (_WINCHANGED|_WINSDEL);
2N/A
2N/A#ifdef _VR3_COMPAT_CODE
2N/A if (update_ptr) {
2N/A _y16update = update_ptr;
2N/A (*_y16update)(win, endy - y, endx, y, 0);
2N/A }
2N/A#endif /* _VR3_COMPAT_CODE */
2N/A
2N/A if (win->_sync)
2N/A wsyncup(win);
2N/A
2N/A return ((win != curscr && savimmed) ? wrefresh(win) : OK);
2N/A}