XRPUSHBUTTON(3X)

NAME
XrPushButton - an editor that controls a set of pushbuttons.

SYNOPSIS
#include <X/Xlib.h>
#include <Xr/Xrlib.h>

xrEditor *
XrPushButton (instance, message, data)
xrEditor * instance;
INT32      message;
INT8     * data;

DESCRIPTION

The push button editor is used to create and process a group of related push buttons within a given window. The number of push buttons, and how they are displayed, is completely controlled by the application. Each push button may include an optional text label, which will be displayed in the center of the oval representing the button. This label may be a single line of text, or it may be multiple lines of text.

The size of the push buttons are proportional to the size of the font being used to display the text labels. By allowing an application to specify this font, the size of the push buttons can be adjusted for individual displays.

An application may specify one of the push buttons to be treated as a default selection. This implies that that button will be drawn with a double wide border around it. This feature may be disabled, if not needed.

This field editor supports two distinct sets of state flags: those associated with the whole instance (which are modified using MSG_GETSTATE and MSG_SETSTATE), and those which are assigned to the individual pushbuttons (which are modified using MSG_GETITEMSTATES and MSG_SETITEMSTATES). The state flags which are associated with the instance as a whole have precedence over the individual state flags. For example, if the XrVISIBLE flags is cleared for the instance, then none of the pushbuttons will be displayed, regardless of their individual state flag settings. But, if the XrVISIBLE flag is set for the instance, then the field editor will look at the state of the XrVISIBLE flag associated with each pushbutton, to determine if the entity should be displayed.

Using the cursor and the mouse, a user is able to interactively select a push button, by moving the cursor over one of the buttons, and 'clicking' the mouse button. When the mouse button is depressed, the selected push button will be drawn as active (solid filled); when the user releases the mouse button, the selected push button will be redrawn as inactive (not filled), and an event will be returned to the application, notifying it that a push button was selected.

When the editor draws the specified push button instance, it will attempt to space out the individual buttons, to take full advantage of the specified editorRect. If the rectangle is larger than needed, then the extra space will be divided equally as blank space between the rows and columns. If the rectangle is too small, then the request will fail.

When displaying a push button editor instance, the button sizes may vary between the various rows and columns. However, to help prevent the instance from looking disorganized, the following steps will be taken:

Each button within a particular horizontal row, will be the same height.

Each button within a particular vertical column, will be the same width.

EDITOR MESSAGES

