#endif /* lint && SABER */
/***********************************************************
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <./Xaw3_1XawInit.h>
#include <./Xaw3_1Cardinals.h>
#include <./Xaw3_1Scrollbar.h>
#include <./Xaw3_1TextP.h>
#ifdef SYSV
#ifndef bcopy
#endif
#ifndef bzero
#endif
#endif
#ifndef SYSV
extern void bcopy();
#endif
extern char* sys_errlist[];
/*
* Defined in Text.c
*/
static void DisplayTextWindow(), ModifySelection();
static void UpdateTextInLine(), UpdateTextInRectangle();
static Boolean LineAndXYForPosition();
void _XawTextAlterSelection(), _XawTextExecuteUpdate();
void _XawTextBuildLineTable(), _XawTextSetScrollBars();
/****************************************************************
*
* Full class record constant
*
****************************************************************/
};
extern char *_XawDefaultTextTranslations1, *_XawDefaultTextTranslations2,
#ifdef XAW_BC
/*
* This resource is obsolete.
*/
#endif
};
/* ARGSUSED */
static void
{
XrmQuark q;
if ( !inited ) {
}
q = XrmStringToQuark(lowerName);
else {
return;
}
return;
}
/* ARGSUSED */
static void
{
XrmQuark q;
if ( !inited ) {
}
q = XrmStringToQuark(lowerName);
else {
return;
}
return;
}
/* ARGSUSED */
static void
{
XrmQuark q;
if ( !inited ) {
}
q = XrmStringToQuark(lowerName);
else {
return;
}
return;
}
/* ARGSUSED */
static void
{
XrmQuark q;
if ( !inited ) {
}
q = XrmStringToQuark(lowerName);
else {
return;
}
return;
}
static void
{
/*
* Set the number of actions.
*/
}
/* Function Name: PositionHScrollBar.
* Description: Positions the Horizontal scrollbar.
* Arguments: ctx - the text widget.
* Returns: none
*/
static void
{
}
/* Function Name: PositionVScrollBar.
* Description: Positions the Vertical scrollbar.
* Arguments: ctx - the text widget.
* Returns: none.
*/
static void
{
}
static void
{
}
}
/* Function Name: DestroyVScrollBar
* Description: Removes a vertical ScrollBar.
* Arguments: ctx - the parent text widget.
* Returns: none.
*/
static void
{
}
static void
{
}
}
/* Function Name: DestroyHScrollBar
* Description: Removes a horizontal ScrollBar.
* Arguments: ctx - the parent text widget.
* Returns: none.
*/
static void
{
/*
ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width;
ctx->text.margin.bottom = ctx->text.r_margin.bottom;
*/
}
/* ARGSUSED */
static void
{
if (!FMT8BIT)
#ifdef XAW_BC
/*******************************
* For Compatability. */
/*******************************/
#endif /* XAW_BC */
}
"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.");
}
}
static void
Widget w;
{
(w, valueMask, attributes);
}
}
}
/* Utility routines for support of Text */
static void
Display *d;
{
static struct _DisplayRec {
PropModeAppend, NULL, 0 );
Create( XA_CUT_BUFFER0 );
Create( XA_CUT_BUFFER1 );
Create( XA_CUT_BUFFER2 );
Create( XA_CUT_BUFFER3 );
Create( XA_CUT_BUFFER4 );
Create( XA_CUT_BUFFER5 );
Create( XA_CUT_BUFFER6 );
Create( XA_CUT_BUFFER7 );
}
/*
* 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.
*/
static void
Widget w;
{
Position x, y;
int line;
else
}
}
/*
* 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
* updates.
*/
void
{
int i;
return;
}
}
}
}
}
/*
* 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].
*/
char *
{
}
return(result);
}
/* like _XawTextGetText, but enforces ICCCM STRING type encoding */
char *
{
register unsigned char *s;
register unsigned char c;
register int i, j, n;
/* only HT and NL control chars are allowed, strip out others */
n = strlen((char *)s);
i = 0;
for (j = 0; j < n; j++) {
c = s[j];
if (((c >= 0x20) && c <= 0x7f) ||
(c >= 0xa0) || (c == '\t') || (c == '\n')) {
s[i] = c;
i++;
}
}
s[i] = 0;
return (char *)s;
}
/*
* 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 ***/
static XawTextPosition
Position x,y;
{
break;
}
return(position);
}
/*
* 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!
*/
static int
{
int line;
break;
return(line);
}
/*
* 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!
*/
static Boolean
int *line;
Position *x, *y;
{
*line = 0;
*x += realW;
}
return(visible);
}
/*
* 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.).
*/
void
{
int lines = 0;
}
}
}
}
/*
* This assumes that the line table does not change size.
*/
static XawTextPosition
int line;
{
Position y;
else
while ( TRUE ) {
lt->y = y;
y += realH;
break;
}
++lt;
++line;
return(position);
}
/*
* 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
* minimum.
*
* One valid endty is needed at the end of the table so that the cursor
* does not jump off the bottom of the window.
*/
}
return(endPos);
}
/* Function Name: GetWidestLine
* Description: Returns the width (in pixels) of the widest line that
* is currently visable.
* Arguments: ctx - the text widget.
* Returns: the width of the widest line.
*
* NOTE: This function requires a valid line table.
*/
static Dimension
{
int i;
return(widest);
}
static void
{
else
last = 1.0;
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.
*/
void
{
else
if (widest < 1.0)
else
}
}
}
}
/*
* 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].
*/
void
int n;
{
int y;
if (n == 0) return;
if (n > 0) {
if ( IsValidLine(ctx, n) )
else
else {
(Position) 0,
}
}
else {
n = -n;
else
height = 0;
else
clear_height = 0;
}
}
}
/*ARGSUSED*/
static void
Widget w;
{
}
if (pixels > 0) {
0, (int) rect.y);
}
else if (pixels < 0) {
rect.x = 0;
/*
* Redraw the line overflow marks.
*/
}
/*
* Put in the text that just became visable.
*/
if ( pixels != 0 ) {
}
}
/*ARGSUSED*/
static void
Widget w;
{
return;
}
}
/* 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
* area to update.
* Returns: none.
*/
static void
int line;
{
return; /* no need to update. */
else
pos2 = GETLASTPOS;
else {
}
}
/*
* The routine will scroll the displayed text by pixels. If the calldata is
* positive, move up; otherwise, move down.
*/
/*ARGSUSED*/
static void
Widget w;
{
if (height < 1)
height = 1;
}
/*
* 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.
*/
/*ARGSUSED*/
static void
Widget w;
{
else
int line = 0;
}
else {
int line = 0;
}
else
}
}
static Boolean
Widget w;
unsigned long *length;
int *format;
{
if (*target == XA_TARGETS(d)) {
unsigned long std_length;
return True;
&std_length, format);
*targetP++ = XA_COMPOUND_TEXT(d);
*targetP++ = XA_LIST_LENGTH(d);
*targetP++ = XA_CHARACTER_POSITION(d);
if (edit_mode == XawtextEdit) {
(*length)++;
}
XtFree((char*)std_targets);
*format = 32;
return True;
}
return True;
*target == XA_COMPOUND_TEXT(d)) {
if (*target == XA_COMPOUND_TEXT(d))
else
*format = 8;
return True;
}
long * temp;
if (*target == XA_LIST_LENGTH(d))
*temp = 1L;
else /* *target == XA_LENGTH(d) */
*type = XA_INTEGER;
*length = 1L;
*format = 32;
return True;
}
if (*target == XA_CHARACTER_POSITION(d)) {
long * temp;
*length = 2L;
*format = 32;
return True;
}
void _XawTextZapSelection(); /* From TextAction.c */
*length = 0;
*format = 32;
return True;
}
return True;
/* else */
return False;
}
/* 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
* NOT_A_CUT_BUFFER.
*/
static int
{
if (atom == XA_CUT_BUFFER0) return(0);
return(NOT_A_CUT_BUFFER);
}
static void
Widget w;
{
register int i;
/*
* Must walk the selection list in opposite order from UnsetSelection.
*/
}
}
void
{
}
}
}
}
int buffer;
while (count) {
/*
* If this is a cut buffer.
*/
char *ptr;
if (buffer == 0) {
}
}
else /* This is a real selection. */
}
}
else
}
/*
* 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!
*/
int
{
/*
* The insertPos may not always be set to the right spot in XawtextAppend
*/
return( XawEditError );
}
}
return(error);
}
return(0); /* Things are fine. */
}
else
}
}
/*
* fixup all current line table entries to reflect edit.
* %%% it is not legal to do arithmetic on positions.
* using Scan would be more proper.
*/
if (delta != 0) {
}
/*
* 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
* is a valid line table!
*/
static void
Widget w;
{
Position x, y;
return; /* line not visible, or pos1 >= pos2. */
}
else {
}
(Position) 0, y,
else {
}
}
if (clear_eol) {
/*
* 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.
*/
if (done_painting) {
y += height;
break; /* set single_char to FALSE and return. */
}
}
break;
}
}
/*
* 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.]
*/
static void
{
if (motion)
else {
if (*sarray == XawselectNull)
else {
if (newType == XawselectNull)
}
}
else /* single-click event */
}
switch (newType) {
case XawselectPosition:
break;
case XawselectChar:
break;
case XawselectWord:
break;
case XawselectParagraph:
break;
case XawselectLine:
break;
case XawselectAll:
break;
default:
"Text Widget: empty selection array.");
return;
}
else
}
if (!motion) { /* setup so we can freely mix select extend calls*/
else
}
}
/*
* 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.]
*/
static void
{
if (!motion) { /* setup for extending selection */
else
}
else /* check for change in extend direction */
}
case XawselectWord:
break;
case XawselectLine:
break;
case XawselectParagraph:
break;
case XawselectAll:
case XawselectPosition: /* fall through. */
default:
break;
}
else
}
/*
* Clear the window to background color.
*/
static void
ClearWindow (w)
Widget w;
{
if (XtIsRealized(w))
}
/* Function Name: _XawTextClearAndCenterDisplay
* Description: Redraws the display with the cursor in insert point
* centered vertically.
* Arguments: ctx - the text widget.
* Returns: none.
*/
void
{
}
/*
* Internal redisplay entire window.
* Legal to call only if widget is realized.
*/
static void
Widget w;
{
ClearWindow(w);
}
/*
* 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.
*/
void
{
}
}
return;
else
return;
}
/*
* Converts (params, num_params) to a list of atoms & caches the
* list in the TextWidget instance.
*/
Atom*
{
}
}
/* 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).
* Returns: none.
*
* is unset.
*/
void
XawTextPosition l, r;
{
if (nelems == 0) {
list = &defaultSel;
nelems = 1;
}
}
/* Function Name: ModifySelection
* Description: Modifies the current selection.
* Arguments: ctx - the text widget.
* left, right - the left and right ends of the selection.
* Returns: none.
*
* is unset.
*/
static void
{
}
/*
* 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.
*/
void
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.
*/
if (mode == XawsmTextSelect)
else /* mode == XawsmTextExtend */
if (action == XawactionEnd)
params, *num_params);
}
/* Function Name: RectanglesOverlap
* Description: Returns TRUE if two rectangles overlap.
* Arguments: rect1, rect2 - the two rectangles to check.
* Returns: TRUE iff these rectangles overlap.
*/
static Boolean
{
}
/* Function Name: UpdateTextInRectangle.
* Description: Updates the text in a rectangle.
* Arguments: ctx - the text widget.
* rect - the rectangle to update.
* Returns: none.
*/
static void
XRectangle * rect;
{
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
* window, that it can.
*/
/* ARGSUSED */
static void
Widget w;
{
}
else { /* Graphics Expose. */
}
}
}
/*
* This routine does all setup required to syncronize batched screen updates
*/
void
{
}
}
/*
* This is a private utility routine used by _XawTextExecuteUpdate. It
* processes all the outstanding update requests and merges update
* ranges where possible.
*/
static
{
int i, w;
return;
}
w = 0;
w = i;
}
}
}
}
}
}
/*
* 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.
*/
{
return;
#ifdef notdef
else
#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
* visable window.
*/
max_pos++;
#endif
return;
else
number = 1;
else
break;
}
} else {
}
}
/*
* This routine causes all batched screen updates to be performed
*/
void
{
return;
}
static void
TextDestroy(w)
Widget w;
{
}
/*
* by the time we are managed (and get this far) we had better
* have both a source and a sink
*/
static void
Resize(w)
Widget w;
{
}
/*
* This routine allow the application program to Set attributes.
*/
/*ARGSUSED*/
static Boolean
{
#ifdef XAW_BC
/*******************************
* For Compatability. */
/*******************************/
#endif /* XAW_BC */
}
}
}
}
{
}
if (redisplay)
return redisplay;
}
/* 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.
* Returns: none.
*/
static void
Widget w;
{
}
/* Function Name: FindGoodPosition
* Description: Returns a valid position given any postition
* Arguments: pos - any position.
* Returns: a position between (0 and lastPos);
*/
static XawTextPosition
{
if (pos < 0) return(0);
}
/*******************************************************************
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
version of Text.
********************************************************************/
void
XawTextDisplay (w)
Widget w;
{
if (!XtIsRealized(w)) return;
_XawTextExecuteUpdate( (TextWidget) w);
}
void
Widget w;
{
}
void
Widget w;
{
}
void
{
XawTextDisplay(w);
}
/*
* 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.
*/
int
Widget w;
{
int result;
}
}
return result;
}
Widget w;
{
}
void
Widget w;
{
}
Widget w;
{
}
/*
* NOTE: Must walk the selection list in opposite order from LoseSelection.
*/
void
Widget w;
{
/*
* As selections are lost the atom_count will decrement.
*/
XtDisownSelection failed to call us. */
}
}
}
#ifdef XAW_BC
void
Widget w;
int options;
{
else
else
else
else
else
}
int
Widget w;
{
}
#endif /* XAW_BC */
void
Widget w;
{
}
void
Widget w;
{
}
/*ARGSUSED*/
void
Widget w;
{
}
void
Widget w;
{
if (XtIsRealized(w))
}
Widget w;
{
}
void
Widget w;
{
if (XtIsRealized(w)) {
}
else
}
/* 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
* to search for.
* Returns: The position of the text found, or XawTextSearchError on
* an error.
*/
Widget w;
XawTextBlock * text;
{
}
{ /* core fields */
/* class_name */ "Text",
/* widget_size */ sizeof(TextRec),
/* class_initialize */ ClassInitialize,
/* class_part_init */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ textActionsTable,
/* num_actions */ 0, /* Set in ClassInitialize. */
/* resources */ resources,
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure*/ XtExposeGraphicsExpose,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* destroy */ TextDestroy,
/* resize */ Resize,
/* expose */ ProcessExposeRegion,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost*/ XtInheritSetValuesAlmost,
/* get_values_hook */ GetValuesHook,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator*/ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{ /* Simple fields */
/* change_sensitive */ XtInheritChangeSensitive
},
{ /* text fields */
/* empty */ 0
}
};