/* Generated by wbuild from "RadioBtn.w"
** (generator version $Revision: 3.0 $ of $Date: 95/08/30 17:50:38 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 290 "RadioBtn.w"
#include <assert.h>
#line 291 "RadioBtn.w"
#include <ctype.h>
#line 292 "RadioBtn.w"
#include <stdio.h>
#line 293 "RadioBtn.w"
#include <string.h>
#include <./RadioBtnP.h>
#line 72 "RadioBtn.w"
static void press(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);

static XtActionsRec actionsList[] = {
{"press", press},
};

static char defaultTranslations[] = "\
<Btn1Down>,<Btn1Up>: press() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 165 "RadioBtn.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 176 "RadioBtn.w"
static void destroy(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 185 "RadioBtn.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 223 "RadioBtn.w"
static XtGeometryResult  query_geometry(
#if NeedFunctionPrototypes
Widget,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);
#line 234 "RadioBtn.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 96 "RadioBtn.w"
static void make_gc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 116 "RadioBtn.w"
static void compute_line_height(
#if NeedFunctionPrototypes
Widget,int *,int *
#endif
);
#line 128 "RadioBtn.w"
static void compute_size(
#if NeedFunctionPrototypes
Widget,Dimension *,Dimension *
#endif
);
#line 96 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 96 "RadioBtn.w"
static void make_gc(Widget self)
#else
#line 96 "RadioBtn.w"
static void make_gc(self)Widget self;
#endif
#line 97 "RadioBtn.w"
{
	XtGCMask mask, dynmask, dontcaremask;
	XGCValues values;

	values.foreground=((RadioBtnWidget)self)->radioBtn.color;
	values.background=((RadioBtnWidget)self)->core.background_pixel;
	values.font=((RadioBtnWidget)self)->radioBtn.font->fid;
	dynmask = GCForeground | GCBackground | GCFont;
	dontcaremask = GCJoinStyle | GCFillRule | GCTile
		| GCTileStipXOrigin | GCTileStipYOrigin | GCDashOffset | GCDashList
		| GCStipple | GCGraphicsExposures | GCArcMode | GCLineWidth | GCClipMask;
	mask=0;
	((RadioBtnWidget)self)->radioBtn.gc=XtAllocateGC(self,((RadioBtnWidget)self)->core.depth,mask,&values,dynmask,dontcaremask);
}
#line 116 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 116 "RadioBtn.w"
static void compute_line_height(Widget self,int * ma,int * md)
#else
#line 116 "RadioBtn.w"
static void compute_line_height(self,ma,md)Widget self;int * ma;int * md;
#endif
#line 117 "RadioBtn.w"
{
	XFontStruct *f;

	*ma=0, *md=0;
	f=((RadioBtnWidget)self)->radioBtn.font;
	*ma =  ((RadioBtnWidget)self)->radioBtn.circleSize > f->ascent ? ((RadioBtnWidget)self)->radioBtn.circleSize : f->ascent;
	*md =  f->descent;
}
#line 128 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 128 "RadioBtn.w"
static void compute_size(Widget self,Dimension * wd,Dimension * ht)
#else
#line 128 "RadioBtn.w"
static void compute_size(self,wd,ht)Widget self;Dimension * wd;Dimension * ht;
#endif
#line 129 "RadioBtn.w"
{
	int ma, md, num_buttons, w, maxw;
	char *cp, *start, *end;
	
	if (((RadioBtnWidget)self)->radioBtn.buttons != NULL) {
		num_buttons = 1;
		for (cp=((RadioBtnWidget)self)->radioBtn.buttons; *cp!='\0'; cp++)
			if (*cp=='|') num_buttons++;
		}
	compute_line_height(self, &ma, &md);
	*ht = (((RadioBtnWidget)self)->radioBtn.internalOffset)*2 + (ma + md)*num_buttons + 
			((RadioBtnWidget)self)->radioBtn.verticalGap*(num_buttons-1);
		
	start=((RadioBtnWidget)self)->radioBtn.buttons;
	end=((RadioBtnWidget)self)->radioBtn.buttons; 
	while ((*end != '|') && (*end != '\0'))	end++;
	
	/* find maximum button label length */
	maxw=0;
	while (*start != '\0') {
		w = XTextWidth(((RadioBtnWidget)self)->radioBtn.font,start,end-start); 
		if (w>maxw) maxw=w;

		start=end;
		if (*start == '|') start++;
		end=start;
		while ((*end != '|') && (*end != '\0'))	end++;
		}
	*wd = maxw + (((RadioBtnWidget)self)->radioBtn.internalOffset)*2 + ((RadioBtnWidget)self)->radioBtn.circleSize + ((RadioBtnWidget)self)->radioBtn.circleGap;
}

