1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 *
31 ****************************************************************************/
34 * This is an extension to the curses library. It provides callers with a hook
35 * into the NCURSES data to resize windows, primarily for use by programs
36 * running in an X Window terminal (e.g., xterm). I abstracted this module
37 * from my application library for NCURSES because it must be compiled with
38 * the private data structures -- T.Dickey 1995/7/4.
41 #include <curses.priv.h>
44 MODULE_ID("$Id: resizeterm.c,v 1.6 1998/02/11 12:13:55 tom Exp $")
47 * This function reallocates NCURSES window structures. It is invoked in
48 * response to a SIGWINCH interrupt. Other user-defined windows may also need
51 * Because this performs memory allocation, it should not (in general) be
52 * invoked directly from the signal handler.
55 resizeterm(int ToLines, int ToCols)
57 int stolen = screen_lines - SP->_lines_avail;
58 int bottom = screen_lines + SP->_topstolen - stolen;
60 T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
62 screen_lines, screen_columns));
64 SP->_sig_winch = FALSE;
66 if (ToLines != screen_lines
67 || ToCols != screen_columns) {
71 ungetch(KEY_RESIZE); /* so application can know this */
72 clearok(curscr, TRUE); /* screen contents is unknown */
75 for (wp = _nc_windows; wp != 0; wp = wp->next) {
76 WINDOW *win = wp->win;
77 int myLines = win->_maxy + 1;
78 int myCols = win->_maxx + 1;
80 /* pads aren't treated this way */
81 if (win->_flags & _ISPAD)
84 if (win->_begy >= bottom) {
85 win->_begy += (ToLines - screen_lines);
87 if (myLines == screen_lines - stolen
88 && ToLines != screen_lines)
89 myLines = ToLines - stolen;
91 if (myLines == screen_lines
92 && ToLines != screen_lines)
96 if (myCols == screen_columns
97 && ToCols != screen_columns)
100 if (wresize(win, myLines, myCols) != OK)
104 screen_lines = lines = ToLines;
105 screen_columns = columns = ToCols;
107 SP->_lines_avail = lines - stolen;
111 * Always update LINES, to allow for call from lib_doupdate.c which
112 * needs to have the count adjusted by the stolen (ripped off) lines.
114 LINES = ToLines - stolen;