]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/resizeterm.c
ncurses 4.1
[ncurses.git] / ncurses / resizeterm.c
1 /******************************************************************************
2  * Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net>                 *
3  * All Rights Reserved.                                                       *
4  *                                                                            *
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  ******************************************************************************/
20
21 /*
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.
27  */
28
29 #include <curses.priv.h>
30 #include <term.h>
31
32 MODULE_ID("$Id: resizeterm.c,v 1.3 1997/02/02 01:03:06 tom Exp $")
33
34 /*
35  * This function reallocates NCURSES window structures.  It is invoked in
36  * response to a SIGWINCH interrupt.  Other user-defined windows may also need
37  * to be reallocated.
38  *
39  * Because this performs memory allocation, it should not (in general) be
40  * invoked directly from the signal handler.
41  */
42 int
43 resizeterm(int ToLines, int ToCols)
44 {
45         int stolen = screen_lines - SP->_lines_avail;
46         int bottom = screen_lines + SP->_topstolen - stolen;
47
48         T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
49                 ToLines, ToCols,
50                 screen_lines, screen_columns));
51
52         if (ToLines != screen_lines
53          || ToCols  != screen_columns) {
54                 WINDOWLIST *wp;
55
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;
60
61                         /* pads aren't treated this way */
62                         if (win->_flags & _ISPAD)
63                                 continue;
64
65                         if (win->_begy >= bottom) {
66                                 win->_begy += (ToLines - screen_lines);
67                         } else {
68                                 if (myLines == screen_lines - stolen
69                                  && ToLines != screen_lines)
70                                         myLines = ToLines - stolen;
71                                 else
72                                 if (myLines == screen_lines
73                                  && ToLines != screen_lines)
74                                         myLines = ToLines;
75                         }
76
77                         if (myCols  == screen_columns
78                          && ToCols  != screen_columns)
79                                 myCols = ToCols;
80
81                         if (wresize(win, myLines, myCols) != OK)
82                                 returnCode(ERR);
83                 }
84
85                 screen_lines   = lines    = ToLines;
86                 screen_columns = columns  = ToCols;
87
88                 SP->_lines_avail = lines - stolen;
89         }
90
91         /*
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.
94          */
95         LINES = ToLines - stolen;
96         COLS  = ToCols;
97
98         returnCode(OK);
99 }