#include <stdio.h>

#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>

#include "mygraph.h"
#include "mydebug.h"
#include "point.h"
#include "line.h"

int DEBUG;

void draw_line_callback (Widget where, XtPointer client_data, XtPointer call_data);

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

    XtAppContext  app_context;
    Widget        toplevel,drawing_board,line_button,main_form;
    char  *       myclassname = "Line";
    Arg           args[10];
    int           nargs=0;
    XmString      astring;
 
    DEBUG =  NODEBUG;
   
    toplevel = XtAppInitialize(&app_context,myclassname,NULL,0,
                &argc,argv,NULL,args,nargs);

    main_form = XtCreateManagedWidget("form",xmFormWidgetClass,toplevel,NULL,0);

    nargs=0;

    astring = XmStringCreateSimple("Draw A Line");
    XtSetArg(args[nargs],XmNlabelString,astring); nargs++;

    line_button =  XtCreateManagedWidget("line_button",xmPushButtonWidgetClass,
	       main_form, args, nargs);

    nargs=0;
    XtSetArg(args[nargs],XmNwidth,400); nargs++;
    XtSetArg(args[nargs],XmNheight,400); nargs++;
    XtSetArg(args[nargs],XmNtopWidget,line_button); nargs++;
    XtSetArg(args[nargs],XmNtopAttachment,XmATTACH_WIDGET); nargs++;

    drawing_board = XtCreateManagedWidget("msgs",xmDrawingAreaWidgetClass,
               main_form, args,nargs);

    XtAddCallback(line_button,XmNactivateCallback,draw_line_callback,
		     drawing_board);
    
    XtRealizeWidget(toplevel);
 
    XtAppMainLoop(app_context);
}

void draw_line_callback 
(Widget where, XtPointer client_data, XtPointer call_data) {

    line  aline;

    read_line(&aline);
    print_line (aline);
    dc_drawline (aline,client_data);
}
