1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 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 ****************************************************************************/
33 #include <curses.priv.h>
35 MODULE_ID("$Id: wresize.c,v 1.16 2000/03/05 00:14:35 tom Exp $")
38 * Reallocate a curses WINDOW struct to either shrink or grow to the specified
39 * new lines/columns. If it grows, the new character cells are filled with
40 * blanks. The application is responsible for repainting the blank area.
43 #define DOALLOC(p,t,n) typeRealloc(t, n, p)
44 #define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n)
45 #define c_ALLOC(p,n) DOALLOC(p,chtype,n)
48 wresize(WINDOW *win, int ToLines, int ToCols)
56 T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
58 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
59 win->_begy, win->_begx,
60 win->_maxy, win->_maxx,
61 win->_regtop, win->_regbottom));
62 if (_nc_tracing & TRACE_UPDATE)
63 _tracedump("...before", win);
67 if (!win || --ToLines < 0 || --ToCols < 0)
77 if ((win->_flags & _SUBWIN)) {
79 * Check if the new limits will fit into the parent window's size. If
80 * not, do not resize. We could adjust the location of the subwindow,
81 * but the application may not like that.
83 if (win->_pary + ToLines > win->_parent->_maxy
84 || win->_parx + ToCols > win->_parent->_maxx) {
87 pline = win->_parent->_line;
93 * If the number of lines has changed, adjust the size of the overall
96 if (ToLines != size_y) {
97 if (!(win->_flags & _SUBWIN)) {
98 for (row = ToLines + 1; row <= size_y; row++)
99 free((char *) (win->_line[row].text));
102 win->_line = ld_ALLOC(win->_line, ToLines + 1);
106 for (row = size_y + 1; row <= ToLines; row++) {
107 win->_line[row].text = 0;
108 win->_line[row].firstchar = 0;
109 win->_line[row].lastchar = ToCols;
110 if ((win->_flags & _SUBWIN)) {
111 win->_line[row].text =
112 &pline[win->_pary + row].text[win->_parx];
118 * Adjust the width of the columns:
120 blank = _nc_background(win);
121 for (row = 0; row <= ToLines; row++) {
122 chtype *s = win->_line[row].text;
123 int begin = (s == 0) ? 0 : size_x + 1;
126 if_USE_SCROLL_HINTS(win->_line[row].oldindex = row);
128 if (ToCols != size_x || s == 0) {
129 if (!(win->_flags & _SUBWIN)) {
130 win->_line[row].text = s = c_ALLOC(s, ToCols + 1);
131 if (win->_line[row].text == 0)
134 win->_line[row].text = s =
135 &pline[win->_pary + row].text[win->_parx];
138 if (end >= begin) { /* growing */
139 if (win->_line[row].firstchar < begin)
140 win->_line[row].firstchar = begin;
141 win->_line[row].lastchar = ToCols;
144 } while (--end >= begin);
145 } else { /* shrinking */
146 win->_line[row].firstchar = 0;
147 win->_line[row].lastchar = ToCols;
153 * Finally, adjust the parameters showing screen size and cursor
157 win->_maxy = ToLines;
159 if (win->_regtop > win->_maxy)
160 win->_regtop = win->_maxy;
161 if (win->_regbottom > win->_maxy
162 || win->_regbottom == size_y)
163 win->_regbottom = win->_maxy;
165 if (win->_curx > win->_maxx)
166 win->_curx = win->_maxx;
167 if (win->_cury > win->_maxy)
168 win->_cury = win->_maxy;
171 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
172 win->_begy, win->_begx,
173 win->_maxy, win->_maxx,
174 win->_regtop, win->_regbottom));
175 if (_nc_tracing & TRACE_UPDATE)
176 _tracedump("...after:", win);