/* Generated by wbuild from "PcBar.w"
** (generator version $Revision: 3.0 $ of $Date: 95/08/30 17:50:38 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 176 "PcBar.w"
#include <stdio.h>
#include <./PcBarP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 69 "PcBar.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 84 "PcBar.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 93 "PcBar.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 118 "PcBar.w"
static void destroy(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 127 "PcBar.w"
static XtGeometryResult  query_geometry(
#if NeedFunctionPrototypes
Widget,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);
#line 46 "PcBar.w"
static void GetGC(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 46 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 46 "PcBar.w"
static void GetGC(Widget self)
#else
#line 46 "PcBar.w"
static void GetGC(self)Widget self;
#endif
#line 47 "PcBar.w"
{
    XGCValues values;
    XtGCMask mask = GCForeground | GCBackground;

    values.foreground = ((PcBarWidget)self)->pcBar.foreground;
    values.background = ((PcBarWidget)self)->core.background_pixel;

    ((PcBarWidget)self)->pcBar.draw_gc = XtGetGC(self, mask, &values);

	values.function = GXxor;
	values.foreground = ((PcBarWidget)self)->pcBar.foreground ^ ((PcBarWidget)self)->core.background_pixel;
	mask = GCFunction | GCForeground | GCBackground;
    ((PcBarWidget)self)->pcBar.text_gc = XtGetGC(self, mask, &values);
	XSetFont(XtDisplay(self), ((PcBarWidget)self)->pcBar.text_gc, ((PcBarWidget)self)->pcBar.font->fid); 
	}

static XtResource resources[] = {
#line 10 "PcBar.w"
{XtNforeground,XtCForeground,XtRPixel,sizeof(((PcBarRec*)NULL)->pcBar.foreground),XtOffsetOf(PcBarRec,pcBar.foreground),XtRString,(XtPointer)XtDefaultForeground },
#line 14 "PcBar.w"
{XtNpercentage,XtCPercentage,XtRInt,sizeof(((PcBarRec*)NULL)->pcBar.percentage),XtOffsetOf(PcBarRec,pcBar.percentage),XtRImmediate,(XtPointer)0 },
#line 18 "PcBar.w"
{XtNdisplaypc,XtCDisplaypc,XtRBoolean,sizeof(((PcBarRec*)NULL)->pcBar.displaypc),XtOffsetOf(PcBarRec,pcBar.displaypc),XtRImmediate,(XtPointer)False },
#line 22 "PcBar.w"
{XtNshowzero,XtCShowzero,XtRBoolean,sizeof(((PcBarRec*)NULL)->pcBar.showzero),XtOffsetOf(PcBarRec,pcBar.showzero),XtRImmediate,(XtPointer)False },
#line 26 "PcBar.w"
{XtNvertical,XtCVertical,XtRBoolean,sizeof(((PcBarRec*)NULL)->pcBar.vertical),XtOffsetOf(PcBarRec,pcBar.vertical),XtRImmediate,(XtPointer)False },
#line 30 "PcBar.w"
{XtNfont,XtCFont,XtRFontStruct,sizeof(((PcBarRec*)NULL)->pcBar.font),XtOffsetOf(PcBarRec,pcBar.font),XtRString,(XtPointer)XtDefaultFont },
};

PcBarClassRec pcBarClassRec = {
{ /* core_class part */
/* superclass   	*/  (WidgetClass) &coreClassRec,
/* class_name   	*/  "PcBar",
/* widget_size  	*/  sizeof(PcBarRec),
/* class_initialize 	*/  NULL,
/* class_part_initialize*/  _resolve_inheritance,
/* class_inited 	*/  FALSE,
/* initialize   	*/  initialize,
/* initialize_hook 	*/  NULL,
/* realize      	*/  XtInheritRealize,
/* actions      	*/  NULL,
/* num_actions  	*/  0,
/* resources    	*/  resources,
/* num_resources 	*/  6,
/* xrm_class    	*/  NULLQUARK,
/* compres_motion 	*/  False ,
/* compress_exposure 	*/  FALSE ,
/* 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      	*/  NULL,
/* query_geometry 	*/  query_geometry,
/* display_acceleator 	*/  XtInheritDisplayAccelerator,
/* extension    	*/  NULL 
},
{ /* PcBar_class part */
 /* dummy */  0
},
};
WidgetClass pcBarWidgetClass = (WidgetClass) &pcBarClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  PcBarWidgetClass c = (PcBarWidgetClass) class;
  PcBarWidgetClass super;
  if (class == pcBarWidgetClass) return;
  super = (PcBarWidgetClass)class->core_class.superclass;
}
#define H_DEFAULTWIDTH 200 


