/*==================================================================
  ==================================================================
  ==	XMusic -- An Interactive Interface to Csound		  ==
  ==       Copyright (C) 1988 by George D. Drapeau                ==
  ==                  All Rights Reserved                         ==
  ==================================================================
  ==================================================================
*/
/* $Log:	inputWin.c,v $
 * Revision 1.2  89/08/06  18:13:06  drapeau
 * Cleaned up the code for the first X11 release.
 *  */

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Command.h>
#include <X11/Dialog.h>
#include "defs.h"
#include "externs.h"
#include <string.h>

void CreateInputWindow(label,value,callback,callbackData)
     String		label,value;
     XtCallbackProc	callback;
     char		*callbackData;
{
  Window		rootReturn,childReturn;
  int			rootX,rootY,x,y;
  unsigned int		maskReturn;
  Bool			returnVal;
  Widget		inputCancelWidget;
  Arg			argList[4];
  static String		dialogTranslations = "#override\n <Key>Return: AcceptInput()\n";
  XtTranslations	translationTable;

  returnVal = XQueryPointer(dpy,musicWin,			    /* Find out where the user clicked the mouse */
			    &rootReturn,&childReturn,
			    &rootX,&rootY,
			    &x,&y,
			    &maskReturn);
  XtSetArg(argList[0],XtNinput,True);
  XtSetArg(argList[1],XtNx,rootX);
  XtSetArg(argList[2],XtNy,rootY);
  XtSetArg(argList[3],XtNallowShellResize,True);
  inputWidget		= XtCreatePopupShell("Input",		    /* Create a Popup shell for the Input window */
					     transientShellWidgetClass,
					     topLevelShell,
					     argList,XtNumber(argList));
  XtSetArg(argList[0],XtNlabel,label);
  XtSetArg(argList[1],XtNvalue,value);
  inputDialogWidget 	= XtCreateManagedWidget("InputDialog",	    /* Create a Dialog widget to prompt for input */
						dialogWidgetClass,
					        inputWidget,
						argList,2);
  XtSetArg(argList[0],XtNlabel,"Enter");
  inputEnterWidget	= XtCreateManagedWidget("Enter",	    /* Create a 'Enter' command for the Input Window */
						commandWidgetClass,
						inputDialogWidget,
						argList,1);
  XtSetArg(argList[0],XtNlabel,"Cancel");
  inputCancelWidget	= XtCreateManagedWidget("Cancel",	    /* Create a 'Cancel' command for the Input Window */
						commandWidgetClass,
						inputDialogWidget,
						argList,1);
  XtAddCallback(inputEnterWidget,XtNcallback,AcceptInput,NULL);	    /* Add callback functions to the Enter and Cancel buttons */
  XtAddCallback(inputEnterWidget,XtNcallback,callback,callbackData); /* 1st callback is so pressing Return activates callbacks */
  XtAddCallback(inputEnterWidget,XtNcallback,			    /* There are 3 callbacks for the enter button... */
		DestroyInputWin,NULL);				    /* ...This one destroys the Input widget & children */
  XtAddCallback(inputCancelWidget,XtNcallback,CancelInput,NULL);
  translationTable = XtParseTranslationTable(dialogTranslations);
  XtOverrideTranslations(XtNameToWidget(inputDialogWidget,"value"), /* Make pressing Return do the same as pressing Enter button */
			 translationTable);
  XtRealizeWidget(inputWidget);
  XtPopup(inputWidget,XtGrabNone);
}								    /* end function CreateInputWindow */
