#include <curspriv.h>
#include <string.h>
static int save_pminrow, save_pmincol;
static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol;
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, 0, 0))
|| !(win = PDC_makelines(win)) )
return (WINDOW *)NULL;
werase(win);
win->_flags = _PAD;
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;
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;
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_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;
}
int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2)
{
PDC_LOG(("prefresh() - called\n"));
if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR)
return ERR;
doupdate();
return OK;
}
int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2)
{
int num_cols;
int sline = sy1;
int pline = py;
PDC_LOG(("pnoutrefresh() - called\n"));
if (!w || !(w->_flags & (_PAD|_SUBPAD)) || (sy2 >= LINES) || (sx2 >= COLS))
return ERR;
if (py < 0)
py = 0;
if (px < 0)
px = 0;
if (sy1 < 0)
sy1 = 0;
if (sx1 < 0)
sx1 = 0;
if (sy2 < sy1 || sx2 < sx1)
return ERR;
num_cols = min((sx2 - sx1 + 1), (w->_maxx - px));
while (sline <= sy2)
{
if (pline < w->_maxy)
{
memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px,
num_cols * sizeof(chtype));
if ((curscr->_firstch[sline] == _NO_CHANGE)
|| (curscr->_firstch[sline] > sx1))
curscr->_firstch[sline] = sx1;
if (sx2 > curscr->_lastch[sline])
curscr->_lastch[sline] = sx2;
w->_firstch[pline] = _NO_CHANGE;
w->_lastch[pline] = _NO_CHANGE;
}
sline++;
pline++;
}
if (w->_clear)
{
w->_clear = FALSE;
curscr->_clear = TRUE;
}
if (!w->_leaveit && w->_cury >= py && w->_curx >= px &&
w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1))
{
curscr->_cury = (w->_cury - py) + sy1;
curscr->_curx = (w->_curx - px) + sx1;
}
return OK;
}
int pechochar(WINDOW *pad, chtype ch)
{
PDC_LOG(("pechochar() - called\n"));
if (waddch(pad, ch) == ERR)
return ERR;
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
save_smincol, save_smaxrow, save_smaxcol);
}
#ifdef PDC_WIDE
int pecho_wchar(WINDOW *pad, const cchar_t *wch)
{
PDC_LOG(("pecho_wchar() - called\n"));
if (!wch || (waddch(pad, *wch) == ERR))
return ERR;
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
save_smincol, save_smaxrow, save_smaxcol);
}
#endif