#define H_DEFAULTHEIGHT 20 


#define V_DEFAULTWIDTH 30 


#define V_DEFAULTHEIGHT 200 


#line 69 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 69 "PcBar.w"
static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 69 "PcBar.w"
static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 70 "PcBar.w"
{

    if ((((PcBarWidget)self)->pcBar.percentage < 0) ||	(((PcBarWidget)self)->pcBar.percentage > 100))  {
		XtWarning("PcBar: invalid percentage (using 0)."); 
    	((PcBarWidget)self)->pcBar.percentage = 0;
	    }

    GetGC(self);
    if (((PcBarWidget)self)->core.width == 0) 
		((PcBarWidget)self)->core.width = ((PcBarWidget)self)->pcBar.vertical ? V_DEFAULTWIDTH : H_DEFAULTWIDTH;
    if (((PcBarWidget)self)->core.height == 0) 
		((PcBarWidget)self)->core.height = ((PcBarWidget)self)->pcBar.vertical ? V_DEFAULTHEIGHT : H_DEFAULTHEIGHT;

	}
#line 84 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 84 "PcBar.w"
static void expose(Widget self,XEvent * event,Region  region)
#else
#line 84 "PcBar.w"
static void expose(self,event,region)Widget self;XEvent * event;Region  region;
#endif
#line 85 "PcBar.w"
{

    if (!XtIsRealized(self))
		return;

	PcBarSetPercentage(self, ((PcBarWidget)self)->pcBar.percentage);
	}
#line 93 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 93 "PcBar.w"
static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 93 "PcBar.w"
static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 94 "PcBar.w"
{
    Boolean do_redisplay = False;

    if ((((PcBarWidget)old)->pcBar.foreground != ((PcBarWidget)self)->pcBar.foreground) ||
    	(((PcBarWidget)old)->core.background_pixel != ((PcBarWidget)self)->core.background_pixel) ||
     	(((PcBarWidget)old)->pcBar.font != ((PcBarWidget)self)->pcBar.font)) {
		XtReleaseGC(self, ((PcBarWidget)self)->pcBar.draw_gc);
		XtReleaseGC(self, ((PcBarWidget)self)->pcBar.text_gc);
		GetGC(self);
		do_redisplay = True;
	    }
    if (((PcBarWidget)old)->pcBar.percentage != ((PcBarWidget)self)->pcBar.percentage) 
		do_redisplay = True;
    if (((PcBarWidget)old)->pcBar.displaypc != ((PcBarWidget)self)->pcBar.displaypc) 
		do_redisplay = True;
    if ((((PcBarWidget)old)->pcBar.showzero != ((PcBarWidget)self)->pcBar.showzero) && (((PcBarWidget)self)->pcBar.percentage == 0)) {
		do_redisplay = True;
		}
    if (((PcBarWidget)old)->pcBar.vertical != ((PcBarWidget)self)->pcBar.vertical) 
		do_redisplay = True;

    return do_redisplay;
	}
