Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020,2021 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 | * copy of this software and associated documentation files (the * |
| 7 | * "Software"), to deal in the Software without restriction, including * |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, * |
| 9 | * distribute, distribute with modifications, sublicense, and/or sell * |
| 10 | * copies of the Software, and to permit persons to whom the Software is * |
| 11 | * furnished to do so, subject to the following conditions: * |
| 12 | * * |
| 13 | * The above copyright notice and this permission notice shall be included * |
| 14 | * in all copies or substantial portions of the Software. * |
| 15 | * * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 | * * |
| 24 | * Except as contained in this notice, the name(s) of the above copyright * |
| 25 | * holders shall not be used in advertising or otherwise to promote the * |
| 26 | * sale, use or other dealings in this Software without prior written * |
| 27 | * authorization. * |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
| 33 | * and: Thomas E. Dickey 1996-on * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 34 | * and: Juergen Pfeifer 2009 * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | ****************************************************************************/ |
| 36 | |
| 37 | /* |
| 38 | ** lib_newwin.c |
| 39 | ** |
| 40 | ** The routines newwin(), subwin() and their dependent |
| 41 | ** |
| 42 | */ |
| 43 | |
| 44 | #include <curses.priv.h> |
| 45 | #include <stddef.h> |
| 46 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 47 | MODULE_ID("$Id: lib_newwin.c,v 1.76 2021/10/23 18:53:38 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 48 | |
| 49 | #define window_is(name) ((sp)->_##name == win) |
| 50 | |
| 51 | #if USE_REENTRANT |
| 52 | #define remove_window(name) \ |
| 53 | sp->_##name = 0 |
| 54 | #else |
| 55 | #define remove_window(name) \ |
| 56 | sp->_##name = 0; \ |
| 57 | if (win == name) \ |
| 58 | name = 0 |
| 59 | #endif |
| 60 | |
| 61 | static void |
| 62 | remove_window_from_screen(WINDOW *win) |
| 63 | { |
| 64 | SCREEN *sp; |
| 65 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 66 | #ifdef USE_SP_WINDOWLIST |
| 67 | if ((sp = _nc_screen_of(win)) != 0) { |
| 68 | if (window_is(curscr)) { |
| 69 | remove_window(curscr); |
| 70 | } else if (window_is(stdscr)) { |
| 71 | remove_window(stdscr); |
| 72 | } else if (window_is(newscr)) { |
| 73 | remove_window(newscr); |
| 74 | } |
| 75 | } |
| 76 | #else |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 77 | for (each_screen(sp)) { |
| 78 | if (window_is(curscr)) { |
| 79 | remove_window(curscr); |
| 80 | break; |
| 81 | } else if (window_is(stdscr)) { |
| 82 | remove_window(stdscr); |
| 83 | break; |
| 84 | } else if (window_is(newscr)) { |
| 85 | remove_window(newscr); |
| 86 | break; |
| 87 | } |
| 88 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 89 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | NCURSES_EXPORT(int) |
| 93 | _nc_freewin(WINDOW *win) |
| 94 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 95 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 96 | #ifdef USE_SP_WINDOWLIST |
| 97 | SCREEN *sp = _nc_screen_of(win); /* pretend this is parameter */ |
| 98 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 99 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 100 | T((T_CALLED("_nc_freewin(%p)"), (void *) win)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 101 | |
| 102 | if (win != 0) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 103 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 104 | if (_nc_nonsp_try_global(curses) == 0) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 105 | WINDOWLIST *p, *q; |
| 106 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 107 | q = 0; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 108 | for (each_window(sp, p)) { |
| 109 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 110 | if (&(p->win) == win) { |
| 111 | remove_window_from_screen(win); |
| 112 | if (q == 0) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 113 | WindowList(sp) = p->next; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 114 | else |
| 115 | q->next = p->next; |
| 116 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 117 | if (!IS_SUBWIN(win)) { |
| 118 | int i; |
| 119 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | for (i = 0; i <= win->_maxy; i++) |
| 121 | FreeIfNeeded(win->_line[i].text); |
| 122 | } |
| 123 | free(win->_line); |
| 124 | free(p); |
| 125 | |
| 126 | result = OK; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 127 | T(("...deleted win=%p", (void *) win)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | q = p; |
| 131 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | _nc_nonsp_unlock_global(curses); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | returnCode(result); |
| 136 | } |
| 137 | |
| 138 | NCURSES_EXPORT(WINDOW *) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 139 | NCURSES_SP_NAME(newwin) (NCURSES_SP_DCLx |
| 140 | int num_lines, int num_columns, int begy, int begx) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 141 | { |
| 142 | WINDOW *win; |
| 143 | NCURSES_CH_T *ptr; |
| 144 | int i; |
| 145 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 146 | T((T_CALLED("newwin(%p, %d,%d,%d,%d)"), (void *) SP_PARM, num_lines, num_columns, |
| 147 | begy, begx)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 148 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 149 | if (begy < 0 |
| 150 | || begx < 0 |
| 151 | || num_lines < 0 |
| 152 | || num_columns < 0 |
| 153 | || SP_PARM == 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 154 | returnWin(0); |
| 155 | |
| 156 | if (num_lines == 0) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 157 | num_lines = SP_PARM->_lines_avail - begy; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 158 | if (num_columns == 0) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 159 | num_columns = screen_columns(SP_PARM) - begx; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 160 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 161 | win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx |
| 162 | num_lines, num_columns, begy, begx, 0); |
| 163 | if (win == 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 164 | returnWin(0); |
| 165 | |
| 166 | for (i = 0; i < num_lines; i++) { |
| 167 | win->_line[i].text = typeCalloc(NCURSES_CH_T, (unsigned) num_columns); |
| 168 | if (win->_line[i].text == 0) { |
| 169 | (void) _nc_freewin(win); |
| 170 | returnWin(0); |
| 171 | } |
| 172 | for (ptr = win->_line[i].text; |
| 173 | ptr < win->_line[i].text + num_columns; |
| 174 | ptr++) |
| 175 | SetChar(*ptr, BLANK_TEXT, BLANK_ATTR); |
| 176 | } |
| 177 | |
| 178 | returnWin(win); |
| 179 | } |
| 180 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 181 | #if NCURSES_SP_FUNCS |
| 182 | NCURSES_EXPORT(WINDOW *) |
| 183 | newwin(int num_lines, int num_columns, int begy, int begx) |
| 184 | { |
| 185 | WINDOW *win; |
| 186 | _nc_sp_lock_global(curses); |
| 187 | win = NCURSES_SP_NAME(newwin) (CURRENT_SCREEN, |
| 188 | num_lines, num_columns, begy, begx); |
| 189 | _nc_sp_unlock_global(curses); |
| 190 | return (win); |
| 191 | } |
| 192 | #endif |
| 193 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 194 | NCURSES_EXPORT(WINDOW *) |
| 195 | derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) |
| 196 | { |
| 197 | WINDOW *win; |
| 198 | int i; |
| 199 | int flags = _SUBWIN; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 200 | #if NCURSES_SP_FUNCS |
| 201 | SCREEN *sp = _nc_screen_of(orig); |
| 202 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 203 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 204 | T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), (void *) orig, num_lines, num_columns, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 205 | begy, begx)); |
| 206 | |
| 207 | /* |
| 208 | * make sure window fits inside the original one |
| 209 | */ |
| 210 | if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) |
| 211 | returnWin(0); |
| 212 | if (begy + num_lines > orig->_maxy + 1 |
| 213 | || begx + num_columns > orig->_maxx + 1) |
| 214 | returnWin(0); |
| 215 | |
| 216 | if (num_lines == 0) |
| 217 | num_lines = orig->_maxy + 1 - begy; |
| 218 | |
| 219 | if (num_columns == 0) |
| 220 | num_columns = orig->_maxx + 1 - begx; |
| 221 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 222 | if (IS_PAD(orig)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 223 | flags |= _ISPAD; |
| 224 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 225 | win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx num_lines, num_columns, |
| 226 | orig->_begy + begy, |
| 227 | orig->_begx + begx, flags); |
| 228 | if (win == 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 229 | returnWin(0); |
| 230 | |
| 231 | win->_pary = begy; |
| 232 | win->_parx = begx; |
| 233 | WINDOW_ATTRS(win) = WINDOW_ATTRS(orig); |
| 234 | win->_nc_bkgd = orig->_nc_bkgd; |
| 235 | |
| 236 | for (i = 0; i < num_lines; i++) |
| 237 | win->_line[i].text = &orig->_line[begy++].text[begx]; |
| 238 | |
| 239 | win->_parent = orig; |
| 240 | |
| 241 | returnWin(win); |
| 242 | } |
| 243 | |
| 244 | NCURSES_EXPORT(WINDOW *) |
| 245 | subwin(WINDOW *w, int l, int c, int y, int x) |
| 246 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 247 | WINDOW *result = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 248 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 249 | T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), (void *) w, l, c, y, x)); |
| 250 | if (w != 0) { |
| 251 | T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx)); |
| 252 | |
| 253 | result = derwin(w, l, c, y - w->_begy, x - w->_begx); |
| 254 | } |
| 255 | returnWin(result); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static bool |
| 259 | dimension_limit(int value) |
| 260 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 261 | NCURSES_SIZE_T test = (NCURSES_SIZE_T) value; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 262 | return (test == value && value > 0); |
| 263 | } |
| 264 | |
| 265 | NCURSES_EXPORT(WINDOW *) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 266 | NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_DCLx |
| 267 | int num_lines, |
| 268 | int num_columns, |
| 269 | int begy, |
| 270 | int begx, |
| 271 | int flags) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 272 | { |
| 273 | int i; |
| 274 | WINDOWLIST *wp; |
| 275 | WINDOW *win; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 276 | bool is_padwin = (flags & _ISPAD); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 277 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 278 | T((T_CALLED("_nc_makenew(%p,%d,%d,%d,%d)"), |
| 279 | (void *) SP_PARM, num_lines, num_columns, begy, begx)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 280 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 281 | if (SP_PARM == 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 282 | returnWin(0); |
| 283 | |
| 284 | if (!dimension_limit(num_lines) || !dimension_limit(num_columns)) |
| 285 | returnWin(0); |
| 286 | |
| 287 | if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) |
| 288 | returnWin(0); |
| 289 | |
| 290 | win = &(wp->win); |
| 291 | |
| 292 | if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 293 | free(wp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 294 | returnWin(0); |
| 295 | } |
| 296 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 297 | _nc_nonsp_lock_global(curses); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 298 | |
| 299 | win->_curx = 0; |
| 300 | win->_cury = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 301 | win->_maxy = (NCURSES_SIZE_T) (num_lines - 1); |
| 302 | win->_maxx = (NCURSES_SIZE_T) (num_columns - 1); |
| 303 | win->_begy = (NCURSES_SIZE_T) begy; |
| 304 | win->_begx = (NCURSES_SIZE_T) begx; |
| 305 | win->_yoffset = SP_PARM->_topstolen; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 306 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 307 | win->_flags = (short) flags; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 308 | WINDOW_ATTRS(win) = A_NORMAL; |
| 309 | SetChar(win->_nc_bkgd, BLANK_TEXT, BLANK_ATTR); |
| 310 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 311 | win->_clear = (is_padwin |
| 312 | ? FALSE |
| 313 | : (num_lines == screen_lines(SP_PARM) |
| 314 | && num_columns == screen_columns(SP_PARM))); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 315 | win->_idlok = FALSE; |
| 316 | win->_idcok = TRUE; |
| 317 | win->_scroll = FALSE; |
| 318 | win->_leaveok = FALSE; |
| 319 | win->_use_keypad = FALSE; |
| 320 | win->_delay = -1; |
| 321 | win->_immed = FALSE; |
| 322 | win->_sync = 0; |
| 323 | win->_parx = -1; |
| 324 | win->_pary = -1; |
| 325 | win->_parent = 0; |
| 326 | |
| 327 | win->_regtop = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 328 | win->_regbottom = (NCURSES_SIZE_T) (num_lines - 1); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 329 | |
| 330 | win->_pad._pad_y = -1; |
| 331 | win->_pad._pad_x = -1; |
| 332 | win->_pad._pad_top = -1; |
| 333 | win->_pad._pad_bottom = -1; |
| 334 | win->_pad._pad_left = -1; |
| 335 | win->_pad._pad_right = -1; |
| 336 | |
| 337 | for (i = 0; i < num_lines; i++) { |
| 338 | /* |
| 339 | * This used to do |
| 340 | * |
| 341 | * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; |
| 342 | * |
| 343 | * which marks the whole window unchanged. That's how |
| 344 | * SVr1 curses did it, but SVr4 curses marks the whole new |
| 345 | * window changed. |
| 346 | * |
| 347 | * With the old SVr1-like code, say you have stdscr full of |
| 348 | * characters, then create a new window with newwin(), |
| 349 | * then do a printw(win, "foo ");, the trailing spaces are |
| 350 | * completely ignored by the following refreshes. So, you |
| 351 | * get "foojunkjunk" on the screen instead of "foo " as |
| 352 | * you actually intended. |
| 353 | * |
| 354 | * SVr4 doesn't do this. Instead the spaces are actually written. |
| 355 | * So that's how we want ncurses to behave. |
| 356 | */ |
| 357 | win->_line[i].firstchar = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 358 | win->_line[i].lastchar = (NCURSES_SIZE_T) (num_columns - 1); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 359 | |
| 360 | if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); |
| 361 | } |
| 362 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 363 | if (!is_padwin && (begx + num_columns == screen_columns(SP_PARM))) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 364 | win->_flags |= _ENDLINE; |
| 365 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 366 | if (begx == 0 && num_lines == screen_lines(SP_PARM) && begy == 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 367 | win->_flags |= _FULLWIN; |
| 368 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 369 | if (begy + num_lines == screen_lines(SP_PARM)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 370 | win->_flags |= _SCROLLWIN; |
| 371 | } |
| 372 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 373 | wp->next = WindowList(SP_PARM); |
| 374 | wp->screen = SP_PARM; |
| 375 | WindowList(SP_PARM) = wp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 376 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 377 | T((T_CREATE("window %p"), (void *) win)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 378 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 379 | _nc_nonsp_unlock_global(curses); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 380 | returnWin(win); |
| 381 | } |
| 382 | |
| 383 | /* |
| 384 | * wgetch() and other functions with a WINDOW* parameter may use a SCREEN* |
| 385 | * internally, and it is useful to allow those to be invoked without switching |
| 386 | * SCREEN's, e.g., for multi-threaded applications. |
| 387 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 388 | #if NCURSES_SP_FUNCS |
| 389 | NCURSES_EXPORT(WINDOW *) |
| 390 | _nc_curscr_of(SCREEN *sp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 391 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 392 | return (sp == 0) ? NULL : CurScreen(sp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 393 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 394 | |
| 395 | NCURSES_EXPORT(WINDOW *) |
| 396 | _nc_newscr_of(SCREEN *sp) |
| 397 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 398 | return (sp == 0) ? NULL : NewScreen(sp); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | NCURSES_EXPORT(WINDOW *) |
| 402 | _nc_stdscr_of(SCREEN *sp) |
| 403 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 404 | return (sp == 0) ? NULL : StdScreen(sp); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 405 | } |
| 406 | #endif |