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