5.6. Ascii Source Object and Multi Source Object

Application Header file<X11/Xaw/AsciiSrc.h> or <X11/Xaw/MultiSrc.h>
Class Header file<X11/Xaw/AsciiSrcP.h> or <X11/Xaw/MultiSrcP.h>
ClassasciiSrcObjectClass or multiSrcObjectClass
Class NameAsciiSrc or MultiSrc
SuperclassTextSource

The AsciiSrc or MultiSrc object is used by a text widget to read the text from a file or string in memory. Depending on its international resource, an AsciiText widget will create one or the other of these when the AsciiText itself is created. Both types are nearly identical; the following discussion applies to both, with MultiSrc differences noted only as they occur.

The AsciiSrc understands all Latin characters plus Tab and Carriage Return. The MuXtiSrc understands any set of character sets that the underlying X implementation's internationalization handles.

The AsciiSrc can be either of two types: XawAsciiFile or XawAsciiString.

AsciiSrc objects of type XawAsciiFile read the text from a file and store it into an internal buffer. This buffer may then be modified, provided the text widget is in the correct edit mode, just as if it were a source of type XawAsciiString. Unlike R3 and earlier versions of the AsciiSrc, it is now possible to specify an editable disk source. The file is not updated, however, until a call to XawAsciiSave is made. When the source is in this mode the useStringInPlace resource is ignored.

AsciiSrc objects of type XawAsciiString have the text buffer implemented as a string. MultiSrc objects of type XawAsciiString have the text buffer implemented as a wide character string. The string owner is responsible for allocating and managing storage for the string.

In the default case for AsciiSrc objects of type XawAsciiString, the resource useStringlnPlace is false, and the widget owns the string. The initial value of the string resource, and any update made by the application programmer to the string resource with XtSetValues, is copied into memory private to the widget, and managed internally by the widget. The application writer does not need to worry about running out of buffer space (subject to the total memory available to the application). The performance does not decay linearly as the buffer grows large, as is necessarily the case when the text buffer is used in place. The application writer must use XtGetValues to determine the contents of the text buffer, which will return a copy of the widget's text buffer as it existed at the time of the XtGetValues call. This copy is not affected by subsequent updates to the text buffer, i.e., it is not updated as the user types input into the text buffer. This copy is freed upon the next call to XtGetValues to retrieve the string resource; however, to conserve memory, there is a convenience routine, XawAsciiSrcFreeString, allowing the application programmer to direct the widget to free the copy.

When the resource useStringInPlace is true and the AsciiSrc object is of type XawAsciiString, the application is the string owner. The widget will take the value of the string resource as its own text buffer, and the length resource indicates the buffer size. In this case the buffer contents change as the user types at the widget; it is not necessary to call XtGetValues on the string resource to determine the contents of the buffer -- it will simply return the address of the application's implementation of the text buffer.

5.6.1. Resources

When creating an AsciiSrc object instance, the following resources are retrieved from the argument list or from the resource database:

NameClassType NotesDefault Value
callbackCallbackXtCallbaekList NULL
dalaCompressionDataCompression BooleanTrue
destoyCallbackCallback CallbackNULL
editTypeEditTypeEditMode XawtextRead
lengthLengthInt AIength of string
pieceSizePieceSizeInt BUFSIZ
stringStringString NULL
typeTypeAsciiType XawAsciiStnng
useStringInPlaceUseStringInPlace BooleanFalse

