1 /* Copyright (C) 1992-1998 The Geometry Center
2  * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3  *
4  * This file is part of Geomview.
5  *
6  * Geomview is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Geomview is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Geomview; see the file COPYING.  If not, write
18  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19  * USA, or visit http://www.gnu.org.
20  */
21 
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25 
26 #if 0
27 static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
28 Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
29 #endif
30 
31 #include "mibload.h"
32 #include "mibwidgets.h"
33 
34 extern Display	*dpy;
35 extern GC	 mib_gc;
36 
37 /* Code for RadioBox */
38 /*****************************************************************************/
39 
mib_create_RadioBox(mib_Widget * parent,char * name,char * label,int posx,int posy,int width,int height,int mib_fill)40 mib_Widget *mib_create_RadioBox(mib_Widget *parent, char *name, char *label,
41 		int posx, int posy, int width, int height, int mib_fill)
42 {
43   mib_Widget    *temp;
44   mib_RadioBox  *myres;
45   Widget	wtemp;
46   char		label_temp[50];
47   Arg		args[20];
48   int		n;
49 
50   /* create the new widget and add it to the tree */
51 
52   temp = mib_new_mib_Widget();
53   if (mib_fill == WDEFAULT)
54     mib_add_backward(temp, parent);
55   else
56     mib_add_mib_Widget(temp, parent);
57 
58   myres = (mib_RadioBox *)malloc(sizeof(mib_RadioBox));
59 
60   /* initialize public resources */
61 
62   if (mib_fill == WDEFAULT)
63   {
64     temp->name = (char *)malloc(strlen(name)+1);
65     strcpy(temp->name,name);
66   }
67   temp->mib_class = (char *)malloc(9);
68   sprintf(temp->mib_class,"RadioBox");
69   temp->mib_class_num = MIB_RADIOBOX;
70 
71   temp->width = width;
72   temp->height = height;
73   temp->topOffset = posy;
74   temp->leftOffset = posx;
75   temp->bottomOffset = 0;
76   temp->rightOffset = 0;
77   temp->topAttachment = 1;
78   temp->leftAttachment = 1;
79   temp->bottomAttachment = 0;
80   temp->rightAttachment = 0;
81 
82   temp->mib_allowresize = 0;
83 
84   /* initialize private resources */
85 
86   temp->myres = (void *)myres;
87 
88   myres->numlabel = 0;
89 
90   if (mib_fill == WDEFAULT)
91   {
92     myres->numlabel = 2;
93     myres->labels = (char **)malloc(10);
94     myres->buttons = (Widget *)malloc(sizeof(Widget) * myres->numlabel);
95     sprintf(label_temp, "Radio 1");
96     myres->labels[0] = (char *)malloc(strlen(label_temp)+1);
97     strcpy(myres->labels[0],label_temp);
98     sprintf(label_temp, "Radio 2");
99     myres->labels[1] = (char *)malloc(strlen(label_temp)+1);
100     strcpy(myres->labels[1],label_temp);
101   }
102 
103 
104   /* create Xt widget */
105 
106   n = 0;
107 
108   XtSetArg (args[n], XmNrubberPositioning, False); n++;
109 
110   if (mib_fill == WDEFAULT)
111   {
112     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
113     XtSetArg (args[n], XmNleftOffset, posx);n++;
114     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
115     XtSetArg (args[n], XmNtopOffset, posy);n++;
116     XtSetArg (args[n], XmNwidth, width); n++;
117     XtSetArg (args[n], XmNheight, height); n++;
118   }
119 
120   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
121 
122   temp->me = XmCreateRadioBox(temp->parent->me, "Radio", args, n);
123   wtemp = temp->me;
124 
125 
126   if (mib_fill == WDEFAULT)
127   {
128     n = 0;
129     XtSetArg (args[n], XmNhighlightThickness, 0); n++;
130 
131     XtCreateManagedWidget("Radio 1", xmToggleButtonGadgetClass,
132 		wtemp, args, n);
133 
134     n = 0;
135     XtSetArg (args[n], XmNhighlightThickness, 0); n++;
136     XtCreateManagedWidget("Radio 2", xmToggleButtonGadgetClass,
137 		wtemp, args, n);
138   }
139 
140 
141   XtManageChild(wtemp);
142 
143   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
144   {
145     mib_apply_eventhandlers(temp->me, temp);
146   }
147 
148   return temp;
149 }
150 
mib_delete_RadioBox(mib_Widget * this)151 void mib_delete_RadioBox(mib_Widget *this)
152 {
153   mib_RadioBox *temp = (mib_RadioBox *)this->myres;
154   int		count;
155 
156   for (count=0; count < temp->numlabel; count++)
157     free(temp->labels[count]);
158 
159   free(temp);
160 }
161 
mib_save_RadioBox(mib_Widget * this,FILE * fout)162 void mib_save_RadioBox(mib_Widget *this, FILE *fout)
163 {
164   mib_RadioBox *temp = (mib_RadioBox *)this->myres;
165   int count;
166 
167   fprintf(fout,"numlabel: %d\\n\\\n", temp->numlabel);
168 
169   for (count=0; count < temp->numlabel; count++)
170   {
171     fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->labels[count]);
172   }
173 }
174 
mib_load_RadioBox(mib_Widget * this,mib_Buffer * fin)175 int mib_load_RadioBox(mib_Widget *this, mib_Buffer *fin)
176 {
177   char		res[MI_MAXSTRLEN];
178   char		val[MI_MAXSTRLEN];
179   int		count, vallen, n;
180   Arg		args[5];
181   mib_RadioBox *myres;
182 
183   myres = (mib_RadioBox *)this->myres;
184 
185   if (!mib_read_line(fin, res, val))
186     return 0;
187 
188   if (!strcmp(res,"numlabel"))
189   {
190     myres->numlabel = 0;
191     sscanf(val,"%d",&(myres->numlabel));
192     if (!(myres->numlabel))
193       return 0;
194 
195     myres->labels = (char **)malloc((myres->numlabel+1)*4);
196     myres->buttons = (Widget *)malloc(sizeof(Widget)*(myres->numlabel));
197     for (count=0; count < myres->numlabel; count++)
198     {
199       if (!mib_read_line(fin, res, val))
200 	return 0;
201       vallen = strlen(val);
202       if (vallen < 2)
203 	return 0;
204       val[vallen-1] = '\0';
205       myres->labels[count] = (char *)malloc(vallen-1);
206       sprintf(myres->labels[count],"%s",&(val[1]));
207 
208       n = 0;
209       XtSetArg (args[n], XmNhighlightThickness, 0); n++;
210 
211       myres->buttons[count] = XtCreateManagedWidget(myres->labels[count],
212 		xmToggleButtonGadgetClass, this->me, args, n);
213 
214     }
215   }
216   else
217     return 0;
218 
219   if (!mib_read_line(fin, res, val))
220     return 0;
221   if (strcmp(res,"EndWidget"))
222     return 0;
223 
224   return 1;
225 }
226