/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56touch7-----89### Synopsis1011int touchwin(WINDOW *win);12int touchline(WINDOW *win, int start, int count);13int untouchwin(WINDOW *win);14int wtouchln(WINDOW *win, int y, int n, int changed);15bool is_linetouched(WINDOW *win, int line);16bool is_wintouched(WINDOW *win);1718int touchoverlap(const WINDOW *win1, WINDOW *win2);1920### Description2122touchwin() and touchline() throw away all information about which23parts of the window have been touched, pretending that the entire24window has been drawn on. This is sometimes necessary when using25overlapping windows, since a change to one window will affect the26other window, but the records of which lines have been changed in the27other window will not reflect the change.2829untouchwin() marks all lines in the window as unchanged since the30last call to wrefresh().3132wtouchln() makes n lines in the window, starting at line y, look as33if they have (changed == 1) or have not (changed == 0) been changed34since the last call to wrefresh().3536is_linetouched() returns TRUE if the specified line in the specified37window has been changed since the last call to wrefresh().3839is_wintouched() returns TRUE if the specified window has been changed40since the last call to wrefresh().4142touchoverlap(win1, win2) marks the portion of win2 which overlaps43with win1 as modified.4445### Return Value4647All functions return OK on success and ERR on error except48is_wintouched() and is_linetouched().4950### Portability51X/Open ncurses NetBSD52touchwin Y Y Y53touchline Y Y Y54untouchwin Y Y Y55wtouchln Y Y Y56is_linetouched Y Y Y57is_wintouched Y Y Y58touchoverlap - - Y5960**man-end****************************************************************/6162int touchwin(WINDOW *win)63{64int i;6566PDC_LOG(("touchwin() - called: Win=%x\n", win));6768if (!win)69return ERR;7071for (i = 0; i < win->_maxy; i++)72{73win->_firstch[i] = 0;74win->_lastch[i] = win->_maxx - 1;75}7677return OK;78}7980int touchline(WINDOW *win, int start, int count)81{82int i;8384PDC_LOG(("touchline() - called: win=%p start %d count %d\n",85win, start, count));8687if (!win || start > win->_maxy || start + count > win->_maxy)88return ERR;8990for (i = start; i < start + count; i++)91{92win->_firstch[i] = 0;93win->_lastch[i] = win->_maxx - 1;94}9596return OK;97}9899int untouchwin(WINDOW *win)100{101int i;102103PDC_LOG(("untouchwin() - called: win=%p", win));104105if (!win)106return ERR;107108for (i = 0; i < win->_maxy; i++)109{110win->_firstch[i] = _NO_CHANGE;111win->_lastch[i] = _NO_CHANGE;112}113114return OK;115}116117int wtouchln(WINDOW *win, int y, int n, int changed)118{119int i;120121PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n",122win, y, n, changed));123124if (!win || y > win->_maxy || y + n > win->_maxy)125return ERR;126127for (i = y; i < y + n; i++)128{129if (changed)130{131win->_firstch[i] = 0;132win->_lastch[i] = win->_maxx - 1;133}134else135{136win->_firstch[i] = _NO_CHANGE;137win->_lastch[i] = _NO_CHANGE;138}139}140141return OK;142}143144bool is_linetouched(WINDOW *win, int line)145{146PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line));147148if (!win || line > win->_maxy || line < 0)149return FALSE;150151return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE;152}153154bool is_wintouched(WINDOW *win)155{156int i;157158PDC_LOG(("is_wintouched() - called: win=%p\n", win));159160if (win)161for (i = 0; i < win->_maxy; i++)162if (win->_firstch[i] != _NO_CHANGE)163return TRUE;164165return FALSE;166}167168int touchoverlap(const WINDOW *win1, WINDOW *win2)169{170int y, endy, endx, starty, startx;171172PDC_LOG(("touchoverlap() - called: win1=%p win2=%p\n", win1, win2));173174if (!win1 || !win2)175return ERR;176177starty = max(win1->_begy, win2->_begy);178startx = max(win1->_begx, win2->_begx);179endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);180endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);181182if (starty >= endy || startx >= endx)183return OK;184185starty -= win2->_begy;186startx -= win2->_begx;187endy -= win2->_begy;188endx -= win2->_begx;189endx -= 1;190191for (y = starty; y < endy; y++)192{193win2->_firstch[y] = startx;194win2->_lastch[y] = endx;195}196197return OK;198}199200201