static char AlarmPage_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/AlarmPage.cc,v 1.2 1998/12/18 21:12:05 oreilly Exp $";


/*
$Log: AlarmPage.cc,v $
Revision 1.2  1998/12/18 21:12:05  oreilly
Removed unused methods

Revision 1.1  1997/05/30 15:44:28  oreilly
Initial revision

Revision 1.4  97/04/30  19:25:04  19:25:04  oreilly (Thomas C. O'Reilly)
Put AlarmLists within PanedWindow manager widget

Revision 1.3  97/03/20  12:28:34  12:28:34  oreilly (Thomas C. O'Reilly)
*** empty log message ***

Revision 1.2  96/10/28  09:11:37  09:11:37  oreilly (Thomas C. O'Reilly)
*** empty log message ***

Revision 1.1  96/07/22  10:41:28  10:41:28  oreilly (Thomas C. O'Reilly)
First external release

*/
#include <Xm/Form.h>
#include <Xm/PanedW.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/List.h>
#include <Xm/Separator.h>
#include <string.h>
#include <Vk/VkInfoDialog.h>
#include "AlarmPage.h"
#include "TiburonApp.h"

AlarmPage::AlarmPage(const char *name, Widget parent, AlarmPopup **popups,
		       AlarmSetupWindow *setupWindow)
  : VkComponent(name)
{
  _baseWidget = XtCreateWidget(_name, xmPanedWindowWidgetClass, parent, NULL, 
			       0);

  installDestroyHandler();
  
  Widget listLabel[NAlarmLists];
  TiburonApp *app = (TiburonApp *)theApplication;
  
  _setupWindow = setupWindow;
  
  for (int p = 0; p < NAlarmLists; p++)
  {
    Widget mgr = XtVaCreateWidget("alarmPageMgr", xmFormWidgetClass, 
				  _baseWidget, NULL);
    
    _listPopup[p] = popups[p];
    
    Pixel foreground, background;

    app->priorityColors((Priority )(p + 1), &foreground, &background);
    
    char name[20];
    sprintf(name, "priority%dListLabel", p + 1);
    
    listLabel[p] = 
      XtVaCreateManagedWidget(name, xmLabelWidgetClass, mgr,
			      XmNleftAttachment, XmATTACH_FORM,
			      XmNtopAttachment, XmATTACH_FORM,
			      XmNforeground, foreground,
			      XmNbackground, background,
			      NULL);

    _attributeButton[p] = 
      XtVaCreateManagedWidget("attributes", 
			      xmPushButtonWidgetClass, mgr,
			      XmNleftAttachment, XmATTACH_WIDGET,
			      XmNleftWidget, listLabel[p],
			      XmNtopAttachment, XmATTACH_FORM,
			      NULL);

    XtAddCallback(_attributeButton[p], XmNactivateCallback,
		  &AlarmPage::attributeCallback, (XtPointer )this);


    _popupButton[p] = 
      XtVaCreateManagedWidget("popupList", 
			      xmPushButtonWidgetClass, mgr,
			      XmNleftAttachment, XmATTACH_WIDGET,
			      XmNleftWidget, _attributeButton[p],
			      XmNtopAttachment, XmATTACH_FORM,
			      NULL);

    XtAddCallback(_popupButton[p], XmNactivateCallback,
		  &AlarmPage::popupListCallback, (XtPointer )this);
    
    sprintf(name, "priority%dList", p + 1);
    
    alarmList[p] = new AlarmList(name, mgr, (Priority )(p + 1));

    XtVaSetValues(alarmList[p]->baseWidget(),
		  XmNtopAttachment, XmATTACH_WIDGET,
		  XmNtopWidget, _attributeButton[p],
		  XmNleftAttachment, XmATTACH_FORM,
		  XmNrightAttachment, XmATTACH_FORM,
		  XmNbottomAttachment, XmATTACH_FORM,
		  NULL);

    XtManageChild(mgr);
  }
}


void AlarmPage::clear()
{
  for (int p = 0; p < NAlarmLists; p++)
    alarmList[p]->clear();
}


void AlarmPage::popupListCallback(Widget w, XtPointer clientData,
				   XtPointer callData)
{
  AlarmPage *obj = (AlarmPage *)clientData;
  
  for (int p = 0; p < NAlarmLists; p++)
  {
    if (w == obj->_popupButton[p])
    {
      obj->_listPopup[p]->open();
      obj->_listPopup[p]->raise();
      obj->_listPopup[p]->show();
      break;
    }
  }
}


void AlarmPage::attributeCallback(Widget w, XtPointer clientData,
				   XtPointer callData)
{
  AlarmPage *obj = (AlarmPage *)clientData;
  
  for (int p = 0; p < NAlarmLists; p++)
  {
    if (w == obj->_attributeButton[p])
    {
      Alarm *alarm;
      if ((alarm = obj->alarmList[p]->selectedItem()) == NULL)
      {
	theInfoDialog->postAndWait("No alarm item selected");
	return;
      }
      obj->_setupWindow->open();
      obj->_setupWindow->show();
      obj->_setupWindow->raise();
      obj->_setupWindow->alarmEditor->selectItem(alarm->name());
      break;
    }
  }
}
