blob: c96e417a9a487951c4f575cefd4aff2ec4f83c1a [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020-2021,2023 Thomas E. Dickey *
3 * Copyright 1998-2008,2009 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
27 * authorization. *
28 ****************************************************************************/
29
30/****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
Steve Kondikae271bc2015-11-15 02:50:53 +010033 * and: Thomas E. Dickey 1996-on *
34 * and: Juergen Pfeifer 2008 *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053035 ****************************************************************************/
36
37/*
38** lib_delwin.c
39**
40** The routine delwin().
41**
42*/
43
44#include <curses.priv.h>
45
micky3879b9f5e72025-07-08 18:04:53 -040046MODULE_ID("$Id: lib_delwin.c,v 1.25 2023/10/21 11:12:44 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047
48static bool
49cannot_delete(WINDOW *win)
50{
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053051 bool result = TRUE;
micky3879b9f5e72025-07-08 18:04:53 -040052
53 if (IS_PAD(win)) {
54 result = FALSE;
55 } else {
56 WINDOWLIST *p;
57#if NCURSES_SP_FUNCS && defined(USE_SP_WINDOWLIST)
58 SCREEN *sp = _nc_screen_of(win);
Steve Kondikae271bc2015-11-15 02:50:53 +010059#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053060
micky3879b9f5e72025-07-08 18:04:53 -040061 for (each_window(SP_PARM, p)) {
62 if (&(p->win) == win) {
63 result = FALSE;
64 } else if (IS_SUBWIN(&(p->win))
65 && p->win._parent == win) {
66 result = TRUE;
67 break;
68 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053069 }
70 }
71 return result;
72}
73
74NCURSES_EXPORT(int)
75delwin(WINDOW *win)
76{
77 int result = ERR;
78
Steve Kondikae271bc2015-11-15 02:50:53 +010079 T((T_CALLED("delwin(%p)"), (void *) win));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053080
81 if (_nc_try_global(curses) == 0) {
82 if (win == 0
83 || cannot_delete(win)) {
84 result = ERR;
micky3879b9f5e72025-07-08 18:04:53 -040085 } else if (IS_PAD(win)) {
86 win->_parent = NULL;
87 result = _nc_freewin(win);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053088 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +010089#if NCURSES_SP_FUNCS
90 SCREEN *sp = _nc_screen_of(win);
91#endif
micky3879b9f5e72025-07-08 18:04:53 -040092 if (IS_SUBWIN(win)) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053093 touchwin(win->_parent);
micky3879b9f5e72025-07-08 18:04:53 -040094 } else if (CurScreen(SP_PARM) != 0) {
Steve Kondikae271bc2015-11-15 02:50:53 +010095 touchwin(CurScreen(SP_PARM));
micky3879b9f5e72025-07-08 18:04:53 -040096 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097 result = _nc_freewin(win);
98 }
99 _nc_unlock_global(curses);
100 }
101 returnCode(result);
102}