/*toplevel*wstripchart*geometry:		500x500
toplevel*wstripchart*bottomWidget:      wdivchange
toplevel*wdivchange*bottomWidget:       wdivszchange
toplevel*wdivszchange*bottomWidget:     wforcechange
toplevel*wforcechange*bottomWidget:     wkill
*/


#include<Xm/XmP.h>
#include<X11/StringDefs.h>
#include<X11/Shell.h>
#include<Xm/Form.h>
#include"Stripchart.h"
#include<Xm/PushB.h>
#include<stdio.h>

static XrmOptionDescRec options[] = {
        {"-margin_hgt","*stripchart.marginHeight",XrmoptionSepArg,NULL},
	{"-margin_wdth","*stripchart.marginWidth",XrmoptionSepArg,NULL},
	{"-num_xdiv","*stripchart.xDivisions",XrmoptionSepArg, NULL},
	{"-num_ydiv","*stripchart.yDivisions",XrmoptionSepArg,NULL},
	{"-xdiv_sz","*stripchart.xDivisionSize",XrmoptionSepArg,"NULL"},
	{"-ydiv_sz","*stripchart.yDivisionSize",XrmoptionSepArg,"NULL"},
	{"-xunits","*stripchart.xunits",XrmoptionSepArg,NULL},
	{"-yunits","*stripchart.yunits",XrmoptionSepArg,NULL},
	{"-xunit/div","*stripchart.xUnitsPerDivision",XrmoptionSepArg,NULL},
	{"-yunit/div","*stripchart.yUnitsPerDivision", XrmoptionSepArg, NULL},
      };


/************************************************************************/
/* The following are the callback procedures for the application of the */
/* stripchart widget.                                                      */
/************************************************************************/


void CallbackChangeDivButton(w,wstripchart,temp)

Widget 	w;
caddr_t wstripchart, temp;

{
  
  int	i = 0;
  Arg	arglist[5];

  XtSetArg(arglist[i], XtNxDivisions, 15); i++;
  XtSetArg(arglist[i], XtNyDivisions, 20); i++;
  XtSetValues(wstripchart,arglist,i);
  
} /** end CallbackChangeDivButton **/


/***********************************/
void CallbackKillButton(w,thing,thing2)

Widget w;
caddr_t thing, thing2;

{
  exit(0);
} /** end CallbackKillButton **/


/************************************/
void CallbackChangeDivSzButton(w,wstripchart,temp)

Widget w;
caddr_t wstripchart,temp;

{
  int i = 0;
  Arg arglist[5];

  XtSetArg(arglist[i], XtNxDivisionSize, 5); i++;
  XtSetArg(arglist[i], XtNyDivisionSize, 30); i++; 
  XtSetValues(wstripchart,arglist,i);

} /** end CallbackChangeDivSzButton **/


/************************************/
void CallbackChangeForceSqButton(w,wstripchart,temp)

Widget w;
caddr_t wstripchart,temp;

{
  int i = 0;
  Arg arglist[5];
 
  XtSetArg(arglist[i], XtNforceSquare, "FALSE"); i++;
  XtSetValues(wstripchart,arglist,i);

} /** end CallbackChangeForceSqButton **/


/**********************************************************************/
/* The main program for the application and the XtMainLoop            */
/**********************************************************************/

/*****************************************************
 * Widget layout:
 *
 * Top level shell "toplevel"
 *   form widget "form"
 *      stripchart widget "stripchart"
 *      push button "Change # x=15 y=20"
 *      push button "Dv Sz x=5mm y=30mm"
 *      push button "To make ForceSquare flase"
 *      push button "killbutton"
 ******************************************************/

main(argc,argv)
     int argc;
     char *argv[];

{

  Widget toplevel;
  Widget wform;
  Widget wstripchart;
  Widget wdivchange, wdivszchange, wforcechange, wkill;
  Arg arglist[5];
  int i;


  /** creation of the toplevel widget.  This is the parent of pane  **/


  toplevel = XtInitialize("main","AtStripchart",options,XtNumber(options),
			  &argc, argv);
  
 
  /** Creation of the form widget.  This is the child of toplevel   **/
  /** and the parent of all the other widgets in this application   **/
  i = 0;
  XtSetArg(arglist[i], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); i++;
  XtSetArg(arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  XtSetArg(arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  XtSetArg(arglist[i], XmNresizePolicy, XmRESIZE_ANY); i++;
  wform = XtCreateManagedWidget("form",xmFormWidgetClass,toplevel,
			       arglist, i);

  /** now to create children of the form widget **/

  /** creation of the stripchart widget (and callbacks) **/

  i=0;
/*  XtSetArg(arglist[i], XtNheight, 500); i++;
  XtSetArg(arglist[i], XtNwidth, 500); i++;
  */  
  wstripchart = XtCreateManagedWidget("stripchart",atstripchartWidgetClass,
				      wform, arglist,i);
  
  /** creation of the Change Divisions (and its callbacks) **/

  i = 0;

  XtSetArg(arglist[i], XmNheight, 15); i++;
  wdivchange = XtCreateManagedWidget("Change # Divs x=15 y=20",
				     xmPushButtonWidgetClass, 
				     wform, arglist, i);

  XtAddCallback(wdivchange,  XmNactivateCallback, CallbackChangeDivButton, 
					(caddr_t)wstripchart);



  /** creation of Change Division Size Button **/

  i = 0;

  XtSetArg(arglist[i], XmNheight, 15); i++;
  wdivszchange = XtCreateManagedWidget("Div Sz x=5mm y=30mm",
			    xmPushButtonWidgetClass, wform, arglist, i);

  XtAddCallback(wdivszchange,  XmNactivateCallback, 
		CallbackChangeDivSzButton, (caddr_t)wstripchart);


  /** creation of the Change Force Square Button **/

  i = 0;

  XtSetArg(arglist[i], XmNheight, 15); i++;
  wforcechange = XtCreateManagedWidget("To make ForceSquare false",
		           xmPushButtonWidgetClass, wform, arglist, i);

  XtAddCallback(wforcechange, XmNactivateCallback, 
		CallbackChangeForceSqButton, (caddr_t)wstripchart);



  /** creation of the Kill Widget button (and its callback) **/

  i = 0;

  XtSetArg(arglist[i], XmNheight, 15); i++;
  wkill = XtCreateManagedWidget("killbutton",xmPushButtonWidgetClass, 
				wform, arglist, i);

  XtAddCallback(wkill,  XmNactivateCallback, CallbackKillButton, NULL);


  /** The infinite loop that processes events **/

  XtRealizeWidget(toplevel);
  XtMainLoop();

}  /** end main() **/


