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 * Good gRace! Old Maple Actually Chews Slate
36 static char *SRCID_popup_c = "$Id$";
45 bool ChildCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
52 child=(t_child *)data;
55 switch (event->type) {
57 XSetForeground(x11->disp,x11->gc,x11->fg);
58 TextInRect(x11,w,m->str,16,0,wd->width-16-2,wd->height-2,
61 int y=x11->font->ascent;
62 XDrawLine(x11->disp,w,x11->gc,2,(y*2)/3,6,y);
63 XDrawLine(x11->disp,w,x11->gc,3,(y*2)/3,7,y);
64 XDrawLine(x11->disp,w,x11->gc,7,y,12,2);
68 LightBorder(x11->disp,w,x11->fg);
71 LightBorder(x11->disp,w,x11->bg);
74 letter.type=ClientMessage;
75 letter.xclient.display=x11->disp;
76 letter.xclient.window=m->send_to ? m->send_to : child->Parent;
77 letter.xclient.message_type=0;
78 letter.xclient.format=32;
79 letter.xclient.data.l[0]=m->nreturn;
80 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
88 bool MenuCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
95 /* Nothing to be done */
98 GrabOK(stderr,XGrabPointer(x11->disp,m->wd.self,True,
99 ButtonReleaseMask,GrabModeAsync,
100 GrabModeAsync,m->wd.self,None,CurrentTime));
106 event->xclient.window=m->Parent;
107 XSendEvent(x11->disp,m->Parent,True,0,event);
115 t_menu *init_menu(t_x11 *x11,Window Parent,unsigned long fg,unsigned long bg,
116 int nent,t_mentry ent[],int ncol)
118 int i,mlen,mht,area,ht;
129 /* Calculate dimensions of the menu */
131 for(i=0; (i<nent); i++)
132 mlen=max(mlen,XTextWidth(x11->font,ent[i].str,strlen(ent[i].str)));
133 mht=XTextHeight(x11->font);
134 /* Now we have the biggest single box, add a border of 2 pixels */
135 mlen+=20; /* We need extra space at the left for checkmarks */
137 /* Calculate the area of the menu */
140 /* No the number of rows per column, only beyond 8 rows */
154 InitWin(&(m->wd),10,10,fcol*mlen,frows*mht,1,"Menu");
156 m->wd.self=XCreateSimpleWindow(x11->disp,Parent,
158 m->wd.width,m->wd.height,
160 x11->RegisterCallback(x11,m->wd.self,Parent,MenuCallBack,m);
161 x11->SetInputMask(x11,m->wd.self,ExposureMask |
162 OwnerGrabButtonMask | ButtonReleaseMask);
164 for(j=l=0; (j<fcol); j++)
165 for(k=0; (k<frows) && (l<nent); k++,l++) {
170 InitWin(w,j*mlen,k*mht,mlen-2,mht-2,1,NULL);
171 w->self=XCreateSimpleWindow(x11->disp,m->wd.self,
172 w->x,w->y,w->width,w->height,
174 x11->RegisterCallback(x11,w->self,m->wd.self,
176 x11->SetInputMask(x11,w->self,
177 ButtonPressMask | ButtonReleaseMask |
178 OwnerGrabButtonMask | ExposureMask |
179 EnterWindowMask | LeaveWindowMask);
185 void show_menu(t_x11 *x11,t_menu *m,int x,int y,bool bGrab)
187 XMoveWindow(x11->disp,m->wd.self,x,y);
189 XMapWindow(x11->disp,m->wd.self);
190 XMapSubwindows(x11->disp,m->wd.self);
193 void hide_menu(t_x11 *x11,t_menu *m)
196 XUngrabPointer(x11->disp,CurrentTime);
197 XUnmapWindow(x11->disp,m->wd.self);
200 void check_menu_item(t_menu *m,int nreturn,bool bStatus)
204 for(i=0; (i<m->nitem); i++)
205 if(m->item[i].m->nreturn==nreturn)
206 m->item[i].m->bChecked=bStatus;
209 void done_menu(t_x11 *x11,t_menu *m)
213 for(i=0; (i<m->nitem); i++)
214 x11->UnRegisterCallback(x11,m->item[i].wd.self);
216 x11->UnRegisterCallback(x11,m->wd.self);
220 int menu_width(t_menu *m)
225 int menu_height(t_menu *m)