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