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

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/List.h>
#include "defs.h"
#include "externs.h"




void ToolInfo(widget,clientData,callData)
     Widget	widget;
     char	*clientData,*callData;
{
  int		wInfoX,wInfoY,wInfoWidth,wInfoHeight;
  int		borderWidth,depth,x,y,rootX,rootY;
  unsigned int	maskReturn;
  XEvent	event;
  Window	rootReturn,childReturn,subW;
  Tool		*tool, *GetToolFromCoords();
  Bool		returnVal;
  Arg		argList[2];
  
  if (infoMapped==True)						    /* Is the Info window showing already? */
    {
      XtSetArg(argList[0],XtNlabel,"Inspect A Tool");		    /* Change the Inspect button's label back to normal */
      XtSetValues(infoCommand,argList,1);
      XtPopdown(infoWidget);					    /* Yes, hide the Info window, and... */
      infoMapped = False;					    /* ...set the flag saying that the window is hidden */
      lastTool = NULL;						    /* Reset variable pointing to last tool looked at */
      return;
    }
  XGrabPointer(dpy,musicWin,False,ButtonPressMask,		    /* Allow input only on the music window now */
	       GrabModeAsync,GrabModeAsync,
	       None,mCursor,CurrentTime);
  XWindowEvent(dpy,musicWin,ButtonPressMask,&event);		    /* Wait until the user clicks in the music window */
  returnVal = XQueryPointer(dpy,musicWin,			    /* Determine where the mouse was clicked */
			    &rootReturn,&childReturn,
			    &rootX,&rootY,
			    &x,&y,
			    &maskReturn);
  XUngrabPointer(dpy,CurrentTime);				    /* Release exclusive hold of the mouse */
  if ((tool = GetToolFromCoords(x,y)) == NULL)			    /* Was a tool pointed to? */
    {
      printf("Not pointing to any tool.\n");			    /* Nope, print an error message */
      infoMapped = False;					    /* Set flag saying that the Info window is hidden */
      lastTool = NULL;						    /* Reset variable pointing to last tool looked at */
      return;
    }
  lastTool = tool;						    /* Set last tool looked at to this one */
  XGetGeometry(dpy,(Drawable)musicWin,&rootReturn,		    /* Find out where musicWin is in relation to RootWindow */
	       &wInfoX,&wInfoY,&wInfoWidth,&wInfoHeight,
	       &borderWidth,&depth);
  GetToolInfo(lastTool);					    /* Get info about each of this tool's parameter names */
  DrawInfoWin(lastTool);					    /* Draw the Info window */
  XtListChange(infoListWidget,toolInfoList,0,0,True);		    /* Use this new list for the InfoListWidget */
  XtMoveWidget(infoWidget,(Position)rootX,(Position)rootY);	    /* Move the Info Window close to the tool being inspected */
  XtPopup(infoWidget,XtGrabNone);				    /* Show the Info Window */
  XtSetArg(argList[0],XtNlabel,"Done Inspecting");		    /* Change the Inspect button's label */
  XtSetValues(infoCommand,argList,1);
  infoMapped = True;						    /* Set flag saying the Info window is showing. */
}								    /* end function ToolInfo */