callbackThe callbacks registered on this resource will be called every time the text buffer changes, after the text has been updated.
destroyCallbackAll functions on this list are called when this widget is destroyed.
dataCompressionThe AsciiSrc uses an algorithm that may cause the text buffer to grow to about twice the size of the actual text over time, as the text is edited. On systems where CPU cycles are cheaper than memory, it is helpful to spend some extra time to compress this buffer back to its minimum size. If this resource is True, the AsciiSrc will compress its data to the minimum size required every time the text string is saved, or the value of the string is queried.
editTypeThis is the type of editing that will be allowed in this text widget. Legal values are XawtextRead, XawtextEdit, and XawtextAppend. A converter is registered for this resource that will convert the following strings: read, edit, and append.
lengthIf the uscStringlnPlace resource is False this attribute has no effect. If that resource is True, however, then the length resource specifies the length of the buffer passed to the text widget in the string resource.
pieceSizeThis is the size of the internal chunks into which the text buffer is broken down for memory management. The larger this value the less segmented your memory will be, but the slower your editing will be. The text widgets will always allocate a chunk of memory this size to stuff the string into, so when using small strings, having this buffer large can waste memory. This resource has no effect if useStringlnPlace is True.
stringIf type is XawAsciiString then this string contains the buffer to be displayed in the widget. If type is XawAsciiFile then the string contains the name of the file to be displayed. This string is normally copied by the text widget into internal memory, but may be used in place by setting the useStringlnPlace resource. As of XllR4 this is a settable resource. When the string resource is queried, using XtGetValues, and useStringlnPlace is false, the value returned is valid until the next time the string resource is queried, or until the application writer calls XawAsci iSrcFreeString. If useStringlnPlace is true, a pointer to the actual string is returned. See also section 5.6.
typehis resource may be either XawAsciiString or XawAsciiFile. The value of this resource determines whether the string resource contains the name of a file to be opened or a buffer to be displayed by the text widget. A converter has been registered for this resource and accepts the values string and file.
useStringlnPlaceStting this resource to True will disable the memory management provided by the Text widget, updating the string resource in place. Using the string in place can be much more efficient for text widgets that display static data, or where the programmer wishes to impose strict constraints on the contents of the string. When using the string in place be sure that: the length of the string is specified by setting the length resource, the type of the Text widget is XawAsciiString, and that the string exists for the lifetime of the text widget, or until it has been reset. Note: Since the MultiSrc and AsciiSrc have different data formats, use of this resource forces application code to be cognisant as to which of the two is being used. Application programming is simplified when use of this resource is avoided.

5.6.2. Convenience Routines

The AsciiSrc has a few convenience routines that allow the application programmer quicker or easier access to some of the commonly used functionality of the AsciiSrc.

5.6.2.1. Conserving Memory
When the AsciiSrc widget is not in useStringlnPlace mode space must be allocated whenever the file is saved, or the string is requested with a call to XtGetValues. This memory is allocated on the fly, and remains valid until the next time a string needs to be allocated. You may save memory by freeing this string as soon as you are done with it by calling XawAsciiSrcFreeString.
void XawAsciiSourceFreeString(w)
Widget w;

wSpecifies the AsciiSrc object.

This function will free the memory that contains the string pointer returned by XtGetValues. This will normally happen automatically when the next call to XtGetValues occurs, or when the widget is destroyed.

5.6.2.2. Saving Files
To save the changes made in the current text source into a file use XawAsciiSave.
Boolean XawAsciiSave(w) Widget w;

wSpecifies the AsciiSrc object.

XawAsciiSave returns True if the save was successful. It will update the file named in the string resource. If the buffer has not been changed, no action will be taken. This function only works on an AsciiSrc of type XawAsciiFile.

To save the contents of the current text buffer into a named file use XawAsciiSaveAsFile.

Boolean XawAsciiSaveAsFile(w, name)
Widget w;
String name;

wSpecifies the AsciiSrc object.
nameThe name of the file to save the current buffer into.

This function returns True if the save was successful. XawAsciiSaveAsFile will work with a buffer of either type XawAsciiString or type XawAsciiFile.

5.6.2.3. Seeing if the Source has Changed
To find out if the text buffer in an AsciiSrc object has changed since the last time it was saved with XawAsciiSave or queried use XawAsciiSourceChanged. Boolean XawAsciiSourceChanged(w) Widget w;
wSpecifies the AsciiSrc object.

This function will return True if the source has changed since the last time it was saved or queried. The internal change flag is reset whenever the string is queried via XtGetValues or the buffer is saved via XawAsciiSave.

Home


5.7. Ascii Sink Object and Multi Sink Object

Application Header file<X11/Xaw/AsciiSink.h>
Class Header file<X11/Xaw/AsciiSinkP.h>
ClassasciiSinkObjectClass
Class NameAsciiSink
SuperclassTextSink

The AsciiSink or MultiSink object is used by a text widget to render the text. Depending on its international resource, a AsciiText widget will create one or the other of these when the AsciiText itself is created. Both types are nearly identical; the following discussion applies to both, with MultiSink differences noted only as they occur. The AsciiSink will display all printing characters in an 8 bit font, along with handling Tab and Carriage Return. The name has been left as "AsciiSink" for compatibility. The MultiSink will display all printing characters in a font set, along with handling Tab and Carriage Return. The source object also reports the text window metrics to the text widgets.

5.7.1. Resources

When creating an AsciiSink object instance, the following resources are retrieved from the argument list or from the resource database:

