Fix AVX-512 SIMD test for C
[gromacs.git] / src / programs / view / pulldown.cpp
blob57a62e88680c15489cc7d1a745978484bd6ddcbf
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-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 #include "gmxpre.h"
39 #include "pulldown.h"
41 #include <cstdio>
42 #include <cstring>
44 #include <algorithm>
46 #include "gromacs/utility/smalloc.h"
48 #include "popup.h"
49 #include "x11.h"
51 static bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
53 t_pulldown *pd;
54 int i, x, x1, y, nsel;
56 pd = (t_pulldown *)data;
57 y = pd->wd.height;
58 switch (event->type)
60 case Expose:
61 XSetForeground(x11->disp, x11->gc, x11->fg);
62 XDrawLine(x11->disp, w, x11->gc, 0, y-1, pd->wd.width, y-1);
63 for (i = 0; (i < pd->nmenu); i++)
65 XDrawString(x11->disp, pd->wd.self, x11->gc, pd->xpos[i], x11->font->ascent,
66 pd->title[i], std::strlen(pd->title[i]));
68 break;
69 case ButtonPress:
70 if (pd->nsel == -1)
72 x = event->xbutton.x;
73 for (nsel = 0; (pd->xpos[nsel+1] < x) && (nsel < pd->nmenu-1); nsel++)
77 pd->nsel = nsel;
78 x1 = std::max(0, std::min(pd_width(pd)-menu_width(pd->m[nsel]), pd->xpos[nsel]));
79 show_menu(x11, pd->m[nsel], x1, y+1, false);
81 break;
82 case ButtonRelease:
83 hide_pd(x11, pd);
84 break;
85 default:
86 break;
88 return false;
91 t_pulldown *init_pd(t_x11 *x11, Window Parent, int width,
92 unsigned long fg, unsigned long bg,
93 int nmenu, int *nsub, t_mentry *ent[], const char **title)
95 t_pulldown *pd;
96 int i;
98 snew(pd, 1);
99 pd->title = title;
100 pd->nmenu = nmenu;
101 pd->nsel = -1;
102 snew(pd->m, nmenu);
103 snew(pd->xpos, nmenu+1);
104 pd->xpos[0] = 5;
105 for (i = 1; (i <= nmenu); i++)
107 pd->xpos[i] = 20+pd->xpos[i-1]+
108 XTextWidth(x11->font, title[i-1], std::strlen(title[i-1]));
110 if (pd->xpos[nmenu] > width)
112 std::printf("Menu too wide\n");
115 InitWin(&(pd->wd), 0, 0, width, XTextHeight(x11->font)+2, 0, "PullDown");
116 pd->wd.self = XCreateSimpleWindow(x11->disp, Parent,
117 pd->wd.x, pd->wd.y,
118 pd->wd.width, pd->wd.height,
119 pd->wd.bwidth, fg, bg);
120 x11->RegisterCallback(x11, pd->wd.self, Parent, PDCallBack, pd);
121 x11->SetInputMask(x11, pd->wd.self, ExposureMask | ButtonPressMask |
122 OwnerGrabButtonMask | ButtonReleaseMask);
123 XMapWindow(x11->disp, pd->wd.self);
125 for (i = 0; (i < nmenu); i++)
127 pd->m[i] = init_menu(x11, Parent, fg, bg, nsub[i], ent[i], 1);
130 return pd;
133 void hide_pd(t_x11 *x11, t_pulldown *pd)
135 if (pd->nsel != -1)
137 hide_menu(x11, pd->m[pd->nsel]);
139 pd->nsel = -1;
142 void check_pd_item(t_pulldown *pd, int nreturn, bool bStatus)
144 int i;
146 for (i = 0; (i < pd->nmenu); i++)
148 check_menu_item(pd->m[i], nreturn, bStatus);
152 void done_pd(t_x11 *x11, t_pulldown *pd)
154 int i;
156 for (i = 0; (i < pd->nmenu); i++)
158 done_menu(x11, pd->m[i]);
160 x11->UnRegisterCallback(x11, pd->wd.self);
161 sfree(pd->m);
162 sfree(pd->xpos);
165 int pd_width(t_pulldown *pd)
167 int i, w;
169 w = 0;
170 for (i = 0; (i < pd->nmenu); i++)
172 w = std::max(w, menu_width(pd->m[i]));
174 w = std::max(w, pd->xpos[pd->nmenu]);
175 return w;
178 int pd_height(t_pulldown *pd)
180 int i, h;
182 h = 0;
183 for (i = 0; (i < pd->nmenu); i++)
185 h = std::max(h, menu_height(pd->m[i]));
188 return h;