1 /******************************************************************************
2 * Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net> *
3 * All Rights Reserved. *
5 * Permission to use, copy, modify, and distribute this software and its *
6 * documentation for any purpose and without fee is hereby granted, provided *
7 * that the above copyright notice appear in all copies and that both that *
8 * copyright notice and this permission notice appear in supporting *
9 * documentation, and that the name of the above listed copyright holder(s) *
10 * not be used in advertising or publicity pertaining to distribution of the *
11 * software without specific, written prior permission. THE ABOVE LISTED *
12 * COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *
13 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO *
14 * EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY *
15 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER *
16 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF *
17 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN *
18 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
19 ******************************************************************************/
22 * This is an extension to the curses library. It provides callers with a hook
23 * into the NCURSES data to resize windows, primarily for use by programs
24 * running in an X Window terminal (e.g., xterm). I abstracted this module
25 * from my application library for NCURSES because it must be compiled with
26 * the private data structures -- T.Dickey 1995/7/4.
29 #include <curses.priv.h>
32 MODULE_ID("$Id: resizeterm.c,v 1.3 1997/02/02 01:03:06 tom Exp $")
35 * This function reallocates NCURSES window structures. It is invoked in
36 * response to a SIGWINCH interrupt. Other user-defined windows may also need
39 * Because this performs memory allocation, it should not (in general) be
40 * invoked directly from the signal handler.
43 resizeterm(int ToLines, int ToCols)
45 int stolen = screen_lines - SP->_lines_avail;
46 int bottom = screen_lines + SP->_topstolen - stolen;
48 T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
50 screen_lines, screen_columns));
52 if (ToLines != screen_lines
53 || ToCols != screen_columns) {
56 for (wp = _nc_windows; wp != 0; wp = wp->next) {
57 WINDOW *win = wp->win;
58 int myLines = win->_maxy + 1;
59 int myCols = win->_maxx + 1;
61 /* pads aren't treated this way */
62 if (win->_flags & _ISPAD)
65 if (win->_begy >= bottom) {
66 win->_begy += (ToLines - screen_lines);
68 if (myLines == screen_lines - stolen
69 && ToLines != screen_lines)
70 myLines = ToLines - stolen;
72 if (myLines == screen_lines
73 && ToLines != screen_lines)
77 if (myCols == screen_columns
78 && ToCols != screen_columns)
81 if (wresize(win, myLines, myCols) != OK)
85 screen_lines = lines = ToLines;
86 screen_columns = columns = ToCols;
88 SP->_lines_avail = lines - stolen;
92 * Always update LINES, to allow for call from lib_doupdate.c which
93 * needs to have the count adjusted by the stolen (ripped off) lines.
95 LINES = ToLines - stolen;