/* Generated by wbuild from "CheckBox.w"
** (generator version $Revision: 3.0 $ of $Date: 95/08/30 17:50:38 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 279 "CheckBox.w"
#include "stip4.bm"
#line 280 "CheckBox.w"
#include <assert.h>
#line 281 "CheckBox.w"
#include <ctype.h>
#line 282 "CheckBox.w"
#include <stdio.h>
#line 283 "CheckBox.w"
#include <string.h>
#include <./CheckBoxP.h>
#line 69 "CheckBox.w"
static void toggle(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);

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

static char defaultTranslations[] = "\
<Btn1Down>,<Btn1Up>: toggle() \n\
<Key>space: toggle() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 152 "CheckBox.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 165 "CheckBox.w"
static void destroy(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 174 "CheckBox.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 218 "CheckBox.w"
static XtGeometryResult  query_geometry(
#if NeedFunctionPrototypes
Widget,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);
#line 229 "CheckBox.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 84 "CheckBox.w"
static void make_gc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 104 "CheckBox.w"
static void make_graygc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 124 "CheckBox.w"
static void compute_line_height(
#if NeedFunctionPrototypes
Widget,int *,int *
#endif
);
#line 136 "CheckBox.w"
static void compute_size(
#if NeedFunctionPrototypes
Widget,Dimension *,Dimension *
#endif
);
#line 84 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 84 "CheckBox.w"
static void make_gc(Widget self)
#else
#line 84 "CheckBox.w"
static void make_gc(self)Widget self;
#endif
#line 85 "CheckBox.w"
{
	XtGCMask mask, dynmask, dontcaremask;
	XGCValues values;

	values.foreground=((CheckBoxWidget)self)->checkBox.color;
	values.background=((CheckBoxWidget)self)->core.background_pixel;
	values.font=((CheckBoxWidget)self)->checkBox.font->fid;
	dynmask = GCForeground | GCBackground | GCFont;
	dontcaremask = GCJoinStyle | GCFillRule | GCTile
		| GCTileStipXOrigin | GCTileStipYOrigin | GCDashOffset | GCDashList
		| GCStipple | GCGraphicsExposures | GCArcMode | GCLineWidth | GCClipMask;
	mask=0;
	((CheckBoxWidget)self)->checkBox.gc=XtAllocateGC(self,((CheckBoxWidget)self)->core.depth,mask,&values,dynmask,dontcaremask);
}
#line 104 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 104 "CheckBox.w"
static void make_graygc(Widget self)
#else
#line 104 "CheckBox.w"
static void make_graygc(self)Widget self;
#endif
#line 105 "CheckBox.w"
{
    XtGCMask mask;
    XGCValues values;

    if (((CheckBoxWidget)self)->checkBox.graygc != NULL) XtReleaseGC(self, ((CheckBoxWidget)self)->checkBox.graygc);
    values.foreground = ((CheckBoxWidget)self)->core.background_pixel;
    values.stipple =
        XCreateBitmapFromData(XtDisplay(self),
                              RootWindowOfScreen(XtScreen(self)),
                              stip4_bits, stip4_width, stip4_height);
    values.fill_style = FillStippled;
    mask = GCForeground | GCStipple | GCFillStyle;
    ((CheckBoxWidget)self)->checkBox.graygc = XtGetGC(self, mask, &values);
	}
#line 124 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 124 "CheckBox.w"
static void compute_line_height(Widget self,int * ma,int * md)
#else
#line 124 "CheckBox.w"
static void compute_line_height(self,ma,md)Widget self;int * ma;int * md;
#endif
#line 125 "CheckBox.w"
{
	XFontStruct *f;

	*ma=0, *md=0;
	f=((CheckBoxWidget)self)->checkBox.font;
	*ma =  ((CheckBoxWidget)self)->checkBox.boxSize > f->ascent ? ((CheckBoxWidget)self)->checkBox.boxSize : f->ascent;
	*md =  f->descent;
}
#line 136 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 136 "CheckBox.w"
static void compute_size(Widget self,Dimension * wd,Dimension * ht)
#else
#line 136 "CheckBox.w"
static void compute_size(self,wd,ht)Widget self;Dimension * wd;Dimension * ht;
#endif
#line 137 "CheckBox.w"
{
	int ma, md;
	
	compute_line_height(self, &ma, &md);
	*ht = (((CheckBoxWidget)self)->checkBox.internalOffset)*2 + ma + md;
		
	*wd = XTextWidth(((CheckBoxWidget)self)->checkBox.font,((CheckBoxWidget)self)->checkBox.label,strlen(((CheckBoxWidget)self)->checkBox.label)) + (((CheckBoxWidget)self)->checkBox.internalOffset)*2 
			+ ((CheckBoxWidget)self)->checkBox.boxSize + ((CheckBoxWidget)self)->checkBox.boxGap;
}

static XtResource resources[] = {
#line 12 "CheckBox.w"
{XtNlabel,XtCLabel,XtRString,sizeof(((CheckBoxRec*)NULL)->checkBox.label),XtOffsetOf(CheckBoxRec,checkBox.label),XtRImmediate,(XtPointer)NULL },
#line 16 "CheckBox.w"
{XtNfont,XtCFont,XtRFontStruct,sizeof(((CheckBoxRec*)NULL)->checkBox.font),XtOffsetOf(CheckBoxRec,checkBox.font),XtRString,(XtPointer)XtDefaultFont },
#line 20 "CheckBox.w"
{XtNcolor,XtCColor,XtRPixel,sizeof(((CheckBoxRec*)NULL)->checkBox.color),XtOffsetOf(CheckBoxRec,checkBox.color),XtRString,(XtPointer)XtDefaultForeground },
#line 24 "CheckBox.w"
{XtNinternalOffset,XtCInternalOffset,XtRDimension,sizeof(((CheckBoxRec*)NULL)->checkBox.internalOffset),XtOffsetOf(CheckBoxRec,checkBox.internalOffset),XtRImmediate,(XtPointer)2 },
#line 28 "CheckBox.w"
{XtNboxSize,XtCBoxSize,XtRDimension,sizeof(((CheckBoxRec*)NULL)->checkBox.boxSize),XtOffsetOf(CheckBoxRec,checkBox.boxSize),XtRImmediate,(XtPointer)11 },
#line 32 "CheckBox.w"
{XtNboxGap,XtCBoxGap,XtRDimension,sizeof(((CheckBoxRec*)NULL)->checkBox.boxGap),XtOffsetOf(CheckBoxRec,checkBox.boxGap),XtRImmediate,(XtPointer)9 },
#line 36 "CheckBox.w"
{XtNstate,XtCState,XtRBoolean,sizeof(((CheckBoxRec*)NULL)->checkBox.state),XtOffsetOf(CheckBoxRec,checkBox.state),XtRImmediate,(XtPointer)False },
#line 40 "CheckBox.w"
{XtNborderWidth,XtCBorderWidth,XtRDimension,sizeof(((CheckBoxRec*)NULL)->core.border_width),XtOffsetOf(CheckBoxRec,core.border_width),XtRImmediate,(XtPointer)0 },
};

CheckBoxClassRec checkBoxClassRec = {
{ /* core_class part */
/* superclass   	*/  (WidgetClass) &coreClassRec,
/* class_name   	*/  "CheckBox",
/* widget_size  	*/  sizeof(CheckBoxRec),
/* 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 	*/  8,
/* 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 
},
{ /* CheckBox_class part */
 /* dummy */  0
},
};
WidgetClass checkBoxWidgetClass = (WidgetClass) &checkBoxClassRec;
/*ARGSUSED*/
#line 69 "CheckBox.w"
static void toggle(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    XtVaSetValues(self, XtNstate, !((CheckBoxWidget)self)->checkBox.state, NULL);
}

