98N/Astatic char Xrcsid[] =
"$XConsortium: Text.c,v 1.136 89/12/15 12:10:56 kit Exp $";
287N/A#
endif /* lint && SABER */ 98N/A/*********************************************************** 98N/ACopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, 98N/Aand the Massachusetts Institute of Technology, Cambridge, Massachusetts. 98N/A All Rights Reserved 98N/APermission to use, copy, modify, and distribute this software and its 98N/Adocumentation for any purpose and without fee is hereby granted, 98N/Aprovided that the above copyright notice appear in all copies and that 98N/Aboth that copyright notice and this permission notice appear in 98N/Asupporting documentation, and that the names of Digital or MIT not be 98N/Aused in advertising or publicity pertaining to distribution of the 98N/Asoftware without specific, written prior permission. 98N/ADIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 98N/AALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 98N/ADIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 98N/AANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 98N/AWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 98N/AARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 98N/A******************************************************************/ 98N/A/**************************************************************** 98N/A * Full class record constant 98N/A ****************************************************************/ * This resource is obsolete. * Set the number of actions. /* Function Name: PositionHScrollBar. * Description: Positions the Horizontal scrollbar. * Arguments: ctx - the text widget. /* Function Name: PositionVScrollBar. * Description: Positions the Vertical scrollbar. * Arguments: ctx - the text widget. /* Function Name: DestroyVScrollBar * Description: Removes a vertical ScrollBar. * Arguments: ctx - the parent text widget. /* Function Name: DestroyHScrollBar * Description: Removes a horizontal ScrollBar. * Arguments: ctx - the parent text widget. ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width; ctx->text.margin.bottom = ctx->text.r_margin.bottom; /******************************* /*******************************/ "Vertical scrolling not allowed with height resize.\n",
"Vertical scrolling has been DEACTIVATED.");
"Horizontal scrolling not allowed with wrapping active.\n",
"Horizontal scrolling has been DEACTIVATED.");
"Horizontal scrolling not allowed with width resize.\n",
"Horizontal scrolling has been DEACTIVATED.");
/* Utility routines for support of Text */ * Procedure to manage insert cursor visibility for editable text. It uses * the value of ctx->insertPos and an implicit argument. In the event that * position is immediately preceded by an eol graphic, then the insert cursor * is displayed at the beginning of the next line. * Procedure to register a span of text that is no longer valid on the display * It is used to avoid a number of small, and potentially overlapping, screen * Procedure to read a span of text in Ascii form. This is purely a hack and * we probably need to add a function to sources to provide this functionality. * [note: this is really a private procedure but is used in multiple modules]. result[(
int)
length] =
'\0';
/* NULL terminate this sucker */ /* like _XawTextGetText, but enforces ICCCM STRING type encoding */ register unsigned char *s;
register unsigned char c;
/* only HT and NL control chars are allowed, strip out others */ for (j = 0; j < n; j++) {
if (((c >=
0x20) && c <=
0x7f) ||
(c >=
0xa0) || (c ==
'\t') || (c ==
'\n')) {
* This routine maps an x and y position in a window that is displaying text * into the corresponding position in the source. * NOTE: it is illegal to call this routine unless there is a valid line table! /*** figure out what line it is on ***/ * This routine maps a source position in to the corresponding line number * of the text that is displayed in the window. * NOTE: It is illegal to call this routine unless there is a valid line table! * This routine maps a source position into the corresponding line number * and the x, y coordinates of the text that is displayed in the window. * NOTE: It is illegal to call this routine unless there is a valid line table! * This routine builds a line table. It does this by starting at the * specified position and measuring text to determine the staring position * of each line to be displayed. It also determines and saves in the * linetable all the required metrics for displaying a given line (e.g. * x offset, y offset, line length, etc.). * This assumes that the line table does not change size. * If we are at the end of the buffer put two special lines in the table. * a) Both have position > text.lastPos and lt->textWidth = 0. * b) The first has a real height, and the second has a height that * is the rest of the screen. * I counld fill in the rest of the table with valid heights and a large * lastPos, but this method keeps the number of fill regions down to a * One valid endty is needed at the end of the table so that the cursor * does not jump off the bottom of the window. /* Function Name: GetWidestLine * Description: Returns the width (in pixels) of the widest line that * Arguments: ctx - the text widget. * Returns: the width of the widest line. * NOTE: This function requires a valid line table. else /* last - first >= 1.0 */ * This routine is used by Text to notify an associated scrollbar of the * correct metrics (position and shown fraction) for the text being currently * displayed in the window. * The routine will scroll the displayed text by lines. If the arg is * positive, move up; otherwise, move down. [note: this is really a private * procedure but is used in multiple modules]. if (n <
lt->
lines) n++;
/* update descenders at bottom */ * Redraw the line overflow marks. * Put in the text that just became visable. /* Function Name: UpdateTextInLine * Description: Updates some text in a given line. * Arguments: ctx - the text widget. * line - the line number (in the line table) of this line. * left, right - left and right pixel offsets of the return;
/* no need to update. */ * The routine will scroll the displayed text by pixels. If the calldata is * positive, move up; otherwise, move down. * The routine "thumbs" the displayed text. Thumbing means reposition the * displayed view of the source to a new position determined by a fraction * of the way from beginning to end. Ideally, this should be determined by * the number of displayable lines in the source. This routine does it as a * fraction of the first position and last position and then normalizes to * the start of the line containing the position. * BUG/deficiency: The normalize to line portion of this routine will * cause thumbing to always position to the start of the source. else /* *target == XA_LENGTH(d) */ /* Function Name: GetCutBuffferNumber * Description: Returns the number of the cut buffer. * Arguments: atom - the atom to check. * Returns: the number of the cut buffer representing this atom or * Must walk the selection list in opposite order from UnsetSelection. * If this is a cut buffer. else /* This is a real selection. */ * This internal routine deletes the text from pos1 to pos2 in a source and * then inserts, at pos1, the text that was passed. As a side effect it * "invalidates" that portion of the displayed text (if any). * NOTE: It is illegal to call this routine unless there is a valid line table! * The insertPos may not always be set to the right spot in XawtextAppend return(0);
/* Things are fine. */ * fixup all current line table entries to reflect edit. * %%% it is not legal to do arithmetic on positions. * using Scan would be more proper. * Now process the line table and fixup in case edits caused * changes in line breaks. If we are breaking on word boundaries, * this code checks for moving words to and from lines. return(0);
/* Things are fine. */ * This routine will display text between two arbitrary source positions. * In the event that this span contains highlighted text for the selection, * only that portion will be displayed highlighted. * NOTE: it is illegal to call this routine unless there return;
/* line not visible, or pos1 >= pos2. */ * We only get here if single character is true, and we need * to clear to the end of the screen. We know that since there * was only on character deleted that this is the same * as clearing an extra line, so we do this, and are done. * This a performance hack, and a pretty gross one, but it works. * Chris Peterson 11/13/89. break;
/* set single_char to FALSE and return. */ * This routine implements multi-click selection in a hardwired manner. * It supports multi-click entity cycling (char, word, line, file) and mouse * motion adjustment of the selected entitie (i.e. select a word then, with * button still down, adjust wich word you really meant by moving the mouse). * [NOTE: This routine is to be replaced by a set of procedures that * will allows clients to implements a wide class of draw through and * multi-click selection user interfaces.] else /* single-click event */ "Text Widget: empty selection array.");
if (!
motion) {
/* setup so we can freely mix select extend calls*/ * This routine implements extension of the currently selected text in * the "current" mode (i.e. char word, line, etc.). It worries about * extending from either end of the selection and handles the case when you * cross through the "center" of the current selection (e.g. switch which * end you are extending!). * [NOTE: This routine will be replaced by a set of procedures that * will allows clients to implements a wide class of draw through and * multi-click selection user interfaces.] if (!
motion) {
/* setup for extending selection */ else /* check for change in extend direction */ * Clear the window to background color. /* Function Name: _XawTextClearAndCenterDisplay * Description: Redraws the display with the cursor in insert point * Arguments: ctx - the text widget. * Internal redisplay entire window. * Legal to call only if widget is realized. * This routine checks to see if the window should be resized (grown or * shrunk) when text to be painted overflows to the right or * the bottom of the window. It is used by the keyboard input routine. * Converts (params, num_params) to a list of atoms & caches the * list in the TextWidget instance. /* Function Name: SetSelection * Description: Sets the current selection. * Arguments: ctx - the text widget. * defaultSel - the default selection. * l, r - the left and right ends of the selection. * list, nelems - the selection list (as strings). * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection /* Function Name: ModifySelection * Description: Modifies the current selection. * Arguments: ctx - the text widget. * left, right - the left and right ends of the selection. * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection * This routine is used to perform various selection functions. The goal is * to be able to specify all the more popular forms of draw-through and * multi-click selection user interfaces from the outside. XawactionAdjust, XawactionEnd} */ * This flag is used by TextPop.c:DoReplace() to determine if the selection * is okay to use, or if it has been modified. else /* mode == XawsmTextExtend */ /* Function Name: RectanglesOverlap * Description: Returns TRUE if two rectangles overlap. * Arguments: rect1, rect2 - the two rectangles to check. * Returns: TRUE iff these rectangles overlap. /* Function Name: UpdateTextInRectangle. * Description: Updates the text in a rectangle. * Arguments: ctx - the text widget. * rect - the rectangle to update. if ( (
info +
1)->y >= y )
* This routine processes all "expose region" XEvents. In general, its job * is to the best job at minimal re-paint of the text, displayed in the else {
/* Graphics Expose. */ * This routine does all setup required to syncronize batched screen updates * This is a private utility routine used by _XawTextExecuteUpdate. It * processes all the outstanding update requests and merges update * This is a private utility routine used by _XawTextExecuteUpdate. This * routine worries about edits causing new data or the insertion point becoming * invisible (off the screen, or under the horiz. scrollbar). Currently * it always makes it visible by scrolling. It probably needs * generalization to allow more options. #
else /* Using this code now... */ * Find out the bottom the visable window, and make sure that the * cursor does not go past the end of this space. * This makes sure that the cursor does not go past the end of the * This routine causes all batched screen updates to be performed * by the time we are managed (and get this far) we had better * have both a source and a sink * This routine allow the application program to Set attributes. /******************************* /*******************************/ /* Function Name: GetValuesHook * Description: This is a get values hook routine that gets the * values in the text source and sink. * Arguments: w - the Text Widget. * args - the argument list. * num_args - the number of args. /* Function Name: FindGoodPosition * Description: Returns a valid position given any postition * Arguments: pos - any position. * Returns: a position between (0 and lastPos); /******************************************************************* The following routines provide procedural interfaces to Text window state setting and getting. They need to be redone so than the args code can use them. I suggest we create a complete set that takes the context as an argument and then have the public version lookp the context and call the internal one. The major value of this set is that they have actual application clients and therefore the functionality provided is required for any future ********************************************************************/ * This public routine deletes the text from startPos to endPos in a source and * then inserts, at startPos, the text that was passed. As a side effect it * "invalidates" that portion of the displayed text (if any), so that things * will be repainted properly. * NOTE: Must walk the selection list in opposite order from LoseSelection. * As selections are lost the atom_count will decrement. XtDisownSelection failed to call us. */ /* Function Name: XawTextSearch(w, dir, text). * Description: searches for the given text block. * Arguments: w - The text widget. * dir - The direction to search. * text - The text block containing info about the string * Returns: The position of the text found, or XawTextSearchError on /* class_part_init */ NULL,
/* class_inited */ FALSE,
/* initialize_hook */ NULL,
/* num_actions */ 0,
/* Set in ClassInitialize. */ /* compress_motion */ TRUE,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* set_values_hook */ NULL,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* set in ClassInitialize */