
#include "generalP.h"
#include "general.h"

char *gensym()
 {
   char *str;
   int places;
   float n;

   /* Generate a unique symbol (string) for internal Widget Builder use */
   /* ----------------------------------------------------------------- */
   n = WBgensymValue + 1;
   for (places = 1; n > 1; places++)
     n = n / 10.0;
   /* Generate a unique widget name */
   str = (char *) calloc((strlen("WBwidget") + places + 3), 1);
   sprintf(str, "WBwidget%d%c", WBgensymValue++, '\0');
   return(str);

 };       /* end of gensym() */

/****************************************************************/

void documentation_line(msg)
     char msg[];
 { 
   extern Widget documentation_line_widget;
   int i, msg_len;

   /* Display a line of documentation at the bottom */
   /* of the Widget Builder window                  */
   /* --------------------------------------------- */
   msg_len = strlen(msg);
   for (i = 0; i < MAX_DOCUMENTATION_LINE_LENGTH; i++)
     { if (i >= msg_len)
	 documentation_string[i] = ' ';
       else
	 documentation_string[i] = msg[i];
     };
   documentation_string[MAX_DOCUMENTATION_LINE_LENGTH] = '\0';
   XtSetArg(arg_list[0], XtNlabel, documentation_string);
   XtSetValues(documentation_line_widget, arg_list, 1);

 };         /* end of documentation_line() */

/****************************************************************/

void make_widget_movable(widget, parent)
     Widget widget, parent;
 {
   char *str;

   str = (char *) calloc((
	strlen("<Btn3Down>: StartMoving(\"\") \n\
<Btn3Motion>: WidgetMover(\"\")  \n<Btn3Up>: DoneMoving(\"\")")
		+ 1 + 130) , 1);  

   /* make translation table string */
   sprintf(str, "<Btn3Down>: StartMoving(\"%d\") \n\
<Btn3Motion>: WidgetMover(\"%d\") \n<Btn3Up>: DoneMoving(\"%d\")%c",
	   (int) parent, (int) parent, (int) parent, '\0');
   XtOverrideTranslations(widget, 
			  XtParseTranslationTable(str));
 };

/****************************************************************/

void make_widget_resizable(widget, parent)
     Widget widget, parent;
 {
   char *str;

   str = (char *) calloc((
	strlen("<Btn2Down>: StartResizing(\"\") \n\
<Btn2Motion>: WidgetSizer(\"\")  \n<Btn2Up>: DoneSizing(\"\")")
		+ 1 + 130) , 1);  

   /* make translation table string */
   sprintf(str, 
           "<Btn2Down>: StartResizing(\"%d\") \n\
<Btn2Motion>: WidgetSizer(\"%d\") \n<Btn2Up>: DoneSizing(\"%d\")%c",
	   (int) parent, (int) parent, (int) parent, '\0');
   XtOverrideTranslations(widget, 
			  XtParseTranslationTable(str));
 };

/****************************************************************/

void make_widget_debugable(widget, parent)
     Widget widget, parent;
 {
   char *str;

   str = (char *) calloc((
             strlen("<Btn1Down>: MyDebug()\n") + 2), 1);

   /* make translation table string */
   sprintf(str, "<Btn1Down>: MyDebug()\n%c", '\0');  /* double-click left */
   XtOverrideTranslations(widget, 
			  XtParseTranslationTable(str));
 };

/****************************************************************/

void inverseVideo(widget)
     Widget widget;
 {
   Pixel foreground;
   Pixel background;
   Arg arg_list[2];

   /* Swap the Pixel coloring of the foreground and background */
   /* -------------------------------------------------------- */
   arg_list[0].name = XtNforeground;
   arg_list[0].value = (XtArgVal) &foreground;
   arg_list[1].name = XtNbackground;
   arg_list[1].value = (XtArgVal) &background;
   XtGetValues(widget, arg_list, 2);
   arg_list[0].name = XtNforeground;
   arg_list[0].value = (XtArgVal) background;
   arg_list[1].name = XtNbackground;
   arg_list[1].value = (XtArgVal) foreground;
   XtSetValues(widget, arg_list, 2);
 };        /* end of inverseVideo() */

/****************************************************************/