#line 118 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 118 "PcBar.w"
static void destroy(Widget self)
#else
#line 118 "PcBar.w"
static void destroy(self)Widget self;
#endif
#line 119 "PcBar.w"
{
    if (((PcBarWidget)self)->pcBar.draw_gc)
		XtReleaseGC(self, ((PcBarWidget)self)->pcBar.draw_gc);
    if (((PcBarWidget)self)->pcBar.text_gc)
		XtReleaseGC(self, ((PcBarWidget)self)->pcBar.text_gc);
	}
#line 127 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 127 "PcBar.w"
static XtGeometryResult  query_geometry(Widget self,XtWidgetGeometry * request,XtWidgetGeometry * reply)
#else
#line 127 "PcBar.w"
static XtGeometryResult  query_geometry(self,request,reply)Widget self;XtWidgetGeometry * request;XtWidgetGeometry * reply;
#endif
#line 128 "PcBar.w"
{
	/* accept any requested change in size */
    return XtGeometryYes;
	}
#line 134 "PcBar.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 134 "PcBar.w"
void  PcBarSetPercentage(Widget self,int  pc)
#else
#line 134 "PcBar.w"
void  PcBarSetPercentage(self,pc)Widget self;int  pc;
#endif
#line 135 "PcBar.w"
{
    Display *disp;
    Window win;
	int x,y;
	int tx,ty;
	char buf[10];
	int asc, des, dir;
	XCharStruct overall;

	((PcBarWidget)self)->pcBar.percentage=pc;
    if (!XtIsRealized(self))
		return;

	disp=XtDisplay(self);
	win=XtWindow(self);

    XSetLineAttributes(disp, ((PcBarWidget)self)->pcBar.draw_gc, ((PcBarWidget)self)->core.height, LineSolid,CapButt,JoinBevel);
	if (((PcBarWidget)self)->pcBar.vertical) {
	    XSetLineAttributes(disp, ((PcBarWidget)self)->pcBar.draw_gc, ((PcBarWidget)self)->core.width, LineSolid,CapButt,JoinBevel);
	    y= ((PcBarWidget)self)->core.height - (((PcBarWidget)self)->pcBar.percentage * ((PcBarWidget)self)->core.height)/100;
	    XDrawLine(disp, win,((PcBarWidget)self)->pcBar.draw_gc,  ((PcBarWidget)self)->core.width/2, y, ((PcBarWidget)self)->core.width/2, ((PcBarWidget)self)->core.height);
    	if (((PcBarWidget)self)->pcBar.percentage <100) 
			XClearArea(disp, win, 0, 0, ((PcBarWidget)self)->core.width, y, False);
		}
	else {
	    XSetLineAttributes(disp,((PcBarWidget)self)->pcBar.draw_gc, ((PcBarWidget)self)->core.height, LineSolid,CapButt,JoinBevel);
	    x=(((PcBarWidget)self)->pcBar.percentage * ((PcBarWidget)self)->core.width)/100;
	    XDrawLine(disp, win, ((PcBarWidget)self)->pcBar.draw_gc, 0, ((PcBarWidget)self)->core.height/2, x, ((PcBarWidget)self)->core.height/2);
    	XClearArea(disp, win, x, 0, ((PcBarWidget)self)->core.width, ((PcBarWidget)self)->core.height, False);
		}

	if ((((PcBarWidget)self)->pcBar.displaypc) && (((PcBarWidget)self)->pcBar.showzero || ((PcBarWidget)self)->pcBar.percentage > 0)) {
		sprintf(buf, "%d%%", ((PcBarWidget)self)->pcBar.percentage);
        XTextExtents(((PcBarWidget)self)->pcBar.font, buf, strlen(buf), &dir, &asc, &des, &overall);
		tx = (((PcBarWidget)self)->core.width-overall.width)/2;
		ty = (((PcBarWidget)self)->core.height - (asc+des))/2 + asc;
		XDrawString(disp, win, ((PcBarWidget)self)->pcBar.text_gc, tx, ty,  buf, strlen(buf));
		}
	}