static XtResource resources[] = {
#line 13 "RadioBtn.w"
{XtNbuttons,XtCButtons,XtRString,sizeof(((RadioBtnRec*)NULL)->radioBtn.buttons),XtOffsetOf(RadioBtnRec,radioBtn.buttons),XtRImmediate,(XtPointer)NULL },
#line 17 "RadioBtn.w"
{XtNfont,XtCFont,XtRFontStruct,sizeof(((RadioBtnRec*)NULL)->radioBtn.font),XtOffsetOf(RadioBtnRec,radioBtn.font),XtRString,(XtPointer)XtDefaultFont },
#line 21 "RadioBtn.w"
{XtNcolor,XtCColor,XtRPixel,sizeof(((RadioBtnRec*)NULL)->radioBtn.color),XtOffsetOf(RadioBtnRec,radioBtn.color),XtRString,(XtPointer)XtDefaultForeground },
#line 25 "RadioBtn.w"
{XtNinternalOffset,XtCInternalOffset,XtRDimension,sizeof(((RadioBtnRec*)NULL)->radioBtn.internalOffset),XtOffsetOf(RadioBtnRec,radioBtn.internalOffset),XtRImmediate,(XtPointer)2 },
#line 29 "RadioBtn.w"
{XtNcircleSize,XtCCircleSize,XtRDimension,sizeof(((RadioBtnRec*)NULL)->radioBtn.circleSize),XtOffsetOf(RadioBtnRec,radioBtn.circleSize),XtRImmediate,(XtPointer)11 },
#line 33 "RadioBtn.w"
{XtNcircleGap,XtCCircleGap,XtRDimension,sizeof(((RadioBtnRec*)NULL)->radioBtn.circleGap),XtOffsetOf(RadioBtnRec,radioBtn.circleGap),XtRImmediate,(XtPointer)9 },
#line 37 "RadioBtn.w"
{XtNverticalGap,XtCVerticalGap,XtRDimension,sizeof(((RadioBtnRec*)NULL)->radioBtn.verticalGap),XtOffsetOf(RadioBtnRec,radioBtn.verticalGap),XtRImmediate,(XtPointer)9 },
#line 41 "RadioBtn.w"
{XtNselected,XtCSelected,XtRInt,sizeof(((RadioBtnRec*)NULL)->radioBtn.selected),XtOffsetOf(RadioBtnRec,radioBtn.selected),XtRImmediate,(XtPointer)0 },
#line 47 "RadioBtn.w"
{XtNradioCallback,XtCRadioCallback,XtRCallback,sizeof(((RadioBtnRec*)NULL)->radioBtn.radioCallback),XtOffsetOf(RadioBtnRec,radioBtn.radioCallback),XtRImmediate,(XtPointer)NULL },
#line 51 "RadioBtn.w"
{XtNborderWidth,XtCBorderWidth,XtRDimension,sizeof(((RadioBtnRec*)NULL)->core.border_width),XtOffsetOf(RadioBtnRec,core.border_width),XtRImmediate,(XtPointer)0 },
};

