| 1 |
|
| 2 |
|
| 3 |
#include <curspriv.h> |
| 4 |
|
| 5 |
RCSID("$Id: pad.c,v 1.50 2008/07/14 12:22:13 wmcbrine Exp $") |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
#include <string.h> |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static int save_pminrow, save_pmincol; |
| 74 |
static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol; |
| 75 |
|
| 76 |
WINDOW *newpad(int nlines, int ncols) |
| 77 |
{ |
| 78 |
WINDOW *win; |
| 79 |
|
| 80 |
PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols)); |
| 81 |
|
| 82 |
if ( !(win = PDC_makenew(nlines, ncols, -1, -1)) |
| 83 |
|| !(win = PDC_makelines(win)) ) |
| 84 |
return (WINDOW *)NULL; |
| 85 |
|
| 86 |
werase(win); |
| 87 |
|
| 88 |
win->_flags = _PAD; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
save_pminrow = 0; |
| 94 |
save_pmincol = 0; |
| 95 |
save_sminrow = 0; |
| 96 |
save_smincol = 0; |
| 97 |
save_smaxrow = min(LINES, nlines) - 1; |
| 98 |
save_smaxcol = min(COLS, ncols) - 1; |
| 99 |
|
| 100 |
return win; |
| 101 |
} |
| 102 |
|
| 103 |
WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) |
| 104 |
{ |
| 105 |
WINDOW *win; |
| 106 |
int i; |
| 107 |
int j = begy; |
| 108 |
int k = begx; |
| 109 |
|
| 110 |
PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n", |
| 111 |
nlines, ncols, begy, begx)); |
| 112 |
|
| 113 |
if (!orig || !(orig->_flags & _PAD)) |
| 114 |
return (WINDOW *)NULL; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
if ((begy < orig->_begy) || (begx < orig->_begx) || |
| 119 |
(begy + nlines) > (orig->_begy + orig->_maxy) || |
| 120 |
(begx + ncols) > (orig->_begx + orig->_maxx)) |
| 121 |
return (WINDOW *)NULL; |
| 122 |
|
| 123 |
if (!nlines) |
| 124 |
nlines = orig->_maxy - 1 - j; |
| 125 |
|
| 126 |
if (!ncols) |
| 127 |
ncols = orig->_maxx - 1 - k; |
| 128 |
|
| 129 |
if ( !(win = PDC_makenew(nlines, ncols, begy, begx)) ) |
| 130 |
return (WINDOW *)NULL; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
win->_attrs = orig->_attrs; |
| 135 |
win->_leaveit = orig->_leaveit; |
| 136 |
win->_scroll = orig->_scroll; |
| 137 |
win->_nodelay = orig->_nodelay; |
| 138 |
win->_use_keypad = orig->_use_keypad; |
| 139 |
win->_parent = orig; |
| 140 |
|
| 141 |
for (i = 0; i < nlines; i++) |
| 142 |
win->_y[i] = (orig->_y[j++]) + k; |
| 143 |
|
| 144 |
win->_flags = _SUBPAD; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
save_pminrow = 0; |
| 150 |
save_pmincol = 0; |
| 151 |
save_sminrow = 0; |
| 152 |
save_smincol = 0; |
| 153 |
save_smaxrow = min(LINES, nlines) - 1; |
| 154 |
save_smaxcol = min(COLS, ncols) - 1; |
| 155 |
|
| 156 |
return win; |
| 157 |
} |
| 158 |
|
| 159 |
int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2) |
| 160 |
{ |
| 161 |
PDC_LOG(("prefresh() - called\n")); |
| 162 |
|
| 163 |
if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR) |
| 164 |
return ERR; |
| 165 |
|
| 166 |
doupdate(); |
| 167 |
return OK; |
| 168 |
} |
| 169 |
|
| 170 |
int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2) |
| 171 |
{ |
| 172 |
int num_cols; |
| 173 |
int sline = sy1; |
| 174 |
int pline = py; |
| 175 |
|
| 176 |
PDC_LOG(("pnoutrefresh() - called\n")); |
| 177 |
|
| 178 |
if (!w || !(w->_flags & (_PAD|_SUBPAD)) || (sy2 >= LINES) || (sy2 >= COLS)) |
| 179 |
return ERR; |
| 180 |
|
| 181 |
if (py < 0) |
| 182 |
py = 0; |
| 183 |
if (px < 0) |
| 184 |
px = 0; |
| 185 |
if (sy1 < 0) |
| 186 |
sy1 = 0; |
| 187 |
if (sx1 < 0) |
| 188 |
sx1 = 0; |
| 189 |
|
| 190 |
if (sy2 < sy1 || sx2 < sx1) |
| 191 |
return ERR; |
| 192 |
|
| 193 |
num_cols = min((sx2 - sx1 + 1), (w->_maxx - px)); |
| 194 |
|
| 195 |
while (sline <= sy2) |
| 196 |
{ |
| 197 |
if (pline < w->_maxy) |
| 198 |
{ |
| 199 |
memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px, |
| 200 |
num_cols * sizeof(chtype)); |
| 201 |
|
| 202 |
if ((curscr->_firstch[sline] == _NO_CHANGE) |
| 203 |
|| (curscr->_firstch[sline] > sx1)) |
| 204 |
curscr->_firstch[sline] = sx1; |
| 205 |
|
| 206 |
if (sx2 > curscr->_lastch[sline]) |
| 207 |
curscr->_lastch[sline] = sx2; |
| 208 |
|
| 209 |
w->_firstch[pline] = _NO_CHANGE; |
| 210 |
w->_lastch[pline] = _NO_CHANGE; |
| 211 |
} |
| 212 |
|
| 213 |
sline++; |
| 214 |
pline++; |
| 215 |
} |
| 216 |
|
| 217 |
if (w->_clear) |
| 218 |
{ |
| 219 |
w->_clear = FALSE; |
| 220 |
curscr->_clear = TRUE; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
if (!w->_leaveit && w->_cury >= py && w->_curx >= px && |
| 228 |
w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1)) |
| 229 |
{ |
| 230 |
curscr->_cury = (w->_cury - py) + sy1; |
| 231 |
curscr->_curx = (w->_curx - px) + sx1; |
| 232 |
} |
| 233 |
|
| 234 |
return OK; |
| 235 |
} |
| 236 |
|
| 237 |
int pechochar(WINDOW *pad, chtype ch) |
| 238 |
{ |
| 239 |
PDC_LOG(("pechochar() - called\n")); |
| 240 |
|
| 241 |
if (waddch(pad, ch) == ERR) |
| 242 |
return ERR; |
| 243 |
|
| 244 |
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow, |
| 245 |
save_smincol, save_smaxrow, save_smaxcol); |
| 246 |
} |
| 247 |
|
| 248 |
#ifdef PDC_WIDE |
| 249 |
int pecho_wchar(WINDOW *pad, const cchar_t *wch) |
| 250 |
{ |
| 251 |
PDC_LOG(("pecho_wchar() - called\n")); |
| 252 |
|
| 253 |
if (!wch || (waddch(pad, *wch) == ERR)) |
| 254 |
return ERR; |
| 255 |
|
| 256 |
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow, |
| 257 |
save_smincol, save_smaxrow, save_smaxcol); |
| 258 |
} |
| 259 |
#endif |