home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / tkText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-16  |  16.4 KB  |  429 lines

  1. /*
  2.  * tkText.h --
  3.  *
  4.  *    Declarations shared among the files that implement text
  5.  *    widgets.
  6.  *
  7.  * Copyright (c) 1992-1993 The Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Permission is hereby granted, without written agreement and without
  11.  * license or royalty fees, to use, copy, modify, and distribute this
  12.  * software and its documentation for any purpose, provided that the
  13.  * above copyright notice and the following two paragraphs appear in
  14.  * all copies of this software.
  15.  * 
  16.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20.  *
  21.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26.  *
  27.  * $Header: /user6/ouster/wish/RCS/tkText.h,v 1.15 93/06/16 17:16:28 ouster Exp $ SPRITE (Berkeley)
  28.  */
  29.  
  30. #ifndef _TKTEXT
  31. #define _TKTEXT
  32.  
  33. #ifndef _TK
  34. #include "tk.h"
  35. #endif
  36.  
  37. /*
  38.  * Opaque types for structures whose guts are only needed by a single
  39.  * file:
  40.  */
  41.  
  42. typedef struct TkTextBTree *TkTextBTree;
  43.  
  44. /*
  45.  * The data structure below defines a single line of text (from newline
  46.  * to newline, not necessarily what appears on one line of the screen).
  47.  */
  48.  
  49. typedef struct TkTextLine {
  50.     struct Node *parentPtr;        /* Pointer to parent node containing
  51.                      * line. */
  52.     struct TkTextLine *nextPtr;        /* Next in linked list of lines with
  53.                      * same parent node in B-tree.  NULL
  54.                      * means end of list. */
  55.     struct TkAnnotation *annotPtr;    /* First in list of annotations for
  56.                      * this line. */
  57.     int numBytes;            /* Number of  bytes in line, including
  58.                      * newline but not terminating NULL. */
  59.     char bytes[4];            /* Contents of line, null-terminated.
  60.                      * The actual length of the array will
  61.                      * be as large as needed to hold the
  62.                      * line.  THIS MUST BE THE LAST FIELD
  63.                      * OF THE STRUCT. */
  64. } TkTextLine;
  65.  
  66. /*
  67.  * The structures below are used to describe annotations to the text
  68.  * (such as marks and embedded windows).  Annotations are placed at
  69.  * a given place in the text and then float to keep their position
  70.  * as text is inserted and deleted.  Each actual annotation
  71.  * contains a standard set of fields, plus a type-specific set of
  72.  * fields.  The types are as follows:
  73.  *
  74.  * TK_ANNOT_TOGGLE -    Marks the beginning or end of a range of
  75.  *            characters that have a given tag.
  76.  * TK_ANNOT_MARK -    Holds information about a given "mark" (see
  77.  *            user doc. for information on marks).
  78.  * TK_ANNOT_WINDOW -    Holds information on a window embedded in the
  79.  *            text.  Not implemented yet.
  80.  */
  81.  
  82. typedef enum {TK_ANNOT_TOGGLE, TK_ANNOT_MARK, TK_ANNOT_WINDOW} TkAnnotType;
  83.  
  84. typedef struct TkAnnotation {
  85.     TkAnnotType type;            /* Type of annotation. */
  86.     TkTextLine *linePtr;        /* Pointer to line structure
  87.                      * containing this annotation. */
  88.     int ch;                /* Index of character that annotation
  89.                      * is attached to (annotation is
  90.                      * considered to be just before this
  91.                      * character). */
  92.     struct TkAnnotation *nextPtr;    /* Next in list of annotations for
  93.                      * same line of text, or NULL if
  94.                      * end of list. */
  95.     union {                /* Type-specific information. */
  96.     struct TkTextTag *tagPtr;    /* Type == TK_ANNOT_TOGGLE. */
  97.     Tcl_HashEntry *hPtr;        /* Type == TK_ANNOT_MARK. */
  98.     } info;
  99. } TkAnnotation;
  100.  
  101. /*
  102.  * One data structure of the following type is used for each tag that
  103.  * is currently being used in a text widget.  These structures are kept
  104.  * in textPtr->tagTable and referred to in other structures, like
  105.  * TkTagToggles.
  106.  */
  107.  
  108. typedef struct TkTextTag {
  109.     char *name;            /* Name of this tag.  This field is actually
  110.                  * a pointer to the key from the entry in
  111.                  * textPtr->tagTable, so it needn't be freed
  112.                  * explicitly. */
  113.     int priority;        /* Priority of this tag within widget.  0
  114.                  * means lowest priority.  Exactly one tag
  115.                  * has each integer value between 0 and
  116.                  * numTags-1. */
  117.  
  118.     /*
  119.      * Information for displaying text with this tag.  The information
  120.      * belows acts as an override on information specified by lower-priority
  121.      * tags.  If no value is specified, then the next-lower-priority tag
  122.      * on the text determins the value.  The text widget itself provides
  123.      * defaults if no tag specifies an override.
  124.      */
  125.  
  126.     Tk_3DBorder border;        /* Used for drawing background.  NULL means
  127.                  * no value specified here. */
  128.     int borderWidth;        /* Width of 3-D border for background. */
  129.     int relief;            /* 3-D relief for background. */
  130.     Pixmap bgStipple;        /* Stipple bitmap for background.  None
  131.                  * means no value specified here. */
  132.     XColor *fgColor;        /* Foreground color for text.  NULL means
  133.                  * no value specified here. */
  134.     XFontStruct *fontPtr;    /* Font for displaying text.  NULL means
  135.                  * no value specified here. */
  136.     Pixmap fgStipple;        /* Stipple bitmap for text and other
  137.                  * foreground stuff.   None means no value
  138.                  * specified here.*/
  139.     int underline;        /* Non-zero means draw underline underneath
  140.                  * text. */
  141. } TkTextTag;
  142.  
  143. /*
  144.  * The macro below determines whether or not a particular tag affects
  145.  * the way information is displayed on the screen.  It's used, for
  146.  * example, to determine when to redisplay in response to tag changes.
  147.  */
  148.  
  149. #define TK_TAG_AFFECTS_DISPLAY(tagPtr)                     \
  150.     (((tagPtr)->border != NULL) || ((tagPtr)->bgStipple != None)    \
  151.     || ((tagPtr)->fgColor != NULL) || ((tagPtr)->fontPtr != NULL)     \
  152.     || ((tagPtr)->fgStipple != None) || ((tagPtr)->underline))
  153.  
  154. /*
  155.  * The data structure below is used for searching a B-tree for transitions
  156.  * on a single tag (or for all tag transitions).  No code outside of
  157.  * tkTextBTree.c should ever modify any of the fields in these structures,
  158.  * but it's OK to use them for read-only information.
  159.  */
  160.  
  161. typedef struct TkTextSearch {
  162.     TkTextBTree tree;            /* Tree being searched. */
  163.     int line1, ch1;            /* Position of last tag returned
  164.                      * by TkBTreeNextTag. */
  165.     int line2, ch2;            /* Stop search after all tags at this
  166.                      * character position have been
  167.                      * processed. */
  168.     TkTextTag *tagPtr;            /* Tag to search for (or tag found, if
  169.                      * allTags is non-zero). */
  170.     int allTags;            /* Non-zero means ignore tag check:
  171.                      * search for transitions on all
  172.                      * tags. */
  173.     TkTextLine *linePtr;        /* Line currently being searched.  NULL
  174.                      * means search is over. */
  175.     TkAnnotation *annotPtr;        /* Pointer to next annotation to
  176.                      * consider.  NULL means no annotations
  177.                      * left in current line;  must go on
  178.                      * to next line. */
  179. } TkTextSearch;
  180.  
  181. /*
  182.  * A data structure of the following type is kept for each text widget that
  183.  * currently exists for this process:
  184.  */
  185.  
  186. typedef struct TkText {
  187.     Tk_Window tkwin;        /* Window that embodies the text.  NULL
  188.                  * means that the window has been destroyed
  189.                  * but the data structures haven't yet been
  190.                  * cleaned up.*/
  191.     Display *display;        /* Display for widget.  Needed, among other
  192.                  * things, to allow resources to be freed
  193.                  * even after tkwin has gone away. */
  194.     Tcl_Interp *interp;        /* Interpreter associated with widget.  Used
  195.                  * to delete widget command.  */
  196.     TkTextBTree tree;        /* B-tree representation of text and tags for
  197.                  * widget. */
  198.     Tcl_HashTable tagTable;    /* Hash table that maps from tag names to
  199.                  * pointers to TkTextTag structures. */
  200.     int numTags;        /* Number of tags currently defined for
  201.                  * widget;  needed to keep track of
  202.                  * priorities. */
  203.     Tcl_HashTable markTable;    /* Hash table that maps from mark names to
  204.                  * pointer to TkAnnotation structures of
  205.                  * type TK_ANNOT_MARK. */
  206.     Tk_Uid state;        /* Normal or disabled.  Text is read-only
  207.                  * when disabled. */
  208.  
  209.     /*
  210.      * Default information for displaying (may be overridden by tags
  211.      * applied to ranges of characters).
  212.      */
  213.  
  214.     Tk_3DBorder border;        /* Structure used to draw 3-D border and
  215.                  * default background. */
  216.     int borderWidth;        /* Width of 3-D border to draw around entire
  217.                  * widget. */
  218.     int padX, padY;        /* Padding between text and window border. */
  219.     int relief;            /* 3-d effect for border around entire
  220.                  * widget: TK_RELIEF_RAISED etc. */
  221.     Cursor cursor;        /* Current cursor for window, or None. */
  222.     XColor *fgColor;        /* Default foreground color for text. */
  223.     XFontStruct *fontPtr;    /* Default font for displaying text. */
  224.  
  225.     /*
  226.      * Additional information used for displaying:
  227.      */
  228.  
  229.     Tk_Uid wrapMode;        /* How to handle wrap-around.  Must be
  230.                  * tkTextCharUid, tkTextNoneUid, or
  231.                  * tkTextWordUid. */
  232.     int width, height;        /* Desired dimensions for window, measured
  233.                  * in characters. */
  234.     int setGrid;        /* Non-zero means pass gridding information
  235.                  * to window manager. */
  236.     int prevWidth, prevHeight;    /* Last known dimensions of window;  used to
  237.                  * detect changes in size. */
  238.     TkTextLine *topLinePtr;    /* Text line that is supposed to be displayed
  239.                  * at top of the window:  set only by
  240.                  * tkTextDisp.c. */
  241.     struct DInfo *dInfoPtr;    /* Additional information maintained by
  242.                  * tkTextDisp.c. */
  243.     /*
  244.      * Information related to selection.
  245.      */
  246.  
  247.     TkTextTag *selTagPtr;    /* Pointer to "sel" tag.  Used to tell when
  248.                  * a new selection has been made. */
  249.     Tk_3DBorder selBorder;    /* Border and background for selected
  250.                  * characters.  This is a copy of information
  251.                  * in *cursorTagPtr, so it shouldn't be
  252.                  * explicitly freed. */
  253.     int selBorderWidth;        /* Width of border around selection. */
  254.     XColor *selFgColorPtr;    /* Foreground color for selected text.
  255.                  * This is a copy of information in
  256.                  * *cursorTagPtr, so it shouldn't be
  257.                  * explicitly freed. */
  258.     int exportSelection;    /* Non-zero means tie "sel" tag to X
  259.                  * selection. */
  260.     int selLine, selCh;        /* Used during multi-pass selection retrievals.
  261.                  * These identify the next character to be
  262.                  * returned from the selection. */
  263.     int selOffset;        /* Offset in selection corresponding to
  264.                  * selLine and selCh.  -1 means neither
  265.                  * this information nor selLine or selCh
  266.                  * is of any use. */
  267.  
  268.     /*
  269.      * Information related to insertion cursor:
  270.      */
  271.  
  272.     TkAnnotation *insertAnnotPtr;
  273.                 /* Always points to annotation for "insert"
  274.                  * mark. */
  275.     Tk_3DBorder insertBorder;    /* Used to draw vertical bar for insertion
  276.                  * cursor. */
  277.     int insertWidth;        /* Total width of insert cursor. */
  278.     int insertBorderWidth;    /* Width of 3-D border around insert cursor. */
  279.     int insertOnTime;        /* Number of milliseconds cursor should spend
  280.                  * in "on" state for each blink. */
  281.     int insertOffTime;        /* Number of milliseconds cursor should spend
  282.                  * in "off" state for each blink. */
  283.     Tk_TimerToken insertBlinkHandler;
  284.                 /* Timer handler used to blink cursor on and
  285.                  * off. */
  286.  
  287.     /*
  288.      * Information used for event bindings associated with tags:
  289.      */
  290.  
  291.     Tk_BindingTable bindingTable;
  292.                 /* Table of all bindings currently defined
  293.                  * for this widget.  NULL means that no
  294.                  * bindings exist, so the table hasn't been
  295.                  * created.  Each "object" used for this
  296.                  * table is the address of a tag. */
  297.     TkAnnotation *currentAnnotPtr;
  298.                 /* Pointer to annotation for "current" mark,
  299.                  * or NULL if none. */
  300.     XEvent pickEvent;        /* The event from which the current character
  301.                  * was chosen.  Must be saved so that we
  302.                  * can repick after insertions and deletions. */
  303.  
  304.     /*
  305.      * Miscellaneous additional information:
  306.      */
  307.  
  308.     char *yScrollCmd;        /* Prefix of command to issue to update
  309.                  * vertical scrollbar when view changes. */
  310.     int scanMarkLine;        /* Line that was at the top of the window
  311.                  * when the scan started. */
  312.     int scanMarkY;        /* Y-position of mouse at time scan started. */
  313.     int flags;            /* Miscellaneous flags;  see below for
  314.                  * definitions. */
  315. } TkText;
  316.  
  317. /*
  318.  * Flag values for TkText records:
  319.  *
  320.  * GOT_SELECTION:        Non-zero means we've already claimed the
  321.  *                selection.
  322.  * INSERT_ON:            Non-zero means insertion cursor should be
  323.  *                displayed on screen.
  324.  * GOT_FOCUS:            Non-zero means this window has the input
  325.  *                focus.
  326.  * BUTTON_DOWN:            1 means that a mouse button is currently
  327.  *                down;  this is used to implement grabs
  328.  *                for the duration of button presses.
  329.  * IN_CURRENT:            1 means that an EnterNotify event has been
  330.  *                delivered to the current character with
  331.  *                no matching LeaveNotify event yet.
  332.  */
  333.  
  334. #define GOT_SELECTION    1
  335. #define INSERT_ON    2
  336. #define GOT_FOCUS    4
  337. #define BUTTON_DOWN    8
  338. #define IN_CURRENT    0x10
  339.  
  340. /*
  341.  * The constant below is used to specify a line when what is really
  342.  * wanted is the entire text.  For now, just use a very big number.
  343.  */
  344.  
  345. #define TK_END_OF_TEXT 1000000
  346.  
  347. /*
  348.  * Declarations for variables shared among the text-related files:
  349.  */
  350.  
  351. extern int tkBTreeDebug;
  352. extern Tk_Uid tkTextCharUid;
  353. extern Tk_Uid tkTextDisabledUid;
  354. extern Tk_Uid tkTextNoneUid;
  355. extern Tk_Uid tkTextNormalUid;
  356. extern Tk_Uid tkTextWordUid;
  357.  
  358. /*
  359.  * Declarations for procedures that are used by the text-related files
  360.  * but shouldn't be used anywhere else in Tk (or by Tk clients):
  361.  */
  362.  
  363. extern void        TkBTreeAddAnnotation _ANSI_ARGS_((
  364.                 TkAnnotation *annotPtr));
  365. extern int        TkBTreeCharTagged _ANSI_ARGS_((TkTextLine *linePtr,
  366.                 int index, TkTextTag *tagPtr));
  367. extern void        TkBTreeCheck _ANSI_ARGS_((TkTextBTree tree));
  368. extern TkTextBTree    TkBTreeCreate _ANSI_ARGS_((void));
  369. extern void        TkBTreeDestroy _ANSI_ARGS_((TkTextBTree tree));
  370. extern void        TkBTreeDeleteChars _ANSI_ARGS_((TkTextBTree tree,
  371.                 TkTextLine *line1Ptr, int ch1,
  372.                 TkTextLine *line2Ptr, int ch2));
  373. extern TkTextLine *    TkBTreeFindLine _ANSI_ARGS_((TkTextBTree tree,
  374.                 int line));
  375. extern TkTextTag **    TkBTreeGetTags _ANSI_ARGS_((TkTextBTree tree,
  376.                 TkTextLine *linePtr, int ch, int *numTagsPtr));
  377. extern void        TkBTreeInsertChars _ANSI_ARGS_((TkTextBTree tree,
  378.                 TkTextLine *linePtr, int ch, char *string));
  379. extern int        TkBTreeLineIndex _ANSI_ARGS_((TkTextLine *linePtr));
  380. extern TkTextLine *    TkBTreeNextLine _ANSI_ARGS_((TkTextLine *linePtr));
  381. extern int        TkBTreeNextTag _ANSI_ARGS_((TkTextSearch *searchPtr));
  382. extern int        TkBTreeNumLines _ANSI_ARGS_((TkTextBTree tree));
  383. extern void        TkBTreeRemoveAnnotation _ANSI_ARGS_((
  384.                 TkAnnotation *annotPtr));
  385. extern void        TkBTreeStartSearch _ANSI_ARGS_((TkTextBTree tree,
  386.                 int line1, int ch1, int line2, int ch2,
  387.                 TkTextTag *tagPtr, TkTextSearch *searchPtr));
  388. extern void        TkBTreeTag _ANSI_ARGS_((TkTextBTree tree, int line1,
  389.                 int ch1, int line2, int ch2, TkTextTag *tagPtr,
  390.                 int add));
  391. extern void        TkTextBindProc _ANSI_ARGS_((ClientData clientData,
  392.                 XEvent *eventPtr));
  393. extern TkTextLine *    TkTextCharAtLoc _ANSI_ARGS_((TkText *textPtr,
  394.                 int x, int y, int *chPtr));
  395. extern void        TkTextCreateDInfo _ANSI_ARGS_((TkText *textPtr));
  396. extern TkTextTag *    TkTextCreateTag _ANSI_ARGS_((TkText *textPtr,
  397.                 char *tagName));
  398. extern void        TkTextFreeDInfo _ANSI_ARGS_((TkText *textPtr));
  399. extern void        TkTextFreeTag _ANSI_ARGS_((TkText *textPtr,
  400.                 TkTextTag *tagPtr));
  401. extern int        TkTextGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
  402.                 TkText *textPtr, char *string, int *lineIndexPtr,
  403.                 int *chPtr));
  404. extern void        TkTextLinesChanged _ANSI_ARGS_((TkText *textPtr,
  405.                 int first, int last));
  406. extern void        TkTextLostSelection _ANSI_ARGS_((
  407.                 ClientData clientData));
  408. extern void        TkTextPickCurrent _ANSI_ARGS_((TkText *textPtr,
  409.                 XEvent *eventPtr));
  410. extern void        TkTextPrintIndex _ANSI_ARGS_((int line, int ch,
  411.                 char *string));
  412. extern TkTextLine *    TkTextRoundIndex _ANSI_ARGS_((TkText *textPtr,
  413.                 int *lineIndexPtr, int *chPtr));
  414. extern void        TkTextRedrawRegion _ANSI_ARGS_((TkText *textPtr,
  415.                 int x, int y, int width, int height));
  416. extern void        TkTextRedrawTag _ANSI_ARGS_((TkText *textPtr,
  417.                 int line1, int ch1, int line2, int ch2,
  418.                 TkTextTag *tagPtr, int withTag));
  419. extern void        TkTextRelayoutWindow _ANSI_ARGS_((TkText *textPtr));
  420. extern TkAnnotation *    TkTextSetMark _ANSI_ARGS_((TkText *textPtr, char *name,
  421.                 int line, int ch));
  422. extern void        TkTextSetView _ANSI_ARGS_((TkText *textPtr,
  423.                 int line, int pickPlace));
  424. extern int        TkTextTagCmd _ANSI_ARGS_((TkText *textPtr,
  425.                 Tcl_Interp *interp, int argc, char **argv));
  426. extern void        TkTextUnpickCurrent _ANSI_ARGS_((TkText *textPtr));
  427.  
  428. #endif /* _TKTEXT */
  429.