NameClassType NotesDefault Value
backgroundBackground PixelXtDefaullBackground
destroyCallbackCallback XlCallbackListNULL
displayNonprintingOutput BooleanTrue
echoOutputBoolean True
fontFontXFontStruct* XtDefaultFont
fontSetFontSetXFonlSet XtDefaultFontSet
foregroundForeground PixclXtDefaultForeRround

backgroundA pixel value which indexes the widget's colormap to derive the back ground color of the widget's window. This resource is retrieved by the AsciiSink instead of being copied from the Text widget.
destroyCallbackAll functions on this list are called when this widget is destroyed.
displayNonprintingIf this resource is True, the Text widget will display all non-printable characters as the string ^@. If False, the Text widget will just leave a blank space where a non-printable character exists in the text buffer.
echoWhether or not to echo characters to the screen. The buffer can still be edited, but nothing is displayed. This mode can be useful for entering passwords and other sensitive information.
fontThe text font to use when displaying the string. (This resource is present in the AsciiSink, but not the MultiSink.)
fontSetThe text font set to use when displaying the string. (This resource is present in the MultiSink, but not the AsciiSink.)

Home


5.8. Customizing the Text Widget

The remainder of this chapter will describe customizing the Text widget. The Text widget may be customized by subclassing, or by creating new sources and sinks. Subclassing is described in detail in Chapter 7; this section will describe only those things that are specific to the Text widget. Attributes of the Text widget base class and creating new sources and sinks will be discussed.

The Text widget is made up of a number of different pieces, with the Text widget as the base widget class. It and the AsciiText widget are the only true "widgets" in the Text widget family. The other pieces (sources and sinks) are X Toolkit objects and have no window associated with them. No source or sink is useful unless assigned to a Text widget.

Each of the following pieces of the Text widget has a specific purpose, and will be, or has been, discussed in detail in this chapter:

TextThis is the glue that binds everything else together. This widget reads the text data from the source, and displays the information in the sink. All translations and actions are handled in the Text widget itself.
TextSinkThis object is responsible for displaying and clearing the drawing area. It also reports the configuration of the window that contains the drawing area The TextSink does not have its own window; instead it does its drawing on the Text widget's window.
TextSrcThis object is responsible for reading, editing and searching through the text buffer.
AsciiSinkThis object is a subclass of the TextSink and knows how to display ASCII text. Support has been added to display any 8-bit character set, given the font.
MultiSinkThis object is a subclass of the TextSink and knows how to display font sets.
AsciiSrcThis object is a subclass of the TextSrc and knows how to read strings and files.
MultiSrcThis object is a subclass of the TextSrc and knows how to read strings and multibyte files, converting them to wide characters based on locale.
AsciiTextThis widget is a subclass of the Text widget. When created, the AsciiText automatically creates and attaches either an AsciiSrc and AsciiSink, or a MultiSrc and MultiSink, to itself. The AsciiText provides the simplest interface to the Athena Text widgets.

Home


5.9. Text Widget

Application Header file<X11/Xaw/Text.h>
Class Header file<X1l/lXaw/TextP.h>
ClasstextWidgetClass
Class NameText
SuperclassSimple

The Text widget is the glue that binds all the other pieces together, it maintains the internal state of the displayed text, and acts as a mediator between the source and sink.

This section lists the resources that are actually part of the Text widget, and explains the functionality provided by each.

5.9.1. Resources

When creating an Text widget instance, the following resources are retrieved from the argument list or from the resource database:

NameClassType NotesDcfault Value
acceleratorsAccelerators AcceleratorTableNULL
ancestorSensitiveAncestorSensitive BooleanDTrue
autoFillAutoFillBoolean False
backgroundBackground PixelXtDefaultBackground
backgroundPixmapPixmap PixmapXtUnspecifiedPixmap
borderColorBorderColor PixelXtDcraultForeground
borderPixmapPixmapPixmap XtUnspecifiedPixmap
borderWidthBorderWidth Dimension1
bottomMarginMarginPosition 2
colormapColormapColormap Parent's ColorMap
cursorCursorCursor XC_xterm
cursorNameCursorString NULL
depthDepthint CParent's Depth
destroyCallbackCallback XtCallbackListNULL
displayCaretOutputBoolean True
displayPosilionTextPosition XawTextPosition0
heightHightDimension AFont height + margins
insensitiveBorderInsensitive PixmapGreyPixmap
insertPositionTextPosition int0
leftMarginMarginPosition 2
mappedWhenManagedMappedWhenManaged BooleanTrue
pointerColorForeground PixelXtDefaultForeground
pointerColorBackgroundBackground PixelXtDefaultBackground
resizeResizeXawTextResizeMode XawtextResizcNever
rightMarginMarginPosition 4
screenScreenPointer RParent's Screen
scrollHorizontalScroll ScrollModeXawtextScollNever
scrollVerticalScroll XawTextScrollModeXawtextScrollNever
selectTypesSelectTypes XawTextSelectType*See above
sensitiveSensitiveBoolean True
textSinkTextSinkWidget NULL
textSourceTextSource WidgetNULL
topMarginMarginPosition 2
translationsTranslations TranslationTableSee above
unrealizeCallbackCallback XtCallbackListNULL
widthWidthDimension 100
wrapWrapWrapMode XawtextWrapNever
xPositionPosition 0
yPositionPosition 0

