[Contents] [Index] [Next] [Previous]

XmToggleButton


NAME

XmToggleButton - The ToggleButton widget class

SYNOPSIS

#include <Xm/ToggleB.h>

DESCRIPTION

ToggleButton sets nontransitory state data within an application. Usually this widget consists of an indicator (square or diamond) with either text or a pixmap on one side of it. However, it can also consist of just text or a pixmap without the indicator.

The toggle graphics display a 1-of-many or N-of-many selection state. When a toggle indicator is displayed, a square indicator shows an N-of-many selection state and a diamond indicator shows a 1-of-many selection state.

ToggleButton implies a selected or unselected state. In the case of a label and an indicator, an empty indicator (square or diamond shaped) indicates that ToggleButton is unselected, and a filled indicator shows that it is selected. In the case of a pixmap toggle, different pixmaps are used to display the selected/unselected states.

The default behavior associated with a ToggleButton in a menu depends on the type of menu system in which it resides. By default, BSelect controls the behavior of the ToggleButton. In addition, BMenu controls the behavior of the ToggleButton if it resides in a PopupMenu system. The actual mouse button used is determined by its RowColumn parent.

To accommodate the toggle indicator when created, Label's resource XmNmarginLeft may be increased.

Classes

ToggleButton inherits behavior and resources from Core, XmPrimitive, and XmLabel Classes.

The class pointer is xmToggleButtonWidgetClass.

The class name is XmToggleButton.

New Resources

The following table defines a set of widget resources used by the programmer to specify data. The programmer can also set the resource values for the inherited classes to set attributes for this widget. To reference a resource by name or by class in a .Xdefaults file, remove the XmN or XmC prefix and use the remaining letters. To specify one of the defined values for a resource in a .Xdefaults file, remove the Xm prefix and use the remaining letters (in either lowercase or uppercase, but include any underscores between words). The codes in the access column indicate if the given resource can be set at creation time (C), set by using XtSetValues (S), retrieved by using XtGetValues (G), or is not applicable (N/A).

