WINDOW *newpad(int nlines, int ncols) { WINDOW *win; PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols)); if ( !(win = PDC_makenew(nlines, ncols, -1, -1)) || !(win = PDC_makelines(win)) ) return (WINDOW *)NULL; werase(win); win->_flags = _PAD; /* save default values in case pechochar() is the first call to prefresh(). */ save_pminrow = 0; save_pmincol = 0; save_sminrow = 0; save_smincol = 0; save_smaxrow = min(LINES, nlines) - 1; save_smaxcol = min(COLS, ncols) - 1; return win; }
WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) { WINDOW *win; int i; int j = begy; int k = begx; PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n", nlines, ncols, begy, begx)); if (!orig || !(orig->_flags & _PAD)) return (WINDOW *)NULL; /* make sure window fits inside the original one */ if ((begy < orig->_begy) || (begx < orig->_begx) || (begy + nlines) > (orig->_begy + orig->_maxy) || (begx + ncols) > (orig->_begx + orig->_maxx)) return (WINDOW *)NULL; if (!nlines) nlines = orig->_maxy - 1 - j; if (!ncols) ncols = orig->_maxx - 1 - k; if ( !(win = PDC_makenew(nlines, ncols, begy, begx)) ) return (WINDOW *)NULL; /* initialize window variables */ win->_attrs = orig->_attrs; win->_leaveit = orig->_leaveit; win->_scroll = orig->_scroll; win->_nodelay = orig->_nodelay; win->_use_keypad = orig->_use_keypad; win->_parent = orig; for (i = 0; i < nlines; i++) win->_y[i] = (orig->_y[j++]) + k; win->_flags = _SUBPAD; /* save default values in case pechochar() is the first call to prefresh(). */ save_pminrow = 0; save_pmincol = 0; save_sminrow = 0; save_smincol = 0; save_smaxrow = min(LINES, nlines) - 1; save_smaxcol = min(COLS, ncols) - 1; return win; }
WINDOW *dupwin(WINDOW *win) { WINDOW *new_; chtype *ptr, *ptr1; int nlines, ncols, begy, begx, i; if (!win) return (WINDOW *)NULL; nlines = win->_maxy; ncols = win->_maxx; begy = win->_begy; begx = win->_begx; if ( !(new_ = PDC_makenew(nlines, ncols, begy, begx)) || !(new_ = PDC_makelines(new_)) ) return (WINDOW *)NULL; /* copy the contents of win into new_ */ for (i = 0; i < nlines; i++) { for (ptr = new_->_y[i], ptr1 = win->_y[i]; ptr < new_->_y[i] + ncols; ptr++, ptr1++) *ptr = *ptr1; new_->_firstch[i] = 0; new_->_lastch[i] = ncols - 1; } new_->_curx = win->_curx; new_->_cury = win->_cury; new_->_maxy = win->_maxy; new_->_maxx = win->_maxx; new_->_begy = win->_begy; new_->_begx = win->_begx; new_->_flags = win->_flags; new_->_attrs = win->_attrs; new_->_clear = win->_clear; new_->_leaveit = win->_leaveit; new_->_scroll = win->_scroll; new_->_nodelay = win->_nodelay; new_->_delayms = win->_delayms; new_->_use_keypad = win->_use_keypad; new_->_tmarg = win->_tmarg; new_->_bmarg = win->_bmarg; new_->_parx = win->_parx; new_->_pary = win->_pary; new_->_parent = win->_parent; new_->_bkgd = win->_bkgd; new_->_flags = win->_flags; return new_; }
WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) { WINDOW *win; int i; int j = begy - orig->_begy; int k = begx - orig->_begx; PDC_LOG(("subwin() - called: lines %d cols %d begy %d begx %d\n", nlines, ncols, begy, begx)); /* make sure window fits inside the original one */ if (!orig || (begy < orig->_begy) || (begx < orig->_begx) || (begy + nlines) > (orig->_begy + orig->_maxy) || (begx + ncols) > (orig->_begx + orig->_maxx)) return (WINDOW *)NULL; if (!nlines) nlines = orig->_maxy - 1 - j; if (!ncols) ncols = orig->_maxx - 1 - k; win = PDC_makenew(nlines, ncols, begy, begx); if (!win) return (WINDOW *)NULL; /* initialize window variables */ win->_attrs = orig->_attrs; win->_bkgd = orig->_bkgd; win->_leaveit = orig->_leaveit; win->_scroll = orig->_scroll; win->_nodelay = orig->_nodelay; win->_delayms = orig->_delayms; win->_use_keypad = orig->_use_keypad; win->_immed = orig->_immed; win->_sync = orig->_sync; win->_pary = j; win->_parx = k; win->_parent = orig; for (i = 0; i < nlines; i++, j++) win->_y[i] = orig->_y[j] + k; win->_flags |= _SUBWIN; return win; }
WINDOW *newwin(int nlines, int ncols, int begy, int begx) { WINDOW *win; PDC_LOG(("newwin() - called:lines=%d cols=%d begy=%d begx=%d\n", nlines, ncols, begy, begx)); if (!nlines) nlines = LINES - begy; if (!ncols) ncols = COLS - begx; if ( (begy + nlines > SP->lines || begx + ncols > SP->cols) || !(win = PDC_makenew(nlines, ncols, begy, begx)) || !(win = PDC_makelines(win)) ) return (WINDOW *)NULL; werase(win); return win; }
WINDOW *resize_window(WINDOW *win, int nlines, int ncols) { WINDOW *new_; int i, save_cury, save_curx, new_begy, new_begx; PDC_LOG(("resize_window() - called: nlines %d ncols %d\n", nlines, ncols)); if (!win) return (WINDOW *)NULL; if (win->_flags & _SUBPAD) { if ( !(new_ = subpad(win->_parent, nlines, ncols, win->_begy, win->_begx)) ) return (WINDOW *)NULL; } else if (win->_flags & _SUBWIN) { if ( !(new_ = subwin(win->_parent, nlines, ncols, win->_begy, win->_begx)) ) return (WINDOW *)NULL; } else { if (win == SP->slk_winptr) { new_begy = SP->lines - SP->slklines; new_begx = 0; } else { new_begy = win->_begy; new_begx = win->_begx; } if ( !(new_ = PDC_makenew(nlines, ncols, new_begy, new_begx)) ) return (WINDOW *)NULL; } save_curx = min(win->_curx, (new_->_maxx - 1)); save_cury = min(win->_cury, (new_->_maxy - 1)); if (!(win->_flags & (_SUBPAD|_SUBWIN))) { if ( !(new_ = PDC_makelines(new_)) ) return (WINDOW *)NULL; werase(new_); copywin(win, new_, 0, 0, 0, 0, min(win->_maxy, new_->_maxy) - 1, min(win->_maxx, new_->_maxx) - 1, FALSE); for (i = 0; i < win->_maxy && win->_y[i]; i++) if (win->_y[i]) free(win->_y[i]); } new_->_flags = win->_flags; new_->_attrs = win->_attrs; new_->_clear = win->_clear; new_->_leaveit = win->_leaveit; new_->_scroll = win->_scroll; new_->_nodelay = win->_nodelay; new_->_delayms = win->_delayms; new_->_use_keypad = win->_use_keypad; new_->_tmarg = (win->_tmarg > new_->_maxy - 1) ? 0 : win->_tmarg; new_->_bmarg = (win->_bmarg == win->_maxy - 1) ? new_->_maxy - 1 : min(win->_bmarg, (new_->_maxy - 1)); new_->_parent = win->_parent; new_->_immed = win->_immed; new_->_sync = win->_sync; new_->_bkgd = win->_bkgd; new_->_curx = save_curx; new_->_cury = save_cury; free(win->_firstch); free(win->_lastch); free(win->_y); *win = *new_; free(new_); return win; }