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 * GROningen Mixture of Alchemy and Childrens' Stories
41 Widget w
,other
,parent
;
49 static t_widget
*w
=NULL
;
50 static int nwindex
=0,maxwindex
=0;
58 windex
add_widget(Widget new_widget
,char *desc
)
62 if (nwindex
== maxwindex
) {
65 for(i
=nwindex
; (i
<maxwindex
); i
++) {
73 w
[i
].directory
= NULL
;
76 w
[nwindex
].w
= new_widget
;
78 w
[nwindex
].desc
= char2xms(desc
);
79 w
[nwindex
].bDesc
= TRUE
;
82 fprintf(debug
,"%s,%d: Successfully added widget %d (%s)\n",__FILE__
,__LINE__
,
83 nwindex
,desc
? desc
: "");
89 static void widget_range_check(windex win
)
91 if (!((win
>=0) && (win
<nwindex
)))
92 fatal_error(0,"Widget index %d out of range, nwindex = %d",win
,nwindex
);
95 Widget
get_parent(windex win
)
97 widget_range_check(win
);
98 if (w
[win
].parent
== 0)
99 fatal_error(0,"No parent widget known for widget %d. I'm an orphan!",win
);
101 return w
[win
].parent
;
104 void set_parent(windex win
,Widget parent
)
106 widget_range_check(win
);
107 if (w
[win
].parent
!= 0)
108 fatal_error(0,"Parent widget already set for widget %d",win
);
110 w
[win
].parent
= parent
;
113 void set_windex_orignm(windex win
,char *orignm
)
115 widget_range_check(win
);
118 w
[win
].orignm
= strdup(orignm
);
120 w
[win
].orignm
= NULL
;
123 char *get_windex_orignm(windex win
)
125 widget_range_check(win
);
127 return w
[win
].orignm
;
130 void set_windex_popup(windex win
,bool bPopup
)
132 widget_range_check(win
);
134 w
[win
].bPopup
= bPopup
;
137 bool get_windex_popup(windex win
)
139 widget_range_check(win
);
141 return w
[win
].bPopup
;
144 Widget
get_widget(windex win
)
146 widget_range_check(win
);
151 windex
get_windex(Widget www
)
155 for(i
=0; (i
<nwindex
); i
++)
158 fatal_error(0,"No such widget %x\n",www
);
163 XmString
get_widget_desc(Widget www
)
167 for(i
=0; (i
<nwindex
); i
++)
168 if ((w
[i
].w
== www
) && w
[i
].bDesc
)
174 bool have_windex_desc(windex www
)
176 widget_range_check(www
);
181 int get_widget_ftp(Widget www
)
185 for(i
=0; (i
<nwindex
); i
++)
192 char *get_widget_dir(windex win
)
194 widget_range_check(win
);
196 return w
[win
].directory
? w
[win
].directory
: "";
199 void set_widget_ftp(windex win
,int ftp
)
201 widget_range_check(win
);
206 void set_widget_dir(Widget www
,XmString label
)
215 clab
= xms2char(label
);
217 sfree(w
[i
].directory
);
218 /* Check for last directory slash */
219 if ((ptr
= strrchr(clab
,'/')) != NULL
) {
220 /* check whether there is more than the directory */
221 if (ptr
[1] != '\0') {
224 w
[i
].directory
= strdup(clab
);
227 /* Increase the pointer beyond the slash */
231 w
[i
].directory
= NULL
;
234 if (strlen(ptr
) > 0) {
236 XtSetArg(args
[narg
],XmNvalue
, ptr
); narg
++;
237 XtSetValues(www
,args
,narg
);
238 /* Set the toggle button if we have an optional one */
239 if (w
[i
].other
!= 0) {
241 XtSetArg(args
[narg
], XmNset
, True
); narg
++;
242 XtSetValues(w
[i
].other
,args
,narg
);
248 Widget
get_widget_other(windex win
,bool bFail
)
250 widget_range_check(win
);
251 if ((w
[win
].other
== 0) && bFail
)
252 fatal_error(0,"Calling the wrong window: %d, no other widget\n",win
);
257 void set_widget_other(windex win
,Widget www
)
259 widget_range_check(win
);
263 XmString
char2xms(const char *ptr
)
265 return XmStringCreate(ptr
,XmSTRING_DEFAULT_CHARSET
);
268 char *xms2char(XmString xms
)
270 /* This is NOT fool proof */
273 /* set str to point to the text */
274 XmStringGetLtoR(xms
,XmSTRING_DEFAULT_CHARSET
,&str
);