Re-organize BlueGene toolchain files
[gromacs.git] / src / ngmx / pulldown.c
bloba9d2f52c64b0c58498a34f12cab46791e2849fa1
1 /*
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.
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
42 #include <string.h>
43 #include <smalloc.h>
44 #include <x11.h>
45 #include <macros.h>
46 #include "popup.h"
47 #include "pulldown.h"
49 static gmx_bool PDCallBack(t_x11 *x11,XEvent *event,Window w,void *data)
51 t_pulldown *pd;
52 int i,x,x1,y,nsel;
54 pd=(t_pulldown *)data;
55 y=pd->wd.height;
56 switch(event->type) {
57 case Expose:
58 XSetForeground(x11->disp,x11->gc,x11->fg);
59 XDrawLine(x11->disp,w,x11->gc,0,y-1,pd->wd.width,y-1);
60 for(i=0; (i<pd->nmenu); i++)
61 XDrawString(x11->disp,pd->wd.self,x11->gc,pd->xpos[i],x11->font->ascent,
62 pd->title[i],strlen(pd->title[i]));
63 break;
64 case ButtonPress:
65 if (pd->nsel==-1) {
66 x=event->xbutton.x;
67 for(nsel=0; (pd->xpos[nsel+1] < x) && (nsel < pd->nmenu-1); nsel++);
68 pd->nsel=nsel;
69 x1=max(0,min(pd_width(pd)-menu_width(pd->m[nsel]),pd->xpos[nsel]));
70 show_menu(x11,pd->m[nsel],x1,y+1,FALSE);
72 break;
73 case ButtonRelease:
74 hide_pd(x11,pd);
75 break;
76 default:
77 break;
79 return FALSE;
82 t_pulldown *init_pd(t_x11 *x11,Window Parent,int width,int height,
83 unsigned long fg,unsigned long bg,
84 int nmenu,int *nsub,t_mentry *ent[],const char **title)
86 t_pulldown *pd;
87 int i;
89 snew(pd,1);
90 pd->title=title;
91 pd->nmenu=nmenu;
92 pd->nsel=-1;
93 snew(pd->m,nmenu);
94 snew(pd->xpos,nmenu+1);
95 pd->xpos[0]=5;
96 for(i=1; (i<=nmenu); i++)
97 pd->xpos[i]=20+pd->xpos[i-1]+
98 XTextWidth(x11->font,title[i-1],strlen(title[i-1]));
99 if (pd->xpos[nmenu] > width)
100 printf("Menu too wide\n");
102 InitWin(&(pd->wd),0,0,width,XTextHeight(x11->font)+2,0,"PullDown");
103 pd->wd.self=XCreateSimpleWindow(x11->disp,Parent,
104 pd->wd.x, pd->wd.y,
105 pd->wd.width,pd->wd.height,
106 pd->wd.bwidth,fg,bg);
107 x11->RegisterCallback(x11,pd->wd.self,Parent,PDCallBack,pd);
108 x11->SetInputMask(x11,pd->wd.self,ExposureMask | ButtonPressMask |
109 OwnerGrabButtonMask | ButtonReleaseMask);
110 XMapWindow(x11->disp,pd->wd.self);
112 for(i=0; (i<nmenu); i++)
113 pd->m[i]=init_menu(x11,Parent,fg,bg,nsub[i],ent[i],1);
115 return pd;
118 void hide_pd(t_x11 *x11,t_pulldown *pd)
120 if (pd->nsel != -1)
121 hide_menu(x11,pd->m[pd->nsel]);
122 pd->nsel=-1;
125 void check_pd_item(t_pulldown *pd,int nreturn,gmx_bool bStatus)
127 int i;
129 for(i=0; (i<pd->nmenu); i++)
130 check_menu_item(pd->m[i],nreturn,bStatus);
133 void done_pd(t_x11 *x11,t_pulldown *pd)
135 int i;
137 for(i=0; (i<pd->nmenu); i++)
138 done_menu(x11,pd->m[i]);
139 x11->UnRegisterCallback(x11,pd->wd.self);
140 sfree(pd->m);
141 sfree(pd->xpos);
144 int pd_width(t_pulldown *pd)
146 int i,w;
148 w=0;
149 for(i=0; (i<pd->nmenu); i++)
150 w=max(w,menu_width(pd->m[i]));
151 w=max(w,pd->xpos[pd->nmenu]);
152 return w;
155 int pd_height(t_pulldown *pd)
157 int i,h;
159 h=0;
160 for(i=0; (i<pd->nmenu); i++)
161 h=max(h,menu_height(pd->m[i]));
163 return h;