(3)

NAME
XfwfOptionButton

DESCRIPTION
The option button is very much like a PullDown button, except that the label of the button is automatically set to the label of the last selected menu item. There are now three ways to specify the menu: with the popup resource, with the menu resource, or with the options resource. When the popup resource is used, the option button cannot update its own label, so it becomes the responsibility of the application that created the pop up widget to set the label. The same goes for the use of the menu resource. Much more convenient is the options resource. It should be set simply to a newline-separated list of items. When the user presses the mouse buttonon the button, the activateCallback function is called and then the menu is popped up. When an item from the menu is chosen, the option button's label will be set to reflect the choice and the callback callbacks will ba called, with the chosen item as call_data.

  Public variables
XfwfOptionButton
Name | Class | Type | Default
XtNcallback | XtCCallback | Callback | NULL
XtNoptions | XtCOptions | String | NULL

XtNcallback
    One additional callback is defined, simply called callback. It is called when a choice is made from the options menu (and the options menu has been created with the options resource), but only when the choice is different from the previous choice (as stored in the option button's label.) The call_data argument will contain the new label.
    <Callback> XtCallbackList  callback = NULL

XtNoptions
    The options resource can be set to a newline-separated list of items. If it is set, it will override the menu and popup resources.
    String  options = NULL

XtNframeWidth
    The frame width is again set to a default of 2 pixels.
     frameWidth = 2
    XfwfPullDown
    Name | Class | Type | Default
    XtNpopup | XtCPopup | Widget | NULL
    XtNmenu | XtCMenu | String | NULL
    XtNhotkey | XtCHotkey | String | NULL
    XtNmenuCursor | XtCMenuCursor | Cursor | "arrow"
    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
Since wbuild cannot yet inherit translations, they must be given again.
<Btn1Down>: open_menu()
Button1<Enter>: open_menu()
<Key>Return: open_menu()

  Actions

menu_action
    The menu_action action routine is called when an option from the options menu is selected. It will set the label of the option button, and, if the label is different from the previous one, it will also call the callback functions, with the new label as call_data.
    void menu_action($, XEvent* event, String* params, Cardinal* num_params)
    {
        Widget button = XtParent($);
        if ($button$label  strcmp($button$label, params[0]) == 0) return;
        XtVaSetValues(button, XtNlabel, params[0], NULL);
        XtCallCallbackList(button, $button$callback, $button$label);
    }

Importss
incl
 <stdio.h>

  Methods
The initialize method checks if the options resource has been set and if so, creates a matching menu resource string.
initialize(Widget  request, $, ArgList  args, Cardinal * num_args)
{
    if ($options != NULL)
	create_menu_string($);
}
The set_values method does something similar.
Boolean  set_values(Widget  old, Widget  request, $, ArgList  args, Cardinal * num_args)
{
    String s;
    if ($old$options != $options)
	create_menu_string($);
    return False;
}

Utilities
The create_menu_string routine creates a string in the appropriate syntax for the menu resource. The length is initialized to 1, because the allocated length must always be one greater than the length of the string, to accomodate the null byte.
create_menu_string($)
{
    String p, s = NULL;
    int l = 1;
    s = XtMalloc(1);
    s[0]= '\0';
    p = strtok($options, "\n");
    while (p != NULL) {
	l += 2*strlen(p) + strlen("(item \"\" (action \"menu_action()\"))");
	s = XtRealloc(s, l);
	if (s == NULL) XtError("Out of memory");
	(void) strcat(s, "(item \"");
	(void) strcat(s, p);
	(void) strcat(s, "\" (action \"menu_action(");
	(void) strcat(s, p);
	(void) strcat(s, ")\"))");
	p = strtok(NULL, "\n");
    }
    XtVaSetValues($, XtNmenu, s, NULL);
}