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 
23 #if HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26 
27 #if 0
28 static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
29 Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
30 #endif
31 
32 #include "mibload.h"
33 #include "mibwidgets.h"
34 
35 mib_Widget	*mib_root_Widget;
36 Display		*dpy;
37 GC		 mib_gc;
38 static struct _mib_event_handle_funcs {
39   void		(*mib_pick_mib_Widget)(/* Widget, XtPointer,
40 					  XButtonPressedEvent *, Boolean * */);
41   void		(*mib_move_mib_Widget)(/* Widget, XtPointer,
42 					  XPointerMovedEvent *, Boolean * */);
43   void		(*mib_unpick_mib_Widget)(/* Widget, XtPointer,
44 					    XButtonReleasedEvent *, Boolean * */);
45 } mib_events;
46 
47 mib_widget_funcs mwfuncs[] =
48   {
49     { NULL, NULL, NULL, NULL, NULL },
50     { "TextBox", mib_create_TextBox, mib_delete_TextBox,
51       mib_save_TextBox, mib_load_TextBox},
52     { "Button", mib_create_Button, mib_delete_Button,
53       mib_save_Button, mib_load_Button},
54     { "Toggle", mib_create_Toggle, mib_delete_Toggle,
55       mib_save_Toggle, mib_load_Toggle},
56     { "RadioBox", mib_create_RadioBox, mib_delete_RadioBox,
57       mib_save_RadioBox, mib_load_RadioBox},
58     { "DrawingArea", mib_create_DrawingArea, mib_delete_DrawingArea,
59       mib_save_DrawingArea, mib_load_DrawingArea},
60     { "Label", mib_create_Label, mib_delete_Label,
61       mib_save_Label, mib_load_Label},
62     { "Frame", mib_create_Frame, mib_delete_Frame,
63       mib_save_Frame, mib_load_Frame},
64     { "ScrollBar", mib_create_ScrollBar, mib_delete_ScrollBar,
65       mib_save_ScrollBar, mib_load_ScrollBar},
66     { "TextBig", mib_create_TextBig, mib_delete_TextBig,
67       mib_save_TextBig, mib_load_TextBig},
68     { "List", mib_create_List, mib_delete_List,
69       mib_save_List, mib_load_List},
70     { "Scale", mib_create_Scale, mib_delete_Scale,
71       mib_save_Scale, mib_load_Scale},
72     { "Menu", mib_create_Menu, mib_delete_Menu,
73       mib_save_Menu, mib_load_Menu},
74     { NULL, NULL, NULL, NULL, NULL },
75   };
76 
77 /*****************************************************************************/
78 
mib_add_mib_Widget(mib_Widget * this,mib_Widget * parent)79 void mib_add_mib_Widget(mib_Widget *this, mib_Widget *parent)
80 {
81   mib_Widget *tmp;
82 
83   if (parent->child == NULL)
84     {
85       parent->child = this;
86       this->prev = parent;
87       this->parent = parent;
88       this->sibling = NULL;
89       this->child = NULL;
90     }
91   else
92     {
93       tmp = parent->child;
94       while (tmp->sibling != NULL)
95         tmp = tmp->sibling;
96       tmp->sibling = this;
97       this->prev = tmp;
98       this->parent = parent;
99       this->sibling = NULL;
100       this->child = NULL;
101     }
102 }
103 
104 /*****************************************************************************/
105 
mib_add_backward(mib_Widget * this,mib_Widget * parent)106 void mib_add_backward(mib_Widget *this, mib_Widget *parent)
107 {
108   mib_Widget *tmp;
109 
110   if (parent->child == NULL)
111     {
112       parent->child = this;
113       this->prev = parent;
114       this->parent = parent;
115       this->sibling = NULL;
116       this->child = NULL;
117     }
118   else
119     {
120       tmp = parent->child;
121       parent->child = this;
122       this->prev = parent;
123       this->parent = parent;
124       this->sibling = tmp;
125       this->child = NULL;
126       tmp->prev = this;
127     }
128 }
129 
130 /*****************************************************************************/
131 
mib_remove_mib_Widget(mib_Widget * this)132 void mib_remove_mib_Widget(mib_Widget *this)
133 {
134 
135   XtVaSetValues(mib_root_Widget->me, XmNresizePolicy, XmRESIZE_NONE, NULL);
136   XtDestroyWidget(this->me);
137 
138   while (this->child != NULL)
139     mib_remove_mib_Widget(this->child);
140 
141   if (this->parent == this)
142     {
143       mib_clear_myres(this);
144       return;
145     }
146 
147   if (this->prev == this->parent)
148     {
149       this->parent->child = this->sibling;
150       if (this->sibling != NULL)
151 	this->sibling->prev = this->parent;
152     }
153   else
154     {
155       this->prev->sibling = this->sibling;
156       if (this->sibling != NULL)
157 	this->sibling->prev = this->prev;
158     }
159 
160   mib_clear_myres(this);
161 }
162 
163 /*****************************************************************************/
164 
mib_clear_myres(mib_Widget * this)165 void mib_clear_myres(mib_Widget *this)
166 {
167   free(this->mib_class);
168   free(this->name);
169 
170   if ((this->mib_class_num < 1) || (this->mib_class_num > MI_NUMCLASSES))
171     return;
172 
173   mwfuncs[this->mib_class_num].mib_delete(this);
174   free(this);
175 }
176 
177 /*****************************************************************************/
178 
mib_new_mib_Widget()179 mib_Widget *mib_new_mib_Widget()
180 {
181   mib_Widget *this;
182   this = (mib_Widget *)malloc(sizeof(mib_Widget));
183   this->me = NULL;
184   this->mib_class_num = MIB_NULL;
185   this->mib_selected = 0;
186   this->mib_resizing = 0;
187   this->myres = NULL;
188   this->parent = NULL;
189   this->sibling = NULL;
190   this->prev = NULL;
191   this->child = NULL;
192   this->width = 0;
193   this->height = 0;
194   this->topAttachment = 0;
195   this->bottomAttachment = 0;
196   this->leftAttachment = 0;
197   this->rightAttachment = 0;
198   this->topOffset = 0;
199   this->bottomOffset = 0;
200   this->leftOffset = 0;
201   this->rightOffset = 0;
202 
203   return this;
204 }
205 
206 /*****************************************************************************/
207 
mib_find_name(mib_Widget * temp,char * name)208 mib_Widget *mib_find_name(mib_Widget *temp, char *name)
209 {
210   mib_Widget *child = temp->child;
211   mib_Widget *ret = NULL;
212 
213   if (!strcmp(temp->name, name))
214     return temp;
215 
216   if (child != NULL)
217     if ((ret = mib_find_name(child, name)))
218       return ret;
219 
220   child = temp->sibling;
221   if (child != NULL)
222     if ((ret = mib_find_name(child, name)))
223       return ret;
224 
225   return NULL;
226 }
227 
228 /*****************************************************************************/
229 
230 Widget
BuildMenu(Widget parent,int menu_type,char * menu_title,char menu_mnemonic,MenuItem * items)231 BuildMenu(Widget parent, int menu_type, char *menu_title, char menu_mnemonic,
232 	  MenuItem *items)
233 {
234   Widget menu, cascade = NULL, widget;
235   int i;
236   XmString str;
237 
238   if (menu_type == XmMENU_PULLDOWN || menu_type == XmMENU_OPTION)
239     menu = XmCreatePulldownMenu(parent, "_pulldown", NULL, 0);
240   else if (menu_type == XmMENU_POPUP)
241     menu = XmCreatePopupMenu(parent, "_popup", NULL, 0);
242   else {
243     XtWarning("Invalid menu type passed to BuildMenu()");
244     return NULL;
245   }
246 
247   /* Pulldown menus require a cascade button to be made */
248   if (menu_type == XmMENU_PULLDOWN) {
249     int i;
250     char bname[24];
251 
252     XtVaGetValues(parent, XmNnumChildren, &i, NULL);
253     sprintf(bname, "button_%d", i);
254     str = XmStringCreateSimple(menu_title);
255     cascade = XtVaCreateManagedWidget(bname,
256 				      xmCascadeButtonGadgetClass, parent,
257 				      XmNsubMenuId,   menu,
258 				      XmNlabelString, str,
259 				      XmNmnemonic,    (XID)menu_mnemonic,
260 				      NULL);
261     XmStringFree(str);
262   } else if (menu_type == XmMENU_OPTION) {
263     /* Option menus are a special case, but not hard to handle */
264     Arg args[2];
265     str = XmStringCreateSimple(menu_title);
266     XtSetArg(args[0], XmNsubMenuId, menu);
267     XtSetArg(args[1], XmNlabelString, str);
268     /* This really isn't a cascade, but this is the widget handle
269      * we're going to return at the end of the function.
270      */
271     cascade = XmCreateOptionMenu(parent, menu_title, args, 2);
272     XmStringFree(str);
273   }
274 
275   /* Now add the menu items */
276   for (i = 0; items[i].label != NULL; i++) {
277     /* If subitems exist, create the pull-right menu by calling this
278      * function recursively.  Since the function returns a cascade
279      * button, the widget returned is used..
280      */
281     if (items[i].subitems)
282       if (menu_type == XmMENU_OPTION) {
283 	widget = XtVaCreateManagedWidget(items[i].label,
284 					 *items[i].class, menu, NULL);
285 	items[i].subitems = (struct _menu_item *) widget;
286 	/* daeron mod (tm) :-) ... we now use this to pass back each
287 	   widget we create to the mibMenu functions so that it can
288 	   be stored as part of the mibMenu structure */
289 
290 	/* XtWarning("You can't have submenus from option menu items.");
291 	   continue;*/
292       } else
293 	widget = BuildMenu(menu, XmMENU_PULLDOWN,
294 			   items[i].label, items[i].mnemonic, items[i].subitems);
295     else
296       {
297 	widget = XtVaCreateManagedWidget(items[i].label,
298 					 *items[i].class, menu,
299 					 NULL);
300 	/* ditto here from above ... - Daeron mod (tm) */
301 	items[i].subitems = (struct _menu_item *) widget;
302       }
303 
304     /* Whether the item is a real item or a cascade button with a
305      * menu, it can still have a mnemonic.
306      */
307     if (items[i].mnemonic)
308       XtVaSetValues(widget, XmNmnemonic, (XID)items[i].mnemonic, NULL);
309 
310     /* any item can have an accelerator, except cascade menus. But,
311      * we don't worry about that; we know better in our declarations.
312      */
313     if (items[i].accelerator) {
314       str = XmStringCreateSimple(items[i].accel_text);
315       XtVaSetValues(widget,
316 		    XmNaccelerator, items[i].accelerator,
317 		    XmNacceleratorText, str,
318 		    NULL);
319       XmStringFree(str);
320     }
321 
322     if (items[i].callback)
323       XtAddCallback(widget,
324 		    (items[i].class == &xmToggleButtonWidgetClass ||
325 		     items[i].class == &xmToggleButtonGadgetClass)?
326                     XmNvalueChangedCallback : /* ToggleButton class */
327                     XmNactivateCallback,      /* PushButton class */
328 		    items[i].callback, items[i].callback_data);
329   }
330 
331   /* for popup menus, just return the menu; pulldown menus, return
332    * the cascade button; option menus, return the thing returned
333    * from XmCreateOptionMenu().  This isn't a menu, or a cascade button!
334    */
335   return menu_type == XmMENU_POPUP? menu : cascade;
336 }
337 
338 /*****************************************************************************/
339 
mib_load_interface(Widget parent,char * from,int file_type)340 mib_Widget *mib_load_interface(Widget parent, char *from, int file_type)
341 {
342   mib_Buffer  thisfile;
343   mib_Widget *this;
344   FILE	     *infile;
345   char	     *instring;
346   char	      ch;
347 
348   thisfile.buf_type = file_type;
349 
350   dpy = XtDisplay(parent);
351 
352   if ((file_type == MI_FROMFILE) || (file_type == MI_EDITFROMFILE))
353     {
354       if (!(infile = fopen(from,"r")))
355 	return NULL;
356 
357       ch = '\0';
358       while ((ch != '\n')&&(!feof(infile)))  /* throw away first line */
359 	ch = (char)fgetc(infile);
360 
361       thisfile.buffer = (void *)infile;
362       thisfile.point = 0;
363 
364       if (!mib_load_Root(parent, &this, &thisfile))
365 	{
366 	  /* delete this */
367 	  return NULL;
368 	}
369       else
370 	{
371 	  fclose(infile);
372 	  return this;
373 	}
374     }
375   else
376     if ((file_type == MI_FROMSTRING) || (file_type == MI_EDITFROMSTRING))
377       {
378 	instring = from;
379 	if (instring == NULL)
380 	  return NULL;
381 
382 	thisfile.buffer = (void *)instring;
383 	thisfile.buflen = strlen(instring);
384 	thisfile.point = 0;
385 
386 	if (!mib_load_Root(parent, &this, &thisfile))
387 	  {
388 	    /* delete this */
389 	    return NULL;
390 	  }
391 	else
392 	  return this;
393       }
394     else
395       return NULL;
396 
397 }
398 
399 /*****************************************************************************/
400 
mib_load_mib_class(mib_Widget ** this,mib_Widget * parent,char * name,char * iname,mib_Buffer * fin)401 int mib_load_mib_class(mib_Widget **this, mib_Widget *parent, char *name,
402 		       char *iname, mib_Buffer *fin )
403 {
404   int namelen, editstate, count;
405 
406   if ((fin->buf_type == MI_EDITFROMFILE) ||
407       (fin->buf_type == MI_EDITFROMSTRING))
408     editstate = WEDIT;
409   else
410     editstate = WEMPTY;
411 
412   namelen = strlen(name);
413   if (namelen < 2)
414     return 0;
415 
416   name[namelen-1] = '\0';
417   name[0] = ' ';
418 
419   count = 1;
420 
421   while (mwfuncs[count].name)
422     {
423       if (!strcmp(&(name[1]), mwfuncs[count].name))
424 	{
425 	  *this = mwfuncs[count].mib_create(parent, iname, NULL, 0, 0, 0, 0,
426 					    editstate);
427 	  return 1;
428 	}
429       count++;
430     }
431 
432   (*this)->parent = (*this);
433   return 1;
434 }
435 
436 /*****************************************************************************/
437 
mib_load_public(mib_Widget * root,mib_Widget * this,mib_Buffer * fin)438 mib_Widget *mib_load_public(mib_Widget *root, mib_Widget *this, mib_Buffer *fin)
439 {
440   int	got_line, done;
441   char	res[MI_MAXSTRLEN];
442   char	val[MI_MAXSTRLEN];
443   char	valcp[MI_MAXSTRLEN];
444   Arg	args[20];
445   int	mynum, n;
446 
447   got_line = 1;
448   done = 0;
449 
450   /* this loop reads basic info about Widget */
451   while (got_line && (!done))
452     {
453       got_line = mib_read_line(fin, res, val);
454       if (!strcmp(res,"Ref"))
455 	sscanf(val, "%d", &mynum);
456       else
457 	if (!strcmp(res,"Widget"))
458 	  {
459 	    strcpy(valcp,val);
460 	    done = 1;
461 	  }
462     }
463 
464   done = 0;
465 
466   while (got_line && (!done))
467     {
468       got_line = mib_read_line(fin, res, val);
469       if (!strcmp(res, "Children"))
470 	n = 0;
471       else
472 	if (!strcmp(res, "Parent")) /* don't support complete widget tree yet */
473 	  n = 0;
474 	else
475 	  if (!strcmp(res,"Public-"))
476 	    n = 0;
477 	  else
478 	    if (!strcmp(res,"Name"))
479 	      {
480 		val[strlen(val)-1] = '\0';
481 		mib_load_mib_class(&this, root, valcp, &(val[1]), fin);
482 		this->name = (char *)malloc(strlen(val));
483 		sprintf(this->name,"%s",&(val[1]));
484 		this->mib_mynum = mynum;
485 		done = 1;
486 	      }
487 	    else
488 	      return 0;
489     }
490 
491   if (!got_line)
492     return NULL;
493 
494   done = 0;
495 
496   /* second loop reads public info */
497   while (got_line && (!done))
498     {
499       got_line = mib_read_line(fin, res, val);
500       if (!strcmp(res,"Xmwidth"))
501 	sscanf(val,"%d",&(this->width));
502       else
503 	if (!strcmp(res,"Xmheight"))
504 	  sscanf(val,"%d",&(this->height));
505 	else
506 	  if (!strcmp(res,"XmtopAttachment"))
507 	    sscanf(val,"%d",&(this->topAttachment));
508 	  else
509 	    if (!strcmp(res,"XmbottomAttachment"))
510 	      sscanf(val,"%d",&(this->bottomAttachment));
511 	    else
512 	      if (!strcmp(res,"XmleftAttachment"))
513 		sscanf(val,"%d",&(this->leftAttachment));
514 	      else
515 		if (!strcmp(res,"XmrightAttachment"))
516 		  sscanf(val,"%d",&(this->rightAttachment));
517 		else
518 		  if (!strcmp(res,"XmtopOffset"))
519 		    sscanf(val,"%d",&(this->topOffset));
520 		  else
521 		    if (!strcmp(res,"XmbottomOffset"))
522 		      sscanf(val,"%d",&(this->bottomOffset));
523 		    else
524 		      if (!strcmp(res,"XmleftOffset"))
525 			sscanf(val,"%d",&(this->leftOffset));
526 		      else
527 			if (!strcmp(res,"XmrightOffset"))
528 			  sscanf(val,"%d",&(this->rightOffset));
529 			else
530 			  if (!strcmp(res,"Private-"))
531 			    done = 1;
532     }
533 
534   n = 0;
535   if ((fin->buf_type == MI_EDITFROMFILE) ||
536       (fin->buf_type == MI_EDITFROMSTRING))
537     {
538       XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
539       XtSetArg (args[n], XmNleftOffset, this->leftOffset); n++;
540       XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
541       XtSetArg (args[n], XmNtopOffset, this->topOffset); n++;
542       if (this == root)
543 	{
544 	  XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
545 	  XtSetArg (args[n], XmNrightOffset, this->rightOffset); n++;
546 	  XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
547 	  XtSetArg (args[n], XmNbottomOffset, this->bottomOffset); n++;
548 	}
549     }
550   else
551     {
552       if (this->leftAttachment)
553 	{
554 	  XtSetArg (args[n], XmNleftAttachment, this->leftAttachment); n++;
555 	  if(this->leftAttachment == XmATTACH_FORM)
556 	    XtSetArg (args[n], XmNleftOffset, this->leftOffset);
557 	  else
558 	    XtSetArg (args[n], XmNleftPosition, this->leftOffset*100/root->width);
559 	  n++;
560 	}
561       if (this->topAttachment)
562 	{
563 	  XtSetArg (args[n], XmNtopAttachment, this->topAttachment); n++;
564 	  if(this->topAttachment == XmATTACH_FORM)
565 	    XtSetArg (args[n], XmNtopOffset, this->topOffset);
566 	  else
567 	    XtSetArg (args[n], XmNtopPosition, this->topOffset*100/root->height);
568 	  n++;
569 	}
570       if (this->bottomAttachment)
571 	{
572 	  XtSetArg (args[n], XmNbottomAttachment, this->bottomAttachment); n++;
573 	  if(this->bottomAttachment == XmATTACH_FORM)
574 	    XtSetArg (args[n], XmNbottomOffset, this->bottomOffset);
575 	  else
576 	    XtSetArg (args[n], XmNbottomPosition, 100-this->bottomOffset*100/root->height);
577 	  n++;
578 	}
579       if (this->rightAttachment)
580 	{
581 	  XtSetArg (args[n], XmNrightAttachment, this->rightAttachment); n++;
582 	  if(this->rightAttachment == XmATTACH_FORM)
583 	    XtSetArg (args[n], XmNrightOffset, this->rightOffset);
584 	  else
585 	    XtSetArg (args[n], XmNrightPosition, 100-this->rightOffset*100/root->width);
586 	  n++;
587 	}
588     }
589 
590   /* Do not set the width or height, if zero.
591      The core widget will compute appropriately. */
592   if ( this->width ) {
593     XtSetArg (args[n], XmNwidth, this->width); n++;
594   }
595   if ( this->height ) {
596     XtSetArg (args[n], XmNheight, this->height); n++;
597   }
598 
599   XtSetValues(this->me, args, n);
600 
601   return this;
602 }
603 
604 /*****************************************************************************/
605 
mib_load_private(mib_Widget * this,mib_Buffer * fin)606 int mib_load_private(mib_Widget *this, mib_Buffer *fin)
607 {
608 
609   if (this->mib_class_num == MIB_NULL)
610     return 1;
611 
612   if ((this->mib_class_num < 1) || (this->mib_class_num > MI_NUMCLASSES))
613     return 0;
614 
615   mwfuncs[this->mib_class_num].mib_load(this, fin);
616 
617   return 1;
618 }
619 
620 /*****************************************************************************/
621 
mib_load_Root(Widget parent,mib_Widget ** this,mib_Buffer * fin)622 int mib_load_Root(Widget parent, mib_Widget **this, mib_Buffer *fin)
623 {
624 
625   char		res[MI_MAXSTRLEN];
626   char		val[MI_MAXSTRLEN];
627   int		num_widgets, count;
628   Arg		args[20];
629   XGCValues     gcvals;
630   XtGCMask      val_mask;
631   mib_Widget   *temp = NULL;
632   int		rubberPositioning = False;
633 
634   mib_read_line(fin, res, val);
635   if (!strcmp(res,"TotalWidgets"))
636     sscanf(val, "%d", &num_widgets);
637   else
638     return 0;
639 
640   (*this) = mib_new_mib_Widget();
641   (*this)->mib_class = (char*)malloc(9);
642   sprintf((*this)->mib_class,"RootForm");
643 
644   XtVaGetValues(parent, XmNrubberPositioning, &rubberPositioning, NULL);
645 
646   (*this)->me = XmCreateForm(parent, "MainForm", args, 0);
647   if (!mib_load_public((*this), (*this), fin))
648     return 0;
649 
650   /* we don't expect any private resources for the root widget */
651 
652   mib_read_line(fin, res, val);
653   if (strcmp(res,"EndWidget."))
654     return 0;
655 
656   XtManageChild((*this)->me);
657   XtVaSetValues((*this)->me, XmNresizePolicy, XmRESIZE_NONE,
658 		XmNrubberPositioning, rubberPositioning,
659 		XmNresizable, rubberPositioning, NULL);
660 
661   count = num_widgets - 1;
662   while (count > 0)
663     {
664 
665       if (!(temp = mib_load_public((*this), temp, fin)))
666 	{
667 	  /* delete temp */
668 	  return 0;
669 	}
670 
671       if (!mib_load_private(temp,fin))
672 	{
673 	  /* delete temp */
674 	  return 0;
675 	}
676       count--;
677 
678     }
679 
680   mib_reset_size((*this));
681 
682   XtVaSetValues((*this)->me, XmNresizePolicy, XmRESIZE_ANY, NULL);
683 
684   val_mask = (long)0;
685   mib_gc = XtGetGC((*this)->me, val_mask, &gcvals);
686 
687   return 1;
688 }
689 
690 /*****************************************************************************/
691 
mib_read_line(mib_Buffer * bufin,char * res,char * val)692 int mib_read_line(mib_Buffer *bufin, char *res, char *val)
693 {
694   FILE *fin;
695   char *strin;
696   char  ch;
697   int   count, mark;
698   char  inbuf[MI_MAXSTRLEN];
699 
700   if ((bufin->buf_type == MI_FROMFILE) || (bufin->buf_type == MI_EDITFROMFILE))
701     {
702       fin = (FILE *)bufin->buffer;
703       ch = '\0';
704       count = 0;
705       mark = 0;
706       while ((ch != '\n')&&(!feof(fin))&&(count<MI_MAXSTRLEN))
707 	{
708 	  ch = (char)fgetc(fin);
709 	  if ((mark == 0) && (ch == ':'))
710 	    mark = count;
711 	  if ((ch != '\\')&&(ch != '\n'))
712 	    {
713 	      inbuf[count] = ch;
714 	      count++;
715 	    }
716 	}
717       if (feof(fin))
718 	return 0;
719       inbuf[count] = '\0';
720       if (count > 0)
721 	{
722 	  if (inbuf[count-1] == 'n')
723 	    inbuf[count-1] = '\0';
724 	}
725       else
726 	return 0;
727 
728     }
729   else
730     if ((bufin->buf_type == MI_FROMSTRING) ||
731 	(bufin->buf_type == MI_EDITFROMSTRING))
732       {
733 	strin = (char *)bufin->buffer;
734 	count = bufin->point;
735 	mark = 0;
736 
737 	if (count >= bufin->buflen)
738 	  return 0;
739 
740 	while ((strin[count] != '\n') && (count < bufin->buflen))
741 	  {
742 	    if ((mark == 0) && (strin[count] == ':'))
743 	      mark = count;
744 	    count++;
745 	  }
746 
747 	strin[count] = '\0';
748 	if (count >= bufin->buflen)
749 	  return 0;
750 	sprintf(inbuf,"%s",&(strin[bufin->point]));
751 	strin[count] = '\n';
752 	if (mark != 0)
753 	  mark -= bufin->point;
754 	bufin->point = count+1;
755       }
756     else
757       return 0;
758 
759   if (mark == 0)
760     {
761       sprintf(res,"%s",inbuf);
762 #if 0
763       sprintf(val,"\0"); /* ???? */
764 #else
765       val[0] = '\0';
766       val[1] = '\0';
767 #endif
768     }
769   else
770     {
771       inbuf[mark] = '\0';
772       sprintf(res,"%s",inbuf);
773       inbuf[mark] = ' ';
774       if (strlen(inbuf)-mark > 1)
775 	sprintf(val,"%s",&(inbuf[mark+2]));
776       else
777 #if 0
778 	sprintf(val,"\0");
779 #else
780       {
781 	val[0] = '\0';
782 	val[1] = '\0';
783       }
784 #endif
785     }
786 
787   return 1;
788 }
789 
790 /*****************************************************************************/
791 
mib_reset_size(mib_Widget * temp)792 void mib_reset_size(mib_Widget *temp)
793 {
794   Arg	args[5];
795   int	n;
796 
797   mib_Widget *child = temp->child;
798 
799   if (temp->mib_class_num != MIB_NULL)
800     {
801       n = 0;
802 
803       /* Do not set the width or height, if zero.
804 	 The core widget will compute appropriately. */
805       if (temp->width) {
806 	XtSetArg (args[n], XmNwidth, temp->width); n++;
807       }
808       if (temp->height) {
809 	XtSetArg (args[n], XmNheight, temp->height); n++;
810       }
811 
812       XtSetValues(temp->me, args, n);
813     }
814 
815   if (child != NULL)
816     mib_reset_size(child);
817 
818   child = temp->sibling;
819   if (child != NULL)
820     mib_reset_size(child);
821 }
822 
823 /*****************************************************************************/
824 
mib_set_eventhandlers(void (* a)(),void (* b)(),void (* c)())825 void mib_set_eventhandlers(void (*a)(), void (*b)(), void (*c)())
826 {
827   mib_events.mib_pick_mib_Widget = (void (*)())a;
828   mib_events.mib_move_mib_Widget = (void (*)())b;
829   mib_events.mib_unpick_mib_Widget = (void (*)())c;
830 }
831 
832 /*****************************************************************************/
833 
mib_apply_eventhandlers(Widget this,mib_Widget * actual)834 void mib_apply_eventhandlers(Widget this, mib_Widget *actual)
835 {
836   XtAddEventHandler(this, ButtonPressMask, FALSE,
837 		    mib_events.mib_pick_mib_Widget, (XtPointer)actual);
838   XtAddEventHandler(this, Button3MotionMask, FALSE,
839 		    mib_events.mib_move_mib_Widget, (XtPointer)actual);
840   XtAddEventHandler(this, ButtonReleaseMask, FALSE,
841 		    mib_events.mib_unpick_mib_Widget, (XtPointer)actual);
842 
843 }
844 
845 /*****************************************************************************/
846 
847 /*
848  * Local Variables: ***
849  * mode: c ***
850  * c-basic-offset: 2 ***
851  * End: ***
852  */
853