11 |
|
* 9/26/88 |
12 |
|
*/ |
13 |
|
|
14 |
< |
/* ==================================================================== |
15 |
< |
* The Radiance Software License, Version 1.0 |
16 |
< |
* |
17 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
18 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
19 |
< |
* |
20 |
< |
* Redistribution and use in source and binary forms, with or without |
21 |
< |
* modification, are permitted provided that the following conditions |
22 |
< |
* are met: |
23 |
< |
* |
24 |
< |
* 1. Redistributions of source code must retain the above copyright |
25 |
< |
* notice, this list of conditions and the following disclaimer. |
26 |
< |
* |
27 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
28 |
< |
* notice, this list of conditions and the following disclaimer in |
29 |
< |
* the documentation and/or other materials provided with the |
30 |
< |
* distribution. |
31 |
< |
* |
32 |
< |
* 3. The end-user documentation included with the redistribution, |
33 |
< |
* if any, must include the following acknowledgment: |
34 |
< |
* "This product includes Radiance software |
35 |
< |
* (http://radsite.lbl.gov/) |
36 |
< |
* developed by the Lawrence Berkeley National Laboratory |
37 |
< |
* (http://www.lbl.gov/)." |
38 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
39 |
< |
* if and wherever such third-party acknowledgments normally appear. |
40 |
< |
* |
41 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
42 |
< |
* and "The Regents of the University of California" must |
43 |
< |
* not be used to endorse or promote products derived from this |
44 |
< |
* software without prior written permission. For written |
45 |
< |
* permission, please contact [email protected]. |
46 |
< |
* |
47 |
< |
* 5. Products derived from this software may not be called "Radiance", |
48 |
< |
* nor may "Radiance" appear in their name, without prior written |
49 |
< |
* permission of Lawrence Berkeley National Laboratory. |
50 |
< |
* |
51 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
52 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
53 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
54 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
55 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
56 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
57 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
58 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
59 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
60 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
61 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
62 |
< |
* SUCH DAMAGE. |
63 |
< |
* ==================================================================== |
64 |
< |
* |
65 |
< |
* This software consists of voluntary contributions made by many |
66 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
67 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
68 |
< |
* <http://www.lbl.gov/>. |
69 |
< |
*/ |
14 |
> |
#include "copyright.h" |
15 |
|
|
16 |
|
#include <stdio.h> |
72 |
– |
|
17 |
|
#include <stdlib.h> |
18 |
< |
|
18 |
> |
#include <string.h> |
19 |
|
#include <X11/Xlib.h> |
20 |
|
|
21 |
|
#include "x11twind.h" |
22 |
|
|
79 |
– |
#ifndef BSD |
80 |
– |
#define bzero(d,n) (void)memset(d,0,n) |
81 |
– |
#endif |
82 |
– |
|
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 |
< |
static void togglecurs(); |
32 |
> |
static void togglecurs(TEXTWIND *t); |
33 |
|
|
34 |
|
|
35 |
|
TEXTWIND * |
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; |
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); |
85 |
|
|
86 |
|
|
87 |
|
void |
88 |
< |
xt_puts(s, t) /* output a string */ |
89 |
< |
register char *s; |
90 |
< |
TEXTWIND *t; |
88 |
> |
xt_putc( /* output a character */ |
89 |
> |
int c, |
90 |
> |
TEXTWIND *t |
91 |
> |
) |
92 |
|
{ |
93 |
< |
int oldcurs; |
93 |
> |
char ch[2]; |
94 |
|
|
153 |
– |
oldcurs = xt_cursor(t, TNOCURS); /* for efficiency */ |
154 |
– |
while (*s) |
155 |
– |
xt_putc(*s++, t); |
156 |
– |
xt_cursor(t, oldcurs); |
157 |
– |
} |
158 |
– |
|
159 |
– |
|
160 |
– |
void |
161 |
– |
xt_putc(c, t) /* output a character */ |
162 |
– |
char c; |
163 |
– |
register TEXTWIND *t; |
164 |
– |
{ |
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 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
void |
126 |
< |
xt_delete(t, r) /* delete a line */ |
196 |
< |
register TEXTWIND *t; |
197 |
< |
int r; |
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) |
147 |
|
return; |
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 |
|
void |
167 |
< |
xt_insert(t, r) /* insert a line */ |
168 |
< |
register TEXTWIND *t; |
169 |
< |
int r; |
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) |
176 |
|
return; |
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 |
|
void |
195 |
< |
xt_redraw(t) /* redraw text window */ |
251 |
< |
register TEXTWIND *t; |
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++) |
207 |
|
|
208 |
|
|
209 |
|
void |
210 |
< |
xt_clear(t) /* clear text window */ |
267 |
< |
register TEXTWIND *t; |
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 |
|
void |
223 |
< |
xt_move(t, r, c) /* move to new position */ |
224 |
< |
register TEXTWIND *t; |
225 |
< |
int r, c; |
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) |
229 |
|
return; |
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); |
253 |
|
|
254 |
|
|
255 |
|
void |
256 |
< |
xt_close(t) /* close text window */ |
312 |
< |
register TEXTWIND *t; |
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); |
268 |
|
|
269 |
|
|
270 |
|
static void |
271 |
< |
togglecurs(t) |
328 |
< |
register TEXTWIND *t; |
271 |
> |
togglecurs(TEXTWIND *t) |
272 |
|
{ |
273 |
|
XSetFunction(t->dpy, t->gc, GXinvert); |
274 |
|
XSetPlaneMask(t->dpy, t->gc, 1L); |