1 /*
2  * tkCanvas.h --
3  *
4  *	Declarations shared among all the files that implement
5  *	canvas widgets.
6  *
7  * Copyright (c) 1991-1994 The Regents of the University of California.
8  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
9  * Copyright (c) 1998 by Scriptics Corporation.
10  *
11  * See the file "license.terms" for information on usage and redistribution
12  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13  *
14  * RCS: @(#) $Id: tkCanvas.h,v 1.7 2003/01/08 23:02:33 drh Exp $
15  */
16 
17 #ifndef _TKCANVAS
18 #define _TKCANVAS
19 
20 #ifndef _TK
21 #include "tk.h"
22 #endif
23 
24 #ifndef USE_OLD_TAG_SEARCH
25 typedef struct TagSearchExpr_s TagSearchExpr;
26 
27 struct TagSearchExpr_s {
28     TagSearchExpr *next;        /* for linked lists of expressions - used in 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 evaluation */
34     int match;                  /* this expression matches event's item's tags*/
35 };
36 #endif /* not USE_OLD_TAG_SEARCH */
37 
38 /*
39  * The record below describes a canvas widget.  It is made available
40  * to the item procedures so they can access certain shared fields such
41  * as the overall displacement and scale factor for the canvas.
42  */
43 
44 typedef struct TkCanvas {
45     Tk_Window tkwin;		/* Window that embodies the canvas.  NULL
46 				 * means that the window has been destroyed
47 				 * but the data structures haven't yet been
48 				 * cleaned 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,
55 				 * or NULL if canvas empty. */
56     Tk_Item *lastItemPtr;	/* Last in list of all items in canvas,
57 				 * or 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
68 				 * around widget when it has the focus.
69 				 * <= 0 means don't draw a highlight. */
70     XColor *highlightBgColorPtr;
71 				/* Color for drawing traversal highlight
72 				 * area 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
77 				 * be offset from outside edges to leave
78 				 * room for 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,
84 				 * in pixel coordinates.  Border pixels
85 				 * are included.  Only valid if
86 				 * REDRAW_PENDING flag is set. */
87     int redrawX2, redrawY2;	/* Lower right corner of area to redraw,
88 				 * in integer canvas coordinates.  Border
89 				 * pixels will *not* be redrawn. */
90     int confine;		/* Non-zero means constrain view to keep
91 				 * as 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
99 				 * the 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
122 				 * the upper-left corner of the drawable
123 				 * where items are actually being drawn
124 				 * (typically a pixmap smaller than the
125 				 * whole window). */
126 
127     /*
128      * Information used for event bindings associated with items.
129      */
130 
131     Tk_BindingTable bindingTable;
132 				/* Table of all bindings currently defined
133 				 * for this canvas.  NULL means that no
134 				 * bindings exist, so the table hasn't been
135 				 * created.  Each "object" used for this
136 				 * table is either a Tk_Uid for a tag or
137 				 * the address of an item named by id. */
138     Tk_Item *currentItemPtr;	/* The item currently containing the mouse
139 				 * pointer, or NULL if none. */
140     Tk_Item *newCurrentPtr;	/* The item that is about to become the
141 				 * current one, or NULL.  This field is
142 				 * used to detect deletions  of the new
143 				 * current item pointer that occur during
144 				 * Leave processing of the previous current
145 				 * item.  */
146     double closeEnough;		/* The mouse is assumed to be inside an
147 				 * item if it is this close to it. */
148     XEvent pickEvent;		/* The event upon which the current choice
149 				 * of currentItem is based.  Must be saved
150 				 * so that if the currentItem is deleted,
151 				 * can pick another. */
152     int state;			/* Last known modifier state.  Used to
153 				 * defer picking a new current object
154 				 * while buttons are down. */
155 
156     /*
157      * Information used for managing scrollbars:
158      */
159 
160     LangCallback *xScrollCmd;	/* Command prefix for communicating with
161 				 * horizontal scrollbar.  NULL means no
162 				 * horizontal scrollbar.  Malloc'ed*/
163     LangCallback *yScrollCmd;	/* Command prefix for communicating with
164 				 * vertical scrollbar.  NULL means no
165 				 * vertical 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     Tcl_Obj * regionArg;		/* The option string from which scrollX1
173 				 * etc. 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
201 				 * hot item. */
202     Tk_Item *hotPrevPtr;	/* Pointer to predecessor to hotPtr (NULL
203 				 * means item is first in list).  This is
204 				 * only 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
213 				 * the C code, but used by keyboard traversal
214 				 * scripts.  Malloc'ed, but may be NULL. */
215     double pixelsPerMM;		/* Scale factor between MM and pixels;
216 				 * used when converting coordinates. */
217     int flags;			/* Various flags;  see below for
218 				 * definitions. */
219     int nextId;			/* Number to use as id for next item
220 				 * created in widget. */
221     Tk_PostscriptInfo psInfo;
222 				/* Pointer to information used for generating
223 				 * Postscript for the canvas.  NULL means
224 				 * no Postscript is currently being
225 				 * generated. */
226     Tcl_HashTable idTable;	/* Table of integer indices. */
227     /*
228      * Additional information, added by the 'dash'-patch
229      */
230     Tk_State canvas_state;	/* state of canvas */
231     Tk_Tile tile;
232     Tk_Tile disabledTile;
233     Tk_TSOffset tsoffset;
234 #ifndef USE_OLD_TAG_SEARCH
235     TagSearchExpr *bindTagExprs; /* linked list of tag expressions used in bindings */
236 #endif
237     /* pTk additions */
238     Tk_Item *activeGroup;		/* Which group item is active */
239     Tcl_Obj *updateCmds;
240 } TkCanvas;
241 
242 /*
243  * Flag bits for canvases:
244  *
245  * REDRAW_PENDING -		1 means a DoWhenIdle handler has already
246  *				been created to redraw some or all of the
247  *				canvas.
248  * REDRAW_BORDERS - 		1 means that the borders need to be redrawn
249  *				during the next redisplay operation.
250  * REPICK_NEEDED -		1 means DisplayCanvas should pick a new
251  *				current item before redrawing the canvas.
252  * GOT_FOCUS -			1 means the focus is currently in this
253  *				widget, so should draw the insertion cursor
254  *				and traversal highlight.
255  * CURSOR_ON -			1 means the insertion cursor is in the "on"
256  *				phase of its blink cycle.  0 means either
257  *				we don't have the focus or the cursor is in
258  *				the "off" phase of its cycle.
259  * UPDATE_SCROLLBARS -		1 means the scrollbars should get updated
260  *				as part of the next display operation.
261  * LEFT_GRABBED_ITEM -		1 means that the mouse left the current
262  *				item while a grab was in effect, so we
263  *				didn't change canvasPtr->currentItemPtr.
264  * REPICK_IN_PROGRESS -		1 means PickCurrentItem is currently
265  *				executing.  If it should be called recursively,
266  *				it should simply return immediately.
267  * BBOX_NOT_EMPTY -		1 means that the bounding box of the area
268  *				that should be redrawn is not empty.
269  */
270 
271 #define REDRAW_PENDING		1
272 #define REDRAW_BORDERS		2
273 #define REPICK_NEEDED		4
274 #define GOT_FOCUS		8
275 #define CURSOR_ON		0x10
276 #define UPDATE_SCROLLBARS	0x20
277 #define LEFT_GRABBED_ITEM	0x40
278 #define REPICK_IN_PROGRESS	0x100
279 #define BBOX_NOT_EMPTY		0x200
280 
281 /*
282  * Flag bits for canvas items (redraw_flags):
283  *
284  * FORCE_REDRAW -		1 means that the new coordinates of some
285  *				item are not yet registered using
286  *				Tk_CanvasEventuallyRedraw(). It should still
287  *				be done by the general canvas code.
288  */
289 
290 #define FORCE_REDRAW		8
291 #define NEEDS_DISPLAY		16
292 
293 /*
294  * Canvas-related procedures that are shared among Tk modules but not
295  * exported to the outside world:
296  */
297 
298 extern int		TkCanvPostscriptCmd _ANSI_ARGS_((TkCanvas *canvasPtr,
299 			    Tcl_Interp *interp, int argc, CONST84 Tcl_Obj *CONST *objv));
300 
301 /*
302  * Other procedures that are shared among Tk canvas modules but not exported
303  * to the outside world:
304  */
305 extern int 		TkCanvTranslatePath _ANSI_ARGS_((TkCanvas *canvPtr,
306 			    int numVertex, double *coordPtr, int closed,
307 			    XPoint *outPtr));
308 
309 
310 #define Tk_CanvasActiveGroup(canvas) ((TkCanvas *) (canvas))->activeGroup
311 
312 #define Tk_CanvasGroupHidden(canvas,itemPtr) (             \
313  ( Tk_CanvasActiveGroup(canvas) &&                         \
314    (itemPtr)->group != Tk_CanvasActiveGroup(canvas)) ||    \
315  ( (itemPtr)->group &&                                     \
316    (itemPtr)->group != Tk_CanvasActiveGroup(canvas) &&     \
317    (itemPtr)->group->state != TK_STATE_ACTIVE ))
318 
319 #define Tk_GetItemState(canvas,itemPtr)                    \
320 (                                                          \
321  (0 && Tk_CanvasGroupHidden(canvas,itemPtr))               \
322   ? TK_STATE_HIDDEN                                        \
323   : (((itemPtr)->state == TK_STATE_NULL)                   \
324     ? ((TkCanvas *)(canvas))->canvas_state                 \
325     : (itemPtr)->state                                     \
326     )                                                      \
327 )
328 
329 EXTERN void		TkGroupRemoveItem _ANSI_ARGS_((Tk_Item *item));
330 
331 #endif /* _TKCANVAS */
332 
333 
334 
335