MSG_NEW
    This message will be the means by which an application program can create a push button editor instance in a window. It will expect the instance parameter to be set to NULL, and the data parameter to point to a filled out instance of the following structure:

         typedef struct {
              Window       editorWindowId;
              RECTANGLE    editorRect;
              INT8         editorState;
              INT32        editorFGColor;
              INT32        editorBGColor;
              FontInfo   * editorFont;
              INT16        numFields;
              INT16        numCols;
              INT16        defaultButton;
              INT16        borderWidth;
              INT8      ** labels;
              INT8       * stateFlags;
          } xrPushButtonInfo;

    editorWindowId
    This field indicates the window to which the editor instance is to be attached. Anytime the instance is redrawn, it will be redrawn in this window.

    editorRect
    This describes the location and size of the region into which the push button instance is to be located. If the rectangle is larger than is needed to hold the specified instance, then the extra space will be used as padding between the individual push buttons. If the rectangle is too small, then the request will fail.

    editorState
    This field contains the initial value of the state flags for this editor instance. It can be composed of any combination of the XrSENSITIVE and XrVISIBLE flags.

    editorFGColor
    This field specifies the foreground color to be used when drawing the editor instance. This is used when displaying the button labels, and for filling an active button. If this is set to -1, the default foreground color (see XrInit(3X) ) will be used.

    editorBGColor
    This field specifies the background color to be used when drawing the editor instance. This is used for filling the interior of an inactive button. If this is set to -1, the default background color (see XrInit(3X) ) will be used.

    editorFont
    This is a pointer to a structure which describes the font to be used when creating this editor instance. If the pointer has been set to NULL, then the editor will use the default system base font. The font is important not only because it determines how the labels will look, but it is also used to determine how large the buttons should be.

    numFields
    This value indicates the total number of push buttons which are included in this instance. Once specified, this value cannot be changed.

    numCols
    This value indicates the number of columns into which the push buttons are to be displayed. Using this value, and numFields, the editor will automatically calculate the number of rows. If this value is greater than numFields, then the create request will fail.

    defaultButton
    This value indicates which push button should be displayed as the default selection; this involves drawing the button with a double wide border. This value must be in the range 0 - (numFields - 1); any value outside this range will disable this feature. Setting this field to -1 is the standard way to disable this feature.

    borderWidth
    This value describes the width of the border surrounding each of the push buttons. This value must be greater than zero.

    labels
    This is a pointer to an array of NULL terminated character strings, representing the labels associated with each push button. If this pointer is set to NULL, then none of the buttons will have labels. If any of the pointers within the array are NULL, or if a label has a length of zero, then those buttons will not have labels. The first entry in the array will correspond to push button 0, the second to push button 1, etc. The editor will not keep a copy of each of these strings; instead, it will only keep a copy of the pointer to the string array. It will rely on the application to NOT modify these strings, once the instance has been created.

    As was stated earlier, a label may be a single line of text, or multiple lines of text. To create multiple lines, insert a NEWLINE character (octal 012) at the end of each line of the label.

    stateFlags
    This is a pointer to an array of 8 bit integer values, each containing the initial state flag settings to be associated with each pushbutton in the instance. If this pointer has been set to NULL, then the state flags for each entity will be set to XrSENSITIVE and XrVISIBLE. The first entry in the array corresponds to pushbutton 0, etc.

    The editor will then draw the push button editor instance in the specified window.

    Upon successful completion, a pointer to the newly created editor structure will be returned to the application. This value must be used there after, whenever the application wishes to refer to this particular editor instance.

MSG_FREE
    This message is the mechanism by which an editor instance can be destroyed. The only parameter of importance is the instance parameter, which is a pointer to the editor structure, returned by the MSG_NEW message; this parameter specifies which instance is to be destroyed.

    When a push button instance is destroyed, it will be internally disconnected from the window to which it was attached, it will no longer handle mouse selects, and it will be removed from the window, if the instance is visible.

    After an editor instance has been destroyed, no further messages should be issued in regard to that instance.

MSG_GETSTATE
    This message returns the current state of the XrVISIBLE and XrSENSITIVE flags for the specified push button instance. The instance parameter specifies which instance to use. The data parameter should be a pointer to an 8 bit integer value, into which the current state flags will be placed. REMEMBER: these are the state flags for the whole instance; not the state flags for the individual buttons.

MSG_SETSTATE
    This message allows an application program to modify the setting of the XrSENSITIVE and XrVISIBLE flags, for a given push button editor instance. The data parameter is interpreted as an 8 bit integer value, containing the new state flag values. After saving the new state flags, the editor instance will be redrawn, to reflect the new state. If an instance is not visible, then the rectangle which it occupies will be drawn using the background tile for the window, thus making it invisible. If an instance is visible, but not sensitive, then each push button will be drawn and filled with a 50% pattern.

MSG_GETITEMSTATES
    This message allows an application to obtain a copy of the individual state flags associated with each of the pushbuttons contained within the specified editor instance. These state flags differ from the state flags obtained using MSG_GETSTATE. The instance parameter must specify the editor instance to be queried, while the data parameter should point to an array of 8 bit integer values. The state flags will be returned by means of this array. The flags associated with pushbutton 0 will be returned in the first slot in the array, etc.

MSG_SETITEMSTATES
    This message allows an application to modify the individual state flags associated with each of the pushbuttons contained within the specified editor instance. Presently, only the XrVISIBLE and XrSENSITIVE flags are supported. The instance parameter must specify the editor instance which is to be modified, while the data parameter should point to an array of 8 bit integer values. The new state flags which are to be assigned to each entity within the instance will be obtained from this array. The value in the first slot of the array will be assigned to pushbutton 0, etc. After the new state flags have been saved, only those pushbuttons whose state flags changed will be redrawn.

