1 2 3 4 5 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "ztypes.h"
#include "xio.h"
#define BLANKATTR (-1)
#define SPACEWIDTH (spacewidth[FIXED_FONT])
typedef struct sline_t {
int dirtybeg, dirtyend; /* [) protocol; -1,-1 for non-dirty */
int isclear; /* TRUE if text is all blank */
char *text; /* pointer to array of stat_wid chars */
int *attr; /* pointer to array of stat_wid ints */
int *font; /* pointer to array of stat_wid ints */
} sline;
/*static int stat_xpos, stat_ypos;*/ /* in pixels */
static int stat_realwid, stat_realhgt; /* in pixels */
static int stat_wid, stat_hgt; /* in chars */
static sline *linelist; /* array of stat_hgt slines */
static int linesused; /* z-machine's idea of the status line size */
static int maxlinesused; /* lines currently visible -- reset only by hitting return. */
static int curlines; /* actual window size */
static int cursorx, cursory;
static int cursorattr, cursorfont;
static int dotactive; /* is there an insertion mark? */
static int dotdrawn; /* is the insertion mark currently drawn? */
static int dotdrawnx, dotdrawny;
static XPoint polydot[3];
#ifdef __STDC__
static void resizewindow(int lines);
static void clearlines(int beg, int end);
static void flipdot();
#else
static void resizewindow();
static void clearlines();
static void flipdot();
#endif
#ifdef __STDC__
void xstat_init(int cols, int rows, int xpos, int ypos)
#else
void xstat_init(cols, rows, xpos, ypos)
int cols;
int rows;
int xpos;
int ypos;
#endif
{
int ix;
stat_wid = cols;
stat_hgt = rows;
/*stat_xpos = xpos;
stat_ypos = ypos;*/
stat_realwid = cols * SPACEWIDTH;
stat_realhgt = rows * lineheight;
polydot[0].x = 0;
polydot[0].y = 0;
polydot[1].x = 4;
polydot[1].y = 5;
polydot[2].x = -8;
polydot[2].y = 0;
dotactive = FALSE;
dotdrawn = FALSE;
dotdrawnx = 0;
dotdrawny = 0;
linelist = (sline *)malloc(sizeof(sline) * stat_hgt);
for (ix=0; ix<stat_hgt; ix++) {
linelist[ix].text = (char *)malloc(sizeof(char) * stat_wid);
linelist[ix].attr = (int *)malloc(sizeof(int) * stat_wid);
linelist[ix].font = (int *)malloc(sizeof(int) * stat_wid);
linelist[ix].isclear = FALSE;
}
linesused = 0;
maxlinesused = 0;
curlines = rows;
cursorx = 0;
cursory = 0;
cursorattr = FIXED_FONT;
cursorfont = TEXT_FONT;
#ifndef TESTING
/* export to ZIP code */
screen_cols = cols;
screen_rows = rows;
#endif
xstat_clear_window();
}
#ifdef __STDC__
void xstat_newgeometry(int newx, int newy, int newwid, int newhgt)
#else
void xstat_newgeometry(newx, newy, newwid, newhgt)
int newx;
int newy;
int newwid;
int newhgt;
#endif
{
stat_realwid = newwid;
stat_realhgt = newhgt;
}
#ifdef __STDC__
void xstat_redraw()
#else
void xstat_redraw()
#endif
{
int ix;
sline *curline;
for (ix=0; ix<stat_hgt; ix++) {
curline = (&linelist[ix]);
if (!curline->isclear) {
curline->dirtybeg = 0;
curline->dirtyend = stat_wid;
}
}
dotdrawn = FALSE;
xstat_layout();
}
#ifdef __STDC__
void xstat_insert(int ch)
#else
void xstat_insert(ch)
int ch;
#endif
{
sline *curline;
if (cursory<0 || cursory>=stat_hgt || cursorx<0 || cursorx>=stat_wid)
return;
if (cursory+1 > linesused) {
xstat_set_window_size(cursory+1);
}
curline = (&linelist[cursory]);
if (curline->text[cursorx] != (char)ch ||
curline->attr[cursorx] != cursorattr ||
curline->font[cursorx] != cursorfont) {
curline->text[cursorx] = (char)ch;
curline->attr[cursorx] = cursorattr;
curline->font[cursorx] = cursorfont;
curline->isclear = FALSE;
if (curline->dirtybeg == (-1) || cursorx < curline->dirtybeg)
curline->dirtybeg = cursorx;
if (curline->dirtyend == (-1) || cursorx+1 > curline->dirtyend)
curline->dirtyend = cursorx+1;
}
cursorx++;
if (cursorx == stat_wid) {
cursorx = 0;
cursory++;
}
}
#ifdef __STDC__
void xstat_newline()
#else
void xstat_newline()
#endif
{
cursorx = 0;
cursory++;
}
#ifdef __STDC__
void xstat_getpos(int *row, int *col)
#else
void xstat_getpos(row, col)
int *row;
int *col;
#endif
{
*col = cursorx+1;
*row = cursory+1;
}
#ifdef __STDC__
void xstat_setpos(int row, int col)
#else
void xstat_setpos(row, col)
int row;
int col;
#endif
{
cursorx = col-1;
cursory = row-1;
}
#ifdef __STDC__
void xstat_setattr(int attr, int font)
#else
void xstat_setattr(attr, font)
int attr;
int font;
#endif
{
cursorattr = attr | FIXED_FONT;
cursorfont = font;
}
#ifdef __STDC__
void xstat_set_window_size(int lines)
#else
void xstat_set_window_size(lines)
int lines;
#endif
{
linesused = lines;
if (lines > maxlinesused)
maxlinesused = lines;
}
#ifdef __STDC__
void xstat_set_dot_active(int visible)
#else
void xstat_set_dot_active(visible)
int visible;
#endif
{
if (visible) {
/* turn it on */
if (dotactive)
return;
dotactive = TRUE;
}
else {
/* turn it off */
if (!dotactive)
return;
dotactive = FALSE;
}
}
/* clear to blankness */
#ifdef __STDC__
void xstat_clear_window()
#else
void xstat_clear_window()
#endif
{
clearlines(0, stat_hgt);
linesused = 0;
maxlinesused = linesused; /* because anything below the status window has been cleared */
}
#ifdef __STDC__
static void clearlines(int beg, int end)
#else
static void clearlines(beg, end)
int beg;
int end;
#endif
{
int ix;
int jx;
char *cx;
int *ax;
for (ix=beg; ix<end; ix++) {
if (!linelist[ix].isclear) {
linelist[ix].isclear = TRUE;
linelist[ix].dirtybeg = 0;
linelist[ix].dirtyend = stat_wid;
for (cx=linelist[ix].text, jx=stat_wid; jx; cx++, jx--)
*cx = ' ';
for (ax=linelist[ix].attr, jx=stat_wid; jx; ax++, jx--)
*ax = BLANKATTR;
for (ax=linelist[ix].font, jx=stat_wid; jx; ax++, jx--)
*ax = TEXT_FONT;
}
}
}
/* redraw the dirty stuff */
#ifdef __STDC__
void xstat_layout()
#else
void xstat_layout()
#endif
{
int ix;
int beg, end, pos, px;
int attr, font;
int newsize;
sline *curline;
GC gcf, gcnf;
if (dotdrawn) {
flipdot();
dotdrawn = FALSE;
}
newsize = maxlinesused;
if (prefs.autoclear && newsize != curlines) {
clearlines(newsize, stat_hgt);
}
for (ix=0; ix<stat_hgt; ix++) {
curline = (&linelist[ix]);
if (curline->dirtybeg == (-1))
continue;
beg = curline->dirtybeg;
end = curline->dirtyend;
pos = beg;
while (pos < end) {
attr = curline->attr[pos];
font = curline->font[pos];
for (px=pos; px<end && curline->attr[px]==attr; px++);
gcf = gcsfont[attr];
gcnf = gcsnegfont[attr];
if (font == GRAPHICS_FONT)
{
gcf = gcsfont [FONT_FOR_GFX];
gcnf = gcsnegfont[FONT_FOR_GFX];
}
if (attr==BLANKATTR) {
XClearArea(xiodpy, xioswin, pos*SPACEWIDTH, ix*lineheight, (px-pos)*SPACEWIDTH, lineheight, FALSE);
}
else if (attr & REVERSE) {
XFillRectangle(xiodpy, xioswin, gcf, pos*SPACEWIDTH, ix*lineheight, (px-pos)*SPACEWIDTH, lineheight);
XDrawString(xiodpy, xioswin, gcnf, pos*SPACEWIDTH, ix*lineheight+lineheightoff, curline->text+pos, (px-pos));
}
else {
XClearArea(xiodpy, xioswin, pos*SPACEWIDTH, ix*lineheight, (px-pos)*SPACEWIDTH, lineheight, FALSE);
XDrawString(xiodpy, xioswin, gcf, pos*SPACEWIDTH, ix*lineheight+lineheightoff, curline->text+pos, (px-pos));
}
pos = px;
}
curline->dirtybeg = (-1);
curline->dirtyend = (-1);
}
if (dotactive) {
dotdrawnx = cursorx * SPACEWIDTH;
dotdrawny = cursory * lineheight + lineheightoff;
flipdot();
dotdrawn = TRUE;
}
if (prefs.autoresize && newsize != curlines) {
resizewindow(newsize);
}
}
/* reset the window size to linesused (if max==FALSE) or temporarily to stat_hgt (if max==TRUE) */
#ifdef __STDC__
void xstat_reset_window_size(int op)
#else
void xstat_reset_window_size(op)
int op;
#endif
{
int newsize;
if (op==op_Clear) {
clearlines(linesused, stat_hgt);
xstat_layout();
return;
}
else if (op==op_Zoom)
newsize = stat_hgt;
else if (op==op_Shrink)
newsize = linesused;
else {
return;
}
if (prefs.autoclear && newsize != curlines) {
clearlines(newsize, stat_hgt);
}
if (prefs.autoresize && newsize != curlines) {
resizewindow(newsize);
}
maxlinesused = newsize;
}
#ifdef __STDC__
static void resizewindow(int lines)
#else
static void resizewindow(lines)
int lines;
#endif
{
XSizeHints szhints;
int xp, yp;
int newheight;
Window child;
curlines = lines;
newheight = curlines*lineheight;
if (newheight==0)
newheight++;
if (!prefs.resizeupward) {
szhints.flags = USSize;
szhints.width = stat_wid*SPACEWIDTH;
szhints.height = newheight;
XResizeWindow(xiodpy, xioswin, szhints.width, szhints.height);
XSetNormalHints(xiodpy, xioswin, &szhints);
}
else {
XTranslateCoordinates(xiodpy, xioswin, RootWindow(xiodpy, xioscn), 0, 0, &xp, &yp, &child);
yp -= (newheight - stat_realhgt);
szhints.flags = PMinSize|PResizeInc|USPosition|USSize;
szhints.width = stat_wid*SPACEWIDTH;
szhints.height = newheight;
szhints.x = xp;
szhints.y = yp;
szhints.width_inc = spacewidth[FIXED_FONT];
szhints.height_inc = lineheight;
szhints.min_width = 1 * szhints.width_inc;
szhints.min_height = 1 * szhints.height_inc;
XMoveResizeWindow(xiodpy, xioswin, xp, yp, szhints.width, szhints.height);
XSetNormalHints(xiodpy, xioswin, &szhints);
}
}
#ifdef __STDC__
static void flipdot()
#else
static void flipdot()
#endif
{
polydot[0].x = dotdrawnx;
polydot[0].y = dotdrawny;
XFillPolygon(xiodpy, xioswin, gcsflip, polydot, 3, Convex, CoordModePrevious);
}
|