### _________________________________________________________Xaw Plus

### 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():

> void DisplayText(w, x, y, pos1, pos2, highlight)
> Widget w;
> Position x, y;
> XawTextPosition pos1, pos2;
> Boolean highlight;

> w | Specifies the TextSink object.
> x | Specifies the x location to start drawing the text.
> y | Specifies the y location to start drawing text.
> pos1 | Specifies the location within the text source of the first character to be printed.
> pos2 | Specifies the location within the text source of the last character to be printed.
> highlight | Specifies whether or not to paint the text region highlighted.

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.

> void InsertCursor(w, x, y, state)
> Widget w;
> Position x, y;
> XawTextInsertState state;

> w | Specifies the TextSink object.
> x | Specifies the x location of the cursor in Pixels.
> y | Specifies the y location of the cursor in Pixels. |
> state | Specifies the state of the cursor, may be one of XawisOn or XawisOff.

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.

> void ClearToBackground(w, x, y, width, height)
> Widget w;
> Position x, y;
> Dimension width, height;

> w | Specifies the TextSink object.
> x | Specifies the x location, in pixels, of the Region to clear.
> y | Specifies the y location, in pixels, of the Region to clear.
> width | Specifies the width, in pixels, of the Region to clear.
> height | Specifies the height, in pixels, of the Region to clear.

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():

> void FindPosition(w, fromPos, fromX, width, stopAtWordBreak, pos_return, width_return, height_return)
> Widget w;
> XawTextPosition fromPos;
> int fromX, width;
> Boolean stopAtWordBreak;
> XawTextPosition *pos_return;
> int *width_return, *height_return;

> w | Specifies the TextSink object.
> fromPos | Specifies a reference position, usually the first character in this line. This character is always to the left of the desired character location.
> fromX | Specifies the distance that the left edge of fromPos is from the left edge of the window. This is the reference x location for the reference position.
> width | Specifies the distance, in pixels, from the reference position to the desired character position.
> stopAtWordBreak | Specifies whether or not the position that is returned should be forced to be on a word boundary.
> pos_return | Returns the character position that corresponds to the location that has been specified, or the work break immediately to the left of the position if stopAtWordBreak is True.
> width_return | Returns the actual distance between fromPos and pos_return.
> height_return | Returns the maximum height of the text between fromPos and pos_return.

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:

> void Resolve(w, fromPos, fromX, width, pos_return)
> Widget w;
> XawTextPosition fromPos;
> int fromX, width;
> XawTextPosition *pos_return;

> w | Specifies the TextSink object.
> fromPos | Specifies a reference position, usually the first character in this line. This character is always to the left of the desired character location.
> fromX | Specifies the distance that the left edge of fromPos is from the left edge of the window. This is the reference x location for the reference position.
> width | Specifies the distance, in pixels, from the reference position to the desired character position.
> pos_return | Returns the character position that corresponds to the location that has been specified, or the word break immediately to the left if stopAtWordBreak is True.

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().

> void FindDistance(w, fromPos, fromX, toPos, width_return, pos_return, height_return)
> Widget w;
> XawTextPosition fromPos, toPos;
> int fromX;
> XawTextPosition *pos_return;
> int *width_return, *height_return;

> w | Specifies the TextSink object.
> fromPos | Specifies the text buffer position, in characters, of the first position.
> fromX | Specifies the distance that the left edge of fromPos is from the left edge of the window. This is the reference x location for the reference position.
> toPos | Specifies the text buffer position, in characters, of the second position.
> resWidth | Return the actual distance between fromPos and pos_return.
> resPos | Returns the character position that corresponds to the actual character position used for toPos in the calculations. This may be different than toPos, for example if fromPos and toPos are on different lines in the file.
> height_return | Returns the maximum height of the text between fromPos and pos_return.

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.

> int MaxLines(w, height)
> Widget w;
> Dimension height;

> w | Specifies the TextSink object.
> height | Specifies the height of the current drawing area.

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.

> int MaxHeight(w, lines)
> Widget w;
> int lines;

> w | Specifies the TextSink object.
> height | Specifies the height of the current drawing area.

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.

> void SetTabs(w, tab_count, tabs)
> Widget w;
> int tab_count, *tabs;

> w | Specifies the TextSink object.
> tab_count | Specifies the number of tabs passed in tabs.
> tabs | Specifies the position, in characters, of the tab stops.

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.

> void GetCursorBounds(w, rect_return)
> Widget w;
> XRectangle *rect_return;

> w | Specifies the TextSink object.
> rect_return | Returns the location and size of the insert point.

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

### Xaw Plus_________________________________________________________