### _________________________________________________________Xaw Plus

### The Text Source Object

Application Header file Class Header file Class Class Name Superclass | <X11/XawPlus/TextSrc.h> <X11/XawPlus/TextSrcP.h> textSrcObjectClass TextSource Object

The TextSrc object is the root object for all text sources. Any new text source objects should be subclasses of the TextSrc Object. The TextSrc Class contains all methods the Text widget expects a text source to export.
Since all text sources will have some resources in common the TextSrc defines a few new resources.

### Differences between Xaw and XawPlus

None.

### Resources

When creating a TextSrc object instance, the following resources are retrieved from the argument list of XtSetValues() or XtVaSetValues() or from the resource database:

Name | Class | Type | Default Value
OBJECT: |  |  |
destroyCallback | Callback | Pointer | NULL
TEXTSRC OBJECT: |  |  |
editType | EditType | XawTextEditType | XawtextRead

### Subclassing the TextSrc

The only purpose of the TextSrc Object is to be subclassed. It contains the minimum set of class methods that all text sources must have. All class methods of the TextSrc must be defined, as the Text widget uses them all. While all may be inherited, the direct descendant of TextSrc must specify some of them as TextSrc does not contain enough information to be a valid text source by itself. Do not try to use the TextSrc as a valid source for the Text widget; it is not intended to be used as a source by itself and bad things will probably happen.

Function | Public Interface | must specify
Read Replace Scan Search SetSelection ConvertSelection | XawTextSourceRead XawTextSourceReplace XawTextSourceScan XawTextSourceSearch XawTextSourceSetSelection XawTextSourceConvertSelection | yes no yes no no no

### Reading Text

To read the text in a text source use the Read() function:

> XawTextPosition Read(w, pos, text_return, length)
> Widget w;
> XawTextPosition pos;
> XawTextBlock *text_return;
> int length;

> w | Specifies the TextSrc object.
> pos | Specifies the position of the first character to be read from the text buffer.
> text | Returns the text read from the source.
> length | Specifies the maximum number of characters the TextSrc should return to the application in text_return.

This function returns the actual number of characters read from the text buffer. The function is not required to return length characters if that many characters are in the file, it may break at any point that is convenient to the internal structure of the source. It may take several calls to Read() before the desired portion of the text buffer is fully retrieved.

### Replacing Text

To replace or edit the text in a text buffer use the Replace() function:

> XawTextPosition Replace(w, start, end, text)
> Widget w;
> XawTextPosition start, end;
> XawTextBlock *text;

> w | Specifies the TextSrc object.
> start | Specifies the position of the first character to be removed from the text buffer. This is also the location to begin inserting the new text.
> end | Specifies the position immediately after the last character to be removed from the text buffer.
> text | Specifies the text to be added to the text source.

This function can return any of the following values:

XawEditDone | The text replacement was successful.
XawPositionError | The edit mode is XawtextAppend and start is not the last character of the source.
XawEditError | Either the Source was read-only or the range to be deleted is larger than the length of the Source.

The Replace arguments start and end represent the text source character positions for the existing text that is to be replaced by the text in the text block. The characters from start up to but not including end are deleted, and the buffer specified by the text block is inserted in their place. If start and end are equal, no text is deleted and the new text is inserted after start.

### Scanning the TextSrc

To search the text source for one of the predefined boundary types use the Scan() function:

> XawTextPosition Scan(w, position, type, dir, count, include)
> Widget w;
> XawTextPosition position;
> XawTextScanType type;
> XawTextScanDirection dir;
> int count;
> Boolean include;

> w | Specifies the TextSrc object.
> position | Specifies the position to begin scanning the source.
> type | Specifies the type of boundary to scan for, may be one of: XawstPosition, XawstWhiteSpace, XawstEOL, XawstParagraph, XawstAll. The exact meaning of these boundaries is left up to the individual text source.
> dir | Specifies the direction to scan, may be either XawsdLeft to search backward, or XawsdRight to search forward.
> count | Specifies the number of boundaries to scan for.
> include | Specifies whether the boundary itself should be included in the scan.

The Scan() function returns the position in the text source of the desired boundary. It is expected to return a valid address for all calls made to it, thus if a particular request is made that would take the text widget beyond the end of the source it must return the position of that end.

### Searching through a TextSrc

To search for a particular string use the Search() function.

> XawTextPosition Search(w, position, dir, text)
> Widget w;
> XawTextPosition position;
> XawTextScanDirection dir;
> XawTextBlock *text;

> w | Specifies the TextSrc object.
> position | Specifies the position to begin the search.
> dir | Specifies the direction to search, may be either XawsdLeft to search backward, or XawsdRight to search forward.
> text | Specifies a text block containing the text to search for.

This function will search through the text buffer attempting to find a match for the string in the text block. If a match is found in the direction specified, then the character location of the first character in the string is returned. If no text was found then XawTextSearchError is returned.

### Text Selections

While many selection types are handled by the Text widget, text sources may have selection types unknown to the Text widget. When a selection conversion is requested by the X server the Text widget will first call the ConvertSelection function, to attempt the selection conversion.

> Boolean ConvertSelections(w, selection, target, type, value_return, length_return, format_return)
> Widget w;
> Atom *selection, *target, *type;
> caddr_t *value_return;
> unsigned long *length_return;
> int *format_return;

> w | Specifies the TextSrc object.
> selection | Specifies the type of selection that was requested (e.g. PRIMARY).
> target | Specifies the type of the selection that has been requested, which indicates the desired information about the selection (e.g. Filename, Text, Window).
> type | Specifies a pointer to the atom into which the property type of the converted value of the selection is to be stored. For instance, either file name or text might have property type XA_STRING.
> value_return | Returns a pointer into which a pointer to the converted value of the selection is to be stored. The selection owner is responsible for allocating this storage. The memory is considered owned by the toolkit, and is freed by XtFree when the Intrinsics selection mechanism is done with it.
> length_return | Returns a pointer into which the number of elements in value is to be stored. The size of each element is determined by format.
> format_return | Returns a pointer into which the size in bits of the data elements of the selection value is to be stored.

If this function returns True then the Text widget will assume that the source has taken care of converting the selection, Otherwise the Text widget will attempt to convert the selection itself.

If the source needs to know when the text selection is modified it should define a SetSelection() procedure:

> void SetSelection(w, start, end, selection)
> Widget w;
> XawTextPosition start, end;
> Atom selection;

> w | Specifies the TextSrc object.
> start | Specifies the character position of the beginning of the new text selection.
> end | Specifies the character position of the end of the new text selection.
> selection | Specifies the type of selection that was requested (e.g. PRIMARY).

### Xaw Plus_________________________________________________________