1 /* $OpenBSD: p_new.c,v 1.4 2001/01/22 18:02:09 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998,2000 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1995 * 33 * and: Eric S. Raymond <esr@snark.thyrsus.com> * 34 ****************************************************************************/ 35 36 /* p_new.c 37 * Creation of a new panel 38 */ 39 #include "panel.priv.h" 40 41 MODULE_ID("$From: p_new.c,v 1.6 2000/12/10 02:20:44 tom Exp $") 42 43 #ifdef TRACE 44 static char* stdscr_id; 45 static char* new_id; 46 #endif 47 48 /*+------------------------------------------------------------------------- 49 Get root (i.e. stdscr's) panel. 50 Establish the pseudo panel for stdscr if necessary. 51 --------------------------------------------------------------------------*/ 52 static PANEL* 53 root_panel(void) 54 { 55 if(_nc_stdscr_pseudo_panel == (PANEL*)0) 56 { 57 58 assert(stdscr && !_nc_bottom_panel && !_nc_top_panel); 59 _nc_stdscr_pseudo_panel = (PANEL*)malloc(sizeof(PANEL)); 60 if (_nc_stdscr_pseudo_panel != 0) { 61 PANEL* pan = _nc_stdscr_pseudo_panel; 62 WINDOW* win = stdscr; 63 pan->win = win; 64 pan->below = (PANEL*)0; 65 pan->above = (PANEL*)0; 66 #ifdef TRACE 67 if (!stdscr_id) 68 stdscr_id = strdup("stdscr"); 69 pan->user = stdscr_id; 70 #else 71 pan->user = (void*)0; 72 #endif 73 _nc_bottom_panel = _nc_top_panel = pan; 74 } 75 } 76 return _nc_stdscr_pseudo_panel; 77 } 78 79 NCURSES_EXPORT(PANEL *) 80 new_panel (WINDOW *win) 81 { 82 PANEL *pan = (PANEL*)0; 83 84 if (!win) 85 return(pan); 86 87 if (!_nc_stdscr_pseudo_panel) 88 (void)root_panel(); 89 assert(_nc_stdscr_pseudo_panel); 90 91 if (!(win->_flags & _ISPAD) && (pan = (PANEL*)malloc(sizeof(PANEL)))) 92 { 93 pan->win = win; 94 pan->above = (PANEL *)0; 95 pan->below = (PANEL *)0; 96 #ifdef TRACE 97 if (!new_id) 98 new_id = strdup("new"); 99 pan->user = new_id; 100 #else 101 pan->user = (char *)0; 102 #endif 103 (void)show_panel(pan); 104 } 105 return(pan); 106 } 107