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" |
29 |
|
#define Height(f) ((f)->ascent + (f)->descent) |
30 |
|
#define YStart(f) ((f)->ascent) |
31 |
|
|
32 |
< |
extern char *calloc(), *malloc(); |
32 |
> |
static void togglecurs(TEXTWIND *t); |
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( |
37 |
> |
Display *dpy, |
38 |
> |
Window parent, |
39 |
> |
int x, int y, |
40 |
> |
int width, int height, |
41 |
> |
int bw, |
42 |
> |
unsigned long fore, unsigned long back, |
43 |
> |
char *fontname |
44 |
> |
) |
45 |
|
{ |
46 |
< |
register int i; |
47 |
< |
register TEXTWIND *t; |
46 |
> |
int i; |
47 |
> |
TEXTWIND *t; |
48 |
|
|
49 |
|
if ((t = (TEXTWIND *)malloc(sizeof(TEXTWIND))) == NULL) |
50 |
|
return(NULL); |
51 |
|
|
52 |
|
t->dpy = dpy; |
53 |
< |
t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, bw, |
54 |
< |
BlackPixel(dpy,DefaultScreen(dpy)), |
54 |
< |
WhitePixel(dpy,DefaultScreen(dpy))); |
55 |
< |
/* |
56 |
< |
t->w = XCreateWindow(dpy, parent, x, y, width, height, bw, 0, |
57 |
< |
CopyFromParent, CopyFromParent, 0, 0); |
58 |
< |
*/ |
59 |
< |
|
53 |
> |
t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height, |
54 |
> |
bw, fore, back); |
55 |
|
if (t->w == 0) |
56 |
|
return(NULL); |
57 |
|
XMapWindow(dpy, t->w); |
61 |
|
|
62 |
|
/* if (!t->f.fixedwidth) check for fixedwidth later |
63 |
|
return(NULL); */ |
69 |
– |
t->gc = XCreateGC(dpy,t->w,0,NULL); |
64 |
|
|
65 |
< |
XCopyGC(dpy, gc, ~0L, t->gc); |
66 |
< |
|
65 |
> |
t->gc = XCreateGC(dpy,t->w,0,NULL); |
66 |
> |
XSetState(dpy, t->gc, fore, back, GXcopy, AllPlanes); |
67 |
|
XSetFont(dpy, t->gc, t->f->fid); |
74 |
– |
XSetFunction(dpy, t->gc, GXcopy); |
68 |
|
|
69 |
|
t->nc = (width - LEFTMAR) / |
70 |
|
Width(t->f); /* number of columns */ |
71 |
|
t->nr = height / |
72 |
|
Height(t->f); /* number of rows */ |
73 |
< |
if (t->nc < 1 || t->nr < 1) |
73 |
> |
if ((t->nc < 1) | (t->nr < 1)) |
74 |
|
return(NULL); |
75 |
|
if ((t->lp = (char **)calloc(t->nr, sizeof(char *))) == NULL) |
76 |
|
return(NULL); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
< |
xt_puts(s, t) /* output a string */ |
88 |
< |
register char *s; |
89 |
< |
TEXTWIND *t; |
87 |
> |
void |
88 |
> |
xt_putc( /* output a character */ |
89 |
> |
int c, |
90 |
> |
TEXTWIND *t |
91 |
> |
) |
92 |
|
{ |
93 |
< |
int oldcurs; |
93 |
> |
char ch[2]; |
94 |
|
|
100 |
– |
oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ |
101 |
– |
while (*s) |
102 |
– |
xt_putc(*s++, t); |
103 |
– |
xt_cursor(t, oldcurs); |
104 |
– |
} |
105 |
– |
|
106 |
– |
|
107 |
– |
xt_putc(c, t) /* output a character */ |
108 |
– |
char c; |
109 |
– |
register TEXTWIND *t; |
110 |
– |
{ |
95 |
|
checkcurs(t); |
96 |
|
switch (c) { |
97 |
|
case '\n': |
112 |
|
default: |
113 |
|
if (t->c >= t->nc) |
114 |
|
xt_putc('\n', t); |
115 |
+ |
ch[0] = c; ch[1] = '\0'; |
116 |
|
XDrawImageString(t->dpy, t->w, t->gc, LEFTMAR+t->c*Width(t->f), |
117 |
< |
YStart(t->f)+t->r*Height(t->f), &c, 1); |
117 |
> |
YStart(t->f)+t->r*Height(t->f), ch, 1); |
118 |
|
t->lp[t->r][t->c++] = c; |
119 |
|
break; |
120 |
|
} |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
xt_delete(t, r) /* delete a line */ |
126 |
< |
register TEXTWIND *t; |
142 |
< |
int r; |
125 |
> |
void |
126 |
> |
xt_puts(const char *s, TEXTWIND *t) /* output a string */ |
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( /* delete a line */ |
139 |
+ |
TEXTWIND *t, |
140 |
+ |
int r |
141 |
+ |
) |
142 |
+ |
{ |
143 |
|
char *cp; |
144 |
< |
register int i; |
144 |
> |
int i; |
145 |
|
|
146 |
< |
if (r < 0 || r >= t->nr) |
146 |
> |
if ((r < 0) | (r >= t->nr)) |
147 |
|
return; |
148 |
|
checkcurs(t); |
149 |
|
/* move lines */ |
158 |
|
XClearArea(t->dpy, t->w, LEFTMAR, (t->nr-1)*Height(t->f), |
159 |
|
t->nc*Width(t->f), Height(t->f),(Bool) 0); |
160 |
|
|
161 |
< |
bzero(cp, t->nc); |
161 |
> |
memset(cp, '\0', t->nc); |
162 |
|
restorecurs(t); /* should we reposition cursor? */ |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
< |
xt_insert(t, r) /* insert a line */ |
167 |
< |
register TEXTWIND *t; |
168 |
< |
int r; |
166 |
> |
void |
167 |
> |
xt_insert( /* insert a line */ |
168 |
> |
TEXTWIND *t, |
169 |
> |
int r |
170 |
> |
) |
171 |
|
{ |
172 |
|
char *cp; |
173 |
< |
register int i; |
173 |
> |
int i; |
174 |
|
|
175 |
< |
if (r < 0 || r >= t->nr) |
175 |
> |
if ((r < 0) | (r >= t->nr)) |
176 |
|
return; |
177 |
|
checkcurs(t); |
178 |
|
/* move lines */ |
186 |
|
/* clear new line */ |
187 |
|
XClearArea(t->dpy, t->w, LEFTMAR, r*Height(t->f), |
188 |
|
t->nc*Width(t->f), Height(t->f), (Bool) 0); |
189 |
< |
bzero(cp, t->nc); |
189 |
> |
memset(cp, '\0', t->nc); |
190 |
|
restorecurs(t); /* should we reposition cursor? */ |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
xt_redraw(t) /* redraw text window */ |
195 |
< |
register TEXTWIND *t; |
194 |
> |
void |
195 |
> |
xt_redraw(TEXTWIND *t) /* redraw text window */ |
196 |
|
{ |
197 |
< |
register int i; |
197 |
> |
int i; |
198 |
|
|
199 |
|
XClearWindow(t->dpy, t->w); |
200 |
|
for (i = 0; i < t->nr; i++) |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
< |
xt_clear(t) /* clear text window */ |
210 |
< |
register TEXTWIND *t; |
209 |
> |
void |
210 |
> |
xt_clear(TEXTWIND *t) /* clear text window */ |
211 |
|
{ |
212 |
< |
register int i; |
212 |
> |
int i; |
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 |
< |
xt_move(t, r, c) /* move to new position */ |
223 |
< |
register TEXTWIND *t; |
224 |
< |
int r, c; |
222 |
> |
void |
223 |
> |
xt_move( /* move to new position */ |
224 |
> |
TEXTWIND *t, |
225 |
> |
int r, int c |
226 |
> |
) |
227 |
|
{ |
228 |
< |
if (r < 0 || c < 0 || r >= t->nr || c >= t->nc) |
228 |
> |
if ((r < 0) | (c < 0) | (r >= t->nr) | (c >= t->nc)) |
229 |
|
return; |
230 |
|
checkcurs(t); |
231 |
|
t->r = r; |
235 |
|
|
236 |
|
|
237 |
|
int |
238 |
< |
xt_cursor(t, curs) /* change cursor */ |
239 |
< |
register TEXTWIND *t; |
240 |
< |
register int curs; |
238 |
> |
xt_cursor( /* change cursor */ |
239 |
> |
TEXTWIND *t, |
240 |
> |
int curs |
241 |
> |
) |
242 |
|
{ |
243 |
< |
register int oldcurs; |
243 |
> |
int oldcurs; |
244 |
|
|
245 |
|
if (curs != TNOCURS && curs != TBLKCURS) |
246 |
|
return(-1); |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
< |
xt_close(t) /* close text window */ |
256 |
< |
register TEXTWIND *t; |
255 |
> |
void |
256 |
> |
xt_close(TEXTWIND *t) /* close text window */ |
257 |
|
{ |
258 |
< |
register int i; |
258 |
> |
int i; |
259 |
|
|
260 |
|
XFreeFont(t->dpy, t->f); |
261 |
|
XFreeGC(t->dpy,t->gc); |
262 |
|
XDestroyWindow(t->dpy, t->w); |
263 |
|
for (i = 0; i < t->nr; i++) |
264 |
|
free(t->lp[i]); |
265 |
< |
free((char *)t->lp); |
266 |
< |
free((char *)t); |
265 |
> |
free((void *)t->lp); |
266 |
> |
free((void *)t); |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
< |
static |
271 |
< |
togglecurs(t) |
268 |
< |
register TEXTWIND *t; |
270 |
> |
static void |
271 |
> |
togglecurs(TEXTWIND *t) |
272 |
|
{ |
273 |
|
XSetFunction(t->dpy, t->gc, GXinvert); |
274 |
|
XSetPlaneMask(t->dpy, t->gc, 1L); |