p_new.c revision 302408
1219820Sjeff/****************************************************************************
2219820Sjeff * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
3219820Sjeff *                                                                          *
4219820Sjeff * Permission is hereby granted, free of charge, to any person obtaining a  *
5219820Sjeff * copy of this software and associated documentation files (the            *
6219820Sjeff * "Software"), to deal in the Software without restriction, including      *
7219820Sjeff * without limitation the rights to use, copy, modify, merge, publish,      *
8219820Sjeff * distribute, distribute with modifications, sublicense, and/or sell       *
9219820Sjeff * copies of the Software, and to permit persons to whom the Software is    *
10219820Sjeff * furnished to do so, subject to the following conditions:                 *
11219820Sjeff *                                                                          *
12219820Sjeff * The above copyright notice and this permission notice shall be included  *
13219820Sjeff * in all copies or substantial portions of the Software.                   *
14219820Sjeff *                                                                          *
15219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16219820Sjeff * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18219820Sjeff * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19219820Sjeff * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20219820Sjeff * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21219820Sjeff * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22219820Sjeff *                                                                          *
23219820Sjeff * Except as contained in this notice, the name(s) of the above copyright   *
24219820Sjeff * holders shall not be used in advertising or otherwise to promote the     *
25219820Sjeff * sale, use or other dealings in this Software without prior written       *
26219820Sjeff * authorization.                                                           *
27219820Sjeff ****************************************************************************/
28219820Sjeff
29219820Sjeff/****************************************************************************
30219820Sjeff *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1995                    *
31219820Sjeff *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32219820Sjeff *     and: Juergen Pfeifer                         1997-1999               *
33219820Sjeff *     and: Thomas E. Dickey                        2000-on                 *
34219820Sjeff ****************************************************************************/
35219820Sjeff
36219820Sjeff/* p_new.c
37219820Sjeff * Creation of a new panel
38219820Sjeff */
39219820Sjeff#include "panel.priv.h"
40219820Sjeff
41219820SjeffMODULE_ID("$Id: p_new.c,v 1.16 2010/01/23 21:22:16 tom Exp $")
42219820Sjeff
43219820Sjeff#ifdef TRACE
44219820Sjeffstatic char *stdscr_id;
45219820Sjeffstatic char *new_id;
46219820Sjeff#endif
47219820Sjeff
48219820Sjeff/*+-------------------------------------------------------------------------
49219820Sjeff  Get root (i.e. stdscr's) panel.
50219820Sjeff  Establish the pseudo panel for stdscr if necessary.
51219820Sjeff--------------------------------------------------------------------------*/
52219820Sjeffstatic PANEL *
53219820Sjeffroot_panel(NCURSES_SP_DCL0)
54219820Sjeff{
55219820Sjeff#if NCURSES_SP_FUNCS
56219820Sjeff  struct panelhook *ph = NCURSES_SP_NAME(_nc_panelhook) (sp);
57219820Sjeff
58219820Sjeff#elif NO_LEAKS
59219820Sjeff  struct panelhook *ph = _nc_panelhook();
60219820Sjeff#endif
61219820Sjeff
62219820Sjeff  if (_nc_stdscr_pseudo_panel == (PANEL *) 0)
63219820Sjeff    {
64219820Sjeff
65219820Sjeff      assert(SP_PARM && SP_PARM->_stdscr && !_nc_bottom_panel && !_nc_top_panel);
66219820Sjeff#if NO_LEAKS
67219820Sjeff      ph->destroy = del_panel;
68219820Sjeff#endif
69219820Sjeff      _nc_stdscr_pseudo_panel = typeMalloc(PANEL, 1);
70219820Sjeff      if (_nc_stdscr_pseudo_panel != 0)
71219820Sjeff	{
72219820Sjeff	  PANEL *pan = _nc_stdscr_pseudo_panel;
73219820Sjeff	  WINDOW *win = SP_PARM->_stdscr;
74219820Sjeff
75219820Sjeff	  pan->win = win;
76219820Sjeff	  pan->below = (PANEL *) 0;
77219820Sjeff	  pan->above = (PANEL *) 0;
78219820Sjeff#ifdef TRACE
79219820Sjeff	  if (!stdscr_id)
80219820Sjeff	    stdscr_id = strdup("stdscr");
81219820Sjeff	  pan->user = stdscr_id;
82219820Sjeff#else
83219820Sjeff	  pan->user = (void *)0;
84219820Sjeff#endif
85219820Sjeff	  _nc_bottom_panel = _nc_top_panel = pan;
86219820Sjeff	}
87219820Sjeff    }
88219820Sjeff  return _nc_stdscr_pseudo_panel;
89219820Sjeff}
90219820Sjeff
91219820SjeffNCURSES_EXPORT(PANEL *)
92219820Sjeffnew_panel(WINDOW *win)
93219820Sjeff{
94219820Sjeff  PANEL *pan = (PANEL *) 0;
95219820Sjeff
96219820Sjeff  GetWindowHook(win);
97219820Sjeff
98219820Sjeff  T((T_CALLED("new_panel(%p)"), (void *)win));
99219820Sjeff
100219820Sjeff  if (!win)
101219820Sjeff    returnPanel(pan);
102219820Sjeff
103219820Sjeff  if (!_nc_stdscr_pseudo_panel)
104219820Sjeff    (void)root_panel(NCURSES_SP_ARG);
105219820Sjeff  assert(_nc_stdscr_pseudo_panel);
106219820Sjeff
107219820Sjeff  if (!(win->_flags & _ISPAD) && (pan = typeMalloc(PANEL, 1)))
108219820Sjeff    {
109219820Sjeff      pan->win = win;
110219820Sjeff      pan->above = (PANEL *) 0;
111219820Sjeff      pan->below = (PANEL *) 0;
112219820Sjeff#ifdef TRACE
113219820Sjeff      if (!new_id)
114219820Sjeff	new_id = strdup("new");
115219820Sjeff      pan->user = new_id;
116219820Sjeff#else
117219820Sjeff      pan->user = (char *)0;
118219820Sjeff#endif
119219820Sjeff      (void)show_panel(pan);
120219820Sjeff    }
121219820Sjeff  returnPanel(pan);
122219820Sjeff}
123219820Sjeff