MSG_GETITEMCOUNT
    This message allows an application to obtain a count, which indicates the number of individual push buttons in the specified instance. The editor will assume that the instance parameter specifies the editor instance to query, and the data parameter points to a 32 bit integer value; the item count value will be returned by means of this integer.

    This message is useful when used in conjunction with the MSG_GETITEMRECTS message. It allows an application to obtain the number of items in the instance, so that the application can then allocate enough memory to hold the rectangle information returned by MSG_GETITEMRECTS.

MSG_GETITEMRECTS
    This message returns the coordinates for the rectangle which describes each of the individual push buttons. The message will expect the instance parameter to specify the editor instance to query, and the data parameter to point to a structure of the following format:

    	RECTANGLE   itemRects[x];

    This array will then be filled with the rectangle information, and returned to the application.

    Before an application can make this call, it needs to know the number of items in the specified instance, so that it can allocate a structure large enough to hold all of the rectangle information. The application should use the MSG_GETITEMCOUNT message to obtain this information; the application can then allocate an array large enough to hold all of the rectangle entries.

    The order of the rectangle items returned in the array directly correlates to the order the items were originally created in. The first element in the array will describe button 0, the second button 1, etc.

    This message is useful to those applications which have a need of knowing where the individual items in a push button instance are located. The most common use would be by a forms controller, which would use the information to place an 'active field' indicator by a given item.

MSG_REDRAW
    This editor provides an application with the means for requesting that an instance of push buttons be redrawn. The current values, labels and font information will be used.

    When this message is issued, the instance parameter must be a pointer to the editor structure associated with the instance to be redrawn. The data parameter must be a 32 bit integer which specifies the type of redraw to perform.

    This message is useful for when an application wishes to modify the value or the state flags for a particular button. The application need only modify the appropriate values in the shared arrays, and then issue a MSG_REDRAW request; the editor instance will automatically be drawn to match the new data.

    The push button editor supports the following redraw mode:

    - XrREDRAW_ALL

    When the XrREDRAW_ALL option is specified, the complete editor instance will be redrawn.

    If any other redraw mode is specified, then the request will fail.

MSG_SIZE
    This message allows an application to obtain the rectangle needed to contain a push button editor instance. The push button editor expects the instance parameter to be set to NULL, and the data parameter to point to an instance of the following structure:

         typedef struct {
              Window       editorWindowId;
              RECTANGLE    editorRect;
              INT8         editorState;
              INT32        editorFGColor;
              INT32        editorBGColor;
              FontInfo   * editorFont;
              INT16        numFields;
              INT16        numCols;
              INT16        defaultButton;
              INT16        borderWidth;
              INT8      ** labels;
              INT8       * stateFlags;
     } xrPushButtonInfo;

    The only fields which must be filled out by the application program BEFORE issuing this call, are the numFields, numCols, labels, borderWidth, defaultButton and editorFont fields; all other fields are ignored.

    In return, the editorRect field will be filled in with the coordinates for the 0 based rectangle needed to contain the instance; an application can then offset and stretch this rectangle, to position it where ever it likes, within its window.

    If numCols > numFields, then the request will fail.

MSG_MOVE
    This message provides an application with a means for quickly relocating a particular editor instance within a window. The size of the editorRect associated with the instance is not changed. To relocate an editor instance, a new origin point for the instance's editorRect must be specified; the top left corner of the editor rectangle will then be translated such that it now coincides with the new origin. The origin point is interpreted as an absolute position within the window.

    When this message is issued, the instance parameter must point to the editor structure associated with the instance which is to be moved, while the data parameter must point to a POINT structure, containing the new editorRect origin.

    When an editor instance is relocated, the field editor will automatically remove the visual image of the instance from the window, and will then redraw the instance at its new location; this occurs only if the instance is visible.

