| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
– |
|
| 5 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* x11twind.c - routines for X11 text windows. |
| 6 |
|
* |
| 11 |
|
* 9/26/88 |
| 12 |
|
*/ |
| 13 |
|
|
| 14 |
< |
#include <stdio.h> |
| 14 |
> |
#include "copyright.h" |
| 15 |
|
|
| 16 |
+ |
#include <stdio.h> |
| 17 |
+ |
#include <stdlib.h> |
| 18 |
+ |
#include <string.h> |
| 19 |
|
#include <X11/Xlib.h> |
| 20 |
|
|
| 21 |
|
#include "x11twind.h" |
| 22 |
|
|
| 23 |
– |
#ifndef BSD |
| 24 |
– |
#define bzero(d,n) (void)memset(d,0,n) |
| 25 |
– |
extern char *memset(); |
| 26 |
– |
#endif |
| 27 |
– |
|
| 23 |
|
#define checkcurs(t) if ((t)->cursor) togglecurs(t) |
| 24 |
|
|
| 25 |
|
#define restorecurs checkcurs |
| 29 |
|
#define Height(f) ((f)->ascent + (f)->descent) |
| 30 |
|
#define YStart(f) ((f)->ascent) |
| 31 |
|
|
| 32 |
< |
extern char *calloc(), *malloc(); |
| 32 |
> |
static void togglecurs(); |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
TEXTWIND * |
| 36 |
< |
xt_open(dpy, gc, parent, x, y, width, height, bw, fontname) |
| 37 |
< |
Display *dpy; |
| 38 |
< |
GC gc; |
| 39 |
< |
Window parent; |
| 40 |
< |
int x, y; |
| 41 |
< |
int width, height; |
| 42 |
< |
int bw; |
| 43 |
< |
char *fontname; |
| 36 |
> |
xt_open(dpy, parent, x, y, width, height, bw, fore, back, fontname) |
| 37 |
> |
Display *dpy; |
| 38 |
> |
Window parent; |
| 39 |
> |
int x, y; |
| 40 |
> |
int width, height; |
| 41 |
> |
int bw; |
| 42 |
> |
unsigned long fore, back; |
| 43 |
> |
char *fontname; |
| 44 |
|
{ |
| 45 |
|
register int i; |
| 46 |
|
register TEXTWIND *t; |
| 49 |
|
return(NULL); |
| 50 |
|
|
| 51 |
|
t->dpy = dpy; |
| 52 |
< |
t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, bw, |
| 53 |
< |
BlackPixel(dpy,DefaultScreen(dpy)), |
| 59 |
< |
WhitePixel(dpy,DefaultScreen(dpy))); |
| 60 |
< |
/* |
| 61 |
< |
t->w = XCreateWindow(dpy, parent, x, y, width, height, bw, 0, |
| 62 |
< |
CopyFromParent, CopyFromParent, 0, 0); |
| 63 |
< |
*/ |
| 64 |
< |
|
| 52 |
> |
t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, |
| 53 |
> |
bw, fore, back); |
| 54 |
|
if (t->w == 0) |
| 55 |
|
return(NULL); |
| 56 |
|
XMapWindow(dpy, t->w); |
| 60 |
|
|
| 61 |
|
/* if (!t->f.fixedwidth) check for fixedwidth later |
| 62 |
|
return(NULL); */ |
| 74 |
– |
t->gc = XCreateGC(dpy,t->w,0,NULL); |
| 63 |
|
|
| 64 |
< |
XCopyGC(dpy, gc, ~0L, t->gc); |
| 65 |
< |
|
| 64 |
> |
t->gc = XCreateGC(dpy,t->w,0,NULL); |
| 65 |
> |
XSetState(dpy, t->gc, fore, back, GXcopy, AllPlanes); |
| 66 |
|
XSetFont(dpy, t->gc, t->f->fid); |
| 79 |
– |
XSetFunction(dpy, t->gc, GXcopy); |
| 67 |
|
|
| 68 |
|
t->nc = (width - LEFTMAR) / |
| 69 |
|
Width(t->f); /* number of columns */ |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
< |
xt_puts(s, t) /* output a string */ |
| 100 |
< |
register char *s; |
| 101 |
< |
TEXTWIND *t; |
| 102 |
< |
{ |
| 103 |
< |
int oldcurs; |
| 104 |
< |
|
| 105 |
< |
oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ |
| 106 |
< |
while (*s) |
| 107 |
< |
xt_putc(*s++, t); |
| 108 |
< |
xt_cursor(t, oldcurs); |
| 109 |
< |
} |
| 110 |
< |
|
| 111 |
< |
|
| 86 |
> |
void |
| 87 |
|
xt_putc(c, t) /* output a character */ |
| 88 |
< |
char c; |
| 88 |
> |
int c; |
| 89 |
|
register TEXTWIND *t; |
| 90 |
|
{ |
| 91 |
+ |
char ch[2]; |
| 92 |
+ |
|
| 93 |
|
checkcurs(t); |
| 94 |
|
switch (c) { |
| 95 |
|
case '\n': |
| 110 |
|
default: |
| 111 |
|
if (t->c >= t->nc) |
| 112 |
|
xt_putc('\n', t); |
| 113 |
+ |
ch[0] = c; ch[1] = '\0'; |
| 114 |
|
XDrawImageString(t->dpy, t->w, t->gc, LEFTMAR+t->c*Width(t->f), |
| 115 |
< |
YStart(t->f)+t->r*Height(t->f), &c, 1); |
| 115 |
> |
YStart(t->f)+t->r*Height(t->f), ch, 1); |
| 116 |
|
t->lp[t->r][t->c++] = c; |
| 117 |
|
break; |
| 118 |
|
} |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
+ |
void |
| 124 |
+ |
xt_puts(s, t) /* output a string */ |
| 125 |
+ |
register char *s; |
| 126 |
+ |
TEXTWIND *t; |
| 127 |
+ |
{ |
| 128 |
+ |
int oldcurs; |
| 129 |
+ |
|
| 130 |
+ |
oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ |
| 131 |
+ |
while (*s) |
| 132 |
+ |
xt_putc(*s++, t); |
| 133 |
+ |
xt_cursor(t, oldcurs); |
| 134 |
+ |
} |
| 135 |
+ |
|
| 136 |
+ |
|
| 137 |
+ |
void |
| 138 |
|
xt_delete(t, r) /* delete a line */ |
| 139 |
|
register TEXTWIND *t; |
| 140 |
|
int r; |
| 157 |
|
XClearArea(t->dpy, t->w, LEFTMAR, (t->nr-1)*Height(t->f), |
| 158 |
|
t->nc*Width(t->f), Height(t->f),(Bool) 0); |
| 159 |
|
|
| 160 |
< |
bzero(cp, t->nc); |
| 160 |
> |
memset(cp, '\0', t->nc); |
| 161 |
|
restorecurs(t); /* should we reposition cursor? */ |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
|
| 165 |
+ |
void |
| 166 |
|
xt_insert(t, r) /* insert a line */ |
| 167 |
|
register TEXTWIND *t; |
| 168 |
|
int r; |
| 184 |
|
/* clear new line */ |
| 185 |
|
XClearArea(t->dpy, t->w, LEFTMAR, r*Height(t->f), |
| 186 |
|
t->nc*Width(t->f), Height(t->f), (Bool) 0); |
| 187 |
< |
bzero(cp, t->nc); |
| 187 |
> |
memset(cp, '\0', t->nc); |
| 188 |
|
restorecurs(t); /* should we reposition cursor? */ |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
+ |
void |
| 193 |
|
xt_redraw(t) /* redraw text window */ |
| 194 |
|
register TEXTWIND *t; |
| 195 |
|
{ |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
|
| 208 |
+ |
void |
| 209 |
|
xt_clear(t) /* clear text window */ |
| 210 |
|
register TEXTWIND *t; |
| 211 |
|
{ |
| 213 |
|
|
| 214 |
|
XClearWindow(t->dpy, t->w); |
| 215 |
|
for (i = 0; i < t->nr; i++) |
| 216 |
< |
bzero(t->lp[i], t->nc); |
| 216 |
> |
memset(t->lp[i], '\0', t->nc); |
| 217 |
|
t->r = t->c = 0; |
| 218 |
|
restorecurs(t); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
+ |
void |
| 223 |
|
xt_move(t, r, c) /* move to new position */ |
| 224 |
|
register TEXTWIND *t; |
| 225 |
|
int r, c; |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
|
| 253 |
+ |
void |
| 254 |
|
xt_close(t) /* close text window */ |
| 255 |
|
register TEXTWIND *t; |
| 256 |
|
{ |
| 261 |
|
XDestroyWindow(t->dpy, t->w); |
| 262 |
|
for (i = 0; i < t->nr; i++) |
| 263 |
|
free(t->lp[i]); |
| 264 |
< |
free((char *)t->lp); |
| 265 |
< |
free((char *)t); |
| 264 |
> |
free((void *)t->lp); |
| 265 |
> |
free((void *)t); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 269 |
< |
static |
| 269 |
> |
static void |
| 270 |
|
togglecurs(t) |
| 271 |
|
register TEXTWIND *t; |
| 272 |
|
{ |