/* Generated by wbuild from "Icon.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 274 "Icon.w"
#include <X11/extensions/shape.h>
#line 275 "Icon.w"
#include <stdio.h>
#line 276 "Icon.w"
#include "FATAL.xpm"
#line 277 "Icon.w"
#include "ERROR.xpm"
#line 278 "Icon.w"
#include "WARNING.xpm"
#line 279 "Icon.w"
#include "QUESTION.xpm"
#line 280 "Icon.w"
#include "INFO.xpm"
#line 281 "Icon.w"
#include "NONE.xpm"
#include <Xfwf/IconP.h>
#line 242 "Icon.w"
static void activate(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);

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

static char defaultTranslations[] = "\
<Btn1Down>,<Btn1Up>: activate() \n\
<Key>Return: activate() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 142 "Icon.w"
static void class_initialize(
#if NeedFunctionPrototypes
void
#endif
);
#line 151 "Icon.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 172 "Icon.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 187 "Icon.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 216 "Icon.w"
static void realize(
#if NeedFunctionPrototypes
Widget,XtValueMask *,XSetWindowAttributes *
#endif
);
#line 253 "Icon.w"
static void create_image_gc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 253 "Icon.w"
/*ARGSUSED*/static void create_image_gc(self)Widget self;
{
    Dimension wd, ht;
    Position x, y;
    XtGCMask mask = GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
    XGCValues values;

    XtReleaseGC(self, ((XfwfIconWidget)self)->xfwfIcon.image_gc);
    ((XfwfIconWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &wd, &ht);
    if (((XfwfIconWidget)self)->xfwfIcon.image && ((XfwfIconWidget)self)->xfwfIcon.image->pixmap != None) {
	values.tile = ((XfwfIconWidget)self)->xfwfIcon.image->pixmap;
	mask |= GCTile;
    }
    values.fill_style = FillTiled;
    values.ts_x_origin = x;
    values.ts_y_origin = y;
    ((XfwfIconWidget)self)->xfwfIcon.image_gc = XtGetGC(self, mask, &values);
}

static XtResource resources[] = {
#line 26 "Icon.w"
{XtNimage,XtCImage,XtRIcon,sizeof(((XfwfIconRec*)NULL)->xfwfIcon.image),XtOffsetOf(XfwfIconRec,xfwfIcon.image),XtRImmediate,(XtPointer)NULL },
#line 31 "Icon.w"
{XtNactivate,XtCActivate,XtRCallback,sizeof(((XfwfIconRec*)NULL)->xfwfIcon.activate),XtOffsetOf(XfwfIconRec,xfwfIcon.activate),XtRImmediate,(XtPointer)NULL },
#line 35 "Icon.w"
{XtNframeWidth,XtCFrameWidth,XtRDimension,sizeof(((XfwfIconRec*)NULL)->xfwfFrame.frameWidth),XtOffsetOf(XfwfIconRec,xfwfFrame.frameWidth),XtRImmediate,(XtPointer)0 },
};

XfwfIconClassRec xfwfIconClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfBoardClassRec,
"XfwfIcon",
sizeof(XfwfIconRec),
class_initialize,
_resolve_inheritance,
FALSE,
initialize,
NULL,
realize,
actionsList,
1,
resources,
3,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
XtInheritResize,
expose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
defaultTranslations,
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,
},
{ /* XfwfIcon_class part */
0
},
};
WidgetClass xfwfIconWidgetClass = (WidgetClass) &xfwfIconClassRec;
/*ARGSUSED*/
#line 242 "Icon.w"
static void activate(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    XtCallCallbackList(self, ((XfwfIconWidget)self)->xfwfIcon.activate, event);
}

