static char Layout_id[] = "$Header: Layout.cc,v 1.2 97/03/20 12:29:44 oreilly Exp $";


/*
$Log:	Layout.cc,v $
Revision 1.2  97/03/20  12:29:44  12:29:44  oreilly (Thomas C. O'Reilly)
..

Revision 1.1  96/07/22  10:42:04  10:42:04  oreilly (Thomas C. O'Reilly)
First external release

*/
#include "Layout.h"

Layout::Layout()
{
  defaults();
}


void Layout::defaults()
{
  for (int i = 0; i < 4; i++)
  {
    _attachment[i] = XmATTACH_NONE;
    _offset[i] = 0;
    _position[i] = 0;
    _widget[i] = NULL;
  }
  _absolute = FALSE;
}
  

void Layout::attach(Side side, DmGuiObject *obj, int offset, MBool opposite)
{
  attach(side, obj->baseWidget(), offset, opposite);
}


void Layout::attach(Side side, Widget w, int offset, MBool opposite)
{
  _absolute = FALSE;

  if (opposite)
    _attachment[side] = XmATTACH_OPPOSITE_WIDGET;
  else
    _attachment[side] = XmATTACH_WIDGET;

  _widget[side] = w;
  _offset[side] = offset;
}


void Layout::attachToEdge(Side side, int offset, MBool opposite)
{
  _absolute = FALSE;
  if (opposite)
    _attachment[side] = XmATTACH_OPPOSITE_FORM;
  else
    _attachment[side] = XmATTACH_FORM;

  _offset[side] = offset;
}


void Layout::position(Side side, int position)
{
  _absolute = FALSE;
  _attachment[side] = XmATTACH_POSITION;
  _position[side] = position;
}

void Layout::free(Side side)
{
  _absolute = FALSE;
  _attachment[side] = XmATTACH_NONE;
}


void Layout::absolutePosition(int x, int y)
{
  _absolute = TRUE;
  _x = x;
  _y = y;
}


int Layout::setArgs(Arg *args)
{
  static char *attachmentKeyword[] = 
  { XmNtopAttachment, XmNbottomAttachment, 
      XmNleftAttachment, XmNrightAttachment };

  static char *offsetKeyword[] = 
  { XmNtopOffset, XmNbottomOffset,
      XmNleftOffset, XmNrightOffset};
  
  static char *positionKeyword[] = 
  { XmNtopPosition, XmNbottomPosition,
      XmNleftPosition, XmNrightPosition};

  static char *widgetKeyword[] = 
  { XmNtopWidget, XmNbottomWidget,
      XmNleftWidget, XmNrightWidget};
  
  int n = 0;
  
  if (_absolute)
  {
    XtSetArg(args[n], XmNx, _x);
    n++;
    XtSetArg(args[n], XmNy, _y);
    n++;
    return n;
  }

  for (int i = 0; i < 4; i++)
  {
    XtSetArg(args[n], attachmentKeyword[i], _attachment[i]);
    n++;
    
    if (_attachment[i] == XmATTACH_WIDGET || 
	_attachment[i] == XmATTACH_OPPOSITE_WIDGET)
    {
      XtSetArg(args[n], widgetKeyword[i], _widget[i]);
      n++;
    }
    else if (_attachment[i] == XmATTACH_POSITION)
    {
      XtSetArg(args[n], positionKeyword[i], _position[i]);
      n++;
    }

    XtSetArg(args[n], offsetKeyword[i], _offset[i]);
    n++;
  }

  return n;
}

