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 Frames */
38 /*****************************************************************************/
39 
mib_create_Frame(mib_Widget * parent,char * name,char * frame_type,int posx,int posy,int width,int height,int mib_fill)40 mib_Widget *mib_create_Frame(mib_Widget *parent, char *name, char *frame_type,
41 		int posx, int posy, int width, int height, int mib_fill)
42 {
43   mib_Widget *temp;
44   mib_Frame *myres;
45   Arg     args[20];
46   int     n;
47 
48   /* create the new widget and add it to the tree */
49 
50   temp = mib_new_mib_Widget();
51   if (mib_fill == WDEFAULT)
52     mib_add_backward(temp, parent);
53   else
54     mib_add_mib_Widget(temp, parent);
55 
56   myres = (mib_Frame *)malloc(sizeof(mib_Frame));
57 
58   /* initialize public resources */
59 
60   if (mib_fill == WDEFAULT)
61   {
62     temp->name = (char *)malloc(strlen(name)+1);
63     strcpy(temp->name,name);
64   }
65   temp->mib_class = (char *)malloc(6);
66   sprintf(temp->mib_class,"Frame");
67   temp->mib_class_num = MIB_FRAME;
68   temp->width = width;
69   temp->height = height;
70   temp->topOffset = posy;
71   temp->leftOffset = posx;
72   temp->bottomOffset = 0;
73   temp->rightOffset = 0;
74   temp->topAttachment = 1;
75   temp->leftAttachment = 1;
76   temp->bottomAttachment = 0;
77   temp->rightAttachment = 0;
78 
79   temp->mib_allowresize = 1;
80 
81   /* initialize private resources */
82 
83   temp->myres = (void *)myres;
84   myres->shadowtype = 0;
85 
86   /* create Xt widget */
87 
88   n = 0;
89 
90   if (mib_fill == WDEFAULT)
91   {
92     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
93     XtSetArg (args[n], XmNleftOffset, posx);n++;
94     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
95     XtSetArg (args[n], XmNtopOffset, posy);n++;
96     XtSetArg (args[n], XmNwidth, width); n++;
97     XtSetArg (args[n], XmNheight, height); n++;
98   }
99 
100   XtSetArg (args[n], XmNrubberPositioning, False); n++;
101 
102   if (mib_fill == WDEFAULT) {
103     if (!strcmp("InFrame",frame_type))
104     {
105       XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
106     }
107     else
108     if (!strcmp("OutFrame",frame_type))
109     {
110       XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
111       myres->shadowtype = 1;
112     }
113     else
114     if (!strcmp("EtchedInFrame",frame_type))
115     {
116       XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_IN); n++;
117       myres->shadowtype = 2;
118     }
119     else
120     if (!strcmp("EtchedOutFrame",frame_type))
121     {
122        XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_OUT); n++;
123        myres->shadowtype = 3;
124     }
125   }
126 
127   temp->me = XtCreateManagedWidget(name, xmFrameWidgetClass,
128                 temp->parent->me, args, n);
129 
130   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
131   {
132     mib_apply_eventhandlers(temp->me, temp);
133   }
134 
135   return temp;
136 }
137 
mib_delete_Frame(mib_Widget * this)138 void mib_delete_Frame(mib_Widget *this)
139 {
140   mib_Frame *temp = (mib_Frame *)this->myres;
141 
142   free(temp);
143 }
144 
mib_save_Frame(mib_Widget * this,FILE * fout)145 void mib_save_Frame(mib_Widget *this, FILE *fout)
146 {
147   mib_Frame *temp = (mib_Frame *)this->myres;
148 
149   fprintf(fout,"shadowtype: %d\\n\\\n", temp->shadowtype);
150 }
151 
mib_load_Frame(mib_Widget * this,mib_Buffer * fin)152 int mib_load_Frame(mib_Widget *this, mib_Buffer *fin)
153 {
154   mib_Frame    *myres;
155   char          res[MI_MAXSTRLEN];
156   char          val[MI_MAXSTRLEN];
157   Arg           args[5];
158   int           n;
159 
160   myres = (mib_Frame *)this->myres;
161 
162   if (!mib_read_line(fin, res, val))
163     return 0;
164 
165   if (!strcmp(res,"shadowtype"))
166   {
167     sscanf(val,"%d",&(myres->shadowtype));
168 
169     n = 0;
170     switch (myres->shadowtype) {
171 	case 0:
172         XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
173 	break;
174 	case 1:
175 	XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
176 	break;
177 	case 2:
178 	XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_IN); n++;
179 	break;
180 	case 3:
181 	XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_OUT); n++;
182 	break;
183 	default:
184 	break;
185     }
186     XtSetValues(this->me, args, n);
187   }
188   else
189     return 0;
190 
191   if (!mib_read_line(fin, res, val))
192     return 0;
193 
194   if (strcmp(res,"EndWidget"))
195     return 0;
196 
197   return 1;
198 }
199