1*c7ef0cfcSnicm /* $OpenBSD: p_new.c,v 1.6 2023/10/17 09:52:10 nicm Exp $ */
215fe46beSmillert
3d5238b59Smillert /****************************************************************************
4*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
5*c7ef0cfcSnicm * Copyright 1998-2009,2010 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> *
3581d8c4e1Snicm * and: Juergen Pfeifer 1997-1999 *
3681d8c4e1Snicm * and: Thomas E. Dickey 2000-on *
37d5238b59Smillert ****************************************************************************/
3815fe46beSmillert
3915fe46beSmillert /* p_new.c
4015fe46beSmillert * Creation of a new panel
4115fe46beSmillert */
4215fe46beSmillert #include "panel.priv.h"
4315fe46beSmillert
44*c7ef0cfcSnicm MODULE_ID("$Id: p_new.c,v 1.6 2023/10/17 09:52:10 nicm Exp $")
459ee63291Smillert
469ee63291Smillert #ifdef TRACE
479ee63291Smillert static char *stdscr_id;
489ee63291Smillert static char *new_id;
49*c7ef0cfcSnicm
50*c7ef0cfcSnicm static PANEL *
AllocPanel(const char * name)51*c7ef0cfcSnicm AllocPanel(const char *name)
52*c7ef0cfcSnicm {
53*c7ef0cfcSnicm PANEL *result = typeMalloc(PANEL, 1);
54*c7ef0cfcSnicm
55*c7ef0cfcSnicm _tracef("create :%s %p", name, (void *)result);
56*c7ef0cfcSnicm return result;
57*c7ef0cfcSnicm }
58*c7ef0cfcSnicm #define InitUser(name) \
59*c7ef0cfcSnicm if (!name ## _id) \
60*c7ef0cfcSnicm name ## _id = strdup(#name); \
61*c7ef0cfcSnicm pan->user = name ## _id; \
62*c7ef0cfcSnicm _tracef("create :user_ptr %p", pan->user)
63*c7ef0cfcSnicm #else
64*c7ef0cfcSnicm #define AllocPanel(name) typeMalloc(PANEL, 1)
65*c7ef0cfcSnicm #define InitUser(name) \
66*c7ef0cfcSnicm pan->user = (void *)0
679ee63291Smillert #endif
6815fe46beSmillert
6915fe46beSmillert /*+-------------------------------------------------------------------------
7015fe46beSmillert Get root (i.e. stdscr's) panel.
7115fe46beSmillert Establish the pseudo panel for stdscr if necessary.
7215fe46beSmillert --------------------------------------------------------------------------*/
7315fe46beSmillert static PANEL *
root_panel(NCURSES_SP_DCL0)74*c7ef0cfcSnicm root_panel(NCURSES_SP_DCL0)
7515fe46beSmillert {
76*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
77*c7ef0cfcSnicm struct panelhook *ph = NCURSES_SP_NAME(_nc_panelhook) (sp);
78*c7ef0cfcSnicm
79*c7ef0cfcSnicm #elif NO_LEAKS
80*c7ef0cfcSnicm struct panelhook *ph = _nc_panelhook();
81*c7ef0cfcSnicm #endif
82*c7ef0cfcSnicm
8315fe46beSmillert if (_nc_stdscr_pseudo_panel == (PANEL *)0)
8415fe46beSmillert {
8515fe46beSmillert
86*c7ef0cfcSnicm assert(SP_PARM && SP_PARM->_stdscr && !_nc_bottom_panel && !_nc_top_panel);
8781d8c4e1Snicm #if NO_LEAKS
88*c7ef0cfcSnicm ph->destroy = del_panel;
8981d8c4e1Snicm #endif
90*c7ef0cfcSnicm _nc_stdscr_pseudo_panel = AllocPanel("root_panel");
9181d8c4e1Snicm if (_nc_stdscr_pseudo_panel != 0)
9281d8c4e1Snicm {
9315fe46beSmillert PANEL *pan = _nc_stdscr_pseudo_panel;
94*c7ef0cfcSnicm WINDOW *win = SP_PARM->_stdscr;
9581d8c4e1Snicm
9615fe46beSmillert pan->win = win;
9715fe46beSmillert pan->below = (PANEL *)0;
9815fe46beSmillert pan->above = (PANEL *)0;
99*c7ef0cfcSnicm InitUser(stdscr);
1009ee63291Smillert _nc_bottom_panel = _nc_top_panel = pan;
10115fe46beSmillert }
10215fe46beSmillert }
10315fe46beSmillert return _nc_stdscr_pseudo_panel;
10415fe46beSmillert }
10515fe46beSmillert
106*c7ef0cfcSnicm PANEL_EXPORT(PANEL *)
new_panel(WINDOW * win)10715fe46beSmillert new_panel(WINDOW *win)
10815fe46beSmillert {
10915fe46beSmillert PANEL *pan = (PANEL *)0;
11015fe46beSmillert
111*c7ef0cfcSnicm GetWindowHook(win);
112*c7ef0cfcSnicm
113*c7ef0cfcSnicm T((T_CALLED("new_panel(%p)"), (void *)win));
11481d8c4e1Snicm
1159ee63291Smillert if (!win)
11681d8c4e1Snicm returnPanel(pan);
1179ee63291Smillert
1189ee63291Smillert if (!_nc_stdscr_pseudo_panel)
119*c7ef0cfcSnicm (void)root_panel(NCURSES_SP_ARG);
12015fe46beSmillert assert(_nc_stdscr_pseudo_panel);
12115fe46beSmillert
122*c7ef0cfcSnicm if ((pan = AllocPanel("new_panel")) != NULL)
12315fe46beSmillert {
12415fe46beSmillert pan->win = win;
12515fe46beSmillert pan->above = (PANEL *)0;
12615fe46beSmillert pan->below = (PANEL *)0;
127*c7ef0cfcSnicm InitUser(new);
12815fe46beSmillert (void)show_panel(pan);
12915fe46beSmillert }
13081d8c4e1Snicm returnPanel(pan);
13115fe46beSmillert }
132