acceleratorsA list of event to action bindings to be executed by this widget, even though the event occurred in another widget. (See the X Toolkit Intrinsics-C Language Interface for details).
ancestorSensitiveThe sensitivity state of the ancestors of this widget. A widget is incense tie if either it or any of its ancestors is insensitive. This resource should not be changed with XtSetValues, although it may be queried.
autoFillIf this resource is True the text widget will automatically break a line when the user attempts to type into the right margin. The attribute has no effect on files or text inserted into the text widget. It only checks to see if the action should be taken when a user enters a new character via the insert-character action.
backgroundA pixel value which indexes the widget's colormap to derive the back ground color of the widget's window.
backgroundPixmapThe background pixmap of this widget's window. If this resource is set to anything other than XtUnspecifiedPixmap, the pixmap specified will be used instead of the background color.
borderColorA pixel value which indexes the widget's colormap to derive the border color of the widget's window.
borderPixmapThe border pixmap of this widget's window. If this resource is set to anything other than XtUnspecifiedPixmap, the pixmap specified will be used instead of the border color.
borderWidthThe width of this widget's window border.
bottomMargin
leftMargin
rightMargin
topMarginThe amount of space, in pixels, between the edge of the window and the corresponding edge of the text within the window. If there is a scrollbar active on this edge, then this is the space between the text and the scrollbar.
colormapThe colormap that this widget will use.
cursorThe image that will be displayed as the pointer cursor whenever it is in this widget. The use of this resource is deprecated in favor of cursorName.
cursorNameThe name of the symbol to use to represent the pointer cursor. This resource will override the cursor resource if both are specified. (See 2.5.1)
depth The depth of this widget's window.
destroyCallbackAll functions on this list are called when this widget is destroyed.
displayCaretWhether or not to display the text insert point.
displayPositionThe position in the text buffer of the character that is currently displayed in the upper left hand corner of the text display.
height
widthThe height and width of this widget in pixels.
insensitiveBorderThis pixmap will be tiled into the widget's border if the widget becomes insensitive.
insertPositionThis is the location of the insert point. It is expressed in characters from the beginning of the file. The cursor will always be forced to be on the screen. This resource may therefore be used to scroll the text display to a certain character position.
mappedWhenManagedIf this resource is True, then the widget's window will automatically be mapped by the Toolkit when it is realized and managed.
pointerColorA pixel value which indexes the widget's colormap to derive the foreground color of the pointer symbol specified by the cursorName resource.
pointerColorBackgroundA pixel value which indexes the widget's colormap to derive the background color of the pointer symbol specified by the cursorName resource.
resizeControls whether or not the Text widget attempts to resize itself when it is no longer able to display the full text buffer in the associated window. Any attempt by the Text widget to resize itself is always subject to the constraints imposed by its parent. The values XawtextResizeNever, XawtextResizeWidth, XawtextResizeHeight, and XawtextResizeBoth are all acceptable for this resource. A converter is registered for this resource that will convert the following strings: never, height, width, and both.
screenThe screen on which this widget is displayed. This is not a settable resource.
ScrollHorizontal
scrollVerticalThese resources control the placement of scrollbars on the left and bottom edge of the text widget. These resources accept the values XawtextScrollAlways, XawtextScrollWhenNeeded, and XawtextScrollNever. A converter is registered for this resource that will convert the following strings: always, never, and whenNeeded. If XawtextScrollWhenNeeded is specified, the appropriate scrollbar will only appear when there is text in the buffer that is not able to fit within the bounds of the current window. The scrollbar will disappear when the text once again fits within the window.
selectTypesSpecifies the selection type array that is used when multi-click is activated (see Text Selections for Application Programmers for details). This resource is used in place, and must not be freed until the widget is destroyed. There is no type converter registered for this resource, so it may not be set from the resource manager.
sensitiveWhether or not the toolkit should pass user events to this widget. The widget will not get input events if either ancestorSensitive or sensitive is False.
textSink
textSource These are the TextSink or TextSource objects used by this widget. When using the Text widget these MUST be set by the application programmer. the AsciiText widget initializes these resources to point to an MultiSink and MultiSrc respectively. the AsciiText widget initializes these resources to point to an AsciiSink and AsciiSrc respectively.
translationsThe event bindings associated with this widget.
wrapWhen the text in any one line is wider than the window there are several possible actions. This resource allows the user to decide what will happen. The accepted values for this resource are XawtextWrapNever, XawtextWrapLine, and XawtextWrapWord. With XawtextWrap Line all text that is beyond the right edge of the window will be displayed on the next line. With XawtextWrapWord the same action occurs but the text is broken at a word boundary if possible. If no wrapping is enabled then the text will extend off the edge of the window, and a small rectangle will be painted in the right margin to alert the user that this line is too long. A converter is registered for this resource that will convert the following strings: never, word, and line.
unrealizeCallbackA list of callback functions which will be executed when the Text widget is unrealized.
x
yThe location of the upper left outside corner of this widget in its parent.

