changed reading hint
[gromacs/adressmacs.git] / src / ngmx / pulldown.c
blob44d6c2b68df8bf94e49de7b48e79f8c01e1c6e9a
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
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
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_pulldown_c = "$Id$";
31 #include <string.h>
32 #include <smalloc.h>
33 #include <x11.h>
34 #include <macros.h>
35 #include "popup.h"
36 #include "pulldown.h"
38 static bool PDCallBack(t_x11 *x11,XEvent *event,Window w,void *data)
40 t_pulldown *pd;
41 int i,x,x1,y,nsel;
43 pd=(t_pulldown *)data;
44 y=pd->wd.height;
45 switch(event->type) {
46 case Expose:
47 XSetForeground(x11->disp,x11->gc,x11->fg);
48 XDrawLine(x11->disp,w,x11->gc,0,y-1,pd->wd.width,y-1);
49 for(i=0; (i<pd->nmenu); i++)
50 XDrawString(x11->disp,pd->wd.self,x11->gc,pd->xpos[i],x11->font->ascent,
51 pd->title[i],strlen(pd->title[i]));
52 break;
53 case ButtonPress:
54 if (pd->nsel==-1) {
55 x=event->xbutton.x;
56 for(nsel=0; (pd->xpos[nsel+1] < x) && (nsel < pd->nmenu-1); nsel++);
57 pd->nsel=nsel;
58 x1=max(0,min(pd_width(pd)-menu_width(pd->m[nsel]),pd->xpos[nsel]));
59 show_menu(x11,pd->m[nsel],x1,y+1,FALSE);
61 break;
62 case ButtonRelease:
63 hide_pd(x11,pd);
64 break;
65 default:
66 break;
68 return FALSE;
71 t_pulldown *init_pd(t_x11 *x11,Window Parent,int width,int height,
72 unsigned long fg,unsigned long bg,
73 int nmenu,int *nsub,t_mentry *ent[],char **title)
75 t_pulldown *pd;
76 int i;
78 snew(pd,1);
79 pd->title=title;
80 pd->nmenu=nmenu;
81 pd->nsel=-1;
82 snew(pd->m,nmenu);
83 snew(pd->xpos,nmenu+1);
84 pd->xpos[0]=5;
85 for(i=1; (i<=nmenu); i++)
86 pd->xpos[i]=20+pd->xpos[i-1]+
87 XTextWidth(x11->font,title[i-1],strlen(title[i-1]));
88 if (pd->xpos[nmenu] > width)
89 printf("Menu too wide\n");
91 InitWin(&(pd->wd),0,0,width,XTextHeight(x11->font)+2,0,"PullDown");
92 pd->wd.self=XCreateSimpleWindow(x11->disp,Parent,
93 pd->wd.x, pd->wd.y,
94 pd->wd.width,pd->wd.height,
95 pd->wd.bwidth,fg,bg);
96 x11->RegisterCallback(x11,pd->wd.self,Parent,PDCallBack,pd);
97 x11->SetInputMask(x11,pd->wd.self,ExposureMask | ButtonPressMask |
98 OwnerGrabButtonMask | ButtonReleaseMask);
99 XMapWindow(x11->disp,pd->wd.self);
101 for(i=0; (i<nmenu); i++)
102 pd->m[i]=init_menu(x11,Parent,fg,bg,nsub[i],ent[i],1);
104 return pd;
107 void hide_pd(t_x11 *x11,t_pulldown *pd)
109 if (pd->nsel != -1)
110 hide_menu(x11,pd->m[pd->nsel]);
111 pd->nsel=-1;
114 void check_pd_item(t_pulldown *pd,int nreturn,bool bStatus)
116 int i;
118 for(i=0; (i<pd->nmenu); i++)
119 check_menu_item(pd->m[i],nreturn,bStatus);
122 void done_pd(t_x11 *x11,t_pulldown *pd)
124 int i;
126 for(i=0; (i<pd->nmenu); i++)
127 done_menu(x11,pd->m[i]);
128 x11->UnRegisterCallback(x11,pd->wd.self);
129 sfree(pd->m);
130 sfree(pd->xpos);
133 int pd_width(t_pulldown *pd)
135 int i,w;
137 w=0;
138 for(i=0; (i<pd->nmenu); i++)
139 w=max(w,menu_width(pd->m[i]));
140 w=max(w,pd->xpos[pd->nmenu]);
141 return w;
144 int pd_height(t_pulldown *pd)
146 int i,h;
148 h=0;
149 for(i=0; (i<pd->nmenu); i++)
150 h=max(h,menu_height(pd->m[i]));
152 return h;