Added Michael Shirts long-range dispersion and repulsion corrections that are correct...
[gromacs.git] / src / gmxlib / widget.c
blob40cac3ec6af886ea6966dd9496135b6ee0a4b77c
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
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
33 * And Hey:
34 * GROningen Mixture of Alchemy and Childrens' Stories
36 #include "widget.h"
37 #include "smalloc.h"
38 #include "fatal.h"
40 typedef struct {
41 Widget w,other,parent;
42 bool bDesc,bPopup;
43 XmString desc;
44 char *orignm;
45 char *directory;
46 int ftp;
47 } t_widget;
49 static t_widget *w=NULL;
50 static int nwindex=0,maxwindex=0;
51 XmString empty_str;
53 int nwidget(void)
55 return nwindex;
58 windex add_widget(Widget new_widget,char *desc)
60 int i;
62 if (nwindex == maxwindex) {
63 maxwindex += 8;
64 srenew(w,maxwindex);
65 for(i=nwindex; (i<maxwindex); i++) {
66 w[i].ftp = -1;
67 w[i].w = 0;
68 w[i].other = 0;
69 w[i].parent= 0;
70 w[i].bDesc = FALSE;
71 w[i].bPopup= FALSE;
72 w[i].orignm = NULL;
73 w[i].directory = NULL;
76 w[nwindex].w = new_widget;
77 if (desc) {
78 w[nwindex].desc = char2xms(desc);
79 w[nwindex].bDesc = TRUE;
81 if (debug)
82 fprintf(debug,"%s,%d: Successfully added widget %d (%s)\n",__FILE__,__LINE__,
83 nwindex,desc ? desc : "");
84 nwindex++;
86 return nwindex-1;
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);
117 if (orignm)
118 w[win].orignm = strdup(orignm);
119 else
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);
148 return w[win].w;
151 windex get_windex(Widget www)
153 int i;
155 for(i=0; (i<nwindex); i++)
156 if (w[i].w == www)
157 return i;
158 fatal_error(0,"No such widget %x\n",www);
160 return -1;
163 XmString get_widget_desc(Widget www)
165 int i;
167 for(i=0; (i<nwindex); i++)
168 if ((w[i].w == www) && w[i].bDesc)
169 return w[i].desc;
171 return empty_str;
174 bool have_windex_desc(windex www)
176 widget_range_check(www);
178 return w[www].bDesc;
181 int get_widget_ftp(Widget www)
183 int i;
185 for(i=0; (i<nwindex); i++)
186 if (w[i].w == www)
187 return w[i].ftp;
189 return -1;
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);
203 w[win].ftp = ftp;
206 void set_widget_dir(Widget www,XmString label)
208 Arg args[4];
209 int i,narg;
210 char *ptr,*clab,tmp;
212 i = get_windex(www);
214 if (i < nwindex) {
215 clab = xms2char(label);
216 if (w[i].directory)
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') {
222 tmp = ptr[1];
223 ptr[1] = '\0';
224 w[i].directory = strdup(clab);
225 ptr[1] = tmp;
227 /* Increase the pointer beyond the slash */
228 ptr++;
230 else {
231 w[i].directory = NULL;
232 ptr = clab;
234 if (strlen(ptr) > 0) {
235 narg = 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) {
240 narg = 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);
254 return w[win].other;
257 void set_widget_other(windex win,Widget www)
259 widget_range_check(win);
260 w[win].other = www;
263 XmString char2xms(const char *ptr)
265 return XmStringCreate(ptr,XmSTRING_DEFAULT_CHARSET);
268 char *xms2char(XmString xms)
270 /* This is NOT fool proof */
271 char *str;
273 /* set str to point to the text */
274 XmStringGetLtoR(xms,XmSTRING_DEFAULT_CHARSET,&str);
276 return str;