XmToggleButton Resource Set
Name Class Type Default Access
XmNarmCallback XmCArmCallback XtCallbackList NULL C
XmNdisarmCallback XmCDisarmCallback XtCallbackList NULL C
XmNfillOnSelect XmCFillOnSelect Boolean dynamic CSG
XmNindicatorOn XmCIndicatorOn Boolean True CSG
XmNindicatorSize XmCIndicatorSize Dimension dynamic CSG
XmNindicatorType XmCIndicatorType unsigned char dynamic CSG
XmNselectColor XmCSelectColor Pixel dynamic CSG
XmNselectInsensitivePixmap XmCSelectInsensitivePixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNselectPixmap XmCSelectPixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNset XmCSet Boolean False CSG
XmNspacing XmCSpacing Dimension 4 CSG
XmNvalueChangedCallback XmCValueChangedCallback XtCallbackList NULL C
XmNvisibleWhenOff XmCVisibleWhenOff Boolean dynamic CSG
XmNarmCallback
Specifies the list of callbacks called when the ToggleButton is armed. To arm this widget, press the active mouse button while the pointer is inside the ToggleButton. For this callback, the reason is XmCR_ARM.
XmNdisarmCallback
Specifies the list of callbacks called when ToggleButton is disarmed. To disarm this widget, press and release the active mouse button while the pointer is inside the ToggleButton. This widget is also disarmed when the user moves out of the widget and releases the mouse button when the pointer is outside the widget. For this callback, the reason is XmCR_DISARM.
XmNfillOnSelect
Fills the indicator with the color specified in XmNselectColor and switches the top and bottom shadow colors when set to True. Otherwise, it switches only the top and bottom shadow colors. The default is set to the value of XmNindicatorOn. When XmNindicatorOn is False, and XmNfillOnSelect is set explicitly to True, the background is filled with the color specified by XmNselectColor.
XmNindicatorOn
Specifies that a toggle indicator is drawn to one side of the toggle text or pixmap when set to True. When set to False, no space is allocated for the indicator, and it is not displayed. If XmNindicatorOn is True, the indicator shadows are switched when the button is selected or unselected, but, any shadows around the entire widget are not switched. However, if XmNindicatorOn is False, any shadows around the entire widget are switched when the toggle is selected or unselected.
XmNindicatorSize
Sets the size of the indicator. If no value is specified, the size of the indicator is based on the size of the label string or pixmap. If the label string or pixmap changes, the size of the indicator is recomputed based on the size of the label string or pixmap. Once a value has been specified for XmNindicatorSize, the indicator has that size, regardless of the size of the label string or pixmap, until a new value is specified.
XmNindicatorType
Specifies if the indicator is a 1-of or N-of indicator. For the 1-of indicator, the value is XmONE_OF_MANY. For the N-of indicator, the value is XmN_OF_MANY. The N-of-many indicator is square. The 1-of-many indicator is diamond shaped. This resource specifies only the visuals and does not enforce the behavior. When the ToggleButton is in a RadioBox, the default is XmONE_OF_MANY; otherwise, the default is XmN_OF_MANY.
XmNselectColor
Allows the application to specify what color fills the center of the square or diamond-shaped indicator when it is set. If this color is the same as either the top or the bottom shadow color of the indicator, a one-pixel-wide margin is left between the shadows and the fill; otherwise, it is filled completely. This resource's default for a color display is a color between the background and the bottom shadow color. For a monochrome display, the default is set to the foreground color. To set the background of the button to XmNselectColor when XmNindicatorOn is False, the value of XmNfillOnSelect must be explicitly set to True.
XmNselectInsensitivePixmap
Specifies a pixmap used as the button face when the ToggleButton is selected and the button is insensitive if the Label resource XmNlabelType is set to XmPIXMAP. If the ToggleButton is unselected and the button is insensitive, the pixmap in XmNlabelInsensitivePixmap is used as the button face. If no value is specified for XmNlabelInsensitivePixmap, that resource is set to the value specified for XmNselectInsensitivePixmap.
XmNselectPixmap
Specifies the pixmap to be used as the button face if XmNlabelType is XmPIXMAP and the ToggleButton is selected. When the ToggleButton is unselected, the pixmap specified in Label's XmNlabelPixmap is used. If no value is specified for XmNlabelPixmap, that resource is set to the value specified for XmNselectPixmap.
XmNset
Represents the state of the ToggleButton. A value of false indicates that the ToggleButton is not set. A value of true indicates that the ToggleButton is set. Setting this resource sets the state of the ToggleButton.
XmNspacing
Specifies the amount of spacing between the toggle indicator and the toggle label (text or pixmap).
XmNvalueChangedCallback
Specifies the list of callbacks called when the ToggleButton value is changed. To change the value, press and release the active mouse button while the pointer is inside the ToggleButton. This action also causes this widget to be disarmed. For this callback, the reason is XmCR_VALUE_CHANGED.
XmNvisibleWhenOff
Indicates that the toggle indicator is visible in the unselected state when the Boolean value is True. When the ToggleButton is in a menu, the default value is False. When the ToggleButton is in a RadioBox, the default value is True.

Inherited Resources

ToggleButton inherits behavior and resources from the following superclasses. For a complete description of each resource, refer to the man page for that superclass.

XmLabel Resource Set
Name Class Type Default Access
XmNaccelerator XmCAccelerator String NULL CSG
XmNacceleratorText XmCAcceleratorText XmString NULL CSG
XmNalignment XmCAlignment unsigned char dynamic CSG
XmNfontList XmCFontList XmFontList dynamic CSG
XmNlabelInsensitivePixmap XmCLabelInsensitivePixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNlabelPixmap XmCLabelPixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNlabelString XmCXmString XmString dynamic CSG
XmNlabelType XmCLabelType unsigned char XmSTRING CSG
XmNmarginBottom XmCMarginBottom Dimension dynamic CSG
XmNmarginHeight XmCMarginHeight Dimension 2 CSG
XmNmarginLeft XmCMarginLeft Dimension dynamic CSG
XmNmarginRight XmCMarginRight Dimension 0 CSG
XmNmarginTop XmCMarginTop Dimension dynamic CSG
XmNmarginWidth XmCMarginWidth Dimension 2 CSG
XmNmnemonic XmCMnemonic KeySym NULL CSG
XmNmnemonicCharSet XmCMnemonicCharSet String XmFONTLIST_DEFAULT_TAG CSG
XmNrecomputeSize XmCRecomputeSize Boolean True CSG
XmNstringDirection XmCStringDirection XmStringDirection dynamic CSG

