1/*
2 * tkCanvas.h --
3 *
4 *	Declarations shared among all the files that implement canvas widgets.
5 *
6 * Copyright (c) 1991-1994 The Regents of the University of California.
7 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
8 * Copyright (c) 1998 by Scriptics Corporation.
9 *
10 * See the file "license.terms" for information on usage and redistribution of
11 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id$
14 */
15
16#ifndef _TKCANVAS
17#define _TKCANVAS
18
19#ifndef _TK
20#include "tk.h"
21#endif
22
23#ifndef USE_OLD_TAG_SEARCH
24typedef struct TagSearchExpr_s TagSearchExpr;
25
26struct TagSearchExpr_s {
27    TagSearchExpr *next;	/* For linked lists of expressions - used in
28				 * bindings. */
29    Tk_Uid uid;			/* The uid of the whole expression. */
30    Tk_Uid *uids;		/* Expresion compiled to an array of uids. */
31    int allocated;		/* Available space for array of uids. */
32    int length;			/* Length of expression. */
33    int index;			/* Current position in expression
34				 * evaluation. */
35    int match;			/* This expression matches event's item's
36				 * tags. */
37};
38#endif /* not USE_OLD_TAG_SEARCH */
39
40/*
41 * The record below describes a canvas widget. It is made available to the
42 * item functions so they can access certain shared fields such as the overall
43 * displacement and scale factor for the canvas.
44 */
45
46typedef struct TkCanvas {
47    Tk_Window tkwin;		/* Window that embodies the canvas. NULL means
48				 * that the window has been destroyed but the
49				 * data structures haven't yet been cleaned
50				 * up.*/
51    Display *display;		/* Display containing widget; needed, among
52				 * other things, to release resources after
53				 * tkwin has already gone away. */
54    Tcl_Interp *interp;		/* Interpreter associated with canvas. */
55    Tcl_Command widgetCmd;	/* Token for canvas's widget command. */
56    Tk_Item *firstItemPtr;	/* First in list of all items in canvas, or
57				 * NULL if canvas empty. */
58    Tk_Item *lastItemPtr;	/* Last in list of all items in canvas, or
59				 * NULL if canvas empty. */
60
61    /*
62     * Information used when displaying widget:
63     */
64
65    int borderWidth;		/* Width of 3-D border around window. */
66    Tk_3DBorder bgBorder;	/* Used for canvas background. */
67    int relief;			/* Indicates whether window as a whole is
68				 * raised, sunken, or flat. */
69    int highlightWidth;		/* Width in pixels of highlight to draw around
70				 * widget when it has the focus. <= 0 means
71				 * don't draw a highlight. */
72    XColor *highlightBgColorPtr;
73				/* Color for drawing traversal highlight area
74				 * when highlight is off. */
75    XColor *highlightColorPtr;	/* Color for drawing traversal highlight. */
76    int inset;			/* Total width of all borders, including
77				 * traversal highlight and 3-D border.
78				 * Indicates how much interior stuff must be
79				 * offset from outside edges to leave room for
80				 * borders. */
81    GC pixmapGC;		/* Used to copy bits from a pixmap to the
82				 * screen and also to clear the pixmap. */
83    int width, height;		/* Dimensions to request for canvas window,
84				 * specified in pixels. */
85    int redrawX1, redrawY1;	/* Upper left corner of area to redraw, in
86				 * pixel coordinates. Border pixels are
87				 * included. Only valid if REDRAW_PENDING flag
88				 * is set. */
89    int redrawX2, redrawY2;	/* Lower right corner of area to redraw, in
90				 * integer canvas coordinates. Border pixels
91				 * will *not* be redrawn. */
92    int confine;		/* Non-zero means constrain view to keep as
93				 * much of canvas visible as possible. */
94
95    /*
96     * Information used to manage the selection and insertion cursor:
97     */
98
99    Tk_CanvasTextInfo textInfo; /* Contains lots of fields; see tk.h for
100				 * details. This structure is shared with the
101				 * code that implements individual items. */
102    int insertOnTime;		/* Number of milliseconds cursor should spend
103				 * in "on" state for each blink. */
104    int insertOffTime;		/* Number of milliseconds cursor should spend
105				 * in "off" state for each blink. */
106    Tcl_TimerToken insertBlinkHandler;
107				/* Timer handler used to blink cursor on and
108				 * off. */
109
110    /*
111     * Transformation applied to canvas as a whole: to compute screen
112     * coordinates (X,Y) from canvas coordinates (x,y), do the following:
113     *
114     * X = x - xOrigin;
115     * Y = y - yOrigin;
116     */
117
118    int xOrigin, yOrigin;	/* Canvas coordinates corresponding to
119				 * upper-left corner of window, given in
120				 * canvas pixel units. */
121    int drawableXOrigin, drawableYOrigin;
122				/* During redisplay, these fields give the
123				 * canvas coordinates corresponding to the
124				 * upper-left corner of the drawable where
125				 * items are actually being drawn (typically a
126				 * pixmap smaller than the whole window). */
127
128    /*
129     * Information used for event bindings associated with items.
130     */
131
132    Tk_BindingTable bindingTable;
133				/* Table of all bindings currently defined for
134				 * this canvas. NULL means that no bindings
135				 * exist, so the table hasn't been created.
136				 * Each "object" used for this table is either
137				 * a Tk_Uid for a tag or the address of an
138				 * item named by id. */
139    Tk_Item *currentItemPtr;	/* The item currently containing the mouse
140				 * pointer, or NULL if none. */
141    Tk_Item *newCurrentPtr;	/* The item that is about to become the
142				 * current one, or NULL. This field is used to
143				 * detect deletions of the new current item
144				 * pointer that occur during Leave processing
145				 * of the previous current item. */
146    double closeEnough;		/* The mouse is assumed to be inside an item
147				 * if it is this close to it. */
148    XEvent pickEvent;		/* The event upon which the current choice of
149				 * currentItem is based. Must be saved so that
150				 * if the currentItem is deleted, can pick
151				 * another. */
152    int state;			/* Last known modifier state. Used to defer
153				 * picking a new current object while buttons
154				 * are down. */
155
156    /*
157     * Information used for managing scrollbars:
158     */
159
160    char *xScrollCmd;		/* Command prefix for communicating with
161				 * horizontal scrollbar. NULL means no
162				 * horizontal scrollbar. Malloc'ed. */
163    char *yScrollCmd;		/* Command prefix for communicating with
164				 * vertical scrollbar. NULL means no vertical
165				 * scrollbar. Malloc'ed. */
166    int scrollX1, scrollY1, scrollX2, scrollY2;
167				/* These four coordinates define the region
168				 * that is the 100% area for scrolling (i.e.
169				 * these numbers determine the size and
170				 * location of the sliders on scrollbars).
171				 * Units are pixels in canvas coords. */
172    char *regionString;		/* The option string from which scrollX1 etc.
173				 * are derived. Malloc'ed. */
174    int xScrollIncrement;	/* If >0, defines a grid for horizontal
175				 * scrolling. This is the size of the "unit",
176				 * and the left edge of the screen will always
177				 * lie on an even unit boundary. */
178    int yScrollIncrement;	/* If >0, defines a grid for horizontal
179				 * scrolling. This is the size of the "unit",
180				 * and the left edge of the screen will always
181				 * lie on an even unit boundary. */
182
183    /*
184     * Information used for scanning:
185     */
186
187    int scanX;			/* X-position at which scan started (e.g.
188				 * button was pressed here). */
189    int scanXOrigin;		/* Value of xOrigin field when scan started. */
190    int scanY;			/* Y-position at which scan started (e.g.
191				 * button was pressed here). */
192    int scanYOrigin;		/* Value of yOrigin field when scan started. */
193
194    /*
195     * Information used to speed up searches by remembering the last item
196     * created or found with an item id search.
197     */
198
199    Tk_Item *hotPtr;		/* Pointer to "hot" item (one that's been
200				 * recently used. NULL means there's no hot
201				 * item. */
202    Tk_Item *hotPrevPtr;	/* Pointer to predecessor to hotPtr (NULL
203				 * means item is first in list). This is only
204				 * a hint and may not really be hotPtr's
205				 * predecessor. */
206
207    /*
208     * Miscellaneous information:
209     */
210
211    Tk_Cursor cursor;		/* Current cursor for window, or None. */
212    char *takeFocus;		/* Value of -takefocus option; not used in the
213				 * C code, but used by keyboard traversal
214				 * scripts. Malloc'ed, but may be NULL. */
215    double pixelsPerMM;		/* Scale factor between MM and pixels; used
216				 * when converting coordinates. */
217    int flags;			/* Various flags; see below for
218				 * definitions. */
219    int nextId;			/* Number to use as id for next item created
220				 * in widget. */
221    Tk_PostscriptInfo psInfo;	/* Pointer to information used for generating
222				 * Postscript for the canvas. NULL means no
223				 * Postscript is currently being generated. */
224    Tcl_HashTable idTable;	/* Table of integer indices. */
225
226    /*
227     * Additional information, added by the 'dash'-patch
228     */
229
230    void *reserved1;
231    Tk_State canvas_state;	/* State of canvas. */
232    void *reserved2;
233    void *reserved3;
234    Tk_TSOffset tsoffset;
235#ifndef USE_OLD_TAG_SEARCH
236    TagSearchExpr *bindTagExprs;/* Linked list of tag expressions used in
237				 * bindings. */
238#endif
239} TkCanvas;
240
241/*
242 * Flag bits for canvases:
243 *
244 * REDRAW_PENDING -		1 means a DoWhenIdle handler has already been
245 *				created to redraw some or all of the canvas.
246 * REDRAW_BORDERS - 		1 means that the borders need to be redrawn
247 *				during the next redisplay operation.
248 * REPICK_NEEDED -		1 means DisplayCanvas should pick a new
249 *				current item before redrawing the canvas.
250 * GOT_FOCUS -			1 means the focus is currently in this widget,
251 *				so should draw the insertion cursor and
252 *				traversal highlight.
253 * CURSOR_ON -			1 means the insertion cursor is in the "on"
254 *				phase of its blink cycle. 0 means either we
255 *				don't have the focus or the cursor is in the
256 *				"off" phase of its cycle.
257 * UPDATE_SCROLLBARS -		1 means the scrollbars should get updated as
258 *				part of the next display operation.
259 * LEFT_GRABBED_ITEM -		1 means that the mouse left the current item
260 *				while a grab was in effect, so we didn't
261 *				change canvasPtr->currentItemPtr.
262 * REPICK_IN_PROGRESS -		1 means PickCurrentItem is currently
263 *				executing. If it should be called recursively,
264 *				it should simply return immediately.
265 * BBOX_NOT_EMPTY -		1 means that the bounding box of the area that
266 *				should be redrawn is not empty.
267 */
268
269#define REDRAW_PENDING		1
270#define REDRAW_BORDERS		2
271#define REPICK_NEEDED		4
272#define GOT_FOCUS		8
273#define CURSOR_ON		0x10
274#define UPDATE_SCROLLBARS	0x20
275#define LEFT_GRABBED_ITEM	0x40
276#define REPICK_IN_PROGRESS	0x100
277#define BBOX_NOT_EMPTY		0x200
278
279/*
280 * Flag bits for canvas items (redraw_flags):
281 *
282 * FORCE_REDRAW -		1 means that the new coordinates of some item
283 *				are not yet registered using
284 *				Tk_CanvasEventuallyRedraw(). It should still
285 *				be done by the general canvas code.
286 */
287
288#define FORCE_REDRAW		8
289
290/*
291 * Canvas-related functions that are shared among Tk modules but not exported
292 * to the outside world:
293 */
294
295MODULE_SCOPE int	TkCanvPostscriptCmd(TkCanvas *canvasPtr,
296			    Tcl_Interp *interp, int argc, CONST char **argv);
297MODULE_SCOPE int 	TkCanvTranslatePath(TkCanvas *canvPtr,
298			    int numVertex, double *coordPtr, int closed,
299			    XPoint *outPtr);
300/*
301 * Standard item types provided by Tk:
302 */
303
304MODULE_SCOPE Tk_ItemType tkArcType, tkBitmapType, tkImageType, tkLineType;
305MODULE_SCOPE Tk_ItemType tkOvalType, tkPolygonType;
306MODULE_SCOPE Tk_ItemType tkRectangleType, tkTextType, tkWindowType;
307
308#endif /* _TKCANVAS */
309