summaryrefslogtreecommitdiff
path: root/usr/src/cmd/fmli/vt/vflush.c
blob: 9a75b1b9769d473e4a0771184c7ab22adc25fd92 (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * 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 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include	<curses.h>
#include	"wish.h"
#include	"vt.h"
#include	"vtdefs.h"
#include	"attrs.h"
#include	"color_pair.h"

extern int Refresh_slks;

extern int Color_terminal;
static void vt_title();
static void vt_scroll_arrow();
static void vt_page_arrow();
static void vt_display(void);

void
vt_flush()
{
/*
	_debug3(stderr, "\t--==[ FLUSHING ]==--\n");
*/
	vt_display();
	if (Refresh_slks) {
		Refresh_slks = 0;
		slk_restore();	
	}
	if (VT_front >= 0)
		wnoutrefresh(VT_array[VT_front].win);
	doupdate();
/*
	_debug3(stderr, "\t--==[ FINISHED ]==--\n");
*/
}

static void
vt_display(void)
{
	register struct vt	*v;
	int colattr;
	vt_id	vid;

	for ( vid = VT_back; vid != VT_UNDEFINED; vid = v->prev )
	{
		v = &VT_array[vid];

		if ( !(v->flags & VT_ANYDIRTY))
			continue;
	
		if (!(v->flags & VT_NOBORDER)) {
			int	row, col;
	
			if (v->flags & VT_BDIRTY)	/* border dirty */
			{
				getyx(v->win, row, col);
				if (vid == VT_curid)
					colattr = ACTIVE_BORD_PAIR;
				else
					colattr = INACTIVE_BORD_PAIR;
				wattrset(v->win, COL_ATTR(A_NORMAL, colattr));
				box(v->win, 0, 0);
				wattrset(v->win, COL_ATTR(A_NORMAL, WINDOW_PAIR));
				v->flags |= VT_TDIRTY | VT_PADIRTY | VT_SADIRTY;
				wmove(v->win, row, col);
			}

			if (v->flags & VT_TDIRTY)	/* title dirty */
			{
				getyx(v->win, row, col);
				if (vid == VT_curid)
					vt_title(v, TRUE);
				else
					vt_title(v, FALSE);
				wmove(v->win, row, col);
			}

			if (v->flags & VT_PADIRTY)	/* page arrow dirty */
			{
				getyx(v->win, row, col);
				if (vid == VT_curid)
					vt_page_arrow(v, TRUE);
				else
					vt_page_arrow(v, FALSE);
				wmove(v->win, row, col);
			}
			if (v->flags & VT_SADIRTY)	/* scroll arrow dirty */
			{
				getyx(v->win, row, col);
				if (vid == VT_curid)
					vt_scroll_arrow(v, TRUE);
				else
					vt_scroll_arrow(v, FALSE);
				wmove(v->win, row, col);
			}
		}
		{
			int	sr1, sc1, r1, c1;
			int	sr2, sc2, r2, c2;
			register vt_id	ov;
			register struct vt	*vp;
/*	
			_debug3(stderr, "flushing %d(#%d) flags = 0x%x\n", vid, v->number, v->flags);
*/
			wnoutrefresh(v->win);
			getbegyx(v->win, sr1, sc1);
			getmaxyx(v->win, r1, c1);
			for (ov = VT_front; ov != vid; ov = vp->next) {
				vp = &VT_array[ov];
				getbegyx(vp->win, sr2, sc2);
				getmaxyx(vp->win, r2, c2);
				if (_vt_overlap(sr1, r1, sr2, r2) && _vt_overlap(sc1, c1, sc2, c2))
					vp->flags |= VT_BDIRTY;
			}
		v->flags &= ~VT_ANYDIRTY;
		}
        }
}

static void
vt_scroll_arrow(v, active_flag)
register struct vt	*v;
int active_flag;
{
	int	r;
	int	c;
	int	colattr;

	getmaxyx(v->win, r, c);
	wmove(v->win, r - 1, c - 4);
	if (active_flag == TRUE)
		colattr = ACTIVE_BORD_PAIR;
	else
		colattr = INACTIVE_BORD_PAIR;
	wattrset(v->win, COL_ATTR(A_NORMAL, colattr));
	if (v->flags & VT_UPSARROW)
		waddch(v->win, ACS_UARROW);
	else
		waddch(v->win, ACS_HLINE);
	if (v->flags & VT_DNSARROW)
		waddch(v->win, ACS_DARROW);
	else
		waddch(v->win, ACS_HLINE);
	wattrset(v->win, COL_ATTR(A_NORMAL, WINDOW_PAIR));
}

static void
vt_page_arrow(v, active_flag)
register struct vt	*v;
int active_flag;
{
	int	row, col;
	int	colattr;

	getmaxyx(v->win, row, col);
	if (row < 5)
		return;	     /* frame too small */
	if (active_flag) {
		if (!Pair_set[ACTIVE_SCROLL_PAIR] && Pair_set[ACTIVE_TITLE_PAIR])
			colattr = ACTIVE_TITLE_PAIR;
		else
			colattr = ACTIVE_SCROLL_PAIR;
		wattrset(v->win, COL_ATTR(Attr_highlight, colattr));
	}
	else {
		if (!Pair_set[INACTIVE_SCROLL_PAIR] && Pair_set[INACTIVE_TITLE_PAIR])
			colattr = INACTIVE_TITLE_PAIR;
		else
			colattr = INACTIVE_SCROLL_PAIR;
		wattrset(v->win, COL_ATTR(Attr_hide, colattr));
	}
	wmove(v->win, (row /= 2) - 1, col - 1);
	if (v->flags & VT_UPPARROW)
		waddch(v->win, ACS_UARROW);
	else
		waddch(v->win, ' ');
	wmove(v->win, row, col - 1);
	waddch(v->win, ' ');
	wmove(v->win, row + 1, col - 1);
	if (v->flags & VT_DNPARROW)
		waddch(v->win, ACS_DARROW);
	else
		waddch(v->win, ' ');
	wattrset(v->win, COL_ATTR(A_NORMAL, WINDOW_PAIR));
}

static void
vt_title(v, active_flag)
register struct vt	*v;
int	active_flag;
{
	register char	*s;
	int	c;
	int	dummy;
	int	bl;
	int	const_cols;

	if ((s = v->title) == NULL)
		s = nil;
	getmaxyx(v->win, dummy, c);

	/*
	 * const_cols is # of columns taken up by corners and by number 
	 * displayed on title line
	 */
	if (v->number > 0)
		const_cols = 5;
	else
		const_cols = 2;
	bl = (c - const_cols) / 2 - (strlen(v->title) + 1) / 2;
	if (bl < 0)
		bl = 0;
	c -= bl + const_cols;
	if (active_flag)
		wattrset(v->win, COL_ATTR(Attr_highlight, ACTIVE_TITLE_PAIR));
	else
		wattrset(v->win, COL_ATTR(Attr_hide, INACTIVE_TITLE_PAIR));
	wmove(v->win, 0, 1);
	if (v->number > 0)
/* abs: changed wprintw to wprintf in following 2 calls */
		wprintw(v->win, "%2d %*s%-*.*s", v->number, bl, "", c, c, s);
	else
		wprintw(v->win, "%*s%-*.*s", bl, "", c, c, s);
	wattrset(v->win, COL_ATTR(A_NORMAL, WINDOW_PAIR));
}