annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/tkText.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /*
jpayne@69 2 * tkText.h --
jpayne@69 3 *
jpayne@69 4 * Declarations shared among the files that implement text widgets.
jpayne@69 5 *
jpayne@69 6 * Copyright (c) 1992-1994 The Regents of the University of California.
jpayne@69 7 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
jpayne@69 8 *
jpayne@69 9 * See the file "license.terms" for information on usage and redistribution of
jpayne@69 10 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
jpayne@69 11 */
jpayne@69 12
jpayne@69 13 #ifndef _TKTEXT
jpayne@69 14 #define _TKTEXT
jpayne@69 15
jpayne@69 16 #ifndef _TK
jpayne@69 17 #include "tk.h"
jpayne@69 18 #endif
jpayne@69 19
jpayne@69 20 #ifndef _TKUNDO
jpayne@69 21 #include "tkUndo.h"
jpayne@69 22 #endif
jpayne@69 23
jpayne@69 24 /*
jpayne@69 25 * The data structure below defines a single logical line of text (from
jpayne@69 26 * newline to newline, not necessarily what appears on one display line of the
jpayne@69 27 * screen).
jpayne@69 28 */
jpayne@69 29
jpayne@69 30 typedef struct TkTextLine {
jpayne@69 31 struct Node *parentPtr; /* Pointer to parent node containing line. */
jpayne@69 32 struct TkTextLine *nextPtr; /* Next in linked list of lines with same
jpayne@69 33 * parent node in B-tree. NULL means end of
jpayne@69 34 * list. */
jpayne@69 35 struct TkTextSegment *segPtr;
jpayne@69 36 /* First in ordered list of segments that make
jpayne@69 37 * up the line. */
jpayne@69 38 int *pixels; /* Array containing two integers for each
jpayne@69 39 * referring text widget. The first of these
jpayne@69 40 * is the number of vertical pixels taken up
jpayne@69 41 * by this line, whether currently displayed
jpayne@69 42 * or not. This number is only updated
jpayne@69 43 * asychronously. The second of these is the
jpayne@69 44 * last epoch at which the pixel height was
jpayne@69 45 * recalculated. */
jpayne@69 46 } TkTextLine;
jpayne@69 47
jpayne@69 48 /*
jpayne@69 49 * -----------------------------------------------------------------------
jpayne@69 50 * Segments: each line is divided into one or more segments, where each
jpayne@69 51 * segment is one of several things, such as a group of characters, a tag
jpayne@69 52 * toggle, a mark, or an embedded widget. Each segment starts with a standard
jpayne@69 53 * header followed by a body that varies from type to type.
jpayne@69 54 * -----------------------------------------------------------------------
jpayne@69 55 */
jpayne@69 56
jpayne@69 57 /*
jpayne@69 58 * The data structure below defines the body of a segment that represents a
jpayne@69 59 * tag toggle. There is one of these structures at both the beginning and end
jpayne@69 60 * of each tagged range.
jpayne@69 61 */
jpayne@69 62
jpayne@69 63 typedef struct TkTextToggle {
jpayne@69 64 struct TkTextTag *tagPtr; /* Tag that starts or ends here. */
jpayne@69 65 int inNodeCounts; /* 1 means this toggle has been accounted for
jpayne@69 66 * in node toggle counts; 0 means it hasn't,
jpayne@69 67 * yet. */
jpayne@69 68 } TkTextToggle;
jpayne@69 69
jpayne@69 70 /*
jpayne@69 71 * The data structure below defines line segments that represent marks. There
jpayne@69 72 * is one of these for each mark in the text.
jpayne@69 73 */
jpayne@69 74
jpayne@69 75 typedef struct TkTextMark {
jpayne@69 76 struct TkText *textPtr; /* Overall information about text widget. */
jpayne@69 77 TkTextLine *linePtr; /* Line structure that contains the
jpayne@69 78 * segment. */
jpayne@69 79 Tcl_HashEntry *hPtr; /* Pointer to hash table entry for mark (in
jpayne@69 80 * sharedTextPtr->markTable). */
jpayne@69 81 } TkTextMark;
jpayne@69 82
jpayne@69 83 /*
jpayne@69 84 * A structure of the following type holds information for each window
jpayne@69 85 * embedded in a text widget. This information is only used by the file
jpayne@69 86 * tkTextWind.c
jpayne@69 87 */
jpayne@69 88
jpayne@69 89 typedef struct TkTextEmbWindowClient {
jpayne@69 90 struct TkText *textPtr; /* Information about the overall text
jpayne@69 91 * widget. */
jpayne@69 92 Tk_Window tkwin; /* Window for this segment. NULL means that
jpayne@69 93 * the window hasn't been created yet. */
jpayne@69 94 int chunkCount; /* Number of display chunks that refer to this
jpayne@69 95 * window. */
jpayne@69 96 int displayed; /* Non-zero means that the window has been
jpayne@69 97 * displayed on the screen recently. */
jpayne@69 98 struct TkTextSegment *parent;
jpayne@69 99 struct TkTextEmbWindowClient *next;
jpayne@69 100 } TkTextEmbWindowClient;
jpayne@69 101
jpayne@69 102 typedef struct TkTextEmbWindow {
jpayne@69 103 struct TkSharedText *sharedTextPtr;
jpayne@69 104 /* Information about the shared portion of the
jpayne@69 105 * text widget. */
jpayne@69 106 Tk_Window tkwin; /* Window for this segment. This is just a
jpayne@69 107 * temporary value, copied from 'clients', to
jpayne@69 108 * make option table updating easier. NULL
jpayne@69 109 * means that the window hasn't been created
jpayne@69 110 * yet. */
jpayne@69 111 TkTextLine *linePtr; /* Line structure that contains this
jpayne@69 112 * window. */
jpayne@69 113 char *create; /* Script to create window on-demand. NULL
jpayne@69 114 * means no such script. Malloc-ed. */
jpayne@69 115 int align; /* How to align window in vertical space. See
jpayne@69 116 * definitions in tkTextWind.c. */
jpayne@69 117 int padX, padY; /* Padding to leave around each side of
jpayne@69 118 * window, in pixels. */
jpayne@69 119 int stretch; /* Should window stretch to fill vertical
jpayne@69 120 * space of line (except for pady)? 0 or 1. */
jpayne@69 121 Tk_OptionTable optionTable; /* Token representing the configuration
jpayne@69 122 * specifications. */
jpayne@69 123 TkTextEmbWindowClient *clients;
jpayne@69 124 /* Linked list of peer-widget specific
jpayne@69 125 * information for this embedded window. */
jpayne@69 126 } TkTextEmbWindow;
jpayne@69 127
jpayne@69 128 /*
jpayne@69 129 * A structure of the following type holds information for each image embedded
jpayne@69 130 * in a text widget. This information is only used by the file tkTextImage.c
jpayne@69 131 */
jpayne@69 132
jpayne@69 133 typedef struct TkTextEmbImage {
jpayne@69 134 struct TkSharedText *sharedTextPtr;
jpayne@69 135 /* Information about the shared portion of the
jpayne@69 136 * text widget. This is used when the image
jpayne@69 137 * changes or is deleted. */
jpayne@69 138 TkTextLine *linePtr; /* Line structure that contains this image. */
jpayne@69 139 char *imageString; /* Name of the image for this segment. */
jpayne@69 140 char *imageName; /* Name used by text widget to identify this
jpayne@69 141 * image. May be unique-ified. */
jpayne@69 142 char *name; /* Name used in the hash table. Used by
jpayne@69 143 * "image names" to identify this instance of
jpayne@69 144 * the image. */
jpayne@69 145 Tk_Image image; /* Image for this segment. NULL means that the
jpayne@69 146 * image hasn't been created yet. */
jpayne@69 147 int align; /* How to align image in vertical space. See
jpayne@69 148 * definitions in tkTextImage.c. */
jpayne@69 149 int padX, padY; /* Padding to leave around each side of image,
jpayne@69 150 * in pixels. */
jpayne@69 151 int chunkCount; /* Number of display chunks that refer to this
jpayne@69 152 * image. */
jpayne@69 153 Tk_OptionTable optionTable; /* Token representing the configuration
jpayne@69 154 * specifications. */
jpayne@69 155 } TkTextEmbImage;
jpayne@69 156
jpayne@69 157 /*
jpayne@69 158 * The data structure below defines line segments.
jpayne@69 159 */
jpayne@69 160
jpayne@69 161 typedef struct TkTextSegment {
jpayne@69 162 const struct Tk_SegType *typePtr;
jpayne@69 163 /* Pointer to record describing segment's
jpayne@69 164 * type. */
jpayne@69 165 struct TkTextSegment *nextPtr;
jpayne@69 166 /* Next in list of segments for this line, or
jpayne@69 167 * NULL for end of list. */
jpayne@69 168 int size; /* Size of this segment (# of bytes of index
jpayne@69 169 * space it occupies). */
jpayne@69 170 union {
jpayne@69 171 char chars[TCL_UTF_MAX]; /* Characters that make up character info.
jpayne@69 172 * Actual length varies to hold as many
jpayne@69 173 * characters as needed.*/
jpayne@69 174 TkTextToggle toggle; /* Information about tag toggle. */
jpayne@69 175 TkTextMark mark; /* Information about mark. */
jpayne@69 176 TkTextEmbWindow ew; /* Information about embedded window. */
jpayne@69 177 TkTextEmbImage ei; /* Information about embedded image. */
jpayne@69 178 } body;
jpayne@69 179 } TkTextSegment;
jpayne@69 180
jpayne@69 181 /*
jpayne@69 182 * Data structures of the type defined below are used during the execution of
jpayne@69 183 * Tcl commands to keep track of various interesting places in a text. An
jpayne@69 184 * index is only valid up until the next modification to the character
jpayne@69 185 * structure of the b-tree so they can't be retained across Tcl commands.
jpayne@69 186 * However, mods to marks or tags don't invalidate indices.
jpayne@69 187 */
jpayne@69 188
jpayne@69 189 typedef struct TkTextIndex {
jpayne@69 190 TkTextBTree tree; /* Tree containing desired position. */
jpayne@69 191 TkTextLine *linePtr; /* Pointer to line containing position of
jpayne@69 192 * interest. */
jpayne@69 193 int byteIndex; /* Index within line of desired character (0
jpayne@69 194 * means first one). */
jpayne@69 195 struct TkText *textPtr; /* May be NULL, but otherwise the text widget
jpayne@69 196 * with which this index is associated. If not
jpayne@69 197 * NULL, then we have a refCount on the
jpayne@69 198 * widget. */
jpayne@69 199 } TkTextIndex;
jpayne@69 200
jpayne@69 201 /*
jpayne@69 202 * Types for procedure pointers stored in TkTextDispChunk strutures:
jpayne@69 203 */
jpayne@69 204
jpayne@69 205 typedef struct TkTextDispChunk TkTextDispChunk;
jpayne@69 206
jpayne@69 207 typedef void Tk_ChunkDisplayProc(struct TkText *textPtr,
jpayne@69 208 TkTextDispChunk *chunkPtr, int x, int y,
jpayne@69 209 int height, int baseline, Display *display,
jpayne@69 210 Drawable dst, int screenY);
jpayne@69 211 typedef void Tk_ChunkUndisplayProc(struct TkText *textPtr,
jpayne@69 212 TkTextDispChunk *chunkPtr);
jpayne@69 213 typedef int Tk_ChunkMeasureProc(TkTextDispChunk *chunkPtr, int x);
jpayne@69 214 typedef void Tk_ChunkBboxProc(struct TkText *textPtr,
jpayne@69 215 TkTextDispChunk *chunkPtr, int index, int y,
jpayne@69 216 int lineHeight, int baseline, int *xPtr,
jpayne@69 217 int *yPtr, int *widthPtr, int *heightPtr);
jpayne@69 218
jpayne@69 219 /*
jpayne@69 220 * The structure below represents a chunk of stuff that is displayed together
jpayne@69 221 * on the screen. This structure is allocated and freed by generic display
jpayne@69 222 * code but most of its fields are filled in by segment-type-specific code.
jpayne@69 223 */
jpayne@69 224
jpayne@69 225 struct TkTextDispChunk {
jpayne@69 226 /*
jpayne@69 227 * The fields below are set by the type-independent code before calling
jpayne@69 228 * the segment-type-specific layoutProc. They should not be modified by
jpayne@69 229 * segment-type-specific code.
jpayne@69 230 */
jpayne@69 231
jpayne@69 232 int x; /* X position of chunk, in pixels. This
jpayne@69 233 * position is measured from the left edge of
jpayne@69 234 * the logical line, not from the left edge of
jpayne@69 235 * the window (i.e. it doesn't change under
jpayne@69 236 * horizontal scrolling). */
jpayne@69 237 struct TkTextDispChunk *nextPtr;
jpayne@69 238 /* Next chunk in the display line or NULL for
jpayne@69 239 * the end of the list. */
jpayne@69 240 struct TextStyle *stylePtr; /* Display information, known only to
jpayne@69 241 * tkTextDisp.c. */
jpayne@69 242
jpayne@69 243 /*
jpayne@69 244 * The fields below are set by the layoutProc that creates the chunk.
jpayne@69 245 */
jpayne@69 246
jpayne@69 247 Tk_ChunkDisplayProc *displayProc;
jpayne@69 248 /* Procedure to invoke to draw this chunk on
jpayne@69 249 * the display or an off-screen pixmap. */
jpayne@69 250 Tk_ChunkUndisplayProc *undisplayProc;
jpayne@69 251 /* Procedure to invoke when segment ceases to
jpayne@69 252 * be displayed on screen anymore. */
jpayne@69 253 Tk_ChunkMeasureProc *measureProc;
jpayne@69 254 /* Procedure to find character under a given
jpayne@69 255 * x-location. */
jpayne@69 256 Tk_ChunkBboxProc *bboxProc; /* Procedure to find bounding box of character
jpayne@69 257 * in chunk. */
jpayne@69 258 int numBytes; /* Number of bytes that will be displayed in
jpayne@69 259 * the chunk. */
jpayne@69 260 int minAscent; /* Minimum space above the baseline needed by
jpayne@69 261 * this chunk. */
jpayne@69 262 int minDescent; /* Minimum space below the baseline needed by
jpayne@69 263 * this chunk. */
jpayne@69 264 int minHeight; /* Minimum total line height needed by this
jpayne@69 265 * chunk. */
jpayne@69 266 int width; /* Width of this chunk, in pixels. Initially
jpayne@69 267 * set by chunk-specific code, but may be
jpayne@69 268 * increased to include tab or extra space at
jpayne@69 269 * end of line. */
jpayne@69 270 int breakIndex; /* Index within chunk of last acceptable
jpayne@69 271 * position for a line (break just before this
jpayne@69 272 * byte index). <= 0 means don't break during
jpayne@69 273 * or immediately after this chunk. */
jpayne@69 274 ClientData clientData; /* Additional information for use of
jpayne@69 275 * displayProc and undisplayProc. */
jpayne@69 276 };
jpayne@69 277
jpayne@69 278 /*
jpayne@69 279 * One data structure of the following type is used for each tag in a text
jpayne@69 280 * widget. These structures are kept in sharedTextPtr->tagTable and referred
jpayne@69 281 * to in other structures.
jpayne@69 282 */
jpayne@69 283
jpayne@69 284 typedef enum {
jpayne@69 285 TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, TEXT_WRAPMODE_WORD,
jpayne@69 286 TEXT_WRAPMODE_NULL
jpayne@69 287 } TkWrapMode;
jpayne@69 288
jpayne@69 289 typedef struct TkTextTag {
jpayne@69 290 const char *name; /* Name of this tag. This field is actually a
jpayne@69 291 * pointer to the key from the entry in
jpayne@69 292 * sharedTextPtr->tagTable, so it needn't be
jpayne@69 293 * freed explicitly. For 'sel' tags this is
jpayne@69 294 * just a static string, so again need not be
jpayne@69 295 * freed. */
jpayne@69 296 const struct TkText *textPtr;
jpayne@69 297 /* If non-NULL, then this tag only applies to
jpayne@69 298 * the given text widget (when there are peer
jpayne@69 299 * widgets). */
jpayne@69 300 int priority; /* Priority of this tag within widget. 0 means
jpayne@69 301 * lowest priority. Exactly one tag has each
jpayne@69 302 * integer value between 0 and numTags-1. */
jpayne@69 303 struct Node *tagRootPtr; /* Pointer into the B-Tree at the lowest node
jpayne@69 304 * that completely dominates the ranges of
jpayne@69 305 * text occupied by the tag. At this node
jpayne@69 306 * there is no information about the tag. One
jpayne@69 307 * or more children of the node do contain
jpayne@69 308 * information about the tag. */
jpayne@69 309 int toggleCount; /* Total number of tag toggles. */
jpayne@69 310
jpayne@69 311 /*
jpayne@69 312 * Information for displaying text with this tag. The information belows
jpayne@69 313 * acts as an override on information specified by lower-priority tags.
jpayne@69 314 * If no value is specified, then the next-lower-priority tag on the text
jpayne@69 315 * determins the value. The text widget itself provides defaults if no tag
jpayne@69 316 * specifies an override.
jpayne@69 317 */
jpayne@69 318
jpayne@69 319 Tk_3DBorder border; /* Used for drawing background. NULL means no
jpayne@69 320 * value specified here. */
jpayne@69 321 int borderWidth; /* Width of 3-D border for background. */
jpayne@69 322 Tcl_Obj *borderWidthPtr; /* Width of 3-D border for background. */
jpayne@69 323 char *reliefString; /* -relief option string (malloc-ed). NULL
jpayne@69 324 * means option not specified. */
jpayne@69 325 int relief; /* 3-D relief for background. */
jpayne@69 326 Pixmap bgStipple; /* Stipple bitmap for background. None means
jpayne@69 327 * no value specified here. */
jpayne@69 328 XColor *fgColor; /* Foreground color for text. NULL means no
jpayne@69 329 * value specified here. */
jpayne@69 330 Tk_Font tkfont; /* Font for displaying text. NULL means no
jpayne@69 331 * value specified here. */
jpayne@69 332 Pixmap fgStipple; /* Stipple bitmap for text and other
jpayne@69 333 * foreground stuff. None means no value
jpayne@69 334 * specified here.*/
jpayne@69 335 char *justifyString; /* -justify option string (malloc-ed). NULL
jpayne@69 336 * means option not specified. */
jpayne@69 337 Tk_Justify justify; /* How to justify text: TK_JUSTIFY_LEFT,
jpayne@69 338 * TK_JUSTIFY_RIGHT, or TK_JUSTIFY_CENTER.
jpayne@69 339 * Only valid if justifyString is non-NULL. */
jpayne@69 340 char *lMargin1String; /* -lmargin1 option string (malloc-ed). NULL
jpayne@69 341 * means option not specified. */
jpayne@69 342 int lMargin1; /* Left margin for first display line of each
jpayne@69 343 * text line, in pixels. Only valid if
jpayne@69 344 * lMargin1String is non-NULL. */
jpayne@69 345 char *lMargin2String; /* -lmargin2 option string (malloc-ed). NULL
jpayne@69 346 * means option not specified. */
jpayne@69 347 int lMargin2; /* Left margin for second and later display
jpayne@69 348 * lines of each text line, in pixels. Only
jpayne@69 349 * valid if lMargin2String is non-NULL. */
jpayne@69 350 Tk_3DBorder lMarginColor; /* Used for drawing background in left margins.
jpayne@69 351 * This is used for both lmargin1 and lmargin2.
jpayne@69 352 * NULL means no value specified here. */
jpayne@69 353 char *offsetString; /* -offset option string (malloc-ed). NULL
jpayne@69 354 * means option not specified. */
jpayne@69 355 int offset; /* Vertical offset of text's baseline from
jpayne@69 356 * baseline of line. Used for superscripts and
jpayne@69 357 * subscripts. Only valid if offsetString is
jpayne@69 358 * non-NULL. */
jpayne@69 359 char *overstrikeString; /* -overstrike option string (malloc-ed). NULL
jpayne@69 360 * means option not specified. */
jpayne@69 361 int overstrike; /* Non-zero means draw horizontal line through
jpayne@69 362 * middle of text. Only valid if
jpayne@69 363 * overstrikeString is non-NULL. */
jpayne@69 364 XColor *overstrikeColor; /* Color for the overstrike. NULL means same
jpayne@69 365 * color as foreground. */
jpayne@69 366 char *rMarginString; /* -rmargin option string (malloc-ed). NULL
jpayne@69 367 * means option not specified. */
jpayne@69 368 int rMargin; /* Right margin for text, in pixels. Only
jpayne@69 369 * valid if rMarginString is non-NULL. */
jpayne@69 370 Tk_3DBorder rMarginColor; /* Used for drawing background in right margin.
jpayne@69 371 * NULL means no value specified here. */
jpayne@69 372 Tk_3DBorder selBorder; /* Used for drawing background for selected text.
jpayne@69 373 * NULL means no value specified here. */
jpayne@69 374 XColor *selFgColor; /* Foreground color for selected text. NULL means
jpayne@69 375 * no value specified here. */
jpayne@69 376 char *spacing1String; /* -spacing1 option string (malloc-ed). NULL
jpayne@69 377 * means option not specified. */
jpayne@69 378 int spacing1; /* Extra spacing above first display line for
jpayne@69 379 * text line. Only valid if spacing1String is
jpayne@69 380 * non-NULL. */
jpayne@69 381 char *spacing2String; /* -spacing2 option string (malloc-ed). NULL
jpayne@69 382 * means option not specified. */
jpayne@69 383 int spacing2; /* Extra spacing between display lines for the
jpayne@69 384 * same text line. Only valid if
jpayne@69 385 * spacing2String is non-NULL. */
jpayne@69 386 char *spacing3String; /* -spacing2 option string (malloc-ed). NULL
jpayne@69 387 * means option not specified. */
jpayne@69 388 int spacing3; /* Extra spacing below last display line for
jpayne@69 389 * text line. Only valid if spacing3String is
jpayne@69 390 * non-NULL. */
jpayne@69 391 Tcl_Obj *tabStringPtr; /* -tabs option string. NULL means option not
jpayne@69 392 * specified. */
jpayne@69 393 struct TkTextTabArray *tabArrayPtr;
jpayne@69 394 /* Info about tabs for tag (malloc-ed) or
jpayne@69 395 * NULL. Corresponds to tabString. */
jpayne@69 396 int tabStyle; /* One of TABULAR or WORDPROCESSOR or NONE (if
jpayne@69 397 * not specified). */
jpayne@69 398 char *underlineString; /* -underline option string (malloc-ed). NULL
jpayne@69 399 * means option not specified. */
jpayne@69 400 int underline; /* Non-zero means draw underline underneath
jpayne@69 401 * text. Only valid if underlineString is
jpayne@69 402 * non-NULL. */
jpayne@69 403 XColor *underlineColor; /* Color for the underline. NULL means same
jpayne@69 404 * color as foreground. */
jpayne@69 405 TkWrapMode wrapMode; /* How to handle wrap-around for this tag.
jpayne@69 406 * Must be TEXT_WRAPMODE_CHAR,
jpayne@69 407 * TEXT_WRAPMODE_NONE, TEXT_WRAPMODE_WORD, or
jpayne@69 408 * TEXT_WRAPMODE_NULL to use wrapmode for
jpayne@69 409 * whole widget. */
jpayne@69 410 char *elideString; /* -elide option string (malloc-ed). NULL
jpayne@69 411 * means option not specified. */
jpayne@69 412 int elide; /* Non-zero means that data under this tag
jpayne@69 413 * should not be displayed. */
jpayne@69 414 int affectsDisplay; /* Non-zero means that this tag affects the
jpayne@69 415 * way information is displayed on the screen
jpayne@69 416 * (so need to redisplay if tag changes). */
jpayne@69 417 Tk_OptionTable optionTable; /* Token representing the configuration
jpayne@69 418 * specifications. */
jpayne@69 419 int affectsDisplayGeometry; /* Non-zero means that this tag affects the
jpayne@69 420 * size with which information is displayed on
jpayne@69 421 * the screen (so need to recalculate line
jpayne@69 422 * dimensions if tag changes). */
jpayne@69 423 } TkTextTag;
jpayne@69 424
jpayne@69 425 #define TK_TAG_AFFECTS_DISPLAY 0x1
jpayne@69 426 #define TK_TAG_UNDERLINE 0x2
jpayne@69 427 #define TK_TAG_JUSTIFY 0x4
jpayne@69 428 #define TK_TAG_OFFSET 0x10
jpayne@69 429
jpayne@69 430 /*
jpayne@69 431 * The data structure below is used for searching a B-tree for transitions on
jpayne@69 432 * a single tag (or for all tag transitions). No code outside of tkTextBTree.c
jpayne@69 433 * should ever modify any of the fields in these structures, but it's OK to
jpayne@69 434 * use them for read-only information.
jpayne@69 435 */
jpayne@69 436
jpayne@69 437 typedef struct TkTextSearch {
jpayne@69 438 TkTextIndex curIndex; /* Position of last tag transition returned by
jpayne@69 439 * TkBTreeNextTag, or index of start of
jpayne@69 440 * segment containing starting position for
jpayne@69 441 * search if TkBTreeNextTag hasn't been called
jpayne@69 442 * yet, or same as stopIndex if search is
jpayne@69 443 * over. */
jpayne@69 444 TkTextSegment *segPtr; /* Actual tag segment returned by last call to
jpayne@69 445 * TkBTreeNextTag, or NULL if TkBTreeNextTag
jpayne@69 446 * hasn't returned anything yet. */
jpayne@69 447 TkTextSegment *nextPtr; /* Where to resume search in next call to
jpayne@69 448 * TkBTreeNextTag. */
jpayne@69 449 TkTextSegment *lastPtr; /* Stop search before just before considering
jpayne@69 450 * this segment. */
jpayne@69 451 TkTextTag *tagPtr; /* Tag to search for (or tag found, if allTags
jpayne@69 452 * is non-zero). */
jpayne@69 453 int linesLeft; /* Lines left to search (including curIndex
jpayne@69 454 * and stopIndex). When this becomes <= 0 the
jpayne@69 455 * search is over. */
jpayne@69 456 int allTags; /* Non-zero means ignore tag check: search for
jpayne@69 457 * transitions on all tags. */
jpayne@69 458 } TkTextSearch;
jpayne@69 459
jpayne@69 460 /*
jpayne@69 461 * The following data structure describes a single tab stop. It must be kept
jpayne@69 462 * in sync with the 'tabOptionStrings' array in the function 'TkTextGetTabs'
jpayne@69 463 */
jpayne@69 464
jpayne@69 465 typedef enum {LEFT, RIGHT, CENTER, NUMERIC} TkTextTabAlign;
jpayne@69 466
jpayne@69 467 /*
jpayne@69 468 * The following are the supported styles of tabbing, used for the -tabstyle
jpayne@69 469 * option of the text widget. The last element is only used for tag options.
jpayne@69 470 */
jpayne@69 471
jpayne@69 472 typedef enum {
jpayne@69 473 TK_TEXT_TABSTYLE_TABULAR,
jpayne@69 474 TK_TEXT_TABSTYLE_WORDPROCESSOR,
jpayne@69 475 TK_TEXT_TABSTYLE_NONE
jpayne@69 476 } TkTextTabStyle;
jpayne@69 477
jpayne@69 478 typedef struct TkTextTab {
jpayne@69 479 int location; /* Offset in pixels of this tab stop from the
jpayne@69 480 * left margin (lmargin2) of the text. */
jpayne@69 481 TkTextTabAlign alignment; /* Where the tab stop appears relative to the
jpayne@69 482 * text. */
jpayne@69 483 } TkTextTab;
jpayne@69 484
jpayne@69 485 typedef struct TkTextTabArray {
jpayne@69 486 int numTabs; /* Number of tab stops. */
jpayne@69 487 double lastTab; /* The accurate fractional pixel position of
jpayne@69 488 * the last tab. */
jpayne@69 489 double tabIncrement; /* The accurate fractional pixel increment
jpayne@69 490 * between interpolated tabs we have to create
jpayne@69 491 * when we exceed numTabs. */
jpayne@69 492 TkTextTab tabs[TKFLEXARRAY];/* Array of tabs. The actual size will be
jpayne@69 493 * numTabs. THIS FIELD MUST BE THE LAST IN THE
jpayne@69 494 * STRUCTURE. */
jpayne@69 495 } TkTextTabArray;
jpayne@69 496
jpayne@69 497 /*
jpayne@69 498 * Enumeration defining the edit modes of the widget.
jpayne@69 499 */
jpayne@69 500
jpayne@69 501 typedef enum {
jpayne@69 502 TK_TEXT_EDIT_INSERT, /* insert mode */
jpayne@69 503 TK_TEXT_EDIT_DELETE, /* delete mode */
jpayne@69 504 TK_TEXT_EDIT_REPLACE, /* replace mode */
jpayne@69 505 TK_TEXT_EDIT_OTHER /* none of the above */
jpayne@69 506 } TkTextEditMode;
jpayne@69 507
jpayne@69 508 /*
jpayne@69 509 * Enumeration defining the ways in which a text widget may be modified (for
jpayne@69 510 * undo/redo handling).
jpayne@69 511 */
jpayne@69 512
jpayne@69 513 typedef enum {
jpayne@69 514 TK_TEXT_DIRTY_NORMAL, /* Normal behavior. */
jpayne@69 515 TK_TEXT_DIRTY_UNDO, /* Reverting a compound action. */
jpayne@69 516 TK_TEXT_DIRTY_REDO, /* Reapplying a compound action. */
jpayne@69 517 TK_TEXT_DIRTY_FIXED /* Forced to be dirty; can't be undone/redone
jpayne@69 518 * by normal activity. */
jpayne@69 519 } TkTextDirtyMode;
jpayne@69 520
jpayne@69 521 /*
jpayne@69 522 * The following enum is used to define a type for the -state option of the
jpayne@69 523 * Text widget.
jpayne@69 524 */
jpayne@69 525
jpayne@69 526 typedef enum {
jpayne@69 527 TK_TEXT_STATE_DISABLED, TK_TEXT_STATE_NORMAL
jpayne@69 528 } TkTextState;
jpayne@69 529
jpayne@69 530 /*
jpayne@69 531 * A data structure of the following type is shared between each text widget
jpayne@69 532 * that are peers.
jpayne@69 533 */
jpayne@69 534
jpayne@69 535 typedef struct TkSharedText {
jpayne@69 536 int refCount; /* Reference count this shared object. */
jpayne@69 537 TkTextBTree tree; /* B-tree representation of text and tags for
jpayne@69 538 * widget. */
jpayne@69 539 Tcl_HashTable tagTable; /* Hash table that maps from tag names to
jpayne@69 540 * pointers to TkTextTag structures. The "sel"
jpayne@69 541 * tag does not feature in this table, since
jpayne@69 542 * there's one of those for each text peer. */
jpayne@69 543 int numTags; /* Number of tags currently defined for
jpayne@69 544 * widget; needed to keep track of
jpayne@69 545 * priorities. */
jpayne@69 546 Tcl_HashTable markTable; /* Hash table that maps from mark names to
jpayne@69 547 * pointers to mark segments. The special
jpayne@69 548 * "insert" and "current" marks are not stored
jpayne@69 549 * in this table, but directly accessed as
jpayne@69 550 * fields of textPtr. */
jpayne@69 551 Tcl_HashTable windowTable; /* Hash table that maps from window names to
jpayne@69 552 * pointers to window segments. If a window
jpayne@69 553 * segment doesn't yet have an associated
jpayne@69 554 * window, there is no entry for it here. */
jpayne@69 555 Tcl_HashTable imageTable; /* Hash table that maps from image names to
jpayne@69 556 * pointers to image segments. If an image
jpayne@69 557 * segment doesn't yet have an associated
jpayne@69 558 * image, there is no entry for it here. */
jpayne@69 559 Tk_BindingTable bindingTable;
jpayne@69 560 /* Table of all bindings currently defined for
jpayne@69 561 * this widget. NULL means that no bindings
jpayne@69 562 * exist, so the table hasn't been created.
jpayne@69 563 * Each "object" used for this table is the
jpayne@69 564 * name of a tag. */
jpayne@69 565 int stateEpoch; /* This is incremented each time the B-tree's
jpayne@69 566 * contents change structurally, or when the
jpayne@69 567 * start/end limits change, and means that any
jpayne@69 568 * cached TkTextIndex objects are no longer
jpayne@69 569 * valid. */
jpayne@69 570
jpayne@69 571 /*
jpayne@69 572 * Information related to the undo/redo functionality.
jpayne@69 573 */
jpayne@69 574
jpayne@69 575 TkUndoRedoStack *undoStack; /* The undo/redo stack. */
jpayne@69 576 int undo; /* Non-zero means the undo/redo behaviour is
jpayne@69 577 * enabled. */
jpayne@69 578 int maxUndo; /* The maximum depth of the undo stack
jpayne@69 579 * expressed as the maximum number of compound
jpayne@69 580 * statements. */
jpayne@69 581 int autoSeparators; /* Non-zero means the separators will be
jpayne@69 582 * inserted automatically. */
jpayne@69 583 int isDirty; /* Flag indicating the 'dirtyness' of the
jpayne@69 584 * text widget. If the flag is not zero,
jpayne@69 585 * unsaved modifications have been applied to
jpayne@69 586 * the text widget. */
jpayne@69 587 TkTextDirtyMode dirtyMode; /* The nature of the dirtyness characterized
jpayne@69 588 * by the isDirty flag. */
jpayne@69 589 TkTextEditMode lastEditMode;/* Keeps track of what the last edit mode
jpayne@69 590 * was. */
jpayne@69 591
jpayne@69 592 /*
jpayne@69 593 * Keep track of all the peers
jpayne@69 594 */
jpayne@69 595
jpayne@69 596 struct TkText *peers;
jpayne@69 597 } TkSharedText;
jpayne@69 598
jpayne@69 599 /*
jpayne@69 600 * The following enum is used to define a type for the -insertunfocussed
jpayne@69 601 * option of the Text widget.
jpayne@69 602 */
jpayne@69 603
jpayne@69 604 typedef enum {
jpayne@69 605 TK_TEXT_INSERT_NOFOCUS_HOLLOW,
jpayne@69 606 TK_TEXT_INSERT_NOFOCUS_NONE,
jpayne@69 607 TK_TEXT_INSERT_NOFOCUS_SOLID
jpayne@69 608 } TkTextInsertUnfocussed;
jpayne@69 609
jpayne@69 610 /*
jpayne@69 611 * A data structure of the following type is kept for each text widget that
jpayne@69 612 * currently exists for this process:
jpayne@69 613 */
jpayne@69 614
jpayne@69 615 typedef struct TkText {
jpayne@69 616 /*
jpayne@69 617 * Information related to and accessed by widget peers and the
jpayne@69 618 * TkSharedText handling routines.
jpayne@69 619 */
jpayne@69 620
jpayne@69 621 TkSharedText *sharedTextPtr;/* Shared section of all peers. */
jpayne@69 622 struct TkText *next; /* Next in list of linked peers. */
jpayne@69 623 TkTextLine *start; /* First B-tree line to show, or NULL to start
jpayne@69 624 * at the beginning. */
jpayne@69 625 TkTextLine *end; /* Last B-tree line to show, or NULL for up to
jpayne@69 626 * the end. */
jpayne@69 627 int pixelReference; /* Counter into the current tree reference
jpayne@69 628 * index corresponding to this widget. */
jpayne@69 629 int abortSelections; /* Set to 1 whenever the text is modified in a
jpayne@69 630 * way that interferes with selection
jpayne@69 631 * retrieval: used to abort incremental
jpayne@69 632 * selection retrievals. */
jpayne@69 633
jpayne@69 634 /*
jpayne@69 635 * Standard Tk widget information and text-widget specific items
jpayne@69 636 */
jpayne@69 637
jpayne@69 638 Tk_Window tkwin; /* Window that embodies the text. NULL means
jpayne@69 639 * that the window has been destroyed but the
jpayne@69 640 * data structures haven't yet been cleaned
jpayne@69 641 * up.*/
jpayne@69 642 Display *display; /* Display for widget. Needed, among other
jpayne@69 643 * things, to allow resources to be freed even
jpayne@69 644 * after tkwin has gone away. */
jpayne@69 645 Tcl_Interp *interp; /* Interpreter associated with widget. Used to
jpayne@69 646 * delete widget command. */
jpayne@69 647 Tcl_Command widgetCmd; /* Token for text's widget command. */
jpayne@69 648 int state; /* Either STATE_NORMAL or STATE_DISABLED. A
jpayne@69 649 * text widget is read-only when disabled. */
jpayne@69 650
jpayne@69 651 /*
jpayne@69 652 * Default information for displaying (may be overridden by tags applied
jpayne@69 653 * to ranges of characters).
jpayne@69 654 */
jpayne@69 655
jpayne@69 656 Tk_3DBorder border; /* Structure used to draw 3-D border and
jpayne@69 657 * default background. */
jpayne@69 658 int borderWidth; /* Width of 3-D border to draw around entire
jpayne@69 659 * widget. */
jpayne@69 660 int padX, padY; /* Padding between text and window border. */
jpayne@69 661 int relief; /* 3-d effect for border around entire widget:
jpayne@69 662 * TK_RELIEF_RAISED etc. */
jpayne@69 663 int highlightWidth; /* Width in pixels of highlight to draw around
jpayne@69 664 * widget when it has the focus. <= 0 means
jpayne@69 665 * don't draw a highlight. */
jpayne@69 666 XColor *highlightBgColorPtr;
jpayne@69 667 /* Color for drawing traversal highlight area
jpayne@69 668 * when highlight is off. */
jpayne@69 669 XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
jpayne@69 670 Tk_Cursor cursor; /* Current cursor for window, or NULL. */
jpayne@69 671 XColor *fgColor; /* Default foreground color for text. */
jpayne@69 672 Tk_Font tkfont; /* Default font for displaying text. */
jpayne@69 673 int charWidth; /* Width of average character in default
jpayne@69 674 * font. */
jpayne@69 675 int charHeight; /* Height of average character in default
jpayne@69 676 * font, including line spacing. */
jpayne@69 677 int spacing1; /* Default extra spacing above first display
jpayne@69 678 * line for each text line. */
jpayne@69 679 int spacing2; /* Default extra spacing between display lines
jpayne@69 680 * for the same text line. */
jpayne@69 681 int spacing3; /* Default extra spacing below last display
jpayne@69 682 * line for each text line. */
jpayne@69 683 Tcl_Obj *tabOptionPtr; /* Value of -tabs option string. */
jpayne@69 684 TkTextTabArray *tabArrayPtr;
jpayne@69 685 /* Information about tab stops (malloc'ed).
jpayne@69 686 * NULL means perform default tabbing
jpayne@69 687 * behavior. */
jpayne@69 688 int tabStyle; /* One of TABULAR or WORDPROCESSOR. */
jpayne@69 689
jpayne@69 690 /*
jpayne@69 691 * Additional information used for displaying:
jpayne@69 692 */
jpayne@69 693
jpayne@69 694 TkWrapMode wrapMode; /* How to handle wrap-around. Must be
jpayne@69 695 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
jpayne@69 696 * TEXT_WRAPMODE_WORD. */
jpayne@69 697 int width, height; /* Desired dimensions for window, measured in
jpayne@69 698 * characters. */
jpayne@69 699 int setGrid; /* Non-zero means pass gridding information to
jpayne@69 700 * window manager. */
jpayne@69 701 int prevWidth, prevHeight; /* Last known dimensions of window; used to
jpayne@69 702 * detect changes in size. */
jpayne@69 703 TkTextIndex topIndex; /* Identifies first character in top display
jpayne@69 704 * line of window. */
jpayne@69 705 struct TextDInfo *dInfoPtr; /* Information maintained by tkTextDisp.c. */
jpayne@69 706
jpayne@69 707 /*
jpayne@69 708 * Information related to selection.
jpayne@69 709 */
jpayne@69 710
jpayne@69 711 TkTextTag *selTagPtr; /* Pointer to "sel" tag. Used to tell when a
jpayne@69 712 * new selection has been made. */
jpayne@69 713 Tk_3DBorder selBorder; /* Border and background for selected
jpayne@69 714 * characters. This is a copy of information
jpayne@69 715 * in *selTagPtr, so it shouldn't be
jpayne@69 716 * explicitly freed. */
jpayne@69 717 Tk_3DBorder inactiveSelBorder;
jpayne@69 718 /* Border and background for selected
jpayne@69 719 * characters when they don't have the
jpayne@69 720 * focus. */
jpayne@69 721 int selBorderWidth; /* Width of border around selection. */
jpayne@69 722 Tcl_Obj *selBorderWidthPtr; /* Width of border around selection. */
jpayne@69 723 XColor *selFgColorPtr; /* Foreground color for selected text. This is
jpayne@69 724 * a copy of information in *selTagPtr, so it
jpayne@69 725 * shouldn't be explicitly freed. */
jpayne@69 726 int exportSelection; /* Non-zero means tie "sel" tag to X
jpayne@69 727 * selection. */
jpayne@69 728 TkTextIndex selIndex; /* Used during multi-pass selection
jpayne@69 729 * retrievals. This index identifies the next
jpayne@69 730 * character to be returned from the
jpayne@69 731 * selection. */
jpayne@69 732
jpayne@69 733 /*
jpayne@69 734 * Information related to insertion cursor:
jpayne@69 735 */
jpayne@69 736
jpayne@69 737 TkTextSegment *insertMarkPtr;
jpayne@69 738 /* Points to segment for "insert" mark. */
jpayne@69 739 Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion
jpayne@69 740 * cursor. */
jpayne@69 741 int insertWidth; /* Total width of insert cursor. */
jpayne@69 742 int insertBorderWidth; /* Width of 3-D border around insert cursor */
jpayne@69 743 TkTextInsertUnfocussed insertUnfocussed;
jpayne@69 744 /* How to display the insert cursor when the
jpayne@69 745 * text widget does not have the focus. */
jpayne@69 746 int insertOnTime; /* Number of milliseconds cursor should spend
jpayne@69 747 * in "on" state for each blink. */
jpayne@69 748 int insertOffTime; /* Number of milliseconds cursor should spend
jpayne@69 749 * in "off" state for each blink. */
jpayne@69 750 Tcl_TimerToken insertBlinkHandler;
jpayne@69 751 /* Timer handler used to blink cursor on and
jpayne@69 752 * off. */
jpayne@69 753
jpayne@69 754 /*
jpayne@69 755 * Information used for event bindings associated with tags:
jpayne@69 756 */
jpayne@69 757
jpayne@69 758 TkTextSegment *currentMarkPtr;
jpayne@69 759 /* Pointer to segment for "current" mark, or
jpayne@69 760 * NULL if none. */
jpayne@69 761 XEvent pickEvent; /* The event from which the current character
jpayne@69 762 * was chosen. Must be saved so that we can
jpayne@69 763 * repick after modifications to the text. */
jpayne@69 764 int numCurTags; /* Number of tags associated with character at
jpayne@69 765 * current mark. */
jpayne@69 766 TkTextTag **curTagArrayPtr; /* Pointer to array of tags for current mark,
jpayne@69 767 * or NULL if none. */
jpayne@69 768
jpayne@69 769 /*
jpayne@69 770 * Miscellaneous additional information:
jpayne@69 771 */
jpayne@69 772
jpayne@69 773 char *takeFocus; /* Value of -takeFocus option; not used in the
jpayne@69 774 * C code, but used by keyboard traversal
jpayne@69 775 * scripts. Malloc'ed, but may be NULL. */
jpayne@69 776 char *xScrollCmd; /* Prefix of command to issue to update
jpayne@69 777 * horizontal scrollbar when view changes. */
jpayne@69 778 char *yScrollCmd; /* Prefix of command to issue to update
jpayne@69 779 * vertical scrollbar when view changes. */
jpayne@69 780 int flags; /* Miscellaneous flags; see below for
jpayne@69 781 * definitions. */
jpayne@69 782 Tk_OptionTable optionTable; /* Token representing the configuration
jpayne@69 783 * specifications. */
jpayne@69 784 int refCount; /* Number of cached TkTextIndex objects
jpayne@69 785 * refering to us. */
jpayne@69 786 int insertCursorType; /* 0 = standard insertion cursor, 1 = block
jpayne@69 787 * cursor. */
jpayne@69 788
jpayne@69 789 /*
jpayne@69 790 * Copies of information from the shared section relating to the undo/redo
jpayne@69 791 * functonality
jpayne@69 792 */
jpayne@69 793
jpayne@69 794 int undo; /* Non-zero means the undo/redo behaviour is
jpayne@69 795 * enabled. */
jpayne@69 796 int maxUndo; /* The maximum depth of the undo stack
jpayne@69 797 * expressed as the maximum number of compound
jpayne@69 798 * statements. */
jpayne@69 799 int autoSeparators; /* Non-zero means the separators will be
jpayne@69 800 * inserted automatically. */
jpayne@69 801 Tcl_Obj *afterSyncCmd; /* Command to be executed when lines are up to
jpayne@69 802 * date */
jpayne@69 803 } TkText;
jpayne@69 804
jpayne@69 805 /*
jpayne@69 806 * Flag values for TkText records:
jpayne@69 807 *
jpayne@69 808 * GOT_SELECTION: Non-zero means we've already claimed the
jpayne@69 809 * selection.
jpayne@69 810 * INSERT_ON: Non-zero means insertion cursor should be
jpayne@69 811 * displayed on screen.
jpayne@69 812 * GOT_FOCUS: Non-zero means this window has the input
jpayne@69 813 * focus.
jpayne@69 814 * BUTTON_DOWN: 1 means that a mouse button is currently down;
jpayne@69 815 * this is used to implement grabs for the
jpayne@69 816 * duration of button presses.
jpayne@69 817 * UPDATE_SCROLLBARS: Non-zero means scrollbar(s) should be updated
jpayne@69 818 * during next redisplay operation.
jpayne@69 819 * NEED_REPICK This appears unused and should probably be
jpayne@69 820 * ignored.
jpayne@69 821 * OPTIONS_FREED The widget's options have been freed.
jpayne@69 822 * DESTROYED The widget is going away.
jpayne@69 823 */
jpayne@69 824
jpayne@69 825 #define GOT_SELECTION 1
jpayne@69 826 #define INSERT_ON 2
jpayne@69 827 #define GOT_FOCUS 4
jpayne@69 828 #define BUTTON_DOWN 8
jpayne@69 829 #define UPDATE_SCROLLBARS 0x10
jpayne@69 830 #define NEED_REPICK 0x20
jpayne@69 831 #define OPTIONS_FREED 0x40
jpayne@69 832 #define DESTROYED 0x80
jpayne@69 833
jpayne@69 834 /*
jpayne@69 835 * Records of the following type define segment types in terms of a collection
jpayne@69 836 * of procedures that may be called to manipulate segments of that type.
jpayne@69 837 */
jpayne@69 838
jpayne@69 839 typedef TkTextSegment * Tk_SegSplitProc(struct TkTextSegment *segPtr,
jpayne@69 840 int index);
jpayne@69 841 typedef int Tk_SegDeleteProc(struct TkTextSegment *segPtr,
jpayne@69 842 TkTextLine *linePtr, int treeGone);
jpayne@69 843 typedef TkTextSegment * Tk_SegCleanupProc(struct TkTextSegment *segPtr,
jpayne@69 844 TkTextLine *linePtr);
jpayne@69 845 typedef void Tk_SegLineChangeProc(struct TkTextSegment *segPtr,
jpayne@69 846 TkTextLine *linePtr);
jpayne@69 847 typedef int Tk_SegLayoutProc(struct TkText *textPtr,
jpayne@69 848 struct TkTextIndex *indexPtr,
jpayne@69 849 TkTextSegment *segPtr, int offset, int maxX,
jpayne@69 850 int maxChars, int noCharsYet, TkWrapMode wrapMode,
jpayne@69 851 struct TkTextDispChunk *chunkPtr);
jpayne@69 852 typedef void Tk_SegCheckProc(TkTextSegment *segPtr,
jpayne@69 853 TkTextLine *linePtr);
jpayne@69 854
jpayne@69 855 typedef struct Tk_SegType {
jpayne@69 856 const char *name; /* Name of this kind of segment. */
jpayne@69 857 int leftGravity; /* If a segment has zero size (e.g. a mark or
jpayne@69 858 * tag toggle), does it attach to character to
jpayne@69 859 * its left or right? 1 means left, 0 means
jpayne@69 860 * right. */
jpayne@69 861 Tk_SegSplitProc *splitProc; /* Procedure to split large segment into two
jpayne@69 862 * smaller ones. */
jpayne@69 863 Tk_SegDeleteProc *deleteProc;
jpayne@69 864 /* Procedure to call to delete segment. */
jpayne@69 865 Tk_SegCleanupProc *cleanupProc;
jpayne@69 866 /* After any change to a line, this procedure
jpayne@69 867 * is invoked for all segments left in the
jpayne@69 868 * line to perform any cleanup they wish
jpayne@69 869 * (e.g. joining neighboring segments). */
jpayne@69 870 Tk_SegLineChangeProc *lineChangeProc;
jpayne@69 871 /* Invoked when a segment is about to be moved
jpayne@69 872 * from its current line to an earlier line
jpayne@69 873 * because of a deletion. The linePtr is that
jpayne@69 874 * for the segment's old line. CleanupProc
jpayne@69 875 * will be invoked after the deletion is
jpayne@69 876 * finished. */
jpayne@69 877 Tk_SegLayoutProc *layoutProc;
jpayne@69 878 /* Returns size information when figuring out
jpayne@69 879 * what to display in window. */
jpayne@69 880 Tk_SegCheckProc *checkProc; /* Called during consistency checks to check
jpayne@69 881 * internal consistency of segment. */
jpayne@69 882 } Tk_SegType;
jpayne@69 883
jpayne@69 884 /*
jpayne@69 885 * The following type and items describe different flags for text widget items
jpayne@69 886 * to count. They are used in both tkText.c and tkTextIndex.c, in
jpayne@69 887 * 'CountIndices', 'TkTextIndexBackChars', 'TkTextIndexForwChars', and
jpayne@69 888 * 'TkTextIndexCount'.
jpayne@69 889 */
jpayne@69 890
jpayne@69 891 typedef int TkTextCountType;
jpayne@69 892
jpayne@69 893 #define COUNT_CHARS 0
jpayne@69 894 #define COUNT_INDICES 1
jpayne@69 895 #define COUNT_DISPLAY 2
jpayne@69 896 #define COUNT_DISPLAY_CHARS (COUNT_CHARS | COUNT_DISPLAY)
jpayne@69 897 #define COUNT_DISPLAY_INDICES (COUNT_INDICES | COUNT_DISPLAY)
jpayne@69 898
jpayne@69 899 /*
jpayne@69 900 * The following structure is used to keep track of elided text taking account
jpayne@69 901 * of different tag priorities, it is need for quick calculations of whether a
jpayne@69 902 * single index is elided, and to start at a given index and maintain a
jpayne@69 903 * correct elide state as we move or count forwards or backwards.
jpayne@69 904 */
jpayne@69 905
jpayne@69 906 #define LOTSA_TAGS 1000
jpayne@69 907 typedef struct TkTextElideInfo {
jpayne@69 908 int numTags; /* Total tags in widget. */
jpayne@69 909 int elide; /* Is the state currently elided. */
jpayne@69 910 int elidePriority; /* Tag priority controlling elide state. */
jpayne@69 911 TkTextSegment *segPtr; /* Segment to look at next. */
jpayne@69 912 int segOffset; /* Offset of segment within line. */
jpayne@69 913 int deftagCnts[LOTSA_TAGS];
jpayne@69 914 TkTextTag *deftagPtrs[LOTSA_TAGS];
jpayne@69 915 int *tagCnts; /* 0 or 1 depending if the tag with that
jpayne@69 916 * priority is on or off. */
jpayne@69 917 TkTextTag **tagPtrs; /* Only filled with a tagPtr if the
jpayne@69 918 * corresponding tagCnt is 1. */
jpayne@69 919 } TkTextElideInfo;
jpayne@69 920
jpayne@69 921 /*
jpayne@69 922 * The constant below is used to specify a line when what is really wanted is
jpayne@69 923 * the entire text. For now, just use a very big number.
jpayne@69 924 */
jpayne@69 925
jpayne@69 926 #define TK_END_OF_TEXT 1000000
jpayne@69 927
jpayne@69 928 /*
jpayne@69 929 * The following definition specifies the maximum number of characters needed
jpayne@69 930 * in a string to hold a position specifier.
jpayne@69 931 */
jpayne@69 932
jpayne@69 933 #define TK_POS_CHARS 30
jpayne@69 934
jpayne@69 935 /*
jpayne@69 936 * Mask used for those options which may impact the pixel height calculations
jpayne@69 937 * of individual lines displayed in the widget.
jpayne@69 938 */
jpayne@69 939
jpayne@69 940 #define TK_TEXT_LINE_GEOMETRY 1
jpayne@69 941
jpayne@69 942 /*
jpayne@69 943 * Mask used for those options which may impact the start and end lines used
jpayne@69 944 * in the widget.
jpayne@69 945 */
jpayne@69 946
jpayne@69 947 #define TK_TEXT_LINE_RANGE 2
jpayne@69 948
jpayne@69 949 /*
jpayne@69 950 * Used as 'action' values in calls to TkTextInvalidateLineMetrics
jpayne@69 951 */
jpayne@69 952
jpayne@69 953 #define TK_TEXT_INVALIDATE_ONLY 0
jpayne@69 954 #define TK_TEXT_INVALIDATE_INSERT 1
jpayne@69 955 #define TK_TEXT_INVALIDATE_DELETE 2
jpayne@69 956
jpayne@69 957 /*
jpayne@69 958 * Used as special 'pickPlace' values in calls to TkTextSetYView. Zero or
jpayne@69 959 * positive values indicate a number of pixels.
jpayne@69 960 */
jpayne@69 961
jpayne@69 962 #define TK_TEXT_PICKPLACE -1
jpayne@69 963 #define TK_TEXT_NOPIXELADJUST -2
jpayne@69 964
jpayne@69 965 /*
jpayne@69 966 * Declarations for variables shared among the text-related files:
jpayne@69 967 */
jpayne@69 968
jpayne@69 969 MODULE_SCOPE int tkBTreeDebug;
jpayne@69 970 MODULE_SCOPE int tkTextDebug;
jpayne@69 971 MODULE_SCOPE const Tk_SegType tkTextCharType;
jpayne@69 972 MODULE_SCOPE const Tk_SegType tkTextLeftMarkType;
jpayne@69 973 MODULE_SCOPE const Tk_SegType tkTextRightMarkType;
jpayne@69 974 MODULE_SCOPE const Tk_SegType tkTextToggleOnType;
jpayne@69 975 MODULE_SCOPE const Tk_SegType tkTextToggleOffType;
jpayne@69 976 MODULE_SCOPE const Tk_SegType tkTextEmbWindowType;
jpayne@69 977 MODULE_SCOPE const Tk_SegType tkTextEmbImageType;
jpayne@69 978
jpayne@69 979 /*
jpayne@69 980 * Convenience macros for use by B-tree clients which want to access pixel
jpayne@69 981 * information on each line. Currently only used by TkTextDisp.c
jpayne@69 982 */
jpayne@69 983
jpayne@69 984 #define TkBTreeLinePixelCount(text, line) \
jpayne@69 985 (line)->pixels[2*(text)->pixelReference]
jpayne@69 986 #define TkBTreeLinePixelEpoch(text, line) \
jpayne@69 987 (line)->pixels[1+2*(text)->pixelReference]
jpayne@69 988
jpayne@69 989 /*
jpayne@69 990 * Declarations for procedures that are used by the text-related files but
jpayne@69 991 * shouldn't be used anywhere else in Tk (or by Tk clients):
jpayne@69 992 */
jpayne@69 993
jpayne@69 994 MODULE_SCOPE int TkBTreeAdjustPixelHeight(const TkText *textPtr,
jpayne@69 995 TkTextLine *linePtr, int newPixelHeight,
jpayne@69 996 int mergedLogicalLines);
jpayne@69 997 MODULE_SCOPE int TkBTreeCharTagged(const TkTextIndex *indexPtr,
jpayne@69 998 TkTextTag *tagPtr);
jpayne@69 999 MODULE_SCOPE void TkBTreeCheck(TkTextBTree tree);
jpayne@69 1000 MODULE_SCOPE TkTextBTree TkBTreeCreate(TkSharedText *sharedTextPtr);
jpayne@69 1001 MODULE_SCOPE void TkBTreeAddClient(TkTextBTree tree, TkText *textPtr,
jpayne@69 1002 int defaultHeight);
jpayne@69 1003 MODULE_SCOPE void TkBTreeClientRangeChanged(TkText *textPtr,
jpayne@69 1004 int defaultHeight);
jpayne@69 1005 MODULE_SCOPE void TkBTreeRemoveClient(TkTextBTree tree,
jpayne@69 1006 TkText *textPtr);
jpayne@69 1007 MODULE_SCOPE void TkBTreeDestroy(TkTextBTree tree);
jpayne@69 1008 MODULE_SCOPE void TkBTreeDeleteIndexRange(TkTextBTree tree,
jpayne@69 1009 TkTextIndex *index1Ptr, TkTextIndex *index2Ptr);
jpayne@69 1010 MODULE_SCOPE int TkBTreeEpoch(TkTextBTree tree);
jpayne@69 1011 MODULE_SCOPE TkTextLine *TkBTreeFindLine(TkTextBTree tree,
jpayne@69 1012 const TkText *textPtr, int line);
jpayne@69 1013 MODULE_SCOPE TkTextLine *TkBTreeFindPixelLine(TkTextBTree tree,
jpayne@69 1014 const TkText *textPtr, int pixels,
jpayne@69 1015 int *pixelOffset);
jpayne@69 1016 MODULE_SCOPE TkTextTag **TkBTreeGetTags(const TkTextIndex *indexPtr,
jpayne@69 1017 const TkText *textPtr, int *numTagsPtr);
jpayne@69 1018 MODULE_SCOPE void TkBTreeInsertChars(TkTextBTree tree,
jpayne@69 1019 TkTextIndex *indexPtr, const char *string);
jpayne@69 1020 MODULE_SCOPE int TkBTreeLinesTo(const TkText *textPtr,
jpayne@69 1021 TkTextLine *linePtr);
jpayne@69 1022 MODULE_SCOPE int TkBTreePixelsTo(const TkText *textPtr,
jpayne@69 1023 TkTextLine *linePtr);
jpayne@69 1024 MODULE_SCOPE void TkBTreeLinkSegment(TkTextSegment *segPtr,
jpayne@69 1025 TkTextIndex *indexPtr);
jpayne@69 1026 MODULE_SCOPE TkTextLine *TkBTreeNextLine(const TkText *textPtr,
jpayne@69 1027 TkTextLine *linePtr);
jpayne@69 1028 MODULE_SCOPE int TkBTreeNextTag(TkTextSearch *searchPtr);
jpayne@69 1029 MODULE_SCOPE int TkBTreeNumPixels(TkTextBTree tree,
jpayne@69 1030 const TkText *textPtr);
jpayne@69 1031 MODULE_SCOPE TkTextLine *TkBTreePreviousLine(TkText *textPtr,
jpayne@69 1032 TkTextLine *linePtr);
jpayne@69 1033 MODULE_SCOPE int TkBTreePrevTag(TkTextSearch *searchPtr);
jpayne@69 1034 MODULE_SCOPE void TkBTreeStartSearch(TkTextIndex *index1Ptr,
jpayne@69 1035 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
jpayne@69 1036 TkTextSearch *searchPtr);
jpayne@69 1037 MODULE_SCOPE void TkBTreeStartSearchBack(TkTextIndex *index1Ptr,
jpayne@69 1038 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
jpayne@69 1039 TkTextSearch *searchPtr);
jpayne@69 1040 MODULE_SCOPE int TkBTreeTag(TkTextIndex *index1Ptr,
jpayne@69 1041 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
jpayne@69 1042 int add);
jpayne@69 1043 MODULE_SCOPE void TkBTreeUnlinkSegment(TkTextSegment *segPtr,
jpayne@69 1044 TkTextLine *linePtr);
jpayne@69 1045 MODULE_SCOPE void TkTextBindProc(ClientData clientData,
jpayne@69 1046 XEvent *eventPtr);
jpayne@69 1047 MODULE_SCOPE void TkTextSelectionEvent(TkText *textPtr);
jpayne@69 1048 MODULE_SCOPE int TkTextIndexBbox(TkText *textPtr,
jpayne@69 1049 const TkTextIndex *indexPtr, int *xPtr, int *yPtr,
jpayne@69 1050 int *widthPtr, int *heightPtr, int *charWidthPtr);
jpayne@69 1051 MODULE_SCOPE int TkTextCharLayoutProc(TkText *textPtr,
jpayne@69 1052 TkTextIndex *indexPtr, TkTextSegment *segPtr,
jpayne@69 1053 int offset, int maxX, int maxChars, int noBreakYet,
jpayne@69 1054 TkWrapMode wrapMode, TkTextDispChunk *chunkPtr);
jpayne@69 1055 MODULE_SCOPE void TkTextCreateDInfo(TkText *textPtr);
jpayne@69 1056 MODULE_SCOPE int TkTextDLineInfo(TkText *textPtr,
jpayne@69 1057 const TkTextIndex *indexPtr, int *xPtr, int *yPtr,
jpayne@69 1058 int *widthPtr, int *heightPtr, int *basePtr);
jpayne@69 1059 MODULE_SCOPE void TkTextEmbWinDisplayProc(TkText *textPtr,
jpayne@69 1060 TkTextDispChunk *chunkPtr, int x, int y,
jpayne@69 1061 int lineHeight, int baseline, Display *display,
jpayne@69 1062 Drawable dst, int screenY);
jpayne@69 1063 MODULE_SCOPE TkTextTag *TkTextCreateTag(TkText *textPtr,
jpayne@69 1064 const char *tagName, int *newTag);
jpayne@69 1065 MODULE_SCOPE void TkTextFreeDInfo(TkText *textPtr);
jpayne@69 1066 MODULE_SCOPE void TkTextDeleteTag(TkText *textPtr, TkTextTag *tagPtr);
jpayne@69 1067 MODULE_SCOPE void TkTextFreeTag(TkText *textPtr, TkTextTag *tagPtr);
jpayne@69 1068 MODULE_SCOPE int TkTextGetObjIndex(Tcl_Interp *interp, TkText *textPtr,
jpayne@69 1069 Tcl_Obj *idxPtr, TkTextIndex *indexPtr);
jpayne@69 1070 MODULE_SCOPE int TkTextSharedGetObjIndex(Tcl_Interp *interp,
jpayne@69 1071 TkSharedText *sharedTextPtr, Tcl_Obj *idxPtr,
jpayne@69 1072 TkTextIndex *indexPtr);
jpayne@69 1073 MODULE_SCOPE const TkTextIndex *TkTextGetIndexFromObj(Tcl_Interp *interp,
jpayne@69 1074 TkText *textPtr, Tcl_Obj *objPtr);
jpayne@69 1075 MODULE_SCOPE TkTextTabArray *TkTextGetTabs(Tcl_Interp *interp,
jpayne@69 1076 TkText *textPtr, Tcl_Obj *stringPtr);
jpayne@69 1077 MODULE_SCOPE void TkTextFindDisplayLineEnd(TkText *textPtr,
jpayne@69 1078 TkTextIndex *indexPtr, int end, int *xOffset);
jpayne@69 1079 MODULE_SCOPE void TkTextIndexBackChars(const TkText *textPtr,
jpayne@69 1080 const TkTextIndex *srcPtr, int count,
jpayne@69 1081 TkTextIndex *dstPtr, TkTextCountType type);
jpayne@69 1082 MODULE_SCOPE int TkTextIndexCmp(const TkTextIndex *index1Ptr,
jpayne@69 1083 const TkTextIndex *index2Ptr);
jpayne@69 1084 MODULE_SCOPE int TkTextIndexCountBytes(const TkText *textPtr,
jpayne@69 1085 const TkTextIndex *index1Ptr,
jpayne@69 1086 const TkTextIndex *index2Ptr);
jpayne@69 1087 MODULE_SCOPE int TkTextIndexCount(const TkText *textPtr,
jpayne@69 1088 const TkTextIndex *index1Ptr,
jpayne@69 1089 const TkTextIndex *index2Ptr,
jpayne@69 1090 TkTextCountType type);
jpayne@69 1091 MODULE_SCOPE void TkTextIndexForwChars(const TkText *textPtr,
jpayne@69 1092 const TkTextIndex *srcPtr, int count,
jpayne@69 1093 TkTextIndex *dstPtr, TkTextCountType type);
jpayne@69 1094 MODULE_SCOPE void TkTextIndexOfX(TkText *textPtr, int x,
jpayne@69 1095 TkTextIndex *indexPtr);
jpayne@69 1096 MODULE_SCOPE int TkTextIndexYPixels(TkText *textPtr,
jpayne@69 1097 const TkTextIndex *indexPtr);
jpayne@69 1098 MODULE_SCOPE TkTextSegment *TkTextIndexToSeg(const TkTextIndex *indexPtr,
jpayne@69 1099 int *offsetPtr);
jpayne@69 1100 MODULE_SCOPE void TkTextLostSelection(ClientData clientData);
jpayne@69 1101 MODULE_SCOPE TkTextIndex *TkTextMakeCharIndex(TkTextBTree tree, TkText *textPtr,
jpayne@69 1102 int lineIndex, int charIndex,
jpayne@69 1103 TkTextIndex *indexPtr);
jpayne@69 1104 MODULE_SCOPE int TkTextMeasureDown(TkText *textPtr,
jpayne@69 1105 TkTextIndex *srcPtr, int distance);
jpayne@69 1106 MODULE_SCOPE void TkTextFreeElideInfo(TkTextElideInfo *infoPtr);
jpayne@69 1107 MODULE_SCOPE int TkTextIsElided(const TkText *textPtr,
jpayne@69 1108 const TkTextIndex *indexPtr,
jpayne@69 1109 TkTextElideInfo *infoPtr);
jpayne@69 1110 MODULE_SCOPE int TkTextMakePixelIndex(TkText *textPtr,
jpayne@69 1111 int pixelIndex, TkTextIndex *indexPtr);
jpayne@69 1112 MODULE_SCOPE void TkTextInvalidateLineMetrics(
jpayne@69 1113 TkSharedText *sharedTextPtr, TkText *textPtr,
jpayne@69 1114 TkTextLine *linePtr, int lineCount, int action);
jpayne@69 1115 MODULE_SCOPE int TkTextUpdateLineMetrics(TkText *textPtr, int lineNum,
jpayne@69 1116 int endLine, int doThisMuch);
jpayne@69 1117 MODULE_SCOPE int TkTextUpdateOneLine(TkText *textPtr,
jpayne@69 1118 TkTextLine *linePtr, int pixelHeight,
jpayne@69 1119 TkTextIndex *indexPtr, int partialCalc);
jpayne@69 1120 MODULE_SCOPE int TkTextMarkCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1121 int objc, Tcl_Obj *const objv[]);
jpayne@69 1122 MODULE_SCOPE int TkTextMarkNameToIndex(TkText *textPtr,
jpayne@69 1123 const char *name, TkTextIndex *indexPtr);
jpayne@69 1124 MODULE_SCOPE void TkTextMarkSegToIndex(TkText *textPtr,
jpayne@69 1125 TkTextSegment *markPtr, TkTextIndex *indexPtr);
jpayne@69 1126 MODULE_SCOPE void TkTextEventuallyRepick(TkText *textPtr);
jpayne@69 1127 MODULE_SCOPE Bool TkTextPendingsync(TkText *textPtr);
jpayne@69 1128 MODULE_SCOPE void TkTextPickCurrent(TkText *textPtr, XEvent *eventPtr);
jpayne@69 1129 MODULE_SCOPE void TkTextPixelIndex(TkText *textPtr, int x, int y,
jpayne@69 1130 TkTextIndex *indexPtr, int *nearest);
jpayne@69 1131 MODULE_SCOPE Tcl_Obj * TkTextNewIndexObj(TkText *textPtr,
jpayne@69 1132 const TkTextIndex *indexPtr);
jpayne@69 1133 MODULE_SCOPE void TkTextRedrawRegion(TkText *textPtr, int x, int y,
jpayne@69 1134 int width, int height);
jpayne@69 1135 MODULE_SCOPE void TkTextRedrawTag(TkSharedText *sharedTextPtr,
jpayne@69 1136 TkText *textPtr, TkTextIndex *index1Ptr,
jpayne@69 1137 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
jpayne@69 1138 int withTag);
jpayne@69 1139 MODULE_SCOPE void TkTextRelayoutWindow(TkText *textPtr, int mask);
jpayne@69 1140 MODULE_SCOPE int TkTextScanCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1141 int objc, Tcl_Obj *const objv[]);
jpayne@69 1142 MODULE_SCOPE int TkTextSeeCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1143 int objc, Tcl_Obj *const objv[]);
jpayne@69 1144 MODULE_SCOPE int TkTextSegToOffset(const TkTextSegment *segPtr,
jpayne@69 1145 const TkTextLine *linePtr);
jpayne@69 1146 MODULE_SCOPE void TkTextSetYView(TkText *textPtr,
jpayne@69 1147 TkTextIndex *indexPtr, int pickPlace);
jpayne@69 1148 MODULE_SCOPE int TkTextTagCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1149 int objc, Tcl_Obj *const objv[]);
jpayne@69 1150 MODULE_SCOPE int TkTextImageCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1151 int objc, Tcl_Obj *const objv[]);
jpayne@69 1152 MODULE_SCOPE int TkTextImageIndex(TkText *textPtr,
jpayne@69 1153 const char *name, TkTextIndex *indexPtr);
jpayne@69 1154 MODULE_SCOPE int TkTextWindowCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1155 int objc, Tcl_Obj *const objv[]);
jpayne@69 1156 MODULE_SCOPE int TkTextWindowIndex(TkText *textPtr, const char *name,
jpayne@69 1157 TkTextIndex *indexPtr);
jpayne@69 1158 MODULE_SCOPE int TkTextYviewCmd(TkText *textPtr, Tcl_Interp *interp,
jpayne@69 1159 int objc, Tcl_Obj *const objv[]);
jpayne@69 1160 MODULE_SCOPE void TkTextWinFreeClient(Tcl_HashEntry *hPtr,
jpayne@69 1161 TkTextEmbWindowClient *client);
jpayne@69 1162 MODULE_SCOPE void TkTextRunAfterSyncCmd(ClientData clientData);
jpayne@69 1163 MODULE_SCOPE int TkTextIndexAdjustToStartEnd(TkText *textPtr,
jpayne@69 1164 TkTextIndex *indexPtr, int err);
jpayne@69 1165 #endif /* _TKTEXT */
jpayne@69 1166
jpayne@69 1167 /*
jpayne@69 1168 * Local Variables:
jpayne@69 1169 * mode: c
jpayne@69 1170 * c-basic-offset: 4
jpayne@69 1171 * fill-column: 78
jpayne@69 1172 * End:
jpayne@69 1173 */