1/*
2 * tkText.h --
3 *
4 *	Declarations shared among the files that implement text
5 *	widgets.
6 *
7 * Copyright (c) 1992-1994 The Regents of the University of California.
8 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id: tkText.h,v 1.13.2.1 2006/10/17 05:38:48 dgp Exp $
14 */
15
16#ifndef _TKTEXT
17#define _TKTEXT
18
19#ifndef _TK
20#include "tk.h"
21#endif
22
23#ifndef _TKUNDO
24#include "tkUndo.h"
25#endif
26
27#ifdef BUILD_tk
28# undef TCL_STORAGE_CLASS
29# define TCL_STORAGE_CLASS DLLEXPORT
30#endif
31
32/*
33 * Opaque types for structures whose guts are only needed by a single
34 * file:
35 */
36
37typedef struct TkTextBTree_ *TkTextBTree;
38
39/*
40 * The data structure below defines a single line of text (from newline
41 * to newline, not necessarily what appears on one line of the screen).
42 */
43
44typedef struct TkTextLine {
45    struct Node *parentPtr;		/* Pointer to parent node containing
46					 * line. */
47    struct TkTextLine *nextPtr;		/* Next in linked list of lines with
48					 * same parent node in B-tree.  NULL
49					 * means end of list. */
50    struct TkTextSegment *segPtr;	/* First in ordered list of segments
51					 * that make up the line. */
52} TkTextLine;
53
54/*
55 * -----------------------------------------------------------------------
56 * Segments: each line is divided into one or more segments, where each
57 * segment is one of several things, such as a group of characters, a
58 * tag toggle, a mark, or an embedded widget.  Each segment starts with
59 * a standard header followed by a body that varies from type to type.
60 * -----------------------------------------------------------------------
61 */
62
63/*
64 * The data structure below defines the body of a segment that represents
65 * a tag toggle.  There is one of these structures at both the beginning
66 * and end of each tagged range.
67 */
68
69typedef struct TkTextToggle {
70    struct TkTextTag *tagPtr;		/* Tag that starts or ends here. */
71    int inNodeCounts;			/* 1 means this toggle has been
72					 * accounted for in node toggle
73					 * counts; 0 means it hasn't, yet. */
74} TkTextToggle;
75
76/*
77 * The data structure below defines line segments that represent
78 * marks.  There is one of these for each mark in the text.
79 */
80
81typedef struct TkTextMark {
82    struct TkText *textPtr;		/* Overall information about text
83					 * widget. */
84    TkTextLine *linePtr;		/* Line structure that contains the
85					 * segment. */
86    Tcl_HashEntry *hPtr;		/* Pointer to hash table entry for mark
87					 * (in textPtr->markTable). */
88} TkTextMark;
89
90/*
91 * A structure of the following type holds information for each window
92 * embedded in a text widget.  This information is only used by the
93 * file tkTextWind.c
94 */
95
96typedef struct TkTextEmbWindow {
97    struct TkText *textPtr;		/* Information about the overall text
98					 * widget. */
99    TkTextLine *linePtr;		/* Line structure that contains this
100					 * window. */
101    Tk_Window tkwin;			/* Window for this segment.  NULL
102					 * means that the window hasn't
103					 * been created yet. */
104    char *create;			/* Script to create window on-demand.
105					 * NULL means no such script.
106					 * Malloc-ed. */
107    int align;				/* How to align window in vertical
108					 * space.  See definitions in
109					 * tkTextWind.c. */
110    int padX, padY;			/* Padding to leave around each side
111					 * of window, in pixels. */
112    int stretch;			/* Should window stretch to fill
113					 * vertical space of line (except for
114					 * pady)?  0 or 1. */
115    int chunkCount;			/* Number of display chunks that
116					 * refer to this window. */
117    int displayed;			/* Non-zero means that the window
118					 * has been displayed on the screen
119					 * recently. */
120} TkTextEmbWindow;
121
122/*
123 * A structure of the following type holds information for each image
124 * embedded in a text widget.  This information is only used by the
125 * file tkTextImage.c
126 */
127
128typedef struct TkTextEmbImage {
129    struct TkText *textPtr;		/* Information about the overall text
130					 * widget. */
131    TkTextLine *linePtr;		/* Line structure that contains this
132					 * image. */
133    char *imageString;			/* Name of the image for this segment */
134    char *imageName;			/* Name used by text widget to identify
135    					 * this image.  May be unique-ified */
136    char *name;				/* Name used in the hash table.
137    					 * used by "image names" to identify
138    					 * this instance of the image */
139    Tk_Image image;			/* Image for this segment.  NULL
140					 * means that the image hasn't
141					 * been created yet. */
142    int align;				/* How to align image in vertical
143					 * space.  See definitions in
144					 * tkTextImage.c. */
145    int padX, padY;			/* Padding to leave around each side
146					 * of image, in pixels. */
147    int chunkCount;			/* Number of display chunks that
148					 * refer to this image. */
149} TkTextEmbImage;
150
151/*
152 * The data structure below defines line segments.
153 */
154
155typedef struct TkTextSegment {
156    struct Tk_SegType *typePtr;		/* Pointer to record describing
157					 * segment's type. */
158    struct TkTextSegment *nextPtr;	/* Next in list of segments for this
159					 * line, or NULL for end of list. */
160    int size;				/* Size of this segment (# of bytes
161					 * of index space it occupies). */
162    union {
163	char chars[4];			/* Characters that make up character
164					 * info.  Actual length varies to
165					 * hold as many characters as needed.*/
166	TkTextToggle toggle;		/* Information about tag toggle. */
167	TkTextMark mark;		/* Information about mark. */
168	TkTextEmbWindow ew;		/* Information about embedded
169					 * window. */
170	TkTextEmbImage ei;		/* Information about embedded
171					 * image. */
172    } body;
173} TkTextSegment;
174
175/*
176 * Data structures of the type defined below are used during the
177 * execution of Tcl commands to keep track of various interesting
178 * places in a text.  An index is only valid up until the next
179 * modification to the character structure of the b-tree so they
180 * can't be retained across Tcl commands.  However, mods to marks
181 * or tags don't invalidate indices.
182 */
183
184typedef struct TkTextIndex {
185    TkTextBTree tree;			/* Tree containing desired position. */
186    TkTextLine *linePtr;		/* Pointer to line containing position
187					 * of interest. */
188    int byteIndex;			/* Index within line of desired
189					 * character (0 means first one). */
190} TkTextIndex;
191
192/*
193 * Types for procedure pointers stored in TkTextDispChunk strutures:
194 */
195
196typedef struct TkTextDispChunk TkTextDispChunk;
197
198typedef void 		Tk_ChunkDisplayProc _ANSI_ARGS_((
199			    TkTextDispChunk *chunkPtr, int x, int y,
200			    int height, int baseline, Display *display,
201			    Drawable dst, int screenY));
202typedef void		Tk_ChunkUndisplayProc _ANSI_ARGS_((
203			    struct TkText *textPtr,
204			    TkTextDispChunk *chunkPtr));
205typedef int		Tk_ChunkMeasureProc _ANSI_ARGS_((
206			    TkTextDispChunk *chunkPtr, int x));
207typedef void		Tk_ChunkBboxProc _ANSI_ARGS_((
208			    TkTextDispChunk *chunkPtr, int index, int y,
209			    int lineHeight, int baseline, int *xPtr,
210			    int *yPtr, int *widthPtr, int *heightPtr));
211
212/*
213 * The structure below represents a chunk of stuff that is displayed
214 * together on the screen.  This structure is allocated and freed by
215 * generic display code but most of its fields are filled in by
216 * segment-type-specific code.
217 */
218
219struct TkTextDispChunk {
220    /*
221     * The fields below are set by the type-independent code before
222     * calling the segment-type-specific layoutProc.  They should not
223     * be modified by segment-type-specific code.
224     */
225
226    int x;				/* X position of chunk, in pixels.
227					 * This position is measured from the
228					 * left edge of the logical line,
229					 * not from the left edge of the
230					 * window (i.e. it doesn't change
231					 * under horizontal scrolling). */
232    struct TkTextDispChunk *nextPtr;	/* Next chunk in the display line
233					 * or NULL for the end of the list. */
234    struct TextStyle *stylePtr;		/* Display information, known only
235					 * to tkTextDisp.c. */
236
237    /*
238     * The fields below are set by the layoutProc that creates the
239     * chunk.
240     */
241
242    Tk_ChunkDisplayProc *displayProc;	/* Procedure to invoke to draw this
243					 * chunk on the display or an
244					 * off-screen pixmap. */
245    Tk_ChunkUndisplayProc *undisplayProc;
246					/* Procedure to invoke when segment
247					 * ceases to be displayed on screen
248					 * anymore. */
249    Tk_ChunkMeasureProc *measureProc;	/* Procedure to find character under
250					 * a given x-location. */
251    Tk_ChunkBboxProc *bboxProc;		/* Procedure to find bounding box
252					 * of character in chunk. */
253    int numBytes;			/* Number of bytes that will be
254					 * displayed in the chunk. */
255    int minAscent;			/* Minimum space above the baseline
256					 * needed by this chunk. */
257    int minDescent;			/* Minimum space below the baseline
258					 * needed by this chunk. */
259    int minHeight;			/* Minimum total line height needed
260					 * by this chunk. */
261    int width;				/* Width of this chunk, in pixels.
262					 * Initially set by chunk-specific
263					 * code, but may be increased to
264					 * include tab or extra space at end
265					 * of line. */
266    int breakIndex;			/* Index within chunk of last
267					 * acceptable position for a line
268					 * (break just before this byte index).
269					 * <= 0 means don't break during or
270					 * immediately after this chunk. */
271    ClientData clientData;		/* Additional information for use
272					 * of displayProc and undisplayProc. */
273};
274
275/*
276 * One data structure of the following type is used for each tag in a
277 * text widget.  These structures are kept in textPtr->tagTable and
278 * referred to in other structures.
279 */
280
281typedef enum {	TEXT_WRAPMODE_NULL, TEXT_WRAPMODE_NONE,
282		TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_WORD
283} TkWrapMode;
284
285EXTERN Tk_CustomOption TkTextWrapModeOption;
286
287typedef struct TkTextTag {
288    char *name;			/* Name of this tag.  This field is actually
289				 * a pointer to the key from the entry in
290				 * textPtr->tagTable, so it needn't be freed
291				 * explicitly. */
292    int priority;		/* Priority of this tag within widget.  0
293				 * means lowest priority.  Exactly one tag
294				 * has each integer value between 0 and
295				 * numTags-1. */
296    struct Node *tagRootPtr;	/* Pointer into the B-Tree at the lowest
297				 * node that completely dominates the ranges
298				 * of text occupied by the tag.  At this
299				 * node there is no information about the
300				 * tag.  One or more children of the node
301				 * do contain information about the tag. */
302    int toggleCount;		/* Total number of tag toggles */
303
304    /*
305     * Information for displaying text with this tag.  The information
306     * belows acts as an override on information specified by lower-priority
307     * tags.  If no value is specified, then the next-lower-priority tag
308     * on the text determins the value.  The text widget itself provides
309     * defaults if no tag specifies an override.
310     */
311
312    Tk_3DBorder border;		/* Used for drawing background.  NULL means
313				 * no value specified here. */
314    char *bdString;		/* -borderwidth option string (malloc-ed).
315				 * NULL means option not specified. */
316    int borderWidth;		/* Width of 3-D border for background. */
317    char *reliefString;		/* -relief option string (malloc-ed).
318				 * NULL means option not specified. */
319    int relief;			/* 3-D relief for background. */
320    Pixmap bgStipple;		/* Stipple bitmap for background.  None
321				 * means no value specified here. */
322    XColor *fgColor;		/* Foreground color for text.  NULL means
323				 * no value specified here. */
324    Tk_Font tkfont;		/* Font for displaying text.  NULL means
325				 * no value specified here. */
326    Pixmap fgStipple;		/* Stipple bitmap for text and other
327				 * foreground stuff.   None means no value
328				 * specified here.*/
329    char *justifyString;	/* -justify option string (malloc-ed).
330				 * NULL means option not specified. */
331    Tk_Justify justify;		/* How to justify text: TK_JUSTIFY_LEFT,
332				 * TK_JUSTIFY_RIGHT, or TK_JUSTIFY_CENTER.
333				 * Only valid if justifyString is non-NULL. */
334    char *lMargin1String;	/* -lmargin1 option string (malloc-ed).
335				 * NULL means option not specified. */
336    int lMargin1;		/* Left margin for first display line of
337				 * each text line, in pixels.  Only valid
338				 * if lMargin1String is non-NULL. */
339    char *lMargin2String;	/* -lmargin2 option string (malloc-ed).
340				 * NULL means option not specified. */
341    int lMargin2;		/* Left margin for second and later display
342				 * lines of each text line, in pixels.  Only
343				 * valid if lMargin2String is non-NULL. */
344    char *offsetString;		/* -offset option string (malloc-ed).
345				 * NULL means option not specified. */
346    int offset;			/* Vertical offset of text's baseline from
347				 * baseline of line.  Used for superscripts
348				 * and subscripts.  Only valid if
349				 * offsetString is non-NULL. */
350    char *overstrikeString;	/* -overstrike option string (malloc-ed).
351				 * NULL means option not specified. */
352    int overstrike;		/* Non-zero means draw horizontal line through
353				 * middle of text.  Only valid if
354				 * overstrikeString is non-NULL. */
355    char *rMarginString;	/* -rmargin option string (malloc-ed).
356				 * NULL means option not specified. */
357    int rMargin;		/* Right margin for text, in pixels.  Only
358				 * valid if rMarginString is non-NULL. */
359    char *spacing1String;	/* -spacing1 option string (malloc-ed).
360				 * NULL means option not specified. */
361    int spacing1;		/* Extra spacing above first display
362				 * line for text line.  Only valid if
363				 * spacing1String is non-NULL. */
364    char *spacing2String;	/* -spacing2 option string (malloc-ed).
365				 * NULL means option not specified. */
366    int spacing2;		/* Extra spacing between display
367				 * lines for the same text line.  Only valid
368				 * if spacing2String is non-NULL. */
369    char *spacing3String;	/* -spacing2 option string (malloc-ed).
370				 * NULL means option not specified. */
371    int spacing3;		/* Extra spacing below last display
372				 * line for text line.  Only valid if
373				 * spacing3String is non-NULL. */
374    char *tabString;		/* -tabs option string (malloc-ed).
375				 * NULL means option not specified. */
376    struct TkTextTabArray *tabArrayPtr;
377				/* Info about tabs for tag (malloc-ed)
378				 * or NULL.  Corresponds to tabString. */
379    char *underlineString;	/* -underline option string (malloc-ed).
380				 * NULL means option not specified. */
381    int underline;		/* Non-zero means draw underline underneath
382				 * text.  Only valid if underlineString is
383				 * non-NULL. */
384    TkWrapMode wrapMode;	/* How to handle wrap-around for this tag.
385				 * Must be TEXT_WRAPMODE_CHAR,
386				 * TEXT_WRAPMODE_NONE, TEXT_WRAPMODE_WORD,
387				 * or TEXT_WRAPMODE_NULL to use wrapmode for
388				 * whole widget. */
389    char *elideString;		/* -elide option string (malloc-ed).
390				 * NULL means option not specified. */
391    int elide;			/* Non-zero means that data under this tag
392				 * should not be displayed. */
393    int affectsDisplay;		/* Non-zero means that this tag affects the
394				 * way information is displayed on the screen
395				 * (so need to redisplay if tag changes). */
396} TkTextTag;
397
398#define TK_TAG_AFFECTS_DISPLAY	0x1
399#define TK_TAG_UNDERLINE	0x2
400#define TK_TAG_JUSTIFY		0x4
401#define TK_TAG_OFFSET		0x10
402
403/*
404 * The data structure below is used for searching a B-tree for transitions
405 * on a single tag (or for all tag transitions).  No code outside of
406 * tkTextBTree.c should ever modify any of the fields in these structures,
407 * but it's OK to use them for read-only information.
408 */
409
410typedef struct TkTextSearch {
411    TkTextIndex curIndex;		/* Position of last tag transition
412					 * returned by TkBTreeNextTag, or
413					 * index of start of segment
414					 * containing starting position for
415					 * search if TkBTreeNextTag hasn't
416					 * been called yet, or same as
417					 * stopIndex if search is over. */
418    TkTextSegment *segPtr;		/* Actual tag segment returned by last
419					 * call to TkBTreeNextTag, or NULL if
420					 * TkBTreeNextTag hasn't returned
421					 * anything yet. */
422    TkTextSegment *nextPtr;		/* Where to resume search in next
423					 * call to TkBTreeNextTag. */
424    TkTextSegment *lastPtr;		/* Stop search before just before
425					 * considering this segment. */
426    TkTextTag *tagPtr;			/* Tag to search for (or tag found, if
427					 * allTags is non-zero). */
428    int linesLeft;			/* Lines left to search (including
429					 * curIndex and stopIndex).  When
430					 * this becomes <= 0 the search is
431					 * over. */
432    int allTags;			/* Non-zero means ignore tag check:
433					 * search for transitions on all
434					 * tags. */
435} TkTextSearch;
436
437/*
438 * The following data structure describes a single tab stop.
439 */
440
441typedef enum {LEFT, RIGHT, CENTER, NUMERIC} TkTextTabAlign;
442
443typedef struct TkTextTab {
444    int location;			/* Offset in pixels of this tab stop
445					 * from the left margin (lmargin2) of
446					 * the text. */
447    TkTextTabAlign alignment;		/* Where the tab stop appears relative
448					 * to the text. */
449} TkTextTab;
450
451typedef struct TkTextTabArray {
452    int numTabs;			/* Number of tab stops. */
453    TkTextTab tabs[1];			/* Array of tabs.  The actual size
454					 * will be numTabs.  THIS FIELD MUST
455					 * BE THE LAST IN THE STRUCTURE. */
456} TkTextTabArray;
457
458/* enum definining the edit modes of */
459
460typedef enum {
461    TK_TEXT_EDIT_INSERT,			/* insert mode */
462    TK_TEXT_EDIT_DELETE,			/* delete mode */
463    TK_TEXT_EDIT_OTHER			   /* none of the above */
464} TkTextEditMode;
465
466/*
467 * Enumeration defining the ways in which a text widget may be modified (for
468 * undo/redo handling).
469 */
470
471typedef enum {
472    TK_TEXT_DIRTY_NORMAL,	/* Normal behavior. */
473    TK_TEXT_DIRTY_UNDO,		/* Reverting a compound action. */
474    TK_TEXT_DIRTY_REDO,		/* Reapplying a compound action. */
475    TK_TEXT_DIRTY_FIXED		/* Forced to be dirty; can't be undone/redone
476				 * by normal activity. */
477} TkTextDirtyMode;
478
479/*
480 * A data structure of the following type is kept for each text widget that
481 * currently exists for this process:
482 */
483
484typedef struct TkText {
485    Tk_Window tkwin;		/* Window that embodies the text.  NULL
486				 * means that the window has been destroyed
487				 * but the data structures haven't yet been
488				 * cleaned up.*/
489    Display *display;		/* Display for widget.  Needed, among other
490				 * things, to allow resources to be freed
491				 * even after tkwin has gone away. */
492    Tcl_Interp *interp;		/* Interpreter associated with widget.  Used
493				 * to delete widget command.  */
494    Tcl_Command widgetCmd;	/* Token for text's widget command. */
495    TkTextBTree tree;		/* B-tree representation of text and tags for
496				 * widget. */
497    Tcl_HashTable tagTable;	/* Hash table that maps from tag names to
498				 * pointers to TkTextTag structures. */
499    int numTags;		/* Number of tags currently defined for
500				 * widget;  needed to keep track of
501				 * priorities. */
502    Tcl_HashTable markTable;	/* Hash table that maps from mark names to
503				 * pointers to mark segments. */
504    Tcl_HashTable windowTable;	/* Hash table that maps from window names
505				 * to pointers to window segments.  If a
506				 * window segment doesn't yet have an
507				 * associated window, there is no entry for
508				 * it here. */
509    Tcl_HashTable imageTable;	/* Hash table that maps from image names
510				 * to pointers to image segments.  If an
511				 * image segment doesn't yet have an
512				 * associated image, there is no entry for
513				 * it here. */
514    int state;			/* Either STATE_NORMAL or STATE_DISABLED. A
515				 * text widget is read-only when disabled. */
516
517    /*
518     * Default information for displaying (may be overridden by tags
519     * applied to ranges of characters).
520     */
521
522    Tk_3DBorder border;		/* Structure used to draw 3-D border and
523				 * default background. */
524    int borderWidth;		/* Width of 3-D border to draw around entire
525				 * widget. */
526    int padX, padY;		/* Padding between text and window border. */
527    int relief;			/* 3-d effect for border around entire
528				 * widget: TK_RELIEF_RAISED etc. */
529    int highlightWidth;		/* Width in pixels of highlight to draw
530				 * around widget when it has the focus.
531				 * <= 0 means don't draw a highlight. */
532    XColor *highlightBgColorPtr;
533				/* Color for drawing traversal highlight
534				 * area when highlight is off. */
535    XColor *highlightColorPtr;	/* Color for drawing traversal highlight. */
536    Tk_Cursor cursor;		/* Current cursor for window, or None. */
537    XColor *fgColor;		/* Default foreground color for text. */
538    Tk_Font tkfont;		/* Default font for displaying text. */
539    int charWidth;		/* Width of average character in default
540				 * font. */
541    int spacing1;		/* Default extra spacing above first display
542				 * line for each text line. */
543    int spacing2;		/* Default extra spacing between display lines
544				 * for the same text line. */
545    int spacing3;		/* Default extra spacing below last display
546				 * line for each text line. */
547    char *tabOptionString;	/* Value of -tabs option string (malloc'ed). */
548    TkTextTabArray *tabArrayPtr;
549				/* Information about tab stops (malloc'ed).
550				 * NULL means perform default tabbing
551				 * behavior. */
552
553    /*
554     * Additional information used for displaying:
555     */
556
557    TkWrapMode wrapMode;	/* How to handle wrap-around.  Must be
558				 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
559				 * TEXT_WRAPMODE_WORD. */
560    int width, height;		/* Desired dimensions for window, measured
561				 * in characters. */
562    int setGrid;		/* Non-zero means pass gridding information
563				 * to window manager. */
564    int prevWidth, prevHeight;	/* Last known dimensions of window;  used to
565				 * detect changes in size. */
566    TkTextIndex topIndex;	/* Identifies first character in top display
567				 * line of window. */
568    struct TextDInfo *dInfoPtr;	/* Information maintained by tkTextDisp.c. */
569
570    /*
571     * Information related to selection.
572     */
573
574    TkTextTag *selTagPtr;	/* Pointer to "sel" tag.  Used to tell when
575				 * a new selection has been made. */
576    Tk_3DBorder selBorder;	/* Border and background for selected
577				 * characters.  This is a copy of information
578				 * in *cursorTagPtr, so it shouldn't be
579				 * explicitly freed. */
580    char *selBdString;		/* Value of -selectborderwidth option, or NULL
581				 * if not specified (malloc'ed). */
582    XColor *selFgColorPtr;	/* Foreground color for selected text.
583				 * This is a copy of information in
584				 * *cursorTagPtr, so it shouldn't be
585				 * explicitly freed. */
586    int exportSelection;	/* Non-zero means tie "sel" tag to X
587				 * selection. */
588    TkTextIndex selIndex;	/* Used during multi-pass selection retrievals.
589				 * This index identifies the next character
590				 * to be returned from the selection. */
591    int abortSelections;	/* Set to 1 whenever the text is modified
592				 * in a way that interferes with selection
593				 * retrieval:  used to abort incremental
594				 * selection retrievals. */
595    int selOffset;		/* Offset in selection corresponding to
596				 * selLine and selCh.  -1 means neither
597				 * this information nor selIndex is of any
598				 * use. */
599
600    /*
601     * Information related to insertion cursor:
602     */
603
604    TkTextSegment *insertMarkPtr;
605				/* Points to segment for "insert" mark. */
606    Tk_3DBorder insertBorder;	/* Used to draw vertical bar for insertion
607				 * cursor. */
608    int insertWidth;		/* Total width of insert cursor. */
609    int insertBorderWidth;	/* Width of 3-D border around insert cursor. */
610    int insertOnTime;		/* Number of milliseconds cursor should spend
611				 * in "on" state for each blink. */
612    int insertOffTime;		/* Number of milliseconds cursor should spend
613				 * in "off" state for each blink. */
614    Tcl_TimerToken insertBlinkHandler;
615				/* Timer handler used to blink cursor on and
616				 * off. */
617
618    /*
619     * Information used for event bindings associated with tags:
620     */
621
622    Tk_BindingTable bindingTable;
623				/* Table of all bindings currently defined
624				 * for this widget.  NULL means that no
625				 * bindings exist, so the table hasn't been
626				 * created.  Each "object" used for this
627				 * table is the address of a tag. */
628    TkTextSegment *currentMarkPtr;
629				/* Pointer to segment for "current" mark,
630				 * or NULL if none. */
631    XEvent pickEvent;		/* The event from which the current character
632				 * was chosen.	Must be saved so that we
633				 * can repick after modifications to the
634				 * text. */
635    int numCurTags;		/* Number of tags associated with character
636				 * at current mark. */
637    TkTextTag **curTagArrayPtr;	/* Pointer to array of tags for current
638				 * mark, or NULL if none. */
639
640    /*
641     * Miscellaneous additional information:
642     */
643
644    char *takeFocus;		/* Value of -takeFocus option;	not used in
645				 * the C code, but used by keyboard traversal
646				 * scripts.  Malloc'ed, but may be NULL. */
647    char *xScrollCmd;		/* Prefix of command to issue to update
648				 * horizontal scrollbar when view changes. */
649    char *yScrollCmd;		/* Prefix of command to issue to update
650				 * vertical scrollbar when view changes. */
651    int flags;			/* Miscellaneous flags;	 see below for
652				 * definitions. */
653
654    /*
655     * Information related to the undo/redo funcitonality
656     */
657
658    TkUndoRedoStack *undoStack;	/* The undo/redo stack. */
659    int undo;			/* non zero means the undo/redo behaviour is
660				 * enabled. */
661    int maxUndo;		/* The maximum depth of the undo stack
662				 * expressed as the maximum number of compound
663				 * statements. */
664    int autoSeparators;		/* non zero means the separatorss will be
665				 * inserted automatically. */
666    int isDirty;		/* Flag indicating the 'dirtynesss' of the
667				 * text widget. If the flag is not zero,
668				 * unsaved modifications have been applied to
669				 * the text widget. */
670    TkTextDirtyMode dirtyMode;	/* The nature of the dirtyness characterized
671				 * by the isDirty flag. */
672    TkTextEditMode lastEditMode;/* Keeps track of what the last edit mode
673				 * was. */
674} TkText;
675
676/*
677 * Flag values for TkText records:
678 *
679 * GOT_SELECTION:		Non-zero means we've already claimed the
680 *				selection.
681 * INSERT_ON:			Non-zero means insertion cursor should be
682 *				displayed on screen.
683 * GOT_FOCUS:			Non-zero means this window has the input
684 *				focus.
685 * BUTTON_DOWN:			1 means that a mouse button is currently
686 *				down;  this is used to implement grabs
687 *				for the duration of button presses.
688 * UPDATE_SCROLLBARS:		Non-zero means scrollbar(s) should be updated
689 *				during next redisplay operation.
690 */
691
692#define GOT_SELECTION		1
693#define INSERT_ON		2
694#define GOT_FOCUS		4
695#define BUTTON_DOWN		8
696#define UPDATE_SCROLLBARS	0x10
697#define NEED_REPICK		0x20
698
699/*
700 * Records of the following type define segment types in terms of
701 * a collection of procedures that may be called to manipulate
702 * segments of that type.
703 */
704
705typedef TkTextSegment *	Tk_SegSplitProc _ANSI_ARGS_((
706			    struct TkTextSegment *segPtr, int index));
707typedef int		Tk_SegDeleteProc _ANSI_ARGS_((
708			    struct TkTextSegment *segPtr,
709			    TkTextLine *linePtr, int treeGone));
710typedef TkTextSegment *	Tk_SegCleanupProc _ANSI_ARGS_((
711			    struct TkTextSegment *segPtr, TkTextLine *linePtr));
712typedef void		Tk_SegLineChangeProc _ANSI_ARGS_((
713			    struct TkTextSegment *segPtr, TkTextLine *linePtr));
714typedef int		Tk_SegLayoutProc _ANSI_ARGS_((struct TkText *textPtr,
715			    struct TkTextIndex *indexPtr, TkTextSegment *segPtr,
716			    int offset, int maxX, int maxChars,
717			    int noCharsYet, TkWrapMode wrapMode,
718			    struct TkTextDispChunk *chunkPtr));
719typedef void		Tk_SegCheckProc _ANSI_ARGS_((TkTextSegment *segPtr,
720			    TkTextLine *linePtr));
721
722typedef struct Tk_SegType {
723    char *name;				/* Name of this kind of segment. */
724    int leftGravity;			/* If a segment has zero size (e.g. a
725					 * mark or tag toggle), does it
726					 * attach to character to its left
727					 * or right?  1 means left, 0 means
728					 * right. */
729    Tk_SegSplitProc *splitProc;		/* Procedure to split large segment
730					 * into two smaller ones. */
731    Tk_SegDeleteProc *deleteProc;	/* Procedure to call to delete
732					 * segment. */
733    Tk_SegCleanupProc *cleanupProc;	/* After any change to a line, this
734					 * procedure is invoked for all
735					 * segments left in the line to
736					 * perform any cleanup they wish
737					 * (e.g. joining neighboring
738					 * segments). */
739    Tk_SegLineChangeProc *lineChangeProc;
740					/* Invoked when a segment is about
741					 * to be moved from its current line
742					 * to an earlier line because of
743					 * a deletion.  The linePtr is that
744					 * for the segment's old line.
745					 * CleanupProc will be invoked after
746					 * the deletion is finished. */
747    Tk_SegLayoutProc *layoutProc;	/* Returns size information when
748					 * figuring out what to display in
749					 * window. */
750    Tk_SegCheckProc *checkProc;		/* Called during consistency checks
751					 * to check internal consistency of
752					 * segment. */
753} Tk_SegType;
754
755/*
756 * The constant below is used to specify a line when what is really
757 * wanted is the entire text.  For now, just use a very big number.
758 */
759
760#define TK_END_OF_TEXT 1000000
761
762/*
763 * The following definition specifies the maximum number of characters
764 * needed in a string to hold a position specifier.
765 */
766
767#define TK_POS_CHARS 30
768
769/*
770 * Declarations for variables shared among the text-related files:
771 */
772
773EXTERN int		tkBTreeDebug;
774EXTERN int		tkTextDebug;
775EXTERN Tk_SegType	tkTextCharType;
776EXTERN Tk_SegType	tkTextLeftMarkType;
777EXTERN Tk_SegType	tkTextRightMarkType;
778EXTERN Tk_SegType	tkTextToggleOnType;
779EXTERN Tk_SegType	tkTextToggleOffType;
780
781/*
782 * Declarations for procedures that are used by the text-related files
783 * but shouldn't be used anywhere else in Tk (or by Tk clients):
784 */
785
786EXTERN int		TkBTreeCharTagged _ANSI_ARGS_((TkTextIndex *indexPtr,
787			    TkTextTag *tagPtr));
788EXTERN void		TkBTreeCheck _ANSI_ARGS_((TkTextBTree tree));
789EXTERN int		TkBTreeCharsInLine _ANSI_ARGS_((TkTextLine *linePtr));
790EXTERN int		TkBTreeBytesInLine _ANSI_ARGS_((TkTextLine *linePtr));
791EXTERN TkTextBTree	TkBTreeCreate _ANSI_ARGS_((TkText *textPtr));
792EXTERN void		TkBTreeDestroy _ANSI_ARGS_((TkTextBTree tree));
793EXTERN void		TkBTreeDeleteChars _ANSI_ARGS_((TkTextIndex *index1Ptr,
794			    TkTextIndex *index2Ptr));
795EXTERN TkTextLine *	TkBTreeFindLine _ANSI_ARGS_((TkTextBTree tree,
796			    int line));
797EXTERN TkTextTag **	TkBTreeGetTags _ANSI_ARGS_((TkTextIndex *indexPtr,
798			    int *numTagsPtr));
799EXTERN void		TkBTreeInsertChars _ANSI_ARGS_((TkTextIndex *indexPtr,
800			    CONST char *string));
801EXTERN int		TkBTreeLineIndex _ANSI_ARGS_((TkTextLine *linePtr));
802EXTERN void		TkBTreeLinkSegment _ANSI_ARGS_((TkTextSegment *segPtr,
803			    TkTextIndex *indexPtr));
804EXTERN TkTextLine *	TkBTreeNextLine _ANSI_ARGS_((TkTextLine *linePtr));
805EXTERN int		TkBTreeNextTag _ANSI_ARGS_((TkTextSearch *searchPtr));
806EXTERN int		TkBTreeNumLines _ANSI_ARGS_((TkTextBTree tree));
807EXTERN TkTextLine *	TkBTreePreviousLine _ANSI_ARGS_((TkTextLine *linePtr));
808EXTERN int		TkBTreePrevTag _ANSI_ARGS_((TkTextSearch *searchPtr));
809EXTERN void		TkBTreeStartSearch _ANSI_ARGS_((TkTextIndex *index1Ptr,
810			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
811			    TkTextSearch *searchPtr));
812EXTERN void		TkBTreeStartSearchBack _ANSI_ARGS_((TkTextIndex *index1Ptr,
813			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
814			    TkTextSearch *searchPtr));
815EXTERN void		TkBTreeTag _ANSI_ARGS_((TkTextIndex *index1Ptr,
816			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
817			    int add));
818EXTERN void		TkBTreeUnlinkSegment _ANSI_ARGS_((TkTextBTree tree,
819			    TkTextSegment *segPtr, TkTextLine *linePtr));
820EXTERN void		TkTextBindProc _ANSI_ARGS_((ClientData clientData,
821			    XEvent *eventPtr));
822EXTERN void		TkTextChanged _ANSI_ARGS_((TkText *textPtr,
823			    TkTextIndex *index1Ptr, TkTextIndex *index2Ptr));
824EXTERN int		TkTextCharBbox _ANSI_ARGS_((TkText *textPtr,
825			    TkTextIndex *indexPtr, int *xPtr, int *yPtr,
826			    int *widthPtr, int *heightPtr));
827EXTERN int		TkTextCharLayoutProc _ANSI_ARGS_((TkText *textPtr,
828			    TkTextIndex *indexPtr, TkTextSegment *segPtr,
829			    int offset, int maxX, int maxChars, int noBreakYet,
830			    TkWrapMode wrapMode, TkTextDispChunk *chunkPtr));
831EXTERN void		TkTextCreateDInfo _ANSI_ARGS_((TkText *textPtr));
832EXTERN int		TkTextDLineInfo _ANSI_ARGS_((TkText *textPtr,
833			    TkTextIndex *indexPtr, int *xPtr, int *yPtr,
834			    int *widthPtr, int *heightPtr, int *basePtr));
835EXTERN TkTextTag *	TkTextCreateTag _ANSI_ARGS_((TkText *textPtr,
836			    CONST char *tagName));
837EXTERN void		TkTextFreeDInfo _ANSI_ARGS_((TkText *textPtr));
838EXTERN void		TkTextFreeTag _ANSI_ARGS_((TkText *textPtr,
839			    TkTextTag *tagPtr));
840EXTERN int		TkTextGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
841			    TkText *textPtr, CONST char *string,
842			    TkTextIndex *indexPtr));
843EXTERN TkTextTabArray *	TkTextGetTabs _ANSI_ARGS_((Tcl_Interp *interp,
844			    Tk_Window tkwin, char *string));
845EXTERN void		TkTextIndexBackBytes _ANSI_ARGS_((
846			    CONST TkTextIndex *srcPtr, int count,
847			    TkTextIndex *dstPtr));
848EXTERN void		TkTextIndexBackChars _ANSI_ARGS_((
849			    CONST TkTextIndex *srcPtr, int count,
850			    TkTextIndex *dstPtr));
851EXTERN int		TkTextIndexCmp _ANSI_ARGS_((
852			    CONST TkTextIndex *index1Ptr,
853			    CONST TkTextIndex *index2Ptr));
854EXTERN void		TkTextIndexForwBytes _ANSI_ARGS_((
855			    CONST TkTextIndex *srcPtr, int count,
856			    TkTextIndex *dstPtr));
857EXTERN void		TkTextIndexForwChars _ANSI_ARGS_((
858			    CONST TkTextIndex *srcPtr, int count,
859			    TkTextIndex *dstPtr));
860EXTERN TkTextSegment *	TkTextIndexToSeg _ANSI_ARGS_((
861			    CONST TkTextIndex *indexPtr, int *offsetPtr));
862EXTERN void		TkTextInsertDisplayProc _ANSI_ARGS_((
863			    TkTextDispChunk *chunkPtr, int x, int y, int height,
864			    int baseline, Display *display, Drawable dst,
865			    int screenY));
866EXTERN void		TkTextLostSelection _ANSI_ARGS_((
867			    ClientData clientData));
868EXTERN TkTextIndex *	TkTextMakeCharIndex _ANSI_ARGS_((TkTextBTree tree,
869			    int lineIndex, int charIndex,
870			    TkTextIndex *indexPtr));
871EXTERN int		TkTextIsElided _ANSI_ARGS_((TkText *textPtr,
872			    TkTextIndex *indexPtr));
873EXTERN TkTextIndex *	TkTextMakeByteIndex _ANSI_ARGS_((TkTextBTree tree,
874			    int lineIndex, int byteIndex,
875			    TkTextIndex *indexPtr));
876EXTERN int		TkTextMarkCmd _ANSI_ARGS_((TkText *textPtr,
877			    Tcl_Interp *interp, int argc, CONST char **argv));
878EXTERN int		TkTextMarkNameToIndex _ANSI_ARGS_((TkText *textPtr,
879			    CONST char *name, TkTextIndex *indexPtr));
880EXTERN void		TkTextMarkSegToIndex _ANSI_ARGS_((TkText *textPtr,
881			    TkTextSegment *markPtr, TkTextIndex *indexPtr));
882EXTERN void		TkTextEventuallyRepick _ANSI_ARGS_((TkText *textPtr));
883EXTERN void		TkTextPickCurrent _ANSI_ARGS_((TkText *textPtr,
884			    XEvent *eventPtr));
885EXTERN void		TkTextPixelIndex _ANSI_ARGS_((TkText *textPtr,
886			    int x, int y, TkTextIndex *indexPtr));
887EXTERN void		TkTextPrintIndex _ANSI_ARGS_((
888			    CONST TkTextIndex *indexPtr, char *string));
889EXTERN void		TkTextRedrawRegion _ANSI_ARGS_((TkText *textPtr,
890			    int x, int y, int width, int height));
891EXTERN void		TkTextRedrawTag _ANSI_ARGS_((TkText *textPtr,
892			    TkTextIndex *index1Ptr, TkTextIndex *index2Ptr,
893			    TkTextTag *tagPtr, int withTag));
894EXTERN void		TkTextRelayoutWindow _ANSI_ARGS_((TkText *textPtr));
895EXTERN int		TkTextScanCmd _ANSI_ARGS_((TkText *textPtr,
896			    Tcl_Interp *interp, int argc, CONST char **argv));
897EXTERN int		TkTextSeeCmd _ANSI_ARGS_((TkText *textPtr,
898			    Tcl_Interp *interp, int argc, CONST char **argv));
899EXTERN int		TkTextSegToOffset _ANSI_ARGS_((
900			    CONST TkTextSegment *segPtr,
901			    CONST TkTextLine *linePtr));
902EXTERN TkTextSegment *	TkTextSetMark _ANSI_ARGS_((TkText *textPtr,
903			    CONST char *name, TkTextIndex *indexPtr));
904EXTERN void		TkTextSetYView _ANSI_ARGS_((TkText *textPtr,
905			    TkTextIndex *indexPtr, int pickPlace));
906EXTERN int		TkTextTagCmd _ANSI_ARGS_((TkText *textPtr,
907			    Tcl_Interp *interp, int argc, CONST char **argv));
908EXTERN int		TkTextImageCmd _ANSI_ARGS_((TkText *textPtr,
909			    Tcl_Interp *interp, int argc, CONST char **argv));
910EXTERN int		TkTextImageIndex _ANSI_ARGS_((TkText *textPtr,
911			    CONST char *name, TkTextIndex *indexPtr));
912EXTERN int		TkTextWindowCmd _ANSI_ARGS_((TkText *textPtr,
913			    Tcl_Interp *interp, int argc, CONST char **argv));
914EXTERN int		TkTextWindowIndex _ANSI_ARGS_((TkText *textPtr,
915			    CONST char *name, TkTextIndex *indexPtr));
916EXTERN int		TkTextXviewCmd _ANSI_ARGS_((TkText *textPtr,
917			    Tcl_Interp *interp, int argc, CONST char **argv));
918EXTERN int		TkTextYviewCmd _ANSI_ARGS_((TkText *textPtr,
919			    Tcl_Interp *interp, int argc, CONST char **argv));
920
921# undef TCL_STORAGE_CLASS
922# define TCL_STORAGE_CLASS DLLIMPORT
923
924#endif /* _TKTEXT */
925