xref: /illumos-gate/usr/src/lib/libeti/panel/common/delete.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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--Delete panel routines */
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 /* hide_panel - Unlink a panel from the pile and remove it from the screen. */
43 int
44 hide_panel(PANEL *panel)
45 {
46 	if (!panel)
47 		return (ERR);
48 
49 	/* It is ok to hide a panel that is already hidden. */
50 
51 	if (panel == panel -> below)
52 		return (OK);
53 
54 	/* unlink panel */
55 
56 	_remove_overlap(panel);
57 	if (panel == _Bottom_panel)
58 		_Bottom_panel = panel -> above;
59 	else
60 		panel -> below -> above = panel -> above;
61 
62 	if (panel == _Top_panel)
63 		_Top_panel = panel -> below;
64 	else
65 		panel -> above -> below = panel -> below;
66 
67 	_Panel_cnt--;
68 	panel -> below = panel;
69 	return (OK);
70 }
71 
72 /*
73  * del_panel - Delete a panel from the pile
74  * and free all memory associated with it.
75  */
76 int
77 del_panel(PANEL *panel)
78 {
79 	return ((hide_panel(panel) == OK) ? free(panel), OK : ERR);
80 }
81 
82 /*
83  *  _remove_overlap
84  * Remove all references to a panel from the obscured lists of all panels.
85  * Also remove all obscured nodes from the given panel.  This routine
86  * touches the appropriate places to ensure that everybody is properly
87  * updated.
88  */
89 void
90 _remove_overlap(PANEL *panel)
91 {
92 	PANEL		*pnl;
93 	_obscured_list	*obs;
94 	_obscured_list	*prev_obs;
95 
96 	/* Make sure that the background gets updated */
97 
98 	(void) touchline(stdscr, panel->wstarty,
99 	    panel->wendy - panel->wstarty + 1);
100 
101 	/* Remove all references to the panel from the remaining panels */
102 
103 	for (pnl = _Bottom_panel; pnl != panel; pnl = pnl->above) {
104 		if (obs = _unlink_obs(pnl, panel))
105 			_free_overlap(obs);
106 	}
107 
108 	/* delete the obscured list from the panel */
109 
110 	if ((obs = panel -> obscured) != 0) {
111 		do {
112 			prev_obs = obs;
113 			obs = obs -> next;
114 			_free_overlap(prev_obs);
115 		}
116 		while (obs != panel -> obscured);
117 		panel -> obscured = 0;
118 	}
119 }
120