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 Button */
38 /*****************************************************************************/
39 
mib_create_Button(mib_Widget * parent,char * name,char * label,int posx,int posy,int width,int height,int mib_fill)40 mib_Widget *mib_create_Button(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_Button *myres;
45   /*  unsigned char *label_text; */
46   XmString label_text;
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   myres = (mib_Button *)malloc(sizeof(mib_Button));
58 
59   /* initialize public resources */
60 
61   if (mib_fill == WDEFAULT)
62   {
63     temp->name = (char *)malloc(strlen(name)+1);
64     strcpy(temp->name,name);
65   }
66   temp->mib_class = (char *)malloc(7);
67   sprintf(temp->mib_class,"Button");
68   temp->mib_class_num = MIB_BUTTON;
69   temp->width = width;
70   temp->height = height;
71   temp->topOffset = posy;
72   temp->leftOffset = posx;
73   temp->bottomOffset = 0;
74   temp->rightOffset = 0;
75   temp->topAttachment = 1;
76   temp->leftAttachment = 1;
77   temp->bottomAttachment = 0;
78   temp->rightAttachment = 0;
79 
80   temp->mib_allowresize = 1;
81 
82   /* initialize private resources */
83 
84   temp->myres = (void *)myres;
85 
86   if (mib_fill == WDEFAULT)
87   {
88     myres->label = (char *)malloc(strlen(label)+1);
89     strcpy(myres->label,label);
90   }
91 
92   /* create Xt widget */
93 
94   n = 0;
95 
96   if (mib_fill == WDEFAULT)
97   {
98     label_text = XmStringCreateLtoR(label, XmSTRING_DEFAULT_CHARSET);
99 
100     XtSetArg (args[n], XmNlabelString, label_text); n++;
101     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
102     XtSetArg (args[n], XmNleftOffset, posx);n++;
103     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
104     XtSetArg (args[n], XmNtopOffset, posy);n++;
105     XtSetArg (args[n], XmNwidth, width); n++;
106     XtSetArg (args[n], XmNheight, height); n++;
107   }
108 
109   XtSetArg (args[n], XmNrubberPositioning, False); n++;
110   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
111 
112   temp->me = XtCreateManagedWidget(name, xmPushButtonWidgetClass,
113                 temp->parent->me, args, n);
114 
115   if (mib_fill == WDEFAULT)
116   {
117     XmStringFree(label_text);
118   }
119 
120   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
121   {
122     mib_apply_eventhandlers(temp->me, temp);
123   }
124 
125   return temp;
126 }
127 
mib_delete_Button(mib_Widget * this)128 void mib_delete_Button(mib_Widget *this)
129 {
130   mib_Button *temp = (mib_Button *)this->myres;
131 
132   free(temp->label);
133   free(temp);
134 }
135 
mib_save_Button(mib_Widget * this,FILE * fout)136 void mib_save_Button(mib_Widget *this, FILE *fout)
137 {
138   mib_Button *temp = (mib_Button *)this->myres;
139 
140   fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->label);
141 }
142 
mib_code_gen_Button(mib_Widget * this,FILE * fout)143 void mib_code_gen_Button(mib_Widget *this, FILE *fout)
144 {
145 }
146 
mib_load_Button(mib_Widget * this,mib_Buffer * fin)147 int mib_load_Button(mib_Widget *this, mib_Buffer *fin)
148 {
149   mib_Button	*myres;
150   /*  unsigned char *label_text; */
151   XmString label_text;
152   char          res[MI_MAXSTRLEN];
153   char          val[MI_MAXSTRLEN];
154   Arg		args[20];
155   int		n, got_line, vallen;
156 
157   myres = (mib_Button *)this->myres;
158 
159   got_line = mib_read_line(fin, res, val);
160   if (!got_line)
161     return 0;
162 
163   if (!strcmp(res,"label"))
164   {
165     vallen = strlen(val);
166     if (vallen < 2)
167       return 0;
168     val[vallen-1] = '\0';
169     myres->label = (char *)malloc(vallen-1);
170     sprintf(myres->label,"%s",&(val[1]));
171 
172     label_text = XmStringCreateLtoR(myres->label, XmSTRING_DEFAULT_CHARSET);
173 
174     n = 0;
175     XtSetArg (args[n], XmNlabelString, label_text); n++;
176     XtSetValues(this->me, args, n);
177 
178     XmStringFree(label_text);
179 
180   }
181   else
182     return 0;
183 
184   got_line = mib_read_line(fin, res, val);
185   if (!got_line)
186     return 0;
187 
188   if (strcmp(res,"EndWidget"))
189     return 0;
190 
191   return 1;
192 }
193