17a84e134Smrg/***********************************************************
27a84e134Smrg
37a84e134SmrgCopyright 1987, 1988, 1994, 1998  The Open Group
47a84e134Smrg
57a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its
67a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that
77a84e134Smrgthe above copyright notice appear in all copies and that both that
87a84e134Smrgcopyright notice and this permission notice appear in supporting
97a84e134Smrgdocumentation.
107a84e134Smrg
117a84e134SmrgThe above copyright notice and this permission notice shall be included in
127a84e134Smrgall copies or substantial portions of the Software.
137a84e134Smrg
147a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
177a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
187a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
197a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
207a84e134Smrg
217a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be
227a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings
237a84e134Smrgin this Software without prior written authorization from The Open Group.
247a84e134Smrg
257a84e134Smrg
267a84e134SmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
277a84e134Smrg
287a84e134Smrg                        All Rights Reserved
297a84e134Smrg
30421c997bSmrgPermission to use, copy, modify, and distribute this software and its
31421c997bSmrgdocumentation for any purpose and without fee is hereby granted,
327a84e134Smrgprovided that the above copyright notice appear in all copies and that
33421c997bSmrgboth that copyright notice and this permission notice appear in
347a84e134Smrgsupporting documentation, and that the name of Digital not be
357a84e134Smrgused in advertising or publicity pertaining to distribution of the
36421c997bSmrgsoftware without specific, written prior permission.
377a84e134Smrg
387a84e134SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
397a84e134SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
407a84e134SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
417a84e134SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
427a84e134SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
437a84e134SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
447a84e134SmrgSOFTWARE.
457a84e134Smrg
467a84e134Smrg******************************************************************/
477a84e134Smrg
487a84e134Smrg#ifndef _XawTextP_h
497a84e134Smrg#define _XawTextP_h
507a84e134Smrg
517a84e134Smrg#include <X11/Xfuncproto.h>
527a84e134Smrg
537a84e134Smrg#include <X11/Xaw/Text.h>
547a84e134Smrg#include <X11/Xaw/SimpleP.h>
557a84e134Smrg
567a84e134Smrg_XFUNCPROTOBEGIN
577a84e134Smrg
587a84e134Smrg#define MAXCUT	30000	/* Maximum number of characters that can be cut */
597a84e134Smrg
607a84e134Smrg#define XawTextGetLastPosition(ctx)				\
617a84e134Smrg	XawTextSourceScan((ctx)->text.source, 0,		\
627a84e134Smrg			  XawstAll, XawsdRight, 1, True)
637a84e134Smrg#define GETLASTPOS	XawTextGetLastPosition(ctx)
647a84e134Smrg
657a84e134Smrg#define zeroPosition ((XawTextPosition)0)
667a84e134Smrg
677a84e134Smrgextern XtActionsRec _XawTextActionsTable[];
687a84e134Smrgextern Cardinal _XawTextActionsTableCount;
697a84e134Smrg
70775e7de9Smrgextern char _XawDefaultTextTranslations[];
71775e7de9Smrg
727a84e134Smrg#define XawLF	  0x0a
737a84e134Smrg#define XawCR	  0x0d
747a84e134Smrg#define XawTAB	  0x09
757a84e134Smrg#define XawBS	  0x08
767a84e134Smrg#define XawSP	  0x20
777a84e134Smrg#define XawDEL	  0x7f
787a84e134Smrg#define XawESC	  0x1b
797a84e134Smrg#define XawBSLASH '\\'
807a84e134Smrg
817a84e134Smrg/* constants that subclasses may want to know */
827a84e134Smrg#define DEFAULT_TEXT_HEIGHT ((Dimension)~0)
837a84e134Smrg#define DEFAULT_TAB_SIZE	8
847a84e134Smrg
857a84e134Smrg/* displayable text management data structures */
867a84e134Smrgtypedef struct {
877a84e134Smrg    XawTextPosition position;
887a84e134Smrg    Position y;
897a84e134Smrg#ifndef OLDXAW
907a84e134Smrg    unsigned int textWidth;
917a84e134Smrg#else
927a84e134Smrg    Dimension textWidth;
937a84e134Smrg#endif
947a84e134Smrg} XawTextLineTableEntry, *XawTextLineTableEntryPtr;
957a84e134Smrg
967a84e134Smrgtypedef struct {
977a84e134Smrg    XawTextPosition left, right;
987a84e134Smrg    XawTextSelectType type;
997a84e134Smrg    Atom *selections;
1007a84e134Smrg    int atom_count;
1017a84e134Smrg    int array_size;
1027a84e134Smrg} XawTextSelection;
1037a84e134Smrg
1047a84e134Smrgtypedef struct _XawTextSelectionSalt {
1057a84e134Smrg    struct _XawTextSelectionSalt *next;
1067a84e134Smrg    XawTextSelection	s;
107421c997bSmrg    /*
1087a84e134Smrg     * The element "contents" stores the CT string which is gotten in the
1097a84e134Smrg     * function _XawTextSaltAwaySelection()
110421c997bSmrg    */
1117a84e134Smrg    char		*contents;
1127a84e134Smrg    int			length;
1137a84e134Smrg} XawTextSelectionSalt;
1147a84e134Smrg
1157a84e134Smrg#ifndef OLDXAW
1167a84e134Smrgtypedef struct _XawTextKillRing {
1177a84e134Smrg    struct _XawTextKillRing *next;
1187a84e134Smrg    char *contents;
1197a84e134Smrg    int length;
1207a84e134Smrg    unsigned refcount;
1217a84e134Smrg    unsigned long format;
1227a84e134Smrg} XawTextKillRing;
1237a84e134Smrg
1247a84e134Smrgextern XawTextKillRing *xaw_text_kill_ring;
1257a84e134Smrg#endif
1267a84e134Smrg
1277a84e134Smrg/* Line Tables are n+1 long - last position displayed is in last lt entry */
1287a84e134Smrgtypedef struct {
1297a84e134Smrg    XawTextPosition top;	 /* Top of the displayed text */
1307a84e134Smrg    int lines;			 /* How many lines in this table */
1317a84e134Smrg#ifndef OLDXAW
1327a84e134Smrg    int base_line;		 /* line number of first entry */
1337a84e134Smrg#endif
1347a84e134Smrg    XawTextLineTableEntry *info; /* A dynamic array, one entry per line  */
1357a84e134Smrg} XawTextLineTable, *XawTextLineTablePtr;
1367a84e134Smrg
1377a84e134Smrgtypedef struct _XawTextMargin {
1387a84e134Smrg    Position left, right, top, bottom;
1397a84e134Smrg} XawTextMargin;
1407a84e134Smrg
1417a84e134Smrgtypedef struct _XmuScanline XmuTextUpdate;
1427a84e134Smrg
1437a84e134Smrg#define VMargins(ctx)  ((ctx)->text.margin.top + (ctx)->text.margin.bottom)
1447a84e134Smrg#define HMargins(ctx)  ((ctx)->text.left_margin + (ctx)->text.margin.right)
1457a84e134Smrg#define RVMargins(ctx) ((ctx)->text.r_margin.top + (ctx)->text.r_margin.bottom)
1467a84e134Smrg#define RHMargins(ctx) ((ctx)->text.r_margin.left + (ctx)->text.r_margin.right)
1477a84e134Smrg
1487a84e134Smrg#define IsPositionVisible(ctx, pos) \
1497a84e134Smrg(pos >= ctx->text.lt.info[0].position && \
1507a84e134Smrg		 pos < ctx->text.lt.info[ctx->text.lt.lines].position)
1517a84e134Smrg
1527a84e134Smrg/*
1537a84e134Smrg * Search & Replace data structure
1547a84e134Smrg */
1557a84e134Smrgstruct SearchAndReplace {
1567a84e134Smrg    Boolean selection_changed;	/* flag so that the selection cannot be
1577a84e134Smrg				   changed out from underneath query-replace.*/
1585b16253fSmrg    Widget search_popup;	/* The popup widget that allows searches.*/
1597a84e134Smrg    Widget label1;		/* The label widgets for the search window. */
1607a84e134Smrg    Widget label2;
161421c997bSmrg    Widget left_toggle;		/* The left search toggle radioGroup. */
1627a84e134Smrg    Widget right_toggle;	/* The right search toggle radioGroup. */
1637a84e134Smrg    Widget rep_label;		/* The Replace label string. */
1647a84e134Smrg    Widget rep_text;		/* The Replace text field. */
165421c997bSmrg    Widget search_text;		/* The Search text field. */
1667a84e134Smrg    Widget rep_one;		/* The Replace one button. */
1677a84e134Smrg    Widget rep_all;		/* The Replace all button. */
1687a84e134Smrg#ifndef OLDXAW
1697a84e134Smrg    Widget case_sensitive;	/* The "Case Sensitive" toggle */
1707a84e134Smrg#endif
1717a84e134Smrg};
1727a84e134Smrg
1737a84e134Smrg/* New fields for the Text widget class record */
1747a84e134Smrgtypedef struct {
1757a84e134Smrg  XtPointer extension;
1767a84e134Smrg} TextClassPart;
1777a84e134Smrg
1787a84e134Smrg/* Full class record declaration */
1797a84e134Smrgtypedef struct _TextClassRec {
1807a84e134Smrg    CoreClassPart	core_class;
1817a84e134Smrg    SimpleClassPart	simple_class;
1827a84e134Smrg    TextClassPart	text_class;
1837a84e134Smrg} TextClassRec;
1847a84e134Smrg
1857a84e134Smrgextern TextClassRec textClassRec;
1867a84e134Smrg
1877a84e134Smrg/* New fields for the Text widget record */
1887a84e134Smrgtypedef struct _TextPart {
1897a84e134Smrg    /* resources */
1907a84e134Smrg    Widget source, sink;
1917a84e134Smrg    XawTextPosition insertPos;
1927a84e134Smrg    XawTextSelection s;
1937a84e134Smrg    XawTextSelectType *sarray;		     /* Array to cycle for selections */
1947a84e134Smrg    XawTextSelectionSalt *salt;		     /* salted away selections */
1957a84e134Smrg    int left_margin;
1967a84e134Smrg    int dialog_horiz_offset, dialog_vert_offset; /* position for popup dialog */
1977a84e134Smrg    Boolean display_caret;		     /* insertion pt visible iff T */
1987a84e134Smrg    Boolean auto_fill;			     /* Auto fill mode? */
1997a84e134Smrg    XawTextScrollMode scroll_vert, scroll_horiz;
2007a84e134Smrg    XawTextWrapMode wrap;		     /* The type of wrapping */
2017a84e134Smrg    XawTextResizeMode resize;
2027a84e134Smrg    XawTextMargin r_margin;		     /* The real margins */
2037a84e134Smrg#ifndef OLDXAW
2047a84e134Smrg    XtCallbackList position_callbacks;
2057a84e134Smrg#else
2067a84e134Smrg    XtPointer pad1;
2077a84e134Smrg#endif
2087a84e134Smrg
2097a84e134Smrg    /* private state */
2107a84e134Smrg    XawTextMargin margin;		     /* The current margins */
2117a84e134Smrg    XawTextLineTable lt;
2127a84e134Smrg    XawTextScanDirection extendDir;
2137a84e134Smrg    XawTextSelection origSel;		     /* the selection being modified */
2147a84e134Smrg    Time lasttime;			     /* timestamp of last processed action */
2157a84e134Smrg    Time time;				     /* time of last key or button action */
2167a84e134Smrg    Position ev_x, ev_y;		     /* x, y coords for key or button action */
2177a84e134Smrg    Widget vbar, hbar;			     /* The scroll bars (none = NULL) */
2187a84e134Smrg    struct SearchAndReplace *search;	     /* Search and replace structure */
2197a84e134Smrg    Widget file_insert;			     /* The file insert popup widget */
2207a84e134Smrg    XmuTextUpdate *update;		     /* Position intervals to update */
2217a84e134Smrg#ifndef OLDXAW
2227a84e134Smrg    int line_number;
2237a84e134Smrg    short column_number;
2247a84e134Smrg    unsigned char kill_ring;
2257a84e134Smrg    Boolean selection_state;
2267a84e134Smrg#else
2277a84e134Smrg    XtPointer pad2;
2287a84e134Smrg    int pad3;
2297a84e134Smrg#endif
2307a84e134Smrg    int from_left;			     /* Cursor position */
2317a84e134Smrg    XawTextPosition lastPos;		     /* Last position of source */
2327a84e134Smrg    GC gc;
2337a84e134Smrg    Boolean showposition;		     /* True if we need to show the position */
2347a84e134Smrg    Boolean hasfocus;			     /* TRUE if we currently have input focus*/
2357a84e134Smrg    Boolean update_disabled;		     /* TRUE if display updating turned off */
2367a84e134Smrg    Boolean clear_to_eol;		     /* Clear to eol when painting text? */
2377a84e134Smrg    XawTextPosition old_insert;		     /* Last insertPos for batched updates */
2387a84e134Smrg    short mult;				     /* Multiplier */
2397a84e134Smrg#ifndef OLDXAW
2407a84e134Smrg    XawTextKillRing *kill_ring_ptr;
2417a84e134Smrg#else
2427a84e134Smrg    XtPointer pad4;
2437a84e134Smrg#endif
2447a84e134Smrg
2457a84e134Smrg    /* private state, shared w/Source and Sink */
2467a84e134Smrg    Boolean redisplay_needed;		     /* in SetValues */
2477a84e134Smrg    XawTextSelectionSalt *salt2;	     /* salted away selections */
2487a84e134Smrg
2497a84e134Smrg#ifndef OLDXAW
2507a84e134Smrg    char numeric;
2517a84e134Smrg    char source_changed;
2527a84e134Smrg    Boolean overwrite;                      /* Overwrite mode */
2537a84e134Smrg
2547a84e134Smrg    /* new resources and states, for text edition
2557a84e134Smrg     * Note: a fixed width font is required for these resources/states.
2567a84e134Smrg     */
2577a84e134Smrg    short left_column, right_column;
2587a84e134Smrg    XawTextJustifyMode justify;
2595b16253fSmrg    XtPointer pad[4];	/* for future use and keep binary compatibility */
2607a84e134Smrg#endif
2617a84e134Smrg} TextPart;
2627a84e134Smrg
2637a84e134Smrg#define XtRWrapMode	"WrapMode"
2647a84e134Smrg#define XtRScrollMode	"ScrollMode"
2657a84e134Smrg#define XtRResizeMode	"ResizeMode"
2667a84e134Smrg#define XtRJustifyMode	"JustifyMode"
2677a84e134Smrg
2687a84e134Smrg/* full instance record */
2697a84e134Smrgtypedef struct _TextRec {
2707a84e134Smrg    CorePart	core;
2717a84e134Smrg    SimplePart	simple;
2727a84e134Smrg    TextPart	text;
2737a84e134Smrg} TextRec;
2747a84e134Smrg
2757a84e134Smrg/*
2767a84e134Smrg * Semi-private functions
2777a84e134Smrg * for use by other Xaw modules only
2787a84e134Smrg */
2797a84e134Smrgvoid _XawTextBuildLineTable
2807a84e134Smrg(
2817a84e134Smrg TextWidget		ctx,
2827a84e134Smrg XawTextPosition	top_pos,
2837a84e134Smrg _XtBoolean		force_rebuild
2847a84e134Smrg );
2857a84e134Smrg
2867a84e134Smrgchar *_XawTextGetSTRING
2877a84e134Smrg(
2887a84e134Smrg TextWidget		ctx,
2897a84e134Smrg XawTextPosition	left,
2907a84e134Smrg XawTextPosition	right
2917a84e134Smrg );
2927a84e134Smrg
2937a84e134Smrgvoid _XawTextSaltAwaySelection
2947a84e134Smrg(
2957a84e134Smrg TextWidget		ctx,
2967a84e134Smrg Atom			*selections,
2977a84e134Smrg int			num_atoms
2987a84e134Smrg );
2997a84e134Smrg
3007a84e134Smrgvoid _XawTextPosToXY
3017a84e134Smrg(
3027a84e134Smrg Widget			w,
3037a84e134Smrg XawTextPosition	pos,
3047a84e134Smrg Position		*x,
3057a84e134Smrg Position		*y
3067a84e134Smrg );
3077a84e134Smrg
3087a84e134Smrgvoid _XawTextNeedsUpdating
3097a84e134Smrg(
3107a84e134Smrg TextWidget		ctx,
3117a84e134Smrg XawTextPosition	left,
3127a84e134Smrg XawTextPosition	right
3137a84e134Smrg );
3147a84e134Smrg
3157a84e134Smrg_XFUNCPROTOEND
3167a84e134Smrg
3177a84e134Smrg#endif /* _XawTextP_h */
318