xref: /dflybsd-src/contrib/ncurses/panel/p_above.c (revision 0cadad7e49c6219b0de0675ef6a6f44683d177d4)
1fdd4e1e0SJan Lentfer /****************************************************************************
2*32bb5217SDaniel Fojt  * Copyright 2020 Thomas E. Dickey                                          *
3*32bb5217SDaniel Fojt  * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
4fdd4e1e0SJan Lentfer  *                                                                          *
5fdd4e1e0SJan Lentfer  * Permission is hereby granted, free of charge, to any person obtaining a  *
6fdd4e1e0SJan Lentfer  * copy of this software and associated documentation files (the            *
7fdd4e1e0SJan Lentfer  * "Software"), to deal in the Software without restriction, including      *
8fdd4e1e0SJan Lentfer  * without limitation the rights to use, copy, modify, merge, publish,      *
9fdd4e1e0SJan Lentfer  * distribute, distribute with modifications, sublicense, and/or sell       *
10fdd4e1e0SJan Lentfer  * copies of the Software, and to permit persons to whom the Software is    *
11fdd4e1e0SJan Lentfer  * furnished to do so, subject to the following conditions:                 *
12fdd4e1e0SJan Lentfer  *                                                                          *
13fdd4e1e0SJan Lentfer  * The above copyright notice and this permission notice shall be included  *
14fdd4e1e0SJan Lentfer  * in all copies or substantial portions of the Software.                   *
15fdd4e1e0SJan Lentfer  *                                                                          *
16fdd4e1e0SJan Lentfer  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17fdd4e1e0SJan Lentfer  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18fdd4e1e0SJan Lentfer  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19fdd4e1e0SJan Lentfer  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20fdd4e1e0SJan Lentfer  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21fdd4e1e0SJan Lentfer  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22fdd4e1e0SJan Lentfer  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23fdd4e1e0SJan Lentfer  *                                                                          *
24fdd4e1e0SJan Lentfer  * Except as contained in this notice, the name(s) of the above copyright   *
25fdd4e1e0SJan Lentfer  * holders shall not be used in advertising or otherwise to promote the     *
26fdd4e1e0SJan Lentfer  * sale, use or other dealings in this Software without prior written       *
27fdd4e1e0SJan Lentfer  * authorization.                                                           *
28fdd4e1e0SJan Lentfer  ****************************************************************************/
29fdd4e1e0SJan Lentfer 
30fdd4e1e0SJan Lentfer /****************************************************************************
31fdd4e1e0SJan Lentfer  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1995                    *
32fdd4e1e0SJan Lentfer  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
3300d8f3c4SJohn Marino  *     and: Juergen Pfeifer                         1997-1999,2008          *
34fdd4e1e0SJan Lentfer  ****************************************************************************/
35fdd4e1e0SJan Lentfer 
36fdd4e1e0SJan Lentfer /* p_above.c
37fdd4e1e0SJan Lentfer  */
38fdd4e1e0SJan Lentfer #include "panel.priv.h"
39fdd4e1e0SJan Lentfer 
40*32bb5217SDaniel Fojt MODULE_ID("$Id: p_above.c,v 1.10 2020/02/02 23:34:34 tom Exp $")
4100d8f3c4SJohn Marino 
4200d8f3c4SJohn Marino #if NCURSES_SP_FUNCS
NCURSES_EXPORT(PANEL *)4300d8f3c4SJohn Marino NCURSES_EXPORT(PANEL *)
4400d8f3c4SJohn Marino ground_panel(SCREEN * sp)
4500d8f3c4SJohn Marino {
463468e90cSJohn Marino   T((T_CALLED("ground_panel(%p)"), (void *)sp));
4700d8f3c4SJohn Marino   if (sp)
4800d8f3c4SJohn Marino     {
4900d8f3c4SJohn Marino       struct panelhook *ph = NCURSES_SP_NAME(_nc_panelhook) (sp);
5000d8f3c4SJohn Marino 
5100d8f3c4SJohn Marino       if (_nc_bottom_panel)	/* this is the pseudo panel */
5200d8f3c4SJohn Marino 	returnPanel(_nc_bottom_panel->above);
5300d8f3c4SJohn Marino       else
5400d8f3c4SJohn Marino 	returnPanel(0);
5500d8f3c4SJohn Marino     }
5600d8f3c4SJohn Marino   else
5700d8f3c4SJohn Marino     {
5800d8f3c4SJohn Marino       if (0 == CURRENT_SCREEN)
5900d8f3c4SJohn Marino 	returnPanel(0);
6000d8f3c4SJohn Marino       else
6100d8f3c4SJohn Marino 	returnPanel(ground_panel(CURRENT_SCREEN));
6200d8f3c4SJohn Marino     }
6300d8f3c4SJohn Marino }
6400d8f3c4SJohn Marino #endif
65fdd4e1e0SJan Lentfer 
66fdd4e1e0SJan Lentfer NCURSES_EXPORT(PANEL *)
panel_above(const PANEL * pan)67fdd4e1e0SJan Lentfer panel_above(const PANEL * pan)
68fdd4e1e0SJan Lentfer {
6900d8f3c4SJohn Marino   PANEL *result;
7000d8f3c4SJohn Marino 
7100d8f3c4SJohn Marino   T((T_CALLED("panel_above(%p)"), (const void *)pan));
7200d8f3c4SJohn Marino   if (pan)
7300d8f3c4SJohn Marino     result = pan->above;
7400d8f3c4SJohn Marino   else
75fdd4e1e0SJan Lentfer     {
7600d8f3c4SJohn Marino #if NCURSES_SP_FUNCS
7700d8f3c4SJohn Marino       result = ground_panel(CURRENT_SCREEN);
7800d8f3c4SJohn Marino #else
79fdd4e1e0SJan Lentfer       /* if top and bottom are equal, we have no or only the pseudo panel;
80fdd4e1e0SJan Lentfer          if not, we return the panel above the pseudo panel */
8100d8f3c4SJohn Marino       result = EMPTY_STACK()? (PANEL *) 0 : _nc_bottom_panel->above;
8200d8f3c4SJohn Marino #endif
83fdd4e1e0SJan Lentfer     }
8400d8f3c4SJohn Marino   returnPanel(result);
85fdd4e1e0SJan Lentfer }
86