/* Copyright (C) 1992 by Gustaf Neumann, Stefan Nusser

 *      Wirtschaftsuniversitaet Wien, 
 *      Abteilung fuer Wirtschaftsinformatik
 *      Augasse 2-6, 
 *      A-1090 Vienna, Austria
 *      neumann@wu-wien.ac.at, nusser@wu-wien.ac.at

 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appears in all copies and that both that
 * copyright notice and this permission notice appear in all supporting
 * documentation.  This software is provided "as is" without expressed or
 * implied warranty.

 * Creation: Sun Jun  5 18:37:58 GMT 1994 on mohegan
 * Author: genc
 * Version: 0.96999999999999997335


 */
#define XT

#define XT_C
#include <wafe.h>
#ifdef XT

#include <X11/Shell.h>
#include <X11/Xatom.h>

 XrmQuark qbusyWindow;
/* 
 * ******* begin required file <Xt.inc> *******
 */
/* das ist ein -*- C -*- Programm */
#include <X11/cursorfont.h>

#ifdef MOTIF11
#include <Xm/Xm.h>
#endif

#ifdef RDD
extern Boolean rddDeliverMessageEvent(
#if NeedFunctionPrototypes
    XEvent
#endif
);
#endif

extern Boolean wafeOwnSelectionCmd(
#if NeedFunctionPrototypes
     String, String, String
#endif
);

extern void callback (
#if NeedFunctionPrototypes
     Widget, char *, XtCallbackProc, char *
#endif
);

extern Cardinal wafeGetResourcesOfClass(
#if NeedFunctionPrototypes
     WidgetClass, QTypeList *
#endif
);

extern Cardinal wafeGetConstraintsOfClass(
#if NeedFunctionPrototypes
     WidgetClass, QTypeList *
#endif
);

extern void wafeCallbackCmd(
#if NeedFunctionPrototypes
     Widget, String, XtCallbackProc, String
#endif
);

#ifdef ATHENA
#include <X11/Xaw/List.h>
#endif


static void
action(w, TranslationModifier, translationTable)
Widget	w;
int	TranslationModifier;
XtTranslations translationTable;
    {
    switch (TranslationModifier) 
        {
	case 1: XtOverrideTranslations(w, translationTable);
		break;
	case 2: XtAugmentTranslations(w, translationTable);
		break;
	case 3: XtVaSetValues (w, XtNtranslations, translationTable, NULL);
		break;
        }
    }


static void
realizeWidgets()
    {
    WidgetListPtr ptr = wafeWidgetTrees;
    while(ptr) 
	{
	XtRealizeWidget(ptr->widget);
	ptr = ptr->next;
	}
    }

static void
callCallbacks(w, callback, argc,argv)
Widget   w;
String   callback;
int      argc;
char   **argv;
    {
    float   f;
    if (argc == 0)
	XtCallCallbacks(w, callback, NULL);
    else
	{
	if (!strcmp(argv[0], "float"))
	    {
	    sscanf(argv[1], "%f", &f);
	    XtCallCallbacks(w, callback, (XtPointer)&f);
	    }
	else
	    {
	    fprintf(stderr, "Wafe(callCallbacks): Wrong type: %s\n", argv[1]);
	    }
	}
    }


static void
callActionProc(w, eventType, action, argc, argv)
Widget         w;
String         eventType;
String         action;
int            argc;
char         **argv;
    {
    char          *token;
    XEvent         event;
    Display       *display;
    Window         win, root, child;
    int            x, y, xR, yR;
    unsigned int   state, button, keycode;

    display = XtDisplay(wafeTopLevel);
    win = XtWindow(w);

    if (!strcmp(eventType, ""))
	{
	event.type = 0;
	event.xany.display = display;
	event.xany.window = win;
	}
    else
	{
	token = strtok(eventType, " ");
	if (strcmp(token, "type"))
	    {
	    fprintf(stderr, 
		    "Wafe(callActionProc): Missing type, aborting\n");
	    return;
	    }

	XQueryPointer(display, win, &root, &child, &xR, &yR, &x, &y, &state);

	token = strtok(NULL, " ");
	if (!strcmp(token, "buttonEvent"))
	    {
	    token = strtok(NULL, " ");
	    if (!strcmp(token, "button"))
		{
		token = strtok(NULL, " ");
		if (!strcmp(token, "button1"))
		    button = Button1;
		else
                if (!strcmp(token, "button2"))
		    button = Button2;
                else
                if (!strcmp(token, "button3"))
		    button = Button3;
		else
                if (!strcmp(token, "button4"))
		    button = Button4;
		else
                if (!strcmp(token, "button5"))
		    button = Button5;
		else
		    {
		    fprintf(stderr, 
			    "Wafe(callActionProc): Unknown Button, %s\n", 
			    token);
		    return;
		    }
		}
	    else
		{
		fprintf(stderr, 
			"Wafe(callActionProc): This event field (%s) can't be specified\n", token);
		return;
		}

	    event.type = ButtonPress;
	    event.xbutton.display = display;
	    event.xbutton.window = win;
	    event.xbutton.root = root;
	    event.xbutton.subwindow = child;
	    event.xbutton.x = x;
	    event.xbutton.y = y;
	    event.xbutton.x_root = xR;
	    event.xbutton.y_root = yR;
	    event.xbutton.state = state;
	    event.xbutton.button = button;
	    }
	else if(!strcmp(token, "keyEvent"))
	    {
	    token = strtok(NULL, " ");
	    if (!strcmp(token, "key"))
		{                   
		token = strtok(NULL, " ");
		keycode = XKeysymToKeycode(display, XStringToKeysym(token));
		}
	    else
		{
		fprintf(stderr, "Wafe(callActionProc): This event field (%s) can't be specified", token);
		return;
		}

	    event.type = KeyPress;
	    event.xkey.display = display;
	    event.xkey.window = win;
	    event.xkey.root = root;
	    event.xkey.subwindow = child;
	    event.xkey.x = x;
	    event.xkey.y = y;
	    event.xkey.x_root = xR;
	    event.xkey.y_root = yR;
	    event.xkey.state = state;
	    event.xkey.keycode = keycode;
	    }
	else
	    {
	    fprintf(stderr, 
		    "Wafe(callActionProc): This event type can't be specified\n");
	    return;
	    }                    
	}

    XtCallActionProc(w, action, &event, argv, argc);
    return;
    }

/* used by addTimeOut */
static void
timerProc(command, junk)
XtPointer        command;
XtIntervalId     *junk;
    {
    DBUG_ENTER("timerProc");
    (void) wafeEval(wafeInterpreter, (char *)command, "timerProc");
    XtFree((char *)command);
    DBUG_VOID_RETURN;
    }

/* used by addTimeOut */
static Boolean
workProc(command)
XtPointer command;
    {
    char *r;
    int  rc;

    DBUG_ENTER("workProc");
    rc = wafeEval(wafeInterpreter, (char *)command, "workProc");
    r = wafeInterpreter->result;
    if ( rc || ( r && *r++ == '1' && *r == '\0' ) ) /* don't do it again */
	{
	XtFree((char *)command);
	DBUG_RETURN(True);
	}
    DBUG_RETURN(False);
    }


static char *
cvtToString(clientData, quarkOfType, freeProcPtr)
XtPointer     clientData;
XrmQuark      quarkOfType;
freeProc      *freeProcPtr;
    {
    XrmValue   input,output;
    
    DBUG_PRINT("cvtToString", ("Converting to <%s>", 
			       XrmQuarkToString(quarkOfType)));

    input.addr  =  clientData;            /* ??? */
    input.size  =  sizeof(XtPointer);     /* ??? */
    output.addr =  NULL;

    IFCONVERTANDSTORE(wafeTopLevel, 
		      XrmQuarkToString(quarkOfType),input, 
		      "String", output)
	{
	*freeProcPtr = XtFree;
	return output.addr;
	}
    else
	return NULL;
    }



static String
getValue(w, Qname, freeProcPtr)
Widget        w;
XrmQuark      Qname;
freeProc     *freeProcPtr;
    {
    char      *result;
    XrmQuark   Qtype;
    XtPointer  value;
    Arg        arg;

    DBUG_PRINT("getValue", ("widget is %p resource is <%s>",
			    w,XrmQuarkToString(Qname))); 

    if (!(Qtype = wafeGetQTypeOfAttribute(XtClass(w), ParentWidget(w), Qname)))
	{
	fprintf(stderr, "Wafe(getValues): Unknown Attribute %s\n",
		XrmQuarkToString(Qname));
	*freeProcPtr = TCL_STATIC;
	return NULL;
	}

    if (Qtype == qString)
	{
	String    valueString;
	*freeProcPtr = TCL_VOLATILE;
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueString, NULL);
	return valueString;
	}

    /* this is the Default value for the following types 
     * assuming that dense code is better than one instruction more
     */ 
    *freeProcPtr = XtFree;
	
    if (Qtype == qInt) 
	{
	int valueInt;
	result = XtMalloc(INT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueInt, NULL);
	sprintf(result, "%d", (int)valueInt);
	return result;
	}

    if (Qtype == qPosition
#ifdef MOTIF11
	|| Qtype == qVerticalPosition
	|| Qtype == qHorizontalPosition
#endif
       )
	{
	Position    valuePosition;
	result = XtMalloc(INT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valuePosition, NULL);
	sprintf(result, "%hd", valuePosition);
	return result;
        }
#ifdef MOTIF11
    if (Qtype == qTextPosition) 
	{
	XmTextPosition    valuePosition;
	result = XtMalloc(INT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valuePosition, NULL);
	sprintf(result, "%ld", valuePosition);
	return result;
        }
#endif

    if (Qtype == qDimension
#ifdef MOTIF11
	|| Qtype == qVerticalDimension
	|| Qtype == qHorizontalDimension
#endif
	) 
	{
	Dimension    valueDimension;
	result = XtMalloc(INT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueDimension, NULL);
	sprintf(result, "%hu", valueDimension);
	return result;
        }

    if (Qtype == qCardinal)
	{
	Cardinal    valueCardinal;
	result = XtMalloc(INT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueCardinal, NULL);
	sprintf(result, "%u", valueCardinal);	
	return result;
	}

    if (Qtype == qBoolean)
	{
	Boolean    valueBoolean;
	*freeProcPtr = TCL_STATIC;
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueBoolean, NULL);
	return valueBoolean ? "true" : "false";   
	}


    if (Qtype == qFloat) 
	{
	float    valueFloat;
	result = XtMalloc(FLOAT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueFloat, NULL);
	sprintf(result, "%f", valueFloat);
	return result;
	}

    if (Qtype == qDouble) 
	{
	double    valueDouble;
	result = XtMalloc(FLOAT_AS_STRING);
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueDouble, NULL);
	sprintf(result, "%f", valueDouble);
	return result;
	}

    if (Qtype == qPixel) 
	{
	XColor  c;
	Display *dpy = XtDisplay(w);
	result = XtMalloc(8); /* "#RRGGBB" */
	XtVaGetValues(w, XrmQuarkToString(Qname), &(c.pixel), NULL);
	XQueryColor(dpy,DefaultColormap(dpy, DefaultScreen(dpy)),&c);
	sprintf(result, "#%02X%02X%02X", 
		(int)(c.red>>8), (int)(c.green>>8), (int)(c.blue>>8));
	return result;
	}

     /* Callbacks sind ... anders: die String-Information 
	kommt aus wafe's privatem Memory-Management und nicht 
	über getValues!
      */
    if (Qtype == qCallback) 
	{
	MMattribListPtr ptr = *wafeMMgetAttribList(w,True);
	
	*freeProcPtr = TCL_STATIC;
	result = "";
	while(ptr) 
	    {
	    if (ptr->attribute == Qname) 
		{
		result = ((char*)ptr->value) +
		    sizeof(XtCallbackList)*2 +
		    sizeof(XtCallbackRec[2]) +
		    sizeof(XrmQuark);
		break;
		}
	    ptr = ptr->next;
	    }
	return result;
	}

    if (Qtype == qWidget
#ifdef MOTIF11
	|| Qtype == qWindow
#endif
	)
	{
	Widget valueWidget;
	*freeProcPtr = TCL_STATIC;
	XtVaGetValues(w, XrmQuarkToString(Qname), &valueWidget, NULL);
	return widget2Name(valueWidget);
	}

    if (Qtype == qWidgetList) 
        {
	WidgetList children;
        Cardinal   numChildren;
        XtVaGetValues(w, XtNnumChildren, &numChildren,
                         XtNchildren,    &children,    NULL);
	return wafeCvtWidgetListToList(NULL, numChildren, children);
        }

