#include <Xm/RowColumn.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include "PanTiltButton.h"
#include "TiburonApp.h"

#define dprintf if (debug) fprintf

PanTiltButton::PanTiltButton(const char *name, Widget parent, 
			     IviewDevice device, 
			     IviewControl *control,
			     IviewMonitor *monitor)
  : IviewDeviceGrabber(device, control, monitor), VkComponent(name)
{
  _baseWidget = XtVaCreateWidget(name, xmFormWidgetClass, parent, NULL);
  
  installDestroyHandler();
  
  _button =
    XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, _baseWidget,
			    XmNleftAttachment, XmATTACH_FORM,
			    XmNtopAttachment, XmATTACH_FORM,
			    NULL);

  XtVaGetValues(_baseWidget,
		XmNforeground, &_unusedForeground,
		XmNbackground, &_unusedBackground,
		NULL);
  

  TiburonApp *app = (TiburonApp *)theApplication;
  app->powerOnColors(&_usedForeground, &_usedBackground);
  app->faultColors(&_externUsedForeground, &_externUsedBackground);

  getIviewDeviceState();
}


PanTiltButton::~PanTiltButton()
{
}


int PanTiltButton::displayIviewDeviceState(State state)
{
  Pixel foreground, background;
  MBool debug = FALSE;

  dprintf(stderr, "PanTiltButton::displayState() - device=%d, ", _device);
  
  switch (state)
  {
    case Unused:
    dprintf(stderr, "Unused\n");
    foreground = _unusedForeground;
    background = _unusedBackground;
    break;
    
    case Used:
    dprintf(stderr, "Used\n");
    foreground = _usedForeground;
    background = _usedBackground;
    break;
    
    case ExternallyUsed:
    dprintf(stderr, "ExternallyUsed\n");
    foreground = _externUsedForeground;
    background = _externUsedBackground;
    break;

    default:
    dprintf(stderr, "Unknown!\n");
    fprintf(stderr, "PanTiltButton::setAppearance() - unknown state %d\n",
	    _state);
    
  }

    XtVaSetValues(_button,
		  XmNforeground, foreground,
		  XmNbackground, background,
		  NULL);
  return 0;
}








