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$";
40 int CheckWin(Window win
,char *file
, int line
)
47 { BadAlloc
, "Bad Alloc" },
48 { BadColor
, "Bad Color" },
49 { BadCursor
, "Bad Cursor"},
50 { BadMatch
, "Bad Match" },
51 { BadPixmap
, "Bad Pixmap"},
52 { BadValue
, "Bad Value" },
53 { BadWindow
, "Bad Window"}
55 #define NERR (sizeof(winerr)/sizeof(winerr[0]))
58 for(i
=0; (i
<NERR
); i
++)
59 if (win
==winerr
[i
].n
) {
60 fprintf(stderr
,"%s",winerr
[i
].s
);
63 if (i
==NERR
) return 1;
65 fprintf(stderr
," in file %s, line %d\n",file
,line
);
69 void LightBorder(Display
*disp
, Window win
, unsigned long color
)
71 XSetWindowAttributes attributes
;
73 attributes
.border_pixel
= color
;
74 XChangeWindowAttributes(disp
,win
,CWBorderPixel
,&attributes
);
77 void SpecialTextInRect(t_x11
*x11
,XFontStruct
*font
,Drawable win
,
78 char *s
,int x
,int y
,int width
,int height
,
85 XSetFont(x11
->disp
,x11
->gc
,font
->fid
);
91 fw
=XTextWidth(f
,s
,strlen(s
));
110 y0
=y
+height
-f
->descent
;
114 y0
=y
+(height
-fh
)/2+f
->ascent
;
117 XDrawString(x11
->disp
,win
,x11
->gc
,x0
,y0
,s
,strlen(s
));
119 XSetFont(x11
->disp
,x11
->gc
,x11
->font
->fid
);
122 void TextInRect(t_x11
*x11
,Drawable win
,
123 char *s
,int x
,int y
,int width
,int height
,
126 SpecialTextInRect(x11
,NULL
,win
,s
,x
,y
,width
,height
,eX
,eY
);
129 void TextInWin(t_x11
*x11
, t_windata
*win
,
130 char *s
, eXPos eX
, eYPos eY
)
132 TextInRect(x11
,win
->self
,s
,0,0,win
->width
,win
->height
,eX
,eY
);
135 void InitWin(t_windata
*win
, int x0
,int y0
, int w
, int h
, int bw
, char *text
)
147 win
->text
=strdup(text
);
151 printf("%s: %d x %d at %d, %d\n",text
,w
,h
,x0
,y0
);
155 void FreeWin(Display
*disp
, t_windata
*win
)
160 XFreeCursor(disp
,win
->cursor
);
163 void ExposeWin(Display
*disp
,Window win
)
168 event
.xexpose
.send_event
=True
;
169 event
.xexpose
.window
= win
;
172 event
.xexpose
.width
=1000;
173 event
.xexpose
.height
=1000;
174 event
.xexpose
.count
= 0;
175 XSendEvent(disp
,win
,False
,ExposureMask
,&event
);
178 void XDrawRoundRect(Display
*disp
, Window win
, GC gc
,
179 int x
, int y
, int w
, int h
)
181 #define RAD (OFFS_X/2)
182 #define SetPoint(pn,x0,y0) pn.x=x0; pn.y=y0
184 if ((w
<10) || (h
<10))
185 XDrawRectangle(disp
,win
,gc
,x
,y
,w
,h
);
189 SetPoint(p
[0],x
+RAD
,y
);
190 SetPoint(p
[1],w
-2*RAD
,0);
191 SetPoint(p
[2],RAD
,RAD
);
192 SetPoint(p
[3],0,h
-2*RAD
);
193 SetPoint(p
[4],-RAD
,RAD
);
194 SetPoint(p
[5],2*RAD
-w
,0);
195 SetPoint(p
[6],-RAD
,-RAD
);
196 SetPoint(p
[7],0,2*RAD
-h
);
197 SetPoint(p
[8],RAD
,-RAD
);
198 XDrawLines(disp
,win
,gc
,p
,9,CoordModePrevious
);
202 void RoundRectWin(Display
*disp
, GC gc
, t_windata
*win
,
203 int offsx
, int offsy
,unsigned long color
)
205 XSetLineAttributes(disp
,gc
,1,LineOnOffDash
,CapButt
,JoinRound
);
206 XSetForeground(disp
,gc
,color
);
207 XDrawRoundRect(disp
,win
->self
,gc
,offsx
,offsy
,
208 win
->width
-2*offsx
-1,win
->height
-2*offsy
-1);
209 XSetLineAttributes(disp
,gc
,1,LineSolid
,CapButt
,JoinRound
);
212 void RectWin(Display
*disp
, GC gc
, t_windata
*win
, unsigned long color
)
214 int bw
=1; /*2*w.bwidth;*/
216 XSetForeground(disp
,gc
,color
);
217 XDrawRoundRect(disp
,win
->self
,gc
,0,0,win
->width
-bw
,win
->height
-bw
);
220 typedef struct t_mpos
{
225 static t_mpos
*mpos
=NULL
;
227 void PushMouse(Display
*disp
, Window dest
, int x
, int y
)
236 XQueryPointer(disp
,DefaultRootWindow(disp
),&root
,&child
,&root_x
,&root_y
,
237 &win_x
,&win_y
,&keybut
);
242 XWarpPointer(disp
,None
,dest
,0,0,0,0,x
,y
);
244 fprintf(stderr
,"Pushmouse %d, %d\n",x
,y
);
248 void PopMouse(Display
*disp
)
255 XWarpPointer(disp
,None
,DefaultRootWindow(disp
),0,0,0,0,old
->x
,old
->y
);
257 fprintf(stderr
,"Popmouse %d, %d\n",old
->x
,old
->y
);
263 bool HelpPressed(XEvent
*event
)
267 XComposeStatus compose
;
270 (void)XLookupString(&(event
->xkey
),buf
,BUFSIZE
,&keysym
,&compose
);
272 return (keysym
== XK_F1
);
275 bool GrabOK(FILE *out
, int err
)
280 case GrabNotViewable
:
281 fprintf(out
,"GrabNotViewable\n"); break;
283 fprintf(out
,"AlreadyGrabbed\n"); break;
285 fprintf(out
,"GrabFrozen\n"); break;
286 case GrabInvalidTime
:
287 fprintf(out
,"GrabInvalidTime\n"); break;