jpayne@69: /* jpayne@69: * tkCanvas.h -- jpayne@69: * jpayne@69: * Declarations shared among all the files that implement canvas widgets. jpayne@69: * jpayne@69: * Copyright (c) 1991-1994 The Regents of the University of California. jpayne@69: * Copyright (c) 1994-1995 Sun Microsystems, Inc. jpayne@69: * Copyright (c) 1998 by Scriptics Corporation. jpayne@69: * jpayne@69: * See the file "license.terms" for information on usage and redistribution of jpayne@69: * this file, and for a DISCLAIMER OF ALL WARRANTIES. jpayne@69: */ jpayne@69: jpayne@69: #ifndef _TKCANVAS jpayne@69: #define _TKCANVAS jpayne@69: jpayne@69: #ifndef _TK jpayne@69: #include "tk.h" jpayne@69: #endif jpayne@69: jpayne@69: #ifndef USE_OLD_TAG_SEARCH jpayne@69: typedef struct TagSearchExpr_s TagSearchExpr; jpayne@69: jpayne@69: struct TagSearchExpr_s { jpayne@69: TagSearchExpr *next; /* For linked lists of expressions - used in jpayne@69: * bindings. */ jpayne@69: Tk_Uid uid; /* The uid of the whole expression. */ jpayne@69: Tk_Uid *uids; /* Expresion compiled to an array of uids. */ jpayne@69: int allocated; /* Available space for array of uids. */ jpayne@69: int length; /* Length of expression. */ jpayne@69: int index; /* Current position in expression jpayne@69: * evaluation. */ jpayne@69: int match; /* This expression matches event's item's jpayne@69: * tags. */ jpayne@69: }; jpayne@69: #endif /* not USE_OLD_TAG_SEARCH */ jpayne@69: jpayne@69: /* jpayne@69: * The record below describes a canvas widget. It is made available to the jpayne@69: * item functions so they can access certain shared fields such as the overall jpayne@69: * displacement and scale factor for the canvas. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkCanvas { jpayne@69: Tk_Window tkwin; /* Window that embodies the canvas. NULL means jpayne@69: * that the window has been destroyed but the jpayne@69: * data structures haven't yet been cleaned jpayne@69: * up.*/ jpayne@69: Display *display; /* Display containing widget; needed, among jpayne@69: * other things, to release resources after jpayne@69: * tkwin has already gone away. */ jpayne@69: Tcl_Interp *interp; /* Interpreter associated with canvas. */ jpayne@69: Tcl_Command widgetCmd; /* Token for canvas's widget command. */ jpayne@69: Tk_Item *firstItemPtr; /* First in list of all items in canvas, or jpayne@69: * NULL if canvas empty. */ jpayne@69: Tk_Item *lastItemPtr; /* Last in list of all items in canvas, or jpayne@69: * NULL if canvas empty. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used when displaying widget: jpayne@69: */ jpayne@69: jpayne@69: int borderWidth; /* Width of 3-D border around window. */ jpayne@69: Tk_3DBorder bgBorder; /* Used for canvas background. */ jpayne@69: int relief; /* Indicates whether window as a whole is jpayne@69: * raised, sunken, or flat. */ jpayne@69: int highlightWidth; /* Width in pixels of highlight to draw around jpayne@69: * widget when it has the focus. <= 0 means jpayne@69: * don't draw a highlight. */ jpayne@69: XColor *highlightBgColorPtr; jpayne@69: /* Color for drawing traversal highlight area jpayne@69: * when highlight is off. */ jpayne@69: XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ jpayne@69: int inset; /* Total width of all borders, including jpayne@69: * traversal highlight and 3-D border. jpayne@69: * Indicates how much interior stuff must be jpayne@69: * offset from outside edges to leave room for jpayne@69: * borders. */ jpayne@69: GC pixmapGC; /* Used to copy bits from a pixmap to the jpayne@69: * screen and also to clear the pixmap. */ jpayne@69: int width, height; /* Dimensions to request for canvas window, jpayne@69: * specified in pixels. */ jpayne@69: int redrawX1, redrawY1; /* Upper left corner of area to redraw, in jpayne@69: * pixel coordinates. Border pixels are jpayne@69: * included. Only valid if REDRAW_PENDING flag jpayne@69: * is set. */ jpayne@69: int redrawX2, redrawY2; /* Lower right corner of area to redraw, in jpayne@69: * integer canvas coordinates. Border pixels jpayne@69: * will *not* be redrawn. */ jpayne@69: int confine; /* Non-zero means constrain view to keep as jpayne@69: * much of canvas visible as possible. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used to manage the selection and insertion cursor: jpayne@69: */ jpayne@69: jpayne@69: Tk_CanvasTextInfo textInfo; /* Contains lots of fields; see tk.h for jpayne@69: * details. This structure is shared with the jpayne@69: * code that implements individual items. */ jpayne@69: int insertOnTime; /* Number of milliseconds cursor should spend jpayne@69: * in "on" state for each blink. */ jpayne@69: int insertOffTime; /* Number of milliseconds cursor should spend jpayne@69: * in "off" state for each blink. */ jpayne@69: Tcl_TimerToken insertBlinkHandler; jpayne@69: /* Timer handler used to blink cursor on and jpayne@69: * off. */ jpayne@69: jpayne@69: /* jpayne@69: * Transformation applied to canvas as a whole: to compute screen jpayne@69: * coordinates (X,Y) from canvas coordinates (x,y), do the following: jpayne@69: * jpayne@69: * X = x - xOrigin; jpayne@69: * Y = y - yOrigin; jpayne@69: */ jpayne@69: jpayne@69: int xOrigin, yOrigin; /* Canvas coordinates corresponding to jpayne@69: * upper-left corner of window, given in jpayne@69: * canvas pixel units. */ jpayne@69: int drawableXOrigin, drawableYOrigin; jpayne@69: /* During redisplay, these fields give the jpayne@69: * canvas coordinates corresponding to the jpayne@69: * upper-left corner of the drawable where jpayne@69: * items are actually being drawn (typically a jpayne@69: * pixmap smaller than the whole window). */ jpayne@69: jpayne@69: /* jpayne@69: * Information used for event bindings associated with items. jpayne@69: */ jpayne@69: jpayne@69: Tk_BindingTable bindingTable; jpayne@69: /* Table of all bindings currently defined for jpayne@69: * this canvas. NULL means that no bindings jpayne@69: * exist, so the table hasn't been created. jpayne@69: * Each "object" used for this table is either jpayne@69: * a Tk_Uid for a tag or the address of an jpayne@69: * item named by id. */ jpayne@69: Tk_Item *currentItemPtr; /* The item currently containing the mouse jpayne@69: * pointer, or NULL if none. */ jpayne@69: Tk_Item *newCurrentPtr; /* The item that is about to become the jpayne@69: * current one, or NULL. This field is used to jpayne@69: * detect deletions of the new current item jpayne@69: * pointer that occur during Leave processing jpayne@69: * of the previous current item. */ jpayne@69: double closeEnough; /* The mouse is assumed to be inside an item jpayne@69: * if it is this close to it. */ jpayne@69: XEvent pickEvent; /* The event upon which the current choice of jpayne@69: * currentItem is based. Must be saved so that jpayne@69: * if the currentItem is deleted, can pick jpayne@69: * another. */ jpayne@69: int state; /* Last known modifier state. Used to defer jpayne@69: * picking a new current object while buttons jpayne@69: * are down. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used for managing scrollbars: jpayne@69: */ jpayne@69: jpayne@69: char *xScrollCmd; /* Command prefix for communicating with jpayne@69: * horizontal scrollbar. NULL means no jpayne@69: * horizontal scrollbar. Malloc'ed. */ jpayne@69: char *yScrollCmd; /* Command prefix for communicating with jpayne@69: * vertical scrollbar. NULL means no vertical jpayne@69: * scrollbar. Malloc'ed. */ jpayne@69: int scrollX1, scrollY1, scrollX2, scrollY2; jpayne@69: /* These four coordinates define the region jpayne@69: * that is the 100% area for scrolling (i.e. jpayne@69: * these numbers determine the size and jpayne@69: * location of the sliders on scrollbars). jpayne@69: * Units are pixels in canvas coords. */ jpayne@69: char *regionString; /* The option string from which scrollX1 etc. jpayne@69: * are derived. Malloc'ed. */ jpayne@69: int xScrollIncrement; /* If >0, defines a grid for horizontal jpayne@69: * scrolling. This is the size of the "unit", jpayne@69: * and the left edge of the screen will always jpayne@69: * lie on an even unit boundary. */ jpayne@69: int yScrollIncrement; /* If >0, defines a grid for horizontal jpayne@69: * scrolling. This is the size of the "unit", jpayne@69: * and the left edge of the screen will always jpayne@69: * lie on an even unit boundary. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used for scanning: jpayne@69: */ jpayne@69: jpayne@69: int scanX; /* X-position at which scan started (e.g. jpayne@69: * button was pressed here). */ jpayne@69: int scanXOrigin; /* Value of xOrigin field when scan started. */ jpayne@69: int scanY; /* Y-position at which scan started (e.g. jpayne@69: * button was pressed here). */ jpayne@69: int scanYOrigin; /* Value of yOrigin field when scan started. */ jpayne@69: jpayne@69: /* jpayne@69: * Information used to speed up searches by remembering the last item jpayne@69: * created or found with an item id search. jpayne@69: */ jpayne@69: jpayne@69: Tk_Item *hotPtr; /* Pointer to "hot" item (one that's been jpayne@69: * recently used. NULL means there's no hot jpayne@69: * item. */ jpayne@69: Tk_Item *hotPrevPtr; /* Pointer to predecessor to hotPtr (NULL jpayne@69: * means item is first in list). This is only jpayne@69: * a hint and may not really be hotPtr's jpayne@69: * predecessor. */ jpayne@69: jpayne@69: /* jpayne@69: * Miscellaneous information: jpayne@69: */ jpayne@69: jpayne@69: Tk_Cursor cursor; /* Current cursor for window, or NULL. */ jpayne@69: char *takeFocus; /* Value of -takefocus option; not used in the jpayne@69: * C code, but used by keyboard traversal jpayne@69: * scripts. Malloc'ed, but may be NULL. */ jpayne@69: double pixelsPerMM; /* Scale factor between MM and pixels; used jpayne@69: * when converting coordinates. */ jpayne@69: int flags; /* Various flags; see below for jpayne@69: * definitions. */ jpayne@69: int nextId; /* Number to use as id for next item created jpayne@69: * in widget. */ jpayne@69: Tk_PostscriptInfo psInfo; /* Pointer to information used for generating jpayne@69: * Postscript for the canvas. NULL means no jpayne@69: * Postscript is currently being generated. */ jpayne@69: Tcl_HashTable idTable; /* Table of integer indices. */ jpayne@69: jpayne@69: /* jpayne@69: * Additional information, added by the 'dash'-patch jpayne@69: */ jpayne@69: jpayne@69: void *reserved1; jpayne@69: Tk_State canvas_state; /* State of canvas. */ jpayne@69: void *reserved2; jpayne@69: void *reserved3; jpayne@69: Tk_TSOffset tsoffset; jpayne@69: #ifndef USE_OLD_TAG_SEARCH jpayne@69: TagSearchExpr *bindTagExprs;/* Linked list of tag expressions used in jpayne@69: * bindings. */ jpayne@69: #endif jpayne@69: } TkCanvas; jpayne@69: jpayne@69: /* jpayne@69: * Flag bits for canvases: jpayne@69: * jpayne@69: * REDRAW_PENDING - 1 means a DoWhenIdle handler has already been jpayne@69: * created to redraw some or all of the canvas. jpayne@69: * REDRAW_BORDERS - 1 means that the borders need to be redrawn jpayne@69: * during the next redisplay operation. jpayne@69: * REPICK_NEEDED - 1 means DisplayCanvas should pick a new jpayne@69: * current item before redrawing the canvas. jpayne@69: * GOT_FOCUS - 1 means the focus is currently in this widget, jpayne@69: * so should draw the insertion cursor and jpayne@69: * traversal highlight. jpayne@69: * CURSOR_ON - 1 means the insertion cursor is in the "on" jpayne@69: * phase of its blink cycle. 0 means either we jpayne@69: * don't have the focus or the cursor is in the jpayne@69: * "off" phase of its cycle. jpayne@69: * UPDATE_SCROLLBARS - 1 means the scrollbars should get updated as jpayne@69: * part of the next display operation. jpayne@69: * LEFT_GRABBED_ITEM - 1 means that the mouse left the current item jpayne@69: * while a grab was in effect, so we didn't jpayne@69: * change canvasPtr->currentItemPtr. jpayne@69: * REPICK_IN_PROGRESS - 1 means PickCurrentItem is currently jpayne@69: * executing. If it should be called recursively, jpayne@69: * it should simply return immediately. jpayne@69: * BBOX_NOT_EMPTY - 1 means that the bounding box of the area that jpayne@69: * should be redrawn is not empty. jpayne@69: */ jpayne@69: jpayne@69: #define REDRAW_PENDING 1 jpayne@69: #define REDRAW_BORDERS 2 jpayne@69: #define REPICK_NEEDED 4 jpayne@69: #define GOT_FOCUS 8 jpayne@69: #define CURSOR_ON 0x10 jpayne@69: #define UPDATE_SCROLLBARS 0x20 jpayne@69: #define LEFT_GRABBED_ITEM 0x40 jpayne@69: #define REPICK_IN_PROGRESS 0x100 jpayne@69: #define BBOX_NOT_EMPTY 0x200 jpayne@69: jpayne@69: /* jpayne@69: * Flag bits for canvas items (redraw_flags): jpayne@69: * jpayne@69: * FORCE_REDRAW - 1 means that the new coordinates of some item jpayne@69: * are not yet registered using jpayne@69: * Tk_CanvasEventuallyRedraw(). It should still jpayne@69: * be done by the general canvas code. jpayne@69: */ jpayne@69: jpayne@69: #define FORCE_REDRAW 8 jpayne@69: jpayne@69: /* jpayne@69: * Canvas-related functions that are shared among Tk modules but not exported jpayne@69: * to the outside world: jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE int TkCanvPostscriptCmd(TkCanvas *canvasPtr, jpayne@69: Tcl_Interp *interp, int argc, const char **argv); jpayne@69: MODULE_SCOPE int TkCanvTranslatePath(TkCanvas *canvPtr, jpayne@69: int numVertex, double *coordPtr, int closed, jpayne@69: XPoint *outPtr); jpayne@69: /* jpayne@69: * Standard item types provided by Tk: jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE Tk_ItemType tkArcType, tkBitmapType, tkImageType, tkLineType; jpayne@69: MODULE_SCOPE Tk_ItemType tkOvalType, tkPolygonType; jpayne@69: MODULE_SCOPE Tk_ItemType tkRectangleType, tkTextType, tkWindowType; jpayne@69: jpayne@69: /* jpayne@69: * Convenience macro. jpayne@69: */ jpayne@69: jpayne@69: #define Canvas(canvas) ((TkCanvas *) (canvas)) jpayne@69: jpayne@69: #endif /* _TKCANVAS */