RadioBtnClassRec radioBtnClassRec = {
{ /* core_class part */
/* superclass   	*/  (WidgetClass) &coreClassRec,
/* class_name   	*/  "RadioBtn",
/* widget_size  	*/  sizeof(RadioBtnRec),
/* class_initialize 	*/  NULL,
/* class_part_initialize*/  _resolve_inheritance,
/* class_inited 	*/  FALSE,
/* initialize   	*/  initialize,
/* initialize_hook 	*/  NULL,
/* realize      	*/  XtInheritRealize,
/* actions      	*/  actionsList,
/* num_actions  	*/  1,
/* resources    	*/  resources,
/* num_resources 	*/  10,
/* xrm_class    	*/  NULLQUARK,
/* compres_motion 	*/  False ,
/* compress_exposure 	*/  XtExposeCompressMultiple |XtExposeGraphicsExposeMerged ,
/* compress_enterleave 	*/  False ,
/* visible_interest 	*/  False ,
/* destroy      	*/  destroy,
/* resize       	*/  XtInheritResize,
/* expose       	*/  expose,
/* set_values   	*/  set_values,
/* set_values_hook 	*/  NULL,
/* set_values_almost 	*/  XtInheritSetValuesAlmost,
/* get_values+hook 	*/  NULL,
/* accept_focus 	*/  XtInheritAcceptFocus,
/* version      	*/  XtVersion,
/* callback_private 	*/  NULL,
/* tm_table      	*/  defaultTranslations,
/* query_geometry 	*/  query_geometry,
/* display_acceleator 	*/  XtInheritDisplayAccelerator,
/* extension    	*/  NULL 
},
{ /* RadioBtn_class part */
 /* dummy */  0
},
};
WidgetClass radioBtnWidgetClass = (WidgetClass) &radioBtnClassRec;
/*ARGSUSED*/
#line 72 "RadioBtn.w"
static void press(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    int my, ma, md, v, s;

    my=event->xbutton.y;
    compute_line_height(self, &ma, &md);
	v=ma + md + ((RadioBtnWidget)self)->radioBtn.verticalGap;

	s= (my-((RadioBtnWidget)self)->radioBtn.internalOffset)/v;
	if (s!=((RadioBtnWidget)self)->radioBtn.selected)
		XtCallCallbackList(self, ((RadioBtnWidget)self)->radioBtn.radioCallback, (XtPointer) s);
	XtVaSetValues(self, XtNselected, s, NULL);
	}

static void _resolve_inheritance(class)
WidgetClass class;
{
  RadioBtnWidgetClass c = (RadioBtnWidgetClass) class;
  RadioBtnWidgetClass super;
  if (class == radioBtnWidgetClass) return;
  super = (RadioBtnWidgetClass)class->core_class.superclass;
}
#line 165 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 165 "RadioBtn.w"
static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 165 "RadioBtn.w"
static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 166 "RadioBtn.w"
{
    if (((RadioBtnWidget)self)->radioBtn.buttons) {
		((RadioBtnWidget)self)->radioBtn.buttons = XtNewString(((RadioBtnWidget)self)->radioBtn.buttons);
		compute_size(self, &((RadioBtnWidget)self)->core.width, &((RadioBtnWidget)self)->core.height);
		}
	((RadioBtnWidget)self)->radioBtn.gc=NULL;
	make_gc(self);
}
#line 176 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 176 "RadioBtn.w"
static void destroy(Widget self)
#else
#line 176 "RadioBtn.w"
static void destroy(self)Widget self;
#endif
#line 177 "RadioBtn.w"
{
	XtReleaseGC(self, ((RadioBtnWidget)self)->radioBtn.gc);
	XtFree(((RadioBtnWidget)self)->radioBtn.buttons);
}
#line 185 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 185 "RadioBtn.w"
static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 185 "RadioBtn.w"
static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 186 "RadioBtn.w"
{
	Boolean do_size = False;
	Boolean need_redisplay = False;

	if(((RadioBtnWidget)old)->radioBtn.buttons != ((RadioBtnWidget)self)->radioBtn.buttons) {
        XtFree(((RadioBtnWidget)old)->radioBtn.buttons);
        ((RadioBtnWidget)self)->radioBtn.buttons = XtNewString(((RadioBtnWidget)self)->radioBtn.buttons);
		do_size = True;
		}

    if (((RadioBtnWidget)self)->radioBtn.selected != ((RadioBtnWidget)old)->radioBtn.selected) 
		do_size = True;
    if (((RadioBtnWidget)self)->radioBtn.circleSize != ((RadioBtnWidget)old)->radioBtn.circleSize) 
		do_size = True;
    if (((RadioBtnWidget)self)->radioBtn.circleGap != ((RadioBtnWidget)old)->radioBtn.circleGap) 
		do_size = True;

	if(((RadioBtnWidget)old)->radioBtn.internalOffset != ((RadioBtnWidget)self)->radioBtn.internalOffset)
		do_size = True;

	if(((RadioBtnWidget)old)->radioBtn.font != ((RadioBtnWidget)self)->radioBtn.font)
		do_size = True;
		
	if(((RadioBtnWidget)old)->radioBtn.color != ((RadioBtnWidget)self)->radioBtn.color)
		need_redisplay = True;

	if(do_size) {
		compute_size(self, &(((RadioBtnWidget)self)->core.width), &(((RadioBtnWidget)self)->core.height));
		need_redisplay = True;
		}

	return need_redisplay;
}
#line 223 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 223 "RadioBtn.w"
static XtGeometryResult  query_geometry(Widget self,XtWidgetGeometry * request,XtWidgetGeometry * reply)
#else
#line 223 "RadioBtn.w"
static XtGeometryResult  query_geometry(self,request,reply)Widget self;XtWidgetGeometry * request;XtWidgetGeometry * reply;
#endif
#line 224 "RadioBtn.w"
{
	return XtGeometryYes;
	}
