/* Generated by wbuild from "Label.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 367 "Label.w"
#include "stip4.bm"
#line 369 "Label.w"
#include <stdio.h>
#include <Xfwf/LabelP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 110 "Label.w"
static void set_label(
#if NeedFunctionPrototypes
Widget,String 
#endif
);
#line 134 "Label.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 186 "Label.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 242 "Label.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 296 "Label.w"
static void make_gc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 320 "Label.w"
static void make_graygc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 339 "Label.w"
static void count_lines(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 296 "Label.w"
/*ARGSUSED*/static void make_gc(self)Widget self;
{
    XtGCMask mask;
    XGCValues values;

    if (((XfwfLabelWidget)self)->xfwfLabel.gc != NULL) XtReleaseGC(self, ((XfwfLabelWidget)self)->xfwfLabel.gc);
    values.background = ((XfwfLabelWidget)self)->core.background_pixel;
    values.foreground = ((XfwfLabelWidget)self)->xfwfLabel.foreground;
    values.font = ((XfwfLabelWidget)self)->xfwfLabel.font->fid;
    mask = GCFont | GCBackground | GCForeground;
    ((XfwfLabelWidget)self)->xfwfLabel.gc = XtGetGC(self, mask, &values);

    if (((XfwfLabelWidget)self)->xfwfLabel.rv_gc != NULL) XtReleaseGC(self, ((XfwfLabelWidget)self)->xfwfLabel.rv_gc);
    values.foreground = ((XfwfLabelWidget)self)->core.background_pixel;
    values.background = ((XfwfLabelWidget)self)->xfwfLabel.foreground;
    values.font = ((XfwfLabelWidget)self)->xfwfLabel.font->fid;
    mask = GCFont | GCBackground | GCForeground;
    ((XfwfLabelWidget)self)->xfwfLabel.rv_gc = XtGetGC(self, mask, &values);
}
#line 320 "Label.w"
/*ARGSUSED*/static void make_graygc(self)Widget self;
{
    XtGCMask mask;
    XGCValues values;

    if (((XfwfLabelWidget)self)->xfwfLabel.graygc != NULL) XtReleaseGC(self, ((XfwfLabelWidget)self)->xfwfLabel.graygc);
    values.foreground = ((XfwfLabelWidget)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;
    ((XfwfLabelWidget)self)->xfwfLabel.graygc = XtGetGC(self, mask, &values);
}
#line 339 "Label.w"
/*ARGSUSED*/static void count_lines(self)Widget self;
{
    String p, s;
    Dimension w;

    ((XfwfLabelWidget)self)->xfwfLabel.nlines = 0;
    ((XfwfLabelWidget)self)->xfwfLabel.label_width = 0;
    if (((XfwfLabelWidget)self)->xfwfLabel.label) {
	for (p = ((XfwfLabelWidget)self)->xfwfLabel.label, ((XfwfLabelWidget)self)->xfwfLabel.nlines = 1, s = ((XfwfLabelWidget)self)->xfwfLabel.label; *s; s++) {
	    if (*s == '\n') {
		((XfwfLabelWidget)self)->xfwfLabel.nlines++;
		w = XTextWidth(((XfwfLabelWidget)self)->xfwfLabel.font, p, s - p);
		p = s + 1;
		if (w > ((XfwfLabelWidget)self)->xfwfLabel.label_width) ((XfwfLabelWidget)self)->xfwfLabel.label_width = w;
	    }
	}
	w = XTextWidth(((XfwfLabelWidget)self)->xfwfLabel.font, p, s - p);
	if (w > ((XfwfLabelWidget)self)->xfwfLabel.label_width) ((XfwfLabelWidget)self)->xfwfLabel.label_width = w;
    }
    ((XfwfLabelWidget)self)->xfwfLabel.label_height = ((XfwfLabelWidget)self)->xfwfLabel.nlines * (((XfwfLabelWidget)self)->xfwfLabel.font->ascent + ((XfwfLabelWidget)self)->xfwfLabel.font->descent);
    ((XfwfLabelWidget)self)->xfwfLabel.label_width += 2 * ((XfwfLabelWidget)self)->xfwfLabel.margin;
    ((XfwfLabelWidget)self)->xfwfLabel.label_height += 2 * ((XfwfLabelWidget)self)->xfwfLabel.margin;
}

static XtResource resources[] = {
#line 19 "Label.w"
{XtNlabel,XtCLabel,XtRString,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.label),XtOffsetOf(XfwfLabelRec,xfwfLabel.label),XtRImmediate,(XtPointer)NULL },
#line 23 "Label.w"
{XtNfont,XtCFont,XtRFontStruct,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.font),XtOffsetOf(XfwfLabelRec,xfwfLabel.font),XtRString,(XtPointer)XtDefaultFont },
#line 27 "Label.w"
{XtNforeground,XtCForeground,XtRPixel,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.foreground),XtOffsetOf(XfwfLabelRec,xfwfLabel.foreground),XtRString,(XtPointer)XtDefaultForeground },
#line 39 "Label.w"
{XtNalignment,XtCAlignment,XtRAlignment,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.alignment),XtOffsetOf(XfwfLabelRec,xfwfLabel.alignment),XtRImmediate,(XtPointer)0 },
#line 44 "Label.w"
{XtNmargin,XtCMargin,XtRInt,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.margin),XtOffsetOf(XfwfLabelRec,xfwfLabel.margin),XtRImmediate,(XtPointer)2 },
#line 51 "Label.w"
{XtNshrinkToFit,XtCShrinkToFit,XtRBoolean,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.shrinkToFit),XtOffsetOf(XfwfLabelRec,xfwfLabel.shrinkToFit),XtRImmediate,(XtPointer)False },
#line 57 "Label.w"
{XtNrvStart,XtCRvStart,XtRInt,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.rvStart),XtOffsetOf(XfwfLabelRec,xfwfLabel.rvStart),XtRImmediate,(XtPointer)0 },
#line 62 "Label.w"
{XtNrvLength,XtCRvLength,XtRInt,sizeof(((XfwfLabelRec*)NULL)->xfwfLabel.rvLength),XtOffsetOf(XfwfLabelRec,xfwfLabel.rvLength),XtRImmediate,(XtPointer)0 },
#line 67 "Label.w"
{XtNtraversalOn,XtCTraversalOn,XtRBoolean,sizeof(((XfwfLabelRec*)NULL)->xfwfCommon.traversalOn),XtOffsetOf(XfwfLabelRec,xfwfCommon.traversalOn),XtRImmediate,(XtPointer)False },
};