MSG_RESIZE
    This message provides an application with a means for both changing the size of the editorRect associated with a particular editor instance, and also the location of the new editorRect. All restrictions regarding the editorRect size which applied when the instance was first created using MSG_NEW, still apply. If an invalid editorRect is specified, then the resize request will fail.

    When this message is issued, the instance parameter must point to the editor structure associated with the instance which is to be resized, while the data parameter must point to a RECTANGLE structure containing the new size and origin for the editorRect.

    When an editor instance is resized, the field editor will automatically remove the visual image of the instance from the window, and will then redraw the instance using the new size and location information; this occurs only if the instance is visible.

MSG_EDIT
    Normally, an application will not issue this message; it is usually issued by the Xrlib input routines, when an input event occurs within a push button instance.

    When such an event occurs, a MSG_EDIT message will be issued to the editor, with the first parameter, instance, indicating which push button instance to process, and the third parameter, data, pointing to an XEvent structure.

    The push button editor only handles an event if event maps to an XrSELECT event, as described by XrMapButton(3X) and XrInit(3X); all others are ignored. When a select event occurs within a push button instance, the first thing done is to determine if one of the individual push buttons was selected.

    If one of the push buttons was selected, then that button will be drawn as active (filled), and the editor will then wait for the user to release the select button. When the user releases the select button, the push button will again be drawn as inactive (not filled). Afterwards, an input event will be added to the front of the application's input queue, informing it that one of the push buttons has been selected. The returned xrEvent structure is set to the following value:

    type      = XrXRAY
    source    = the window id
    inputType = XrEDITOR
    inputCode = XrPUSHBUTTON
    value1    = XrSELECT
    value2    = index of button which was selected.
    valuePtr  = pointer to instance's editor structure

    If a select occurs within a push button instance, but not within the boundary of a button, then the editor will do nothing but push an input event onto the front of the application's input queue. The event will notify the application that the editor was selected, but no action took place. It will also include the cursor position at the time the select event occurred. The returned xrEvent structure is set to the following value:

    type      = XrXRAY
    source    = the window id
    inputType = XrEDITOR
    inputCode = XrPUSHBUTTON
    value1    = NULL
    valuePt   = cursor position
    valuePtr  = pointer to instance's editor structure

RETURN VALUE
Upon successful completion of any of the messages, a non-NULL value will be returned. In the case of MSG_NEW, this non-NULL value will be the pointer to the newly created editor instance structure.

If a message request fails, then a NULL value is returned.

ERROR CONDITIONS
Messages to the push button editor will fail, set the xrErrno global and return a NULL value, under the following conditions:

MSG_NEW
    data is set to NULL [XrINVALIDPTR].

    editorWindowId is an invalid Id [XrINVALIDID].

    numCols > numFields [XrINVALIDPARM].

    The width specified in borderWidth is zero [XrINVALIDPARM].

    An invalid editor rectangle is specified [XrINVALIDRECT].

    A call to 'X' failed { XMakePixmap() } [XrXCALLFAILED].

    Memory cannot be allocated [XrOUTOFMEM].

MSG_REDRAW
    A redraw mode other than XrREDRAW_ALL is specified [XrINVALIDOPTION].

MSG_SIZE
    data is set to NULL [XrINVALIDPTR].

    numCols > numFields [XrINVALIDPARM].

    The width specified in borderWidth is zero [XrINVALIDPARM].

MSG_RESIZE
    An invalid editor rectangle is specified [XrINVALIDRECT].

MSG_GETSTATE, MSG_MOVE, MSG_RESIZE, MSG_GETITEMRECTS,

MSG_GETITEMSTATES, MSG_SETITEMSTATES and MSG_GETITEMCOUNT
    data is set to NULL [XrINVALIDPTR].

All messages, except MSG_NEW and MSG_SIZE
    The instance parameter is set to NULL [XrINVALIDID].

SEE ALSO
XrInput(3X), XrInit(3X)