#line 234 "RadioBtn.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 234 "RadioBtn.w"
static void expose(Widget self,XEvent * event,Region  region)
#else
#line 234 "RadioBtn.w"
static void expose(self,event,region)Widget self;XEvent * event;Region  region;
#endif
#line 235 "RadioBtn.w"
{
	XFontStruct *f;
    int ma, md;
	int x, y;
	int btn_num;
	char *start, *end;
	
	if(! XtIsRealized(self))
		return ;

	if(event == NULL)
	{
		XClearWindow(XtDisplay(self),XtWindow(self));
		return;
	}

	/* printf("Expose: width=%d\n", $width);*/

    compute_line_height(self, &ma, &md);

	f = ((RadioBtnWidget)self)->radioBtn.font;
	XSetFont(XtDisplay(self), ((RadioBtnWidget)self)->radioBtn.gc, f->fid);
	XSetForeground(XtDisplay(self), ((RadioBtnWidget)self)->radioBtn.gc, ((RadioBtnWidget)self)->radioBtn.color);

	start=((RadioBtnWidget)self)->radioBtn.buttons;
	end=((RadioBtnWidget)self)->radioBtn.buttons; 
	while ((*end != '|') && (*end != '\0'))	end++;
	
	btn_num=0;
	while (*start != '\0') {
		/* draw the circle */
		x = ((RadioBtnWidget)self)->radioBtn.internalOffset;
		y = ((RadioBtnWidget)self)->radioBtn.internalOffset + btn_num * (ma + md + ((RadioBtnWidget)self)->radioBtn.verticalGap);
		XDrawArc(XtDisplay(self), XtWindow(self), ((RadioBtnWidget)self)->radioBtn.gc, x, y, ((RadioBtnWidget)self)->radioBtn.circleSize, ((RadioBtnWidget)self)->radioBtn.circleSize, 0, 360*64);
		if (btn_num==((RadioBtnWidget)self)->radioBtn.selected)
			XFillArc(XtDisplay(self), XtWindow(self), ((RadioBtnWidget)self)->radioBtn.gc, x+2, y+2, ((RadioBtnWidget)self)->radioBtn.circleSize-4, ((RadioBtnWidget)self)->radioBtn.circleSize-4, 0, 360*64);

		/* draw the label */
			
		x = ((RadioBtnWidget)self)->radioBtn.internalOffset+((RadioBtnWidget)self)->radioBtn.circleSize+((RadioBtnWidget)self)->radioBtn.circleGap;
		y = ((RadioBtnWidget)self)->radioBtn.internalOffset + btn_num * (ma + md + ((RadioBtnWidget)self)->radioBtn.verticalGap) + ma;
		XDrawString(XtDisplay(self),XtWindow(self),((RadioBtnWidget)self)->radioBtn.gc,
			x, y, start, end-start);

		btn_num++;
		start=end;
		if (*start == '|') start++;
		end=start;
		while ((*end != '|') && (*end != '\0'))	end++;
		}
}
