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

  1. /*
  2.  * tkCanvas.h --
  3.  *
  4.  *    Declarations shared among all the files that implement
  5.  *    canvas widgets.
  6.  *
  7.  * Copyright (c) 1991-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/tkCanvas.h,v 1.21 93/06/16 17:15:32 ouster Exp $ SPRITE (Berkeley)
  28.  */
  29.  
  30. #ifndef _TKCANVAS
  31. #define _TKCANVAS
  32.  
  33. #ifndef _TK
  34. #include "tk.h"
  35. #endif
  36.  
  37. /*
  38.  * For each item in a canvas widget there exists one record with
  39.  * the following structure.  Each actual item is represented by
  40.  * a record with the following stuff at its beginning, plus additional
  41.  * type-specific stuff after that.
  42.  */
  43.  
  44. #define TK_TAG_SPACE 3
  45.  
  46. typedef struct Tk_Item  {
  47.     int id;                /* Unique identifier for this item
  48.                      * (also serves as first tag for
  49.                      * item). */
  50.     struct Tk_Item *nextPtr;        /* Next in display list of all
  51.                      * items in this canvas.  Later items
  52.                      * in list are drawn on top of earlier
  53.                      * ones. */
  54.     Tk_Uid staticTagSpace[TK_TAG_SPACE];/* Built-in space for limited # of
  55.                      * tags. */
  56.     Tk_Uid *tagPtr;            /* Pointer to array of tags.  Usually
  57.                      * points to staticTagSpace, but
  58.                      * may point to malloc-ed space if
  59.                      * there are lots of tags. */
  60.     int tagSpace;            /* Total amount of tag space available
  61.                      * at tagPtr. */
  62.     int numTags;            /* Number of tag slots actually used
  63.                      * at *tagPtr. */
  64.     struct Tk_ItemType *typePtr;    /* Table of procedures that implement
  65.                      * this type of item. */
  66.     int x1, y1, x2, y2;            /* Bounding box for item, in integer
  67.                      * canvas units. Set by item-specific
  68.                      * code and guaranteed to contain every
  69.                      * pixel drawn in item.  Item area
  70.                      * includes x1 and y1 but not x2
  71.                      * and y2. */
  72.  
  73.     /*
  74.      *------------------------------------------------------------------
  75.      * Starting here is additional type-specific stuff;  see the
  76.      * declarations for individual types to see what is part of
  77.      * each type.  The actual space below is determined by the
  78.      * "itemInfoSize" of the type's Tk_ItemType record.
  79.      *------------------------------------------------------------------
  80.      */
  81. } Tk_Item;
  82.  
  83. /*
  84.  * The record below describes a canvas widget.  It is made available
  85.  * to the item procedures so they can access certain shared fields such
  86.  * as the overall displacement and scale factor for the canvas.
  87.  */
  88.  
  89. typedef struct {
  90.     Tk_Window tkwin;        /* Window that embodies the canvas.  NULL
  91.                  * means that the window has been destroyed
  92.                  * but the data structures haven't yet been
  93.                  * cleaned up.*/
  94.     Display *display;        /* Display containing widget;  needed, among
  95.                  * other things, to release resources after
  96.                  * tkwin has already gone away. */
  97.     Tcl_Interp *interp;        /* Interpreter associated with canvas. */
  98.     Tk_Item *firstItemPtr;    /* First in list of all items in canvas,
  99.                  * or NULL if canvas empty. */
  100.     Tk_Item *lastItemPtr;    /* Last in list of all items in canvas,
  101.                  * or NULL if canvas empty. */
  102.  
  103.     /*
  104.      * Information used when displaying widget:
  105.      */
  106.  
  107.     int borderWidth;        /* Width of 3-D border around window. */
  108.     Tk_3DBorder bgBorder;    /* Used for canvas background. */
  109.     int relief;            /* Indicates whether window as a whole is
  110.                  * raised, sunken, or flat. */
  111.     GC pixmapGC;        /* Used to copy bits from a pixmap to the
  112.                  * screen and also to clear the pixmap. */
  113.     int width, height;        /* Dimensions to request for canvas window,
  114.                  * specified in pixels. */
  115.     int redrawX1, redrawY1;    /* Upper left corner of area to redraw,
  116.                  * in pixel coordinates.  Border pixels
  117.                  * are included.  Only valid if
  118.                  * REDRAW_PENDING flag is set. */
  119.     int redrawX2, redrawY2;    /* Lower right corner of area to redraw,
  120.                  * in pixel coordinates.  Border pixels
  121.                  * will *not* be redrawn. */
  122.     int confine;        /* Non-zero means constrain view to keep
  123.                  * as much of canvas visible as possible. */
  124.  
  125.     /*
  126.      * Information used to manage and display selection:
  127.      */
  128.  
  129.     Tk_3DBorder selBorder;    /* Border and background for selected
  130.                  * characters. */
  131.     int selBorderWidth;        /* Width of border around selection. */
  132.     XColor *selFgColorPtr;    /* Foreground color for selected text. */
  133.     Tk_Item *selItemPtr;    /* Pointer to selected item.  NULL means
  134.                  * selection isn't in this canvas. */
  135.     int selectFirst;        /* Index of first selected character. */
  136.     int selectLast;        /* Index of last selected character. */
  137.     Tk_Item *anchorItemPtr;    /* Item corresponding to "selectAnchor":
  138.                  * not necessarily selItemPtr. */
  139.     int selectAnchor;        /* Fixed end of selection (i.e. "select to"
  140.                  * operation will use this as one end of the
  141.                  * selection). */
  142.  
  143.     /*
  144.      * Information for display insertion cursor in text:
  145.      */
  146.  
  147.     Tk_3DBorder insertBorder;    /* Used to draw vertical bar for insertion
  148.                  * cursor. */
  149.     int insertWidth;        /* Total width of insertion cursor. */
  150.     int insertBorderWidth;    /* Width of 3-D border around insert cursor. */
  151.     int insertOnTime;        /* Number of milliseconds cursor should spend
  152.                  * in "on" state for each blink. */
  153.     int insertOffTime;        /* Number of milliseconds cursor should spend
  154.                  * in "off" state for each blink. */
  155.     Tk_TimerToken insertBlinkHandler;
  156.                 /* Timer handler used to blink cursor on and
  157.                  * off. */
  158.     Tk_Item *focusItemPtr;    /* Item that currently has the input focus,
  159.                  * or NULL if no such item. */
  160.  
  161.     /*
  162.      * Transformation applied to canvas as a whole:  to compute screen
  163.      * coordinates (X,Y) from canvas coordinates (x,y), do the following:
  164.      *
  165.      * X = x - xOrigin;
  166.      * Y = y - yOrigin;
  167.      */
  168.  
  169.     int xOrigin, yOrigin;    /* Canvas coordinates corresponding to
  170.                  * upper-left corner of window, given in
  171.                  * canvas pixel units. */
  172.     int drawableXOrigin, drawableYOrigin;
  173.                 /* During redisplay, these fields give the
  174.                  * canvas coordinates corresponding to
  175.                  * the upper-left corner of the drawable
  176.                  * where items are actually being drawn
  177.                  * (typically a pixmap smaller than the
  178.                  * whole window). */
  179.  
  180.     /*
  181.      * Information used for event bindings associated with items.
  182.      */
  183.  
  184.     Tk_BindingTable bindingTable;
  185.                 /* Table of all bindings currently defined
  186.                  * for this canvas.  NULL means that no
  187.                  * bindings exist, so the table hasn't been
  188.                  * created.  Each "object" used for this
  189.                  * table is either a Tk_Uid for a tag or
  190.                  * the address of an item named by id. */
  191.     Tk_Item *currentItemPtr;    /* The item currently containing the mouse
  192.                  * pointer, or NULL if none. */
  193.     double closeEnough;        /* The mouse is assumed to be inside an
  194.                  * item if it is this close to it. */
  195.     XEvent pickEvent;        /* The event upon which the current choice
  196.                  * of currentItem is based.  Must be saved
  197.                  * so that if the currentItem is deleted,
  198.                  * can pick another. */
  199.     int state;            /* Last known modifier state.  Used to
  200.                  * defer picking a new current object
  201.                  * while buttons are down. */
  202.  
  203.     /*
  204.      * Information used for managing scrollbars:
  205.      */
  206.  
  207.     char *xScrollCmd;        /* Command prefix for communicating with
  208.                  * horizontal scrollbar.  NULL means no
  209.                  * horizontal scrollbar.  Malloc'ed*/
  210.     char *yScrollCmd;        /* Command prefix for communicating with
  211.                  * vertical scrollbar.  NULL means no
  212.                  * vertical scrollbar.  Malloc'ed*/
  213.     int scrollX1, scrollY1, scrollX2, scrollY2;
  214.                 /* These four coordinates define the region
  215.                  * that is the 100% area for scrolling (i.e.
  216.                  * these numbers determine the size and
  217.                  * location of the sliders on scrollbars).
  218.                  * Units are pixels in canvas coords. */
  219.     char *regionString;        /* The option string from which scrollX1
  220.                  * etc. are derived.  Malloc'ed. */
  221.     int scrollIncrement;    /* The number of canvas units that the
  222.                  * picture shifts when a scrollbar up or
  223.                  * down arrow is pressed. */
  224.  
  225.     /*
  226.      * Information used for scanning:
  227.      */
  228.  
  229.     int scanX;            /* X-position at which scan started (e.g.
  230.                  * button was pressed here). */
  231.     int scanXOrigin;        /* Value of xOrigin field when scan started. */
  232.     int scanY;            /* Y-position at which scan started (e.g.
  233.                  * button was pressed here). */
  234.     int scanYOrigin;        /* Value of yOrigin field when scan started. */
  235.  
  236.     /*
  237.      * Information used to speed up searches by remembering the last item
  238.      * created or found with an item id search.
  239.      */
  240.  
  241.     Tk_Item *hotPtr;        /* Pointer to "hot" item (one that's been
  242.                  * recently used.  NULL means there's no
  243.                  * hot item. */
  244.     Tk_Item *hotPrevPtr;    /* Pointer to predecessor to hotPtr (NULL
  245.                  * means item is first in list).  This is
  246.                  * only a hint and may not really be hotPtr's
  247.                  * predecessor. */
  248.  
  249.     /*
  250.      * Miscellaneous information:
  251.      */
  252.  
  253.     Cursor cursor;        /* Current cursor for window, or None. */
  254.     double pixelsPerMM;        /* Scale factor between MM and pixels;
  255.                  * used when converting coordinates. */
  256.     int flags;            /* Various flags;  see below for
  257.                  * definitions. */
  258.     int nextId;            /* Number to use as id for next item
  259.                  * created in widget. */
  260. } Tk_Canvas;
  261.  
  262. /*
  263.  * Flag bits for canvases:
  264.  *
  265.  * REDRAW_PENDING -        1 means a DoWhenIdle handler has already
  266.  *                been created to redraw some or all of the
  267.  *                canvas.
  268.  * REPICK_NEEDED -        1 means DisplayCanvas should pick a new
  269.  *                current item before redrawing the canvas.
  270.  * GOT_FOCUS -            1 means the focus is currently in this
  271.  *                widget, so should draw the insertion cursor.
  272.  * CURSOR_ON -            1 means the insertion cursor is in the "on"
  273.  *                phase of its blink cycle.  0 means either
  274.  *                we don't have the focus or the cursor is in
  275.  *                the "off" phase of its cycle.
  276.  * UPDATE_SCROLLBARS -        1 means the scrollbars should get updated
  277.  *                as part of the next display operation.
  278.  */
  279.  
  280. #define REDRAW_PENDING        1
  281. #define REPICK_NEEDED        2
  282. #define GOT_FOCUS        4
  283. #define CURSOR_ON        8
  284. #define UPDATE_SCROLLBARS    0x10
  285.  
  286. /*
  287.  * Records of the following type are used to describe a type of
  288.  * item (e.g.  lines, circles, etc.) that can form part of a
  289.  * canvas widget.
  290.  */
  291.  
  292. typedef int    Tk_ItemCreateProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  293.             Tk_Item *itemPtr, int argc, char **argv));
  294. typedef int    Tk_ItemConfigureProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  295.             Tk_Item *itemPtr, int argc, char **argv, int flags));
  296. typedef int    Tk_ItemCoordProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  297.             Tk_Item *itemPtr, int argc, char **argv));
  298. typedef void    Tk_ItemDeleteProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  299.             Tk_Item *itemPtr));
  300. typedef void    Tk_ItemDisplayProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  301.             Tk_Item *itemPtr, Drawable dst));
  302. typedef double    Tk_ItemPointProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  303.             Tk_Item *itemPtr, double *pointPtr));
  304. typedef int    Tk_ItemAreaProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  305.             Tk_Item *itemPtr, double *rectPtr));
  306. typedef int    Tk_ItemPostscriptProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  307.             Tk_Item *itemPtr, Tk_PostscriptInfo *psInfoPtr));
  308. typedef void    Tk_ItemScaleProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  309.             Tk_Item *itemPtr, double originX, double originY,
  310.             double scaleX, double scaleY));
  311. typedef void    Tk_ItemTranslateProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  312.             Tk_Item *itemPtr, double deltaX, double deltaY));
  313. typedef int    Tk_ItemIndexProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  314.             Tk_Item *itemPtr, char *indexString,
  315.             int *indexPtr));
  316. typedef void    Tk_ItemCursorProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  317.             Tk_Item *itemPtr, int index));
  318. typedef int    Tk_ItemSelectionProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  319.             Tk_Item *itemPtr, int offset, char *buffer,
  320.             int maxBytes));
  321. typedef int    Tk_ItemInsertProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  322.             Tk_Item *itemPtr, int beforeThis, char *string));
  323. typedef int    Tk_ItemDCharsProc _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  324.             Tk_Item *itemPtr, int first, int last));
  325.  
  326. typedef struct Tk_ItemType {
  327.     char *name;                /* The name of this type of item, such
  328.                      * as "line". */
  329.     int itemSize;            /* Total amount of space needed for
  330.                      * item's record. */
  331.     Tk_ItemCreateProc *createProc;    /* Procedure to create a new item of
  332.                      * this type. */
  333.     Tk_ConfigSpec *configSpecs;        /* Pointer to array of configuration
  334.                      * specs for this type.  Used for
  335.                      * returning configuration info. */
  336.     Tk_ItemConfigureProc *configProc;    /* Procedure to call to change
  337.                      * configuration options. */
  338.     Tk_ItemCoordProc *coordProc;    /* Procedure to call to get and set
  339.                      * the item's coordinates. */
  340.     Tk_ItemDeleteProc *deleteProc;    /* Procedure to delete existing item of
  341.                      * this type. */
  342.     Tk_ItemDisplayProc *displayProc;    /* Procedure to display items of
  343.                      * this type. */
  344.     int alwaysRedraw;            /* Non-zero means displayProc should
  345.                      * be called even when the item has
  346.                      * been moved off-screen. */
  347.     Tk_ItemPointProc *pointProc;    /* Computes distance from item to
  348.                      * a given point. */
  349.     Tk_ItemAreaProc *areaProc;        /* Computes whether item is inside,
  350.                      * outside, or overlapping an area. */
  351.     Tk_ItemPostscriptProc *postscriptProc;
  352.                     /* Procedure to write a Postscript
  353.                      * description for items of this
  354.                      * type. */
  355.     Tk_ItemScaleProc *scaleProc;    /* Procedure to rescale items of
  356.                      * this type. */
  357.     Tk_ItemTranslateProc *translateProc;/* Procedure to translate items of
  358.                      * this type. */
  359.     Tk_ItemIndexProc *indexProc;    /* Procedure to determine index of
  360.                      * indicated character.  NULL if
  361.                      * item doesn't support indexing. */
  362.     Tk_ItemCursorProc *icursorProc;    /* Procedure to set insert cursor pos.
  363.                      * to just before a given position. */
  364.     Tk_ItemSelectionProc *selectionProc;/* Procedure to return selection (in
  365.                      * STRING format) when it is in this
  366.                      * item. */
  367.     Tk_ItemInsertProc *insertProc;    /* Procedure to insert something into
  368.                      * an item. */
  369.     Tk_ItemDCharsProc *dCharsProc;    /* Procedure to delete characters
  370.                      * from an item. */
  371.     struct Tk_ItemType *nextPtr;    /* Used to link types together into
  372.                      * a list. */
  373. } Tk_ItemType;
  374.  
  375. /*
  376.  * Macros to transform a point from double-precision canvas coordinates
  377.  * to integer pixel coordinates in the pixmap where redisplay is being
  378.  * done.
  379.  */
  380.  
  381. #define SCREEN_X(canvasPtr, x) \
  382.     (((int) ((x) + (((x) > 0) ? 0.5 : -0.5))) - (canvasPtr)->drawableXOrigin)
  383. #define SCREEN_Y(canvasPtr, y) \
  384.     (((int) ((y) + (((y) > 0) ? 0.5 : -0.5))) - (canvasPtr)->drawableYOrigin)
  385.  
  386. /*
  387.  * Canvas-related variables that are shared among Tk modules but not
  388.  * exported to the outside world:
  389.  */
  390.  
  391. extern Tk_CustomOption tkCanvasTagsOption;
  392.  
  393. /*
  394.  * Canvas-related procedures that are shared among Tk modules but not
  395.  * exported to the outside world:
  396.  */
  397.  
  398. extern void        TkBezierScreenPoints _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  399.                 double control[], int numSteps,
  400.                 XPoint *xPointPtr));
  401. extern int        TkCanvPostscriptCmd _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  402.                 Tcl_Interp *interp, int argc, char **argv));
  403. extern int        TkCanvPsBitmap _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  404.                 Tk_PostscriptInfo *psInfoPtr, Pixmap bitmap));
  405. extern int        TkCanvPsColor _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  406.                 Tk_PostscriptInfo *psInfoPtr, XColor *colorPtr));
  407. extern int        TkCanvPsFont _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  408.                 Tk_PostscriptInfo *psInfoPtr,
  409.                 XFontStruct *fontStructPtr));
  410. extern void        TkCanvPsPath _ANSI_ARGS_((Tcl_Interp *interp,
  411.                 double *coordPtr, int numPoints,
  412.                 Tk_PostscriptInfo *psInfoPtr));
  413. extern int        TkCanvPsStipple _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  414.                 Tk_PostscriptInfo *psInfoPtr, Pixmap bitmap,
  415.                 int filled));
  416. extern double        TkCanvPsY _ANSI_ARGS_((Tk_PostscriptInfo *psInfoPtr,
  417.                 double y));
  418. extern void        TkFillPolygon _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  419.                 double *coordPtr, int numPoints, Drawable drawable,
  420.                 GC gc));
  421. extern int        TkGetCanvasCoord _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  422.                 char *string, double *doublePtr));
  423. extern void        TkIncludePoint _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  424.                 Tk_Item *itemPtr, double *pointPtr));
  425. extern int        TkMakeBezierCurve _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  426.                 double *pointPtr, int numPoints, int numSteps,
  427.                 XPoint xPoints[], double dblPoints[]));
  428.  
  429. #endif /* _TKCANVAS */
  430.