home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _55e3e5dbbff8a690ca312928cdc0a47b < prev    next >
Encoding:
Text File  |  2004-06-01  |  36.6 KB  |  928 lines

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