4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_xutil_c = "$Id$";
41 int CheckWin(Window win,char *file, int line)
48 { BadAlloc, "Bad Alloc" },
49 { BadColor, "Bad Color" },
50 { BadCursor, "Bad Cursor"},
51 { BadMatch, "Bad Match" },
52 { BadPixmap, "Bad Pixmap"},
53 { BadValue, "Bad Value" },
54 { BadWindow, "Bad Window"}
56 #define NERR (sizeof(winerr)/sizeof(winerr[0]))
59 for(i=0; (i<NERR); i++)
60 if (win==winerr[i].n) {
61 fprintf(stderr,"%s",winerr[i].s);
64 if (i==NERR) return 1;
66 fprintf(stderr," in file %s, line %d\n",file,line);
70 void LightBorder(Display *disp, Window win, unsigned long color)
72 XSetWindowAttributes attributes;
74 attributes.border_pixel = color;
75 XChangeWindowAttributes(disp,win,CWBorderPixel,&attributes);
78 void SpecialTextInRect(t_x11 *x11,XFontStruct *font,Drawable win,
79 char *s,int x,int y,int width,int height,
86 XSetFont(x11->disp,x11->gc,font->fid);
92 fw=XTextWidth(f,s,strlen(s));
111 y0=y+height-f->descent;
115 y0=y+(height-fh)/2+f->ascent;
118 XDrawString(x11->disp,win,x11->gc,x0,y0,s,strlen(s));
120 XSetFont(x11->disp,x11->gc,x11->font->fid);
123 void TextInRect(t_x11 *x11,Drawable win,
124 char *s,int x,int y,int width,int height,
127 SpecialTextInRect(x11,NULL,win,s,x,y,width,height,eX,eY);
130 void TextInWin(t_x11 *x11, t_windata *win,
131 char *s, eXPos eX, eYPos eY)
133 TextInRect(x11,win->self,s,0,0,win->width,win->height,eX,eY);
136 void InitWin(t_windata *win, int x0,int y0, int w, int h, int bw, char *text)
148 win->text=strdup(text);
152 printf("%s: %d x %d at %d, %d\n",text,w,h,x0,y0);
156 void FreeWin(Display *disp, t_windata *win)
161 XFreeCursor(disp,win->cursor);
164 void ExposeWin(Display *disp,Window win)
169 event.xexpose.send_event=True;
170 event.xexpose.window = win;
173 event.xexpose.width=1000;
174 event.xexpose.height=1000;
175 event.xexpose.count = 0;
176 XSendEvent(disp,win,False,ExposureMask,&event);
179 void XDrawRoundRect(Display *disp, Window win, GC gc,
180 int x, int y, int w, int h)
182 #define RAD (OFFS_X/2)
183 #define SetPoint(pn,x0,y0) pn.x=x0; pn.y=y0
185 if ((w<10) || (h<10))
186 XDrawRectangle(disp,win,gc,x,y,w,h);
190 SetPoint(p[0],x+RAD,y);
191 SetPoint(p[1],w-2*RAD,0);
192 SetPoint(p[2],RAD,RAD);
193 SetPoint(p[3],0,h-2*RAD);
194 SetPoint(p[4],-RAD,RAD);
195 SetPoint(p[5],2*RAD-w,0);
196 SetPoint(p[6],-RAD,-RAD);
197 SetPoint(p[7],0,2*RAD-h);
198 SetPoint(p[8],RAD,-RAD);
199 XDrawLines(disp,win,gc,p,9,CoordModePrevious);
203 void RoundRectWin(Display *disp, GC gc, t_windata *win,
204 int offsx, int offsy,unsigned long color)
206 XSetLineAttributes(disp,gc,1,LineOnOffDash,CapButt,JoinRound);
207 XSetForeground(disp,gc,color);
208 XDrawRoundRect(disp,win->self,gc,offsx,offsy,
209 win->width-2*offsx-1,win->height-2*offsy-1);
210 XSetLineAttributes(disp,gc,1,LineSolid,CapButt,JoinRound);
213 void RectWin(Display *disp, GC gc, t_windata *win, unsigned long color)
215 int bw=1; /*2*w.bwidth;*/
217 XSetForeground(disp,gc,color);
218 XDrawRoundRect(disp,win->self,gc,0,0,win->width-bw,win->height-bw);
221 typedef struct t_mpos {
226 static t_mpos *mpos=NULL;
228 void PushMouse(Display *disp, Window dest, int x, int y)
237 XQueryPointer(disp,DefaultRootWindow(disp),&root,&child,&root_x,&root_y,
238 &win_x,&win_y,&keybut);
243 XWarpPointer(disp,None,dest,0,0,0,0,x,y);
245 fprintf(stderr,"Pushmouse %d, %d\n",x,y);
249 void PopMouse(Display *disp)
256 XWarpPointer(disp,None,DefaultRootWindow(disp),0,0,0,0,old->x,old->y);
258 fprintf(stderr,"Popmouse %d, %d\n",old->x,old->y);
264 bool HelpPressed(XEvent *event)
268 XComposeStatus compose;
271 (void)XLookupString(&(event->xkey),buf,BUFSIZE,&keysym,&compose);
273 return (keysym == XK_F1);
276 bool GrabOK(FILE *out, int err)
281 case GrabNotViewable:
282 fprintf(out,"GrabNotViewable\n"); break;
284 fprintf(out,"AlreadyGrabbed\n"); break;
286 fprintf(out,"GrabFrozen\n"); break;
287 case GrabInvalidTime:
288 fprintf(out,"GrabInvalidTime\n"); break;