XmPrimitive Resource Set
Name Class Type Default Access
XmNbottomShadowColor XmCBottomShadowColor Pixel dynamic CSG
XmNbottomShadowPixmap XmCBottomShadowPixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNforeground XmCForeground Pixel dynamic CSG
XmNhelpCallback XmCCallback XtCallbackList NULL C
XmNhighlightColor XmCHighlightColor Pixel dynamic CSG
XmNhighlightOnEnter XmCHighlightOnEnter Boolean False CSG
XmNhighlightPixmap XmCHighlightPixmap Pixmap dynamic CSG
XmNhighlightThickness XmCHighlightThickness Dimension 2 CSG
XmNnavigationType XmCNavigationType XmNavigationType XmNONE CSG
XmNshadowThickness XmCShadowThickness Dimension dynamic CSG
XmNtopShadowColor XmCTopShadowColor Pixel dynamic CSG
XmNtopShadowPixmap XmCTopShadowPixmap Pixmap dynamic CSG
XmNtraversalOn XmCTraversalOn Boolean True CSG
XmNunitType XmCUnitType unsigned char dynamic CSG
XmNuserData XmCUserData XtPointer NULL CSG

Core Resource Set
Name Class Type Default Access
XmNaccelerators XmCAccelerators XtAccelerators dynamic CSG
XmNancestorSensitive XmCSensitive Boolean dynamic G
XmNbackground XmCBackground Pixel dynamic CSG
XmNbackgroundPixmap XmCPixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNborderColor XmCBorderColor Pixel XtDefaultForeground CSG
XmNborderPixmap XmCPixmap Pixmap XmUNSPECIFIED_PIXMAP CSG
XmNborderWidth XmCBorderWidth Dimension 0 CSG
XmNcolormap XmCColormap Colormap dynamic CG
XmNdepth XmCDepth int dynamic CG
XmNdestroyCallback XmCCallback XtCallbackList NULL C
XmNheight XmCHeight Dimension dynamic CSG
XmNinitialResourcesPersistent XmCInitialResourcesPersistent Boolean True C
XmNmappedWhenManaged XmCMappedWhenManaged Boolean True CSG
XmNsensitive XmCSensitive Boolean True CSG
XmNtranslations XmCTranslations XtTranslations dynamic CSG
XmNwidth XmCWidth Dimension dynamic CSG
XmNx XmCPosition Position 0 CSG
XmNy XmCPosition Position 0 CSG

Callback Information

A pointer to the following structure is passed to each callback:

typedef struct
{
   int     reason;
   XEvent  * event;
   int     set;
} XmToggleButtonCallbackStruct;
reason
Indicates why the callback was invoked
event
Points to the XEvent that triggered the callback
set
Reflects the ToggleButton's current state when the callback occurred, either True (selected) or False (unselected)

Translations

XmToggleButton includes translations from Primitive. Additional XmToggleButton translations for buttons not in a menu system are listed below. These translations may not directly correspond to a translation table.

Note that altering translations in #override or #augment mode is undefined.

BDragPress:       ProcessDrag()
BSelect Press:    Arm()
BSelect Release:  Select()
                  Disarm()
KHelp:            Help()
KSelect:          ArmAndActivate()

XmToggleButton inherits menu traversal translations from XmLabel. Additional XmToggleButton translations for ToggleButtons in a menu system are listed below. In a Popup menu system, BMenu also performs the BSelect actions. These translations may not directly correspond to a translation table.

BSelect Press:    BtnDown()
BSelect Release:  BtnUp()
KHelp:            Help()
KActivate:        ArmAndActivate()
KSelect:          ArmAndActivate()
MAny KCancel:     MenuShellPopdownOne()

Action Routines

The XmToggleButton action routines are described below:

Arm():
If the button was previously unset, this action does the following: If XmNindicatorOn is True, it draws the indicator shadow so that the indicator looks pressed; if XmNfillOnSelect is True, it fills the indicator with the color specified by XmNselectColor. If XmNindicatorOn is False, it draws the button shadow so that the button looks pressed. If XmNlabelType is XmPIXMAP, the XmNselectPixmap is used as the button face. Calls the XmNarmCallback callbacks.

If the button was previously set, this action does the following: If both XmNindicatorOn and XmNvisibleWhenOff are True, it draws the indicator shadow so that the indicator looks raised; if XmNfillOnSelect is True, it fills the indicator with the background color. If XmNindicatorOn is False, it draws the button shadow so that the button looks raised. If XmNlabelType is XmPIXMAP, the XmNlabelPixmap is used as the button face. Calls the XmNarmCallback callbacks.

