XRSTATICTEXT(3X)

NAME
XrStaticText - an editor which displays a block of static text

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

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

DESCRIPTION

The static text editor provides an application with the means for placing uneditable blocks of text anywhere within the bounds of a window. In addition, the font to be used when displaying the text, and the type of alignment to use, can also be specified. The application must specify a rectangular region into which the text will be drawn. If the text will not fit completely within the rectangle, then only that portion which fits will be displayed.

Once a block of static text has been displayed, the only attributes which may be modified are the XrVISIBLE and XrSENSITIVE state flags. The actual textual data cannot be modified.

Four forms of text alignment will be provided by the editor:

- None
- Centered
- Left
- Right

Alignment will be done in relation to the rectangle passed in at the time the text request is made. The rules governing alignment are:

Centered
The text will be displayed such that the center of each line of text is positioned at the center of the specified rectangle. Before the text is displayed, all leading and trailing spaces in the line will be stripped.

Left
Each line of text will be displayed such that the first character of the line is positioned at the left most edge of the specified rectangle. Before the text is displayed, all leading and trailing spaces in the line will be stripped.

Right
Each line of text will be displayed such that the last character in each line ends at the right most edge of the specified rectangle. Before the text is displayed, all leading and trailing spaces in the line will be stripped.

None
Each line of text will be displayed such that the first character of the line is positioned at the left most edge of the specified rectangle. Leading and trailing spaces in a line of text are not stripped.

When the editor displays a block of static text, the initial pen position will be in the upper left hand corner of the editorRect. The bounds used when displaying the text are the right hand edge of the rectangle, and the bottom edge.

Each time the pen position goes beyond the right edge of the editorRect, or each time one of the following characters is encountered in the string, a new line will be started:

Newline         (octal 012)
Vertical tab    (octal 013)
Form feed       (octal 014)
Carriage return (octal 015)

If, at some point, the pen's y position goes below the bottom edge of the editorRect, then no more lines of text will be displayed.

EDITOR MESSAGES

MSG_NEW
    This message will be the means by which an application program can create a block of static text within 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;
              INT8       * string;
              INT32        alignment;
          } xrStaticTextInfo;

    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 block of static text is to be formated and displayed. If the text will not fit completely within this rectangle, then the text will be clipped, until it does fit. However, if a rectangle with a width of 0 is specified, then the editor will refuse to handle the request, and it 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. The foreground color is used to display the text. 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. The background color is used to paint the area upon which the text is displayed. If this is set to -1, the default background color (see XrInit(3X) ) will be used.

    editorFont
    This points to the structure which contains all of the information necessary to describe the font to be used when displaying the block of static text. If this pointer is NULL, then the default system base font will be used.

    string
    This should be a pointer to the NULL terminated block of text. If the pointer is NULL, or if the string has a length of 0, then the create request will fail; a string must be specified! A block of text can be composed of just about any characters; however, the editor will expect words to be separated by spaces, in order for it to properly parse the block. Unpredictable results will occur if words are not separated by spaces. Forced newline characters (Carriage return, Newline, Vertical tab and Form feed) can be included in the block of text; these will force the pen to the next line, even though the right edge of the editorRect was not reached.

    alignment
    This value will specify to the editor what form of text alignment should be used when displaying each line of text. The following values will be accepted:

    - XrNO_ALIGNMENT
    - XrCENTER_ALIGNED
    - XrLEFT_ALIGNED
    - XrRIGHT_ALIGNED

    Any value other than one of those outlined above, will cause the create request to fail. Each line of static text will use this alignment.

    The editor will then draw the block of static text 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, which was returned by MSG_NEW; this parameter specifies which instance is to be destroyed.

    When a static text instance is destroyed, it will be internally disconnected from the window to which it was attached, it will no longer handler 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 block of static text . 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.

MSG_SETSTATE
    This message allows an application program to modify the setting of the XrSENSITIVE and XrVISIBLE flags, for a given block of static text. 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.

MSG_REDRAW
    This editor provides an application with the means for requesting that a block of static text be redrawn. The text string data, font information, and the alignment which were specified when the instance was created, 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.

    The static text editor supports the following redraw mode:

    - XrREDRAW_ALL

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

MSG_SIZE
    This message allows an application to obtain the height of the rectangle needed to contain a given block of static text. The width of the rectangle MUST have been specified by the application program, via the width field within editorRect, BEFORE it issued this message. If the rectangle is specified with a width of 0, or the length of the string is 0, or the string pointer is NULL, then the request will fail.

    The static text 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;
              INT8       * string;
              INT32        alignment;
          } xrStaticTextInfo;

    The fields which must be filled out by the application program BEFORE issuing this call, are the string, alignment, and editorFont fields. In addition, the width of the rectangle into which the block of static text is to be fit, must also be filled out. This involves setting the following field of the editorRect:

    editorRect.width

    The editor will set the origin (top and left) of the rectangle to (0,0).

    If editorFont has been set to NULL, then the default system base font will be used when calculating the rectangle size; if a particular font is requested, then it will be used.

    The rectangle calculated will be the smallest 0 based rectangle of the specified width, into which the specified block of static text will fit, using the specified font and text alignment mode. Only the height of the rectangle needs to be calculated, since the width was supplied by the application, and the origin (top and left) of the rectangle is forced to (0,0).

    Since the width of the rectangle is fixed by the calling application, it is possible for a single word to be too long to fit on a line. If this occurs, then the editor will return with an error; the editor will not break up a word.

    An application can then take this rectangle, and offset it, so that the origin of the block of text can be set.

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 toolbox input routines, when an input event occurs within a static text instance.

    When such an event occurs, a MSG_EDIT message will be issued to the editor, with the instance parameter indicating which block of static text to process, and the data parameter pointing to an XEvent structure.

    The static text editor only handles an event if it maps to an XrSELECT event, as described by XrMapButton(3X) and XrInit(3X); all others are ignored.

    When a select event occurs within a block of static text, the editor will do nothing but add an input event to the front of the application's input queue, informing it that a block of static text was selected. The returned xrEvent structure is set to the following value:

       type      = XrXRAY
       source    = the window Id
       inputType = XrEDITOR
       inputCode = XrSTATICTEXT
       value1    = XrSELECT
       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 static text 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].

    editorRect is specified with a height or width of zero [XrINVALIDRECT].

    The editorRect width is too small [XrINVALIDRECT].

    string is set to NULL [XrINVALIDPTR].

    string points to an empty string [XrINVALIDPARM].

    alignment is set to an unknown value [XrINVALIDOPTION].

    Memory cannot be allocated [XrOUTOFMEM].

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

MSG_RESIZE
    data is set to NULL [XrINVALIDPTR].

    editorRect is specified with a height or width of zero [XrINVALIDRECT].

MSG_SIZE
    data is set to NULL [XrINVALIDPTR].

    The width of the rectangle has been set to zero [XrINVALIDRECT].

    The width of the rectangle is too small [XrINVALIDRECT].

    string is set to NULL [XrINVALIDPTR].

    string points to an empty string [XrINVALIDPARM].

MSG_GETSTATE and MSG_MOVE
    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)