/* Motif WidgetSet category for Implemenation of Form class
 *
 * Copyright (C)  1993, 1994  The Board of Trustees of  
 * The Leland Stanford Junior University.  All Rights Reserved.
 *
 * Authors: Scott Francis, Fred Harris, Paul Kunz, 
 *          Imran Qureshi, and Libing Wang
 *
 * This file is part of an Objective-C class library for X/Motif
 *
 * xmForm.m,v 1.4 1995/04/15 00:42:32 pfkeb Exp
 */

#include "Form.h"
#include "xtResponder.h"

#include "Application.h"
#include "FormCell.h"
#include "Window.h"
#include "Motif.h"
#include <Xm/Text.h>
#include <Xm/LabelG.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>

#include <objc/List.h>

typedef struct {
    XFontStruct     *font;
    XmFontList      fontlist;
    XmString        titleStr;
    Dimension       strWidth;
    Dimension       strHeight;
} title_data, *title_data_ptr;

static XtResource resources[] = {
  {XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *),
     XtOffset(title_data_ptr, font), XtRString, "Fixed"  },
};

char *FormInstanceName(void)
{
    return "Form";
} 

@implementation Form(WidgetSet)

- _calcSize
{
    int		i, count;
    char 	*str;
    title_data	data;

    XtGetApplicationResources([window _shell], &data, resources,
                              XtNumber(resources), NULL, 0);
    data.fontlist = XmFontListCreate(data.font, XmSTRING_DEFAULT_CHARSET);
    count = [cellList count];
    for (i = 0; i < count; i++) {
      str = (char *)[[cellList objectAt:i] title];
      data.titleStr = XmStringCreate(str, XmSTRING_DEFAULT_CHARSET);
      XmStringExtent(data.fontlist, data.titleStr, 
		    &data.strWidth, &data.strHeight);
      if (data.strWidth > maxTitleWidth)
          maxTitleWidth = (NXCoord)data.strWidth;
    }

    return self;
}

- _setEntryWidth:(NXCoord)width
{
    [self _addArg:XmNwidth:width];
    return self;
}

@end
