DtEditorReplace(library call)

NAME
DtEditorReplace — replace a portion of the contents of a DtEditor widget

SYNOPSIS

#include <Dt/Editor.h>
DtEditorErrorCode DtEditorReplace(
Widget widget,
XmTextPosition startPos,
XmTextPosition endPos,
DtEditorContentRec *data);

DESCRIPTION

The DtEditorReplace function replaces part of the contents of a DtEditor widget with a string, a wide character string or sized buffer. The data is transferred to the DtEditor widget using a DtEditorContentRec, which indicates the type of data being transferred along with the actual data. All data following the start position and up to, but not including, the end position is replaced. If the start position and the end position are equal, the data is inserted after the end position. The character positions begin at zero and are numbered sequentially from the beginning of the text. After the replacement, the insertion cursor is positioned after the last character inserted.

The widget argument specifies the DtEditor widget ID.

The startPos argument specifies the starting character position of the portion to replace. The replacement begins at this character.

The endPos argument specifies the ending character position of the portion to replace. The replacement ends before this character.

The data argument is a pointer to the data structure containing the data to insert.

For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3).

For a complete definition of DtEditorContentRec, see Dt/Editor.h - DtEditor(5).

RETURN VALUE

Upon successful completion, the DtEditorReplace function returns one of the following values:

DtEDITOR_NO_ERRORS
    The data was replaced sucessfully.

DtEDITOR_NULLS_REMOVED
    NULL characters were found and removed from the data.

Otherwise, if the DtEditorReplace function cannot replace the data in the DtEditor widget, it returns one of the following values:

DtEDITOR_INVALID_TYPE
    The Type field is not recognized.

DtEDITOR_INVALID_RANGE
    The startPos argument is greater than the endPos argument.

DtEDITOR_ILLEGAL_SIZE
    The size of the buffer passed in is negative.

DtEDITOR_NULL_ITEM
    The data buffer is NULL.

DtEDITOR_INSUFFICIENT_MEMORY
    Not enough system memory is available to replace the data.

EXAMPLES

The following code segment modifies the contents of a DtEditor widget to ``The quick fox.''

Widget                  editor;
DtEditorContentRec      cr;
DtEditorErrorCode       status;
XmTextPosition          start = (XmTextPosition) 4,
                        end = (XmTextPosition) 9;
char                    *sampleString1="The brown fox",
                        *sampleString2="quick";
cr.type = DtEDITOR_TEXT;
cr.value.string = sampleString1;
status = DtEditorSetContents(editor, &cr);
if (status != DtEDITOR_NO_ERRORS && status != DtEDITOR_NULLS_REMOVED) {
        printf("Unable to set contents of the widget\n");
} else {
        cr.type = DtEDITOR_TEXT;
        cr.data.string = sampleString2;
        status = DtEditorReplace(editor, start, end, &cr);
        if (status != DtEDITOR_NO_ERRORS)
          printf("Unable to replace part of the widget contents\n");
}

APPLICATION USAGE

If the data is in a disk file, rather than in memory, the application should use DtEditorReplaceFromFile(3).

SEE ALSO

Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorAppend(3), DtEditorAppendFromFile(3), DtEditorGetContents(3), DtEditorInsert(3), DtEditorInsertFromFile(3), DtEditorReplaceFromFile(3), DtEditorSaveContentsToFile(3), DtEditorSetContents(3), DtEditorSetContentsFromFile(3).