2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
50 gmx_bool ChildCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
57 child=(t_child *)data;
60 switch (event->type) {
62 XSetForeground(x11->disp,x11->gc,x11->fg);
63 TextInRect(x11,w,m->str,16,0,wd->width-16-2,wd->height-2,
66 int y=x11->font->ascent;
67 XDrawLine(x11->disp,w,x11->gc,2,(y*2)/3,6,y);
68 XDrawLine(x11->disp,w,x11->gc,3,(y*2)/3,7,y);
69 XDrawLine(x11->disp,w,x11->gc,7,y,12,2);
73 LightBorder(x11->disp,w,x11->fg);
76 LightBorder(x11->disp,w,x11->bg);
79 letter.type=ClientMessage;
80 letter.xclient.display=x11->disp;
81 letter.xclient.window=m->send_to ? m->send_to : child->Parent;
82 letter.xclient.message_type=0;
83 letter.xclient.format=32;
84 letter.xclient.data.l[0]=m->nreturn;
85 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
93 gmx_bool MenuCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
100 /* Nothing to be done */
103 GrabOK(stderr,XGrabPointer(x11->disp,m->wd.self,True,
104 ButtonReleaseMask,GrabModeAsync,
105 GrabModeAsync,m->wd.self,None,CurrentTime));
111 event->xclient.window=m->Parent;
112 XSendEvent(x11->disp,m->Parent,True,0,event);
120 t_menu *init_menu(t_x11 *x11,Window Parent,unsigned long fg,unsigned long bg,
121 int nent,t_mentry ent[],int ncol)
123 int i,mlen,mht,area,ht;
134 /* Calculate dimensions of the menu */
136 for(i=0; (i<nent); i++)
137 mlen=max(mlen,XTextWidth(x11->font,ent[i].str,strlen(ent[i].str)));
138 mht=XTextHeight(x11->font);
139 /* Now we have the biggest single box, add a border of 2 pixels */
140 mlen+=20; /* We need extra space at the left for checkmarks */
142 /* Calculate the area of the menu */
145 /* No the number of rows per column, only beyond 8 rows */
159 InitWin(&(m->wd),10,10,fcol*mlen,frows*mht,1,"Menu");
161 m->wd.self=XCreateSimpleWindow(x11->disp,Parent,
163 m->wd.width,m->wd.height,
165 x11->RegisterCallback(x11,m->wd.self,Parent,MenuCallBack,m);
166 x11->SetInputMask(x11,m->wd.self,ExposureMask |
167 OwnerGrabButtonMask | ButtonReleaseMask);
169 for(j=l=0; (j<fcol); j++)
170 for(k=0; (k<frows) && (l<nent); k++,l++) {
175 InitWin(w,j*mlen,k*mht,mlen-2,mht-2,1,NULL);
176 w->self=XCreateSimpleWindow(x11->disp,m->wd.self,
177 w->x,w->y,w->width,w->height,
179 x11->RegisterCallback(x11,w->self,m->wd.self,
181 x11->SetInputMask(x11,w->self,
182 ButtonPressMask | ButtonReleaseMask |
183 OwnerGrabButtonMask | ExposureMask |
184 EnterWindowMask | LeaveWindowMask);
190 void show_menu(t_x11 *x11,t_menu *m,int x,int y,gmx_bool bGrab)
192 XMoveWindow(x11->disp,m->wd.self,x,y);
194 XMapWindow(x11->disp,m->wd.self);
195 XMapSubwindows(x11->disp,m->wd.self);
198 void hide_menu(t_x11 *x11,t_menu *m)
201 XUngrabPointer(x11->disp,CurrentTime);
202 XUnmapWindow(x11->disp,m->wd.self);
205 void check_menu_item(t_menu *m,int nreturn,gmx_bool bStatus)
209 for(i=0; (i<m->nitem); i++)
210 if(m->item[i].m->nreturn==nreturn)
211 m->item[i].m->bChecked=bStatus;
214 void done_menu(t_x11 *x11,t_menu *m)
218 for(i=0; (i<m->nitem); i++)
219 x11->UnRegisterCallback(x11,m->item[i].wd.self);
221 x11->UnRegisterCallback(x11,m->wd.self);
225 int menu_width(t_menu *m)
230 int menu_height(t_menu *m)