ArmAndActivate():
If the ToggleButton was previously set, unsets it; if the ToggleButton was previously unset, sets it.

In a menu, does the following: Unposts all menus in the menu hierarchy. Unless the button is already armed, calls the XmNarmCallback callbacks. Calls the XmNvalueChangedCallback and XmNdisarmCallback callbacks.

Outside a menu, if the button was previously unset, this action does the following: If XmNindicatorOn is True, it draws the indicator shadow so that the indicator looks pressed; if XmNfillOnSelect is True, it fills the indicator with the color specified by XmNselectColor. If XmNindicatorOn is False, it draws the button shadow so that the button looks pressed. If XmNlabelType is XmPIXMAP, the XmNselectPixmap is used as the button face. Calls the XmNarmCallback, XmNvalueChangedCallback, and XmNdisarmCallback callbacks.

Outside a menu, if the button was previously set, this action does the following: If both XmNindicatorOn and XmNvisibleWhenOff are True, it draws the indicator shadow so that the indicator looks raised; if XmNfillOnSelect is True, it fills the indicator with the background color. If XmNindicatorOn is False, it draws the button shadow so that the button looks raised. If XmNlabelType is XmPIXMAP, the XmNlabelPixmap is used as the button face. Calls the XmNarmCallback, XmNvalueChangedCallback, and XmNdisarmCallback callbacks.

BtnDown():
This action unposts any menus posted by the ToggleButton's parent menu, disables keyboard traversal for the menu, and enables mouse traversal for the menu. It draws the shadow in the armed state and, unless the button is already armed, calls the XmNarmCallback callbacks.
BtnUp():
This action unposts all menus in the menu hierarchy. If the ToggleButton was previously set, unsets it; if the ToggleButton was previously unset, sets it. It calls the XmNvalueChangedCallback callbacks and then the XmNdisarmCallback callbacks.
Disarm():
Calls the callbacks for XmNdisarmCallback.
Help():
In a Pulldown or Popup MenuPane, unposts all menus in the menu hierarchy and restores keyboard focus to the widget that had the focus before the menu system was entered. Calls the callbacks for XmNhelpCallback if any exist. If there are no help callbacks for this widget, this action calls the help callbacks for the nearest ancestor that has them.
MenuShellPopdownOne():
In a toplevel Pulldown MenuPane from a MenuBar, unposts the menu, disarms the MenuBar CascadeButton and the MenuBar, and restores keyboard focus to the widget that had the focus before the MenuBar was entered. In other Pulldown MenuPanes, unposts the menu.

In a Popup MenuPane, unposts the menu and restores keyboard focus to the widget from which the menu was posted.

ProcessDrag():
Drags the contents of a ToggleButton label, identified by pressing BDrag. This action creates a DragContext object whose XmNexportTargets resource is set to "COMPOUND_TEXT" for a label type of XmSTRING; otherwise, "PIXMAP" if the label type is XmPIXMAP. This action is undefined for ToggleButtons used in a menu system.
Select():
If the pointer is within the button, takes the following actions: If the button was previously unset, sets it; if the button was previously set, unsets it. Calls the XmNvalueChangedCallback callbacks.

Additional Behavior

This widget has the additional behavior described below:

<EnterWindow>:
In a menu, if keyboard traversal is enabled, this action does nothing. Otherwise, it draws the shadow in the armed state and calls the XmNarmCallback callbacks.

If the ToggleButton is not in a menu and the cursor leaves and then reenters the ToggleButton's window while the button is pressed, this action restores the button's armed appearance.

<LeaveWindow>:
In a menu, if keyboard traversal is enabled, this action does nothing. Otherwise, it draws the shadow in the unarmed state and calls the XmNdisarmCallback callbacks.

If the ToggleButton is not in a menu and the cursor leaves the ToggleButton's window while the button is pressed, this action restores the button's unarmed appearance.

Virtual Bindings

The bindings for virtual keys are vendor specific. For information about bindings for virtual buttons and keys, see VirtualBindings(3X).

RELATED INFORMATION

Core(3X), XmCreateRadioBox(3X), XmCreateToggleButton(3X), XmLabel(3X), XmPrimitive(3X), XmRowColumn(3X), XmToggleButtonGetState(3X), and XmToggleButtonSetState(3X).