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

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

void ChangeArg()
{
  int	sLen, whichArg;
  char	**destStr;
  char	*malloc();
  XtListReturnStruct	*listItem;
  
  listItem = XtListShowCurrent(infoListWidget);			    /* Get the listItem being highlighted */
  sLen = strlen(XtDialogGetValueString(inputDialogWidget));	    /* Get the length of the new string */
  whichArg = listItem->list_index / 2;				    /* Determine which tool argument was changed */
  
  switch (whichArg)
    {
    case 1:
      destStr = &lastTool->name;
      break;
    case 3:							    /* No case 2 -- handled by the callback routine */
      destStr = &lastTool->fName;
      break;
    case 4:
      destStr = &lastTool->arg1;
      break;
    case 5:
      destStr = &lastTool->arg2;
      break;
    case 6:
      destStr = &lastTool->arg3;
      break;
    case 7:
      destStr = &lastTool->arg4;
      break;
    case 8:
      destStr = &lastTool->arg5;
      break;
    case 9:
      destStr = &lastTool->arg6;
      break;
    case 10:
      destStr = &lastTool->arg7;
      break;
    case 11:
      destStr = &lastTool->arg8;
      break;
    default:
      printf("Not pointing to a changeable field.\n");
      return;
      break;
    }								    /* end switch whichArg... */
  if (*destStr == NULL)						    /* Did the destination string have a previous value? */
    *destStr = malloc(MAXSTRLEN);				    /* No, allocate space for the value just entered */
  bzero(*destStr,MAXSTRLEN);					    /* Erase previous contents of the destination string */
  strncpy(*destStr,XtDialogGetValueString(inputDialogWidget),sLen); /* Copy value entered to the appropriate tool parameter */
  changesMade = 1;						    /* Set flag saying that changes were made to the diagram */
  XtPopdown(inputWidget);
  DrawInfoWin(lastTool);
  XtListChange(infoListWidget,toolInfoList,0,0,True);		    /* Use the modified list for the InfoListWidget */
}								    /* end function ChangeArg */
