4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Giving Russians Opium May Alter Current Situation
36 static char *SRCID_xutil_c = "$Id$";
47 int CheckWin(Window win,char *file, int line)
54 { BadAlloc, "Bad Alloc" },
55 { BadColor, "Bad Color" },
56 { BadCursor, "Bad Cursor"},
57 { BadMatch, "Bad Match" },
58 { BadPixmap, "Bad Pixmap"},
59 { BadValue, "Bad Value" },
60 { BadWindow, "Bad Window"}
62 #define NERR (sizeof(winerr)/sizeof(winerr[0]))
65 for(i=0; (i<NERR); i++)
66 if (win==winerr[i].n) {
67 fprintf(stderr,"%s",winerr[i].s);
70 if (i==NERR) return 1;
72 fprintf(stderr," in file %s, line %d\n",file,line);
76 void LightBorder(Display *disp, Window win, unsigned long color)
78 XSetWindowAttributes attributes;
80 attributes.border_pixel = color;
81 XChangeWindowAttributes(disp,win,CWBorderPixel,&attributes);
84 void SpecialTextInRect(t_x11 *x11,XFontStruct *font,Drawable win,
85 char *s,int x,int y,int width,int height,
92 XSetFont(x11->disp,x11->gc,font->fid);
98 fw=XTextWidth(f,s,strlen(s));
117 y0=y+height-f->descent;
121 y0=y+(height-fh)/2+f->ascent;
124 XDrawString(x11->disp,win,x11->gc,x0,y0,s,strlen(s));
126 XSetFont(x11->disp,x11->gc,x11->font->fid);
129 void TextInRect(t_x11 *x11,Drawable win,
130 char *s,int x,int y,int width,int height,
133 SpecialTextInRect(x11,NULL,win,s,x,y,width,height,eX,eY);
136 void TextInWin(t_x11 *x11, t_windata *win,
137 char *s, eXPos eX, eYPos eY)
139 TextInRect(x11,win->self,s,0,0,win->width,win->height,eX,eY);
142 void InitWin(t_windata *win, int x0,int y0, int w, int h, int bw, char *text)
154 win->text=strdup(text);
158 printf("%s: %d x %d at %d, %d\n",text,w,h,x0,y0);
162 void FreeWin(Display *disp, t_windata *win)
167 XFreeCursor(disp,win->cursor);
170 void ExposeWin(Display *disp,Window win)
175 event.xexpose.send_event=True;
176 event.xexpose.window = win;
179 event.xexpose.width=1000;
180 event.xexpose.height=1000;
181 event.xexpose.count = 0;
182 XSendEvent(disp,win,False,ExposureMask,&event);
185 void XDrawRoundRect(Display *disp, Window win, GC gc,
186 int x, int y, int w, int h)
188 #define RAD (OFFS_X/2)
189 #define SetPoint(pn,x0,y0) pn.x=x0; pn.y=y0
191 if ((w<10) || (h<10))
192 XDrawRectangle(disp,win,gc,x,y,w,h);
196 SetPoint(p[0],x+RAD,y);
197 SetPoint(p[1],w-2*RAD,0);
198 SetPoint(p[2],RAD,RAD);
199 SetPoint(p[3],0,h-2*RAD);
200 SetPoint(p[4],-RAD,RAD);
201 SetPoint(p[5],2*RAD-w,0);
202 SetPoint(p[6],-RAD,-RAD);
203 SetPoint(p[7],0,2*RAD-h);
204 SetPoint(p[8],RAD,-RAD);
205 XDrawLines(disp,win,gc,p,9,CoordModePrevious);
209 void RoundRectWin(Display *disp, GC gc, t_windata *win,
210 int offsx, int offsy,unsigned long color)
212 XSetLineAttributes(disp,gc,1,LineOnOffDash,CapButt,JoinRound);
213 XSetForeground(disp,gc,color);
214 XDrawRoundRect(disp,win->self,gc,offsx,offsy,
215 win->width-2*offsx-1,win->height-2*offsy-1);
216 XSetLineAttributes(disp,gc,1,LineSolid,CapButt,JoinRound);
219 void RectWin(Display *disp, GC gc, t_windata *win, unsigned long color)
221 int bw=1; /*2*w.bwidth;*/
223 XSetForeground(disp,gc,color);
224 XDrawRoundRect(disp,win->self,gc,0,0,win->width-bw,win->height-bw);
227 typedef struct t_mpos {
232 static t_mpos *mpos=NULL;
234 void PushMouse(Display *disp, Window dest, int x, int y)
243 XQueryPointer(disp,DefaultRootWindow(disp),&root,&child,&root_x,&root_y,
244 &win_x,&win_y,&keybut);
249 XWarpPointer(disp,None,dest,0,0,0,0,x,y);
251 fprintf(stderr,"Pushmouse %d, %d\n",x,y);
255 void PopMouse(Display *disp)
262 XWarpPointer(disp,None,DefaultRootWindow(disp),0,0,0,0,old->x,old->y);
264 fprintf(stderr,"Popmouse %d, %d\n",old->x,old->y);
270 bool HelpPressed(XEvent *event)
274 XComposeStatus compose;
277 (void)XLookupString(&(event->xkey),buf,BUFSIZE,&keysym,&compose);
279 return (keysym == XK_F1);
282 bool GrabOK(FILE *out, int err)
287 case GrabNotViewable:
288 fprintf(out,"GrabNotViewable\n"); break;
290 fprintf(out,"AlreadyGrabbed\n"); break;
292 fprintf(out,"GrabFrozen\n"); break;
293 case GrabInvalidTime:
294 fprintf(out,"GrabInvalidTime\n"); break;