#include<Xm/XmP.h>
#include<X11/StringDefs.h>
#include<X11/Shell.h>
#include<Xm/PanedW.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            */
/**********************************************************************/

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

{

  Widget wbox, toplevel, wstripchart, wbar, wdivchange;
  Widget 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 pane widget.  This is the child of toplevel   **/
  /** and the parent of all the other widgets in this application   **/

  wbox = XtCreateManagedWidget("pane",xmPanedWindowWidgetClass,toplevel,
			       NULL,0);


  /** 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,
				      wbox, 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, 
				     wbox, 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, wbox, 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, wbox, 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, 
				wbox, arglist, i);

  XtAddCallback(wkill,  XmNactivateCallback, CallbackKillButton, NULL);


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

  XtRealizeWidget(toplevel);
  XtMainLoop();

}  /** end main() **/


