1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It is one of the source files comprising zwgc, the Zephyr WindowGram
5 * Created by: Marc Horowitz <marc@athena.mit.edu>
9 * Copyright (c) 1989 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
14 #if (!defined(lint) && !defined(SABER))
15 static char rcsid_xmark_c[] = "$Id$";
18 #include <zephyr/mit-copyright.h>
22 #ifndef X_DISPLAY_MISSING
29 #include "new_string.h"
31 int markblock[3] = { -1 , -1 , -1 };
32 int markchar[3] = { -1 , -1 , -1 };
33 int markpixel[3] = { -1 , -1 , -1 };
34 x_gram *markgram = NULL;
36 int oldblock[2] = { -1 , -1 };
37 int oldpixel[2] = { -1 , -1 };
38 x_gram *oldgram = NULL;
40 #define xmarkValid() \
42 (STARTBLOCK != -1) && (ENDBLOCK != -1) && \
43 (STARTCHAR != -1) && (ENDCHAR != -1) && \
44 (STARTPIXEL != -1) && (ENDPIXEL != -1))
46 void xmarkSetBound(gram,x,y,which)
58 if ((oldblock[which] != markblock[which]) || \
59 (oldpixel[which] != markpixel[which])) { \
60 printf("----- SetBound:\noldblock[%d]=%d, oldpixel[%d]=%d\nmarkblock[%d]=%d, markpixel[%d]=%d\n-----", \
61 which,oldblock[which],which,oldpixel[which], \
62 which,markblock[which],which,markpixel[which]); \
69 if (markgram != gram) {
72 } else if (which < XMARK_TEMP_BOUND) {
73 oldblock[which]=markblock[which];
74 oldpixel[which]=markpixel[which];
77 /* Start at the top, fastforward to first span not too high. */
78 for (i=0,xb=gram->blocks ;
79 (i<gram->numblocks) && (xb->y2 < y) ;
82 /* the point is after the end */
83 if (i==gram->numblocks) {
90 /* is the point before the beginning of the line? */
98 /* is the point in the nether space between this line and the last? */
106 for (yofs=xb->y1;(i<gram->numblocks) && (xb->y1 == yofs);i++,xb++) {
112 if ((x < xofs) || (y < xb->y1)) {
116 font=get_fontst_from_fid(xb->fid);
117 for (i=0,s=(unsigned char *)((gram->text)+(xb->strindex));
118 xofs<x && i<xb->strlen;
120 /* if font->per_char is NULL, then we should use min_bounds */
121 short usewidth = font->per_char ? font->per_char[*s - font->min_char_or_byte2].width : font->min_bounds.width;
122 if (x <= (xofs+=usewidth)) {
124 markpixel[which]=xofs - xb->x1 - usewidth;
131 /* The endpoint is after the end of the block if the loop ends */
138 /* needs both bounds to be valid (!= -1) */
139 static int xmarkNearest(x,y)
144 xmarkSetBound(markgram,x,y,XMARK_TEMP_BOUND);
145 middle=(ENDBLOCK+STARTBLOCK)/2;
147 if (markblock[XMARK_TEMP_BOUND] < middle)
148 return(XMARK_START_BOUND);
149 else if (markblock[XMARK_TEMP_BOUND] > middle)
150 return(XMARK_END_BOUND);
152 middle=(ENDCHAR+STARTCHAR)/2;
153 if (markchar[XMARK_TEMP_BOUND] < middle)
154 return(XMARK_START_BOUND);
156 return(XMARK_END_BOUND);
160 void xmarkExpose(dpy,w,gram,b1,p1,b2,p2)
164 unsigned int b1,p1,b2,p2;
166 #define swap(x,y) temp=(x); (x)=(y); (y)=temp
169 #define expose (event.xexpose)
171 if ((b1==-1) || (p1==-1) || (b2==-1) || (p2==-1)) return;
173 if ((b1 > b2) || ((b1 == b2) && (p1 > p2))) {
178 #if defined(_IBMR2) && !defined(__GNUC__) && defined(RS6000_OPT_BUG)
179 /* A version of the AIX 3.1 RS/6000 C compiler needs this to prevent
180 a core dump in the loop below. */
188 for (i=b1;i<=b2;i++) {
190 expose.x=gram->blocks[i].x1+p1;
191 expose.y=gram->blocks[i].y1;
193 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
196 expose.x=gram->blocks[i].x1+p1;
197 expose.y=gram->blocks[i].y1;
198 expose.width=gram->blocks[i].x2-p1;
199 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
202 expose.x=gram->blocks[i].x1;
203 expose.y=gram->blocks[i].y1;
205 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
208 expose.x=gram->blocks[i].x1;
209 expose.y=gram->blocks[i].y1;
210 expose.width=gram->blocks[i].x2-gram->blocks[i].x1;
211 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
216 if (expose.width && expose.height) {
217 printf("---- markExpose:\nb1=%d p1=%d b2=%d p2=%d\n",b1,p1,b2,p2);
218 printf("x=%d y=%d w=%d h=%d\n-----",
219 expose.x,expose.y,expose.width,expose.height);
222 if ((expose.width && expose.height) || (expose.count == 0))
223 XSendEvent(dpy,w,True,ExposureMask,&event);
227 /* Public functions: */
229 void xmarkRedraw(dpy,w,gram,range)
235 #define ob1 ((unsigned int) oldblock[XMARK_START_BOUND])
236 #define ob2 ((unsigned int) oldblock[XMARK_END_BOUND])
237 #define nb1 ((unsigned int) markblock[XMARK_START_BOUND])
238 #define nb2 ((unsigned int) markblock[XMARK_END_BOUND])
239 #define op1 ((unsigned int) oldpixel[XMARK_START_BOUND])
240 #define op2 ((unsigned int) oldpixel[XMARK_END_BOUND])
241 #define np1 ((unsigned int) markpixel[XMARK_START_BOUND])
242 #define np2 ((unsigned int) markpixel[XMARK_END_BOUND])
244 if (range==XMARK_REDRAW_CURRENT) {
245 if (!markgram) return;
246 xmarkExpose(dpy,w,gram,nb1,np1,nb2,np2);
247 } else if (range==XMARK_REDRAW_OLD) {
248 if (!oldgram) return;
249 xmarkExpose(dpy,w,gram,ob1,op1,ob2,op2);
250 } else if (range==XMARK_REDRAW_START) {
251 if (!markgram) return;
252 xmarkExpose(dpy,w,gram,ob1,op1,nb1,np1);
253 } else if (range==XMARK_REDRAW_END) {
254 if (!markgram) return;
255 xmarkExpose(dpy,w,gram,ob2,op2,nb2,np2);
259 printf("xmarkRedraw: This shouldn't happen!\n");
264 /* needs both bounds to be valid (!= -1) */
267 if (STARTBLOCK > ENDBLOCK)
268 return(XMARK_START_BOUND);
269 else if (STARTBLOCK < ENDBLOCK)
270 return(XMARK_END_BOUND);
272 if (STARTCHAR > ENDCHAR)
273 return(XMARK_START_BOUND);
274 else if (STARTCHAR < ENDCHAR)
275 return(XMARK_END_BOUND);
277 return(XMARK_END_BOUND);
283 oldblock[0]=markblock[0];
284 oldblock[1]=markblock[1];
285 oldpixel[0]=markpixel[0];
286 oldpixel[1]=markpixel[1];
298 int xmarkExtendFromFirst(gram,x,y)
302 if (markgram != gram) {
307 if (STARTBLOCK == -1) {
308 xmarkStart(gram,x,y);
310 return(XMARK_REDRAW_CURRENT);
311 } else if (ENDBLOCK == -1) {
313 return(XMARK_REDRAW_CURRENT);
315 xmarkSetBound(gram,x,y,XMARK_END_BOUND);
316 return(XMARK_REDRAW_END);
320 int xmarkExtendFromNearest(gram,x,y)
326 if (markgram != gram) {
331 if (STARTBLOCK == -1) {
332 xmarkStart(gram,x,y);
334 return(XMARK_REDRAW_CURRENT);
335 } else if (ENDBLOCK == -1) {
337 return(XMARK_REDRAW_CURRENT);
339 xmarkSetBound(gram,x,y,bound=xmarkNearest(x,y));
340 return(bound==XMARK_START_BOUND?XMARK_REDRAW_START:XMARK_REDRAW_END);
349 string text_so_far = string_Copy("");
350 char *text = markgram->text;
351 int startblock,endblock,startchar,endchar;
354 if (xmarkSecond() == XMARK_END_BOUND) {
355 startblock=STARTBLOCK;
366 for (i=startblock; i<=endblock; i++) {
367 if (last_y != -1 && last_y != markgram->blocks[i].y)
368 text_so_far = string_Concat2(text_so_far, "\n");
369 index = markgram->blocks[i].strindex;
370 len = markgram->blocks[i].strlen;
371 if (startblock == endblock)
372 temp = string_CreateFromData(text+index+startchar,
374 else if (i==startblock)
375 temp = string_CreateFromData(text+index+startchar,len-startchar);
376 else if (i==endblock)
377 temp = string_CreateFromData(text+index,endchar);
379 temp = string_CreateFromData(text+index,len);
380 text_so_far = string_Concat2(text_so_far, temp);
382 last_y = markgram->blocks[i].y;
389 #endif /* X_DISPLAY_MISSING */