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>
36 MODULE_ID("$Id: wresize.c,v 1.9 1998/02/11 12:13:54 tom Exp $")
39 * Reallocate a curses WINDOW struct to either shrink or grow to the specified
40 * new lines/columns. If it grows, the new character cells are filled with
41 * blanks. The application is responsible for repainting the blank area.
44 static void *doalloc(void *p, size_t n)
53 #define DOALLOC(p,t,n) (t *)doalloc(p, sizeof(t)*(n))
54 #define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n)
55 #define c_ALLOC(p,n) DOALLOC(p,chtype,n)
58 wresize(WINDOW *win, int ToLines, int ToCols)
66 T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
68 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
69 win->_begy, win->_begx,
70 win->_maxy, win->_maxx,
71 win->_regtop, win->_regbottom));
72 if (_nc_tracing & TRACE_UPDATE)
73 _tracedump("...before", win);
77 if (!win || --ToLines < 0 || --ToCols < 0)
87 pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0;
90 * If the number of lines has changed, adjust the size of the overall
93 if (ToLines != size_y) {
94 if (! (win->_flags & _SUBWIN)) {
95 for (row = ToLines+1; row <= size_y; row++)
96 free((char *)(win->_line[row].text));
99 win->_line = ld_ALLOC(win->_line, ToLines+1);
103 for (row = size_y+1; row <= ToLines; row++) {
104 win->_line[row].text = 0;
105 win->_line[row].firstchar = 0;
106 win->_line[row].lastchar = ToCols;
107 if ((win->_flags & _SUBWIN)) {
108 win->_line[row].text =
109 &pline[win->_begy + row].text[win->_begx];
115 * Adjust the width of the columns:
117 blank = _nc_background(win);
118 for (row = 0; row <= ToLines; row++) {
119 chtype *s = win->_line[row].text;
120 int begin = (s == 0) ? 0 : size_x + 1;
123 if_USE_SCROLL_HINTS(win->_line[row].oldindex = row);
125 if (ToCols != size_x || s == 0) {
126 if (! (win->_flags & _SUBWIN)) {
127 win->_line[row].text = s = c_ALLOC(s, ToCols+1);
128 if (win->_line[row].text == 0)
131 win->_line[row].text = s =
132 &pline[win->_begy + row].text[win->_begx];
135 if (end >= begin) { /* growing */
136 if (win->_line[row].firstchar < begin)
137 win->_line[row].firstchar = begin;
138 win->_line[row].lastchar = ToCols;
141 } while (--end >= begin);
142 } else { /* shrinking */
143 win->_line[row].firstchar = 0;
144 win->_line[row].lastchar = ToCols;
150 * Finally, adjust the parameters showing screen size and cursor
154 win->_maxy = ToLines;
156 if (win->_regtop > win->_maxy)
157 win->_regtop = win->_maxy;
158 if (win->_regbottom > win->_maxy
159 || win->_regbottom == size_y)
160 win->_regbottom = win->_maxy;
162 if (win->_curx > win->_maxx)
163 win->_curx = win->_maxx;
164 if (win->_cury > win->_maxy)
165 win->_cury = win->_maxy;
168 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
169 win->_begy, win->_begx,
170 win->_maxy, win->_maxx,
171 win->_regtop, win->_regbottom));
172 if (_nc_tracing & TRACE_UPDATE)
173 _tracedump("...after:", win);