#include "appl.h"
#include "stdarg.h"

@implementation WDCApplication

- initWithName:(char*)aName managedBy:anObject
{
  return [self shouldNotImplement:_cmd];
}

- (WidgetClass)getWidgetClass
{
  return [self shouldNotImplement:_cmd];
}

- initWithName:(char*)string,...
{
  // Initialize the Intrinsics
  int n;
  char** argvptr;
  va_list alist;
  va_start(alist, string);
  n=va_arg(alist, int);
  argvptr=va_arg(alist, char**);
  va_end(alist);
  //printf("%d %s %s %s\n", n, argvptr[0], argvptr[1], argvptr[2]);
  [self setWidget:XtAppInitialize(&_app, string, NULL, 0, 
				  &n, argvptr, NULL, NULL, 0)];
  return self;
}

- realize;
{
  // Realize all widgets and enter the main event loop
  
  XtRealizeWidget([self getWidget]);
  return self;
}

- (XtAppContext)getApplicationContext;
{
  return _app;
}

/*
- (Widget)getWidget
{
  return _toplevel;
}
*/

- run
{  
  Position x, y;
  Dimension height, width, cx, cy;
  cx=600;
  cy=450;
  [self getArg:XmNx into:&x];
  [self getArg:XmNy into:&y];
  [[self getChildObject] getArg:XmNheight into:&height];
  [[self getChildObject] getArg:XmNwidth into:&width];
/*  
  if (GUI_DEBUG)
    printf("X position is %d and Y position is %d %d %d\n", x, y, width, height);
*/
  if (!x && !y)
    {
      [[self setArg:XmNx to:(char*)(cx-(width>>1))] 
       setArg : XmNy to :(char*)(cy-(height>>1))];  
    }
  [self realize];
  XtAppMainLoop([self getApplicationContext]);
  return self;
}

@end




