3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2013, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gyas ROwers Mature At Cryogenic Speed
46 static bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
49 int i, x, x1, y, nsel;
51 pd = (t_pulldown *)data;
56 XSetForeground(x11->disp, x11->gc, x11->fg);
57 XDrawLine(x11->disp, w, x11->gc, 0, y-1, pd->wd.width, y-1);
58 for (i = 0; (i < pd->nmenu); i++)
60 XDrawString(x11->disp, pd->wd.self, x11->gc, pd->xpos[i], x11->font->ascent,
61 pd->title[i], strlen(pd->title[i]));
68 for (nsel = 0; (pd->xpos[nsel+1] < x) && (nsel < pd->nmenu-1); nsel++)
73 x1 = std::max(0, std::min(pd_width(pd)-menu_width(pd->m[nsel]), pd->xpos[nsel]));
74 show_menu(x11, pd->m[nsel], x1, y+1, false);
86 t_pulldown *init_pd(t_x11 *x11, Window Parent, int width,
87 unsigned long fg, unsigned long bg,
88 int nmenu, int *nsub, t_mentry *ent[], const char **title)
98 snew(pd->xpos, nmenu+1);
100 for (i = 1; (i <= nmenu); i++)
102 pd->xpos[i] = 20+pd->xpos[i-1]+
103 XTextWidth(x11->font, title[i-1], strlen(title[i-1]));
105 if (pd->xpos[nmenu] > width)
107 printf("Menu too wide\n");
110 InitWin(&(pd->wd), 0, 0, width, XTextHeight(x11->font)+2, 0, "PullDown");
111 pd->wd.self = XCreateSimpleWindow(x11->disp, Parent,
113 pd->wd.width, pd->wd.height,
114 pd->wd.bwidth, fg, bg);
115 x11->RegisterCallback(x11, pd->wd.self, Parent, PDCallBack, pd);
116 x11->SetInputMask(x11, pd->wd.self, ExposureMask | ButtonPressMask |
117 OwnerGrabButtonMask | ButtonReleaseMask);
118 XMapWindow(x11->disp, pd->wd.self);
120 for (i = 0; (i < nmenu); i++)
122 pd->m[i] = init_menu(x11, Parent, fg, bg, nsub[i], ent[i], 1);
128 void hide_pd(t_x11 *x11, t_pulldown *pd)
132 hide_menu(x11, pd->m[pd->nsel]);
137 void check_pd_item(t_pulldown *pd, int nreturn, bool bStatus)
141 for (i = 0; (i < pd->nmenu); i++)
143 check_menu_item(pd->m[i], nreturn, bStatus);
147 void done_pd(t_x11 *x11, t_pulldown *pd)
151 for (i = 0; (i < pd->nmenu); i++)
153 done_menu(x11, pd->m[i]);
155 x11->UnRegisterCallback(x11, pd->wd.self);
160 int pd_width(t_pulldown *pd)
165 for (i = 0; (i < pd->nmenu); i++)
167 w = std::max(w, menu_width(pd->m[i]));
169 w = std::max(w, pd->xpos[pd->nmenu]);
173 int pd_height(t_pulldown *pd)
178 for (i = 0; (i < pd->nmenu); i++)
180 h = std::max(h, menu_height(pd->m[i]));