static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfIconWidgetClass c = (XfwfIconWidgetClass) class;
  XfwfIconWidgetClass super;
  if (class == xfwfIconWidgetClass) return;
  super = (XfwfIconWidgetClass) c->core_class.superclass;
}
#line 142 "Icon.w"
/*ARGSUSED*/static void class_initialize()
{
    XtSetTypeConverter(XtRString, "Icon", cvtStringToIcon,
		       NULL, 0, XtCacheNone, NULL);
}
#line 151 "Icon.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Dimension dummy1, dummy2;
    Position x, y;

    ((XfwfIconWidget)self)->xfwfIcon.image_gc = NULL;
    create_image_gc(self);
    if (((XfwfIconWidget)self)->xfwfIcon.image && (((XfwfIconWidget)self)->xfwfIcon.image->attributes.valuemask & XpmSize) != 0) {
	((XfwfIconWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &dummy1, &dummy2);
	XtVaSetValues(self, XtNwidth, ((XfwfIconWidget)self)->xfwfIcon.image->attributes.width + 2*x,
		      XtNheight, ((XfwfIconWidget)self)->xfwfIcon.image->attributes.height + 2*y, NULL);
    }
}
#line 172 "Icon.w"
/*ARGSUSED*/static void expose(self,event,region)Widget self;XEvent * event;Region  region;
{
    Dimension wd, ht;
    Position x, y;

    if (! XtIsRealized(self)) return;
    if (((XfwfIconWidget)self)->xfwfIcon.image && ((XfwfIconWidget)self)->xfwfIcon.image->pixmap != None) {
	((XfwfIconWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &wd, &ht);
	XFillRectangle(XtDisplay(self), XtWindow(self), ((XfwfIconWidget)self)->xfwfIcon.image_gc, x, y, wd, ht);
    }
    xfwfBoardClassRec.core_class.expose(self, event, region);
}
#line 187 "Icon.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Dimension dummy1, dummy2;
    Position x, y;
    Boolean need_redraw = False;

    if (((XfwfIconWidget)old)->xfwfFrame.frameWidth != ((XfwfIconWidget)self)->xfwfFrame.frameWidth
	|| ((XfwfIconWidget)old)->xfwfFrame.frameOffset != ((XfwfIconWidget)self)->xfwfFrame.frameOffset
	|| ((XfwfIconWidget)old)->xfwfIcon.image != ((XfwfIconWidget)self)->xfwfIcon.image) {
	create_image_gc(self);
	need_redraw = True;
    }
    if (((XfwfIconWidget)old)->xfwfIcon.image != ((XfwfIconWidget)self)->xfwfIcon.image && ((XfwfIconWidget)self)->xfwfIcon.image) {
	((XfwfIconWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &dummy1, &dummy2);
	if ((((XfwfIconWidget)self)->xfwfIcon.image->attributes.valuemask & XpmSize) != 0)
	    ((XfwfIconWidgetClass)self->core.widget_class)->xfwfBoard_class.set_abs_location(self, CWWidth | CWHeight, 0, 0,
			      ((XfwfIconWidget)self)->xfwfIcon.image->attributes.width + 2*x,
			      ((XfwfIconWidget)self)->xfwfIcon.image->attributes.height + 2*y);
	if (((XfwfIconWidget)self)->xfwfIcon.image->mask != None && XtIsRealized(self))
	    XShapeCombineMask(XtDisplay(self), XtWindow(self), ShapeBounding,
			      x, y, ((XfwfIconWidget)self)->xfwfIcon.image->mask, ShapeSet);
	need_redraw = True;
    }
    return need_redraw;
}
#line 216 "Icon.w"
/*ARGSUSED*/static void realize(self,mask,attributes)Widget self;XtValueMask * mask;XSetWindowAttributes * attributes;
{
    Dimension wd, ht;
    Position x, y;

    xfwfBoardClassRec.core_class.realize(self, mask, attributes);
    ((XfwfIconWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &wd, &ht);
    if (((XfwfIconWidget)self)->xfwfIcon.image && ((XfwfIconWidget)self)->xfwfIcon.image->mask != None)
	XShapeCombineMask(XtDisplay(self), XtWindow(self), ShapeBounding,
			  x, y, ((XfwfIconWidget)self)->xfwfIcon.image->mask, ShapeSet);
}
#line 48 "Icon.w"
#line 53 "Icon.w"
#line 65 "Icon.w"
#line 82 "Icon.w"
/*ARGSUSED*/Boolean  cvtStringToIcon(display,args,num_args,from,to,converter_data)Display * display;XrmValuePtr  args;Cardinal * num_args;XrmValuePtr  from;XrmValuePtr  to;XtPointer * converter_data;
{
    int status;
    Cardinal one = 1;
    String *data = NULL;
    Icon *view;
    XImage *im, *shape;

    if (*num_args != 0)
	XtAppErrorMsg
	    (XtDisplayToApplicationContext(display),
	     "cvtStringToIcon", "wrongParameters",
	     "XtToolkitError",
	     "String to Icon type conversion needs no arguments", 
	     (String*) NULL, (Cardinal*) NULL);

    view = (Icon*) XtMalloc(sizeof(*view));
    view->attributes.valuemask = XpmSize;
    if (strcmp("QUESTION", (String) from->addr) == 0) data = QUESTION;
    else if (strcmp("FATAL", (String) from->addr) == 0) data = FATAL;
    else if (strcmp("ERROR", (String) from->addr) == 0) data = ERROR;
    else if (strcmp("WARNING", (String) from->addr) == 0) data = WARNING;
    else if (strcmp("INFO", (String) from->addr) == 0) data = INFO;
    else if (strcmp("NONE", (String) from->addr) == 0) data = NONE;
    if (data != NULL)
	status = XpmCreatePixmapFromData
	    (display, DefaultRootWindow(display), data,
	     &view->pixmap, &view->mask, &view->attributes);
    else
	status = XpmReadFileToPixmap
	    (display, DefaultRootWindow(display), (String) from->addr,
	     &view->pixmap, &view->mask, &view->attributes);

    switch (status) {
    case XpmOpenFailed:
    case XpmFileInvalid:
    case XpmNoMemory:
	XtAppWarningMsg
	    (XtDisplayToApplicationContext(display),
	     "cvtStringToIcon", "fileError", "XtToolkitError",
	     "Failed to create image \"%s\"",
	     &from->addr, &one);
	break;	    
    case XpmColorError:
    case XpmColorFailed:
	XtAppWarningMsg
	    (XtDisplayToApplicationContext(display),
	     "cvtStringToIcon", "allocColor", "XtToolkitError",
	     "Could not get (all) colors for image \"%s\"",
	     &from->addr, &one);
    case XpmSuccess:
	; /* skip */
    }
    done(Icon*, view);
}
