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
47 bool ChildCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
54 child = (t_child *)data;
60 XSetForeground(x11->disp, x11->gc, x11->fg);
61 TextInRect(x11, w, m->str, 16, 0, wd->width-16-2, wd->height-2,
65 int y = x11->font->ascent;
66 XDrawLine(x11->disp, w, x11->gc, 2, (y*2)/3, 6, y);
67 XDrawLine(x11->disp, w, x11->gc, 3, (y*2)/3, 7, y);
68 XDrawLine(x11->disp, w, x11->gc, 7, y, 12, 2);
72 LightBorder(x11->disp, w, x11->fg);
75 LightBorder(x11->disp, w, x11->bg);
78 letter.type = ClientMessage;
79 letter.xclient.display = x11->disp;
80 letter.xclient.window = m->send_to ? m->send_to : child->Parent;
81 letter.xclient.message_type = 0;
82 letter.xclient.format = 32;
83 letter.xclient.data.l[0] = m->nreturn;
84 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
92 bool MenuCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
100 /* Nothing to be done */
104 GrabOK(stderr, XGrabPointer(x11->disp, m->wd.self, True,
105 ButtonReleaseMask, GrabModeAsync,
106 GrabModeAsync, m->wd.self, None, CurrentTime));
113 event->xclient.window = m->Parent;
114 XSendEvent(x11->disp, m->Parent, True, 0, event);
122 t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned long bg,
123 int nent, t_mentry ent[], int ncol)
125 int i, mlen, mht, area, ht;
136 /* Calculate dimensions of the menu */
138 for (i = 0; (i < nent); i++)
140 mlen = std::max(mlen, XTextWidth(x11->font, ent[i].str, strlen(ent[i].str)));
142 mht = XTextHeight(x11->font);
143 /* Now we have the biggest single box, add a border of 2 pixels */
144 mlen += 20; /* We need extra space at the left for checkmarks */
146 /* Calculate the area of the menu */
149 /* No the number of rows per column, only beyond 8 rows */
171 InitWin(&(m->wd), 10, 10, fcol*mlen, frows*mht, 1, "Menu");
173 m->wd.self = XCreateSimpleWindow(x11->disp, Parent,
175 m->wd.width, m->wd.height,
176 m->wd.bwidth, fg, bg);
177 x11->RegisterCallback(x11, m->wd.self, Parent, MenuCallBack, m);
178 x11->SetInputMask(x11, m->wd.self, ExposureMask |
179 OwnerGrabButtonMask | ButtonReleaseMask);
181 for (j = l = 0; (j < fcol); j++)
183 for (k = 0; (k < frows) && (l < nent); k++, l++)
187 kid->Parent = Parent;
189 InitWin(w, j*mlen, k*mht, mlen-2, mht-2, 1, NULL);
190 w->self = XCreateSimpleWindow(x11->disp, m->wd.self,
191 w->x, w->y, w->width, w->height,
193 x11->RegisterCallback(x11, w->self, m->wd.self,
195 x11->SetInputMask(x11, w->self,
196 ButtonPressMask | ButtonReleaseMask |
197 OwnerGrabButtonMask | ExposureMask |
198 EnterWindowMask | LeaveWindowMask);
205 void show_menu(t_x11 *x11, t_menu *m, int x, int y, bool bGrab)
207 XMoveWindow(x11->disp, m->wd.self, x, y);
209 XMapWindow(x11->disp, m->wd.self);
210 XMapSubwindows(x11->disp, m->wd.self);
213 void hide_menu(t_x11 *x11, t_menu *m)
217 XUngrabPointer(x11->disp, CurrentTime);
219 XUnmapWindow(x11->disp, m->wd.self);
222 void check_menu_item(t_menu *m, int nreturn, bool bStatus)
226 for (i = 0; (i < m->nitem); i++)
228 if (m->item[i].m->nreturn == nreturn)
230 m->item[i].m->bChecked = bStatus;
235 void done_menu(t_x11 *x11, t_menu *m)
239 for (i = 0; (i < m->nitem); i++)
241 x11->UnRegisterCallback(x11, m->item[i].wd.self);
244 x11->UnRegisterCallback(x11, m->wd.self);
248 int menu_width(t_menu *m)
253 int menu_height(t_menu *m)