/* Generated by wbuild from "Toggle.w"
** (generator version $Revision: 1.17 $ of $Date: 92/12/07 19:32:00 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 160 "Toggle.w"
#include "tick.bm"
#include <Xfwf/ToggleP.h>
#line 54 "Toggle.w"
static void toggle(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
#line 64 "Toggle.w"
static void switch_on(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
#line 76 "Toggle.w"
static void switch_off(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);

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

static char defaultTranslations[] = "\
<Btn1Down>,<Btn1Up>: toggle() \n\
<Key>Return: toggle() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 97 "Toggle.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 107 "Toggle.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 120 "Toggle.w"
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region 
#endif
);
#line 142 "Toggle.w"
static void create_tickgc(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 142 "Toggle.w"
/*ARGSUSED*/static void create_tickgc(self)Widget self;
{
    XtGCMask mask;
    XGCValues values;

    if (((XfwfToggleWidget)self)->xfwfToggle.tickgc != NULL) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.tickgc);
    mask = GCForeground | GCStipple | GCFillStyle;
    values.foreground = ((XfwfToggleWidget)self)->xfwfLabel.foreground;
    values.stipple = XCreateBitmapFromData(XtDisplay(self),
        RootWindowOfScreen(XtScreen(self)), tick_bits, tick_width, tick_height);
    if (! values.stipple) XtError("Couldn't create bitmap for tick mark");
    values.fill_style = FillStippled;
    ((XfwfToggleWidget)self)->xfwfToggle.tickgc = XtGetGC(self, mask, &values);
}

static XtResource resources[] = {
#line 17 "Toggle.w"
{XtNonCallback,XtCOnCallback,XtRCallback,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.onCallback),XtOffsetOf(XfwfToggleRec,xfwfToggle.onCallback),XtRImmediate,(XtPointer)NULL },
#line 23 "Toggle.w"
{XtNoffCallback,XtCOffCallback,XtRCallback,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.offCallback),XtOffsetOf(XfwfToggleRec,xfwfToggle.offCallback),XtRImmediate,(XtPointer)NULL },
#line 30 "Toggle.w"
{XtNtickmark,XtCTickmark,XtRBoolean,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.tickmark),XtOffsetOf(XfwfToggleRec,xfwfToggle.tickmark),XtRImmediate,(XtPointer)True },
#line 35 "Toggle.w"
{XtNon,XtCOn,XtRBoolean,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.on),XtOffsetOf(XfwfToggleRec,xfwfToggle.on),XtRImmediate,(XtPointer)False },
};

XfwfToggleClassRec xfwfToggleClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfButtonClassRec,
"XfwfToggle",
sizeof(XfwfToggleRec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
actionsList,
3,
resources,
4,
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,
},
{ /* XfwfLabel_class part */
XtInherit_set_label,
},
{ /* XfwfButton_class part */
0
},
{ /* XfwfToggle_class part */
0
},
};
WidgetClass xfwfToggleWidgetClass = (WidgetClass) &xfwfToggleClassRec;
/*ARGSUSED*/
#line 54 "Toggle.w"
static void toggle(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    XtVaSetValues(self, "on", !((XfwfToggleWidget)self)->xfwfToggle.on, NULL);
    XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.on ? ((XfwfToggleWidget)self)->xfwfToggle.onCallback : ((XfwfToggleWidget)self)->xfwfToggle.offCallback, event);
}

/*ARGSUSED*/
#line 64 "Toggle.w"
static void switch_on(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    if (! ((XfwfToggleWidget)self)->xfwfToggle.on) {
        XtVaSetValues(self, "on", True, NULL);
        XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.onCallback, event);
    }
}

/*ARGSUSED*/
#line 76 "Toggle.w"
static void switch_off(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
    if (((XfwfToggleWidget)self)->xfwfToggle.on) {
        XtVaSetValues(self, "on", False, NULL);
        XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.offCallback, event);
    }
}

static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfToggleWidgetClass c = (XfwfToggleWidgetClass) class;
  XfwfToggleWidgetClass super;
  if (class == xfwfToggleWidgetClass) return;
  super = (XfwfToggleWidgetClass) c->core_class.superclass;
}
#line 97 "Toggle.w"
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    ((XfwfToggleWidget)self)->xfwfToggle.tickgc = NULL;
    create_tickgc(self);
}
#line 107 "Toggle.w"
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    if (((XfwfToggleWidget)self)->xfwfLabel.foreground != ((XfwfToggleWidget)old)->xfwfLabel.foreground)
        create_tickgc(self);
    if (((XfwfToggleWidget)self)->xfwfToggle.on != ((XfwfToggleWidget)old)->xfwfToggle.on && ((XfwfToggleWidget)self)->xfwfToggle.tickmark)
        return True;
    else
        return False;
}
#line 120 "Toggle.w"
/*ARGSUSED*/static void expose(self,event,region)Widget self;XEvent * event;Region  region;
{
    Position x, y;
    Dimension w, h;

    if (! XtIsRealized(self)) return;
    xfwfButtonClassRec.core_class.expose(self, event, region);
    if (((XfwfToggleWidget)self)->xfwfToggle.tickmark && ((XfwfToggleWidget)self)->xfwfToggle.on) {
        ((XfwfToggleWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
        y = y + (h - tick_height)/2;
	XSetTSOrigin(XtDisplay(self), ((XfwfToggleWidget)self)->xfwfToggle.tickgc, x, y);
        XFillRectangle(XtDisplay(self), XtWindow(self), ((XfwfToggleWidget)self)->xfwfToggle.tickgc, x, y,
            tick_width, tick_height);
    }
}
