1 /****************************************************************************
2 * Copyright (c) 1998-2010,2016 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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
40 #include <curses.priv.h>
42 MODULE_ID("$Id: lib_window.c,v 1.30 2016/05/28 23:11:26 tom Exp $")
45 _nc_synchook(WINDOW *win)
46 /* hook to be called after each window change */
55 mvderwin(WINDOW *win, int y, int x)
56 /* move a derived window */
61 T((T_CALLED("mvderwin(%p,%d,%d)"), (void *) win, y, x));
64 && (orig = win->_parent) != 0
66 && (x + getmaxx(win) <= getmaxx(orig))
67 && (y + getmaxy(win) <= getmaxy(orig))) {
73 for (i = 0; i < getmaxy(win); i++)
74 win->_line[i].text = &(orig->_line[y++].text[x]);
81 syncok(WINDOW *win, bool bf)
82 /* enable/disable automatic wsyncup() on each change to window */
84 T((T_CALLED("syncok(%p,%d)"), (void *) win, bf));
95 /* mark changed every cell in win's ancestors that is changed in win */
96 /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */
100 T((T_CALLED("wsyncup(%p)"), (void *) win));
101 if (win && win->_parent) {
102 for (wp = win; wp->_parent; wp = wp->_parent) {
104 WINDOW *pp = wp->_parent;
106 assert((wp->_pary <= pp->_maxy) &&
107 ((wp->_pary + wp->_maxy) <= pp->_maxy));
109 for (y = 0; y <= wp->_maxy; y++) {
110 int left = wp->_line[y].firstchar;
111 if (left >= 0) { /* line is touched */
112 struct ldat *line = &(pp->_line[wp->_pary + y]);
113 /* left & right character in parent window coordinates */
114 int right = wp->_line[y].lastchar + wp->_parx;
117 CHANGED_RANGE(line, left, right);
126 wsyncdown(WINDOW *win)
127 /* mark changed every cell in win that is changed in any of its ancestors */
128 /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */
130 T((T_CALLED("wsyncdown(%p)"), (void *) win));
132 if (win && win->_parent) {
133 WINDOW *pp = win->_parent;
136 /* This recursion guarantees, that the changes are propagated down-
137 wards from the root to our direct parent. */
140 /* and now we only have to propagate the changes from our direct
141 parent, if there are any. */
142 assert((win->_pary <= pp->_maxy) &&
143 ((win->_pary + win->_maxy) <= pp->_maxy));
145 for (y = 0; y <= win->_maxy; y++) {
146 if (pp->_line[win->_pary + y].firstchar >= 0) { /* parent changed */
147 struct ldat *line = &(win->_line[y]);
148 /* left and right character in child coordinates */
149 int left = pp->_line[win->_pary + y].firstchar - win->_parx;
150 int right = pp->_line[win->_pary + y].lastchar - win->_parx;
151 /* The change may be outside the child's range */
154 if (right > win->_maxx)
156 CHANGED_RANGE(line, left, right);
164 wcursyncup(WINDOW *win)
165 /* sync the cursor in all derived windows to its value in the base window */
169 T((T_CALLED("wcursyncup(%p)"), (void *) win));
170 for (wp = win; wp && wp->_parent; wp = wp->_parent) {
171 wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
176 NCURSES_EXPORT(WINDOW *)
178 /* make an exact duplicate of the given window */
182 T((T_CALLED("dupwin(%p)"), (void *) win));
186 SCREEN *sp = _nc_screen_of(win);
188 _nc_lock_global(curses);
189 if (win->_flags & _ISPAD) {
190 nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
194 nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
205 nwin->_curx = win->_curx;
206 nwin->_cury = win->_cury;
207 nwin->_maxy = win->_maxy;
208 nwin->_maxx = win->_maxx;
209 nwin->_begy = win->_begy;
210 nwin->_begx = win->_begx;
211 nwin->_yoffset = win->_yoffset;
213 nwin->_flags = win->_flags & ~_SUBWIN;
214 /* Due to the use of newwin(), the clone is not a subwindow.
215 * The text is really copied into the clone.
218 WINDOW_ATTRS(nwin) = WINDOW_ATTRS(win);
219 nwin->_nc_bkgd = win->_nc_bkgd;
221 nwin->_notimeout = win->_notimeout;
222 nwin->_clear = win->_clear;
223 nwin->_leaveok = win->_leaveok;
224 nwin->_scroll = win->_scroll;
225 nwin->_idlok = win->_idlok;
226 nwin->_idcok = win->_idcok;
227 nwin->_immed = win->_immed;
228 nwin->_sync = win->_sync;
229 nwin->_use_keypad = win->_use_keypad;
230 nwin->_delay = win->_delay;
234 nwin->_parent = (WINDOW *) 0;
235 /* See above: the clone isn't a subwindow! */
237 nwin->_regtop = win->_regtop;
238 nwin->_regbottom = win->_regbottom;
240 if (win->_flags & _ISPAD)
241 nwin->_pad = win->_pad;
243 linesize = (unsigned) (win->_maxx + 1) * sizeof(NCURSES_CH_T);
244 for (i = 0; i <= nwin->_maxy; i++) {
245 memcpy(nwin->_line[i].text, win->_line[i].text, linesize);
246 nwin->_line[i].firstchar = win->_line[i].firstchar;
247 nwin->_line[i].lastchar = win->_line[i].lastchar;
250 _nc_unlock_global(curses);