xref: /openbsd-src/lib/libpanel/p_above.c (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /* $OpenBSD: p_above.c,v 1.6 2023/10/17 09:52:10 nicm Exp $ */
215fe46beSmillert 
3d5238b59Smillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2020 Thomas E. Dickey                                          *
5*c7ef0cfcSnicm  * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
615fe46beSmillert  *                                                                          *
7d5238b59Smillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
8d5238b59Smillert  * copy of this software and associated documentation files (the            *
9d5238b59Smillert  * "Software"), to deal in the Software without restriction, including      *
10d5238b59Smillert  * without limitation the rights to use, copy, modify, merge, publish,      *
11d5238b59Smillert  * distribute, distribute with modifications, sublicense, and/or sell       *
12d5238b59Smillert  * copies of the Software, and to permit persons to whom the Software is    *
13d5238b59Smillert  * furnished to do so, subject to the following conditions:                 *
1415fe46beSmillert  *                                                                          *
15d5238b59Smillert  * The above copyright notice and this permission notice shall be included  *
16d5238b59Smillert  * in all copies or substantial portions of the Software.                   *
1715fe46beSmillert  *                                                                          *
18d5238b59Smillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19d5238b59Smillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20d5238b59Smillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21d5238b59Smillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22d5238b59Smillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23d5238b59Smillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24d5238b59Smillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2515fe46beSmillert  *                                                                          *
26d5238b59Smillert  * Except as contained in this notice, the name(s) of the above copyright   *
27d5238b59Smillert  * holders shall not be used in advertising or otherwise to promote the     *
28d5238b59Smillert  * sale, use or other dealings in this Software without prior written       *
29d5238b59Smillert  * authorization.                                                           *
30d5238b59Smillert  ****************************************************************************/
31d5238b59Smillert 
32d5238b59Smillert /****************************************************************************
33d5238b59Smillert  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1995                    *
34d5238b59Smillert  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
35*c7ef0cfcSnicm  *     and: Juergen Pfeifer                         1997-1999,2008          *
36d5238b59Smillert  ****************************************************************************/
3715fe46beSmillert 
3815fe46beSmillert /* p_above.c
3915fe46beSmillert  */
4015fe46beSmillert #include "panel.priv.h"
4115fe46beSmillert 
42*c7ef0cfcSnicm MODULE_ID("$Id: p_above.c,v 1.6 2023/10/17 09:52:10 nicm Exp $")
4315fe46beSmillert 
44*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
PANEL_EXPORT(PANEL *)45*c7ef0cfcSnicm PANEL_EXPORT(PANEL *)
46*c7ef0cfcSnicm ground_panel(SCREEN * sp)
4715fe46beSmillert {
48*c7ef0cfcSnicm   T((T_CALLED("ground_panel(%p)"), (void *)sp));
49*c7ef0cfcSnicm   if (sp)
5015fe46beSmillert     {
51*c7ef0cfcSnicm       struct panelhook *ph = NCURSES_SP_NAME(_nc_panelhook) (sp);
52*c7ef0cfcSnicm 
53*c7ef0cfcSnicm       if (_nc_bottom_panel)	/* this is the pseudo panel */
54*c7ef0cfcSnicm 	returnPanel(_nc_bottom_panel->above);
55*c7ef0cfcSnicm       else
56*c7ef0cfcSnicm 	returnPanel(0);
5715fe46beSmillert     }
5815fe46beSmillert   else
59*c7ef0cfcSnicm     {
60*c7ef0cfcSnicm       if (0 == CURRENT_SCREEN)
61*c7ef0cfcSnicm 	returnPanel(0);
62*c7ef0cfcSnicm       else
63*c7ef0cfcSnicm 	returnPanel(ground_panel(CURRENT_SCREEN));
64*c7ef0cfcSnicm     }
65*c7ef0cfcSnicm }
66*c7ef0cfcSnicm #endif
67*c7ef0cfcSnicm 
68*c7ef0cfcSnicm PANEL_EXPORT(PANEL *)
panel_above(const PANEL * pan)69*c7ef0cfcSnicm panel_above(const PANEL * pan)
70*c7ef0cfcSnicm {
71*c7ef0cfcSnicm   PANEL *result;
72*c7ef0cfcSnicm 
73*c7ef0cfcSnicm   T((T_CALLED("panel_above(%p)"), (const void *)pan));
74*c7ef0cfcSnicm   if (pan)
75*c7ef0cfcSnicm     result = pan->above;
76*c7ef0cfcSnicm   else
77*c7ef0cfcSnicm     {
78*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
79*c7ef0cfcSnicm       result = ground_panel(CURRENT_SCREEN);
80*c7ef0cfcSnicm #else
81*c7ef0cfcSnicm       /* if top and bottom are equal, we have no or only the pseudo panel;
82*c7ef0cfcSnicm          if not, we return the panel above the pseudo panel */
83*c7ef0cfcSnicm       result = EMPTY_STACK()? (PANEL *) 0 : _nc_bottom_panel->above;
84*c7ef0cfcSnicm #endif
85*c7ef0cfcSnicm     }
86*c7ef0cfcSnicm   returnPanel(result);
8715fe46beSmillert }
88