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 ****************************************************************************/
33 #include <curses.priv.h>
35 MODULE_ID("$Id: wresize.c,v 1.12 1999/02/27 18:57:31 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 pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0;
80 * If the number of lines has changed, adjust the size of the overall
83 if (ToLines != size_y) {
84 if (! (win->_flags & _SUBWIN)) {
85 for (row = ToLines+1; row <= size_y; row++)
86 free((char *)(win->_line[row].text));
89 win->_line = ld_ALLOC(win->_line, ToLines+1);
93 for (row = size_y+1; row <= ToLines; row++) {
94 win->_line[row].text = 0;
95 win->_line[row].firstchar = 0;
96 win->_line[row].lastchar = ToCols;
97 if ((win->_flags & _SUBWIN)) {
98 win->_line[row].text =
99 &pline[win->_begy + row].text[win->_begx];
105 * Adjust the width of the columns:
107 blank = _nc_background(win);
108 for (row = 0; row <= ToLines; row++) {
109 chtype *s = win->_line[row].text;
110 int begin = (s == 0) ? 0 : size_x + 1;
113 if_USE_SCROLL_HINTS(win->_line[row].oldindex = row);
115 if (ToCols != size_x || s == 0) {
116 if (! (win->_flags & _SUBWIN)) {
117 win->_line[row].text = s = c_ALLOC(s, ToCols+1);
118 if (win->_line[row].text == 0)
121 win->_line[row].text = s =
122 &pline[win->_begy + row].text[win->_begx];
125 if (end >= begin) { /* growing */
126 if (win->_line[row].firstchar < begin)
127 win->_line[row].firstchar = begin;
128 win->_line[row].lastchar = ToCols;
131 } while (--end >= begin);
132 } else { /* shrinking */
133 win->_line[row].firstchar = 0;
134 win->_line[row].lastchar = ToCols;
140 * Finally, adjust the parameters showing screen size and cursor
144 win->_maxy = ToLines;
146 if (win->_regtop > win->_maxy)
147 win->_regtop = win->_maxy;
148 if (win->_regbottom > win->_maxy
149 || win->_regbottom == size_y)
150 win->_regbottom = win->_maxy;
152 if (win->_curx > win->_maxx)
153 win->_curx = win->_maxx;
154 if (win->_cury > win->_maxy)
155 win->_cury = win->_maxy;
158 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
159 win->_begy, win->_begx,
160 win->_maxy, win->_maxx,
161 win->_regtop, win->_regbottom));
162 if (_nc_tracing & TRACE_UPDATE)
163 _tracedump("...after:", win);