SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / programs / view / xmb.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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,2017,2019,2020, 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #include "gmxpre.h"
38
39 #include "xmb.h"
40
41 #include <cstdio>
42 #include <cstdlib>
43
44 #include "gromacs/utility/fatalerror.h"
45
46 #include "Xstuff.h"
47 #include "alert.bm"
48 #include "gromacs.bm"
49 #include "info.bm"
50 #include "stop.bm"
51 #include "x11.h"
52 #include "xdlg.h"
53 #include "xutil.h"
54
55 #define ID_BOX -3
56 #define ID_ICON -2
57 #define ID_TEXT -1
58
59 static bmchar*       icon_bits   = nullptr;
60 static int           icon_width  = 0;
61 static int           icon_height = 0;
62 static unsigned long icon_fg     = 0;
63 static unsigned long icon_bg     = 0;
64
65 static void SetIcon(unsigned char* bits, int w, int h, unsigned long fg, unsigned long bg)
66 {
67     icon_bits   = (bmchar*)bits;
68     icon_width  = w;
69     icon_height = h;
70     icon_fg     = fg;
71     icon_bg     = bg;
72 }
73
74 t_dlg* MessageBox(t_x11*             x11,
75                   Window             Parent,
76                   const char*        title,
77                   int                nlines,
78                   const char* const* lines,
79                   unsigned long      Flags,
80                   DlgCallback*       cb,
81                   void*              data)
82 {
83     t_dlg*        dlg;
84     int           width, nicon;
85     int           x, y, x0;
86     unsigned long nFlag;
87     unsigned long bg;
88
89     /* Check flags for inconsistencies */
90     if (((Flags & MB_OK) && (Flags & MB_YES)) || ((Flags & MB_NO) && (Flags & MB_CANCEL))
91         || (!(Flags & MB_OK) && !(Flags & MB_YES)))
92     {
93         std::fprintf(stderr, "Invalid button selection in MessageBox\n");
94         std::exit(1);
95     }
96     nicon = 0;
97     if (Flags & MB_ICONSTOP)
98     {
99         nicon++;
100     }
101     if (Flags & MB_ICONINFORMATION)
102     {
103         nicon++;
104     }
105     if (Flags & MB_ICONEXCLAMATION)
106     {
107         nicon++;
108     }
109     if (Flags & MB_ICONGMX)
110     {
111         nicon++;
112     }
113     if (nicon > 1)
114     {
115         gmx_fatal(FARGS, "More than one (%d) icon selected in MessageBox", nicon);
116     }
117     /* Input seems ok */
118     bg = x11->bg;
119     if (nicon > 0)
120     {
121         if (Flags & MB_ICONSTOP)
122         {
123             SetIcon(stop_bits, stop_width, stop_height, RED, bg);
124         }
125         if (Flags & MB_ICONINFORMATION)
126         {
127             SetIcon(info_bits, info_width, info_height, BLUE, bg);
128         }
129         if (Flags & MB_ICONEXCLAMATION)
130         {
131             SetIcon(alert_bits, alert_width, alert_height, GREEN, bg);
132         }
133         if (Flags & MB_ICONGMX)
134         {
135             SetIcon(gromacs_bits, gromacs_width, gromacs_height, BLUE, bg);
136         }
137     }
138
139     dlg = CreateDlg(x11, Parent, title, 0, 0, 0, 0, 3, cb, data);
140     x   = 2 * OFFS_X;
141     if (nicon > 0)
142     {
143         AddDlgItem(dlg,
144                    CreatePixmap(
145                            XCreatePixmapFromBitmapData(
146                                    x11->disp, dlg->win.self, icon_bits, icon_width, icon_height, icon_fg, icon_bg, x11->depth),
147                            ID_ICON,
148                            ID_BOX,
149                            2 * OFFS_X,
150                            2 * OFFS_Y,
151                            icon_width,
152                            icon_height,
153                            0));
154         x += QueryDlgItemW(dlg, ID_ICON) + 2 * OFFS_X;
155     }
156
157     AddDlgItem(dlg, CreateStaticText(x11, nlines, lines, ID_TEXT, ID_BOX, x, 2 * OFFS_Y, 0, 0, 0));
158
159     y = QueryDlgItemY(dlg, ID_TEXT) + QueryDlgItemH(dlg, ID_TEXT);
160     if (nicon > 0)
161     {
162         int yi;
163         yi = QueryDlgItemY(dlg, ID_ICON) + QueryDlgItemH(dlg, ID_ICON);
164         if (yi > y)
165         {
166             SetDlgItemPos(dlg, ID_TEXT, x, 2 * OFFS_Y + (yi - y) / 2);
167         }
168         else
169         {
170             SetDlgItemPos(dlg, ID_ICON, 2 * OFFS_X, 2 * OFFS_Y + (y - yi) / 2);
171         }
172         if (yi > y)
173         {
174             y = yi;
175         }
176     }
177     x += QueryDlgItemW(dlg, ID_TEXT) + 2 * OFFS_X;
178     y += 2 * OFFS_Y;
179     width = (x - 8 * OFFS_X) / 2;
180
181     if (((Flags & MB_OKCANCEL) == MB_OKCANCEL) || ((Flags & MB_YESNO) == MB_YESNO))
182     {
183         x0 = 2 * OFFS_X;
184     }
185     else
186     {
187         x0 = (x - width) / 2;
188     }
189
190 #define CB(name, butx, id) \
191     AddDlgItem(dlg, CreateButton(x11, name, true, id, ID_BOX, butx, y, width, 0, 0))
192     if (Flags & MB_OK)
193     {
194         CB("OK", x0, MB_OK);
195     }
196     if (Flags & MB_CANCEL)
197     {
198         CB("Cancel", x / 2 + 2 * OFFS_X, MB_CANCEL);
199     }
200     if (Flags & MB_YES)
201     {
202         CB("Yes", x0, MB_YES);
203     }
204     if (Flags & MB_NO)
205     {
206         CB("No", x / 2 + 2 * OFFS_X, MB_NO);
207     }
208
209     SetDlgSize(dlg, x, y + 2 * OFFS_Y + QueryDlgItemH(dlg, (Flags & MB_OK) ? MB_OK : MB_YES), true);
210
211     if (Flags & MB_SYSTEMMODAL)
212     {
213         nFlag = DLG_SYSTEMMODAL;
214     }
215     else if (Flags & MB_APPLMODAL)
216     {
217         nFlag = DLG_APPLMODAL;
218     }
219     else
220     {
221         nFlag = 0;
222     }
223     nFlag      = nFlag | DLG_FREEONBUTTON;
224     dlg->flags = nFlag;
225
226     if (!(Flags & MB_DONTSHOW))
227     {
228         ShowDlg(dlg);
229     }
230
231     return dlg;
232 }