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>
7 * $Id: xmark.c 2336 2009-03-22 18:59:56Z kcr $
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: xmark.c 2336 2009-03-22 18:59:56Z kcr $";
18 #include <zephyr/mit-copyright.h>
22 #ifndef X_DISPLAY_MISSING
26 #include <zephyr/zephyr.h>
30 #include "new_string.h"
32 int markblock[3] = { -1 , -1 , -1 };
33 int markchar[3] = { -1 , -1 , -1 };
34 int markpixel[3] = { -1 , -1 , -1 };
35 x_gram *markgram = NULL;
37 int oldblock[2] = { -1 , -1 };
38 int oldpixel[2] = { -1 , -1 };
39 x_gram *oldgram = NULL;
41 #define xmarkValid() \
43 (STARTBLOCK != -1) && (ENDBLOCK != -1) && \
44 (STARTCHAR != -1) && (ENDCHAR != -1) && \
45 (STARTPIXEL != -1) && (ENDPIXEL != -1))
48 xmarkSetBound(x_gram *gram,
60 if ((oldblock[which] != markblock[which]) || \
61 (oldpixel[which] != markpixel[which])) { \
62 printf("----- SetBound:\noldblock[%d]=%d, oldpixel[%d]=%d\nmarkblock[%d]=%d, markpixel[%d]=%d\n-----", \
63 which,oldblock[which],which,oldpixel[which], \
64 which,markblock[which],which,markpixel[which]); \
71 if (markgram != gram) {
74 } else if (which < XMARK_TEMP_BOUND) {
75 oldblock[which]=markblock[which];
76 oldpixel[which]=markpixel[which];
79 /* Start at the top, fastforward to first span not too high. */
80 for (i=0,xb=gram->blocks ;
81 (i<gram->numblocks) && (xb->y2 < y) ;
84 /* the point is after the end */
85 if (i==gram->numblocks) {
92 /* is the point before the beginning of the line? */
100 /* is the point in the nether space between this line and the last? */
108 for (yofs=xb->y1;(i<gram->numblocks) && (xb->y1 == yofs);i++,xb++) {
114 if ((x < xofs) || (y < xb->y1)) {
118 font=get_fontst_from_fid(xb->fid);
119 for (i=0,s=(unsigned char *)((gram->text)+(xb->strindex));
120 xofs<x && i<xb->strlen;
122 /* if font->per_char is NULL, then we should use min_bounds */
123 short usewidth = font->per_char ? font->per_char[*s - font->min_char_or_byte2].width : font->min_bounds.width;
124 if (x <= (xofs+=usewidth)) {
126 markpixel[which]=xofs - xb->x1 - usewidth;
133 /* The endpoint is after the end of the block if the loop ends */
140 /* needs both bounds to be valid (!= -1) */
147 xmarkSetBound(markgram,x,y,XMARK_TEMP_BOUND);
148 middle=(ENDBLOCK+STARTBLOCK)/2;
150 if (markblock[XMARK_TEMP_BOUND] < middle)
151 return(XMARK_START_BOUND);
152 else if (markblock[XMARK_TEMP_BOUND] > middle)
153 return(XMARK_END_BOUND);
155 middle=(ENDCHAR+STARTCHAR)/2;
156 if (markchar[XMARK_TEMP_BOUND] < middle)
157 return(XMARK_START_BOUND);
159 return(XMARK_END_BOUND);
164 xmarkExpose(Display *dpy,
172 #define swap(x,y) temp=(x); (x)=(y); (y)=temp
175 #define expose (event.xexpose)
177 if ((b1==-1) || (p1==-1) || (b2==-1) || (p2==-1)) return;
179 if ((b1 > b2) || ((b1 == b2) && (p1 > p2))) {
184 #if defined(_IBMR2) && !defined(__GNUC__) && defined(RS6000_OPT_BUG)
185 /* A version of the AIX 3.1 RS/6000 C compiler needs this to prevent
186 a core dump in the loop below. */
194 for (i=b1;i<=b2;i++) {
196 expose.x=gram->blocks[i].x1+p1;
197 expose.y=gram->blocks[i].y1;
199 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
202 expose.x=gram->blocks[i].x1+p1;
203 expose.y=gram->blocks[i].y1;
204 expose.width=gram->blocks[i].x2-p1;
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;
211 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
214 expose.x=gram->blocks[i].x1;
215 expose.y=gram->blocks[i].y1;
216 expose.width=gram->blocks[i].x2-gram->blocks[i].x1;
217 expose.height=gram->blocks[i].y2-gram->blocks[i].y1;
222 if (expose.width && expose.height) {
223 printf("---- markExpose:\nb1=%d p1=%d b2=%d p2=%d\n",b1,p1,b2,p2);
224 printf("x=%d y=%d w=%d h=%d\n-----",
225 expose.x,expose.y,expose.width,expose.height);
228 if ((expose.width && expose.height) || (expose.count == 0))
229 XSendEvent(dpy,w,True,ExposureMask,&event);
233 /* Public functions: */
236 xmarkRedraw(Display *dpy,
241 #define ob1 ((unsigned int) oldblock[XMARK_START_BOUND])
242 #define ob2 ((unsigned int) oldblock[XMARK_END_BOUND])
243 #define nb1 ((unsigned int) markblock[XMARK_START_BOUND])
244 #define nb2 ((unsigned int) markblock[XMARK_END_BOUND])
245 #define op1 ((unsigned int) oldpixel[XMARK_START_BOUND])
246 #define op2 ((unsigned int) oldpixel[XMARK_END_BOUND])
247 #define np1 ((unsigned int) markpixel[XMARK_START_BOUND])
248 #define np2 ((unsigned int) markpixel[XMARK_END_BOUND])
250 if (range==XMARK_REDRAW_CURRENT) {
251 if (!markgram) return;
252 xmarkExpose(dpy,w,gram,nb1,np1,nb2,np2);
253 } else if (range==XMARK_REDRAW_OLD) {
254 if (!oldgram) return;
255 xmarkExpose(dpy,w,gram,ob1,op1,ob2,op2);
256 } else if (range==XMARK_REDRAW_START) {
257 if (!markgram) return;
258 xmarkExpose(dpy,w,gram,ob1,op1,nb1,np1);
259 } else if (range==XMARK_REDRAW_END) {
260 if (!markgram) return;
261 xmarkExpose(dpy,w,gram,ob2,op2,nb2,np2);
265 printf("xmarkRedraw: This shouldn't happen!\n");
270 /* needs both bounds to be valid (!= -1) */
274 if (STARTBLOCK > ENDBLOCK)
275 return(XMARK_START_BOUND);
276 else if (STARTBLOCK < ENDBLOCK)
277 return(XMARK_END_BOUND);
279 if (STARTCHAR > ENDCHAR)
280 return(XMARK_START_BOUND);
281 else if (STARTCHAR < ENDCHAR)
282 return(XMARK_END_BOUND);
284 return(XMARK_END_BOUND);
291 oldblock[0]=markblock[0];
292 oldblock[1]=markblock[1];
293 oldpixel[0]=markpixel[0];
294 oldpixel[1]=markpixel[1];
307 xmarkExtendFromFirst(x_gram *gram,
311 if (markgram != gram) {
316 if (STARTBLOCK == -1) {
317 xmarkStart(gram,x,y);
319 return(XMARK_REDRAW_CURRENT);
320 } else if (ENDBLOCK == -1) {
322 return(XMARK_REDRAW_CURRENT);
324 xmarkSetBound(gram,x,y,XMARK_END_BOUND);
325 return(XMARK_REDRAW_END);
330 xmarkExtendFromNearest(x_gram *gram,
336 if (markgram != gram) {
341 if (STARTBLOCK == -1) {
342 xmarkStart(gram,x,y);
344 return(XMARK_REDRAW_CURRENT);
345 } else if (ENDBLOCK == -1) {
347 return(XMARK_REDRAW_CURRENT);
349 xmarkSetBound(gram,x,y,bound=xmarkNearest(x,y));
350 return(bound==XMARK_START_BOUND?XMARK_REDRAW_START:XMARK_REDRAW_END);
360 string text_so_far = string_Copy("");
361 char *text = markgram->text;
362 int startblock,endblock,startchar,endchar;
365 if (xmarkSecond() == XMARK_END_BOUND) {
366 startblock=STARTBLOCK;
377 for (i=startblock; i<=endblock; i++) {
378 if (last_y != -1 && last_y != markgram->blocks[i].y)
379 text_so_far = string_Concat2(text_so_far, "\n");
380 index = markgram->blocks[i].strindex;
381 len = markgram->blocks[i].strlen;
382 if (startblock == endblock)
383 temp = string_CreateFromData(text+index+startchar,
385 else if (i==startblock)
386 temp = string_CreateFromData(text+index+startchar,len-startchar);
387 else if (i==endblock)
388 temp = string_CreateFromData(text+index,endchar);
390 temp = string_CreateFromData(text+index,len);
391 text_so_far = string_Concat2(text_so_far, temp);
393 last_y = markgram->blocks[i].y;
400 #endif /* X_DISPLAY_MISSING */