Home


5.10. TextSrc Object

Application Header file<X11/Xaw/TextSrc.h.>
Class Header file<X11/Xaw/TextSrcP.h>
ClasstextSrcObjectClass
Class NameTextSrc
SuperclassObject

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.

5.10.1. Resources

When creating an TextSrc object instance, the following resources are retrieved from the argument list or from the resource database:

NameClassType NotesDefault Value
destroyCallbackCallback XtCallbacicListNULL
editTypeEditTypeEditMode NULL

destroyCallbackAll functions on this list are called when this widget is destroyed.
editTypeThis is the type of editing that will be allowed in this text widget. Legal values are XawtextRead, XawtextEdit, and XawtextAppend. A converter is registered for this resource that will convert the following strings: read, edit, and append.

5.10.2. 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.

FunctionInherit with Publie InterFasemust specify
ReadXtinheritReadXawTextSoureeRead yes
ReplaceXtInheritReplace XawTextSoureeReplaceno
SeanXtinheritScanXawTextSourceSean yes
SearchXtInheritSearch XawTextSoureeSearchno
SetSeleetionXtinheritSetSelection XawTextSourceSetSeleetionno
ConvertseleconXtInheritConvertSelection XawTextSourceConvertSelectionno

5.10.2.1. 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;

wSpecifies the TextSrc object.
posSpecifies the position of the first character to be read from the text buffer.
textReturns the text read from the source.
lengthSpecifies 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.

5.10.2.2. 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;

wSpecifies the TextSrc object.
startSpecifies the position of the first character to be removed from the text buffer. This is also the location to begin inserting the new text.
endSpecifies the position immediately after the last character to be removed from the text buffer.
textSpecifies the text to be added to the text source.

This function can return any of the following values:

XawEditDoneThe text replacement was successful.
XawPositionErrorThe edit mode is XawtextAppend and start is not the last character of the source.
XawEditErrorEither 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.

5.10.2.3. 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;

wSpecifies the TextSrc object.
positionSpecifies the position to begin scanning the source.
typeSpecifies 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.
dirSpecifies the direction to scan, may be either XawsdLeft to search backward, or XawsdRight to search forward.
countSpecifies the number of boundaries to scan for.
includeSpecifies 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.

5.10.2.4. 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;

wSpecifies the TextSrc object.
positionSpecifies the position to begin the search.
dirSpecifies the direction to search, may be either XawsdLeft to search backward, or XawsdRight to search forward.
textSpecifies 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.

