home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / generic / tkText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  33.2 KB  |  849 lines  |  [TEXT/CWIE]

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