2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 6/6/93";
47 * Higher level routines for dealing with windows.
49 * There are two types of windows: user window, and information window.
50 * User windows are the ones with a pty and shell. Information windows
51 * are for displaying error messages, and other information.
53 * The windows are doubly linked in overlapping order and divided into
54 * two groups: foreground and normal. Information
55 * windows are always foreground. User windows can be either.
56 * Addwin() adds a window to the list at the top of one of the two groups.
57 * Deletewin() deletes a window. Front() moves a window to the front
58 * of its group. Wwopen(), wwadd(), and wwdelete() should never be called
66 openwin(id, row, col, nrow, ncol, nline, label, haspty, hasframe, shf, sh)
68 char haspty, hasframe;
71 register struct ww *w;
73 if (id < 0 && (id = findid()) < 0)
75 if (row + nrow <= 0 || row > wwnrow - 1
76 || col + ncol <= 0 || col > wwncol - 1) {
77 error("Illegal window position.");
80 w = wwopen(haspty ? WWO_PTY : WWO_SOCKET, nrow, ncol, row, col, nline);
82 error("Can't open window: %s.", wwerror());
87 w->ww_hasframe = hasframe;
89 if (label != 0 && setlabel(w, label) < 0)
90 error("No memory for label.");
93 * We have to do this little maneuver to make sure
94 * addwin() puts w at the top, so we don't waste an
95 * insert and delete operation.
97 setselwin((struct ww *)0);
100 if (wwspawn(w, shf, sh) < 0) {
101 error("Can't execute %s: %s.", shf, wwerror());
112 for (i = 0; i < NWINDOW && window[i] != 0; i++)
115 error("Too many windows.");
124 register struct ww *w, *s = 0;
127 for (i = 0; i < NWINDOW; i++)
128 if ((w = window[i]) != 0 && w != selwin &&
130 !isfg(w) && (w->ww_order < s->ww_order || isfg(s))))
136 * Close a user window. Close all if w == 0.
139 register struct ww *w;
148 for (i = 0; i < NWINDOW; i++) {
149 if ((w = window[i]) == 0)
156 if (lastselwin != 0) {
157 setselwin(lastselwin);
159 } else if (w = findselwin())
161 if (lastselwin == 0 && selwin)
162 if (w = findselwin())
169 * Open an information (display) window.
172 openiwin(nrow, label)
175 register struct ww *w;
177 if ((w = wwopen(0, nrow, wwncol, 2, 0, 0)) == 0)
186 (void) setlabel(w, label);
193 * Close an information window.
203 register struct ww *w;
209 if (w->ww_id >= 0 && w->ww_id < NWINDOW)
210 window[w->ww_id] = 0;
212 str_free(w->ww_label);
218 * Move the window to the top of its group.
219 * Don't do it if already fully visible.
220 * Wwvisible() doesn't work for tinted windows.
221 * But anything to make it faster.
222 * Always reframe() if doreframe is true.
225 register struct ww *w;
228 if (w->ww_back != (isfg(w) ? framewin : fgwin) && !wwvisible(w)) {
238 * Add a window at the top of normal windows or foreground windows.
239 * For normal windows, we put it behind the current window.
242 register struct ww *w;
247 if (fgwin == framewin)
250 wwadd(w, selwin != 0 && selwin != w && !isfg(selwin)
258 register struct ww *w;
267 register struct ww *w;
270 for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
271 if (w->ww_hasframe) {
272 wwframe(w, framewin);
278 register struct ww *w;
280 int mode = w == selwin ? WWM_REV : 0;
287 buf[0] = w->ww_id + '1';
289 wwlabel(w, framewin, 1, buf, mode);
295 col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
299 wwlabel(w, framewin, col, w->ww_label, mode);
304 register struct ww *w;
306 if (w->ww_pty >= 0 && w->ww_ispty && wwstoptty(w->ww_pty) < 0)
307 error("Can't stop output: %s.", wwerror());
313 register struct ww *w;
315 if (w->ww_pty >= 0 && w->ww_ispty && wwstarttty(w->ww_pty) < 0)
316 error("Can't start output: %s.", wwerror());
321 sizewin(w, nrow, ncol)
322 register struct ww *w;
324 struct ww *back = w->ww_back;
326 w->ww_alt.nr = w->ww_w.nr;
327 w->ww_alt.nc = w->ww_w.nc;
329 if (wwsize(w, nrow, ncol) < 0)
330 error("Can't resize window: %s.", wwerror());
338 (void) waitnl1(w, "[Type any key to continue]");
342 register struct ww *w;
346 char uc = w->ww_unctrl;
348 if (!always && w->ww_cur.r < w->ww_w.b - 2)
350 c = waitnl1(w, "[Type escape to abort, any other key to continue]");
354 return c == ctrl('[') ? 2 : 1;
358 register struct ww *w;
361 char uc = w->ww_unctrl;
365 wwprintf(w, "\033Y%c%c\033sA%s\033rA ",
366 w->ww_w.nr - 1 + ' ', ' ', prompt); /* print on last line */
368 while (wwpeekc() < 0)