(3)

NAME
XfwfToggle

DESCRIPTION
The XfwfToggle is a button that switches states with every activation (which is by default with every mouse click). The states are named `on' and `off'. The states can be indicated with a $urd$ before the label Two callbacks report the changed state to the application: onCallback is called when the button switches to `on', offCallback is called when the button switches back to `off'.

  Public variables
XfwfToggle
Name | Class | Type | Default
XtNonCallback | XtCOnCallback | Callback | NULL
XtNoffCallback | XtCOffCallback | Callback | NULL
XtNtickmark | XtCTickmark | Boolean | True
XtNon | XtCOn | Boolean | False

XtNonCallback
    The onCallback is called by the toggle action or by the switch_on action, if the previous state was `off'. The call_data argument will contain the XEvent pointer that trigerred the action function.
    <Callback> XtCallbackList  onCallback = NULL

XtNoffCallback
    The offCallback is called from the toggle or switch_off action, if the previous state was `on'. The call_data argument will be a pointer to the XEvent that caused the action.
    <Callback> XtCallbackList  offCallback = NULL

XtNtickmark
    The tickmark resource controls whether the label in the button will be prefixed with a tick mark $urd$ in the `on' state. If tickmark is False, the application should find some other means of indicating the state, e.g, by changing the label.
    Boolean  tickmark = True

XtNon
    The variable on records the state of the widget: True means `on' and False means `off'.
    Boolean  on = False
    XfwfButton
    Name | Class | Type | Default
    XtNactivate | XtCActivate | Callback | NULL
    XfwfLabel
    Name | Class | Type | Default
    XtNlabel | XtCLabel | String | NULL
    XtNfont | XtCFont | FontStruct | XtDefaultFont
    XtNforeground | XtCForeground | Pixel | XtDefaultForeground
    XtNalignment | XtCAlignment | Alignment | 0
    XtNmargin | XtCMargin | Int | 2
    XtNshrinkToFit | XtCShrinkToFit | Boolean | False
    XtNrvStart | XtCRvStart | Int | 0
    XtNrvLength | XtCRvLength | Int | 0
    XfwfBoard
    Name | Class | Type | Default
    XtNabs_x | XtCAbs_x | Int | 0
    XtNrel_x | XtCRel_x | Float | "0.0"
    XtNabs_y | XtCAbs_y | Int | 0
    XtNrel_y | XtCRel_y | Float | "0.0"
    XtNabs_width | XtCAbs_width | Int | 0
    XtNrel_width | XtCRel_width | Float | "1.0"
    XtNabs_height | XtCAbs_height | Int | 0
    XtNrel_height | XtCRel_height | Float | "1.0"
    XtNhunit | XtCHunit | Float | "1.0"
    XtNvunit | XtCVunit | Float | "1.0"
    XtNlocation | XtCLocation | String | NULL
    XfwfFrame
    Name | Class | Type | Default
    XtNcursor | XtCCursor | Cursor | None
    XtNframeType | XtCFrameType | FrameType | XfwfRaised
    XtNframeWidth | XtCFrameWidth | Dimension | 0
    XtNframeOffset | XtCFrameOffset | Dimension | 0
    XtNshadowScheme | XtCShadowScheme | ShadowScheme | XfwfAuto
    XtNlightColor | XtCLightColor | Pixel | XtDefaultBackground
    XtNdarkColor | XtCDarkColor | Pixel | XtDefaultForeground
    XtNlightStipple | XtCLightStipple | Bitmap | NULL
    XtNdarkStipple | XtCDarkStipple | Bitmap | NULL
    XfwfCommon
    Name | Class | Type | Default
    XtNtraversalOn | XtCTraversalOn | Boolean | True
    XtNhighlightThickness | XtCHighlightThickness | Dimension | 2
    XtNhighlightColor | XtCHighlightColor | Pixel | XtDefaultForeground
    XtNhighlightPixmap | XtCHighlightPixmap | Pixmap | None
    XtNnextTop | XtCNextTop | Callback | NULL
    XtNuserData | XtCUserData | Pointer | NULL
    Composite
    Name | Class | Type | Default
    XtNchildren | XtCChildren | WidgetList | NULL
    insertPosition | XtCInsertPosition | XTOrderProc | NULL
    numChildren | XtCNumChildren | Cardinal | 0
    Core
    Name | Class | Type | Default
    XtNx | XtCX | Position | 0
    XtNy | XtCY | Position | 0
    XtNwidth | XtCWidth | Dimension | 0
    XtNheight | XtCHeight | Dimension | 0
    borderWidth | XtCBorderWidth | Dimension | 0
    XtNcolormap | XtCColormap | Colormap | NULL
    XtNdepth | XtCDepth | Int | 0
    destroyCallback | XtCDestroyCallback | XTCallbackList | NULL
    XtNsensitive | XtCSensitive | Boolean | True
    XtNtranslations | XtCTranslations | XTTranslations | NULL
    ancestorSensitive | XtCAncestorSensitive | Boolean | False
    accelerators | XtCAccelerators | XTTranslations | NULL
    borderColor | XtCBorderColor | Pixel | 0
    borderPixmap | XtCBorderPixmap | Pixmap | NULL
    background | XtCBackground | Pixel | 0
    backgroundPixmap | XtCBackgroundPixmap | Pixmap | NULL
    mappedWhenManaged | XtCMappedWhenManaged | Boolean | True
    XtNscreen | XtCScreen | Screen * | NULL

  Translations