static void _resolve_inheritance(class)
WidgetClass class;
{
  CheckBoxWidgetClass c = (CheckBoxWidgetClass) class;
  CheckBoxWidgetClass super;
  if (class == checkBoxWidgetClass) return;
  super = (CheckBoxWidgetClass)class->core_class.superclass;
}
#line 152 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 152 "CheckBox.w"
static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 152 "CheckBox.w"
static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 153 "CheckBox.w"
{
    if (((CheckBoxWidget)self)->checkBox.label) {
		((CheckBoxWidget)self)->checkBox.label = XtNewString(((CheckBoxWidget)self)->checkBox.label);
		compute_size(self, &((CheckBoxWidget)self)->core.width, &((CheckBoxWidget)self)->core.height);
		}
	((CheckBoxWidget)self)->checkBox.gc=NULL;
	((CheckBoxWidget)self)->checkBox.graygc=NULL;
	make_gc(self);
	make_graygc(self);
}
#line 165 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 165 "CheckBox.w"
static void destroy(Widget self)
#else
#line 165 "CheckBox.w"
static void destroy(self)Widget self;
#endif
#line 166 "CheckBox.w"
{
	XtReleaseGC(self, ((CheckBoxWidget)self)->checkBox.gc);
	XtFree(((CheckBoxWidget)self)->checkBox.label);
}
#line 174 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 174 "CheckBox.w"
static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 174 "CheckBox.w"
static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 175 "CheckBox.w"
{
	Boolean do_size = False;
	Boolean need_redisplay = False;

	if (((CheckBoxWidget)self)->core.background_pixel != ((CheckBoxWidget)old)->core.background_pixel)
		make_graygc(self);

	if(((CheckBoxWidget)old)->checkBox.label != ((CheckBoxWidget)self)->checkBox.label) {
        XtFree(((CheckBoxWidget)old)->checkBox.label);
        ((CheckBoxWidget)self)->checkBox.label = XtNewString(((CheckBoxWidget)self)->checkBox.label);
		do_size = True;
		}

    if (((CheckBoxWidget)self)->checkBox.state != ((CheckBoxWidget)old)->checkBox.state) 
		do_size = True;
    if (((CheckBoxWidget)self)->checkBox.boxSize != ((CheckBoxWidget)old)->checkBox.boxSize) 
		do_size = True;
    if (((CheckBoxWidget)self)->checkBox.boxGap != ((CheckBoxWidget)old)->checkBox.boxGap) 
		do_size = True;

	if(((CheckBoxWidget)old)->checkBox.internalOffset != ((CheckBoxWidget)self)->checkBox.internalOffset)
		do_size = True;

	if(((CheckBoxWidget)old)->checkBox.font != ((CheckBoxWidget)self)->checkBox.font)
		do_size = True;

	if ((((CheckBoxWidget)old)->checkBox.color != ((CheckBoxWidget)self)->checkBox.color) ||
		(((CheckBoxWidget)old)->core.sensitive != ((CheckBoxWidget)self)->core.sensitive))
			need_redisplay = True;

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

	return need_redisplay;
}
#line 218 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 218 "CheckBox.w"
static XtGeometryResult  query_geometry(Widget self,XtWidgetGeometry * request,XtWidgetGeometry * reply)
#else
#line 218 "CheckBox.w"
static XtGeometryResult  query_geometry(self,request,reply)Widget self;XtWidgetGeometry * request;XtWidgetGeometry * reply;
#endif
#line 219 "CheckBox.w"
{
	return XtGeometryYes;
	}
