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"
51 #include "gromacs/utility/cstringutil.h"
52 #include "gromacs/utility/fatalerror.h"
53 #include "gromacs/utility/smalloc.h"
55 t_dlgitem **CreateRadioButtonGroup(t_x11 *x11, char *szTitle,
56 t_id GroupID, int nrb, t_id rb[],
58 char *szRB[], int x0, int y0)
59 /* This routine creates a radio button group at the
60 * specified position. The return values is a pointer to an
61 * array of dlgitems, the array has length (nrb+1) with the +1
62 * because of the groupbox.
63 * nSelect is the ordinal of the selected button.
71 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nrb, rb, x0, y0, 0, 0, 0);
73 y = dlgitem[0]->win.y+dlgitem[0]->win.height;
75 for (i = 0; (i < nrb); i++)
77 dlgitem[i+1] = CreateRadioButton(x11, szRB[i], (i == nSelect),
78 rb[i], GroupID, x, y, 0, 0, 0);
79 y += dlgitem[i+1]->win.height+OFFS_Y;
80 w = std::max(w, dlgitem[i+1]->win.width);
82 for (i = 0; (i < nrb); i++)
84 dlgitem[i+1]->win.width = w;
86 dlgitem[0]->win.width = w+4*OFFS_X;
87 dlgitem[0]->win.height = y-y0;
92 t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle,
93 t_id GroupID, int x0, int y0,
95 /* This routine creates a dlgitem group at the
96 * specified position. The return values is a pointer to an
97 * array of dlgitems, the array has length (nitem+1) with the +1
98 * because of the groupbox.
115 snew(dlgitem, nitem+1);
118 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nitem, ids, x0, y0, 0, 0, 0);
119 y = dlgitem[0]->win.y+dlgitem[0]->win.height;
121 for (i = 0; (i < nitem); i++)
123 edlg = (edlgitem)va_arg(ap, int);
124 ids[i] = va_arg(ap, int);
128 name = va_arg(ap, char *);
129 bBool = va_arg(ap, int);
130 dlgitem[i+1] = CreateButton(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
133 name = va_arg(ap, char *);
134 bBool = va_arg(ap, int);
135 dlgitem[i+1] = CreateRadioButton(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
138 name = va_arg(ap, char *);
139 bBool = va_arg(ap, int);
140 dlgitem[i+1] = CreateCheckBox(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
143 pm = va_arg(ap, Pixmap);
144 dlgitem[i+1] = CreatePixmap(pm, ids[i], GroupID, x, y, 0, 0, 0);
147 nlines = va_arg(ap, int);
148 lines = va_arg(ap, char **);
149 dlgitem[i+1] = CreateStaticText(x11, nlines, lines, ids[i], GroupID,
153 name = va_arg(ap, char *);
154 buflen = va_arg(ap, int);
155 buf = va_arg(ap, char *);
156 dlgitem[i+1] = CreateEditText(x11, name, buflen, buf, ids[i],
157 GroupID, x, y, 0, 0, 0);
161 gmx_fatal(FARGS, "Invalid dlgitem type: %d\n", edlg);
163 y += dlgitem[i+1]->win.height+OFFS_Y;
164 w = std::max(w, dlgitem[i+1]->win.width);
167 sfree(dlgitem[0]->u.groupbox.item);
168 sfree(dlgitem[0]->win.text);
169 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nitem, ids, x0, y0, 0, 0, 0);
170 for (i = 0; (i < nitem); i++)
172 dlgitem[i+1]->win.width = w;
174 dlgitem[0]->win.width = w+4*OFFS_X;
175 dlgitem[0]->win.height = y-y0;
179 static void AddDlgItemGroups(t_dlg *dlg, int gridx, int gridy,
180 t_dlgitemlist **grid, bool bAutoPosition)
188 for (x = 0; (x < gridx); x++)
190 for (y = 0; (y < gridy); y++)
192 item = &(grid[x][y]);
197 printf("Error: empty list with non-empty nitem (%d)\n", item->nitem);
198 printf(" at grid point: %d,%d\n", x, y);
199 printf(" with size: %dx%d\n", item->w, item->h);
204 AddDlgItems(dlg, item->nitem, item->list);
207 w = std::max(w, ((float) QueryDlgItemW(dlg, item->list[0]->ID))/dw);
208 h = std::max(h, ((float) QueryDlgItemH(dlg, item->list[0]->ID))/dh);
215 SetDlgSize(dlg, w1, h1, bAutoPosition);
217 printf("Dimensions of grid cell: %8.3f x %8.3f\n", w, h);
218 printf("Dimensions of window: %d x %d\n", w1, h1);
221 for (x = 0; (x < gridx); x++)
223 for (y = 0; (y < gridy); y++)
225 item = &(grid[x][y]);
233 printf("New size: %d x %d at %d, %d\n", w1, h1, x1, y1);
235 SetDlgItemSize(dlg, item->list[0]->ID, w1, h1);
236 SetDlgItemPos(dlg, item->list[0]->ID, x1, y1);
242 static t_dlgitemlist **NewDlgitemList(int w, int h)
245 t_dlgitemlist **grid;
248 for (i = 0; (i < w); i++)
251 for (j = 0; (j < h); j++)
253 grid[i][j].nitem = 0;
254 grid[i][j].list = NULL;
260 static void AddListItem(t_dlgitemlist *list, t_dlgitem *item)
262 srenew(list->list, ++list->nitem);
263 list->list[list->nitem-1] = item;
266 static void AddListFItem(t_x11 *x11, t_dlgitemlist *list,
267 t_fitem *fitem, t_id GroupID, t_id *ID,
268 int x, int *y, int *w, bool bUseMon)
277 (list, CreateButton(x11, fitem->name[0], fitem->bDef, (*ID)++, GroupID,
281 strcpy(buf, fitem->def);
283 for (i = 0; (i < fitem->nname); i++)
287 strcpy(buf2, fitem->name[i]);
288 buf2[strlen(buf)] = '\0'; /* truncate itemname */
289 if (gmx_strcasecmp(buf2, buf) == 0)
295 for (i = 0; (i < fitem->nname); i++)
298 CreateRadioButton(x11, fitem->name[i], (iSel == i),
299 (*ID)++, GroupID, x, (*y), 0, 0, 0));
300 (*y) += list->list[list->nitem-1]->win.height+OFFS_Y;
301 (*w) = std::max((*w), list->list[list->nitem-1]->win.width);
302 SetDlgitemOpts(list->list[list->nitem-1], bUseMon,
303 fitem->set, fitem->get, fitem->help);
310 bCheck = gmx_strcasecmp(fitem->def, "TRUE") == 0;
311 AddListItem(list, CreateCheckBox(x11, fitem->name[0], bCheck,
312 (*ID)++, GroupID, x, (*y), 0, 0, 0));
317 CreateStaticText(x11, fitem->nname,
318 fitem->name, (*ID)++,
319 GroupID, x, (*y), 0, 0, 0));
322 slen = strlen(fitem->name[0])+strlen(fitem->def);
323 AddListItem(list, CreateEditText(x11, fitem->name[0], slen, fitem->def,
324 (*ID)++, GroupID, x, (*y), 0, 0, 0));
329 gmx_fatal(FARGS, "Invalid list->list type: %d\n", fitem->edlg);
331 SetDlgitemOpts(list->list[list->nitem-1], bUseMon,
332 fitem->set, fitem->get, fitem->help);
334 if (fitem->edlg != edlgRB)
336 (*y) += list->list[list->nitem-1]->win.height+OFFS_Y;
337 (*w) = std::max((*w), list->list[list->nitem-1]->win.width);
341 static void AddListFGroup(t_x11 *x11, t_dlgitemlist **grid,
342 t_fgroup *fgroup, t_id *ID, bool bUseMon)
350 item = &(grid[fgroup->x][fgroup->y]);
351 AddListItem(item, CreateGroupBox(x11, fgroup->name, GroupID,
352 0, NULL, 0, 0, 0, 0, 0));
354 y = item->list[0]->win.y+item->list[0]->win.height;
356 for (i = 0; (i < fgroup->nfitem); i++)
358 AddListFItem(x11, item, fgroup->fitem[i], GroupID, ID, x, &y, &w, bUseMon);
361 w = std::max(w, item->list[0]->win.width+4*OFFS_X);
362 sfree(item->list[0]->u.groupbox.item);
363 sfree(item->list[0]->win.text);
364 snew(ids, item->nitem);
365 for (i = 0; (i < item->nitem-1); i++)
367 ids[i] = GroupID+i+1;
370 CreateGroupBox(x11, fgroup->name, GroupID, item->nitem-1, ids,
371 2*OFFS_X, 2*OFFS_Y, w+2*OFFS_X, y, 0);
377 static void AddListFSimple(t_x11 *x11, t_dlgitemlist **grid,
378 t_fsimple *fsimple, t_id *ID, bool bUseMon)
383 item = &(grid[fsimple->x][fsimple->y]);
387 AddListFItem(x11, item, fsimple->fitem, *ID, ID, x, &y, &w, bUseMon);
388 item->w = fsimple->w;
389 item->h = fsimple->h;
392 t_dlg *ReadDlg(t_x11 *x11, Window Parent, const char *title,
394 int x0, int y0, bool bAutoPosition, bool bUseMon,
395 DlgCallback *cb, void *data)
398 t_dlgitemlist **grid;
403 fgrid = FGridFromFile(infile);
404 dlg = CreateDlg(x11, Parent, title, x0, y0, 0, 0, 0, cb, data);
405 grid = NewDlgitemList(fgrid->w, fgrid->h);
408 for (i = 0; (i < fgrid->nfgroup); i++)
410 AddListFGroup(x11, grid, fgrid->fgroup[i], &ID, bUseMon);
412 for (i = 0; (i < fgrid->nfsimple); i++)
414 AddListFSimple(x11, grid, fgrid->fsimple[i], &ID, bUseMon);
416 AddDlgItemGroups(dlg, fgrid->w, fgrid->h, grid, bAutoPosition);