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 ******************************************************************************/
21 #include <curses.priv.h>
24 MODULE_ID("$Id: wresize.c,v 1.5 1997/02/01 23:22:54 tom Exp $")
27 * Reallocate a curses WINDOW struct to either shrink or grow to the specified
28 * new lines/columns. If it grows, the new character cells are filled with
29 * blanks. The application is responsible for repainting the blank area.
32 static void *doalloc(void *p, size_t n)
41 #define DOALLOC(p,t,n) (t *)doalloc(p, sizeof(t)*(n))
42 #define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n)
43 #define c_ALLOC(p,n) DOALLOC(p,chtype,n)
46 wresize(WINDOW *win, int ToLines, int ToCols)
50 struct ldat *pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0;
53 T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
54 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
55 win->_begy, win->_begx,
56 win->_maxy, win->_maxx,
57 win->_regtop, win->_regbottom));
58 if (_nc_tracing & TRACE_UPDATE)
59 _tracedump("...before", win);
62 if (--ToLines < 0 || --ToCols < 0)
73 * If the number of lines has changed, adjust the size of the overall
76 if (ToLines != size_y) {
77 if (! (win->_flags & _SUBWIN)) {
78 for (row = ToLines+1; row <= size_y; row++)
79 free((char *)(win->_line[row].text));
82 win->_line = ld_ALLOC(win->_line, ToLines+1);
86 for (row = size_y+1; row <= ToLines; row++) {
87 win->_line[row].text = 0;
88 win->_line[row].firstchar = 0;
89 win->_line[row].lastchar = ToCols;
90 if ((win->_flags & _SUBWIN)) {
91 win->_line[row].text =
92 &pline[win->_begy + row].text[win->_begx];
98 * Adjust the width of the columns:
100 for (row = 0; row <= ToLines; row++) {
101 chtype *s = win->_line[row].text;
102 int begin = (s == 0) ? 0 : size_x + 1;
104 chtype blank = _nc_background(win);
106 win->_line[row].oldindex = row;
108 if (ToCols != size_x || s == 0) {
109 if (! (win->_flags & _SUBWIN)) {
110 win->_line[row].text = s = c_ALLOC(s, ToCols+1);
111 if (win->_line[row].text == 0)
114 win->_line[row].text = s =
115 &pline[win->_begy + row].text[win->_begx];
118 if (end >= begin) { /* growing */
119 if (win->_line[row].firstchar < begin)
120 win->_line[row].firstchar = begin;
121 win->_line[row].lastchar = ToCols;
124 } while (--end >= begin);
125 } else { /* shrinking */
126 win->_line[row].firstchar = 0;
127 win->_line[row].lastchar = ToCols;
133 * Finally, adjust the parameters showing screen size and cursor
137 win->_maxy = ToLines;
139 if (win->_regtop > win->_maxy)
140 win->_regtop = win->_maxy;
141 if (win->_regbottom > win->_maxy
142 || win->_regbottom == size_y)
143 win->_regbottom = win->_maxy;
145 if (win->_curx > win->_maxx)
146 win->_curx = win->_maxx;
147 if (win->_cury > win->_maxy)
148 win->_cury = win->_maxy;
151 TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)",
152 win->_begy, win->_begx,
153 win->_maxy, win->_maxx,
154 win->_regtop, win->_regbottom));
155 if (_nc_tracing & TRACE_UPDATE)
156 _tracedump("...after:", win);