#line 229 "CheckBox.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 229 "CheckBox.w"
static void expose(Widget self,XEvent * event,Region  region)
#else
#line 229 "CheckBox.w"
static void expose(self,event,region)Widget self;XEvent * event;Region  region;
#endif
#line 230 "CheckBox.w"
{
	XFontStruct *f;
    int ma, md;
	int ypos;
	int x1, y1, x2, y2;
		
	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);
	ypos=ma + ((CheckBoxWidget)self)->checkBox.internalOffset;

	/* draw the checkbox */
	XDrawRectangle(XtDisplay(self), XtWindow(self), ((CheckBoxWidget)self)->checkBox.gc, 
		((CheckBoxWidget)self)->checkBox.internalOffset, ((CheckBoxWidget)self)->checkBox.internalOffset, ((CheckBoxWidget)self)->checkBox.boxSize, ((CheckBoxWidget)self)->checkBox.boxSize);
	if (((CheckBoxWidget)self)->checkBox.state) {
		x1=((CheckBoxWidget)self)->checkBox.internalOffset;
		y1=((CheckBoxWidget)self)->checkBox.internalOffset;
		x2=x1+((CheckBoxWidget)self)->checkBox.boxSize;
		y2=y1+((CheckBoxWidget)self)->checkBox.boxSize;
		XDrawLine(XtDisplay(self), XtWindow(self), ((CheckBoxWidget)self)->checkBox.gc, x1, y1, x2, y2);
		XDrawLine(XtDisplay(self), XtWindow(self), ((CheckBoxWidget)self)->checkBox.gc, x1, y2, x2, y1);
		}

	/* draw the label */
	f = ((CheckBoxWidget)self)->checkBox.font;
	XSetFont(XtDisplay(self), ((CheckBoxWidget)self)->checkBox.gc, f->fid);
	XSetForeground(XtDisplay(self), ((CheckBoxWidget)self)->checkBox.gc, ((CheckBoxWidget)self)->checkBox.color);
			
	XDrawString(XtDisplay(self),XtWindow(self),((CheckBoxWidget)self)->checkBox.gc,
			((CheckBoxWidget)self)->checkBox.internalOffset+((CheckBoxWidget)self)->checkBox.boxSize+((CheckBoxWidget)self)->checkBox.boxGap, ypos, ((CheckBoxWidget)self)->checkBox.label, strlen(((CheckBoxWidget)self)->checkBox.label));

	/* Gray out if not sensitive */
	if (! ((CheckBoxWidget)self)->core.sensitive) {
		XFillRectangle(XtDisplay(self), XtWindow(self), ((CheckBoxWidget)self)->checkBox.graygc, 0,
			0, ((CheckBoxWidget)self)->core.width, ((CheckBoxWidget)self)->core.height);
		}
	}
