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, 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.
46 #include "gromacs/legacyheaders/macros.h"
47 #include "gromacs/utility/smalloc.h"
52 bool ChildCallBack(t_x11
*x11
, XEvent
*event
, Window w
, void *data
)
59 child
= (t_child
*)data
;
65 XSetForeground(x11
->disp
, x11
->gc
, x11
->fg
);
66 TextInRect(x11
, w
, m
->str
, 16, 0, wd
->width
-16-2, wd
->height
-2,
70 int y
= x11
->font
->ascent
;
71 XDrawLine(x11
->disp
, w
, x11
->gc
, 2, (y
*2)/3, 6, y
);
72 XDrawLine(x11
->disp
, w
, x11
->gc
, 3, (y
*2)/3, 7, y
);
73 XDrawLine(x11
->disp
, w
, x11
->gc
, 7, y
, 12, 2);
77 LightBorder(x11
->disp
, w
, x11
->fg
);
80 LightBorder(x11
->disp
, w
, x11
->bg
);
83 letter
.type
= ClientMessage
;
84 letter
.xclient
.display
= x11
->disp
;
85 letter
.xclient
.window
= m
->send_to
? m
->send_to
: child
->Parent
;
86 letter
.xclient
.message_type
= 0;
87 letter
.xclient
.format
= 32;
88 letter
.xclient
.data
.l
[0] = m
->nreturn
;
89 XSendEvent(x11
->disp
, letter
.xclient
.window
, True
, 0, &letter
);
97 bool MenuCallBack(t_x11
*x11
, XEvent
*event
, Window
/*w*/, void *data
)
105 /* Nothing to be done */
109 GrabOK(stderr
, XGrabPointer(x11
->disp
, m
->wd
.self
, True
,
110 ButtonReleaseMask
, GrabModeAsync
,
111 GrabModeAsync
, m
->wd
.self
, None
, CurrentTime
));
118 event
->xclient
.window
= m
->Parent
;
119 XSendEvent(x11
->disp
, m
->Parent
, True
, 0, event
);
127 t_menu
*init_menu(t_x11
*x11
, Window Parent
, unsigned long fg
, unsigned long bg
,
128 int nent
, t_mentry ent
[], int ncol
)
130 int i
, mlen
, mht
, area
, ht
;
141 /* Calculate dimensions of the menu */
143 for (i
= 0; (i
< nent
); i
++)
145 mlen
= std::max(mlen
, XTextWidth(x11
->font
, ent
[i
].str
, strlen(ent
[i
].str
)));
147 mht
= XTextHeight(x11
->font
);
148 /* Now we have the biggest single box, add a border of 2 pixels */
149 mlen
+= 20; /* We need extra space at the left for checkmarks */
151 /* Calculate the area of the menu */
154 /* No the number of rows per column, only beyond 8 rows */
176 InitWin(&(m
->wd
), 10, 10, fcol
*mlen
, frows
*mht
, 1, "Menu");
178 m
->wd
.self
= XCreateSimpleWindow(x11
->disp
, Parent
,
180 m
->wd
.width
, m
->wd
.height
,
181 m
->wd
.bwidth
, fg
, bg
);
182 x11
->RegisterCallback(x11
, m
->wd
.self
, Parent
, MenuCallBack
, m
);
183 x11
->SetInputMask(x11
, m
->wd
.self
, ExposureMask
|
184 OwnerGrabButtonMask
| ButtonReleaseMask
);
186 for (j
= l
= 0; (j
< fcol
); j
++)
188 for (k
= 0; (k
< frows
) && (l
< nent
); k
++, l
++)
192 kid
->Parent
= Parent
;
194 InitWin(w
, j
*mlen
, k
*mht
, mlen
-2, mht
-2, 1, NULL
);
195 w
->self
= XCreateSimpleWindow(x11
->disp
, m
->wd
.self
,
196 w
->x
, w
->y
, w
->width
, w
->height
,
198 x11
->RegisterCallback(x11
, w
->self
, m
->wd
.self
,
200 x11
->SetInputMask(x11
, w
->self
,
201 ButtonPressMask
| ButtonReleaseMask
|
202 OwnerGrabButtonMask
| ExposureMask
|
203 EnterWindowMask
| LeaveWindowMask
);
210 void show_menu(t_x11
*x11
, t_menu
*m
, int x
, int y
, bool bGrab
)
212 XMoveWindow(x11
->disp
, m
->wd
.self
, x
, y
);
214 XMapWindow(x11
->disp
, m
->wd
.self
);
215 XMapSubwindows(x11
->disp
, m
->wd
.self
);
218 void hide_menu(t_x11
*x11
, t_menu
*m
)
222 XUngrabPointer(x11
->disp
, CurrentTime
);
224 XUnmapWindow(x11
->disp
, m
->wd
.self
);
227 void check_menu_item(t_menu
*m
, int nreturn
, bool bStatus
)
231 for (i
= 0; (i
< m
->nitem
); i
++)
233 if (m
->item
[i
].m
->nreturn
== nreturn
)
235 m
->item
[i
].m
->bChecked
= bStatus
;
240 void done_menu(t_x11
*x11
, t_menu
*m
)
244 for (i
= 0; (i
< m
->nitem
); i
++)
246 x11
->UnRegisterCallback(x11
, m
->item
[i
].wd
.self
);
249 x11
->UnRegisterCallback(x11
, m
->wd
.self
);
253 int menu_width(t_menu
*m
)
258 int menu_height(t_menu
*m
)