5.10.2.5. 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 ConvenSelections(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;

wSpecifies the TextSrc object.
selectionSpecifies the type of selection that was requested (e.g. PRIMARY).
targetSpecifies the type of the selection that has been requested, which indicates the desired information about the selection (e.g. Filename, Text, Window).
typeSpecifies 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_returnReturns 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_returnRetums a pointer into which the number of elements in value is to be stored. The size of each element is determined by format.
format_returnReturns 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 convening 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;

wSpecifies the TextSrc object.
startSpecifies the character position of the beginning of the new text selection.
endSpecifies the character position of the end of the new text selection.
selectionSpecifies the type of selection that was requested (e.g. PRIMARY).

Home


5.11. TextSink Object

Application Header file<X11/Xaw/TextSink.h>
Class Header file<X11/Xaw/TxtSinkP.h>
ClasstextSinkObjectClass
Class NameTextSink
SuperclassObject

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.

5.11.1. Resources

When creating an TextSink object instance, the following resources are retrieved from the argument list or from the resource database:

NameClassType NotesDefault Value
backgroundBackground PixelXtDefaultBackground
destroyCallbackCallback XtCallbackListNULL
foregroundForeground PixelXtDefaultForeground

backgroundA pixel value which indexes the widget's colormap to derive the back ground color of the widget's window.
destroyCallbackAll functions on this list are called when this widget is destroyed.
foregroundA pixel value which indexes the Text widget's colormap to derive the foreground color used by the text sink.

5.11.2. 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.

FunctionInherit with Public Interfacemust specify
DisplayTextXtInheritDisplayText XawTextSinkDisplayTextyes
InsertCursorXtInheritInsertCursor XawTextSinkInsertCursoryes
ClearToBackgroundXtInheritClearToBackground XawTextsinkClearToBackgroundno
FindPositionXtInheritFindPosition XawTexlSinkFindPositionyes
FindDistanseXtInheritFindDistance XawTexlSinkFindDislanscyes
ResolveXtInheritResolve XawTextSinkResolveyes
MaxLinesXtInheritMaxLines XawTextSinkMaxHightno
MaxHeightXtInheritMaxHeight XawTextSinkMaxHeightno
SetTabsXtInheritSetTabs XawTextSinkSetTabsno
GelCursorBoundsXtInheritGetCursorBounds XawTextSinkGetCursorBoundsyes

5.11.2.1. 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;

wSpecifies the TextSink object.
xSpecifies the x location to start drawing the text.
ySpecifies the y location to start drawing text.
pos1Specifies the location within the text source of the first character to be printed.
pos2Specifies the location within the text source of the last character to be printed.
highlightSpecifies 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.

5.11.2.2. 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;
XawTextlnsertState state;

wSpecifies the TextSink object.
xSpecifies the x location of the cursor in Pixels.
ySpecifies the y location of the cursor in Pixels.
stateSpecifies 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.

5.11.2.3. 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;

wSpecifies the TextSink object.
xSpecifies the x location, in pixels, of the Region to clear.
ySpecifies the y location, in pixels, of the Region to clear.
widthSpecifies the width, in pixels, of the Region to clear.
heightSpecifies the height, in pixels, of the Region to clear.

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

5.11.2.4. 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_returnI, *height_return;

wSpecifies the TextSink object.
fromPosSpecifies a reference position, usually the first character in this line. This character is always to the left of the desired character location.
fromXSpecifies 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.
widthSpecifies the distance, in pixels, from the reference position to the desired character position.
stopAtWordBreakSpecifies whether or not the position that is returned should be forced to be on a word boundary.
pos_returnReturns 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_returnReturns the actual distance between fromPos and pos_return.
height_returnReturns 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;
intfromX, width;
XawTextPosition *pos_return;

wSpecifies the TextSink object.
fromPosSpecifies 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.
widthSpecifies the distance, in pixels, from the reference position to the desired character position.
pos_returnReturns 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.

5.11.2.5. 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;
XawTextPositionfromPos, toPos;
int fromX;
XawTextPosition *pos_return;
int *width_return, *height_return;

wSpecifies the TextSink object.
fromPosSpecifies the text buffer position, in characters, of the first position.
fromXSpecifies 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.
toPosSpecifies the text buffer position, in characters, of the second position.
resWidthReturn the actual distance between fromPos and pos return.
resPosReturns 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_returnReturns the maximum height of the text betweenfromPos 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.

5.11.2.6. 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 Max Line s(w, height)
Widget w;
Dimension height;
wSpecifies the TextSink object.
heightSpecifies 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;
wSpecifies the TextSink object.
hightSpecifies the height of the current drawing area.

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

5.11.2.7. 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;

wSpecifies the TextSink object.
tab_countSpecifies the number of tabs passed in tabs.
tabsSpecifies 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.

5.11.2.8. 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;
wSpecifies the TextSinkObject.
rect_returnReturns the location and size of the insert point.
Rect will be filled with the current size and location of the insert point.

Home

Contents Part 1/Chapter 5 Next Chapter