#ifdef ATHENA
    if ((Qtype == qPointer) && (XtClass(w) == listWidgetClass))
        {
	char **argv;
	int argc;

        XtVaGetValues(w, XtNnumberStrings, &argc,
                         XtNlist,          &argv,    NULL);
	return Tcl_Merge(argc, argv);
        }
#endif

    else 
	{
	  /*
	   * warning: cvtToString assumes, you can free the result 
	   * using XtFree
	   */
	XtSetArg(arg, XrmQuarkToString(Qname), &value);
	XtGetValues(w, &arg, (Cardinal)1);

	if (!(result = cvtToString(value, Qtype, freeProcPtr)))
	  {
	    fprintf(stderr, "Wafe(getValues): Couldn't convert value\n");
	    return NULL;
	  }
	return result;
      }
    }

static int
getResourceList(w, resultPtr)
char    ***resultPtr; 
Widget   w;
    {
    int numTotal, count;
    char **result;
    int rNum = 0;
    int cNum = 0;
    QTypeList rList, cList;

    rNum = wafeGetResourcesOfClass(XtClass(w), &rList);

    if (XtIsConstraint(ParentWidget(w)))   /* If parentWidget is constrain widget => fetch constraints */
	cNum =  wafeGetConstraintsOfClass(XtClass(ParentWidget(w)), &cList);

    numTotal = rNum + cNum;

    *resultPtr = result = (char **)XtMalloc(numTotal *sizeof(char *));       

    for ( count = 0; count < rNum; count++)
	*result++ = XrmQuarkToString(rList[count].qName);

    for ( count = 0; count < cNum; count++)
	*result++ = XrmQuarkToString(cList[count].qName);

    return(numTotal);
    }



typedef struct _busyStruct
    {
    Window                busyWindow;
    Boolean               state;
    } busyStruct, *busyStructPtr;


static void
setBusy(w,sensitive)
Widget w;
Boolean sensitive;
    {
    unsigned long valuemask;
    XSetWindowAttributes attributes;
    MMattribListPtr *al = wafeMMgetAttribList(w,True);
    busyStructPtr bs = (busyStructPtr) wafeMMgetValue(al, qbusyWindow);
    Display *dpy = XtDisplay(w);

    if (sensitive)
	{
	if (!bs)
	    {
	    bs = (busyStructPtr) XtMalloc(sizeof(busyStruct));
	    wafeMMreplace(al,qbusyWindow,(char*)bs,XtFree);
            bs->state = False;

	    /* Ignore device events while the busy cursor is displayed. */
	    valuemask = CWDontPropagate | CWCursor;
	    attributes.do_not_propagate_mask =  (KeyPressMask | KeyReleaseMask |
						 ButtonPressMask | ButtonReleaseMask | 
						 PointerMotionMask);
	    attributes.cursor = XCreateFontCursor(dpy, XC_watch);

	  /* The window will be as big as the display screen, and clipped by
	   * its own parent window, so we never have to worry about resizing
	   */

	    bs->busyWindow = XCreateWindow(dpy, XtWindow(w), 0, 0,
					   HeightOfScreen(XtScreen(w))*2, 
					   WidthOfScreen(XtScreen(w))*2, 
					   (unsigned int) 0, 0, InputOnly,
					   CopyFromParent, valuemask, 
					   &attributes);
	    }
	if (!bs->state) 
	     {
	     XMapRaised(dpy, bs->busyWindow);
	     bs->state = True;
	     }
        }
    else
	{
	if (bs && bs->state)
	    {
	    XUnmapWindow(dpy, bs->busyWindow);
	    bs->state = False;
	    }
	}
    }


static String
waitForVariable(varName)
String varName;
    {
    String result = NULL;
    Tcl_UnsetVar(wafeInterpreter,varName,TCL_GLOBAL_ONLY);
    wafeInnerEventLoop ++;
    while (!(result = Tcl_GetVar(wafeInterpreter,varName,TCL_GLOBAL_ONLY)))
	XtAppProcessEvent(wafeAppContext, XtIMAll);
    wafeInnerEventLoop --;
    return result;
    }

typedef struct {
    String  result;
  } ApplData, *ApplDataPtr;

static ApplData   applData;
static XtResource applResources[] = 
    {
	{
	NULL,                            /* resource_name   */
	NULL,                            /* resource_class  */
	XtRString,                       /* resource_type   */
	sizeof(String),                  /* resource_size   */
	XtOffset(ApplDataPtr, result),   /* resource_offset */
	XtRImmediate,                    /* default_type    */
	"",                              /* default_addr    */
	}
     };


static String
getApplicationResource(w, nameString, classString)
Widget w;
String nameString;
String classString;
    {
    XtResource *res = (XtResource *)XtMalloc(sizeof(XtResource));
    memcpy(res,applResources,sizeof(XtResource));
       
    res->resource_name  = nameString;
    res->resource_class = classString;
    XtVaGetApplicationResources(w, &applData, res,
				XtNumber(applResources), NULL);
    XtFree((char *) res);
     
    return applData.result;
    }


static void
processPendingEvents()
    {
    while (XtAppPending(wafeAppContext))
       {
       XEvent event;
       XtAppNextEvent(wafeAppContext,&event);
#ifdef RDD
       if (rddDeliverMessageEvent(event))
	   continue;
#endif
       wafeInnerEventLoop ++;
       XtDispatchEvent(&event);
       wafeInnerEventLoop --;
       }
    }

typedef int MapState;

static MapState
mapState(w)
Widget w;
    {
    XWindowAttributes wattr;
    Window win = XtWindow(w);
    
    if (!win) return 0;
    if (!XGetWindowAttributes(XtDisplay(w), win, &wattr)) return 0;
    return wattr.map_state;
    }



/* 
 * ******* end required file <Xt.inc> *******
 */
/* 
 * XtIntervalId
 * XtAppAddTimeOut 
 * 	const: wafeAppContext 
 * 	in: unsigned long		# time interval in ms
 * 	const: timerProc
 * 	in: XtNewString(String)		# tcl command
 */

