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
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.
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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 /* A panels subsystem built on curses--Miscellaneous routines */
33 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */
37 #include <sys/types.h>
46 static _obscured_list
*_Free_list
;
47 static int _Free_list_cnt
;
50 /* panel_window - Return the window pointer */
52 panel_window(PANEL
*panel
)
54 return (panel
? panel
-> win
: 0);
57 /* panel_userptr - Return the user pointer */
59 panel_userptr(PANEL
*panel
)
61 return (panel
? panel
-> user
: 0);
64 /* set_panel_userptr - set the user pointer */
66 set_panel_userptr(PANEL
*panel
, char *ptr
)
76 * panel_above - Return the panel above the
77 * given panel (or the bottom panel in 0)
80 panel_above(PANEL
*panel
)
84 return (_Bottom_panel
);
86 return ((panel
== panel
-> below
) ? ((PANEL
*) 0) : panel
-> above
);
91 * panel_below - Return the panel below the
92 * given panel (or the top panel in 0)
95 panel_below(PANEL
*panel
)
101 return ((panel
== panel
-> below
) ? ((PANEL
*) 0) : panel
-> below
);
104 /* panel_hidden - Return TRUE if the panel is hidden, FALSE if not. */
106 panel_hidden(PANEL
*panel
)
108 return ((!panel
|| (panel
!= panel
-> below
)) ? FALSE
: TRUE
);
111 /* _get_overlap - Get an overlap node from the free list. */
112 static _obscured_list
*
115 _obscured_list
*overlap
;
117 if (_Free_list_cnt
-- > 0) {
118 overlap
= _Free_list
;
119 _Free_list
= _Free_list
-> next
;
130 * _unlink_obs - Find the obscured node, if any,
131 * in the first panel which refers the second panel.
134 _unlink_obs(PANEL
*pnl
, PANEL
*panel
)
137 _obscured_list
*prev_obs
;
139 if (!pnl
-> obscured
|| !_panels_intersect(pnl
, panel
))
140 return ((_obscured_list
*) 0);
142 obs
= pnl
-> obscured
;
147 while (obs
->panel_p
!= panel
&& obs
!= pnl
->obscured
);
148 if (obs
-> panel_p
!= panel
) {
150 fprintf(stderr
, "_unlink_obs: Obscured panel lost\n");
152 return ((_obscured_list
*) 0);
158 prev_obs
-> next
= obs
-> next
;
159 if (obs
== pnl
-> obscured
)
160 pnl
-> obscured
= prev_obs
;
166 * add_obs - Add an obscured node to a panel, ensuring
167 * that the obscured list is ordered from top to bottom.
170 add_obs(PANEL
*panel
, _obscured_list
*obs
)
173 _obscured_list
*curr_obs
;
174 _obscured_list
*prev_obs
;
176 if ((prev_obs
= panel
-> obscured
) == 0) {
177 panel
-> obscured
= obs
-> next
= obs
;
181 curr_obs
= prev_obs
-> next
;
183 for (pnl
= _Top_panel
; pnl
!= panel
; pnl
= pnl
->below
) {
184 if (curr_obs
-> panel_p
== pnl
) {
186 curr_obs
= curr_obs
-> next
;
187 if (prev_obs
== panel
-> obscured
) {
188 panel
-> obscured
= obs
;
194 obs
-> next
= curr_obs
;
195 prev_obs
-> next
= obs
;
201 * Create an obscured node for each panel that the given panel intersects.
202 * The overlap record is always attached to the panel which is covered up.
204 * This routine assumes that _alloc_overlap() has been called to ensure
205 * that there are enough overlap nodes to satisfy the requests.
208 _intersect_panel(PANEL
*panel
)
216 for (pnl
= _Bottom_panel
; pnl
; pnl
= pnl
-> above
) {
222 if (!_panels_intersect(pnl
, panel
))
223 continue; /* no overlap */
225 obs
= _get_overlap();
226 obs
->start
= (panel
->wstarty
>= pnl
->wstarty
) ?
227 panel
->wstarty
: pnl
->wstarty
;
228 obs
->end
= (panel
->wendy
<= pnl
->wendy
) ?
229 panel
->wendy
: pnl
->wendy
;
232 obs
-> panel_p
= pnl
;
233 if (panel
-> obscured
) {
234 obs
-> next
= panel
-> obscured
-> next
;
235 panel
-> obscured
-> next
= obs
;
237 obs
-> next
= panel
-> obscured
= obs
;
239 obs
-> panel_p
= panel
;
248 * Create enough obscured nodes to record all overlaps of a given
249 * panel. The obscured nodes must be pre-allocated by this routine
250 * to preserve the integrity of the pile during move.
251 * If the move operation fails, the pile is supposed to remain
252 * unchanged. If the obscured nodes are not allocated in advance,
253 * then an allocation failure in the middle of a move could
254 * leave the pile in a corrupted state with possibly no way to
255 * restore the pile to its original state.
257 * The cnt parameter is the(worst case) number of overlap nodes which
258 * are required to satisfy any request. Return 0 on error, else non-zero
261 _alloc_overlap(int cnt
)
263 _obscured_list
*overlap
;
266 for (i
= cnt
-_Free_list_cnt
; i
> 0; i
--) {
267 if (!(overlap
= (_obscured_list
*)
268 malloc(sizeof (_obscured_list
))))
271 overlap
-> next
= _Free_list
;
272 _Free_list
= overlap
;
281 * _free_overlap - Free a single overlap node. Don't
282 * really free it; just save it on a list.
285 _free_overlap(_obscured_list
*overlap
)
287 overlap
-> next
= _Free_list
;
288 _Free_list
= overlap
;