#include <Xm/Form.h>
#include <Vk/VkErrorDialog.h>
#include "DmInfoWindow.h"

#define HistoryMinutes 5

DmInfoWindow::DmInfoWindow(const char *name, const char *itemName,
			   Boolean plot)
  : VkSimpleWindow(name)
{
  chart = 0;
  info = 0;
  
  Widget mgr = XtVaCreateWidget("mgr", xmFormWidgetClass, 
				mainWindowWidget(), 
				XmNorientation, XmVERTICAL,
				NULL);
  
  if (plot)
  {
    chart = new DmStripChart("dmStripChart", mgr, itemName, HistoryMinutes);

    if (chart->error())
    {
      char errorBuf[errorMsgSize];
      chart->errorMsg(errorBuf);
      theErrorDialog->postAndWait(errorBuf);
      setError(errorBuf);
      return;
    }

  }
  else
    chart = NULL;

  info = new DmInfo("info", mgr, itemName, 500);

  if (plot)
  {
    XtVaSetValues(info->baseWidget(), 
		  XmNleftAttachment, XmATTACH_FORM,
		  XmNbottomAttachment, XmATTACH_FORM,
		  XmNrightAttachment, XmATTACH_FORM,
		  NULL);
    
    XtVaSetValues(chart->baseWidget(), 
		  XmNleftAttachment, XmATTACH_FORM,
		  XmNtopAttachment, XmATTACH_FORM,
		  XmNrightAttachment, XmATTACH_FORM,
		  XmNbottomAttachment, XmATTACH_WIDGET,
		  XmNbottomWidget, info->baseWidget(), 
		  NULL);
    
    chart->show();
  }
  else
  {
    XtVaSetValues(info->baseWidget(), 
		  XmNleftAttachment, XmATTACH_FORM,
		  XmNbottomAttachment, XmATTACH_FORM,
		  XmNrightAttachment, XmATTACH_FORM,
		  XmNtopAttachment, XmATTACH_FORM,
		  NULL);
  }
  
  info->show();
  addView(mgr);
  
  setTitle(itemName);
  setIconName(itemName);  
}


DmInfoWindow::~DmInfoWindow()
{
  delete chart;
  delete info; 
}
