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 const 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))
47 xmarkSetBound(x_gram *gram,
59 if ((oldblock[which] != markblock[which]) || \
60 (oldpixel[which] != markpixel[which])) { \
61 printf("----- SetBound:\noldblock[%d]=%d, oldpixel[%d]=%d\nmarkblock[%d]=%d, markpixel[%d]=%d\n-----", \
62 which,oldblock[which],which,oldpixel[which], \
63 which,markblock[which],which,markpixel[which]); \
70 if (markgram != gram) {
73 } else if (which < XMARK_TEMP_BOUND) {
74 oldblock[which]=markblock[which];
75 oldpixel[which]=markpixel[which];
78 /* Start at the top, fastforward to first span not too high. */
79 for (i=0,xb=gram->blocks ;
80 (i<gram->numblocks) && (xb->y2 < y) ;
83 /* the point is after the end */
84 if (i==gram->numblocks) {
91 /* is the point before the beginning of the line? */
99 /* is the point in the nether space between this line and the last? */
107 for (yofs=xb->y1;(i<gram->numblocks) && (xb->y1 == yofs);i++,xb++) {
113 if ((x < xofs) || (y < xb->y1)) {
117 font=get_fontst_from_fid(xb->fid);
118 for (i=0,s=(unsigned char *)((gram->text)+(xb->strindex));
119 xofs<x && i<xb->strlen;
121 /* if font->per_char is NULL, then we should use min_bounds */
122 short usewidth = font->per_char ? font->per_char[*s - font->min_char_or_byte2].width : font->min_bounds.width;
123 if (x <= (xofs+=usewidth)) {
125 markpixel[which]=xofs - xb->x1 - usewidth;
132 /* The endpoint is after the end of the block if the loop ends */
139 /* needs both bounds to be valid (!= -1) */
146 xmarkSetBound(markgram,x,y,XMARK_TEMP_BOUND);
147 middle=(ENDBLOCK+STARTBLOCK)/2;
149 if (markblock[XMARK_TEMP_BOUND] < middle)
150 return(XMARK_START_BOUND);
151 else if (markblock[XMARK_TEMP_BOUND] > middle)
152 return(XMARK_END_BOUND);
154 middle=(ENDCHAR+STARTCHAR)/2;
155 if (markchar[XMARK_TEMP_BOUND] < middle)
156 return(XMARK_START_BOUND);
158 return(XMARK_END_BOUND);
163 xmarkExpose(Display *dpy,
171 #define swap(x,y) temp=(x); (x)=(y); (y)=temp
174 #define expose (event.xexpose)
176 if ((b1==-1) || (p1==-1) || (b2==-1) || (p2==-1)) return;
178 if ((b1 > b2) || ((b1 == b2) && (p1 > p2))) {
183 #if defined(_IBMR2) && !defined(__GNUC__) && defined(RS6000_OPT_BUG)
184 /* A version of the AIX 3.1 RS/6000 C compiler needs this to prevent
185 a core dump in the loop below. */
193 for (i=b1;i<=b2;i++) {
195 expose.x=gram->blocks[i].x1+p1;
196 expose.y=gram->blocks[i].y1;
198 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
201 expose.x=gram->blocks[i].x1+p1;
202 expose.y=gram->blocks[i].y1;
203 expose.width=gram->blocks[i].x2-p1;
204 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
207 expose.x=gram->blocks[i].x1;
208 expose.y=gram->blocks[i].y1;
210 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
213 expose.x=gram->blocks[i].x1;
214 expose.y=gram->blocks[i].y1;
215 expose.width=gram->blocks[i].x2-gram->blocks[i].x1;
216 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
221 if (expose.width && expose.height) {
222 printf("---- markExpose:\nb1=%d p1=%d b2=%d p2=%d\n",b1,p1,b2,p2);
223 printf("x=%d y=%d w=%d h=%d\n-----",
224 expose.x,expose.y,expose.width,expose.height);
227 if ((expose.width && expose.height) || (expose.count == 0))
228 XSendEvent(dpy,w,True,ExposureMask,&event);
232 /* Public functions: */
235 xmarkRedraw(Display *dpy,
240 #define ob1 ((unsigned int) oldblock[XMARK_START_BOUND])
241 #define ob2 ((unsigned int) oldblock[XMARK_END_BOUND])
242 #define nb1 ((unsigned int) markblock[XMARK_START_BOUND])
243 #define nb2 ((unsigned int) markblock[XMARK_END_BOUND])
244 #define op1 ((unsigned int) oldpixel[XMARK_START_BOUND])
245 #define op2 ((unsigned int) oldpixel[XMARK_END_BOUND])
246 #define np1 ((unsigned int) markpixel[XMARK_START_BOUND])
247 #define np2 ((unsigned int) markpixel[XMARK_END_BOUND])
249 if (range==XMARK_REDRAW_CURRENT) {
250 if (!markgram) return;
251 xmarkExpose(dpy,w,gram,nb1,np1,nb2,np2);
252 } else if (range==XMARK_REDRAW_OLD) {
253 if (!oldgram) return;
254 xmarkExpose(dpy,w,gram,ob1,op1,ob2,op2);
255 } else if (range==XMARK_REDRAW_START) {
256 if (!markgram) return;
257 xmarkExpose(dpy,w,gram,ob1,op1,nb1,np1);
258 } else if (range==XMARK_REDRAW_END) {
259 if (!markgram) return;
260 xmarkExpose(dpy,w,gram,ob2,op2,nb2,np2);
264 printf("xmarkRedraw: This shouldn't happen!\n");
269 /* needs both bounds to be valid (!= -1) */
273 if (STARTBLOCK > ENDBLOCK)
274 return(XMARK_START_BOUND);
275 else if (STARTBLOCK < ENDBLOCK)
276 return(XMARK_END_BOUND);
278 if (STARTCHAR > ENDCHAR)
279 return(XMARK_START_BOUND);
280 else if (STARTCHAR < ENDCHAR)
281 return(XMARK_END_BOUND);
283 return(XMARK_END_BOUND);
290 oldblock[0]=markblock[0];
291 oldblock[1]=markblock[1];
292 oldpixel[0]=markpixel[0];
293 oldpixel[1]=markpixel[1];
306 xmarkExtendFromFirst(x_gram *gram,
310 if (markgram != gram) {
315 if (STARTBLOCK == -1) {
316 xmarkStart(gram,x,y);
318 return(XMARK_REDRAW_CURRENT);
319 } else if (ENDBLOCK == -1) {
321 return(XMARK_REDRAW_CURRENT);
323 xmarkSetBound(gram,x,y,XMARK_END_BOUND);
324 return(XMARK_REDRAW_END);
329 xmarkExtendFromNearest(x_gram *gram,
335 if (markgram != gram) {
340 if (STARTBLOCK == -1) {
341 xmarkStart(gram,x,y);
343 return(XMARK_REDRAW_CURRENT);
344 } else if (ENDBLOCK == -1) {
346 return(XMARK_REDRAW_CURRENT);
348 xmarkSetBound(gram,x,y,bound=xmarkNearest(x,y));
349 return(bound==XMARK_START_BOUND?XMARK_REDRAW_START:XMARK_REDRAW_END);
359 string text_so_far = string_Copy("");
360 char *text = markgram->text;
361 int startblock,endblock,startchar,endchar;
364 if (xmarkSecond() == XMARK_END_BOUND) {
365 startblock=STARTBLOCK;
376 for (i=startblock; i<=endblock; i++) {
377 if (last_y != -1 && last_y != markgram->blocks[i].y)
378 text_so_far = string_Concat2(text_so_far, "\n");
379 index = markgram->blocks[i].strindex;
380 len = markgram->blocks[i].strlen;
381 if (startblock == endblock)
382 temp = string_CreateFromData(text+index+startchar,
384 else if (i==startblock)
385 temp = string_CreateFromData(text+index+startchar,len-startchar);
386 else if (i==endblock)
387 temp = string_CreateFromData(text+index,endchar);
389 temp = string_CreateFromData(text+index,len);
390 text_so_far = string_Concat2(text_so_far, temp);
392 last_y = markgram->blocks[i].y;
399 #endif /* X_DISPLAY_MISSING */