TextSink Object Application Header file <X11/Xaw/TextSink.h> Class Header file <X11/Xaw/TextSinkP.h> Class textSinkObjectClass Class Name TextSink Superclass 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. Resources When creating an TextSink object instance, the following resources are retrieved from the argument list or from the resource database: Name Class Type Notes Default Value background Background Pixel XtDefaultBackground destroyCallback Callback XtCallbackList NULL foreground Foreground Pixel XtDefaultForeground _ 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. Function Inherit with Public Interface must specify DisplayText XtInheritDisplayText XawTextSinkDisplayText yes InsertCursor XtInheritInsertCursor XawTextSinkInsertCursor yes ClearToBackground XtInheritClearToBackground XawTextSinkClearToBackground no FindPosition XtInheritFindPosition XawTextSinkFindPosition yes FindDistance XtInheritFindDistance XawTextSinkFindDistance yes Resolve XtInheritResolve XawTextSinkResolve yes MaxLines XtInheritMaxLines XawTextSinkMaxLines no MaxHeight XtInheritMaxHeight XawTextSinkMaxHeight no SetTabs XtInheritSetTabs XawTextSinkSetTabs no GetCursorBounds XtInheritGetCursorBounds XawTextSinkGetCursorBounds yes Displaying Text To display a section of the text buffer contained in the text source use the function DisplayText: void DisplayText Widget w Positionx, y XawTextPositionpos1, 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 Widget w Positionx, 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 Widget w Positionx, y Dimensionwidth, 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 Widget w XawTextPosition fromPos intfromX, 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 Widget w XawTextPosition fromPos intfromX, 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 Widget w XawTextPositionfromPos, 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 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 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 Widget w inttab_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 Widget w XRectangle *rect_return w Specifies the TextSinkObject. 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.