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