tkEntry.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * tkEntry.h --
  3. *
  4. * This module defined the structures for the Entry & SpinBox widgets.
  5. *
  6. * See the file "license.terms" for information on usage and redistribution of
  7. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  8. *
  9. * Copyright (c) 2002 Apple Inc.
  10. */
  11. #ifndef _TKENTRY
  12. #define _TKENTRY
  13. #ifndef _TKINT
  14. #include "tkInt.h"
  15. #endif
  16. enum EntryType {
  17. TK_ENTRY, TK_SPINBOX
  18. };
  19. /*
  20. * A data structure of the following type is kept for each Entry widget
  21. * managed by this file:
  22. */
  23. typedef struct {
  24. Tk_Window tkwin; /* Window that embodies the entry. NULL means
  25. * that the window has been destroyed but the
  26. * data structures haven't yet been cleaned
  27. * up.*/
  28. Display *display; /* Display containing widget. Used, among
  29. * other things, so that resources can be
  30. * freed even after tkwin has gone away. */
  31. Tcl_Interp *interp; /* Interpreter associated with entry. */
  32. Tcl_Command widgetCmd; /* Token for entry's widget command. */
  33. Tk_OptionTable optionTable; /* Table that defines configuration options
  34. * available for this widget. */
  35. enum EntryType type; /* Specialized type of Entry widget */
  36. /*
  37. * Fields that are set by widget commands other than "configure".
  38. */
  39. const char *string; /* Pointer to storage for string;
  40. * NULL-terminated; malloc-ed. */
  41. int insertPos; /* Character index before which next typed
  42. * character will be inserted. */
  43. /*
  44. * Information about what's selected, if any.
  45. */
  46. int selectFirst; /* Character index of first selected character
  47. * (-1 means nothing selected. */
  48. int selectLast; /* Character index just after last selected
  49. * character (-1 means nothing selected. */
  50. int selectAnchor; /* Fixed end of selection (i.e. "select to"
  51. * operation will use this as one end of the
  52. * selection). */
  53. /*
  54. * Information for scanning:
  55. */
  56. int scanMarkX; /* X-position at which scan started (e.g.
  57. * button was pressed here). */
  58. int scanMarkIndex; /* Character index of character that was at
  59. * left of window when scan started. */
  60. /*
  61. * Configuration settings that are updated by Tk_ConfigureWidget.
  62. */
  63. Tk_3DBorder normalBorder; /* Used for drawing border around whole
  64. * window, plus used for background. */
  65. Tk_3DBorder disabledBorder; /* Used for drawing border around whole window
  66. * in disabled state, plus used for
  67. * background. */
  68. Tk_3DBorder readonlyBorder; /* Used for drawing border around whole window
  69. * in readonly state, plus used for
  70. * background. */
  71. int borderWidth; /* Width of 3-D border around window. */
  72. Tk_Cursor cursor; /* Current cursor for window, or NULL. */
  73. int exportSelection; /* Non-zero means tie internal entry selection
  74. * to X selection. */
  75. Tk_Font tkfont; /* Information about text font, or NULL. */
  76. XColor *fgColorPtr; /* Text color in normal mode. */
  77. XColor *dfgColorPtr; /* Text color in disabled mode. */
  78. XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area
  79. * when highlight is off. */
  80. XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
  81. int highlightWidth; /* Width in pixels of highlight to draw around
  82. * widget when it has the focus. <= 0 means
  83. * don't draw a highlight. */
  84. Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion
  85. * cursor. */
  86. int insertBorderWidth; /* Width of 3-D border around insert cursor. */
  87. int insertOffTime; /* Number of milliseconds cursor should spend
  88. * in "off" state for each blink. */
  89. int insertOnTime; /* Number of milliseconds cursor should spend
  90. * in "on" state for each blink. */
  91. int insertWidth; /* Total width of insert cursor. */
  92. Tk_Justify justify; /* Justification to use for text within
  93. * window. */
  94. int relief; /* 3-D effect: TK_RELIEF_RAISED, etc. */
  95. Tk_3DBorder selBorder; /* Border and background for selected
  96. * characters. */
  97. int selBorderWidth; /* Width of border around selection. */
  98. XColor *selFgColorPtr; /* Foreground color for selected text. */
  99. int state; /* Normal or disabled. Entry is read-only when
  100. * disabled. */
  101. char *textVarName; /* Name of variable (malloc'ed) or NULL. If
  102. * non-NULL, entry's string tracks the
  103. * contents of this variable and vice
  104. * versa. */
  105. char *takeFocus; /* Value of -takefocus option; not used in the
  106. * C code, but used by keyboard traversal
  107. * scripts. Malloc'ed, but may be NULL. */
  108. int prefWidth; /* Desired width of window, measured in
  109. * average characters. */
  110. char *scrollCmd; /* Command prefix for communicating with
  111. * scrollbar(s). Malloc'ed. NULL means no
  112. * command to issue. */
  113. char *showChar; /* Value of -show option. If non-NULL, first
  114. * character is used for displaying all
  115. * characters in entry. Malloc'ed. This is
  116. * only used by the Entry widget. */
  117. /*
  118. * Fields whose values are derived from the current values of the
  119. * configuration settings above.
  120. */
  121. const char *displayString; /* String to use when displaying. This may be
  122. * a pointer to string, or a pointer to
  123. * malloced memory with the same character
  124. * length as string but whose characters are
  125. * all equal to showChar. */
  126. int numBytes; /* Length of string in bytes. */
  127. int numChars; /* Length of string in characters. Both string
  128. * and displayString have the same character
  129. * length, but may have different byte lengths
  130. * due to being made from different UTF-8
  131. * characters. */
  132. int numDisplayBytes; /* Length of displayString in bytes. */
  133. int inset; /* Number of pixels on the left and right
  134. * sides that are taken up by XPAD,
  135. * borderWidth (if any), and highlightWidth
  136. * (if any). */
  137. Tk_TextLayout textLayout; /* Cached text layout information. */
  138. int layoutX, layoutY; /* Origin for layout. */
  139. int leftX; /* X position at which character at leftIndex
  140. * is drawn (varies depending on justify). */
  141. int leftIndex; /* Character index of left-most character
  142. * visible in window. */
  143. Tcl_TimerToken insertBlinkHandler;
  144. /* Timer handler used to blink cursor on and
  145. * off. */
  146. GC textGC; /* For drawing normal text. */
  147. GC selTextGC; /* For drawing selected text. */
  148. GC highlightGC; /* For drawing traversal highlight. */
  149. int avgWidth; /* Width of average character. */
  150. int xWidth; /* Extra width to reserve for widget. Used by
  151. * spinboxes for button space. */
  152. int flags; /* Miscellaneous flags; see below for
  153. * definitions. */
  154. int validate; /* Non-zero means try to validate */
  155. char *validateCmd; /* Command prefix to use when invoking
  156. * validate command. NULL means don't invoke
  157. * commands. Malloc'ed. */
  158. char *invalidCmd; /* Command called when a validation returns 0
  159. * (successfully fails), defaults to {}. */
  160. } Entry;
  161. /*
  162. * A data structure of the following type is kept for each spinbox widget
  163. * managed by this file:
  164. */
  165. typedef struct {
  166. Entry entry; /* A pointer to the generic entry structure.
  167. * This must be the first element of the
  168. * Spinbox. */
  169. /*
  170. * Spinbox specific configuration settings.
  171. */
  172. Tk_3DBorder activeBorder; /* Used for drawing border around active
  173. * buttons. */
  174. Tk_3DBorder buttonBorder; /* Used for drawing border around buttons. */
  175. Tk_Cursor bCursor; /* cursor for buttons, or NULL. */
  176. int bdRelief; /* 3-D effect: TK_RELIEF_RAISED, etc. */
  177. int buRelief; /* 3-D effect: TK_RELIEF_RAISED, etc. */
  178. char *command; /* Command to invoke for spin buttons. NULL
  179. * means no command to issue. */
  180. /*
  181. * Spinbox specific fields for use with configuration settings above.
  182. */
  183. int wrap; /* whether to wrap around when spinning */
  184. int selElement; /* currently selected control */
  185. int curElement; /* currently mouseover control */
  186. int repeatDelay; /* repeat delay */
  187. int repeatInterval; /* repeat interval */
  188. double fromValue; /* Value corresponding to left/top of dial */
  189. double toValue; /* Value corresponding to right/bottom of
  190. * dial */
  191. double increment; /* If > 0, all values are rounded to an even
  192. * multiple of this value. */
  193. char *formatBuf; /* string into which to format value.
  194. * Malloc'ed. */
  195. char *reqFormat; /* Sprintf conversion specifier used for the
  196. * value that the users requests. Malloc'ed */
  197. char *valueFormat; /* Sprintf conversion specifier used for the
  198. * value. */
  199. char digitFormat[16]; /* Sprintf conversion specifier computed from
  200. * digits and other information; used for the
  201. * value. */
  202. char *valueStr; /* Values List. Malloc'ed. */
  203. Tcl_Obj *listObj; /* Pointer to the list object being used */
  204. int eIndex; /* Holds the current index into elements */
  205. int nElements; /* Holds the current count of elements */
  206. } Spinbox;
  207. /*
  208. * Assigned bits of "flags" fields of Entry structures, and what those bits
  209. * mean:
  210. *
  211. * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
  212. * already been queued to redisplay the entry.
  213. * BORDER_NEEDED: Non-zero means 3-D border must be redrawn
  214. * around window during redisplay. Normally only
  215. * text portion needs to be redrawn.
  216. * CURSOR_ON: Non-zero means insert cursor is displayed at
  217. * present. 0 means it isn't displayed.
  218. * GOT_FOCUS: Non-zero means this window has the input
  219. * focus.
  220. * UPDATE_SCROLLBAR: Non-zero means scrollbar should be updated
  221. * during next redisplay operation.
  222. * GOT_SELECTION: Non-zero means we've claimed the selection.
  223. * ENTRY_DELETED: This entry has been effectively destroyed.
  224. * VALIDATING: Non-zero means we are in a validateCmd
  225. * VALIDATE_VAR: Non-zero means we are attempting to validate
  226. * the entry's textvariable with validateCmd
  227. * VALIDATE_ABORT: Non-zero if validatecommand signals an abort
  228. * for current procedure and make no changes
  229. * ENTRY_VAR_TRACED: Non-zero if a var trace is set.
  230. */
  231. #define REDRAW_PENDING 1
  232. #define BORDER_NEEDED 2
  233. #define CURSOR_ON 4
  234. #define GOT_FOCUS 8
  235. #define UPDATE_SCROLLBAR 0x10
  236. #define GOT_SELECTION 0x20
  237. #define ENTRY_DELETED 0x40
  238. #define VALIDATING 0x80
  239. #define VALIDATE_VAR 0x100
  240. #define VALIDATE_ABORT 0x200
  241. #define ENTRY_VAR_TRACED 0x400
  242. /*
  243. * The following enum is used to define a type for the -state option of the
  244. * Entry widget. These values are used as indices into the string table below.
  245. */
  246. enum state {
  247. STATE_DISABLED, STATE_NORMAL, STATE_READONLY
  248. };
  249. /*
  250. * This is the element index corresponding to the strings in selElementNames.
  251. * If you modify them, you must modify the numbers here.
  252. */
  253. enum selelement {
  254. SEL_NONE, SEL_BUTTONDOWN, SEL_BUTTONUP, SEL_NULL, SEL_ENTRY
  255. };
  256. /*
  257. * Declaration of functions used in the implementation of the native side of
  258. * the Entry widget.
  259. */
  260. MODULE_SCOPE int TkpDrawEntryBorderAndFocus(Entry *entryPtr,
  261. Drawable d, int isSpinbox);
  262. MODULE_SCOPE int TkpDrawSpinboxButtons(Spinbox *sbPtr, Drawable d);
  263. #endif /* _TKENTRY */