home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibButton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  3.5 KB  |  161 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display        *dpy;
  5. extern GC         mib_gc;
  6.  
  7. /* Code for Button */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_Button(mib_Widget *parent, char *name, char *label,
  11.         int posx, int posy, int width, int height, int mib_fill)
  12. {
  13.   mib_Widget *temp;
  14.   mib_Button *myres;
  15.   unsigned char *label_text;
  16.   Arg     args[20];
  17.   int     n;
  18.  
  19.   /* create the new widget and add it to the tree */
  20.  
  21.   temp = mib_new_mib_Widget();
  22.   if (mib_fill == WDEFAULT)
  23.     mib_add_backward(temp, parent);
  24.   else
  25.     mib_add_mib_Widget(temp, parent);
  26.   myres = (mib_Button *)malloc(sizeof(mib_Button));
  27.  
  28.   /* initialize public resources */
  29.  
  30.   if (mib_fill == WDEFAULT)
  31.   {
  32.     temp->name = (char *)malloc(strlen(name)+1);
  33.     strcpy(temp->name,name);
  34.   }
  35.   temp->mib_class = (char *)malloc(7);
  36.   sprintf(temp->mib_class,"Button");
  37.   temp->mib_class_num = MIB_BUTTON;
  38.   temp->width = width;
  39.   temp->height = height;
  40.   temp->topOffset = posy;
  41.   temp->leftOffset = posx;
  42.   temp->bottomOffset = 0;
  43.   temp->rightOffset = 0;
  44.   temp->topAttachment = 1;
  45.   temp->leftAttachment = 1;
  46.   temp->bottomAttachment = 0;
  47.   temp->rightAttachment = 0;
  48.  
  49.   temp->mib_allowresize = 1;
  50.  
  51.   /* initialize private resources */
  52.  
  53.   temp->myres = (void *)myres;
  54.  
  55.   if (mib_fill == WDEFAULT)
  56.   {
  57.     myres->label = (char *)malloc(strlen(label)+1);
  58.     strcpy(myres->label,label);
  59.   }
  60.  
  61.   /* create Xt widget */
  62.  
  63.   n = 0;
  64.  
  65.   if (mib_fill == WDEFAULT)
  66.   {
  67.     label_text = XmStringCreateLtoR(label, XmSTRING_DEFAULT_CHARSET);
  68.  
  69.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  70.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  71.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  72.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  73.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  74.     XtSetArg (args[n], XmNwidth, width); n++;
  75.     XtSetArg (args[n], XmNheight, height); n++;
  76.   }
  77.  
  78.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  79.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  80.  
  81.   temp->me = XtCreateManagedWidget(name, xmPushButtonWidgetClass,
  82.                 temp->parent->me, args, n);
  83.  
  84.   if (mib_fill == WDEFAULT)
  85.   {
  86.     XmStringFree(label_text);
  87.   }
  88.  
  89.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  90.   {
  91.     mib_apply_eventhandlers(temp->me, temp);
  92.   }
  93.  
  94.   return temp;
  95. }
  96.  
  97. void mib_delete_Button(mib_Widget *this)
  98. {
  99.   mib_Button *temp = (mib_Button *)this->myres;
  100.  
  101.   free(temp->label);
  102.   free(temp);
  103. }
  104.  
  105. void mib_save_Button(mib_Widget *this, FILE *fout)
  106. {
  107.   mib_Button *temp = (mib_Button *)this->myres;
  108.  
  109.   fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->label);
  110. }
  111.  
  112. void mib_code_gen_Button(mib_Widget *this, FILE *fout)
  113. {
  114. }
  115.  
  116. int mib_load_Button(mib_Widget *this, mib_Buffer *fin)
  117. {
  118.   mib_Button    *myres;
  119.   unsigned char *label_text;
  120.   char          res[MI_MAXSTRLEN];
  121.   char          val[MI_MAXSTRLEN];
  122.   Arg        args[20];
  123.   int        n, got_line, vallen;
  124.  
  125.   myres = (mib_Button *)this->myres;
  126.  
  127.   got_line = mib_read_line(fin, res, val);
  128.   if (!got_line)
  129.     return 0;
  130.  
  131.   if (!strcmp(res,"label"))
  132.   {
  133.     vallen = strlen(val);
  134.     if (vallen < 2)
  135.       return 0;
  136.     val[vallen-1] = '\0';
  137.     myres->label = (char *)malloc(vallen-1);
  138.     sprintf(myres->label,"%s",&(val[1]));
  139.  
  140.     label_text = XmStringCreateLtoR(myres->label, XmSTRING_DEFAULT_CHARSET);
  141.  
  142.     n = 0;
  143.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  144.     XtSetValues(this->me, args, n);
  145.  
  146.     XmStringFree(label_text);
  147.  
  148.   }
  149.   else
  150.     return 0;
  151.  
  152.   got_line = mib_read_line(fin, res, val);
  153.   if (!got_line)
  154.     return 0;
  155.  
  156.   if (strcmp(res,"EndWidget"))
  157.     return 0;
  158.  
  159.   return 1;
  160. }
  161.