/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56pad7---89### Synopsis1011WINDOW *newpad(int nlines, int ncols);12WINDOW *subpad(WINDOW *orig, int nlines, int ncols,13int begy, int begx);14int prefresh(WINDOW *win, int py, int px, int sy1, int sx1,15int sy2, int sx2);16int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1,17int sy2, int sx2);18int pechochar(WINDOW *pad, chtype ch);19int pecho_wchar(WINDOW *pad, const cchar_t *wch);2021bool is_pad(const WINDOW *pad);2223### Description2425A pad is a special kind of window, which is not restricted by the26screen size, and is not necessarily associated with a particular part27of the screen. You can use a pad when you need a large window, and28only a part of the window will be on the screen at one time. Pads are29not refreshed automatically (e.g., from scrolling or echoing of30input). You can't call wrefresh() with a pad as an argument; use31prefresh() or pnoutrefresh() instead. Note that these routines32require additional parameters to specify the part of the pad to be33displayed, and the location to use on the screen.3435newpad() creates a new pad data structure.3637subpad() creates a new sub-pad within a pad, at position (begy,38begx), with dimensions of nlines lines and ncols columns. This39position is relative to the pad, and not to the screen as with40subwin. Changes to either the parent pad or sub-pad will affect both.41When using sub-pads, you may need to call touchwin() before calling42prefresh().4344pnoutrefresh() copies the specified pad to the virtual screen.4546prefresh() calls pnoutrefresh(), followed by doupdate().4748These routines are analogous to wnoutrefresh() and wrefresh(). (py,49px) specifies the upper left corner of the part of the pad to be50displayed; (sy1, sx1) and (sy2, sx2) describe the screen rectangle51that will contain the selected part of the pad.5253pechochar() is functionally equivalent to addch() followed by a call54to prefresh(), with the last-used coordinates and dimensions.55pecho_wchar() is the wide-character version.5657is_pad() reports whether the specified window is a pad.5859### Return Value6061All functions except is_pad() return OK on success and ERR on error.6263### Portability64X/Open ncurses NetBSD65newpad Y Y Y66subpad Y Y Y67prefresh Y Y Y68pnoutrefresh Y Y Y69pechochar Y Y Y70pecho_wchar Y Y Y71is_pad - Y Y7273**man-end****************************************************************/7475#include <string.h>7677/* save values for pechochar() */7879static int save_pminrow, save_pmincol;80static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol;8182WINDOW *newpad(int nlines, int ncols)83{84WINDOW *win;8586PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols));8788win = PDC_makenew(nlines, ncols, 0, 0);89if (win)90win = PDC_makelines(win);9192if (!win)93return (WINDOW *)NULL;9495werase(win);9697win->_flags = _PAD;9899/* save default values in case pechochar() is the first call to100prefresh(). */101102save_pminrow = 0;103save_pmincol = 0;104save_sminrow = 0;105save_smincol = 0;106save_smaxrow = min(LINES, nlines) - 1;107save_smaxcol = min(COLS, ncols) - 1;108109return win;110}111112WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx)113{114WINDOW *win;115int i;116117PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n",118nlines, ncols, begy, begx));119120if (!orig || !(orig->_flags & _PAD))121return (WINDOW *)NULL;122123/* make sure window fits inside the original one */124125if (begy < 0 || begx < 0 ||126(begy + nlines) > orig->_maxy ||127(begx + ncols) > orig->_maxx)128return (WINDOW *)NULL;129130if (!nlines)131nlines = orig->_maxy - begy;132133if (!ncols)134ncols = orig->_maxx - begx;135136win = PDC_makenew(nlines, ncols, begy, begx);137if (!win)138return (WINDOW *)NULL;139140/* initialize window variables */141142win->_attrs = orig->_attrs;143win->_leaveit = orig->_leaveit;144win->_scroll = orig->_scroll;145win->_nodelay = orig->_nodelay;146win->_use_keypad = orig->_use_keypad;147win->_parent = orig;148149for (i = 0; i < nlines; i++)150win->_y[i] = orig->_y[begy + i] + begx;151152win->_flags = _SUBPAD;153154/* save default values in case pechochar() is the first call155to prefresh(). */156157save_pminrow = 0;158save_pmincol = 0;159save_sminrow = 0;160save_smincol = 0;161save_smaxrow = min(LINES, nlines) - 1;162save_smaxcol = min(COLS, ncols) - 1;163164return win;165}166167int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2)168{169PDC_LOG(("prefresh() - called\n"));170171if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR)172return ERR;173174doupdate();175return OK;176}177178int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2)179{180int num_cols;181int sline;182int pline;183184PDC_LOG(("pnoutrefresh() - called\n"));185186if (py < 0)187py = 0;188if (px < 0)189px = 0;190if (sy1 < 0)191sy1 = 0;192if (sx1 < 0)193sx1 = 0;194195if ((!w || !(w->_flags & (_PAD|_SUBPAD)) ||196(sy2 >= LINES) || (sx2 >= COLS)) ||197(sy2 < sy1) || (sx2 < sx1))198return ERR;199200sline = sy1;201pline = py;202203num_cols = min((sx2 - sx1 + 1), (w->_maxx - px));204205while (sline <= sy2)206{207if (pline < w->_maxy)208{209memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px,210num_cols * sizeof(chtype));211212if ((curscr->_firstch[sline] == _NO_CHANGE)213|| (curscr->_firstch[sline] > sx1))214curscr->_firstch[sline] = sx1;215216if (sx2 > curscr->_lastch[sline])217curscr->_lastch[sline] = sx2;218219w->_firstch[pline] = _NO_CHANGE; /* updated now */220w->_lastch[pline] = _NO_CHANGE; /* updated now */221}222223sline++;224pline++;225}226227if (w->_clear)228{229w->_clear = FALSE;230curscr->_clear = TRUE;231}232233/* position the cursor to the pad's current position if possible --234is the pad current position going to end up displayed? if not,235then don't move the cursor; if so, move it to the correct place */236237if (!w->_leaveit && w->_cury >= py && w->_curx >= px &&238w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1))239{240curscr->_cury = (w->_cury - py) + sy1;241curscr->_curx = (w->_curx - px) + sx1;242}243244return OK;245}246247int pechochar(WINDOW *pad, chtype ch)248{249PDC_LOG(("pechochar() - called\n"));250251if (waddch(pad, ch) == ERR)252return ERR;253254return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,255save_smincol, save_smaxrow, save_smaxcol);256}257258#ifdef PDC_WIDE259int pecho_wchar(WINDOW *pad, const cchar_t *wch)260{261PDC_LOG(("pecho_wchar() - called\n"));262263if (!wch || (waddch(pad, *wch) == ERR))264return ERR;265266return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,267save_smincol, save_smaxrow, save_smaxcol);268}269#endif270271bool is_pad(const WINDOW *pad)272{273PDC_LOG(("is_pad() - called\n"));274275if (!pad)276return FALSE;277278return (pad->_flags & _PAD) ? TRUE : FALSE;279}280281282