static int 
cmd_addTimeOut(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     unsigned long localVar1;
     XtIntervalId returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("addTimeOut");  

     if (argc != 3) 
	 {
	 wafeArgcError("addTimeOut","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(sscanf(argv[1], "%lu", &localVar1)))
          {
          wafeConvError("addTimeOut","2",argv[1],"unsigned long");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     returnVar = XtAppAddTimeOut(wafeAppContext,localVar1,timerProc,XtNewString(argv[2]));

     sprintf(conversionBuffer, "%lu", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * action
 * 	in: Widget			# widget
 * 	in: (int)TranslationModifier	# override | augment | replace
 *         in: XtTranslations		# translatontable
 */

static int 
cmd_action(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int localVar2;
     XtTranslations localVar3;

     DBUG_ENTER("action");  

     if (argc != 4) 
	 {
	 wafeArgcError("action","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("action","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "override")) 
         localVar2 = 1;
     else
     if (!strcmp(argv[2], "augment")) 
         localVar2 = 2;
     else
     if (!strcmp(argv[2], "replace")) 
         localVar2 = 3;
     else
         {
         wafeConvError("action","2",argv[2],"TranslationModifier");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!(localVar3 = (XtTranslations) XtParseTranslationTable(argv[3])))
          {
          wafeConvError("action","3",argv[3],"XtTranslations");
          DBUG_RETURN (TCL_ERROR);
          }

     action(localVar1,localVar2,localVar3);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XBell
 * 	in: XtDisplay(Widget)		# widget to determine display
 * 	in: int				# percent (-100 = off, 0 .. 100)
 */

static int 
cmd_bell(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int localVar2;

     DBUG_ENTER("bell");  

     if (argc != 3) 
	 {
	 wafeArgcError("bell","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("bell","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(sscanf(argv[2], "%d", &localVar2)))
          {
          wafeConvError("bell","2",argv[2],"int");
          DBUG_RETURN (TCL_ERROR);
          }

     XBell(XtDisplay(localVar1),localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * callActionProc
 * 	in: Widget			# widget
 * 	in: String			# event type
 * 	in: String			# action
 * 	in: [args opt]			# args
 */

static int 
cmd_callActionProc(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("callActionProc");  

     if (argc < 4) 
	 {
	 wafeArgcError("callActionProc","at least ",4,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("callActionProc","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

    /* no need to assign  << localVar3 = argv[3] >>  */ 

     argc -= 4;
     callActionProc(localVar1,argv[2],argv[3],argc,&argv[4]);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * callCallbacks
 * 	in: Widget			# widget
 * 	in: String			# callback
 * 	in: [args opt]			# optional float and value
 */

static int 
cmd_callCallbacks(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("callCallbacks");  

     if (argc < 3) 
	 {
	 wafeArgcError("callCallbacks","at least ",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("callCallbacks","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     argc -= 3;
     callCallbacks(localVar1,argv[2],argc,&argv[3]);

     DBUG_RETURN (TCL_OK);
     }     


extern wafePositionCallbackProc();
extern wafePositionCursorCallbackProc();

/* 
 * void
 * wafeCallbackCmd vulgo callback
 * 	in: Widget			# widget
 * 	in: String			# callback resource
 *         in: XtCallbackProc		# none | exclusive | nonexclusive | popdown | position | positionCursor
 *         in: XtNewString(String)		# string
 */

static int 
cmd_callback(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     XtCallbackProc localVar3;

     DBUG_ENTER("callback");  

     if (argc != 5) 
	 {
	 wafeArgcError("callback","",4,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("callback","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     if (!strcmp(argv[3], "exec")) 
         localVar3 = (XtCallbackProc)wafeExecCallbackProc;
     else
     if (!strcmp(argv[3], "none")) 
         localVar3 = XtCallbackNone;
     else
     if (!strcmp(argv[3], "exclusive")) 
         localVar3 = XtCallbackExclusive;
     else
     if (!strcmp(argv[3], "nonexclusive")) 
         localVar3 = XtCallbackNonexclusive;
     else
     if (!strcmp(argv[3], "popdown")) 
         localVar3 = XtCallbackPopdown;
     else
     if (!strcmp(argv[3], "position")) 
         localVar3 = (XtCallbackProc)wafePositionCallbackProc;
     else
     if (!strcmp(argv[3], "positionCursor")) 
         localVar3 = (XtCallbackProc)wafePositionCursorCallbackProc;
     else
         {
         wafeConvError("callback","3",argv[3],"XtCallbackProc");
         DBUG_RETURN (TCL_ERROR);
        }


    /* no need to assign  << localVar4 = argv[4] >>  */ 

     wafeCallbackCmd(localVar1,argv[2],localVar3,XtNewString(argv[4]));

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtDestroyWidget
 * 	callmultiple
 * 		in: wafeMMfreeGarbage(Widget)	# widgets
 */

static int 
cmd_destroyWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int count;

     DBUG_ENTER("destroyWidget");  

     if (argc < 2) 
	 {
	 wafeArgcError("destroyWidget","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     for (count = 1; count < argc; count++)
          {
         if (!(localVar1 = (Widget) name2Widget(argv[count])))
              {
              wafeConvError("destroyWidget","count",argv[count],"Widget");
              DBUG_RETURN (TCL_ERROR);
              }

         XtDestroyWidget(wafeMMfreeGarbage(localVar1));
          }

     DBUG_RETURN (TCL_OK);
     }     


#define fontHeight(w,resource) (font->max_bounds.ascent + font->max_bounds.descent)

/* 
 * int
 * fontHeight
 * 	pre: {XFontStruct *font; XtVaGetValues(localVar1, argv[2], &font, NULL);
 * 	in: Widget			# Widget
 * 	in: String			# fontResource
 *         post: }
 */

static int 
cmd_fontHeight(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("fontHeight");  

     if (argc != 3) 
	 {
	 wafeArgcError("fontHeight","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("fontHeight","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     {XFontStruct *font; XtVaGetValues(localVar1, argv[2], &font, NULL);
     returnVar = fontHeight(localVar1,argv[2]);
     }

     sprintf(conversionBuffer, "%d", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XFlush
 * 	in: XtDisplay(Widget)		# Widget to determine display
 */

static int 
cmd_flush(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("flush");  

     if (argc != 2) 
	 {
	 wafeArgcError("flush","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("flush","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XFlush(XtDisplay(localVar1));

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * getApplicationResource
 * 	in: Widget			# base widget 
 * 	in: String			# resource name
 * 	in: String			# resource class
 */

static int 
cmd_getApplicationResource(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String returnVar;

     DBUG_ENTER("getApplicationResource");  

     if (argc != 4) 
	 {
	 wafeArgcError("getApplicationResource","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("getApplicationResource","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

    /* no need to assign  << localVar3 = argv[3] >>  */ 

     returnVar = getApplicationResource(localVar1,argv[2],argv[3]);

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


#include <X11/IntrinsicP.h>
#define getClass(widget) (XtClass(widget)->core_class.class_name)

/* 
 * String
 * getClass
 * 	in: Widget			# widget | None
 */

static int 
cmd_getClass(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String returnVar;

     DBUG_ENTER("getClass");  

     if (argc != 2) 
	 {
	 wafeArgcError("getClass","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("getClass","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = getClass(localVar1);

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * int
 * getResourceList
 * 	in: Widget			# widget
 * 	out: String *			# variable name for output of reslist
 * 	end: XtFree((String)localVar2);
 */

static int 
cmd_getResourceList(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String * localVar2;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("getResourceList");  

     if (argc != 3) 
	 {
	 wafeArgcError("getResourceList","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("getResourceList","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = getResourceList(localVar1,&localVar2);

     
     Tcl_SetVar(wafeInterpreter, argv[2], Tcl_Merge(returnVar,localVar2), 0);

     sprintf(conversionBuffer, "%d", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     XtFree((String)localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * XrmQuark
 * wafeGetQTypeOfAttribute vulgo getTypeOfAttribute
 * 	in: XtClass(Widget)		# widget
 * 	const: ParentWidget(localVar1)
 * 	in: XrmStringToQuark(String)	# attribute
 */

static int 
cmd_getTypeOfAttribute(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     XrmQuark returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("getTypeOfAttribute");  

     if (argc != 3) 
	 {
	 wafeArgcError("getTypeOfAttribute","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("getTypeOfAttribute","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     returnVar = wafeGetQTypeOfAttribute(XtClass(localVar1),ParentWidget(localVar1),XrmStringToQuark(argv[2]));

     
     Tcl_SetResult(comInterpreter, XrmQuarkToString(returnVar), TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * getValue
 * 	in: Widget			# widget
 * 	in: XrmQuark			# attribute
 * 	free: freeProc
 */

static int 
cmd_getValue(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     XrmQuark localVar2;
     freeProc localVar3;
     String returnVar;

     DBUG_ENTER("getValue");  

     if (argc != 3) 
	 {
	 wafeArgcError("getValue","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("getValue","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(localVar2 = (XrmQuark) XrmStringToQuark(argv[2])))
          {
          wafeConvError("getValue","2",argv[2],"XrmQuark");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = getValue(localVar1,localVar2,&localVar3);

     
     Tcl_SetResult(comInterpreter, returnVar, localVar3);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * (int) GrabReturns
 * XtGrabPointer
 * 	in: Widget			# widget
 * 	in: Boolean			# true | false
 *         const: NoEventMask
 * 	in: (int) SyncAsync		# pointer mode (sync | async)
 * 	in: (int) SyncAsync             # keyboard mode (sync | async)
 * 	in: None | XtWindow(Widget)	# None | confine widget
 * 	const: None
 * 	const: CurrentTime
 */

static int 
cmd_grabPointer(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean localVar2;
     int localVar3;
     int localVar4;
     Widget localVar5;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("grabPointer");  

     if (argc != 6) 
	 {
	 wafeArgcError("grabPointer","",5,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("grabPointer","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "false")) 
         localVar2 = 0;
     else
     if (!strcmp(argv[2], "true")) 
         localVar2 = 1;
     else
         {
         wafeConvError("grabPointer","2",argv[2],"Boolean");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!strcmp(argv[3], "sync")) 
         localVar3 = GrabModeSync;
     else
     if (!strcmp(argv[3], "async")) 
         localVar3 = GrabModeAsync;
     else
         {
         wafeConvError("grabPointer","4",argv[3],"SyncAsync");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!strcmp(argv[4], "sync")) 
         localVar4 = GrabModeSync;
     else
     if (!strcmp(argv[4], "async")) 
         localVar4 = GrabModeAsync;
     else
         {
         wafeConvError("grabPointer","5",argv[4],"SyncAsync");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!strcmp(argv[5], "None")) 
         localVar5 = None;
     else
         if (!(localVar5 = (Widget) name2Widget(argv[5])))
          {
          wafeConvError("grabPointer","6",argv[5],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = XtGrabPointer(localVar1,localVar2,NoEventMask,localVar3,localVar4,XtWindow(localVar5),None,CurrentTime);

          if (returnVar == GrabSuccess) 
          strcpy(conversionBuffer, "success");
     else
     if (returnVar == AlreadyGrabbed) 
          strcpy(conversionBuffer, "alreadyGrabbed");
     else
     if (returnVar == GrabNotViewable) 
          strcpy(conversionBuffer, "notViewable");
     else
     if (returnVar == GrabFrozen) 
          strcpy(conversionBuffer, "frozen");


     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * (int) GrabReturns
 * XtGrabKeyboard
 * 	in: Widget			# widget
 * 	in: Boolean			# true | false
 * 	in: (int) SyncAsync		# pointer mode (sync | async)
 * 	in: (int) SyncAsync		# keyboard mode (sync | async)
 * 	const: CurrentTime
 */

static int 
cmd_grabKeyboard(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean localVar2;
     int localVar3;
     int localVar4;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("grabKeyboard");  

     if (argc != 5) 
	 {
	 wafeArgcError("grabKeyboard","",4,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("grabKeyboard","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "false")) 
         localVar2 = 0;
     else
     if (!strcmp(argv[2], "true")) 
         localVar2 = 1;
     else
         {
         wafeConvError("grabKeyboard","2",argv[2],"Boolean");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!strcmp(argv[3], "sync")) 
         localVar3 = GrabModeSync;
     else
     if (!strcmp(argv[3], "async")) 
         localVar3 = GrabModeAsync;
     else
         {
         wafeConvError("grabKeyboard","3",argv[3],"SyncAsync");
         DBUG_RETURN (TCL_ERROR);
        }


     if (!strcmp(argv[4], "sync")) 
         localVar4 = GrabModeSync;
     else
     if (!strcmp(argv[4], "async")) 
         localVar4 = GrabModeAsync;
     else
         {
         wafeConvError("grabKeyboard","4",argv[4],"SyncAsync");
         DBUG_RETURN (TCL_ERROR);
        }


     returnVar = XtGrabKeyboard(localVar1,localVar2,localVar3,localVar4,CurrentTime);

          if (returnVar == GrabSuccess) 
          strcpy(conversionBuffer, "success");
     else
     if (returnVar == AlreadyGrabbed) 
          strcpy(conversionBuffer, "alreadyGrabbed");
     else
     if (returnVar == GrabNotViewable) 
          strcpy(conversionBuffer, "notViewable");
     else
     if (returnVar == GrabFrozen) 
          strcpy(conversionBuffer, "frozen");


     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * int
 * HeightOfScreen
 * 	in: XtScreen(Widget)     	# widget to determine screen
 */

static int 
cmd_heightOfScreen(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("heightOfScreen");  

     if (argc != 2) 
	 {
	 wafeArgcError("heightOfScreen","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("heightOfScreen","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = HeightOfScreen(XtScreen(localVar1));

     sprintf(conversionBuffer, "%d", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtInstallAccelerators
 * 	in: Widget			# destination
 * 	in: Widget			# source
 */

static int 
cmd_installAccelerators(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Widget localVar2;

     DBUG_ENTER("installAccelerators");  

     if (argc != 3) 
	 {
	 wafeArgcError("installAccelerators","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("installAccelerators","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(localVar2 = (Widget) name2Widget(argv[2])))
          {
          wafeConvError("installAccelerators","2",argv[2],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtInstallAccelerators(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtInstallAllAccelerators
 * 	in: Widget			# destination
 * 	in: Widget			# source
 */

static int 
cmd_installAllAccelerators(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Widget localVar2;

     DBUG_ENTER("installAllAccelerators");  

     if (argc != 3) 
	 {
	 wafeArgcError("installAllAccelerators","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("installAllAccelerators","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(localVar2 = (Widget) name2Widget(argv[2])))
          {
          wafeConvError("installAllAccelerators","2",argv[2],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtInstallAllAccelerators(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * WidgetID (WidgetID)
 * name2WidgetId vulgo isWidget
 * 	in: String			# widget name
 */

static int 
cmd_isWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     WidgetID returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("isWidget");  

     if (argc != 2) 
	 {
	 wafeArgcError("isWidget","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     returnVar = (WidgetID) name2WidgetId(argv[1]);

     sprintf(conversionBuffer, "%ld", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


#ifdef LAYOUT
#include "Layout.h"
#endif
/* 
 * void
 * XLowerWindow
 * 	in: XtDisplay(Widget)           # Widget to be lowered
 * 	const: XtWindow(localVar1)
 */

static int 
cmd_lowerWindow(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("lowerWindow");  

     if (argc != 2) 
	 {
	 wafeArgcError("lowerWindow","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("lowerWindow","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XLowerWindow(XtDisplay(localVar1),XtWindow(localVar1));

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtManageChildren vulgo manageChild
 * 	in: [Widget]		        # widgets
 * 	const: argc -1
 */

static int 
cmd_manageChild(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget * localVar1;

     DBUG_ENTER("manageChild");  

     if (argc < 2) 
	 {
	 wafeArgcError("manageChild","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     {    Widget *ptr;
          argv += 1;
          localVar1 = ptr =
             (Widget *)XtMalloc((argc-1)*sizeof(Widget));

          while (*argv)
             {
             if (!(*ptr =  name2Widget(*argv)))
                  {
                  wafeConvError("manageChild","1",*argv,"Widget");
                  DBUG_RETURN (TCL_ERROR);
                  }

          ptr ++; argv++;
          }
     }
     XtManageChildren(localVar1,argc -1);
     XtFree((char *)localVar1);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtMapWidget
 * 	callmultiple
 * 		in: Widget		# widgets
 */

static int 
cmd_mapWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int count;

     DBUG_ENTER("mapWidget");  

     if (argc < 2) 
	 {
	 wafeArgcError("mapWidget","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     for (count = 1; count < argc; count++)
          {
         if (!(localVar1 = (Widget) name2Widget(argv[count])))
              {
              wafeConvError("mapWidget","count",argv[count],"Widget");
              DBUG_RETURN (TCL_ERROR);
              }

         XtMapWidget(localVar1);
          }

     DBUG_RETURN (TCL_OK);
     }     


#define mergeResources(localVar1,argc,argv) { XrmDatabase    dispDb, newDb = NULL; int            i; char         **v = argv; dispDb = XtDatabase(XtDisplay(localVar1)); for (i = 0; i < argc; i+=2)  XrmPutStringResource(&newDb, v[i], v[i+1]); XrmMergeDatabases(newDb, &dispDb);}

/* 
 * void 
 * mergeResources
 * 	in: Widget			# widget to determine display
 * 	in: [args avp] 			# resource value pairs
 */

static int 
cmd_mergeResources(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean freeArgv = False;
     char **argvArg;

     DBUG_ENTER("mergeResources");  

     if (argc < 3) 
	 {
	 wafeArgcError("mergeResources","at least ",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("mergeResources","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     argc -= 2;
     argvArg = &argv[2];
     if (argc == 1)
        {
        if (wafeMergeArguments(argv[2],"mergeResources",&argc,&argvArg))
           freeArgv = True;
        else 
           DBUG_RETURN (TCL_ERROR);
        }
     if (argc%2)
        {
        wafeArgcError("mergeResources","even number of arguments such as 2 or ",4,argc+1);
        if (freeArgv) XtFree((char*)argvArg);
        DBUG_RETURN (TCL_ERROR);
        }

     mergeResources(localVar1,argc,argvArg);
     if (freeArgv) XtFree((char *)argvArg);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * WidgetID (WidgetID)
 * XtNameToWidget
 * 	in: Widget			# reference widget
 * 	in: String                      # partial widget name path
 */

static int 
cmd_nameToWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     WidgetID returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("nameToWidget");  

     if (argc != 3) 
	 {
	 wafeArgcError("nameToWidget","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("nameToWidget","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     returnVar = (WidgetID) XtNameToWidget(localVar1,argv[2]);

     sprintf(conversionBuffer, "%ld", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * WidgetID (WidgetID)
 * ParentWidget vulgo parent
 * 	in: Widget			# child widget
 */

static int 
cmd_parent(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     WidgetID returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("parent");  

     if (argc != 2) 
	 {
	 wafeArgcError("parent","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("parent","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = (WidgetID) ParentWidget(localVar1);

     sprintf(conversionBuffer, "%ld", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtPopdown
 *         in: ShellWidget			# shell widget
 */

static int 
cmd_popdown(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("popdown");  

     if (argc != 2) 
	 {
	 wafeArgcError("popdown","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 =  name2WidgetOfClass(argv[1],shellWidgetClass,"Shell")))
          {
          wafeConvError("popdown","1",argv[1],"ShellWidget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtPopdown(localVar1);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtPopup
 *         in: ShellWidget			# widget
 *         in: XtGrabKind			# none | nonexclusive | exclusive
 */

static int 
cmd_popup(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     XtGrabKind localVar2;

     DBUG_ENTER("popup");  

     if (argc != 3) 
	 {
	 wafeArgcError("popup","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 =  name2WidgetOfClass(argv[1],shellWidgetClass,"Shell")))
          {
          wafeConvError("popup","1",argv[1],"ShellWidget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "none")) 
         localVar2 = XtGrabNone;
     else
     if (!strcmp(argv[2], "nonexclusive")) 
         localVar2 = XtGrabNonexclusive;
     else
     if (!strcmp(argv[2], "exclusive")) 
         localVar2 = XtGrabExclusive;
     else
         {
         wafeConvError("popup","2",argv[2],"XtGrabKind");
         DBUG_RETURN (TCL_ERROR);
        }


     XtPopup(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


#define popupChildren(w) wafeCvtWidgetListToList(NULL,(w)->core.num_popups,(w)->core.popup_list)

/* 
 * String
 * popupChildren
 * 	in: Widget
 * 	post: XtFree(returnVar);
 */

static int 
cmd_popupChildren(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String returnVar;

     DBUG_ENTER("popupChildren");  

     if (argc != 2) 
	 {
	 wafeArgcError("popupChildren","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("popupChildren","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = popupChildren(localVar1);
     XtFree(returnVar);

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtPopupSpringLoaded
 *         in: ShellWidget			# shell widget
 */

static int 
cmd_popupSpringLoaded(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("popupSpringLoaded");  

     if (argc != 2) 
	 {
	 wafeArgcError("popupSpringLoaded","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 =  name2WidgetOfClass(argv[1],shellWidgetClass,"Shell")))
          {
          wafeConvError("popupSpringLoaded","1",argv[1],"ShellWidget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtPopupSpringLoaded(localVar1);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * processPendingEvents
 */

static int 
cmd_processPendingEvents(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {

     DBUG_ENTER("processPendingEvents");  

     if (argc != 1) 
	 {
	 wafeArgcError("processPendingEvents","",0,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     processPendingEvents();

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XRaiseWindow
 * 	in: XtDisplay(Widget)		# widget to be raised
 * 	const: XtWindow(localVar1)
 */

static int 
cmd_raiseWindow(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("raiseWindow");  

     if (argc != 2) 
	 {
	 wafeArgcError("raiseWindow","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("raiseWindow","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XRaiseWindow(XtDisplay(localVar1),XtWindow(localVar1));

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * realizeWidgets vulgo realize
 */

static int 
cmd_realize(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {

     DBUG_ENTER("realize");  

     if (argc != 1) 
	 {
	 wafeArgcError("realize","",0,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     realizeWidgets();

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtRealizeWidget
 * 	callmultiple
 * 		in: Widget		# widgets
 */

static int 
cmd_realizeWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int count;

     DBUG_ENTER("realizeWidget");  

     if (argc < 2) 
	 {
	 wafeArgcError("realizeWidget","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     for (count = 1; count < argc; count++)
          {
         if (!(localVar1 = (Widget) name2Widget(argv[count])))
              {
              wafeConvError("realizeWidget","count",argv[count],"Widget");
              DBUG_RETURN (TCL_ERROR);
              }

         XtRealizeWidget(localVar1);
          }

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtRemoveAllCallbacks
 * 	in: Widget			# widget
 * 	in: String			# callback name
 */

static int 
cmd_removeAllCallbacks(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("removeAllCallbacks");  

     if (argc != 3) 
	 {
	 wafeArgcError("removeAllCallbacks","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("removeAllCallbacks","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     XtRemoveAllCallbacks(localVar1,argv[2]);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void 
 * XtRemoveTimeOut 
 * 	in: XtIntervalId		# interval ID
 */

static int 
cmd_removeTimeOut(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     XtIntervalId localVar1;

     DBUG_ENTER("removeTimeOut");  

     if (argc != 2) 
	 {
	 wafeArgcError("removeTimeOut","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(sscanf(argv[1], "%lu", &localVar1)))
          {
          wafeConvError("removeTimeOut","1",argv[1],"XtIntervalId");
          DBUG_RETURN (TCL_ERROR);
          }

     XtRemoveTimeOut(localVar1);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * XtResolvePathname
 * 	in: XtDisplay(Widget)
 * 	in: NULL | String               # Type
 * 	in: NULL | String               # File
 * 	in: NULL | String               # Suffix
 * 	in: NULL | String               # Path
 * 	const: NULL                     # Substitutions
 * 	const: 0                        # Number of Substitutions
 * 	const: NULL                     # XtFilePredicate
 */

static int 
cmd_resolvePathname(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String localVar2;
     String localVar3;
     String localVar4;
     String localVar5;
     String returnVar;

     DBUG_ENTER("resolvePathname");  

     if (argc != 6) 
	 {
	 wafeArgcError("resolvePathname","",5,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("resolvePathname","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "NULL")) 
         localVar2 = NULL;
     else
         localVar2 = argv[2];
     if (!strcmp(argv[3], "NULL")) 
         localVar3 = NULL;
     else
         localVar3 = argv[3];
     if (!strcmp(argv[4], "NULL")) 
         localVar4 = NULL;
     else
         localVar4 = argv[4];
     if (!strcmp(argv[5], "NULL")) 
         localVar5 = NULL;
     else
         localVar5 = argv[5];
     returnVar = XtResolvePathname(XtDisplay(localVar1),localVar2,localVar3,localVar4,localVar5,NULL,0,NULL);

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * setBusy
 * 	in: Widget			# shell widget 
 * 	in: Boolean			# sensitive true | false
 */

static int 
cmd_setBusy(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean localVar2;

     DBUG_ENTER("setBusy");  

     if (argc != 3) 
	 {
	 wafeArgcError("setBusy","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("setBusy","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "false")) 
         localVar2 = 0;
     else
     if (!strcmp(argv[2], "true")) 
         localVar2 = 1;
     else
         {
         wafeConvError("setBusy","2",argv[2],"Boolean");
         DBUG_RETURN (TCL_ERROR);
        }


     setBusy(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtSetKeyboardFocus
 * 	in: Widget			# from widget tree
 * 	in: None|Widget			# to widget | None
 */

static int 
cmd_setKeyboardFocus(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Widget localVar2;

     DBUG_ENTER("setKeyboardFocus");  

     if (argc != 3) 
	 {
	 wafeArgcError("setKeyboardFocus","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("setKeyboardFocus","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "None")) 
         localVar2 = None;
     else
         if (!(localVar2 = (Widget) name2Widget(argv[2])))
          {
          wafeConvError("setKeyboardFocus","2",argv[2],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtSetKeyboardFocus(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtSetSensitive 
 * 	in: Widget			# widget 
 * 	in: Boolean			# sensitive true | false
 */

static int 
cmd_setSensitive(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean localVar2;

     DBUG_ENTER("setSensitive");  

     if (argc != 3) 
	 {
	 wafeArgcError("setSensitive","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("setSensitive","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "false")) 
         localVar2 = 0;
     else
     if (!strcmp(argv[2], "true")) 
         localVar2 = 1;
     else
         {
         wafeConvError("setSensitive","2",argv[2],"Boolean");
         DBUG_RETURN (TCL_ERROR);
        }


     XtSetSensitive(localVar1,localVar2);

     DBUG_RETURN (TCL_OK);
     }     


#define setValues(w,argc,argv) {ArgList           args; int               numArgs; if (wafeConvert(ParentWidget(w), XtClass(w), argv, &argc, &args, &numArgs, w)) { XtSetValues(w, args, numArgs); wafeCurrentAttribList = NULL; XtFree((String)args); } }

/* 
 * void
 * setValues
 * 	in: Widget			# widget
 * 	in: [args avp]			# resource value pairs
 */

static int 
cmd_setValues(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean freeArgv = False;
     char **argvArg;

     DBUG_ENTER("setValues");  

     if (argc < 3) 
	 {
	 wafeArgcError("setValues","at least ",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("setValues","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     argc -= 2;
     argvArg = &argv[2];
     if (argc == 1)
        {
        if (wafeMergeArguments(argv[2],"setValues",&argc,&argvArg))
           freeArgv = True;
        else 
           DBUG_RETURN (TCL_ERROR);
        }
     if (argc%2)
        {
        wafeArgcError("setValues","even number of arguments such as 2 or ",4,argc+1);
        if (freeArgv) XtFree((char*)argvArg);
        DBUG_RETURN (TCL_ERROR);
        }

     setValues(localVar1,argc,argvArg);
     if (freeArgv) XtFree((char *)argvArg);

     DBUG_RETURN (TCL_OK);
     }     


#define ADDRESS_OF(w) &(w)

/* 
 * Boolean 
 * XSetWMProtocols
 * 	const: XtDisplay(localVar1)
 * 	in: XtWindow(ShellWidget)	# Shell Widget
 * 	in: ADDRESS_OF((Atom)WM_PROTOCOLS)	# WM_TAKE_FOCUS | WM_SAVE_YOURSELF | WM_DELETE_WINDOW
 * 	const: 1
 */

static int 
cmd_setWMProtocols(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Atom localVar2;
     Boolean returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("setWMProtocols");  

     if (argc != 3) 
	 {
	 wafeArgcError("setWMProtocols","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 =  name2WidgetOfClass(argv[1],shellWidgetClass,"Shell")))
          {
          wafeConvError("setWMProtocols","2",argv[1],"ShellWidget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "WM_TAKE_FOCUS")) 
         localVar2 = XInternAtom(XtDisplay(localVar1),"WM_TAKE_FOCUS",False);
     else
     if (!strcmp(argv[2], "WM_SAVE_YOURSELF")) 
         localVar2 = XInternAtom(XtDisplay(localVar1),"WM_SAVE_YOURSELF",False);
     else
     if (!strcmp(argv[2], "WM_DELETE_WINDOW")) 
         localVar2 = XInternAtom(XtDisplay(localVar1),"WM_DELETE_WINDOW",False);
     else
         {
         wafeConvError("setWMProtocols","3",argv[2],"WM_PROTOCOLS");
         DBUG_RETURN (TCL_ERROR);
        }


     returnVar = XSetWMProtocols(XtDisplay(localVar1),XtWindow(localVar1),ADDRESS_OF(localVar2),1);

          if (returnVar == 0) 
          strcpy(conversionBuffer, "false");
     else
     if (returnVar == 1) 
          strcpy(conversionBuffer, "true");


     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XSync
 * 	in: XtDisplay(Widget)		# Widget to determine display
 * 	in: Boolean			# Discard (Boolean)
 */

static int 
cmd_sync(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Boolean localVar2;

     DBUG_ENTER("sync");  

     if (argc != 3) 
	 {
	 wafeArgcError("sync","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("sync","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "false")) 
         localVar2 = 0;
     else
     if (!strcmp(argv[2], "true")) 
         localVar2 = 1;
     else
         {
         wafeConvError("sync","2",argv[2],"Boolean");
         DBUG_RETURN (TCL_ERROR);
        }


     XSync(XtDisplay(localVar1),localVar2);

     DBUG_RETURN (TCL_OK);
     }     


#define textWidth(w,resource,string) XTextWidth(font, string, strlen(string))

/* 
 * int
 * textWidth
 * 	pre: {XFontStruct *font; XtVaGetValues(localVar1, argv[2], &font, NULL);
 * 	in: Widget			# Widget
 * 	in: String			# fontResource
 * 	in: String			# String
 *         post: }
 */

static int 
cmd_textWidth(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("textWidth");  

     if (argc != 4) 
	 {
	 wafeArgcError("textWidth","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("textWidth","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

    /* no need to assign  << localVar3 = argv[3] >>  */ 

     {XFontStruct *font; XtVaGetValues(localVar1, argv[2], &font, NULL);
     returnVar = textWidth(localVar1,argv[2],argv[3]);
     }

     sprintf(conversionBuffer, "%d", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtTranslateCoords
 * 	in: Widget			# widget
 * 	in: Position    		# widget x
 * 	in: Position    		# widget y
 * 	out: Position   		# variable name for root x
 * 	out: Position   		# variable name for root y
 */

static int 
cmd_translateCoords(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Position localVar2;
     Position localVar3;
     Position localVar4;
     Position localVar5;
     char conversionBuffer[100];

     DBUG_ENTER("translateCoords");  

     if (argc != 6) 
	 {
	 wafeArgcError("translateCoords","",5,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("translateCoords","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(sscanf(argv[2], "%hd", &localVar2)))
          {
          wafeConvError("translateCoords","2",argv[2],"Position");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(sscanf(argv[3], "%hd", &localVar3)))
          {
          wafeConvError("translateCoords","3",argv[3],"Position");
          DBUG_RETURN (TCL_ERROR);
          }

     XtTranslateCoords(localVar1,localVar2,localVar3,&localVar4,&localVar5);

     sprintf(conversionBuffer, "%hd", localVar4);
     Tcl_SetVar(wafeInterpreter, argv[4], conversionBuffer, 0);

     sprintf(conversionBuffer, "%hd", localVar5);
     Tcl_SetVar(wafeInterpreter, argv[5], conversionBuffer, 0);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtUngrabPointer
 * 	in: Widget			# widget with active pointer grab
 * 	const: CurrentTime
 */

static int 
cmd_ungrabPointer(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("ungrabPointer");  

     if (argc != 2) 
	 {
	 wafeArgcError("ungrabPointer","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("ungrabPointer","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtUngrabPointer(localVar1,CurrentTime);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtUngrabKeyboard
 * 	in: Widget			# widget with active keyboard grab
 * 	const: CurrentTime
 */

static int 
cmd_ungrabKeyboard(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("ungrabKeyboard");  

     if (argc != 2) 
	 {
	 wafeArgcError("ungrabKeyboard","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("ungrabKeyboard","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     XtUngrabKeyboard(localVar1,CurrentTime);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtUnmanageChildren vulgo unmanageChild
 * 	in: [Widget]		# widgets
 * 	const: argc -1
 */

static int 
cmd_unmanageChild(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget * localVar1;

     DBUG_ENTER("unmanageChild");  

     if (argc < 2) 
	 {
	 wafeArgcError("unmanageChild","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     {    Widget *ptr;
          argv += 1;
          localVar1 = ptr =
             (Widget *)XtMalloc((argc-1)*sizeof(Widget));

          while (*argv)
             {
             if (!(*ptr =  name2Widget(*argv)))
                  {
                  wafeConvError("unmanageChild","1",*argv,"Widget");
                  DBUG_RETURN (TCL_ERROR);
                  }

          ptr ++; argv++;
          }
     }
     XtUnmanageChildren(localVar1,argc -1);
     XtFree((char *)localVar1);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtUnmapWidget
 * 	callmultiple
 * 		in: Widget		# widgets
 */

static int 
cmd_unmapWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int count;

     DBUG_ENTER("unmapWidget");  

     if (argc < 2) 
	 {
	 wafeArgcError("unmapWidget","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     for (count = 1; count < argc; count++)
          {
         if (!(localVar1 = (Widget) name2Widget(argv[count])))
              {
              wafeConvError("unmapWidget","count",argv[count],"Widget");
              DBUG_RETURN (TCL_ERROR);
              }

         XtUnmapWidget(localVar1);
          }

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtUnrealizeWidget
 * 	callmultiple
 * 		in: Widget		# widgets
 */

static int 
cmd_unrealizeWidget(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int count;

     DBUG_ENTER("unrealizeWidget");  

     if (argc < 2) 
	 {
	 wafeArgcError("unrealizeWidget","at least ",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     for (count = 1; count < argc; count++)
          {
         if (!(localVar1 = (Widget) name2Widget(argv[count])))
              {
              wafeConvError("unrealizeWidget","count",argv[count],"Widget");
              DBUG_RETURN (TCL_ERROR);
              }

         XtUnrealizeWidget(localVar1);
          }

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * waitForVariable
 * 	in: String			# variable Name
 */

static int 
cmd_waitForVariable(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     String returnVar;

     DBUG_ENTER("waitForVariable");  

     if (argc != 2) 
	 {
	 wafeArgcError("waitForVariable","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     returnVar = waitForVariable(argv[1]);

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * Widget
 * name2WidgetId vulgo widgetName
 * 	in: String			# widget name
 */

static int 
cmd_widgetName(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("widgetName");  

     if (argc != 2) 
	 {
	 wafeArgcError("widgetName","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     returnVar = name2WidgetId(argv[1]);

     
     Tcl_SetResult(comInterpreter, widget2Name(returnVar), TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * int
 * WidthOfScreen
 * 	in: XtScreen(Widget)     	# widget to determine screen
 */

static int 
cmd_widthOfScreen(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("widthOfScreen");  

     if (argc != 2) 
	 {
	 wafeArgcError("widthOfScreen","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("widthOfScreen","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = WidthOfScreen(XtScreen(localVar1));

     sprintf(conversionBuffer, "%d", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * long (long)
 * XtWindow
 *         in: Widget     			# widget whose window you want
 */

static int 
cmd_window(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     long returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("window");  

     if (argc != 2) 
	 {
	 wafeArgcError("window","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("window","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = (long) XtWindow(localVar1);

     sprintf(conversionBuffer, "%ld", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XtDisownSelection
 * 	const: wafeTopLevel
 * 	const: XA_PRIMARY
 * 	const: CurrentTime
 */

static int 
cmd_disownSelection(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {

     DBUG_ENTER("disownSelection");  

     if (argc != 1) 
	 {
	 wafeArgcError("disownSelection","",0,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     XtDisownSelection(wafeTopLevel,XA_PRIMARY,CurrentTime);

     DBUG_RETURN (TCL_OK);
     }     


extern void wafeGetSelectionValueProc();

/* 
 * void
 * XtGetSelectionValue
 * 	const: wafeTopLevel
 * 	const: XA_PRIMARY
 * 	const: XA_STRING
 * 	const: wafeGetSelectionValueProc
 * 	in: XtNewString(String)		# Tcl command
 * 	const: CurrentTime
 */

static int 
cmd_getSelectionValue(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {

     DBUG_ENTER("getSelectionValue");  

     if (argc != 2) 
	 {
	 wafeArgcError("getSelectionValue","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     XtGetSelectionValue(wafeTopLevel,XA_PRIMARY,XA_STRING,wafeGetSelectionValueProc,XtNewString(argv[1]),CurrentTime);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * Boolean
 * wafeOwnSelectionCmd vulgo ownSelection
 * 	in: XtNewString(String) # string to be put into selection
 * 	in: NULL | String 	# NULL | loseSelection TCL-command
 * 	in: NULL | String 	# NULL | doneSelection TCL-command
 */

static int 
cmd_ownSelection(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     String localVar2;
     String localVar3;
     Boolean returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("ownSelection");  

     if (argc != 4) 
	 {
	 wafeArgcError("ownSelection","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     if (!strcmp(argv[2], "NULL")) 
         localVar2 = NULL;
     else
         localVar2 = argv[2];
     if (!strcmp(argv[3], "NULL")) 
         localVar3 = NULL;
     else
         localVar3 = argv[3];
     returnVar = wafeOwnSelectionCmd(XtNewString(argv[1]),localVar2,localVar3);

          if (returnVar == 0) 
          strcpy(conversionBuffer, "false");
     else
     if (returnVar == 1) 
          strcpy(conversionBuffer, "true");


     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * XFetchBytes
 * 	pre: { int bytes; XConvertSelection(XtDisplay(localVar1), XA_PRIMARY, XA_STRING, XA_CUT_BUFFER0, DefaultRootWindow(XtDisplay(localVar1)), CurrentTime); 
 * 	in: XtDisplay(Widget) 		# widget to determine display
 *         const:  &bytes
 * 	post: }
 * 	end: XtFree(returnVar);
 */

static int 
cmd_fetchBytes(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     String returnVar;

     DBUG_ENTER("fetchBytes");  

     if (argc != 2) 
	 {
	 wafeArgcError("fetchBytes","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("fetchBytes","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     { int bytes; XConvertSelection(XtDisplay(localVar1), XA_PRIMARY, XA_STRING, XA_CUT_BUFFER0, DefaultRootWindow(XtDisplay(localVar1)), CurrentTime);
     returnVar = XFetchBytes(XtDisplay(localVar1),&bytes);
     }

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     XtFree(returnVar);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XConvertSelection
 * 	in: XtDisplay(Widget)		# widget to determine display
 * 	const: XA_PRIMARY
 * 	const: XA_STRING
 * 	in: Atom			# target buffer number
 * 	const: DefaultRootWindow(XtDisplay(wafeTopLevel))
 * 	const: CurrentTime
 */

static int 
cmd_convertSelection(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     Atom localVar2;

     DBUG_ENTER("convertSelection");  

     if (argc != 3) 
	 {
	 wafeArgcError("convertSelection","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("convertSelection","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!strcmp(argv[2], "0")) 
         localVar2 = XA_CUT_BUFFER0;
     else
     if (!strcmp(argv[2], "1")) 
         localVar2 = XA_CUT_BUFFER1;
     else
     if (!strcmp(argv[2], "2")) 
         localVar2 = XA_CUT_BUFFER2;
     else
     if (!strcmp(argv[2], "3")) 
         localVar2 = XA_CUT_BUFFER3;
     else
     if (!strcmp(argv[2], "4")) 
         localVar2 = XA_CUT_BUFFER4;
     else
     if (!strcmp(argv[2], "5")) 
         localVar2 = XA_CUT_BUFFER5;
     else
     if (!strcmp(argv[2], "6")) 
         localVar2 = XA_CUT_BUFFER6;
     else
         {
         wafeConvError("convertSelection","4",argv[2],"Atom");
         DBUG_RETURN (TCL_ERROR);
        }


     XConvertSelection(XtDisplay(localVar1),XA_PRIMARY,XA_STRING,localVar2,DefaultRootWindow(XtDisplay(wafeTopLevel)),CurrentTime);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void
 * XStoreBuffer
 * 	in: XtDisplay(Widget)		# widget to determine display
 * 	in: String			# String
 * 	const: strlen(argv[2])
 * 	in: int				# buffer number (1-7)
 */

static int 
cmd_storeBuffer(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int localVar3;

     DBUG_ENTER("storeBuffer");  

     if (argc != 4) 
	 {
	 wafeArgcError("storeBuffer","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("storeBuffer","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     if (!(sscanf(argv[3], "%d", &localVar3)))
          {
          wafeConvError("storeBuffer","4",argv[3],"int");
          DBUG_RETURN (TCL_ERROR);
          }

     XStoreBuffer(XtDisplay(localVar1),argv[2],strlen(argv[2]),localVar3);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * String
 * XFetchBuffer
 * 	in: XtDisplay(Widget)		# widget to determine display
 * 	const: &nbytes
 * 	in: int				# buffer number (1-7)
 * 	pre: {int nbytes;
 * 	post: }
 * 	end: XtFree(returnVar);
 */

static int 
cmd_fetchBuffer(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     int localVar2;
     String returnVar;

     DBUG_ENTER("fetchBuffer");  

     if (argc != 3) 
	 {
	 wafeArgcError("fetchBuffer","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("fetchBuffer","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     if (!(sscanf(argv[2], "%d", &localVar2)))
          {
          wafeConvError("fetchBuffer","3",argv[2],"int");
          DBUG_RETURN (TCL_ERROR);
          }

     {int nbytes;
     returnVar = XFetchBuffer(XtDisplay(localVar1),&nbytes,localVar2);
     }

     
     Tcl_SetResult(comInterpreter, returnVar, TCL_VOLATILE);

     XtFree(returnVar);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * ******* begin required file <xpm.inc> *******
 */
/* yes buddy, it is a -*- c -*- program! */

 /*
    * This file contains a new converter procedure and xpm support procedures:
    *
    *    A new StringToBitmap Converter, which is also able to convert
    *    Pixmaps (suffix .xpm). First it searches for a valid BitmapFile
    *    under the given filename; if the file format is invalid, it
    *    tries to interpret it as a pixmap file.
    */ 


#ifdef XPM
#include <xpm.h>
#include <X11/extensions/shape.h>
#endif
#include <X11/Xos.h>
#include <X11/Xmu/Xmu.h>

#ifdef XPM
 /* Create a linked list, which keeps track of all created pixmaps,
  * so that we can destroy Colorcells, if they are not longer needed.
  * Only the changePixmap command will use this feature, so pixmaps which
  * are set with setValues are still cached as usual!
  * Note that setting a pixmap with setValues therefore implies loosing these 
  * colorcells for the application's lifetime!
  */

typedef struct _PixmapInfo
     {
     Pixmap                pm;              /* Pixmap                */
     Pixmap                mask;            /* shape mask            */
     Widget                widget;          /* Widget                */
     XpmAttributes         *attribPtr;      /* Colorcells, etc       */
     char                 *pmName;          /* The filename..        */
     int                   count;           /* references            */
     struct _PixmapInfo   *next;
     }  PIXMAPINFO, *PIXMAPINFOPTR;

PIXMAPINFOPTR  pixmapListHead = NULL;
#endif

/* Additional Args for the converter: 
 */

static XtConvertArgRec xpmConvertArgsPixmap[] = {
  {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.window), 
   sizeof(Window)},
  {XtImmediate, (XtPointer)True, sizeof(Boolean)}
};


static XtConvertArgRec xpmConvertArgsBitmap[] = {
  {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.window), 
   sizeof(Window)}
};
   

/* try hard to locate bitmap or pixmap file */
char *
wafeLocateBitmap(dpy, name, toPixmap)
Display *dpy;
char * name;
Boolean toPixmap;
    {
    char *fn;

    /* is it the name a sufficient path? */
    if (access(name, R_OK) == 0)
	return name;
    else
	{
	if (!(fn = XtResolvePathname(dpy, "bitmaps", name, "", 
			       wafeFileSearchPath, NULL, 0, NULL)))
	    {
	    XtStringConversionWarning(name, toPixmap ? "Pixmap" : "Bitmap");
	    fprintf(stderr, 
		    "Wafe(convert): Wafe's current FILESEARCHPATH is <%s>\n", 
		    wafeFileSearchPath);  
	    }
	return fn;
	}
    }


#ifdef XPM
static void
changePixmap(w,resource,fname)
Widget     w;
String     resource;
String     fname;
    {
    Colormap        cmap;
    Pixmap          death, pixmap, mask;
    int             returnVal;

    XpmAttributes  *attribPtr;
    PIXMAPINFOPTR   pptr, cptr;
    char           *fn;

    Display        *dpy       = XtDisplay(w);
    Window          win       = XtWindow(w);
    int             screenNum = DefaultScreen(dpy);
    unsigned int    depth     = DefaultDepth(dpy, screenNum);

    /* Get pixmap adress and colormap of the pixmap, which will be destroyed */
    
    XtVaGetValues(w, resource, &death, 
		  XtNcolormap, &cmap, NULL);

    /* Search the list of pixmaps to find out whether the specified pixmap's 
     * resources are to be freed - which is the case when it was created by
     * this procedure.
     */

    if (pixmapListHead)
	{
	for (pptr = pixmapListHead; pptr != NULL; pptr = pptr->next)
	    {
	    if (pptr->pm == death)
		{
		if (pptr->widget == w && !strcmp(pptr->pmName, fname))
		    {
		    DBUG_PRINT("pixmap",
			       ("You are about to set the same pixmap!"));
		    return;
		    }

                pptr->count--;
                if (pptr->count < 1) 
		    {
		    /* destroy Pixmap and deallocate resources */
		    DBUG_PRINT("pixmap",
			    ("deallocating pixmap %s, %d colors freed", 
			     pptr->pmName, pptr->attribPtr->npixels));

		    /* Set pixmap to "None" => destroying will be save */
		    XtVaSetValues(w, resource, None, NULL);
		    XFreePixmap(dpy, death);

		    if (pptr->attribPtr->depth > 1) 
		        XFreeColors(dpy, cmap, 
				    pptr->attribPtr->pixels, 
				    pptr->attribPtr->npixels, 0);
		    if (pptr->mask) 
		        XFreePixmap(dpy,pptr->mask);

		    XpmFreeAttributes(pptr->attribPtr);

		    if (pptr == pixmapListHead)
		        {
			XtFree((char *)pixmapListHead);
			pixmapListHead = NULL;
		        }
		    else
		        { 
			for(cptr = pixmapListHead; 
			cptr->next != pptr; 
			cptr = cptr->next);
		    
			if (pptr->next == NULL)     /* last Pixmap in list */
			  cptr->next = NULL;
			else                      /* not last Pixmap in list */
			  cptr->next = pptr->next;

			XtFree((char *)pptr);
		        }
		    }
		}
	    }

	/* is the pixmap already in the cache? */
	for (pptr = pixmapListHead; pptr != NULL; pptr = pptr->next)
	  {
	  if (!strcmp(pptr->pmName, fname))
	       {
	       DBUG_PRINT("pixmap", ("Pixmap %s found in cache",fname));
	       pptr->count ++;

	       XtVaSetValues(w, resource, pptr->pm, NULL);
	       if (win)
	          XShapeCombineMask(dpy, win, ShapeBounding,
				    0, 0, pptr->mask, ShapeSet);

	       return;
	       }
	  }
    }
    /* If the new pixmap's filename is None, => don't create new entry. */

    if (!strcmp(fname, "None"))
	{
	DBUG_PRINT("pixmap",
		   ("Setting %s of %s to None", resource, XtName(w)));
	XtVaSetValues(w, resource, None, NULL);
	if (win) 
	  XShapeCombineMask(dpy,win,ShapeBounding,0,0,(Pixmap)NULL,ShapeSet);
	return;
	}
    if (!strcmp(fname, "Unspecified"))
	{
	DBUG_PRINT("pixmap",
		   ("Setting %s %s to Unspecified", XtName(w), resource));
	XtVaSetValues(w, resource, XtUnspecifiedPixmap, NULL);
	if (win) 
	  XShapeCombineMask(dpy,win,ShapeBounding,0,0,(Pixmap)NULL,ShapeSet);
	return;
	}
    if (!strcmp(fname, "ParentRelative"))
	{
	DBUG_PRINT("pixmap",
		   ("Setting %s %s to ParentRelative", XtName(w), resource));
	XtVaSetValues(w, resource, ParentRelative, NULL);
	if (win) 
	  XShapeCombineMask(dpy,win,ShapeBounding,0,0,(Pixmap)NULL,ShapeSet);
	return;
	}


    if (!(fn = wafeLocateBitmap(dpy, fname, True)))
	return;

    /* Now convert the new Pixmap-File, create a new element of the list 
         * and fill it with information.
         */
    attribPtr = (XpmAttributes *)XtCalloc(sizeof(XpmAttributes), sizeof(char));
    attribPtr->valuemask = XpmReturnPixels | XpmDepth | XpmReturnInfos;
    attribPtr->depth = depth;
    /* fprintf(stderr, "Wafe(changePixmap): calling xpmreadfile\n");*/
    returnVal = XpmReadFileToPixmap(dpy, RootWindow(dpy, screenNum), 
				    fn, &pixmap, &mask, attribPtr); 
    /*fprintf(stderr, "Wafe(changePixmap): xpmreadfile returned %d\n",returnVal);*/
    if (fn != fname) 
	XtFree(fn);

    if (returnVal == XpmSuccess)
	{
	if (!pixmapListHead)   /* First Pixmap */
	    {
	    cptr = 
		pixmapListHead = 
		    (PIXMAPINFOPTR)XtMalloc(sizeof(PIXMAPINFO));
	    pixmapListHead->next = NULL;
	    }
	else
	    {
	    for(cptr = pixmapListHead; cptr->next != NULL; cptr = cptr->next);
	    cptr->next = (PIXMAPINFOPTR)XtMalloc(sizeof(PIXMAPINFO));
	    cptr = cptr->next;
	    cptr->next = NULL;
	    }

	cptr->widget = w;
	cptr->pm = pixmap;
	cptr->mask = mask;
	cptr->count = 1;
	cptr->pmName = XtNewString(fname);
	cptr->attribPtr = attribPtr;

	DBUG_PRINT("pixmap", 
		   ("%d colorcells are used for %s", 
		    cptr->attribPtr->npixels, cptr->pmName));
     
	XtVaSetValues(w, resource, pixmap, NULL);

/*   fprintf(stderr, "changePixmap's window is %p\n", win);*/
/* do we really want to shape the pixmap? */

	if (win)
	      XShapeCombineMask(dpy, win, ShapeBounding,
		      0, 0, mask, ShapeSet);

	DBUG_PRINT("pixmap", ("New Pixmap was created"));
	return;
	}
    else
	{
	fprintf(stderr, 
		"Wafe(%s): Couldn't convert %s to pixmap\n", 
		"changePixmap",fname);
	XpmFreeAttributes(attribPtr);
	return;
	}
    }     

static void
setIconPixmap(w,fname)
Widget   w;
String   fname;
    {
    Window        iconWindow;
    Pixmap        pixmap, mask;
    int           iconWidth, iconHeight;
    XpmAttributes attrib;
    Display      *dpy   = XtDisplay(w);
    Window        root  = RootWindow(dpy, DefaultScreen(dpy));
    Pixel         bpix  = XBlackPixelOfScreen(DefaultScreenOfDisplay(dpy));

    attrib.valuemask = XpmReturnInfos;
    if (XpmReadFileToPixmap(dpy, root, fname, &pixmap, &mask, &attrib) 
	!= XpmSuccess)
	{
	fprintf(stderr, "Wafe(%s): Couldn't convert %s to pixmap\n",
		"setIconPixmap",fname);
	return;
	}
    
    iconWidth = attrib.width;
    iconHeight = attrib.height;
    iconWindow = XCreateSimpleWindow(dpy, root, 0, 0, 
				     iconWidth, iconHeight, 1, bpix, bpix);

    XSetWindowBackgroundPixmap(dpy, iconWindow, pixmap);
    XShapeCombineMask(dpy, iconWindow, ShapeBounding,
			  0, 0, mask, ShapeSet);
    
    XtVaSetValues(w, XtNiconWindow, iconWindow, NULL);
    return;
    }
#endif /* XPM */


#define done(address, type) \
        { (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t) address; }
#define	newDone(type, value) \
	{							\
	    if (toVal->addr != NULL) {				\
		if (toVal->size < sizeof(type)) {		\
		    toVal->size = sizeof(type);			\
		    return False;				\
		}						\
		*(type*)(toVal->addr) = (value);		\
	    }							\
	    else {						\
		static type static_val;				\
		static_val = (value);				\
		toVal->addr = (XtPointer)&static_val;		\
	    }							\
	    toVal->size = sizeof(type);				\
	    return True;					\
	}
               

Boolean
CvtStringToPixmapOrBitmap(dpy, args, num_args, fromVal, toVal,
		   converter_data)
Display *dpy;
XrmValuePtr args;
Cardinal *num_args;
XrmValuePtr fromVal;
XrmValuePtr toVal;
XtPointer *converter_data;
    {
    static Pixmap    pixmap;               /* static for cvt magic */
    String           name;
    Screen          *screen;
    int              screenNum;
    String           fn = NULL;
    unsigned int     width, height;
    int              xhot, yhot;
    unsigned char   *data;
    int              returnValue;
    Boolean          toPixmap = *num_args>1;
#ifdef XPM
    Pixmap           mask;
    Window           coreWin;
    XpmAttributes    attrib;
#endif

    pixmap = (Pixmap) NULL;
    name   = (String) fromVal->addr;
/*
    fprintf(stderr,"i am converting <%s> to %s\n",   
	  name, toPixmap ? "Pixmap" : "Bitmap");
 */
    screen = DefaultScreenOfDisplay(dpy);
    screenNum = DefaultScreen(dpy);
    
    if (strcmp(name, "None") == 0) 
        {
        pixmap = None;
        newDone(Pixmap,pixmap);
        }

    if (strcmp(name, "ParentRelative") == 0 && toPixmap) 
        {
        pixmap = ParentRelative;
        newDone(Pixmap,pixmap);
        }

    if (strcmp(name, "Unspecified") == 0 && toPixmap) 
        {
        pixmap = XtUnspecifiedPixmap;
        newDone(Pixmap,pixmap);
        }

    if (!(fn = wafeLocateBitmap(dpy, name,toPixmap)))
	return False;
    /* we have a valid filename fn */

    /* try to read file as bitmap file... */
    if (XmuReadBitmapDataFromFile(fn, &width, &height, &data,
				      &xhot, &yhot) == BitmapSuccess)
	{
	pixmap = XCreatePixmapFromBitmapData(dpy,
			RootWindowOfScreen(screen),
			(char *) data, width, height, 1, 0, 
			toPixmap?DefaultDepth(dpy, DefaultScreen(dpy)):1);
            /* in 0.95 we had:   DefaultDepth(dpy, DefaultScreen(dpy)));*/

	XFree((char *)data);

	if (name != fn) XtFree(fn);
	newDone(Pixmap,pixmap);
	}

#ifdef XPM    
    attrib.valuemask = XpmReturnPixels | XpmDepth | XpmReturnInfos;
    attrib.depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy));

    if ((returnValue = XpmReadFileToPixmap(dpy,RootWindow(dpy,screenNum),
					   fn, &pixmap, &mask, &attrib))
	!= XpmSuccess)
	{
	fprintf(stderr, "Wafe(convertPixmap): XPM-Error-Code: %d\n", 
		returnValue);
#else
	fprintf(stderr, "Wafe(convertPixmap): No XPM configured!\n");
#endif
	XtStringConversionWarning(name, toPixmap ? "Pixmap" : "Bitmap");

	if (name != fn) XtFree(fn);
	return False;
#ifdef XPM
	}
    else 
	{
/*
	fprintf(stderr,"pixmap=%p, width=%d, height=%d, addr=%p\n",pixmap,
		attrib.width,attrib.height,toVal->addr);
*/
	coreWin = *((Window *) args[0].addr);
/*	fprintf(stderr, "The window is %p\n", coreWin); */
	
	/* if toVal->addr is set we assume that the value comes
           from a resource file, in which case we can't assume that
           the core fields of the widget are already initialized; 
           coreWin will be wrong; Wafe never sets toVal->addr */
	if (coreWin && !toVal->addr) 
	    XShapeCombineMask(dpy, coreWin, ShapeBounding,
			      0, 0, mask, ShapeSet);

	if (name != fn) XtFree(fn);
	newDone(Pixmap,pixmap);
	}
#endif /* XPM */
    }

/* to keep knowledge about xpmConvertArgsPixmap etc local ...
 */
void
wafeRegisterXpmTypeConverter(resourceType, toPixmap)
char * resourceType;
Boolean toPixmap;
    { 
    if (toPixmap)
	XtSetTypeConverter(XtRString, 
			   resourceType, 
			   (XtTypeConverter)CvtStringToPixmapOrBitmap, 
			   xpmConvertArgsPixmap, 
			   2,
			   XtCacheByDisplay,
			   NULL);
    else
	XtSetTypeConverter(XtRString, 
			   resourceType, 
			   (XtTypeConverter)CvtStringToPixmapOrBitmap, 
			   xpmConvertArgsBitmap, 
			   1, 
			   XtCacheByDisplay, 
			   NULL);
    }


/* 
 * ******* end required file <xpm.inc> *******
 */
/* 
 * hint: XPM
 * void
 * setIconPixmap
 * 	in: ShellWidget			# Shell Widget (eg topLevel)
 * 	in: String			# pixmap file
 */
#ifdef XPM

static int 
cmd_setIconPixmap(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("setIconPixmap");  

     if (argc != 3) 
	 {
	 wafeArgcError("setIconPixmap","",2,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 =  name2WidgetOfClass(argv[1],shellWidgetClass,"Shell")))
          {
          wafeConvError("setIconPixmap","1",argv[1],"ShellWidget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

     setIconPixmap(localVar1,argv[2]);

     DBUG_RETURN (TCL_OK);
     }     

#endif

/* 
 * hint: XPM
 * void
 * changePixmap
 * 	in: Widget			# widget
 * 	in: String			# resource
 * 	in: String			# pixmap file
 */
#ifdef XPM

static int 
cmd_changePixmap(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;

     DBUG_ENTER("changePixmap");  

     if (argc != 4) 
	 {
	 wafeArgcError("changePixmap","",3,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("changePixmap","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

    /* no need to assign  << localVar2 = argv[2] >>  */ 

    /* no need to assign  << localVar3 = argv[3] >>  */ 

     changePixmap(localVar1,argv[2],argv[3]);

     DBUG_RETURN (TCL_OK);
     }     

#endif

/* 
 * hint: !PRER6
 * WidgetID (WidgetID)
 * XtHooksOfDisplay
 * 	in: XtDisplay(Widget)		# widget to determine display
 *         post: wafeCurrentAttribList=wafeMMgetAttribList((Widget)returnVar,True); wafeMMsetAttribList((Widget)returnVar); wafeCurrentAttribList = NULL;
 */
#ifndef PRER6

static int 
cmd_hooksOfDisplay(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     WidgetID returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("hooksOfDisplay");  

     if (argc != 2) 
	 {
	 wafeArgcError("hooksOfDisplay","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("hooksOfDisplay","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = (WidgetID) XtHooksOfDisplay(XtDisplay(localVar1));
     wafeCurrentAttribList=wafeMMgetAttribList((Widget)returnVar,True); wafeMMsetAttribList((Widget)returnVar); wafeCurrentAttribList = NULL;

     sprintf(conversionBuffer, "%ld", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     

#endif

/* 
 * MapState
 * mapState
 * 	in: Widget
 */

static int 
cmd_mapState(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     Widget localVar1;
     MapState returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("mapState");  

     if (argc != 2) 
	 {
	 wafeArgcError("mapState","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(localVar1 = (Widget) name2Widget(argv[1])))
          {
          wafeConvError("mapState","1",argv[1],"Widget");
          DBUG_RETURN (TCL_ERROR);
          }

     returnVar = mapState(localVar1);

          if (returnVar == 0) 
          strcpy(conversionBuffer, "IsUnmapped");
     else
     if (returnVar == 1) 
          strcpy(conversionBuffer, "IsUnviewable");
     else
     if (returnVar == 2) 
          strcpy(conversionBuffer, "IsViewable");


     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * XtWorkProcId
 * XtAppAddWorkProc
 * 	const: wafeAppContext 
 * 	const: workProc
 * 	in: XtNewString(String)		# tcl command
 */

static int 
cmd_addWorkProc(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     XtWorkProcId returnVar;
     char conversionBuffer[100];

     DBUG_ENTER("addWorkProc");  

     if (argc != 2) 
	 {
	 wafeArgcError("addWorkProc","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

    /* no need to assign  << localVar1 = argv[1] >>  */ 

     returnVar = XtAppAddWorkProc(wafeAppContext,workProc,XtNewString(argv[1]));

     sprintf(conversionBuffer, "%lu", returnVar);
     Tcl_SetResult(comInterpreter, conversionBuffer, TCL_VOLATILE);

     DBUG_RETURN (TCL_OK);
     }     


/* 
 * void 
 * XtRemoveWorkProc 
 * 	in: XtWorkProcId		# work proc ID

 */

static int 
cmd_removeWorkProc(clientData, comInterpreter, argc, argv)
ClientData    clientData;
Tcl_Interp   *comInterpreter;
int           argc;
char        **argv;
     {
     XtWorkProcId localVar1;

     DBUG_ENTER("removeWorkProc");  

     if (argc != 2) 
	 {
	 wafeArgcError("removeWorkProc","",1,argc);
	 DBUG_RETURN (TCL_ERROR);
         }

     if (!(sscanf(argv[1], "%lu", &localVar1)))
          {
          wafeConvError("removeWorkProc","1",argv[1],"XtWorkProcId");
          DBUG_RETURN (TCL_ERROR);
          }

     XtRemoveWorkProc(localVar1);

     DBUG_RETURN (TCL_OK);
     }     


#else
#endif

void
wafeInitialize_XtGen()
{
#ifdef XT
 wafeCreateWidgetCommand("ApplicationShell",applicationShellWidgetClass,XtAppCreateShell,False);
#ifdef LAYOUT
 wafeCreateWidgetCommand("Layout",layoutWidgetClass,NULL,False);
#endif
 wafeCreateWidgetCommand("OverrideShell",overrideShellWidgetClass,XtCreatePopupShell,True);
 wafeCreateWidgetCommand("TopLevelShell",topLevelShellWidgetClass,XtCreatePopupShell,True);
 wafeCreateWidgetCommand("TransientShell",transientShellWidgetClass,XtCreatePopupShell,True);
#ifdef XPM
 Tcl_SetVar(wafeInterpreter,"PACKAGES","XPM",TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
#endif
#ifdef LAYOUT
 Tcl_SetVar(wafeInterpreter,"PACKAGES","LAYOUT",TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
#endif
 qbusyWindow = WafePermStringToQuark("busyWindow");
 qString = WafePermStringToQuark("String");
 qCallback = WafePermStringToQuark("Callback");
 qPointer = WafePermStringToQuark("Pointer");
 qInt = WafePermStringToQuark("Int");
 qDimension = WafePermStringToQuark("Dimension");
 qCardinal = WafePermStringToQuark("Cardinal");
 qPosition = WafePermStringToQuark("Position");
 qFloat = WafePermStringToQuark("Float");
 qDouble = WafePermStringToQuark("Double");
 qPixel = WafePermStringToQuark("Pixel");
 qBoolean = WafePermStringToQuark("Boolean");
 qWidgetList = WafePermStringToQuark("WidgetList");
 qWidget = WafePermStringToQuark("Widget");
 XtSetTypeConverter(XtRString, XtRWidget,
	(XtTypeConverter)CvtStringToWidget, 
	NULL, 0, XtCacheNone, NULL);
 XtSetTypeConverter(XtRString, XtRCallback,
	(XtTypeConverter)CvtStringToCallback, 
	NULL, 0, XtCacheNone, NULL);
 XtSetTypeConverter(XtRString, XtRPointer,
	(XtTypeConverter)CvtStringToPointer, 
	NULL, 0, XtCacheNone, NULL);
 XtSetTypeConverter(XtRString, XtRWidgetList,
	(XtTypeConverter)CvtStringToWidgetList, 
	NULL, 0, XtCacheNone, NULL);
#ifndef PRER5
 XtSetTypeConverter(XtRString, XtRCardinal,
	(XtTypeConverter)XtCvtStringToInt, 
	NULL, 0, XtCacheNone, NULL);
#endif
 Tcl_CreateCommand(wafeInterpreter, "addTimeOut", cmd_addTimeOut, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "action", cmd_action, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "bell", cmd_bell, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "callActionProc", cmd_callActionProc, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "callCallbacks", cmd_callCallbacks, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "callback", cmd_callback, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "destroyWidget", cmd_destroyWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "fontHeight", cmd_fontHeight, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "flush", cmd_flush, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getApplicationResource", cmd_getApplicationResource, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getClass", cmd_getClass, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getResourceList", cmd_getResourceList, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getTypeOfAttribute", cmd_getTypeOfAttribute, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getValue", cmd_getValue, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "grabPointer", cmd_grabPointer, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "grabKeyboard", cmd_grabKeyboard, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "heightOfScreen", cmd_heightOfScreen, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "installAccelerators", cmd_installAccelerators, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "installAllAccelerators", cmd_installAllAccelerators, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "isWidget", cmd_isWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "lowerWindow", cmd_lowerWindow, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "manageChild", cmd_manageChild, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "mapWidget", cmd_mapWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "mergeResources", cmd_mergeResources, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "nameToWidget", cmd_nameToWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "parent", cmd_parent, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "popdown", cmd_popdown, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "popup", cmd_popup, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "popupChildren", cmd_popupChildren, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "popupSpringLoaded", cmd_popupSpringLoaded, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "processPendingEvents", cmd_processPendingEvents, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "raiseWindow", cmd_raiseWindow, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "realize", cmd_realize, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "realizeWidget", cmd_realizeWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "removeAllCallbacks", cmd_removeAllCallbacks, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "removeTimeOut", cmd_removeTimeOut, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "resolvePathname", cmd_resolvePathname, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "setBusy", cmd_setBusy, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "setKeyboardFocus", cmd_setKeyboardFocus, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "setSensitive", cmd_setSensitive, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "setValues", cmd_setValues, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "setWMProtocols", cmd_setWMProtocols, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "sync", cmd_sync, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "textWidth", cmd_textWidth, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "translateCoords", cmd_translateCoords, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "ungrabPointer", cmd_ungrabPointer, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "ungrabKeyboard", cmd_ungrabKeyboard, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "unmanageChild", cmd_unmanageChild, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "unmapWidget", cmd_unmapWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "unrealizeWidget", cmd_unrealizeWidget, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "waitForVariable", cmd_waitForVariable, NULL, NULL);
 /* alias */  Tcl_CreateCommand(wafeInterpreter,"widgetId",cmd_isWidget, NULL,NULL);
 Tcl_CreateCommand(wafeInterpreter, "widgetName", cmd_widgetName, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "widthOfScreen", cmd_widthOfScreen, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "window", cmd_window, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "disownSelection", cmd_disownSelection, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "getSelectionValue", cmd_getSelectionValue, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "ownSelection", cmd_ownSelection, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "fetchBytes", cmd_fetchBytes, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "convertSelection", cmd_convertSelection, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "storeBuffer", cmd_storeBuffer, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "fetchBuffer", cmd_fetchBuffer, NULL, NULL);
 /* alias */  Tcl_CreateCommand(wafeInterpreter,"sV",cmd_setValues, NULL,NULL);
 /* alias */  Tcl_CreateCommand(wafeInterpreter,"gV",cmd_getValue, NULL,NULL);
 wafeRegisterXpmTypeConverter(XtRBitmap, False);
 wafeRegisterXpmTypeConverter(XtRPixmap, True);
#ifdef XPM
 Tcl_CreateCommand(wafeInterpreter, "setIconPixmap", cmd_setIconPixmap, NULL, NULL);
#endif
#ifdef XPM
 Tcl_CreateCommand(wafeInterpreter, "changePixmap", cmd_changePixmap, NULL, NULL);
#endif
#ifndef PRER6
 Tcl_CreateCommand(wafeInterpreter, "hooksOfDisplay", cmd_hooksOfDisplay, NULL, NULL);
#endif
 Tcl_CreateCommand(wafeInterpreter, "mapState", cmd_mapState, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "addWorkProc", cmd_addWorkProc, NULL, NULL);
 Tcl_CreateCommand(wafeInterpreter, "removeWorkProc", cmd_removeWorkProc, NULL, NULL);

#else
#endif
}
