_____________________________________________________XawPlus

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 RepType 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:

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:

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:

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.

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.

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:

XawPlus_____________________________________________________