--- ray/src/rt/x11twind.c 1989/12/19 12:54:31 1.1 +++ ray/src/rt/x11twind.c 2003/06/30 14:59:13 2.9 @@ -1,9 +1,6 @@ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: x11twind.c,v 2.9 2003/06/30 14:59:13 schorsch Exp $"; #endif - -/* Copyright (c) 1989 Regents of the University of California */ - /* * x11twind.c - routines for X11 text windows. * @@ -14,8 +11,11 @@ static char SCCSid[] = "$SunId$ LBL"; * 9/26/88 */ -#include +#include "copyright.h" +#include +#include +#include #include #include "x11twind.h" @@ -29,18 +29,18 @@ static char SCCSid[] = "$SunId$ LBL"; #define Height(f) ((f)->ascent + (f)->descent) #define YStart(f) ((f)->ascent) -extern char *calloc(), *malloc(); +static void togglecurs(); TEXTWIND * -xt_open(dpy, gc, parent, x, y, width, height, bw, fontname) -Display *dpy; -GC gc; -Window parent; -int x, y; -int width, height; -int bw; -char *fontname; +xt_open(dpy, parent, x, y, width, height, bw, fore, back, fontname) +Display *dpy; +Window parent; +int x, y; +int width, height; +int bw; +unsigned long fore, back; +char *fontname; { register int i; register TEXTWIND *t; @@ -49,14 +49,8 @@ char *fontname; return(NULL); t->dpy = dpy; - t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, bw, - BlackPixel(dpy,DefaultScreen(dpy)), - WhitePixel(dpy,DefaultScreen(dpy))); - /* - t->w = XCreateWindow(dpy, parent, x, y, width, height, bw, 0, - CopyFromParent, CopyFromParent, 0, 0); - */ - + t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, + bw, fore, back); if (t->w == 0) return(NULL); XMapWindow(dpy, t->w); @@ -66,12 +60,10 @@ char *fontname; /* if (!t->f.fixedwidth) check for fixedwidth later return(NULL); */ - t->gc = XCreateGC(dpy,t->w,0,NULL); - XCopyGC(dpy, gc, ~0L, t->gc); - + t->gc = XCreateGC(dpy,t->w,0,NULL); + XSetState(dpy, t->gc, fore, back, GXcopy, AllPlanes); XSetFont(dpy, t->gc, t->f->fid); - XSetFunction(dpy, t->gc, GXcopy); t->nc = (width - LEFTMAR) / Width(t->f); /* number of columns */ @@ -91,23 +83,13 @@ char *fontname; } -xt_puts(s, t) /* output a string */ -register char *s; -TEXTWIND *t; -{ - int oldcurs; - - oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ - while (*s) - xt_putc(*s++, t); - xt_cursor(t, oldcurs); -} - - +void xt_putc(c, t) /* output a character */ -char c; +int c; register TEXTWIND *t; { + char ch[2]; + checkcurs(t); switch (c) { case '\n': @@ -128,8 +110,9 @@ register TEXTWIND *t; default: if (t->c >= t->nc) xt_putc('\n', t); + ch[0] = c; ch[1] = '\0'; XDrawImageString(t->dpy, t->w, t->gc, LEFTMAR+t->c*Width(t->f), - YStart(t->f)+t->r*Height(t->f), &c, 1); + YStart(t->f)+t->r*Height(t->f), ch, 1); t->lp[t->r][t->c++] = c; break; } @@ -137,6 +120,21 @@ register TEXTWIND *t; } +void +xt_puts(s, t) /* output a string */ +register char *s; +TEXTWIND *t; +{ + int oldcurs; + + oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ + while (*s) + xt_putc(*s++, t); + xt_cursor(t, oldcurs); +} + + +void xt_delete(t, r) /* delete a line */ register TEXTWIND *t; int r; @@ -159,11 +157,12 @@ int r; XClearArea(t->dpy, t->w, LEFTMAR, (t->nr-1)*Height(t->f), t->nc*Width(t->f), Height(t->f),(Bool) 0); - bzero(cp, t->nc); + memset(cp, '\0', t->nc); restorecurs(t); /* should we reposition cursor? */ } +void xt_insert(t, r) /* insert a line */ register TEXTWIND *t; int r; @@ -185,11 +184,12 @@ int r; /* clear new line */ XClearArea(t->dpy, t->w, LEFTMAR, r*Height(t->f), t->nc*Width(t->f), Height(t->f), (Bool) 0); - bzero(cp, t->nc); + memset(cp, '\0', t->nc); restorecurs(t); /* should we reposition cursor? */ } +void xt_redraw(t) /* redraw text window */ register TEXTWIND *t; { @@ -205,6 +205,7 @@ register TEXTWIND *t; } +void xt_clear(t) /* clear text window */ register TEXTWIND *t; { @@ -212,12 +213,13 @@ register TEXTWIND *t; XClearWindow(t->dpy, t->w); for (i = 0; i < t->nr; i++) - bzero(t->lp[i], t->nc); + memset(t->lp[i], '\0', t->nc); t->r = t->c = 0; restorecurs(t); } +void xt_move(t, r, c) /* move to new position */ register TEXTWIND *t; int r, c; @@ -248,6 +250,7 @@ register int curs; } +void xt_close(t) /* close text window */ register TEXTWIND *t; { @@ -258,12 +261,12 @@ register TEXTWIND *t; XDestroyWindow(t->dpy, t->w); for (i = 0; i < t->nr; i++) free(t->lp[i]); - free((char *)t->lp); - free((char *)t); + free((void *)t->lp); + free((void *)t); } -static +static void togglecurs(t) register TEXTWIND *t; {