ncurses 4.1
[ncurses.git] / ncurses / lib_delwin.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23 **      lib_delwin.c
24 **
25 **      The routine delwin().
26 **
27 */
28
29 #include <curses.priv.h>
30
31 MODULE_ID("$Id: lib_delwin.c,v 1.8 1997/02/01 23:22:54 tom Exp $")
32
33 static bool have_children(WINDOW *win)
34 {
35         WINDOWLIST *p;
36         for (p = _nc_windows; p != 0; p = p->next) {
37                 if (p->win->_flags & _SUBWIN
38                  && p->win->_parent == win)
39                         return TRUE;
40         }
41         return FALSE;
42 }
43
44 int delwin(WINDOW *win)
45 {
46         T((T_CALLED("delwin(%p)"), win));
47
48         if (win == 0
49          || have_children(win))
50                 returnCode(ERR);
51
52         if (win->_flags & _SUBWIN)
53                 touchwin(win->_parent);
54         else if (curscr != 0)
55                 touchwin(curscr);
56
57         _nc_freewin(win);
58
59         returnCode(OK);
60 }