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, 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.
43 #include "gmx_fatal.h"
52 t_dlgitem **CreateRadioButtonGroup(t_x11 *x11, char *szTitle,
53 t_id GroupID, int nrb, t_id rb[],
55 char *szRB[], int x0, int y0)
56 /* This routine creates a radio button group at the
57 * specified position. The return values is a pointer to an
58 * array of dlgitems, the array has length (nrb+1) with the +1
59 * because of the groupbox.
60 * nSelect is the ordinal of the selected button.
68 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nrb, rb, x0, y0, 0, 0, 0);
70 y = dlgitem[0]->win.y+dlgitem[0]->win.height;
72 for (i = 0; (i < nrb); i++)
74 dlgitem[i+1] = CreateRadioButton(x11, szRB[i], (i == nSelect),
75 rb[i], GroupID, x, y, 0, 0, 0);
76 y += dlgitem[i+1]->win.height+OFFS_Y;
77 w = std::max(w, dlgitem[i+1]->win.width);
79 for (i = 0; (i < nrb); i++)
81 dlgitem[i+1]->win.width = w;
83 dlgitem[0]->win.width = w+4*OFFS_X;
84 dlgitem[0]->win.height = y-y0;
89 t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle,
90 t_id GroupID, int x0, int y0,
92 /* This routine creates a dlgitem group at the
93 * specified position. The return values is a pointer to an
94 * array of dlgitems, the array has length (nitem+1) with the +1
95 * because of the groupbox.
112 snew(dlgitem, nitem+1);
115 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nitem, ids, x0, y0, 0, 0, 0);
116 y = dlgitem[0]->win.y+dlgitem[0]->win.height;
118 for (i = 0; (i < nitem); i++)
120 edlg = (edlgitem)va_arg(ap, int);
121 ids[i] = va_arg(ap, int);
125 name = va_arg(ap, char *);
126 bBool = va_arg(ap, int);
127 dlgitem[i+1] = CreateButton(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
130 name = va_arg(ap, char *);
131 bBool = va_arg(ap, int);
132 dlgitem[i+1] = CreateRadioButton(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
135 name = va_arg(ap, char *);
136 bBool = va_arg(ap, int);
137 dlgitem[i+1] = CreateCheckBox(x11, name, bBool, ids[i], GroupID, x, y, 0, 0, 0);
140 pm = va_arg(ap, Pixmap);
141 dlgitem[i+1] = CreatePixmap(pm, ids[i], GroupID, x, y, 0, 0, 0);
144 nlines = va_arg(ap, int);
145 lines = va_arg(ap, char **);
146 dlgitem[i+1] = CreateStaticText(x11, nlines, lines, ids[i], GroupID,
150 name = va_arg(ap, char *);
151 buflen = va_arg(ap, int);
152 buf = va_arg(ap, char *);
153 dlgitem[i+1] = CreateEditText(x11, name, buflen, buf, ids[i],
154 GroupID, x, y, 0, 0, 0);
158 gmx_fatal(FARGS, "Invalid dlgitem type: %d\n", edlg);
160 y += dlgitem[i+1]->win.height+OFFS_Y;
161 w = std::max(w, dlgitem[i+1]->win.width);
164 sfree(dlgitem[0]->u.groupbox.item);
165 sfree(dlgitem[0]->win.text);
166 dlgitem[0] = CreateGroupBox(x11, szTitle, GroupID, nitem, ids, x0, y0, 0, 0, 0);
167 for (i = 0; (i < nitem); i++)
169 dlgitem[i+1]->win.width = w;
171 dlgitem[0]->win.width = w+4*OFFS_X;
172 dlgitem[0]->win.height = y-y0;
176 static void AddDlgItemGroups(t_dlg *dlg, int gridx, int gridy,
177 t_dlgitemlist **grid, bool bAutoPosition)
185 for (x = 0; (x < gridx); x++)
187 for (y = 0; (y < gridy); y++)
189 item = &(grid[x][y]);
194 printf("Error: empty list with non-empty nitem (%d)\n", item->nitem);
195 printf(" at grid point: %d,%d\n", x, y);
196 printf(" with size: %dx%d\n", item->w, item->h);
201 AddDlgItems(dlg, item->nitem, item->list);
204 w = std::max(w, ((float) QueryDlgItemW(dlg, item->list[0]->ID))/dw);
205 h = std::max(h, ((float) QueryDlgItemH(dlg, item->list[0]->ID))/dh);
212 SetDlgSize(dlg, w1, h1, bAutoPosition);
214 printf("Dimensions of grid cell: %8.3f x %8.3f\n", w, h);
215 printf("Dimensions of window: %d x %d\n", w1, h1);
218 for (x = 0; (x < gridx); x++)
220 for (y = 0; (y < gridy); y++)
222 item = &(grid[x][y]);
230 printf("New size: %d x %d at %d, %d\n", w1, h1, x1, y1);
232 SetDlgItemSize(dlg, item->list[0]->ID, w1, h1);
233 SetDlgItemPos(dlg, item->list[0]->ID, x1, y1);
239 static t_dlgitemlist **NewDlgitemList(int w, int h)
242 t_dlgitemlist **grid;
245 for (i = 0; (i < w); i++)
248 for (j = 0; (j < h); j++)
250 grid[i][j].nitem = 0;
251 grid[i][j].list = NULL;
257 static void AddListItem(t_dlgitemlist *list, t_dlgitem *item)
259 srenew(list->list, ++list->nitem);
260 list->list[list->nitem-1] = item;
263 static void AddListFItem(t_x11 *x11, t_dlgitemlist *list,
264 t_fitem *fitem, t_id GroupID, t_id *ID,
265 int x, int *y, int *w, bool bUseMon)
274 (list, CreateButton(x11, fitem->name[0], fitem->bDef, (*ID)++, GroupID,
278 strcpy(buf, fitem->def);
280 for (i = 0; (i < fitem->nname); i++)
284 strcpy(buf2, fitem->name[i]);
285 buf2[strlen(buf)] = '\0'; /* truncate itemname */
286 if (gmx_strcasecmp(buf2, buf) == 0)
292 for (i = 0; (i < fitem->nname); i++)
295 CreateRadioButton(x11, fitem->name[i], (iSel == i),
296 (*ID)++, GroupID, x, (*y), 0, 0, 0));
297 (*y) += list->list[list->nitem-1]->win.height+OFFS_Y;
298 (*w) = std::max((*w), list->list[list->nitem-1]->win.width);
299 SetDlgitemOpts(list->list[list->nitem-1], bUseMon,
300 fitem->set, fitem->get, fitem->help);
307 bCheck = gmx_strcasecmp(fitem->def, "TRUE") == 0;
308 AddListItem(list, CreateCheckBox(x11, fitem->name[0], bCheck,
309 (*ID)++, GroupID, x, (*y), 0, 0, 0));
314 CreateStaticText(x11, fitem->nname,
315 fitem->name, (*ID)++,
316 GroupID, x, (*y), 0, 0, 0));
319 slen = strlen(fitem->name[0])+strlen(fitem->def);
320 AddListItem(list, CreateEditText(x11, fitem->name[0], slen, fitem->def,
321 (*ID)++, GroupID, x, (*y), 0, 0, 0));
326 gmx_fatal(FARGS, "Invalid list->list type: %d\n", fitem->edlg);
328 SetDlgitemOpts(list->list[list->nitem-1], bUseMon,
329 fitem->set, fitem->get, fitem->help);
331 if (fitem->edlg != edlgRB)
333 (*y) += list->list[list->nitem-1]->win.height+OFFS_Y;
334 (*w) = std::max((*w), list->list[list->nitem-1]->win.width);
338 static void AddListFGroup(t_x11 *x11, t_dlgitemlist **grid,
339 t_fgroup *fgroup, t_id *ID, bool bUseMon)
347 item = &(grid[fgroup->x][fgroup->y]);
348 AddListItem(item, CreateGroupBox(x11, fgroup->name, GroupID,
349 0, NULL, 0, 0, 0, 0, 0));
351 y = item->list[0]->win.y+item->list[0]->win.height;
353 for (i = 0; (i < fgroup->nfitem); i++)
355 AddListFItem(x11, item, fgroup->fitem[i], GroupID, ID, x, &y, &w, bUseMon);
358 w = std::max(w, item->list[0]->win.width+4*OFFS_X);
359 sfree(item->list[0]->u.groupbox.item);
360 sfree(item->list[0]->win.text);
361 snew(ids, item->nitem);
362 for (i = 0; (i < item->nitem-1); i++)
364 ids[i] = GroupID+i+1;
367 CreateGroupBox(x11, fgroup->name, GroupID, item->nitem-1, ids,
368 2*OFFS_X, 2*OFFS_Y, w+2*OFFS_X, y, 0);
374 static void AddListFSimple(t_x11 *x11, t_dlgitemlist **grid,
375 t_fsimple *fsimple, t_id *ID, bool bUseMon)
380 item = &(grid[fsimple->x][fsimple->y]);
384 AddListFItem(x11, item, fsimple->fitem, *ID, ID, x, &y, &w, bUseMon);
385 item->w = fsimple->w;
386 item->h = fsimple->h;
389 t_dlg *ReadDlg(t_x11 *x11, Window Parent, const char *title,
391 int x0, int y0, bool bAutoPosition, bool bUseMon,
392 DlgCallback *cb, void *data)
395 t_dlgitemlist **grid;
400 fgrid = FGridFromFile(infile);
401 dlg = CreateDlg(x11, Parent, title, x0, y0, 0, 0, 0, cb, data);
402 grid = NewDlgitemList(fgrid->w, fgrid->h);
405 for (i = 0; (i < fgrid->nfgroup); i++)
407 AddListFGroup(x11, grid, fgrid->fgroup[i], &ID, bUseMon);
409 for (i = 0; (i < fgrid->nfsimple); i++)
411 AddListFSimple(x11, grid, fgrid->fsimple[i], &ID, bUseMon);
413 AddDlgItemGroups(dlg, fgrid->w, fgrid->h, grid, bAutoPosition);