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,2017, 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.
44 #include "gromacs/utility/fatalerror.h"
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;
65 static void SetIcon(unsigned char *bits
, int w
, int h
, unsigned long fg
, unsigned long bg
)
67 icon_bits
= (bmchar
*)bits
;
74 t_dlg
*MessageBox(t_x11
*x11
, Window Parent
, const char *title
,
75 int nlines
, const char * const * lines
, unsigned long Flags
,
76 DlgCallback
*cb
, void *data
)
84 /* Check flags for inconsistencies */
85 if (((Flags
& MB_OK
) && (Flags
& MB_YES
)) ||
86 ((Flags
& MB_NO
) && (Flags
& MB_CANCEL
)) ||
87 (!(Flags
& MB_OK
) && !(Flags
& MB_YES
)))
89 std::fprintf(stderr
, "Invalid button selection in MessageBox\n");
93 if (Flags
& MB_ICONSTOP
)
97 if (Flags
& MB_ICONINFORMATION
)
101 if (Flags
& MB_ICONEXCLAMATION
)
105 if (Flags
& MB_ICONGMX
)
111 gmx_fatal(FARGS
, "More than one (%d) icon selected in MessageBox", nicon
);
117 if (Flags
& MB_ICONSTOP
)
119 SetIcon(stop_bits
, stop_width
, stop_height
, RED
, bg
);
121 if (Flags
& MB_ICONINFORMATION
)
123 SetIcon(info_bits
, info_width
, info_height
, BLUE
, bg
);
125 if (Flags
& MB_ICONEXCLAMATION
)
127 SetIcon(alert_bits
, alert_width
, alert_height
, GREEN
, bg
);
129 if (Flags
& MB_ICONGMX
)
131 SetIcon(gromacs_bits
, gromacs_width
, gromacs_height
, BLUE
, bg
);
135 dlg
= CreateDlg(x11
, Parent
, title
, 0, 0, 0, 0, 3, cb
, data
);
139 AddDlgItem(dlg
, CreatePixmap
140 (XCreatePixmapFromBitmapData
141 (x11
->disp
, dlg
->win
.self
, icon_bits
, icon_width
, icon_height
,
142 icon_fg
, icon_bg
, x11
->depth
),
143 ID_ICON
, ID_BOX
, 2*OFFS_X
, 2*OFFS_Y
, icon_width
, icon_height
, 0));
144 x
+= QueryDlgItemW(dlg
, ID_ICON
)+2*OFFS_X
;
147 AddDlgItem(dlg
, CreateStaticText(x11
, nlines
, lines
, ID_TEXT
, ID_BOX
,
148 x
, 2*OFFS_Y
, 0, 0, 0));
150 y
= QueryDlgItemY(dlg
, ID_TEXT
)+QueryDlgItemH(dlg
, ID_TEXT
);
154 yi
= QueryDlgItemY(dlg
, ID_ICON
)+QueryDlgItemH(dlg
, ID_ICON
);
157 SetDlgItemPos(dlg
, ID_TEXT
, x
, 2*OFFS_Y
+(yi
-y
)/2);
161 SetDlgItemPos(dlg
, ID_ICON
, 2*OFFS_X
, 2*OFFS_Y
+(y
-yi
)/2);
168 x
+= QueryDlgItemW(dlg
, ID_TEXT
)+2*OFFS_X
;
170 width
= (x
-8*OFFS_X
)/2;
172 if (((Flags
& MB_OKCANCEL
) == MB_OKCANCEL
) ||
173 ((Flags
& MB_YESNO
) == MB_YESNO
))
182 #define CB(name, butx, id) AddDlgItem(dlg, CreateButton(x11, name, \
184 butx, y, width, 0, 0))
189 if (Flags
& MB_CANCEL
)
191 CB("Cancel", x
/2+2*OFFS_X
, MB_CANCEL
);
195 CB("Yes", x0
, MB_YES
);
199 CB("No", x
/2+2*OFFS_X
, MB_NO
);
202 SetDlgSize(dlg
, x
, y
+2*OFFS_Y
+
203 QueryDlgItemH(dlg
, (Flags
& MB_OK
) ? MB_OK
: MB_YES
), true);
205 if (Flags
& MB_SYSTEMMODAL
)
207 nFlag
= DLG_SYSTEMMODAL
;
209 else if (Flags
& MB_APPLMODAL
)
211 nFlag
= DLG_APPLMODAL
;
217 nFlag
= nFlag
| DLG_FREEONBUTTON
;
220 if (!(Flags
& MB_DONTSHOW
))