/* Generated by wbuild from "Animator.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 365 "Animator.w"
#include <X11/xpm.h>
#line 366 "Animator.w"
#include <stdio.h>
#include <Xfwf/AnimatorP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 109 "Animator.w"
static void class_initialize(
#if NeedFunctionPrototypes
void
#endif
);
#line 121 "Animator.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 148 "Animator.w"
static void start_animation(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 168 "Animator.w"
static void stop_animation(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 180 "Animator.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 198 "Animator.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 233 "Animator.w"
static void next_image(
#if NeedFunctionPrototypes
XtPointer ,XtIntervalId *
#endif
);
#line 267 "Animator.w"
#define done(type, value) do {\
      if (to->addr != NULL) {\
	  if (to->size < sizeof(type)) {\
	      to->size = sizeof(type);\
	      return False;\
	  }\
	  *(type*)(to->addr) = (value);\
      } else {\
	  static type static_val;\
	  static_val = (value);\
	  to->addr = (XtPointer)&static_val;\
      }\
      to->size = sizeof(type);\
      return True;\
  }while (0 )


#line 284 "Animator.w"
static Boolean  cvtStringToImageList(
#if NeedFunctionPrototypes
Display *,XrmValuePtr ,Cardinal *,XrmValuePtr ,XrmValuePtr ,XtPointer *
#endif
);
#line 336 "Animator.w"
static Boolean  cvtStringToCardinalList(
#if NeedFunctionPrototypes
Display *,XrmValuePtr ,Cardinal *,XrmValuePtr ,XrmValuePtr ,XtPointer *
#endif
);
#line 233 "Animator.w"
/*ARGSUSED*/static void next_image(client_data,timer)XtPointer  client_data;XtIntervalId * timer;
{
    Widget self = (Widget) client_data;
    Cardinal delay;

    if (((XfwfAnimatorWidget)self)->xfwfAnimator.images[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image+1] == NULL) {
	if (! ((XfwfAnimatorWidget)self)->xfwfAnimator.cycle) return;			/* Nothing more */
	((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image = 0;
	((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval = 0;
	if (((XfwfAnimatorWidget)self)->xfwfAnimator.intervals == NULL || ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[0] == 0)
	    delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.defaultInterval;
	else
	    delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[0];
    } else {
	((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image++;
	if (((XfwfAnimatorWidget)self)->xfwfAnimator.intervals == NULL)
	    delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.defaultInterval;
	else if (((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval+1] == 0)
	    delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval];
	else {
	    ((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval++;
	    delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval];
	}
    }
    ((XfwfAnimatorWidgetClass)self->core.widget_class)->core_class.expose(self, NULL, NULL);
    ((XfwfAnimatorWidget)self)->xfwfAnimator.timer = XtAppAddTimeOut(XtWidgetToApplicationContext(self), delay,
			     next_image, self);
}
#line 284 "Animator.w"
/*ARGSUSED*/static Boolean  cvtStringToImageList(display,args,num_args,from,to,converter_data)Display * display;XrmValuePtr  args;Cardinal * num_args;XrmValuePtr  from;XrmValuePtr  to;XtPointer * converter_data;
{
    String p;
    XImage *im, *shape, **list = NULL;
    int status, n = 0;
    Cardinal one = 1;

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

    p = strtok((String) from->addr, " \t\n,");
    while (p) {
	status = XpmReadFileToImage(display, p, &im, &shape, NULL);
	switch (status) {
	case XpmOpenFailed:
	case XpmFileInvalid:
	case XpmNoMemory:
	    XtAppWarningMsg
		(XtDisplayToApplicationContext(display),
		 "cvtStringToImageList", "fileError",
		 "XtToolkitError",
		 "Failed to read image from \"%s\"",
		 &p, &one);
	    break;	    
	case XpmColorError:
	case XpmColorFailed:
	    XtAppWarningMsg
		(XtDisplayToApplicationContext(display),
		 "cvtStringToImageList", "allocColor",
		 "XtToolkitError",
		 "Could not get (all) colors for image \"%s\"",
		 &p, &one);
	case XpmSuccess:
	    n++;
	    list = (XImage**) XtRealloc((char*) list, n * sizeof(im));
	    list[n-1] = im;
	}
	p = strtok(NULL, " \t\n,");
    }
    if (n > 0) {
	n++;
	list = (XImage**) XtRealloc((char*) list, n * sizeof(im));
	list[n-1] = NULL;
    }
    done(XImage**, list);
}
#line 336 "Animator.w"
/*ARGSUSED*/static Boolean  cvtStringToCardinalList(display,args,num_args,from,to,converter_data)Display * display;XrmValuePtr  args;Cardinal * num_args;XrmValuePtr  from;XrmValuePtr  to;XtPointer * converter_data;
{
    String p;
    Cardinal *list = NULL;
    int n = 0, h, stat;

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

    p = (char *) from->addr;
    do {
	n++;
	list = (Cardinal*) XtRealloc((char*) list, n * sizeof(Cardinal));
	/* list[n-1] = strtoul(p, &p, 0); */
	stat = sscanf(p, "%u%n", &list[n-1], &h);
	p = p + h;
	fprintf(stderr, "scanned %d (%u)\n", stat, list[n-1]);
    } while (stat == 1 && list[n-1] != 0);
    list[n-1] = 0;
    done(Cardinal *, list);
}

static XtResource resources[] = {
#line 26 "Animator.w"
{XtNimages,XtCImages,XtRImageList,sizeof(((XfwfAnimatorRec*)NULL)->xfwfAnimator.images),XtOffsetOf(XfwfAnimatorRec,xfwfAnimator.images),XtRImmediate,(XtPointer)NULL },
#line 35 "Animator.w"
{XtNintervals,XtCIntervals,XtRCardinalList,sizeof(((XfwfAnimatorRec*)NULL)->xfwfAnimator.intervals),XtOffsetOf(XfwfAnimatorRec,xfwfAnimator.intervals),XtRImmediate,(XtPointer)NULL },
#line 40 "Animator.w"
{XtNdefaultInterval,XtCDefaultInterval,XtRCardinal,sizeof(((XfwfAnimatorRec*)NULL)->xfwfAnimator.defaultInterval),XtOffsetOf(XfwfAnimatorRec,xfwfAnimator.defaultInterval),XtRImmediate,(XtPointer)500 },
#line 46 "Animator.w"
{XtNcycle,XtCCycle,XtRBoolean,sizeof(((XfwfAnimatorRec*)NULL)->xfwfAnimator.cycle),XtOffsetOf(XfwfAnimatorRec,xfwfAnimator.cycle),XtRImmediate,(XtPointer)True },
#line 50 "Animator.w"
{XtNframeType,XtCFrameType,XtRFrameType,sizeof(((XfwfAnimatorRec*)NULL)->xfwfFrame.frameType),XtOffsetOf(XfwfAnimatorRec,xfwfFrame.frameType),XtRImmediate,(XtPointer)XfwfSunken },
#line 56 "Animator.w"
{XtNrel_width,XtCRel_width,XtRFloat,sizeof(((XfwfAnimatorRec*)NULL)->xfwfBoard.rel_width),XtOffsetOf(XfwfAnimatorRec,xfwfBoard.rel_width),XtRString,(XtPointer)"0.0"},
#line 57 "Animator.w"
{XtNabs_width,XtCAbs_width,XtRInt,sizeof(((XfwfAnimatorRec*)NULL)->xfwfBoard.abs_width),XtOffsetOf(XfwfAnimatorRec,xfwfBoard.abs_width),XtRImmediate,(XtPointer)7 },
#line 58 "Animator.w"
{XtNrel_height,XtCRel_height,XtRFloat,sizeof(((XfwfAnimatorRec*)NULL)->xfwfBoard.rel_height),XtOffsetOf(XfwfAnimatorRec,xfwfBoard.rel_height),XtRString,(XtPointer)"0.0"},
#line 59 "Animator.w"
{XtNabs_height,XtCAbs_height,XtRInt,sizeof(((XfwfAnimatorRec*)NULL)->xfwfBoard.abs_height),XtOffsetOf(XfwfAnimatorRec,xfwfBoard.abs_height),XtRImmediate,(XtPointer)7 },
};

XfwfAnimatorClassRec xfwfAnimatorClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfBoardClassRec,
"XfwfAnimator",
sizeof(XfwfAnimatorRec),
class_initialize,
_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,
},
{ /* XfwfAnimator_class part */
start_animation,
stop_animation,
},
};
WidgetClass xfwfAnimatorWidgetClass = (WidgetClass) &xfwfAnimatorClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfAnimatorWidgetClass c = (XfwfAnimatorWidgetClass) class;
  XfwfAnimatorWidgetClass super;
  if (class == xfwfAnimatorWidgetClass) return;
  super = (XfwfAnimatorWidgetClass) c->core_class.superclass;
  if (c->xfwfAnimator_class.start_animation == XtInherit_start_animation)
    c->xfwfAnimator_class.start_animation = super->xfwfAnimator_class.start_animation;
  if (c->xfwfAnimator_class.stop_animation == XtInherit_stop_animation)
    c->xfwfAnimator_class.stop_animation = super->xfwfAnimator_class.stop_animation;
}
#line 109 "Animator.w"
/*ARGSUSED*/static void class_initialize()
{
    XtSetTypeConverter(XtRString, XtRImageList, cvtStringToImageList,
		       NULL, 0, XtCacheNone, NULL);
    XtSetTypeConverter(XtRString, XtRCardinalList, cvtStringToCardinalList,
		       NULL, 0, XtCacheNone, NULL);
}
#line 121 "Animator.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Dimension wd, ht, dummy1, dummy2;
    Position x, y;
    XImage **p;
    XtGCMask value_mask = 0;
    XGCValues values;

    ((XfwfAnimatorWidget)self)->xfwfAnimator.timer = NULL;
    ((XfwfAnimatorWidget)self)->xfwfAnimator.image_gc = XtGetGC(self, value_mask, &values);
    if (((XfwfAnimatorWidget)self)->xfwfAnimator.images != NULL) {
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &dummy1, &dummy2);
	wd = 1; ht = 1;
	for (p = ((XfwfAnimatorWidget)self)->xfwfAnimator.images; *p; p++) {
	    if ((*p)->width > wd) wd = (*p)->width;
	    if ((*p)->height > ht) ht = (*p)->height;
	}
	XtVaSetValues(self, XtNwidth, wd + 2*x, XtNheight, ht + 2*y, NULL);
    }
}
#line 148 "Animator.w"
/*ARGSUSED*/static void start_animation(self)Widget self;
{
    Cardinal delay;

    if (! ((XfwfAnimatorWidget)self)->xfwfAnimator.images) return;
    if (((XfwfAnimatorWidget)self)->xfwfAnimator.timer) XtRemoveTimeOut(((XfwfAnimatorWidget)self)->xfwfAnimator.timer);
    ((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image = 0;
    ((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval = 0;
    if (! ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals || ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[0] == 0)
	delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.defaultInterval;
    else
	delay = ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_interval];
    ((XfwfAnimatorWidgetClass)self->core.widget_class)->core_class.expose(self, NULL, NULL);
    ((XfwfAnimatorWidget)self)->xfwfAnimator.timer = XtAppAddTimeOut(XtWidgetToApplicationContext(self), delay,
			     next_image, self);
}
#line 168 "Animator.w"
/*ARGSUSED*/static void stop_animation(self)Widget self;
{
    if (((XfwfAnimatorWidget)self)->xfwfAnimator.timer) {
	XtRemoveTimeOut(((XfwfAnimatorWidget)self)->xfwfAnimator.timer);
	((XfwfAnimatorWidget)self)->xfwfAnimator.timer = NULL;
    }
}
#line 180 "Animator.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 (region != NULL)
	XSetRegion(XtDisplay(self), ((XfwfAnimatorWidget)self)->xfwfAnimator.image_gc, region);
    ((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &wd, &ht);
    if (((XfwfAnimatorWidget)self)->xfwfAnimator.images) XPutImage(XtDisplay(self), XtWindow(self), ((XfwfAnimatorWidget)self)->xfwfAnimator.image_gc,
			   ((XfwfAnimatorWidget)self)->xfwfAnimator.images[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image], 0, 0, x, y,
			   ((XfwfAnimatorWidget)self)->xfwfAnimator.images[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image]->width,
			   ((XfwfAnimatorWidget)self)->xfwfAnimator.images[((XfwfAnimatorWidget)self)->xfwfAnimator.cur_image]->height);
    if (region != NULL)
	XSetClipMask(XtDisplay(self), ((XfwfAnimatorWidget)self)->xfwfAnimator.image_gc, None);
    xfwfBoardClassRec.core_class.expose(self, event, region);
}
#line 198 "Animator.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Dimension wd, ht, dummy1, dummy2;
    Position x, y;
    XImage **p;
    Boolean restart = False;

    if (((XfwfAnimatorWidget)old)->xfwfAnimator.images != ((XfwfAnimatorWidget)self)->xfwfAnimator.images) {
	if (((XfwfAnimatorWidget)self)->xfwfAnimator.timer) restart = True;
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfAnimator_class.stop_animation(self);
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &dummy1, &dummy2);
	wd = 1; ht = 1;
	for (p = ((XfwfAnimatorWidget)self)->xfwfAnimator.images; *p; p++) {
	    if ((*p)->width > wd) wd = (*p)->width;
	    if ((*p)->height > ht) ht = (*p)->height;
	}
	XtVaSetValues(self, XtNwidth, wd + 2*x, XtNheight, ht + 2*y, NULL);
    }
    if (((XfwfAnimatorWidget)old)->xfwfAnimator.intervals != ((XfwfAnimatorWidget)self)->xfwfAnimator.intervals) {
	if (((XfwfAnimatorWidget)self)->xfwfAnimator.timer) restart = True;
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfAnimator_class.stop_animation(self);
    }
    if (restart) ((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfAnimator_class.start_animation(self);
    return False;
}
#line 86 "Animator.w"
/*ARGSUSED*/void XfwfStartAnimation(self)Widget self;
{
    if (! XtIsSubclass(self, xfwfAnimatorWidgetClass))
	XtWarning("Illegal widget type in XfwfStartAnimation");
    else
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfAnimator_class.start_animation(self);
}
#line 96 "Animator.w"
/*ARGSUSED*/void XfwfStopAnimation(self)Widget self;
{
    if (! XtIsSubclass(self, xfwfAnimatorWidgetClass))
	XtWarning("Illegal widget type in XfwfStopAnimation");
    else
	((XfwfAnimatorWidgetClass)self->core.widget_class)->xfwfAnimator_class.stop_animation(self);
}