XfwfLabelClassRec xfwfLabelClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfBoardClassRec,
"XfwfLabel",
sizeof(XfwfLabelRec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
NULL,
0,
resources,
9,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
XtInheritResize,
expose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
NULL,
XtInheritQueryGeometry,
XtInheritDisplayAccelerator,
NULL 
},
{ /* composite_class part */
XtInheritGeometryManager,
XtInheritChangeManaged,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* XfwfCommon_class part */
XtInherit_compute_inside,
XtInherit_highlight_border,
XtInherit_unhighlight_border,
XtInherit_would_accept_focus,
XtInherit_traverse,
XtInherit_choose_color,
XtInherit_lighter_color,
XtInherit_darker_color,
NULL ,
},
{ /* XfwfFrame_class part */
0
},
{ /* XfwfBoard_class part */
XtInherit_set_abs_location,
},
{ /* XfwfLabel_class part */
set_label,
},
};
WidgetClass xfwfLabelWidgetClass = (WidgetClass) &xfwfLabelClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfLabelWidgetClass c = (XfwfLabelWidgetClass) class;
  XfwfLabelWidgetClass super;
  if (class == xfwfLabelWidgetClass) return;
  super = (XfwfLabelWidgetClass) c->core_class.superclass;
  if (c->xfwfLabel_class.set_label == XtInherit_set_label)
    c->xfwfLabel_class.set_label = super->xfwfLabel_class.set_label;
}
#line 110 "Label.w"
/*ARGSUSED*/static void set_label(self,newlabel)Widget self;String  newlabel;
{
    Position x, y;
    Dimension w, h;

    XtFree(((XfwfLabelWidget)self)->xfwfLabel.label);
    ((XfwfLabelWidget)self)->xfwfLabel.label = XtNewString(newlabel);
    count_lines(self);
    if (XtIsRealized(self)) {
	((XfwfLabelWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
	XClearArea(XtDisplay(self), XtWindow(self), x, y, w, h, False);
	((XfwfLabelWidgetClass)self->core.widget_class)->core_class.expose(self, NULL, NULL);
    }
}
#line 134 "Label.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Boolean need_redisplay = False, need_count = False;
    Position x, y;
    Dimension w, h, wd, ht;

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

    if (((XfwfLabelWidget)self)->xfwfLabel.font != ((XfwfLabelWidget)old)->xfwfLabel.font) {
	make_gc(self);
	if (((XfwfLabelWidget)self)->xfwfLabel.label != NULL) need_count = True;
    }
    if (((XfwfLabelWidget)self)->xfwfLabel.foreground != ((XfwfLabelWidget)old)->xfwfLabel.foreground
	|| ((XfwfLabelWidget)self)->core.background_pixel != ((XfwfLabelWidget)old)->core.background_pixel) {
	make_gc(self);
	if (((XfwfLabelWidget)self)->xfwfLabel.label != NULL) need_redisplay = True;
    }
    if (((XfwfLabelWidget)self)->xfwfLabel.margin != ((XfwfLabelWidget)old)->xfwfLabel.margin)
	need_count = True;

    if (((XfwfLabelWidget)self)->core.sensitive != ((XfwfLabelWidget)old)->core.sensitive)
	if (((XfwfLabelWidget)self)->xfwfLabel.label != NULL) need_redisplay = True;

    if (((XfwfLabelWidget)self)->xfwfLabel.rvStart != ((XfwfLabelWidget)old)->xfwfLabel.rvStart || ((XfwfLabelWidget)self)->xfwfLabel.rvLength != ((XfwfLabelWidget)old)->xfwfLabel.rvLength)
	if (((XfwfLabelWidget)self)->xfwfLabel.label != NULL) need_redisplay = True;

    if (((XfwfLabelWidget)self)->xfwfLabel.label != ((XfwfLabelWidget)old)->xfwfLabel.label) {
	XtFree(((XfwfLabelWidget)old)->xfwfLabel.label);
	((XfwfLabelWidget)self)->xfwfLabel.label = XtNewString(((XfwfLabelWidget)self)->xfwfLabel.label);
	need_count = True;
    }
    if (need_count) {
	count_lines(self);
	need_redisplay = True;
    }
    if (need_count && ((XfwfLabelWidget)self)->xfwfLabel.shrinkToFit) {
	((XfwfLabelWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
	wd = ((XfwfLabelWidget)self)->xfwfLabel.label_width + ((XfwfLabelWidget)self)->core.width - w;
	ht = ((XfwfLabelWidget)self)->xfwfLabel.label_height + ((XfwfLabelWidget)self)->core.height - h;
	if (wd != ((XfwfLabelWidget)self)->core.width || ht != ((XfwfLabelWidget)self)->core.height) {
	    ((XfwfLabelWidgetClass)self->core.widget_class)->xfwfBoard_class.set_abs_location(self, CWWidth | CWHeight, 0, 0, wd, ht);
	    need_redisplay = False;
	}
    }
    return need_redisplay;
}
#line 186 "Label.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    char *s;
    Position x, y;
    Dimension w, h, wd, ht;

    if (((XfwfLabelWidget)self)->xfwfLabel.label) ((XfwfLabelWidget)self)->xfwfLabel.label = XtNewString(((XfwfLabelWidget)self)->xfwfLabel.label);
    count_lines(self);
    ((XfwfLabelWidget)self)->xfwfLabel.gc = NULL;
    ((XfwfLabelWidget)self)->xfwfLabel.rv_gc = NULL;
    ((XfwfLabelWidget)self)->xfwfLabel.graygc = NULL;
    make_gc(self);
    make_graygc(self);
    if (((XfwfLabelWidget)self)->xfwfLabel.shrinkToFit) {
	((XfwfLabelWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
	wd = ((XfwfLabelWidget)self)->xfwfLabel.label_width + ((XfwfLabelWidget)self)->core.width - w;
	ht = ((XfwfLabelWidget)self)->xfwfLabel.label_height + ((XfwfLabelWidget)self)->core.height - h;
	((XfwfLabelWidgetClass)self->core.widget_class)->xfwfBoard_class.set_abs_location(self, CWWidth | CWHeight, 0, 0, wd, ht);
    }
}
#line 242 "Label.w"
/*ARGSUSED*/static void expose(self,event,region)Widget self;XEvent * event;Region  region;
{
    Region reg;
    XRectangle rect;
    int baseline;
    Dimension w1, w2, w3;
    char *s, *t;
    int x, y, i, j, rstart, rend;

    if (! XtIsRealized(self)) return;
    xfwfBoardClassRec.core_class.expose(self, event, region);
    if (((XfwfLabelWidget)self)->xfwfLabel.label != NULL) {
	baseline = ((XfwfLabelWidget)self)->xfwfLabel.font->ascent + ((XfwfLabelWidget)self)->xfwfLabel.font->descent;
	((XfwfLabelWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &rect.x, &rect.y, &rect.width, &rect.height);
	rect.x += ((XfwfLabelWidget)self)->xfwfLabel.margin;  rect.width -= 2 * ((XfwfLabelWidget)self)->xfwfLabel.margin;
	rect.y += ((XfwfLabelWidget)self)->xfwfLabel.margin;  rect.height -= 2 * ((XfwfLabelWidget)self)->xfwfLabel.margin;
	reg = XCreateRegion();
	XUnionRectWithRegion(&rect, reg, reg);
	if (region != NULL) XIntersectRegion(region, reg, reg);
	XSetRegion(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.gc, reg);
	XSetRegion(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.rv_gc, reg);
	if (((XfwfLabelWidget)self)->xfwfLabel.alignment & XfwfTop)
	    y = rect.y + ((XfwfLabelWidget)self)->xfwfLabel.font->ascent;
	else if (((XfwfLabelWidget)self)->xfwfLabel.alignment & XfwfBottom)
	    y = rect.y + rect.height - ((XfwfLabelWidget)self)->xfwfLabel.nlines * baseline + ((XfwfLabelWidget)self)->xfwfLabel.font->ascent;
	else
	    y = rect.y + (rect.height - ((XfwfLabelWidget)self)->xfwfLabel.nlines * baseline)/2 + ((XfwfLabelWidget)self)->xfwfLabel.font->ascent;
	for (i = 0, j = 0; ((XfwfLabelWidget)self)->xfwfLabel.label[i]; i++) {
	    if (((XfwfLabelWidget)self)->xfwfLabel.label[i] == '\n') {
		draw_line(XtDisplay(self), XtWindow(self), j, i);
		j = i + 1;
		y += baseline;
	    }
	}
	draw_line(XtDisplay(self), XtWindow(self), j, i);

	/* Gray out if not sensitive */
	if (! ((XfwfLabelWidget)self)->core.sensitive) {
	    XSetRegion(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.graygc, reg);
	    XFillRectangle(XtDisplay(self), XtWindow(self), ((XfwfLabelWidget)self)->xfwfLabel.graygc, rect.x,
			   rect.y, rect.width, rect.height);
	    XSetClipMask(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.graygc, None);
	}
	XSetClipMask(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.gc, None);
	XSetClipMask(XtDisplay(self), ((XfwfLabelWidget)self)->xfwfLabel.rv_gc, None);
    }
}