The toggle action toggles the widget between `on' and `off'. By default it is bound to a click of the left mouse button as well as to the Return key.
<Btn1Down>,<Btn1Up>: toggle()
<Key>Return: toggle()

  Actions

toggle
    The toggle action switches the state. Depending on the resources tickmark and invert it might change the label or the colors or both. The onCallback or offCallback functions are called, with the event as call_data argument.
    void toggle($, XEvent* event, String* params, Cardinal* num_params)
    {
        XtVaSetValues($, "on", !$on, NULL);
        XtCallCallbackList($, $on ? $onCallback : $offCallback, event);
    }

switch_on
    The switch_on action switches the button to `on' if it is `off', otherwise it does nothing. By default it isn't bound to any event. If the widget is changed, the onCallback is called with the event as call_data.
    void switch_on($, XEvent* event, String* params, Cardinal* num_params)
    {
        if (! $on) {
            XtVaSetValues($, "on", True, NULL);
            XtCallCallbackList($, $onCallback, event);
        }
    }

switch_off
    The switch_off action switches the widget to `off' if the state is `on', otherwise it does nothing. When the widget changes states, the offCallback is called, with a pointer to the XEvent structure as call_data argument.
    void switch_off($, XEvent* event, String* params, Cardinal* num_params)
    {
        if ($on) {
            XtVaSetValues($, "on", False, NULL);
            XtCallCallbackList($, $offCallback, event);
        }
    }

Importss
incl
 "tick.bm"

  Private variables
The tickgc GC holds the picture of a tick mark as a stipple.
GC  tickgc

  Methods
The tick mark is a small bitmap that is created in a utility function and put into a GC called tickgc.
initialize(Widget  request, $, ArgList  args, Cardinal * num_args)
{
    $tickgc = NULL;
    create_tickgc($);
}
When the on resource changes, the set_values method inspects the tickmark resource to see if the widget needs to be redrawn (to add or remove the tick mark).
Boolean  set_values(Widget  old, Widget  request, $, ArgList  args, Cardinal * num_args)
{
    if ($foreground != $old$foreground)
        create_tickgc($);
    if ($on != $old$on  $tickmark)
        return True;
    else
        return False;
}
The expose method uses the expose method of the superclass to draw the button and then possibly adds a tick mark.
expose($, XEvent * event, Region  region)
{
    Position x, y;
    Dimension w, h;
    if (! XtIsRealized($)) return;
    #expose($, event, region);
    if ($tickmark  $on) {
        $compute_inside($, x, y, w, h);
        y = y + (h - tick_height)/2;
	XSetTSOrigin(XtDisplay($), $tickgc, x, y);
        XFillRectangle(XtDisplay($), XtWindow($), $tickgc, x, y,
            tick_width, tick_height);
    }
}

Utilities
The create_tickgc function creates a GC with the tick mark bitmap as a stipple and the foreground_pixel as the foreground.
create_tickgc($)
{
    XtGCMask mask;
    XGCValues values;
    if ($tickgc != NULL) XtReleaseGC($, $tickgc);
    mask = GCForeground | GCStipple | GCFillStyle;
    values.foreground = $foreground;
    values.stipple = XCreateBitmapFromData(XtDisplay($),
        RootWindowOfScreen(XtScreen($)), tick_bits, tick_width, tick_height);
    if (! values.stipple) XtError("Couldn't create bitmap for tick mark");
    values.fill_style = FillStippled;
    $tickgc = XtGetGC($, mask, values);
}