4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gyas ROwers Mature At Cryogenic Speed
42 #include "gmx_fatal.h"
50 t_dlgitem
**CreateRadioButtonGroup(t_x11
*x11
, char *szTitle
,
51 t_id GroupID
, int nrb
, t_id rb
[],
53 char *szRB
[], int x0
,int y0
)
54 /* This routine creates a radio button group at the
55 * specified position. The return values is a pointer to an
56 * array of dlgitems, the array has length (nrb+1) with the +1
57 * because of the groupbox.
58 * nSelect is the ordinal of the selected button.
66 dlgitem
[0]=CreateGroupBox(x11
,szTitle
,GroupID
,nrb
,rb
,x0
,y0
,0,0,0);
68 y
=dlgitem
[0]->win
.y
+dlgitem
[0]->win
.height
;
70 for (i
=0; (i
<nrb
); i
++) {
71 dlgitem
[i
+1]=CreateRadioButton(x11
,szRB
[i
],(i
==nSelect
),
72 rb
[i
],GroupID
,x
,y
,0,0,0);
73 y
+=dlgitem
[i
+1]->win
.height
+OFFS_Y
;
74 w
=max(w
,dlgitem
[i
+1]->win
.width
);
76 for (i
=0; (i
<nrb
); i
++)
77 dlgitem
[i
+1]->win
.width
=w
;
78 dlgitem
[0]->win
.width
=w
+4*OFFS_X
;
79 dlgitem
[0]->win
.height
=y
-y0
;
84 t_dlgitem
**CreateDlgitemGroup(t_x11
*x11
, const char *szTitle
,
85 t_id GroupID
, int x0
, int y0
,
87 /* This routine creates a dlgitem group at the
88 * specified position. The return values is a pointer to an
89 * array of dlgitems, the array has length (nitem+1) with the +1
90 * because of the groupbox.
107 snew(dlgitem
,nitem
+1);
110 dlgitem
[0]=CreateGroupBox(x11
,szTitle
,GroupID
,nitem
,ids
,x0
,y0
,0,0,0);
111 y
=dlgitem
[0]->win
.y
+dlgitem
[0]->win
.height
;
113 for (i
=0; (i
<nitem
); i
++) {
114 edlg
=(edlgitem
)va_arg(ap
,int);
115 ids
[i
]=va_arg(ap
,int);
118 name
=va_arg(ap
,char *);
119 bBool
=va_arg(ap
,int);
120 dlgitem
[i
+1]=CreateButton(x11
,name
,bBool
,ids
[i
],GroupID
,x
,y
,0,0,0);
123 name
=va_arg(ap
,char *);
124 bBool
=va_arg(ap
,int);
125 dlgitem
[i
+1]=CreateRadioButton(x11
,name
,bBool
,ids
[i
],GroupID
,x
,y
,0,0,0);
128 name
=va_arg(ap
,char *);
129 bBool
=va_arg(ap
,int);
130 dlgitem
[i
+1]=CreateCheckBox(x11
,name
,bBool
,ids
[i
],GroupID
,x
,y
,0,0,0);
133 pm
=va_arg(ap
,Pixmap
);
134 dlgitem
[i
+1]=CreatePixmap(x11
,pm
,ids
[i
],GroupID
,x
,y
,0,0,0);
137 nlines
=va_arg(ap
,int);
138 lines
=va_arg(ap
,char **);
139 dlgitem
[i
+1]=CreateStaticText(x11
,nlines
,lines
,ids
[i
],GroupID
,
143 name
=va_arg(ap
,char *);
144 buflen
=va_arg(ap
,int);
145 buf
=va_arg(ap
,char *);
146 dlgitem
[i
+1]=CreateEditText(x11
,name
,buflen
,buf
,ids
[i
],
151 gmx_fatal(FARGS
,"Invalid dlgitem type: %d\n",edlg
);
153 y
+=dlgitem
[i
+1]->win
.height
+OFFS_Y
;
154 w
=max(w
,dlgitem
[i
+1]->win
.width
);
157 sfree(dlgitem
[0]->u
.groupbox
.item
);
158 sfree(dlgitem
[0]->win
.text
);
159 dlgitem
[0]=CreateGroupBox(x11
,szTitle
,GroupID
,nitem
,ids
,x0
,y0
,0,0,0);
160 for (i
=0; (i
<nitem
); i
++)
161 dlgitem
[i
+1]->win
.width
=w
;
162 dlgitem
[0]->win
.width
=w
+4*OFFS_X
;
163 dlgitem
[0]->win
.height
=y
-y0
;
167 static void AddDlgItemGroups(t_dlg
*dlg
, int gridx
, int gridy
,
168 t_dlgitemlist
**grid
, bool bAutoPosition
)
176 for(x
=0; (x
<gridx
); x
++)
177 for(y
=0; (y
<gridy
); y
++) {
181 printf("Error: empty list with non-empty nitem (%d)\n",item
->nitem
);
182 printf(" at grid point: %d,%d\n",x
,y
);
183 printf(" with size: %dx%d\n",item
->w
,item
->h
);
187 AddDlgItems(dlg
,item
->nitem
,item
->list
);
190 w
=max(w
,((float) QueryDlgItemW(dlg
,item
->list
[0]->ID
))/dw
);
191 h
=max(h
,((float) QueryDlgItemH(dlg
,item
->list
[0]->ID
))/dh
);
197 SetDlgSize(dlg
,w1
,h1
,bAutoPosition
);
199 printf("Dimensions of grid cell: %8.3f x %8.3f\n",w
,h
);
200 printf("Dimensions of window: %d x %d\n",w1
,h1
);
203 for(x
=0; (x
<gridx
); x
++)
204 for(y
=0; (y
<gridy
); y
++) {
212 printf("New size: %d x %d at %d, %d\n",w1
,h1
,x1
,y1
);
214 SetDlgItemSize(dlg
,item
->list
[0]->ID
,w1
,h1
);
215 SetDlgItemPos(dlg
,item
->list
[0]->ID
,x1
,y1
);
220 static t_dlgitemlist
**NewDlgitemList(int w
, int h
)
223 t_dlgitemlist
**grid
;
226 for(i
=0; (i
<w
); i
++) {
228 for (j
=0; (j
<h
); j
++) {
230 grid
[i
][j
].list
=NULL
;
236 static void AddListItem(t_dlgitemlist
*list
, t_dlgitem
*item
)
238 srenew(list
->list
,++list
->nitem
);
239 list
->list
[list
->nitem
-1]=item
;
242 static void AddListFItem(t_x11
*x11
, t_dlgitemlist
*list
,
243 t_fitem
*fitem
, t_id GroupID
, t_id
*ID
,
244 int x
, int *y
, int *w
,bool bUseMon
)
249 switch(fitem
->edlg
) {
252 (list
,CreateButton(x11
,fitem
->name
[0],fitem
->bDef
,(*ID
)++,GroupID
,
256 strcpy(buf
,fitem
->def
);
258 for (i
=0; (i
<fitem
->nname
); i
++) {
261 strcpy(buf2
,fitem
->name
[i
]);
262 buf2
[strlen(buf
)]='\0'; /* truncate itemname */
263 if (strcasecmp(buf2
,buf
)==0)
267 for(i
=0; (i
<fitem
->nname
); i
++) {
269 CreateRadioButton(x11
,fitem
->name
[i
],(iSel
==i
),
270 (*ID
)++,GroupID
,x
,(*y
),0,0,0));
271 (*y
)+=list
->list
[list
->nitem
-1]->win
.height
+OFFS_Y
;
272 (*w
)=max((*w
),list
->list
[list
->nitem
-1]->win
.width
);
273 SetDlgitemOpts(list
->list
[list
->nitem
-1],bUseMon
,
274 fitem
->set
,fitem
->get
,fitem
->help
);
280 bCheck
=strcasecmp(fitem
->def
,"TRUE")==0;
281 AddListItem(list
,CreateCheckBox(x11
,fitem
->name
[0],bCheck
,
282 (*ID
)++,GroupID
,x
,(*y
),0,0,0));
287 CreateStaticText(x11
,fitem
->nname
,fitem
->name
,(*ID
)++,
288 GroupID
,x
,(*y
),0,0,0));
291 slen
=strlen(fitem
->name
[0])+strlen(fitem
->def
);
292 AddListItem(list
,CreateEditText(x11
,fitem
->name
[0],slen
,fitem
->def
,
293 (*ID
)++,GroupID
,x
,(*y
),0,0,0));
298 gmx_fatal(FARGS
,"Invalid list->list type: %d\n",fitem
->edlg
);
300 SetDlgitemOpts(list
->list
[list
->nitem
-1],bUseMon
,
301 fitem
->set
,fitem
->get
,fitem
->help
);
303 if (fitem
->edlg
!= edlgRB
) {
304 (*y
)+=list
->list
[list
->nitem
-1]->win
.height
+OFFS_Y
;
305 (*w
)=max((*w
),list
->list
[list
->nitem
-1]->win
.width
);
309 static void AddListFGroup(t_x11
*x11
, t_dlgitemlist
**grid
,
310 t_fgroup
*fgroup
, t_id
*ID
,bool bUseMon
)
318 item
=&(grid
[fgroup
->x
][fgroup
->y
]);
319 AddListItem(item
,CreateGroupBox(x11
,fgroup
->name
,GroupID
,
322 y
=item
->list
[0]->win
.y
+item
->list
[0]->win
.height
;
324 for(i
=0; (i
<fgroup
->nfitem
); i
++)
325 AddListFItem(x11
,item
,fgroup
->fitem
[i
],GroupID
,ID
,x
,&y
,&w
,bUseMon
);
327 w
=max(w
,item
->list
[0]->win
.width
+4*OFFS_X
);
328 sfree(item
->list
[0]->u
.groupbox
.item
);
329 sfree(item
->list
[0]->win
.text
);
330 snew(ids
,item
->nitem
);
331 for(i
=0; (i
<item
->nitem
-1); i
++)
334 CreateGroupBox(x11
,fgroup
->name
,GroupID
,item
->nitem
-1,ids
,
335 2*OFFS_X
,2*OFFS_Y
,w
+2*OFFS_X
,y
,0);
341 static void AddListFSimple(t_x11
*x11
, t_dlgitemlist
**grid
,
342 t_fsimple
*fsimple
, t_id
*ID
,bool bUseMon
)
347 item
=&(grid
[fsimple
->x
][fsimple
->y
]);
351 AddListFItem(x11
,item
,fsimple
->fitem
,*ID
,ID
,x
,&y
,&w
,bUseMon
);
356 t_dlg
*ReadDlg(t_x11
*x11
,Window Parent
, const char *title
,
357 unsigned long fg
, unsigned long bg
, const char *infile
,
358 int x0
, int y0
, bool bAutoPosition
,bool bUseMon
,
359 DlgCallback
*cb
,void *data
)
362 t_dlgitemlist
**grid
;
367 fgrid
=FGridFromFile(infile
);
368 dlg
=CreateDlg(x11
,Parent
,title
,x0
,y0
,0,0,0,fg
,bg
,cb
,data
);
369 grid
=NewDlgitemList(fgrid
->w
,fgrid
->h
);
372 for(i
=0; (i
<fgrid
->nfgroup
); i
++)
373 AddListFGroup(x11
,grid
,fgrid
->fgroup
[i
],&ID
,bUseMon
);
374 for(i
=0; (i
<fgrid
->nfsimple
); i
++)
375 AddListFSimple(x11
,grid
,fgrid
->fsimple
[i
],&ID
,bUseMon
);
376 AddDlgItemGroups(dlg
,fgrid
->w
,fgrid
->h
,grid
,bAutoPosition
);