/*
 *	sccsid:	@(#)TextDisp.h	1.8	6/8/87
 */
/*
 * Copyright 1987 by Digital Equipment Corporation, Maynard, 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 name of Digital Equipment
 * Corporation 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 ACTIO
N,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

/* File: TextDisplay.h */

#define MAXCUT	30000	/* Maximum number of characters that can be cut. */

#define LF	'\n'
#define CR	'\r'
#define TAB	'\t'
#define BS	'\b'
#define SP	0x20
#define DEL	0x7f
#define BSLASH	'\\'

#define EDITDONE 0
#define EDITERROR 1
#define POSITIONERROR 2

typedef enum {sdLEFT, sdRIGHT} ScanDirection;
typedef enum {stPOSITIONS, stWHITESPACE, stEOL, stPARAGRAPH, stFILE}
	      ScanType;

typedef struct {
    int		    (*read)();
    int		    (*replace)();
    XtTextPosition  (*getLastPos)();
    int		    (*setLastPos)();
    XtTextPosition  (*scan)();
    XtEditType      (*editType)();
    int		    *data;
    } XtTextSource, *TextSourcePtr;

typedef struct {
    int (*display)();
    int (*insertCursor)();
    int (*clearToBackground)();
    int (*findPosition)();
    int (*findDistance)();
    int (*resolve)();
    int (*maxLines)();
    int (*maxHeight)();
    int *data;
    } XtTextSink, *TextSinkPtr;

/* displayable text management data structures */

typedef struct {
    XtTextPosition position;
    int x, y, endX;
    } LineTableEntry, *LineTableEntryPtr;

/* Line Tables are n+1 long - last position displayed is in last lt entry */
typedef struct {
    XtTextPosition  top;	/* Top of the displayed text.		*/
    int		    lines;	/* How many lines in this table.	*/
    LineTableEntry  *entry;	/* A dynamic array, one entry per line  */
    } LineTable, *LineTablePtr;

typedef enum {isON, isOFF} InsertState;

typedef enum {smTEXTSELECT, smTEXTEXTEND} SelectionMode;

typedef enum {actionSTART, actionADJUST, actionEND} SelectionAction;

typedef XtSelectType SelectionArray[20];

typedef struct {
    XtTextPosition left, right;
    XtSelectType  type;
} TextSelection;

#define IsPositionVisible(ctx, pos)	(pos >= ctx->lt.entry[0].position && \
	    pos <= ctx->lt.entry[ctx->lt.lines].position)

/* Private Text Definitions */

typedef int (*ActionProc)();

typedef struct  {
    XtTextSource    *source;
    XtTextSink      *sink;
    LineTable       lt;
    XtTextPosition  insertPos;
    TextSelection   s;
    ScanDirection   extendDir;
    TextSelection   origSel;	    /* the selection being modified */
    SelectionArray  sarray;	    /* Array to cycle for selections. */
    int width, height;		    /* Dimensions of the text subwindow */
    int		    leftmargin;     /* Width of left margin. */
    int		    options;	    /* wordbreak, scroll, etc. */
    unsigned short  lasttime;       /* timestamp of last processed action */
    unsigned short  time;	    /* timestamp of last key or button action */
    unsigned int    x, y;	    /* x, y coords for key or button action */
    Window	    sbar;	    /* The vertical scroll bar (none = 0).  */
    Window	    outer;	    /* Parent of scrollbar & text (if any) */
    Window	    w;		    /* Actual window containing text.  */
    XtTextPosition  *updateFrom;    /* Array of start positions for update. */
    XtTextPosition  *updateTo;      /* Array of end positions for update. */
    int		    numranges;      /* How many update ranges there are. */
    int		    maxranges;      /* How many update ranges we've space for */
    Boolean	    showposition;   /* True if we need to show the position. */
    XtTextPosition  lastPos;	    /* Last position of source. */
    Window	    dialog;	    /* Window containing dialog, if any. */
    int		    borderWidth;    /* width of window border (if any) */
    XtEventsPtr     eventTable;     /* Table for translation mgr. */
    caddr_t	    state;	    /* translation manager state handle */
    Pixmap           border;
    int              background;	    /* window colors */
} TextContext, *TextContextPtr;


extern char *_XtTextGetText(); /* ctx, left, right */
    /* TextContext    *ctx;		*/
    /* XtTextPosition left, right;	*/

extern void ForceBuildLineTable(); /* ctx */
    /* TextContext *ctx;		*/

extern void AlterSelection(); /* ctx, mode, action */
    /* TextContext     *ctx;						  */
    /* SelectionMode   mode;	/* {smTEXTSELECT, smTEXTEXTEND} 	  */
    /* SelectionAction action;	/* {actionSTART, actionADJUST, actionEND} */
