summaryrefslogtreecommitdiff
path: root/usr/src/lib/libeti/panel/common/update.c
blob: be103faeea659733c1ca1472112ccee6270bb8c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/


/*
 *      Copyright (c) 1997, by Sun Microsystems, Inc.
 *      All rights reserved.
 */

/* A panels subsystem built on curses--Update the pile of panels */

#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/

/*LINTLIBRARY*/

#include <sys/types.h>
#include <stdlib.h>
#include <curses.h>
#include "private.h"

/*
 * touch_top - Touch the line in all windows
 * which is visible above a given line
 */
static void
touch_top(PANEL *panel, int line, _obscured_list *obs, int start_x, int end_x)
{
	PANEL		*pnl;
	_obscured_list	*next_obs;

	do {
		pnl = obs -> panel_p;
		if ((next_obs = obs->next) == panel -> obscured -> next)
			next_obs = 0;

		if (line >= obs -> start && line <= obs -> end &&
		    pnl->wstartx <= end_x && pnl->wendx >= start_x) {
			(void) touchline(pnl->win, line - pnl->wstarty, 1);
			if (pnl->wstartx > start_x && pnl->wendx < end_x) {
				if (next_obs)
					touch_top(panel, line, next_obs,
					    pnl->wendx+1, end_x);
				end_x = pnl -> wstartx - 1;
			} else {
				if (pnl->wstartx <= start_x)
					start_x = pnl -> wendx + 1;
				if (pnl->wendx >= end_x)
					end_x = pnl -> wstartx - 1;
				if (start_x > end_x)
					return;
			}
		}
	}
	while ((obs = next_obs) != 0);
}

/*
 *  std_touch_top
 *  Touch the line in all windows which is visible above a given line.
 *  This routine is almost identical to touch_top, except that the "panel"
 *  is stdscr in this case.  The "obscured" list is the list of panels.
 */
static void
std_touch_top(int line, PANEL *obs_pnl, int start_x, int end_x)
{
	PANEL	*next_obs;

	do {
		next_obs = obs_pnl -> below;

		if (line >= obs_pnl->wstarty && line <= obs_pnl->wendy &&
		    obs_pnl->wstartx <= end_x && obs_pnl->wendx >= start_x) {
			(void) touchline(obs_pnl->win,
			    line - obs_pnl->wstarty, 1);
			if (obs_pnl->wstartx > start_x &&
			    obs_pnl->wendx < end_x) {
				if (next_obs)
					std_touch_top(line, next_obs,
					    obs_pnl->wendx+1, end_x);
				end_x = obs_pnl -> wstartx - 1;
			} else {
				if (obs_pnl->wstartx <= start_x)
					start_x = obs_pnl -> wendx + 1;
				if (obs_pnl->wendx >= end_x)
					end_x = obs_pnl -> wstartx - 1;
				if (start_x > end_x)
					return;
			}
		}
	}
	while ((obs_pnl = next_obs) != 0);
}

/* touchup - Touch lines in obscuring panals as necessary */
static void
touchup(PANEL *panel)
{
	int	screen_y, i;

	/*
	 * for each line in the window which has been touched,
	 * touch lines in panals above it.
	 */

	screen_y = panel->wendy;

	for (i = panel->wendy - panel->wstarty; i >= 0; screen_y--, i--) {
		if (is_linetouched(panel -> win, i) == TRUE)
			touch_top(panel, screen_y, panel->obscured->next,
			    panel->wstartx, panel->wendx);
	}
}

/*
 * std_touchup
 * Touch lines in obscuring panals as necessary.  This routine is
 * almost exactly like touchup, except that the "panel" is stdscr,
 * and the obscured list is the list of panels.
 */
static void
std_touchup(void)
{
	int	screen_y;

	/*
	 * for each line in stdscr which has been touched,
	 * touch lines in panals above it.
	 */

	for (screen_y = LINES - 1; screen_y >= 0; screen_y--) {
		if (is_linetouched(stdscr, screen_y) == TRUE)
			std_touch_top(screen_y, _Top_panel, 0, COLS - 1);
	}
}

/* update_panels - Refresh the pile of panels */
void
update_panels(void)
{
	PANEL	*panel;

	/*
	 * if stdscr has been touched, touch the visible lines
	 * in each panel.
	 */

	if (is_wintouched(stdscr)) {
	    if (_Bottom_panel)
		std_touchup();

	    (void) wnoutrefresh(stdscr);
	}

	/*
	 * Refresh panals starting at the bottom of the pile.
	 * If a line in a window has been touched, touch all
	 * corresponding lines in the obscuring windows.
	 */

	for (panel = _Bottom_panel; panel; panel = panel -> above) {
		if (is_wintouched(panel -> win)) {
			if (panel -> obscured)
				touchup(panel);
			(void) wnoutrefresh(panel -> win);
		}
	}
}