/* Generated by wbuild from "Group.w"
** (generator version $Revision: 2.5 $ of $Date: 94/07/29 15:31:49 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <Xmg/GroupP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 14 "Group.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 20 "Group.w"
static void calc_geometry(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 46 "Group.w"
static void set_geometry(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 85 "Group.w"
static void change_managed(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 100 "Group.w"
static XtGeometryResult  geometry_manager(
#if NeedFunctionPrototypes
Widget ,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);
#line 117 "Group.w"
static XtGeometryResult  query_geometry(
#if NeedFunctionPrototypes
Widget,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);

static XtResource resources[] = {
#line 4 "Group.w"
{XtNnumCols,XtCNumCols,XtRInt,sizeof(((GroupRec*)NULL)->group.numCols),XtOffsetOf(GroupRec,group.numCols),XtRImmediate,(XtPointer)1 },
#line 5 "Group.w"
{XtNmargin,XtCMargin,XtRInt,sizeof(((GroupRec*)NULL)->group.margin),XtOffsetOf(GroupRec,group.margin),XtRImmediate,(XtPointer)1 },
#line 6 "Group.w"
{XtNspace,XtCSpace,XtRInt,sizeof(((GroupRec*)NULL)->group.space),XtOffsetOf(GroupRec,group.space),XtRImmediate,(XtPointer)1 },
};

GroupClassRec groupClassRec = {
{ /* core_class part */
(WidgetClass) &compositeClassRec,
"Group",
sizeof(GroupRec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
NULL,
0,
resources,
3,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
XtInheritResize,
XtInheritExpose,
NULL,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
NULL,
query_geometry,
XtInheritDisplayAccelerator,
NULL 
},
{ /* composite_class part */
geometry_manager,
change_managed,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* Group_class part */
calc_geometry,
set_geometry,
},
};
WidgetClass groupWidgetClass = (WidgetClass) &groupClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  GroupWidgetClass c = (GroupWidgetClass) class;
  GroupWidgetClass super;
  static CompositeClassExtensionRec extension_rec = {
    NULL, NULLQUARK, XtCompositeExtensionVersion,
    sizeof(CompositeClassExtensionRec), True};
  CompositeClassExtensionRec *ext;
  ext = (XtPointer)XtMalloc(sizeof(*ext));
  *ext = extension_rec;
  ext->next_extension = c->composite_class.extension;
  c->composite_class.extension = ext;
  if (class == groupWidgetClass) return;
  super = (GroupWidgetClass)class->core_class.superclass;
  if (c->group_class.calc_geometry == XtInherit_calc_geometry)
    c->group_class.calc_geometry = super->group_class.calc_geometry;
  if (c->group_class.set_geometry == XtInherit_set_geometry)
    c->group_class.set_geometry = super->group_class.set_geometry;
}
#line 14 "Group.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
  ((GroupWidget)self)->group.max_width = 0;
  ((GroupWidget)self)->group.max_height = 0;
}
#line 20 "Group.w"
/*ARGSUSED*/static void calc_geometry(self)Widget self;
{
  int					i;
  int					width;
  int					height;
  
  width = height = 0;
  for (i = 0;i < ((GroupWidget)self)->composite.num_children;i++)
    {
      Widget				child;
      int				dim;
      
      child = ((GroupWidget)self)->composite.children[i];
      if (XtIsManaged(child) == False)
	continue;
      dim = ((GroupWidget)child)->core.width + 2 * ((GroupWidget)child)->core.border_width;
      if (dim > width)
	width = dim;
      dim = ((GroupWidget)child)->core.height + 2 * ((GroupWidget)child)->core.border_width;
      if (dim > height)
	height = dim;
    }
  ((GroupWidget)self)->group.max_width = width;
  ((GroupWidget)self)->group.max_height = height;
}
#line 46 "Group.w"
/*ARGSUSED*/static void set_geometry(self)Widget self;
{
  Position				x;
  Position				y;
  int					i;
  int					j;
  int					index;

  x = y = 0;
  index = 0;
  for (i = 0;;i++)
    for (j = 0;j < ((GroupWidget)self)->group.numCols;j++)
      {
	Widget				child;
	Dimension			width;
	Dimension			height;
	
	while (1)
	  {
	    if (index >= ((GroupWidget)self)->composite.num_children)
	      return;
	    child = ((GroupWidget)self)->composite.children[index++];
	    if (((GroupWidget)child)->core.managed == False)
	      continue;
	    x = (((GroupWidget)self)->group.max_width + ((GroupWidget)self)->group.space) * j + ((GroupWidget)self)->group.margin;
	    y = (((GroupWidget)self)->group.max_height + ((GroupWidget)self)->group.space) * i + ((GroupWidget)self)->group.margin;
	    width = ((GroupWidget)self)->group.max_width - 2 * ((GroupWidget)child)->core.border_width;
	    height = ((GroupWidget)self)->group.max_height - 2 * ((GroupWidget)child)->core.border_width;
	    XtConfigureWidget(child,
			      x,
			      y,
			      width,
			      height,
			      ((GroupWidget)child)->core.border_width);
	    break;
	  }
      }
}
#line 85 "Group.w"
/*ARGSUSED*/static void change_managed(self)Widget self;
{
  XtWidgetGeometry			request;
  XtWidgetGeometry			reply;
  
  calc_geometry(self);
  set_geometry(self);
  query_geometry(self,
		 NULL,
		 &request);
  XtMakeGeometryRequest(self,
			&request,
			&reply);
}
#line 100 "Group.w"
/*ARGSUSED*/static XtGeometryResult  geometry_manager(child,request,reply)Widget  child;XtWidgetGeometry * request;XtWidgetGeometry * reply;
{ Widget self = XtParent(child); {
  if (request->request_mode & ~(XtCWQueryOnly|CWWidth|CWHeight))
    return (XtGeometryNo);
  reply->width = ((GroupWidget)self)->group.max_width - 2 * ((GroupWidget)child)->core.border_width;
  reply->height = ((GroupWidget)self)->group.max_height - 2 * ((GroupWidget)child)->core.border_width;
  reply->request_mode = CWWidth|CWHeight;
  if (!(request->request_mode & XtCWQueryOnly))
    {
      XtResizeWidget(child,
		     reply->width,
		     reply->height,
		     ((GroupWidget)child)->core.border_width);
    }
  return (XtGeometryAlmost);
}
}
#line 117 "Group.w"
/*ARGSUSED*/static XtGeometryResult  query_geometry(self,request,reply)Widget self;XtWidgetGeometry * request;XtWidgetGeometry * reply;
{
  int					i;
  int					count;

  count = 0;
  for (i = 0;i < ((GroupWidget)self)->composite.num_children;i++)
    if (XtIsManaged(((GroupWidget)self)->composite.children[i])) 
      count++;
  calc_geometry(self);
  reply->width = ((GroupWidget)self)->group.max_width * ((GroupWidget)self)->group.numCols + 
    (((GroupWidget)self)->group.numCols - 1) * ((GroupWidget)self)->group.space + 
    2 * ((GroupWidget)self)->group.margin;
  reply->height = ((GroupWidget)self)->group.max_height * ((count + ((GroupWidget)self)->group.numCols - 1) / ((GroupWidget)self)->group.numCols) +
    (((count + ((GroupWidget)self)->group.numCols - 1) / ((GroupWidget)self)->group.numCols) - 1) * ((GroupWidget)self)->group.space + 
    2 * ((GroupWidget)self)->group.margin;
  reply->request_mode = CWWidth|CWHeight;
  return (XtGeometryAlmost);
}
