xref: /titanic_52/usr/src/lib/libeti/panel/common/new.c (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28  *      All rights reserved.
29  */
30 
31 /* A panels subsystem built on curses--create a new panel */
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
34 
35 /*LINTLIBRARY*/
36 
37 #include <sys/types.h>
38 #include <stdlib.h>
39 #include <curses.h>
40 #include "private.h"
41 
42 /* add_top - Put a new or hidden panel on top of the pile */
43 static void
44 add_top(PANEL *panel)
45 {
46 	if (!_Top_panel) {
47 		panel-> below = 0;
48 		_Bottom_panel = panel;
49 	} else {
50 		_Top_panel -> above = panel;
51 		panel -> below = _Top_panel;
52 	}
53 
54 	_Top_panel = panel;
55 	panel -> above = 0;
56 	panel -> obscured = 0;
57 	_Panel_cnt++;
58 
59 	/* Determine which panels the new panel obscures */
60 
61 	_intersect_panel(panel);
62 }
63 
64 /*  new_panel    */
65 PANEL *
66 new_panel(WINDOW *window)
67 {
68 	PANEL	*panel;
69 	int	lines, cols;
70 
71 	/* create a panel */
72 
73 	if (!window || !_alloc_overlap(_Panel_cnt) ||
74 	    !(panel = (PANEL *) malloc(sizeof (PANEL))))
75 		return ((PANEL *) 0);
76 
77 	panel -> win = window;
78 	getbegyx(window, panel -> wstarty, panel -> wstartx);
79 	getmaxyx(window, lines, cols);
80 	panel -> wendy = panel->wstarty + lines - 1;
81 	panel -> wendx = panel->wstartx + cols - 1;
82 	panel -> user = 0;
83 
84 	/* put the new panel on top of the pile */
85 
86 	add_top(panel);
87 	return (panel);
88 }
89 
90 /*  show_panel    */
91 int
92 show_panel(PANEL *panel)
93 {
94 	/* Allocate the obscured nodes for the new panel */
95 
96 	if (!panel || panel != panel -> below || !_alloc_overlap(_Panel_cnt))
97 		return (ERR);
98 
99 	/* put the new panel on top of the pile */
100 
101 	add_top(panel);
102 	(void) touchwin(panel -> win);
103 	return (OK);
104 }
105