_________________________________________________________XawPlus

The TextSink Object

Application Header file
Class Header file
Class
Class Name
Superclass
<X11/XawPlus/TextSink.h>
<X11/XawPlus/TextSinkP.h>
textSinkObjectClass
TextSink
Object

The TextSink object is the root object for all text sinks. Any new text sink objects should be subclasses of the TextSink Object. The TextSink Class contains all methods that the Text widget expects a text sink to export.

Since all text sinks will have some resources in common, the TextSink defines a few new resources.

Differences between Xaw and XawPlus

The default background color changes from XtDefaultBackground to grey75.

Resources

When creating a TextSink 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
TEXTSINK:
foreground
background
Foreground
Background
Pixel
Pixel
XtDefaultForeground
grey75

Subclassing the TextSink

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

Function Public Interface must specify
DisplayText
InsertCursor
ClearToBackground
FindPosition
FindDistance
Resolve
MaxLines
MaxHeight
SetTabs
GetCursorBounds
XawTextSinkDisplayText
XawTextSinkInsertCursor
XawTextSinkClearToBackground
XawTextSinkFindPosition
XawTextSinkFindDistance
XawTextSinkResolve
XawTextSinkMaxLines
XawTextSinkMaxHeight
XawTextSinkSetTabs
XawTextSinkGetCursorBounds
yes
yes
no
yes
yes
yes
no
no
no
yes

Displaying Text

To display a section of the text buffer contained in the text source use the function DisplayText():

The Text widget will only pass one line at a time to the text sink, so this function does not need to know how to line feed the text. It is acceptable for this function to just ignore Carriage Returns. x and y denote the upper left hand corner of the first character to be displayed.

Displaying the Insert Point

The function that controls the display of the text cursor is InsertCursor. This function will be called whenever the text widget desires to change the state of, or move the insert point.

x and y denote the upper left hand corner of the insert point.

Clearing Portions of the Text window

To clear a portion of the Text window to its background color, the Text widget will call ClearToBackground(). The TextSink object already defines this function as calling XClearArea() on the region passed. This behavior will be used if you specify XtInheritClearToBackground for this method.

x and y denote the upper left hand corner of region to clear.

Finding a Text Position Given Pixel Values

To find the text character position that will be rendered at a given x location the Text widget uses the function FindPosition():

This function need make no attempt to deal with line feeds. The text widget will only call it one line at a time.

Another means of finding a text position is provided by the Resolve() function:

This function need make no attempt to deal with line feeds. The text widget will only call it one line at a time. This is a more convenient interface to the FindPosition function, and provides a subset of its functionality.

Finding the Distance Between two Text Positions

To find the distance in pixels between two text positions on the same line use the function FindDistance().

This function need make no attempt to deal with line feeds. The Text widget will only call it one line at a time.

Finding the Size of the Drawing area

To find the maximum number of lines that will fit into the current Text widget, use the function MaxLines(). The TextSink already defines this function to compute the maximum number of lines by using the height of font.

Returns the maximum number of lines that will fit in height.

To find the height required for a given number of text lines, use the function MaxHeight(). The TextSink already defines this function to compute the maximum height of the window by using the height of font.

Returns the height that will be taken up by the number of lines passed.

Setting the Tab Stops

To set the tab stops for a text sink use the SetTabs() function. The TextSink already defines this function to set the tab x location in pixels to be the number of characters times the figure width of font.

This function is responsible for the converting character positions passed to it into whatever internal positions the TextSink uses for tab placement.

Getting the Insert Point's Size and Location

To get the size and location of the insert point use the GetCursorBounds() function.

Rect will be filled with the current size and location of the insert point.

XawPlus_________________________________________________________