1/* 2 * tkButton.h -- 3 * 4 * Declarations of types and functions used to implement button-like 5 * widgets. 6 * 7 * Copyright (c) 1996-1998 by Sun Microsystems, Inc. 8 * 9 * See the file "license.terms" for information on usage and redistribution of 10 * this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * 12 * RCS: @(#) $Id$ 13 */ 14 15#ifndef _TKBUTTON 16#define _TKBUTTON 17 18#ifndef _TKINT 19#include "tkInt.h" 20#endif 21 22#ifdef BUILD_tk 23# undef TCL_STORAGE_CLASS 24# define TCL_STORAGE_CLASS DLLEXPORT 25#endif 26 27/* 28 * Legal values for the "compound" field of TkButton records. 29 */ 30 31enum compound { 32 COMPOUND_BOTTOM, COMPOUND_CENTER, COMPOUND_LEFT, COMPOUND_NONE, 33 COMPOUND_RIGHT, COMPOUND_TOP 34}; 35 36/* 37 * Legal values for the "state" field of TkButton records. 38 */ 39 40enum state { 41 STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL 42}; 43 44/* 45 * Legal values for the "defaultState" field of TkButton records. 46 */ 47 48enum defaultState { 49 DEFAULT_ACTIVE, DEFAULT_DISABLED, DEFAULT_NORMAL 50}; 51 52/* 53 * A data structure of the following type is kept for each widget managed by 54 * this file: 55 */ 56 57typedef struct { 58 Tk_Window tkwin; /* Window that embodies the button. NULL means 59 * that the window has been destroyed. */ 60 Display *display; /* Display containing widget. Needed to free 61 * up resources after tkwin is gone. */ 62 Tcl_Interp *interp; /* Interpreter associated with button. */ 63 Tcl_Command widgetCmd; /* Token for button's widget command. */ 64 int type; /* Type of widget, such as TYPE_LABEL: 65 * restricts operations that may be performed 66 * on widget. See below for legal values. */ 67 Tk_OptionTable optionTable; /* Table that defines configuration options 68 * available for this widget. */ 69 70 /* 71 * Information about what's in the button. 72 */ 73 74 Tcl_Obj *textPtr; /* Value of -text option: specifies text to 75 * display in button. */ 76 int underline; /* Value of -underline option: specifies index 77 * of character to underline. < 0 means don't 78 * underline anything. */ 79 Tcl_Obj *textVarNamePtr; /* Value of -textvariable option: specifies 80 * name of variable or NULL. If non-NULL, 81 * button displays the contents of this 82 * variable. */ 83 Pixmap bitmap; /* Value of -bitmap option. If not None, 84 * specifies bitmap to display and text and 85 * textVar are ignored. */ 86 Tcl_Obj *imagePtr; /* Value of -image option: specifies image to 87 * display in window, or NULL if none. If 88 * non-NULL, bitmap, text, and textVarName are 89 * ignored.*/ 90 Tk_Image image; /* Derived from imagePtr by calling 91 * Tk_GetImage, or NULL if imagePtr is 92 * NULL. */ 93 Tcl_Obj *selectImagePtr; /* Value of -selectimage option: specifies 94 * image to display in window when selected, 95 * or NULL if none. Ignored if imagePtr is 96 * NULL. */ 97 Tk_Image selectImage; /* Derived from selectImagePtr by calling 98 * Tk_GetImage, or NULL if selectImagePtr is 99 * NULL. */ 100 Tcl_Obj *tristateImagePtr; /* Value of -tristateimage option: specifies 101 * image to display in window when selected, 102 * or NULL if none. Ignored if imagePtr is 103 * NULL. */ 104 Tk_Image tristateImage; /* Derived from tristateImagePtr by calling 105 * Tk_GetImage, or NULL if tristateImagePtr is 106 * NULL. */ 107 108 /* 109 * Information used when displaying widget: 110 */ 111 112 enum state state; /* Value of -state option: specifies state of 113 * button for display purposes.*/ 114 Tk_3DBorder normalBorder; /* Value of -background option: specifies 115 * color for background (and border) when 116 * window isn't active. */ 117 Tk_3DBorder activeBorder; /* Value of -activebackground option: this is 118 * the color used to draw 3-D border and 119 * background when widget is active. */ 120 Tcl_Obj *borderWidthPtr; /* Value of -borderWidth option: specifies 121 * width of border in pixels. */ 122 int borderWidth; /* Integer value corresponding to 123 * borderWidthPtr. Always >= 0. */ 124 int relief; /* Value of -relief option: specifies 3-d 125 * effect for border, such as 126 * TK_RELIEF_RAISED. */ 127 int overRelief; /* Value of -overrelief option: specifies a 128 * 3-d effect for the border, such as 129 * TK_RELIEF_RAISED, to be used when the mouse 130 * is over the button. */ 131 int offRelief; /* Value of -offrelief option: specifies a 3-d 132 * effect for the border, such as 133 * TK_RELIEF_RAISED, to be used when a 134 * checkbutton or radiobutton without 135 * indicator is off. */ 136 Tcl_Obj *highlightWidthPtr; /* Value of -highlightthickness option: 137 * specifies width in pixels of highlight to 138 * draw around widget when it has the focus. 139 * <= 0 means don't draw a highlight. */ 140 int highlightWidth; /* Integer value corresponding to 141 * highlightWidthPtr. Always >= 0. */ 142 Tk_3DBorder highlightBorder;/* Value of -highlightbackground option: 143 * specifies background with which to draw 3-D 144 * default ring and focus highlight area when 145 * highlight is off. */ 146 XColor *highlightColorPtr; /* Value of -highlightcolor option: specifies 147 * color for drawing traversal highlight. */ 148 int inset; /* Total width of all borders, including 149 * traversal highlight and 3-D border. 150 * Indicates how much interior stuff must be 151 * offset from outside edges to leave room for 152 * borders. */ 153 Tk_Font tkfont; /* Value of -font option: specifies font to 154 * use for display text. */ 155 XColor *normalFg; /* Value of -font option: specifies foreground 156 * color in normal mode. */ 157 XColor *activeFg; /* Value of -activeforeground option: 158 * foreground color in active mode. NULL means 159 * use -foreground instead. */ 160 XColor *disabledFg; /* Value of -disabledforeground option: 161 * foreground color when disabled. NULL means 162 * use normalFg with a 50% stipple instead. */ 163 GC normalTextGC; /* GC for drawing text in normal mode. Also 164 * used to copy from off-screen pixmap onto 165 * screen. */ 166 GC activeTextGC; /* GC for drawing text in active mode (NULL 167 * means use normalTextGC). */ 168 GC disabledGC; /* Used to produce disabled effect for text 169 * and check/radio marks. */ 170 GC stippleGC; /* Used to produce disabled stipple effect for 171 * images when disabled. */ 172 Pixmap gray; /* Pixmap for displaying disabled text if 173 * disabledFg is NULL. */ 174 GC copyGC; /* Used for copying information from an 175 * off-screen pixmap to the screen. */ 176 Tcl_Obj *widthPtr; /* Value of -width option. */ 177 int width; /* Integer value corresponding to widthPtr. */ 178 Tcl_Obj *heightPtr; /* Value of -height option. */ 179 int height; /* Integer value corresponding to heightPtr. */ 180 Tcl_Obj *wrapLengthPtr; /* Value of -wraplength option: specifies line 181 * length (in pixels) at which to wrap onto 182 * next line. <= 0 means don't wrap except at 183 * newlines. */ 184 int wrapLength; /* Integer value corresponding to 185 * wrapLengthPtr. */ 186 Tcl_Obj *padXPtr; /* Value of -padx option: specifies how many 187 * pixels of extra space to leave on left and 188 * right of text. Ignored for bitmaps and 189 * images. */ 190 int padX; /* Integer value corresponding to padXPtr. */ 191 Tcl_Obj *padYPtr; /* Value of -padx option: specifies how many 192 * pixels of extra space to leave above and 193 * below text. Ignored for bitmaps and 194 * images. */ 195 int padY; /* Integer value corresponding to padYPtr. */ 196 Tk_Anchor anchor; /* Value of -anchor option: specifies where 197 * text/bitmap should be displayed inside 198 * button region. */ 199 Tk_Justify justify; /* Value of -justify option: specifies how to 200 * align lines of multi-line text. */ 201 int indicatorOn; /* Value of -indicatoron option: 1 means draw 202 * indicator in checkbuttons and radiobuttons, 203 * 0 means don't draw it. */ 204 Tk_3DBorder selectBorder; /* Value of -selectcolor option: specifies 205 * color for drawing indicator background, or 206 * perhaps widget background, when 207 * selected. */ 208 int textWidth; /* Width needed to display text as requested, 209 * in pixels. */ 210 int textHeight; /* Height needed to display text as requested, 211 * in pixels. */ 212 Tk_TextLayout textLayout; /* Saved text layout information. */ 213 int indicatorSpace; /* Horizontal space (in pixels) allocated for 214 * display of indicator. */ 215 int indicatorDiameter; /* Diameter of indicator, in pixels. */ 216 enum defaultState defaultState; 217 /* Value of -default option, such as 218 * DEFAULT_NORMAL: specifies state of default 219 * ring for buttons (normal, active, or 220 * disabled). NULL for other classes. */ 221 222 /* 223 * For check and radio buttons, the fields below are used to manage the 224 * variable indicating the button's state. 225 */ 226 227 Tcl_Obj *selVarNamePtr; /* Value of -variable option: specifies name 228 * of variable used to control selected state 229 * of button. */ 230 Tcl_Obj *onValuePtr; /* Value of -offvalue option: specifies value 231 * to store in variable when this button is 232 * selected. */ 233 Tcl_Obj *offValuePtr; /* Value of -offvalue option: specifies value 234 * to store in variable when this button isn't 235 * selected. Used only by checkbuttons. */ 236 Tcl_Obj *tristateValuePtr; /* Value of -tristatevalue option: specifies 237 * value to display Tristate or Multivalue 238 * mode when variable matches this value. 239 * Used by check- buttons. */ 240 241 /* 242 * Miscellaneous information: 243 */ 244 245 Tk_Cursor cursor; /* Value of -cursor option: if not None, 246 * specifies current cursor for window. */ 247 Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in the 248 * C code, but used by keyboard traversal 249 * scripts. */ 250 Tcl_Obj *commandPtr; /* Value of -command option: specifies script 251 * to execute when button is invoked. If 252 * widget is label or has no command, this is 253 * NULL. */ 254 int compound; /* Value of -compound option; specifies 255 * whether the button should show both an 256 * image and text, and, if so, how. */ 257 int repeatDelay; /* Value of -repeatdelay option; specifies the 258 * number of ms after which the button will 259 * start to auto-repeat its command. */ 260 int repeatInterval; /* Value of -repeatinterval option; specifies 261 * the number of ms between auto-repeat 262 * invocataions of the button command. */ 263 int flags; /* Various flags; see below for 264 * definitions. */ 265} TkButton; 266 267/* 268 * Possible "type" values for buttons. These are the kinds of widgets 269 * supported by this file. The ordering of the type numbers is significant: 270 * greater means more features and is used in the code. 271 */ 272 273#define TYPE_LABEL 0 274#define TYPE_BUTTON 1 275#define TYPE_CHECK_BUTTON 2 276#define TYPE_RADIO_BUTTON 3 277 278/* 279 * Flag bits for buttons: 280 * 281 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has 282 * already been queued to redraw this window. 283 * SELECTED: Non-zero means this button is selected, so 284 * special highlight should be drawn. 285 * GOT_FOCUS: Non-zero means this button currently has the 286 * input focus. 287 * BUTTON_DELETED: Non-zero needs that this button has been 288 * deleted, or is in the process of being deleted 289 */ 290 291#define REDRAW_PENDING (1 << 0) 292#define SELECTED (1 << 1) 293#define GOT_FOCUS (1 << 2) 294#define BUTTON_DELETED (1 << 3) 295#define TRISTATED (1 << 4) 296 297/* 298 * Declaration of variables shared between the files in the button module. 299 */ 300 301MODULE_SCOPE Tk_ClassProcs tkpButtonProcs; 302MODULE_SCOPE char tkDefButtonBorderWidth[TCL_INTEGER_SPACE]; 303 304/* 305 * Declaration of functions used in the implementation of the button widget. 306 */ 307 308#ifndef TkpButtonSetDefaults 309MODULE_SCOPE void TkpButtonSetDefaults(Tk_OptionSpec *specPtr); 310#endif 311MODULE_SCOPE void TkButtonWorldChanged(ClientData instanceData); 312MODULE_SCOPE void TkpComputeButtonGeometry(TkButton *butPtr); 313MODULE_SCOPE TkButton *TkpCreateButton(Tk_Window tkwin); 314#ifndef TkpDestroyButton 315MODULE_SCOPE void TkpDestroyButton(TkButton *butPtr); 316#endif 317#ifndef TkpDisplayButton 318MODULE_SCOPE void TkpDisplayButton(ClientData clientData); 319#endif 320MODULE_SCOPE int TkInvokeButton(TkButton *butPtr); 321 322# undef TCL_STORAGE_CLASS 323# define TCL_STORAGE_CLASS DLLIMPORT 324 325#endif /* _TKBUTTON */ 326