tkCanvas.h 11 KB

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