| 1 |
/* |
| 2 |
* tkButton.c -- |
| 3 |
* |
| 4 |
* This module implements a collection of button-like |
| 5 |
* widgets for the Tk toolkit. The widgets implemented |
| 6 |
* include labels, buttons, check buttons, and radio |
| 7 |
* buttons. |
| 8 |
* |
| 9 |
* Copyright (c) 1990-1994 The Regents of the University of California. |
| 10 |
* Copyright (c) 1994-1995 Sun Microsystems, Inc. |
| 11 |
* |
| 12 |
* See the file "license.terms" for information on usage and redistribution |
| 13 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 14 |
* |
| 15 |
* SCCS: @(#) tkButton.c 1.128 96/03/01 17:34:49 |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "bltInt.h" |
| 19 |
#include "bltTree.h" |
| 20 |
|
| 21 |
#ifndef NO_TILEBUTTON |
| 22 |
|
| 23 |
#define INDICATOR_WIDTH 28 |
| 24 |
#define INDICATOR_HEIGHT 17 |
| 25 |
|
| 26 |
|
| 27 |
#include "bltTile.h" |
| 28 |
#include "bltImage.h" |
| 29 |
|
| 30 |
extern Tk_CustomOption bltTileOption; |
| 31 |
/* |
| 32 |
* The definitions below provide symbolic names for the default colors. |
| 33 |
* NORMAL_BG - Normal background color. |
| 34 |
* ACTIVE_BG - Background color when widget is active. |
| 35 |
* SELECT_BG - Background color for selected text. |
| 36 |
* TROUGH - Background color for troughs in scales and scrollbars. |
| 37 |
* INDICATOR - Color for indicator when button is selected. |
| 38 |
* DISABLED - Foreground color when widget is disabled. |
| 39 |
*/ |
| 40 |
|
| 41 |
#define NORMAL_BG "#d9d9d9" |
| 42 |
#define ACTIVE_BG "#d9d9d9" |
| 43 |
#define SELECT_BG "#c3c3c3" |
| 44 |
#define TROUGH "#c3c3c3" |
| 45 |
#define INDICATOR "#b03060" |
| 46 |
#define DISABLED "#a3a3a3" |
| 47 |
|
| 48 |
static Tk_Uid tkNormalUid, tkActiveUid, tkDisabledUid; |
| 49 |
|
| 50 |
#define DEF_BUTTON_ANCHOR "center" |
| 51 |
#define DEF_BUTTON_ACTIVE_BACKGROUND "#ececec" |
| 52 |
#define DEF_BUTTON_ACTIVE_BG_MONO RGB_BLACK |
| 53 |
#define DEF_BUTTON_ACTIVE_FOREGROUND RGB_BLACK |
| 54 |
#define DEF_BUTTON_ACTIVE_FG_MONO RGB_WHITE |
| 55 |
#define DEF_BUTTON_BACKGROUND STD_NORMAL_BACKGROUND |
| 56 |
#define DEF_BUTTON_BG_MONO RGB_WHITE |
| 57 |
#define DEF_BUTTON_BITMAP "" |
| 58 |
#define DEF_BUTTON_BORDERWIDTH "1" |
| 59 |
#define DEF_BUTTON_CURSOR "" |
| 60 |
#define DEF_BUTTON_COMMAND "" |
| 61 |
#define DEF_BUTTON_COMPOUND "none" |
| 62 |
#define DEF_DIRECTION_DEFAULT "below" |
| 63 |
#define DEF_BUTTON_DEFAULT "disabled" |
| 64 |
#define DEF_BUTTON_DISABLED_FOREGROUND STD_DISABLE_FOREGROUND |
| 65 |
#define DEF_BUTTON_DISABLED_FG_MONO "" |
| 66 |
#define DEF_BUTTON_FG RGB_BLACK |
| 67 |
#define DEF_BUTTON_FONT "TkDefaultFont" |
| 68 |
#define DEF_BUTTON_HEIGHT "0" |
| 69 |
#define DEF_BUTTON_HIGHLIGHT_BG STD_NORMAL_BACKGROUND |
| 70 |
#define DEF_BUTTON_HIGHLIGHT RGB_BLACK |
| 71 |
#define DEF_LABEL_HIGHLIGHT_WIDTH "0" |
| 72 |
#define DEF_BUTTON_HIGHLIGHT_WIDTH "1" |
| 73 |
#define DEF_BUTTON_IMAGE (char *) NULL |
| 74 |
#define DEF_BUTTON_INDICATOR "1" |
| 75 |
#define DEF_BUTTON_INDICATORSIZE "10" |
| 76 |
#define DEF_BUTTON_JUSTIFY "center" |
| 77 |
#define DEF_BUTTON_OFF_VALUE "0" |
| 78 |
#define DEF_BUTTON_ON_VALUE "1" |
| 79 |
#define DEF_BUTTON_OVER_RELIEF "raised" |
| 80 |
#define DEF_BUTTON_PADX "3m" |
| 81 |
#define DEF_LABCHKRAD_PADX "1" |
| 82 |
#define DEF_BUTTON_PADY "1m" |
| 83 |
#define DEF_LABCHKRAD_PADY "1" |
| 84 |
#define DEF_BUTTON_RELIEF "raised" |
| 85 |
#define DEF_BUTTON_REPEAT_DELAY "0" |
| 86 |
#define DEF_LABCHKRAD_RELIEF "flat" |
| 87 |
#define DEF_BUTTON_SELECT_COLOR STD_INDICATOR_COLOR |
| 88 |
#define DEF_BUTTON_SELECT_MONO RGB_BLACK |
| 89 |
#define DEF_BUTTON_SELECT_IMAGE (char *) NULL |
| 90 |
#define DEF_BUTTON_STATE "normal" |
| 91 |
#define DEF_LABEL_TAKE_FOCUS "0" |
| 92 |
#define DEF_BUTTON_TAKE_FOCUS "" |
| 93 |
#define DEF_BUTTON_TEXT "" |
| 94 |
#define DEF_BUTTON_TEXT_VARIABLE "" |
| 95 |
#define DEF_BUTTON_UNDERLINE "-1" |
| 96 |
#define DEF_BUTTON_VALUE "" |
| 97 |
#define DEF_BUTTON_WIDTH "0" |
| 98 |
#define DEF_BUTTON_WRAP_LENGTH "0" |
| 99 |
#define DEF_RADIOBUTTON_VARIABLE "selectedButton" |
| 100 |
#define DEF_CHECKBUTTON_VARIABLE "" |
| 101 |
#define DEF_SHADOW RGB_BLACK |
| 102 |
#define DEF_ROTATE "0.0" |
| 103 |
|
| 104 |
/* |
| 105 |
* A data structure of the following type is kept for each |
| 106 |
* widget managed by this file: |
| 107 |
*/ |
| 108 |
|
| 109 |
typedef struct { |
| 110 |
Tk_Window tkwin; /* Window that embodies the button. NULL |
| 111 |
* means that the window has been destroyed. */ |
| 112 |
Display *display; /* Display containing widget. Needed to |
| 113 |
* free up resources after tkwin is gone. */ |
| 114 |
Tcl_Interp *interp; /* Interpreter associated with button. */ |
| 115 |
Tcl_Command widgetCmd; /* Token for button's widget command. */ |
| 116 |
int type; /* Type of widget: restricts operations |
| 117 |
* that may be performed on widget. See |
| 118 |
* below for possible values. */ |
| 119 |
|
| 120 |
/* |
| 121 |
* Information about what's in the button. |
| 122 |
*/ |
| 123 |
|
| 124 |
char *textPtr; /* Text to display in button (malloc'ed) |
| 125 |
* or NULL. */ |
| 126 |
int numChars; /* # of characters in text. */ |
| 127 |
int underline; /* Index of character to underline. < 0 means |
| 128 |
* don't underline anything. */ |
| 129 |
char *textVarName; /* Name of variable (malloc'ed) or NULL. |
| 130 |
* If non-NULL, button displays the contents |
| 131 |
* of this variable. */ |
| 132 |
Pixmap bitmap; /* Bitmap to display or None. If not None |
| 133 |
* then text and textVar are ignored. */ |
| 134 |
char *imageString; /* Name of image to display (malloc'ed), or |
| 135 |
* NULL. If non-NULL, bitmap, text, and |
| 136 |
* textVarName are ignored. */ |
| 137 |
char *activeImageString; |
| 138 |
char *disabledImageString; |
| 139 |
Tk_Image image; /* Image to display in window, or NULL if |
| 140 |
* none. */ |
| 141 |
Tk_Image activeImage; |
| 142 |
Tk_Image disabledImage; |
| 143 |
Tk_Image tristateImage; |
| 144 |
char * tristateImageString; |
| 145 |
char *selectImageString; /* Name of image to display when selected |
| 146 |
* (malloc'ed), or NULL. */ |
| 147 |
Tk_Image selectImage; /* Image to display in window when selected, |
| 148 |
* or NULL if none. Ignored if image is |
| 149 |
* NULL. */ |
| 150 |
|
| 151 |
/* |
| 152 |
* Information used when displaying widget: |
| 153 |
*/ |
| 154 |
|
| 155 |
int state; /* State of button for display purposes: |
| 156 |
* normal, active, or disabled. */ |
| 157 |
Tk_3DBorder normalBorder; /* Structure used to draw 3-D |
| 158 |
* border and background when window |
| 159 |
* isn't active. NULL means no such |
| 160 |
* border exists. */ |
| 161 |
Tk_3DBorder activeBorder; /* Structure used to draw 3-D |
| 162 |
* border and background when window |
| 163 |
* is active. NULL means no such |
| 164 |
* border exists. */ |
| 165 |
int borderWidth; /* Width of border. */ |
| 166 |
int relief; /* 3-d effect: TK_RELIEF_RAISED, etc. */ |
| 167 |
int overRelief; /* Value of -overrelief option: specifies a 3-d |
| 168 |
* effect for the border, such as |
| 169 |
* TK_RELIEF_RAISED, to be used when the mouse |
| 170 |
* is over the button. */ |
| 171 |
int offRelief; |
| 172 |
int highlightWidth; /* Width in pixels of highlight to draw |
| 173 |
* around widget when it has the focus. |
| 174 |
* <= 0 means don't draw a highlight. */ |
| 175 |
XColor *highlightBgColorPtr; |
| 176 |
/* Color for drawing traversal highlight |
| 177 |
* area when highlight is off. */ |
| 178 |
XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ |
| 179 |
int inset; /* Total width of all borders, including |
| 180 |
* traversal highlight and 3-D border. |
| 181 |
* Indicates how much interior stuff must |
| 182 |
* be offset from outside edges to leave |
| 183 |
* room for borders. */ |
| 184 |
Tk_Font tkfont; /* Information about text font, or NULL. */ |
| 185 |
XColor *normalFg; /* Foreground color in normal mode. */ |
| 186 |
XColor *activeFg; /* Foreground color in active mode. NULL |
| 187 |
* means use normalFg instead. */ |
| 188 |
XColor *disabledFg; /* Foreground color when disabled. NULL |
| 189 |
* means use normalFg with a 50% stipple |
| 190 |
* instead. */ |
| 191 |
GC normalTextGC; /* GC for drawing text in normal mode. Also |
| 192 |
* used to copy from off-screen pixmap onto |
| 193 |
* screen. */ |
| 194 |
GC activeTextGC; /* GC for drawing text in active mode (NULL |
| 195 |
* means use normalTextGC). */ |
| 196 |
Pixmap gray; /* Pixmap for displaying disabled text if |
| 197 |
* disabledFg is NULL. */ |
| 198 |
GC disabledGC; /* Used to produce disabled effect. If |
| 199 |
* disabledFg isn't NULL, this GC is used to |
| 200 |
* draw button text or icon. Otherwise |
| 201 |
* text or icon is drawn with normalGC and |
| 202 |
* this GC is used to stipple background |
| 203 |
* across it. For labels this is None. */ |
| 204 |
GC copyGC; /* Used for copying information from an |
| 205 |
* off-screen pixmap to the screen. */ |
| 206 |
char *widthString; /* Value of -width option. Malloc'ed. */ |
| 207 |
char *heightString; /* Value of -height option. Malloc'ed. */ |
| 208 |
int width, height; /* If > 0, these specify dimensions to request |
| 209 |
* for window, in characters for text and in |
| 210 |
* pixels for bitmaps. In this case the actual |
| 211 |
* size of the text string or bitmap is |
| 212 |
* ignored in computing desired window size. */ |
| 213 |
int wrapLength; /* Line length (in pixels) at which to wrap |
| 214 |
* onto next line. <= 0 means don't wrap |
| 215 |
* except at newlines. */ |
| 216 |
int padX, padY; /* Extra space around text (pixels to leave |
| 217 |
* on each side). Ignored for bitmaps and |
| 218 |
* images. */ |
| 219 |
Tk_Anchor anchor; /* Where text/bitmap should be displayed |
| 220 |
* inside button region. */ |
| 221 |
Tk_Justify justify; /* Justification to use for multi-line text. */ |
| 222 |
int indicatorOn; /* True means draw indicator, false means |
| 223 |
* don't draw it. */ |
| 224 |
Tk_3DBorder selectBorder; /* For drawing indicator background, or perhaps |
| 225 |
* widget background, when selected. */ |
| 226 |
int textWidth; /* Width needed to display text as requested, |
| 227 |
* in pixels. */ |
| 228 |
int textHeight; /* Height needed to display text as requested, |
| 229 |
* in pixels. */ |
| 230 |
#if (TK_MAJOR_VERSION > 4) |
| 231 |
Tk_TextLayout textLayout; /* Saved text layout information. */ |
| 232 |
#endif |
| 233 |
int indicatorSpace; /* Horizontal space (in pixels) allocated for |
| 234 |
* display of indicator. */ |
| 235 |
int indicatorDiameter; /* Diameter of indicator, in pixels. */ |
| 236 |
int indicatorSize; /* Fixed the size of indicator. */ |
| 237 |
|
| 238 |
int defaultState; /* Used in 8.0 (not here) */ |
| 239 |
|
| 240 |
/* |
| 241 |
* For check and radio buttons, the fields below are used |
| 242 |
* to manage the variable indicating the button's state. |
| 243 |
*/ |
| 244 |
|
| 245 |
char *selVarName; /* Name of variable used to control selected |
| 246 |
* state of button. Malloc'ed (if |
| 247 |
* not NULL). */ |
| 248 |
char *onValue; /* Value to store in variable when |
| 249 |
* this button is selected. Malloc'ed (if |
| 250 |
* not NULL). */ |
| 251 |
char *offValue; /* Value to store in variable when this |
| 252 |
* button isn't selected. Malloc'ed |
| 253 |
* (if not NULL). Valid only for check |
| 254 |
* buttons. */ |
| 255 |
|
| 256 |
/* |
| 257 |
* Miscellaneous information: |
| 258 |
*/ |
| 259 |
|
| 260 |
Tk_Cursor cursor; /* Current cursor for window, or None. */ |
| 261 |
char *takeFocus; /* Value of -takefocus option; not used in |
| 262 |
* the C code, but used by keyboard traversal |
| 263 |
* scripts. Malloc'ed, but may be NULL. */ |
| 264 |
char *command; /* Command to execute when button is |
| 265 |
* invoked; valid for buttons only. |
| 266 |
* If not NULL, it's malloc-ed. */ |
| 267 |
int compound; /* Value of -compound option; specifies whether |
| 268 |
* the button should show both an image and |
| 269 |
* text, and, if so, how. */ |
| 270 |
int repeatDelay; /* Value of -repeatdelay option; specifies |
| 271 |
* the number of ms after which the button will |
| 272 |
* start to auto-repeat its command. */ |
| 273 |
int repeatInterval; /* Value of -repeatinterval option; specifies |
| 274 |
* the number of ms between auto-repeat |
| 275 |
* invocataions of the button command. */ |
| 276 |
int flags; /* Various flags; see below for |
| 277 |
* definitions. */ |
| 278 |
Blt_Tile innerTile, disabledTile; |
| 279 |
Blt_Tile tile, activeTile, activeInnerTile, disabledInnerTile; |
| 280 |
Shadow shadow; |
| 281 |
Shadow activeShadow; |
| 282 |
double rotate; |
| 283 |
GC focusGC; |
| 284 |
char *tristateValue; |
| 285 |
Tk_Image icons[9]; |
| 286 |
char *iconStr; |
| 287 |
int iconCnt; |
| 288 |
Tk_3DBorder innerBorder; |
| 289 |
char *bdImageString; /* Name of image for border. */ |
| 290 |
char *activeBdImageString; /* Name of image for border. */ |
| 291 |
char *disabledBdImageString; /* Name of image for border. */ |
| 292 |
Tk_Image bdImage; |
| 293 |
Tk_Image activeBdImage; |
| 294 |
Tk_Image disabledBdImage; |
| 295 |
Tk_Image bdImageSized; |
| 296 |
int bdHalo; |
| 297 |
Blt_Tree tree; |
| 298 |
int node; |
| 299 |
Blt_TreeTrace textTrace; |
| 300 |
Blt_TreeTrace selTrace; |
| 301 |
Blt_Tile inBdTile; |
| 302 |
int xOffset, yOffset; |
| 303 |
XColor *bdMaskColor; /* Mask color for bdImage */ |
| 304 |
char *menuName; |
| 305 |
int direction; |
| 306 |
int indicatorWidth; |
| 307 |
int indicatorHeight; |
| 308 |
Blt_Dashes dashes; |
| 309 |
int bgTileTop; |
| 310 |
char *classString; |
| 311 |
} Button; |
| 312 |
|
| 313 |
/* |
| 314 |
* Possible "type" values for buttons. These are the kinds of |
| 315 |
* widgets supported by this file. The ordering of the type |
| 316 |
* numbers is significant: greater means more features and is |
| 317 |
* used in the code. |
| 318 |
*/ |
| 319 |
|
| 320 |
#define TYPE_FRAME 0 |
| 321 |
#define TYPE_LABEL 1 |
| 322 |
#define TYPE_BUTTON 2 |
| 323 |
#define TYPE_CHECK_BUTTON 3 |
| 324 |
#define TYPE_RADIO_BUTTON 4 |
| 325 |
#define TYPE_MENU_BUTTON 5 |
| 326 |
#define CHOOSE(default, override) \ |
| 327 |
(((override) == NULL) ? (default) : (override)) |
| 328 |
|
| 329 |
extern Tk_CustomOption bltShadowOption; |
| 330 |
extern Tk_CustomOption bltGradientOption; |
| 331 |
|
| 332 |
/* static char *defaultStrings[] = { |
| 333 |
"active", "disabled", "normal", NULL |
| 334 |
}; */ |
| 335 |
|
| 336 |
/* enum { STATE_NORMAL, STATE_ACTIVE, STATE_DISABLED } StateEnum; */ |
| 337 |
static char *stateStrings[] = { |
| 338 |
"normal", "active", "disabled", NULL |
| 339 |
}; |
| 340 |
|
| 341 |
static char *directionStrings[] = { |
| 342 |
"above", "below", "flush", "left", "right", NULL |
| 343 |
}; |
| 344 |
|
| 345 |
enum { COMPOUND_NONE, COMPOUND_BOTTOM, COMPOUND_CENTER, COMPOUND_LEFT, COMPOUND_RIGHT, COMPOUND_TOP } CompoundEnum; |
| 346 |
static char *compoundStrings[] = { |
| 347 |
"none", "bottom", "center", "left", "right", "top", NULL |
| 348 |
}; |
| 349 |
|
| 350 |
static int |
| 351 |
StringToName( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 352 |
char *string, char *widgRec, int offset, char *strList[], char *label ) |
| 353 |
{ |
| 354 |
int *namePtr = (int *)(widgRec + offset); |
| 355 |
char c; |
| 356 |
int i; |
| 357 |
|
| 358 |
for (i=0; strList[i]; i++) { |
| 359 |
c = string[0]; |
| 360 |
if (strcmp(string, strList[i]) == 0) { |
| 361 |
*namePtr = i; |
| 362 |
return TCL_OK; |
| 363 |
} |
| 364 |
} |
| 365 |
Tcl_AppendResult(interp, "bad ", label, " \"", string, |
| 366 |
"\": should be one of: ", (char *)NULL); |
| 367 |
for (i=0; strList[i]; i++) { |
| 368 |
if (i>0) Tcl_AppendResult(interp, ", ", (char *)NULL); |
| 369 |
Tcl_AppendResult(interp, strList[i], (char *)NULL); |
| 370 |
} |
| 371 |
return TCL_ERROR; |
| 372 |
} |
| 373 |
|
| 374 |
static |
| 375 |
char * NameToString( ClientData clientData, Tk_Window parent, |
| 376 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr, |
| 377 |
char *strList[], char *msg ) |
| 378 |
{ |
| 379 |
int value = *(int *)(widgRec + offset); |
| 380 |
int i; |
| 381 |
|
| 382 |
for (i=0; strList[i]; i++) ; |
| 383 |
if (value < i) { |
| 384 |
return strList[value]; |
| 385 |
} |
| 386 |
return msg; |
| 387 |
} |
| 388 |
|
| 389 |
static int |
| 390 |
StringToState( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 391 |
char *string, char *widgRec, int offset) |
| 392 |
{ |
| 393 |
return StringToName( clientData, interp, parent, |
| 394 |
string, widgRec, offset, stateStrings, "state" ); |
| 395 |
} |
| 396 |
|
| 397 |
static char * |
| 398 |
StateToString( ClientData clientData, Tk_Window parent, |
| 399 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) |
| 400 |
{ |
| 401 |
return NameToString(clientData, parent, |
| 402 |
widgRec, offset, freeProcPtr, stateStrings, "unknown state value"); |
| 403 |
} |
| 404 |
|
| 405 |
static int |
| 406 |
StringToDirection( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 407 |
char *string, char *widgRec, int offset) |
| 408 |
{ |
| 409 |
return StringToName( clientData, interp, parent, |
| 410 |
string, widgRec, offset, directionStrings, "direction" ); |
| 411 |
} |
| 412 |
|
| 413 |
static char * |
| 414 |
DirectionToString( ClientData clientData, Tk_Window parent, |
| 415 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) |
| 416 |
{ |
| 417 |
return NameToString(clientData, parent, |
| 418 |
widgRec, offset, freeProcPtr, directionStrings, "unknown direction value"); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
static Tk_CustomOption directionOption = |
| 423 |
{ |
| 424 |
StringToDirection, DirectionToString, (ClientData)0, |
| 425 |
}; |
| 426 |
|
| 427 |
static Tk_CustomOption stateOption = |
| 428 |
{ |
| 429 |
StringToState, StateToString, (ClientData)0, |
| 430 |
}; |
| 431 |
|
| 432 |
static int |
| 433 |
StringToCompound( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 434 |
char *string, char *widgRec, int offset) |
| 435 |
{ |
| 436 |
return StringToName( clientData, interp, parent, |
| 437 |
string, widgRec, offset, compoundStrings, "compound" ); |
| 438 |
} |
| 439 |
|
| 440 |
static char * |
| 441 |
CompoundToString( ClientData clientData, Tk_Window parent, |
| 442 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) |
| 443 |
{ |
| 444 |
return NameToString(clientData, parent, |
| 445 |
widgRec, offset, freeProcPtr, compoundStrings, "unknown compound value"); |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
static Tk_CustomOption compoundOption = |
| 450 |
{ |
| 451 |
StringToCompound, CompoundToString, (ClientData)0, |
| 452 |
}; |
| 453 |
|
| 454 |
|
| 455 |
static char * |
| 456 |
IconsToString( ClientData clientData, Tk_Window parent, |
| 457 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) |
| 458 |
{ |
| 459 |
char *imgStr = *(char **)(widgRec + offset); |
| 460 |
return imgStr; |
| 461 |
} |
| 462 |
|
| 463 |
static int |
| 464 |
StringToIcons( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 465 |
char *string, char *widgRec, int offset); |
| 466 |
|
| 467 |
static char * |
| 468 |
TreeToString( ClientData clientData, Tk_Window parent, |
| 469 |
char *widgRec, int offset, Tcl_FreeProc **freeProcPtr) |
| 470 |
{ |
| 471 |
Blt_Tree *treePtr = (Blt_Tree *)(widgRec + offset); |
| 472 |
if (*treePtr == NULL) { |
| 473 |
return NULL; |
| 474 |
} |
| 475 |
return Blt_TreeName(*treePtr); |
| 476 |
} |
| 477 |
|
| 478 |
static int |
| 479 |
StringToTree( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 480 |
char *string, char *widgRec, int offset) |
| 481 |
{ |
| 482 |
Blt_Tree *treePtr = (Blt_Tree *)(widgRec + offset); |
| 483 |
if (string[0] == 0) { |
| 484 |
if (*treePtr) Blt_TreeReleaseToken(*treePtr); |
| 485 |
*treePtr = NULL; |
| 486 |
return TCL_OK; |
| 487 |
} |
| 488 |
return Blt_TreeGetToken(interp, string, treePtr); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
/* WARNING: hardcoded to butPtr->icons. */ |
| 493 |
static Tk_CustomOption iconsOption = |
| 494 |
{ |
| 495 |
StringToIcons, IconsToString, (ClientData)0, |
| 496 |
}; |
| 497 |
|
| 498 |
Tk_CustomOption bltTreeOption = |
| 499 |
{ |
| 500 |
StringToTree, TreeToString, (ClientData)0, |
| 501 |
}; |
| 502 |
|
| 503 |
|
| 504 |
/* |
| 505 |
* Class names for buttons, indexed by one of the type values above. |
| 506 |
*/ |
| 507 |
|
| 508 |
#define BBOFS 6 |
| 509 |
|
| 510 |
static char *classNames[] = |
| 511 |
{"Frame", "Label", "Button", "Checkbutton", "Radiobutton", "Menubutton", |
| 512 |
"BFrame", "BLabel", "BButton", "BCheckbutton", "BRadiobutton", "BMenubutton" |
| 513 |
}; |
| 514 |
|
| 515 |
static void widgetWorldChanged(ClientData clientData); |
| 516 |
|
| 517 |
static Tk_ClassProcs butClass = { |
| 518 |
sizeof(Tk_ClassProcs), /* size */ |
| 519 |
widgetWorldChanged, /* worldChangedProc */ |
| 520 |
}; |
| 521 |
|
| 522 |
/* |
| 523 |
* Flag bits for buttons: |
| 524 |
* |
| 525 |
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler |
| 526 |
* has already been queued to redraw |
| 527 |
* this window. |
| 528 |
* SELECTED: Non-zero means this button is selected, |
| 529 |
* so special highlight should be drawn. |
| 530 |
* GOT_FOCUS: Non-zero means this button currently |
| 531 |
* has the input focus. |
| 532 |
*/ |
| 533 |
|
| 534 |
#define REDRAW_PENDING (1 << 0) |
| 535 |
#define SELECTED (1 << 1) |
| 536 |
#define GOT_FOCUS (1 << 2) |
| 537 |
#define BUTTON_DELETED (1 << 3) |
| 538 |
#define TRISTATED (1 << 4) |
| 539 |
#define HAS_ICONS (1 << 5) |
| 540 |
#define BUTTON_LAYOUT (1 << 6) |
| 541 |
#define BUTTON_DIRTYBD (1 << 7) |
| 542 |
|
| 543 |
|
| 544 |
/* |
| 545 |
* Mask values used to selectively enable entries in the |
| 546 |
* configuration specs: |
| 547 |
*/ |
| 548 |
|
| 549 |
#define FRAME_MASK TK_CONFIG_USER_BIT |
| 550 |
#define LABEL_MASK TK_CONFIG_USER_BIT << 1 |
| 551 |
#define BUTTON_MASK TK_CONFIG_USER_BIT << 2 |
| 552 |
#define CHECK_BUTTON_MASK TK_CONFIG_USER_BIT << 3 |
| 553 |
#define RADIO_BUTTON_MASK TK_CONFIG_USER_BIT << 4 |
| 554 |
#define MENU_BUTTON_MASK TK_CONFIG_USER_BIT << 5 |
| 555 |
#define NALL_MASK (LABEL_MASK | BUTTON_MASK \ |
| 556 |
| CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | MENU_BUTTON_MASK) |
| 557 |
#define ALL_MASK (FRAME_MASK | NALL_MASK ) |
| 558 |
#define NONLABEL_MASK (BUTTON_MASK \ |
| 559 |
| CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | MENU_BUTTON_MASK) |
| 560 |
|
| 561 |
static int configFlags[] = |
| 562 |
{FRAME_MASK, LABEL_MASK, BUTTON_MASK, |
| 563 |
CHECK_BUTTON_MASK, RADIO_BUTTON_MASK, MENU_BUTTON_MASK}; |
| 564 |
|
| 565 |
extern Tk_CustomOption bltDashesOption; |
| 566 |
|
| 567 |
/* |
| 568 |
* Information used for parsing configuration specs: |
| 569 |
*/ |
| 570 |
|
| 571 |
static Tk_ConfigSpec configSpecs[] = |
| 572 |
{ |
| 573 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", |
| 574 |
DEF_BUTTON_ACTIVE_BACKGROUND, Tk_Offset(Button, activeBorder), |
| 575 |
ALL_MASK | TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 576 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", |
| 577 |
DEF_BUTTON_ACTIVE_BG_MONO, Tk_Offset(Button, activeBorder), |
| 578 |
ALL_MASK | TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 579 |
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Background", |
| 580 |
DEF_BUTTON_ACTIVE_FOREGROUND, Tk_Offset(Button, activeFg), |
| 581 |
ALL_MASK | TK_CONFIG_COLOR_ONLY}, |
| 582 |
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Background", |
| 583 |
DEF_BUTTON_ACTIVE_FG_MONO, Tk_Offset(Button, activeFg), |
| 584 |
ALL_MASK | TK_CONFIG_MONO_ONLY}, |
| 585 |
{TK_CONFIG_CUSTOM, "-activeshadow", "activeShadow", "ActiveShadow", |
| 586 |
NULL, Tk_Offset(Button, activeShadow), |
| 587 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltShadowOption}, |
| 588 |
{TK_CONFIG_CUSTOM, "-activetile", "activeTile", "Tile", |
| 589 |
(char *)NULL, Tk_Offset(Button, activeTile), |
| 590 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, |
| 591 |
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", |
| 592 |
DEF_BUTTON_ANCHOR, Tk_Offset(Button, anchor), NALL_MASK}, |
| 593 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 594 |
DEF_BUTTON_BACKGROUND, Tk_Offset(Button, normalBorder), |
| 595 |
ALL_MASK | TK_CONFIG_COLOR_ONLY}, |
| 596 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 597 |
DEF_BUTTON_BG_MONO, Tk_Offset(Button, normalBorder), |
| 598 |
ALL_MASK | TK_CONFIG_MONO_ONLY}, |
| 599 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, |
| 600 |
(char *)NULL, 0, ALL_MASK}, |
| 601 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, |
| 602 |
(char *)NULL, 0, ALL_MASK}, |
| 603 |
{TK_CONFIG_INT, "-bdflags", "bdFlags", "BdFlags", |
| 604 |
"0", Tk_Offset(Button, bdHalo), |
| 605 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 606 |
{TK_CONFIG_STRING, "-bdimage", "bdImage", "Image", |
| 607 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, bdImageString), |
| 608 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 609 |
{TK_CONFIG_STRING, "-activebdimage", "activeBdImage", "Image", |
| 610 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, activeBdImageString), |
| 611 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 612 |
{TK_CONFIG_STRING, "-class", "class", "Class", |
| 613 |
NULL, Tk_Offset(Button, classString), |
| 614 |
FRAME_MASK | TK_CONFIG_NULL_OK}, |
| 615 |
{TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes", |
| 616 |
"dot", Tk_Offset(Button, dashes), |
| 617 |
TK_CONFIG_NULL_OK | NONLABEL_MASK, &bltDashesOption}, |
| 618 |
{TK_CONFIG_STRING, "-disabledbdimage", "disabledBdImage", "Image", |
| 619 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, disabledBdImageString), |
| 620 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 621 |
/*{TK_CONFIG_COLOR, "-bdmaskcolor", "bdMaskColor", "BdMaskColor", |
| 622 |
(char *)NULL, Tk_Offset(Button, bdMaskColor), |
| 623 |
ALL_MASK| TK_CONFIG_NULL_OK}, */ |
| 624 |
{TK_CONFIG_BITMAP, "-bitmap", "bitmap", "Bitmap", |
| 625 |
DEF_BUTTON_BITMAP, Tk_Offset(Button, bitmap), |
| 626 |
NALL_MASK | TK_CONFIG_NULL_OK}, |
| 627 |
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", |
| 628 |
DEF_BUTTON_BORDERWIDTH, Tk_Offset(Button, borderWidth), ALL_MASK}, |
| 629 |
{TK_CONFIG_STRING, "-command", "command", "Command", |
| 630 |
DEF_BUTTON_COMMAND, Tk_Offset(Button, command), |
| 631 |
BUTTON_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 632 |
{TK_CONFIG_CUSTOM, "-compound", "compound", "Compound", |
| 633 |
DEF_BUTTON_COMPOUND, Tk_Offset(Button, compound), |
| 634 |
ALL_MASK | TK_CONFIG_NULL_OK, &compoundOption}, |
| 635 |
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", |
| 636 |
DEF_BUTTON_CURSOR, Tk_Offset(Button, cursor), |
| 637 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 638 |
{TK_CONFIG_CUSTOM, "-default", "default", "Default", |
| 639 |
DEF_BUTTON_DEFAULT, Tk_Offset(Button, defaultState), BUTTON_MASK, &stateOption}, |
| 640 |
{TK_CONFIG_CUSTOM, "-direction", "direction", "Direction", |
| 641 |
DEF_DIRECTION_DEFAULT, Tk_Offset(Button, direction), MENU_BUTTON_MASK, &directionOption}, |
| 642 |
{TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground", |
| 643 |
"DisabledForeground", DEF_BUTTON_DISABLED_FOREGROUND, |
| 644 |
Tk_Offset(Button, disabledFg), ALL_MASK | TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 645 |
{TK_CONFIG_COLOR, "-disabledforeground", "disabledForeground", |
| 646 |
"DisabledForeground", DEF_BUTTON_DISABLED_FG_MONO, |
| 647 |
Tk_Offset(Button, disabledFg), ALL_MASK | TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 648 |
{TK_CONFIG_CUSTOM, "-disabledtile", "disabledTile", "Tile", |
| 649 |
(char *)NULL, Tk_Offset(Button, disabledTile), |
| 650 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, |
| 651 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *)NULL, |
| 652 |
(char *)NULL, 0, NALL_MASK}, |
| 653 |
{TK_CONFIG_FONT, "-font", "font", "Font", |
| 654 |
DEF_BUTTON_FONT, Tk_Offset(Button, tkfont), |
| 655 |
NALL_MASK}, |
| 656 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 657 |
DEF_BUTTON_FG, Tk_Offset(Button, normalFg), NALL_MASK}, |
| 658 |
{TK_CONFIG_STRING, "-height", "height", "Height", |
| 659 |
DEF_BUTTON_HEIGHT, Tk_Offset(Button, heightString), ALL_MASK}, |
| 660 |
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground", |
| 661 |
"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG, |
| 662 |
Tk_Offset(Button, highlightBgColorPtr), NALL_MASK | TK_CONFIG_NULL_OK}, |
| 663 |
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", |
| 664 |
DEF_BUTTON_HIGHLIGHT, Tk_Offset(Button, highlightColorPtr), |
| 665 |
NALL_MASK}, |
| 666 |
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", |
| 667 |
"HighlightThickness", |
| 668 |
DEF_LABEL_HIGHLIGHT_WIDTH, Tk_Offset(Button, highlightWidth), |
| 669 |
LABEL_MASK| MENU_BUTTON_MASK}, |
| 670 |
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", |
| 671 |
"HighlightThickness", |
| 672 |
DEF_BUTTON_HIGHLIGHT_WIDTH, Tk_Offset(Button, highlightWidth), |
| 673 |
BUTTON_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK }, |
| 674 |
{TK_CONFIG_CUSTOM, "-icons", "icons", "icons", |
| 675 |
NULL, Tk_Offset(Button, iconStr), |
| 676 |
TK_CONFIG_NULL_OK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | MENU_BUTTON_MASK, &iconsOption}, |
| 677 |
{TK_CONFIG_STRING, "-image", "image", "Image", |
| 678 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, imageString), |
| 679 |
NALL_MASK | TK_CONFIG_NULL_OK}, |
| 680 |
{TK_CONFIG_STRING, "-activeimage", "activeImage", "Image", |
| 681 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, activeImageString), |
| 682 |
ALL_MASK | TK_CONFIG_NULL_OK}, |
| 683 |
{TK_CONFIG_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn", |
| 684 |
DEF_BUTTON_INDICATOR, Tk_Offset(Button, indicatorOn), |
| 685 |
CHECK_BUTTON_MASK | RADIO_BUTTON_MASK }, |
| 686 |
{TK_CONFIG_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn", |
| 687 |
"0", Tk_Offset(Button, indicatorOn), |
| 688 |
MENU_BUTTON_MASK }, |
| 689 |
{TK_CONFIG_INT, "-checksize", "checkSize", "CheckSize", |
| 690 |
DEF_BUTTON_INDICATORSIZE, Tk_Offset(Button, indicatorSize), |
| 691 |
CHECK_BUTTON_MASK | RADIO_BUTTON_MASK}, |
| 692 |
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", |
| 693 |
DEF_BUTTON_JUSTIFY, Tk_Offset(Button, justify), NALL_MASK}, |
| 694 |
/* {TK_CONFIG_BORDER, "-innerbg", "innerBg", "Background", |
| 695 |
NULL, Tk_Offset(Button, innerBorder), |
| 696 |
ALL_MASK |TK_CONFIG_NULL_OK}, |
| 697 |
{TK_CONFIG_CUSTOM, "-innertile", "innerTile", "InnerTile", |
| 698 |
(char *)NULL, Tk_Offset(Button, innerTile), |
| 699 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, |
| 700 |
{TK_CONFIG_CUSTOM, "-activeinnertile", "activeInnerTile", "ActiveInnerTile", |
| 701 |
(char *)NULL, Tk_Offset(Button, activeInnerTile), |
| 702 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, |
| 703 |
{TK_CONFIG_CUSTOM, "-disabledinnertile", "disabledInnerTile", "DisabledInnerTile", |
| 704 |
(char *)NULL, Tk_Offset(Button, disabledInnerTile), |
| 705 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, */ |
| 706 |
{TK_CONFIG_STRING, "-menu", "menu", "Menu", |
| 707 |
(char *)NULL, Tk_Offset(Button, menuName), |
| 708 |
MENU_BUTTON_MASK}, |
| 709 |
{TK_CONFIG_STRING, "-offvalue", "offValue", "Value", |
| 710 |
DEF_BUTTON_OFF_VALUE, Tk_Offset(Button, offValue), |
| 711 |
CHECK_BUTTON_MASK}, |
| 712 |
{TK_CONFIG_STRING, "-onvalue", "onValue", "Value", |
| 713 |
DEF_BUTTON_ON_VALUE, Tk_Offset(Button, onValue), |
| 714 |
CHECK_BUTTON_MASK}, |
| 715 |
{TK_CONFIG_RELIEF, "-overrelief", "overRelief", "OverRelief", |
| 716 |
DEF_BUTTON_OVER_RELIEF, Tk_Offset(Button, overRelief), |
| 717 |
BUTTON_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | TK_CONFIG_DONT_SET_DEFAULT}, |
| 718 |
{TK_CONFIG_PIXELS, "-padx", "padX", "Pad", |
| 719 |
DEF_BUTTON_PADX, Tk_Offset(Button, padX), BUTTON_MASK | MENU_BUTTON_MASK}, |
| 720 |
{TK_CONFIG_PIXELS, "-padx", "padX", "Pad", |
| 721 |
DEF_LABCHKRAD_PADX, Tk_Offset(Button, padX), |
| 722 |
FRAME_MASK | LABEL_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK}, |
| 723 |
{TK_CONFIG_PIXELS, "-pady", "padY", "Pad", |
| 724 |
DEF_BUTTON_PADY, Tk_Offset(Button, padY), BUTTON_MASK | MENU_BUTTON_MASK}, |
| 725 |
{TK_CONFIG_PIXELS, "-pady", "padY", "Pad", |
| 726 |
DEF_LABCHKRAD_PADY, Tk_Offset(Button, padY), |
| 727 |
FRAME_MASK | LABEL_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK}, |
| 728 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 729 |
DEF_BUTTON_RELIEF, Tk_Offset(Button, relief), BUTTON_MASK}, |
| 730 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 731 |
DEF_LABCHKRAD_RELIEF, Tk_Offset(Button, relief), |
| 732 |
FRAME_MASK | LABEL_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | MENU_BUTTON_MASK}, |
| 733 |
{TK_CONFIG_RELIEF, "-offrelief", "offRelief", "Relief", |
| 734 |
DEF_BUTTON_RELIEF, Tk_Offset(Button, offRelief), CHECK_BUTTON_MASK | RADIO_BUTTON_MASK}, |
| 735 |
{TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay", |
| 736 |
DEF_BUTTON_REPEAT_DELAY, Tk_Offset(Button, repeatDelay), |
| 737 |
BUTTON_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK}, |
| 738 |
{TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate", |
| 739 |
DEF_ROTATE, Tk_Offset(Button, rotate), |
| 740 |
TK_CONFIG_DONT_SET_DEFAULT|ALL_MASK}, |
| 741 |
{TK_CONFIG_BORDER, "-selectcolor", "selectColor", "Background", |
| 742 |
DEF_BUTTON_SELECT_COLOR, Tk_Offset(Button, selectBorder), |
| 743 |
CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | TK_CONFIG_COLOR_ONLY |
| 744 |
| TK_CONFIG_NULL_OK}, |
| 745 |
{TK_CONFIG_BORDER, "-selectcolor", "selectColor", "Background", |
| 746 |
DEF_BUTTON_SELECT_MONO, Tk_Offset(Button, selectBorder), |
| 747 |
CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | TK_CONFIG_MONO_ONLY |
| 748 |
| TK_CONFIG_NULL_OK}, |
| 749 |
{TK_CONFIG_STRING, "-selectimage", "selectImage", "Image", |
| 750 |
DEF_BUTTON_SELECT_IMAGE, Tk_Offset(Button, selectImageString), |
| 751 |
CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 752 |
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow", |
| 753 |
NULL, Tk_Offset(Button, shadow), |
| 754 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltShadowOption}, |
| 755 |
{TK_CONFIG_CUSTOM, "-state", "state", "State", |
| 756 |
DEF_BUTTON_STATE, Tk_Offset(Button, state), |
| 757 |
ALL_MASK, &stateOption}, |
| 758 |
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 759 |
DEF_LABEL_TAKE_FOCUS, Tk_Offset(Button, takeFocus), |
| 760 |
LABEL_MASK | TK_CONFIG_NULL_OK}, |
| 761 |
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 762 |
DEF_BUTTON_TAKE_FOCUS, Tk_Offset(Button, takeFocus), |
| 763 |
BUTTON_MASK | CHECK_BUTTON_MASK | RADIO_BUTTON_MASK | MENU_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 764 |
{TK_CONFIG_STRING, "-text", "text", "Text", |
| 765 |
DEF_BUTTON_TEXT, Tk_Offset(Button, textPtr), NALL_MASK}, |
| 766 |
{TK_CONFIG_STRING, "-textvariable", "textVariable", "Variable", |
| 767 |
DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(Button, textVarName), |
| 768 |
NALL_MASK | TK_CONFIG_NULL_OK}, |
| 769 |
{TK_CONFIG_CUSTOM, "-tile", "tile", "Tile", |
| 770 |
(char *)NULL, Tk_Offset(Button, tile), |
| 771 |
ALL_MASK | TK_CONFIG_NULL_OK, &bltTileOption}, |
| 772 |
{TK_CONFIG_CUSTOM, "-tree", "tree", "Tree", |
| 773 |
(char *)NULL, Tk_Offset(Button, tree), NALL_MASK | TK_CONFIG_NULL_OK, |
| 774 |
&bltTreeOption}, |
| 775 |
{TK_CONFIG_INT, "-node", "node", "Node", |
| 776 |
"0", Tk_Offset(Button, node), NALL_MASK}, |
| 777 |
{TK_CONFIG_INT, "-tiletop", "tileTop", "TileTop", |
| 778 |
"0", Tk_Offset(Button, bgTileTop), |
| 779 |
FRAME_MASK | LABEL_MASK | TK_CONFIG_NULL_OK}, |
| 780 |
{TK_CONFIG_STRING, "-tristateimage", "tristateImage", "Image", |
| 781 |
DEF_BUTTON_IMAGE, Tk_Offset(Button, tristateImageString), |
| 782 |
CHECK_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 783 |
{TK_CONFIG_STRING, "-tristatevalue", "tristateValue", "TristateValue", |
| 784 |
DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(Button, tristateValue), |
| 785 |
CHECK_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 786 |
{TK_CONFIG_INT, "-underline", "underline", "Underline", |
| 787 |
DEF_BUTTON_UNDERLINE, Tk_Offset(Button, underline), NALL_MASK}, |
| 788 |
{TK_CONFIG_STRING, "-value", "value", "Value", |
| 789 |
DEF_BUTTON_VALUE, Tk_Offset(Button, onValue), |
| 790 |
RADIO_BUTTON_MASK}, |
| 791 |
{TK_CONFIG_STRING, "-variable", "variable", "Variable", |
| 792 |
DEF_RADIOBUTTON_VARIABLE, Tk_Offset(Button, selVarName), |
| 793 |
RADIO_BUTTON_MASK}, |
| 794 |
{TK_CONFIG_STRING, "-variable", "variable", "Variable", |
| 795 |
DEF_CHECKBUTTON_VARIABLE, Tk_Offset(Button, selVarName), |
| 796 |
CHECK_BUTTON_MASK | TK_CONFIG_NULL_OK}, |
| 797 |
{TK_CONFIG_STRING, "-width", "width", "Width", |
| 798 |
DEF_BUTTON_WIDTH, Tk_Offset(Button, widthString), ALL_MASK}, |
| 799 |
{TK_CONFIG_PIXELS, "-wraplength", "wrapLength", "WrapLength", |
| 800 |
DEF_BUTTON_WRAP_LENGTH, Tk_Offset(Button, wrapLength), NALL_MASK}, |
| 801 |
{TK_CONFIG_PIXELS, "-xoffset", "xOffset", "XOffset", |
| 802 |
DEF_BUTTON_WRAP_LENGTH, Tk_Offset(Button, xOffset), NALL_MASK}, |
| 803 |
{TK_CONFIG_PIXELS, "-yoffset", "yOffset", "YOffset", |
| 804 |
DEF_BUTTON_WRAP_LENGTH, Tk_Offset(Button, yOffset), NALL_MASK}, |
| 805 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 806 |
(char *)NULL, 0, 0} |
| 807 |
}; |
| 808 |
|
| 809 |
/* |
| 810 |
* String to print out in error messages, identifying options for |
| 811 |
* widget commands for different types of labels or buttons: |
| 812 |
*/ |
| 813 |
|
| 814 |
static char *optionStrings[] = |
| 815 |
{ |
| 816 |
"cget or configure", |
| 817 |
"cget, configure, flash, or invoke", |
| 818 |
"cget, configure, deselect, flash, invoke, select, or toggle", |
| 819 |
"cget, configure, deselect, flash, invoke, or select" |
| 820 |
}; |
| 821 |
|
| 822 |
/* |
| 823 |
* Forward declarations for procedures defined later in this file: |
| 824 |
*/ |
| 825 |
|
| 826 |
static void ButtonCmdDeletedProc _ANSI_ARGS_(( |
| 827 |
ClientData clientData)); |
| 828 |
static int ButtonCreate _ANSI_ARGS_((ClientData clientData, |
| 829 |
Tcl_Interp *interp, int argc, char **argv, |
| 830 |
int type)); |
| 831 |
static void ButtonEventProc _ANSI_ARGS_((ClientData clientData, |
| 832 |
XEvent *eventPtr)); |
| 833 |
static void ButtonImageProc _ANSI_ARGS_((ClientData clientData, |
| 834 |
int x, int y, int width, int height, |
| 835 |
int imgWidth, int imgHeight)); |
| 836 |
static void ButtonImageBdProc _ANSI_ARGS_((ClientData clientData, |
| 837 |
int x, int y, int width, int height, |
| 838 |
int imgWidth, int imgHeight)); |
| 839 |
static void ButtonSelectImageProc _ANSI_ARGS_(( |
| 840 |
ClientData clientData, int x, int y, int width, |
| 841 |
int height, int imgWidth, int imgHeight)); |
| 842 |
static char *ButtonTextVarProc _ANSI_ARGS_((ClientData clientData, |
| 843 |
Tcl_Interp *interp, char *name1, char *name2, |
| 844 |
int flags)); |
| 845 |
static char *ButtonVarProc _ANSI_ARGS_((ClientData clientData, |
| 846 |
Tcl_Interp *interp, char *name1, char *name2, |
| 847 |
int flags)); |
| 848 |
static int TreeTraceProc(ClientData clientData, |
| 849 |
Tcl_Interp *interp, Blt_TreeNode node, Blt_TreeKey key, |
| 850 |
unsigned int flags); |
| 851 |
static int TreeTextTraceProc(ClientData clientData, |
| 852 |
Tcl_Interp *interp, Blt_TreeNode node, Blt_TreeKey key, |
| 853 |
unsigned int flags); |
| 854 |
static int ButtonWidgetCmd _ANSI_ARGS_((ClientData clientData, |
| 855 |
Tcl_Interp *interp, int argc, char **argv)); |
| 856 |
static void ComputeButtonGeometry _ANSI_ARGS_((Button *butPtr)); |
| 857 |
static int ConfigureButton _ANSI_ARGS_((Tcl_Interp *interp, |
| 858 |
Button *butPtr, int argc, char **argv, |
| 859 |
int flags)); |
| 860 |
static void DestroyButton _ANSI_ARGS_((Button *butPtr)); |
| 861 |
static void DisplayButton _ANSI_ARGS_((ClientData clientData)); |
| 862 |
static int InvokeButton _ANSI_ARGS_((Button *butPtr)); |
| 863 |
|
| 864 |
static Blt_TileChangedProc TileChangedProc; |
| 865 |
static Tcl_CmdProc ButtonCmd, LabelCmd, CheckbuttonCmd, RadiobuttonCmd; |
| 866 |
|
| 867 |
EXTERN int TkCopyAndGlobalEval _ANSI_ARGS_((Tcl_Interp *interp, char *script)); |
| 868 |
|
| 869 |
#if (TK_MAJOR_VERSION > 4) |
| 870 |
EXTERN void TkComputeAnchor _ANSI_ARGS_((Tk_Anchor anchor, Tk_Window tkwin, |
| 871 |
int padX, int padY, int innerWidth, int innerHeight, int *xPtr, |
| 872 |
int *yPtr)); |
| 873 |
#endif |
| 874 |
|
| 875 |
static void |
| 876 |
EventuallyRedraw(butPtr) |
| 877 |
Button *butPtr; |
| 878 |
{ |
| 879 |
if ((butPtr->tkwin != NULL) && !(butPtr->flags & REDRAW_PENDING)) { |
| 880 |
butPtr->flags |= REDRAW_PENDING; |
| 881 |
Tcl_DoWhenIdle(DisplayButton, butPtr); |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
static void |
| 887 |
widgetWorldChanged(ClientData clientData) |
| 888 |
{ |
| 889 |
Button *butPtr = (Button *)clientData; |
| 890 |
butPtr->flags |= (BUTTON_LAYOUT); |
| 891 |
|
| 892 |
EventuallyRedraw(butPtr); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
/* TODO: make this a hash table to avoid allocating images for each button???. */ |
| 897 |
static int |
| 898 |
StringToIcons( ClientData clientData, Tcl_Interp *interp, Tk_Window parent, |
| 899 |
char *string, char *widgRec, int offset) |
| 900 |
{ |
| 901 |
Button *butPtr = (Button*)widgRec;; |
| 902 |
int argc = 0; |
| 903 |
int result, i; |
| 904 |
char **argv; |
| 905 |
Tk_Image imgs[9], image; |
| 906 |
|
| 907 |
result = TCL_OK; |
| 908 |
if (string && Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) { |
| 909 |
return TCL_ERROR; |
| 910 |
} |
| 911 |
if (argc == 0) { |
| 912 |
ckfree( (char*)argv); |
| 913 |
for (i = 0; i < 9; i++) { |
| 914 |
if (butPtr->icons[i]) Tk_FreeImage(butPtr->icons[i]); |
| 915 |
butPtr->icons[i] = NULL; |
| 916 |
} |
| 917 |
if (butPtr->iconStr) { |
| 918 |
ckfree(butPtr->iconStr); |
| 919 |
} |
| 920 |
butPtr->iconStr = NULL; |
| 921 |
butPtr->iconCnt = 0; |
| 922 |
return TCL_OK; |
| 923 |
} |
| 924 |
if (argc <2 || argc >9) { |
| 925 |
ckfree( (char*)argv); |
| 926 |
Tcl_AppendResult(interp, "expected 0, or 2-9 icons", 0); |
| 927 |
return TCL_ERROR; |
| 928 |
} |
| 929 |
for (i = 0; i < 9; i++) { |
| 930 |
imgs[i] = NULL; |
| 931 |
} |
| 932 |
for (i = 0; i < argc; i++) { |
| 933 |
image = Tk_GetImage(interp, butPtr->tkwin, argv[i], ButtonImageProc, (ClientData)butPtr); |
| 934 |
if (image == NULL) { |
| 935 |
for (i = i-1; i >=0; i--) { |
| 936 |
Tk_FreeImage(imgs[i]); |
| 937 |
} |
| 938 |
ckfree( (char*)argv); |
| 939 |
return TCL_ERROR; |
| 940 |
} |
| 941 |
imgs[i] = image; |
| 942 |
} |
| 943 |
ckfree( (char*)argv); |
| 944 |
butPtr->iconCnt = argc; |
| 945 |
for (i = 0; i < 9; i++) { |
| 946 |
if (butPtr->icons[i]) { Tk_FreeImage(butPtr->icons[i]); } |
| 947 |
butPtr->icons[i] = imgs[i]; |
| 948 |
} |
| 949 |
if (butPtr->iconStr) { |
| 950 |
ckfree(butPtr->iconStr); |
| 951 |
} |
| 952 |
butPtr->iconStr = strdup(string); |
| 953 |
return TCL_OK; |
| 954 |
} |
| 955 |
|
| 956 |
static void |
| 957 |
ComputeAnchor( Tk_Anchor anchor, Tk_Window tkwin, int padX, int padY, |
| 958 |
int innerWidth, int innerHeight, int *xPtr, int *yPtr, int xAdj, int yAdj) |
| 959 |
{ |
| 960 |
int width, height; |
| 961 |
|
| 962 |
width = Tk_Width(tkwin)-xAdj; |
| 963 |
height = Tk_Height(tkwin)-yAdj; |
| 964 |
/* |
| 965 |
* Handle the horizontal parts. |
| 966 |
*/ |
| 967 |
|
| 968 |
switch (anchor) { |
| 969 |
case TK_ANCHOR_NW: |
| 970 |
case TK_ANCHOR_W: |
| 971 |
case TK_ANCHOR_SW: |
| 972 |
*xPtr = Tk_InternalBorderLeft(tkwin) + padX; |
| 973 |
break; |
| 974 |
|
| 975 |
case TK_ANCHOR_N: |
| 976 |
case TK_ANCHOR_CENTER: |
| 977 |
case TK_ANCHOR_S: |
| 978 |
*xPtr = (width - innerWidth - Tk_InternalBorderLeft(tkwin) - |
| 979 |
Tk_InternalBorderRight(tkwin)) / 2 + |
| 980 |
Tk_InternalBorderLeft(tkwin); |
| 981 |
break; |
| 982 |
|
| 983 |
default: |
| 984 |
*xPtr = width - Tk_InternalBorderRight(tkwin) - padX |
| 985 |
- innerWidth; |
| 986 |
break; |
| 987 |
} |
| 988 |
|
| 989 |
/* |
| 990 |
* Handle the vertical parts. |
| 991 |
*/ |
| 992 |
|
| 993 |
switch (anchor) { |
| 994 |
case TK_ANCHOR_NW: |
| 995 |
case TK_ANCHOR_N: |
| 996 |
case TK_ANCHOR_NE: |
| 997 |
*yPtr = Tk_InternalBorderTop(tkwin) + padY; |
| 998 |
break; |
| 999 |
|
| 1000 |
case TK_ANCHOR_W: |
| 1001 |
case TK_ANCHOR_CENTER: |
| 1002 |
case TK_ANCHOR_E: |
| 1003 |
*yPtr = (height - innerHeight- Tk_InternalBorderTop(tkwin) - |
| 1004 |
Tk_InternalBorderBottom(tkwin)) / 2 + |
| 1005 |
Tk_InternalBorderTop(tkwin); |
| 1006 |
break; |
| 1007 |
|
| 1008 |
default: |
| 1009 |
*yPtr = height - Tk_InternalBorderBottom(tkwin) - padY |
| 1010 |
- innerHeight; |
| 1011 |
break; |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
/* |
| 1016 |
*-------------------------------------------------------------- |
| 1017 |
* |
| 1018 |
* Tk_ButtonCmd, Tk_CheckbuttonCmd, Tk_LabelCmd, Tk_RadiobuttonCmd -- |
| 1019 |
* |
| 1020 |
* These procedures are invoked to process the "button", "label", |
| 1021 |
* "radiobutton", and "checkbutton" Tcl commands. See the |
| 1022 |
* user documentation for details on what they do. |
| 1023 |
* |
| 1024 |
* Results: |
| 1025 |
* A standard Tcl result. |
| 1026 |
* |
| 1027 |
* Side effects: |
| 1028 |
* See the user documentation. These procedures are just wrappers; |
| 1029 |
* they call ButtonCreate to do all of the real work. |
| 1030 |
* |
| 1031 |
*-------------------------------------------------------------- |
| 1032 |
*/ |
| 1033 |
|
| 1034 |
static int |
| 1035 |
ButtonCmd(clientData, interp, argc, argv) |
| 1036 |
ClientData clientData; /* Main window associated with |
| 1037 |
* interpreter. */ |
| 1038 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1039 |
int argc; /* Number of arguments. */ |
| 1040 |
char **argv; /* Argument strings. */ |
| 1041 |
{ |
| 1042 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_BUTTON); |
| 1043 |
} |
| 1044 |
|
| 1045 |
static int |
| 1046 |
CheckbuttonCmd(clientData, interp, argc, argv) |
| 1047 |
ClientData clientData; /* Main window associated with |
| 1048 |
* interpreter. */ |
| 1049 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1050 |
int argc; /* Number of arguments. */ |
| 1051 |
char **argv; /* Argument strings. */ |
| 1052 |
{ |
| 1053 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_CHECK_BUTTON); |
| 1054 |
} |
| 1055 |
|
| 1056 |
static int |
| 1057 |
LabelCmd(clientData, interp, argc, argv) |
| 1058 |
ClientData clientData; /* Main window associated with |
| 1059 |
* interpreter. */ |
| 1060 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1061 |
int argc; /* Number of arguments. */ |
| 1062 |
char **argv; /* Argument strings. */ |
| 1063 |
{ |
| 1064 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_LABEL); |
| 1065 |
} |
| 1066 |
|
| 1067 |
static int |
| 1068 |
BFrameCmd(clientData, interp, argc, argv) |
| 1069 |
ClientData clientData; /* Main window associated with |
| 1070 |
* interpreter. */ |
| 1071 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1072 |
int argc; /* Number of arguments. */ |
| 1073 |
char **argv; /* Argument strings. */ |
| 1074 |
{ |
| 1075 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_FRAME+BBOFS); |
| 1076 |
} |
| 1077 |
|
| 1078 |
static int |
| 1079 |
FrameCmd(clientData, interp, argc, argv) |
| 1080 |
ClientData clientData; /* Main window associated with |
| 1081 |
* interpreter. */ |
| 1082 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1083 |
int argc; /* Number of arguments. */ |
| 1084 |
char **argv; /* Argument strings. */ |
| 1085 |
{ |
| 1086 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_FRAME); |
| 1087 |
} |
| 1088 |
|
| 1089 |
static int |
| 1090 |
MenubuttonCmd(clientData, interp, argc, argv) |
| 1091 |
ClientData clientData; /* Main window associated with |
| 1092 |
* interpreter. */ |
| 1093 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1094 |
int argc; /* Number of arguments. */ |
| 1095 |
char **argv; /* Argument strings. */ |
| 1096 |
{ |
| 1097 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_MENU_BUTTON); |
| 1098 |
} |
| 1099 |
|
| 1100 |
static int |
| 1101 |
RadiobuttonCmd(clientData, interp, argc, argv) |
| 1102 |
ClientData clientData; /* Main window associated with |
| 1103 |
* interpreter. */ |
| 1104 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1105 |
int argc; /* Number of arguments. */ |
| 1106 |
char **argv; /* Argument strings. */ |
| 1107 |
{ |
| 1108 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_RADIO_BUTTON); |
| 1109 |
} |
| 1110 |
static int |
| 1111 |
BButtonCmd(clientData, interp, argc, argv) |
| 1112 |
ClientData clientData; /* Main window associated with |
| 1113 |
* interpreter. */ |
| 1114 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1115 |
int argc; /* Number of arguments. */ |
| 1116 |
char **argv; /* Argument strings. */ |
| 1117 |
{ |
| 1118 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_BUTTON+BBOFS); |
| 1119 |
} |
| 1120 |
|
| 1121 |
static int |
| 1122 |
BCheckbuttonCmd(clientData, interp, argc, argv) |
| 1123 |
ClientData clientData; /* Main window associated with |
| 1124 |
* interpreter. */ |
| 1125 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1126 |
int argc; /* Number of arguments. */ |
| 1127 |
char **argv; /* Argument strings. */ |
| 1128 |
{ |
| 1129 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_CHECK_BUTTON+BBOFS); |
| 1130 |
} |
| 1131 |
|
| 1132 |
static int |
| 1133 |
BLabelCmd(clientData, interp, argc, argv) |
| 1134 |
ClientData clientData; /* Main window associated with |
| 1135 |
* interpreter. */ |
| 1136 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1137 |
int argc; /* Number of arguments. */ |
| 1138 |
char **argv; /* Argument strings. */ |
| 1139 |
{ |
| 1140 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_LABEL+BBOFS); |
| 1141 |
} |
| 1142 |
|
| 1143 |
static int |
| 1144 |
BMenubuttonCmd(clientData, interp, argc, argv) |
| 1145 |
ClientData clientData; /* Main window associated with |
| 1146 |
* interpreter. */ |
| 1147 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1148 |
int argc; /* Number of arguments. */ |
| 1149 |
char **argv; /* Argument strings. */ |
| 1150 |
{ |
| 1151 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_MENU_BUTTON+BBOFS); |
| 1152 |
} |
| 1153 |
|
| 1154 |
static int |
| 1155 |
BRadiobuttonCmd(clientData, interp, argc, argv) |
| 1156 |
ClientData clientData; /* Main window associated with |
| 1157 |
* interpreter. */ |
| 1158 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1159 |
int argc; /* Number of arguments. */ |
| 1160 |
char **argv; /* Argument strings. */ |
| 1161 |
{ |
| 1162 |
return ButtonCreate(clientData, interp, argc, argv, TYPE_RADIO_BUTTON+BBOFS); |
| 1163 |
} |
| 1164 |
|
| 1165 |
/* |
| 1166 |
*-------------------------------------------------------------- |
| 1167 |
* |
| 1168 |
* ButtonCreate -- |
| 1169 |
* |
| 1170 |
* This procedure does all the real work of implementing the |
| 1171 |
* "button", "label", "radiobutton", and "checkbutton" Tcl |
| 1172 |
* commands. See the user documentation for details on what it does. |
| 1173 |
* |
| 1174 |
* Results: |
| 1175 |
* A standard Tcl result. |
| 1176 |
* |
| 1177 |
* Side effects: |
| 1178 |
* See the user documentation. |
| 1179 |
* |
| 1180 |
*-------------------------------------------------------------- |
| 1181 |
*/ |
| 1182 |
|
| 1183 |
/*ARGSUSED*/ |
| 1184 |
static int |
| 1185 |
ButtonCreate(clientData, interp, argc, argv, type) |
| 1186 |
ClientData clientData; /* Main window associated with |
| 1187 |
* interpreter. */ |
| 1188 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1189 |
int argc; /* Number of arguments. */ |
| 1190 |
char **argv; /* Argument strings. */ |
| 1191 |
int type; /* Type of button to create: TYPE_LABEL, |
| 1192 |
* TYPE_BUTTON, TYPE_CHECK_BUTTON, or |
| 1193 |
* TYPE_RADIO_BUTTON. */ |
| 1194 |
{ |
| 1195 |
register Button *butPtr; |
| 1196 |
Tk_Window tkwin; |
| 1197 |
int oType = type; |
| 1198 |
char *className; |
| 1199 |
|
| 1200 |
if (type >= BBOFS) type -= BBOFS; |
| 1201 |
if (argc < 2) { |
| 1202 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1203 |
argv[0], " pathName ?options?\"", (char *)NULL); |
| 1204 |
return TCL_ERROR; |
| 1205 |
} |
| 1206 |
/* |
| 1207 |
* Create the new window. |
| 1208 |
*/ |
| 1209 |
|
| 1210 |
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1], |
| 1211 |
(char *)NULL); |
| 1212 |
if (tkwin == NULL) { |
| 1213 |
return TCL_ERROR; |
| 1214 |
} |
| 1215 |
/* |
| 1216 |
* Initialize the data structure for the button. |
| 1217 |
*/ |
| 1218 |
|
| 1219 |
butPtr = Blt_Calloc(1, sizeof(Button)); |
| 1220 |
butPtr->tkwin = tkwin; |
| 1221 |
butPtr->display = Tk_Display(tkwin); |
| 1222 |
butPtr->widgetCmd = Tcl_CreateCommand(interp, Tk_PathName(butPtr->tkwin), |
| 1223 |
ButtonWidgetCmd, butPtr, ButtonCmdDeletedProc); |
| 1224 |
#ifdef ITCL_NAMESPACES |
| 1225 |
Itk_SetWidgetCommand(butPtr->tkwin, butPtr->widgetCmd); |
| 1226 |
#endif /* ITCL_NAMESPACES */ |
| 1227 |
|
| 1228 |
/* Since calloc was used, could skip most of the following ... */ |
| 1229 |
butPtr->interp = interp; |
| 1230 |
butPtr->type = type; |
| 1231 |
butPtr->textPtr = NULL; |
| 1232 |
butPtr->numChars = 0; |
| 1233 |
butPtr->underline = -1; |
| 1234 |
butPtr->textVarName = NULL; |
| 1235 |
butPtr->bitmap = None; |
| 1236 |
butPtr->imageString = NULL; |
| 1237 |
butPtr->image = NULL; |
| 1238 |
butPtr->tristateImageString = NULL; |
| 1239 |
butPtr->selectImageString = NULL; |
| 1240 |
butPtr->selectImage = NULL; |
| 1241 |
butPtr->state = STATE_NORMAL; |
| 1242 |
butPtr->normalBorder = NULL; |
| 1243 |
butPtr->activeBorder = NULL; |
| 1244 |
butPtr->borderWidth = 0; |
| 1245 |
butPtr->relief = TK_RELIEF_FLAT; |
| 1246 |
butPtr->highlightWidth = 0; |
| 1247 |
butPtr->highlightBgColorPtr = NULL; |
| 1248 |
butPtr->highlightColorPtr = NULL; |
| 1249 |
butPtr->inset = 0; |
| 1250 |
butPtr->tkfont = NULL; |
| 1251 |
butPtr->normalFg = NULL; |
| 1252 |
butPtr->activeFg = NULL; |
| 1253 |
butPtr->disabledFg = NULL; |
| 1254 |
butPtr->normalTextGC = None; |
| 1255 |
butPtr->activeTextGC = None; |
| 1256 |
/*butPtr->gray = None;*/ |
| 1257 |
butPtr->disabledGC = None; |
| 1258 |
butPtr->copyGC = None; |
| 1259 |
butPtr->widthString = NULL; |
| 1260 |
butPtr->heightString = NULL; |
| 1261 |
butPtr->width = 0; |
| 1262 |
butPtr->height = 0; |
| 1263 |
butPtr->wrapLength = 0; |
| 1264 |
butPtr->padX = 0; |
| 1265 |
butPtr->padY = 0; |
| 1266 |
butPtr->anchor = TK_ANCHOR_CENTER; |
| 1267 |
butPtr->justify = TK_JUSTIFY_CENTER; |
| 1268 |
#if (TK_MAJOR_VERSION > 4) |
| 1269 |
butPtr->textLayout = NULL; |
| 1270 |
#endif |
| 1271 |
butPtr->indicatorOn = 0; |
| 1272 |
butPtr->selectBorder = NULL; |
| 1273 |
butPtr->indicatorSpace = 0; |
| 1274 |
butPtr->indicatorDiameter = 0; |
| 1275 |
butPtr->selVarName = NULL; |
| 1276 |
butPtr->onValue = NULL; |
| 1277 |
butPtr->offValue = NULL; |
| 1278 |
butPtr->cursor = None; |
| 1279 |
butPtr->command = NULL; |
| 1280 |
butPtr->takeFocus = NULL; |
| 1281 |
butPtr->flags = 0; |
| 1282 |
butPtr->tile = butPtr->activeTile = butPtr->innerTile = butPtr->disabledTile = NULL; |
| 1283 |
butPtr->defaultState = STATE_DISABLED; |
| 1284 |
butPtr->compound = 0; |
| 1285 |
butPtr->repeatDelay = 0; |
| 1286 |
butPtr->overRelief = TK_RELIEF_RAISED; |
| 1287 |
|
| 1288 |
|
| 1289 |
className = classNames[oType]; |
| 1290 |
if (type == TYPE_FRAME) { |
| 1291 |
int length, i; |
| 1292 |
for (i = 2; i < argc; i += 2) { |
| 1293 |
length = strlen(argv[i]); |
| 1294 |
if (length < 2) { |
| 1295 |
continue; |
| 1296 |
} |
| 1297 |
if ((argv[i][1] == 'c') && (length >= 3) |
| 1298 |
&& (strncmp(argv[i], "-class", (unsigned) length) == 0)) { |
| 1299 |
className = argv[i+1]; |
| 1300 |
} |
| 1301 |
} |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
Tk_SetClass(tkwin, className); |
| 1306 |
Tk_SetClassProcs(tkwin, &butClass, (ClientData)butPtr); |
| 1307 |
Tk_CreateEventHandler(butPtr->tkwin, |
| 1308 |
ExposureMask | StructureNotifyMask | FocusChangeMask, |
| 1309 |
ButtonEventProc, butPtr); |
| 1310 |
if (ConfigureButton(interp, butPtr, argc - 2, argv + 2, |
| 1311 |
configFlags[type]) != TCL_OK) { |
| 1312 |
Tk_DestroyWindow(butPtr->tkwin); |
| 1313 |
return TCL_ERROR; |
| 1314 |
} |
| 1315 |
Tcl_SetResult(interp, Tk_PathName(butPtr->tkwin), TCL_VOLATILE); |
| 1316 |
return TCL_OK; |
| 1317 |
} |
| 1318 |
|
| 1319 |
static char *ButtonGetValue(Button *butPtr) { |
| 1320 |
Blt_TreeNode nodePtr; |
| 1321 |
Tcl_Obj *valuePtr; |
| 1322 |
CONST char *value; |
| 1323 |
Tcl_Interp *interp = butPtr->interp; |
| 1324 |
|
| 1325 |
value = NULL; |
| 1326 |
|
| 1327 |
if (butPtr->tree == NULL) { |
| 1328 |
value = Tcl_GetVar(interp, butPtr->selVarName, TCL_GLOBAL_ONLY); |
| 1329 |
} else { |
| 1330 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 1331 |
if (nodePtr == NULL) { |
| 1332 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 1333 |
} |
| 1334 |
if (nodePtr == NULL) { |
| 1335 |
return NULL; |
| 1336 |
} |
| 1337 |
if (Blt_TreeGetValue(NULL, butPtr->tree, |
| 1338 |
nodePtr, butPtr->selVarName, &valuePtr) == TCL_OK && valuePtr != NULL) { |
| 1339 |
value = Tcl_GetString(valuePtr); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
return value; |
| 1343 |
} |
| 1344 |
|
| 1345 |
static int ButtonSetValue(Button *butPtr, char *value, int warn) { |
| 1346 |
Blt_TreeNode nodePtr; |
| 1347 |
Tcl_Obj *valuePtr; |
| 1348 |
Tcl_Interp *interp = butPtr->interp; |
| 1349 |
|
| 1350 |
if (butPtr->tree == NULL) { |
| 1351 |
if (Tcl_SetVar(interp, butPtr->selVarName, value, |
| 1352 |
TCL_GLOBAL_ONLY | (warn?TCL_LEAVE_ERR_MSG:0)) == NULL) { |
| 1353 |
return TCL_ERROR; |
| 1354 |
} |
| 1355 |
return TCL_OK; |
| 1356 |
} |
| 1357 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 1358 |
if (nodePtr == NULL) { |
| 1359 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 1360 |
} |
| 1361 |
if (nodePtr == NULL) { |
| 1362 |
return TCL_ERROR; |
| 1363 |
} |
| 1364 |
valuePtr = Tcl_NewStringObj(value, -1); |
| 1365 |
return Blt_TreeSetValue(interp, butPtr->tree, |
| 1366 |
nodePtr, butPtr->selVarName, valuePtr); |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
/* |
| 1371 |
*-------------------------------------------------------------- |
| 1372 |
* |
| 1373 |
* ButtonWidgetCmd -- |
| 1374 |
* |
| 1375 |
* This procedure is invoked to process the Tcl command |
| 1376 |
* that corresponds to a widget managed by this module. |
| 1377 |
* See the user documentation for details on what it does. |
| 1378 |
* |
| 1379 |
* Results: |
| 1380 |
* A standard Tcl result. |
| 1381 |
* |
| 1382 |
* Side effects: |
| 1383 |
* See the user documentation. |
| 1384 |
* |
| 1385 |
*-------------------------------------------------------------- |
| 1386 |
*/ |
| 1387 |
|
| 1388 |
static int |
| 1389 |
ButtonWidgetCmd(clientData, interp, argc, argv) |
| 1390 |
ClientData clientData; /* Information about button widget. */ |
| 1391 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 1392 |
int argc; /* Number of arguments. */ |
| 1393 |
char **argv; /* Argument strings. */ |
| 1394 |
{ |
| 1395 |
register Button *butPtr = clientData; |
| 1396 |
int result = TCL_OK; |
| 1397 |
size_t length; |
| 1398 |
int c; |
| 1399 |
|
| 1400 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 1401 |
return TCL_OK; |
| 1402 |
} |
| 1403 |
|
| 1404 |
if (argc < 2) { |
| 1405 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1406 |
" option ?arg arg ...?\"", (char *)NULL); |
| 1407 |
return TCL_ERROR; |
| 1408 |
} |
| 1409 |
Tcl_Preserve(butPtr); |
| 1410 |
c = argv[1][0]; |
| 1411 |
length = strlen(argv[1]); |
| 1412 |
if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0) |
| 1413 |
&& (length >= 2)) { |
| 1414 |
if (argc != 3) { |
| 1415 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1416 |
argv[0], " cget option\"", |
| 1417 |
(char *)NULL); |
| 1418 |
goto error; |
| 1419 |
} |
| 1420 |
result = Tk_ConfigureValue(interp, butPtr->tkwin, configSpecs, |
| 1421 |
(char *)butPtr, argv[2], configFlags[butPtr->type]); |
| 1422 |
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0) |
| 1423 |
&& (length >= 2)) { |
| 1424 |
if (argc == 2) { |
| 1425 |
result = Tk_ConfigureInfo(interp, butPtr->tkwin, configSpecs, |
| 1426 |
(char *)butPtr, (char *)NULL, configFlags[butPtr->type]); |
| 1427 |
} else if (argc == 3) { |
| 1428 |
result = Tk_ConfigureInfo(interp, butPtr->tkwin, configSpecs, |
| 1429 |
(char *)butPtr, argv[2], |
| 1430 |
configFlags[butPtr->type]); |
| 1431 |
} else { |
| 1432 |
result = ConfigureButton(interp, butPtr, argc - 2, argv + 2, |
| 1433 |
configFlags[butPtr->type] | TK_CONFIG_ARGV_ONLY); |
| 1434 |
} |
| 1435 |
} else if ((c == 'd') && (strncmp(argv[1], "deselect", length) == 0) |
| 1436 |
&& (butPtr->type >= TYPE_CHECK_BUTTON) && (butPtr->type < TYPE_MENU_BUTTON)) { |
| 1437 |
if (argc > 2) { |
| 1438 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1439 |
" deselect\"", (char *)NULL); |
| 1440 |
goto error; |
| 1441 |
} |
| 1442 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 1443 |
result = ButtonSetValue(butPtr, butPtr->offValue, 1); |
| 1444 |
} else if (butPtr->flags & SELECTED) { |
| 1445 |
result = ButtonSetValue(butPtr, "", 1); |
| 1446 |
} |
| 1447 |
} else if ((c == 'f') && (strncmp(argv[1], "flash", length) == 0) |
| 1448 |
&& (butPtr->type > TYPE_LABEL)) { |
| 1449 |
int i; |
| 1450 |
|
| 1451 |
if (argc > 2) { |
| 1452 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1453 |
" flash\"", (char *)NULL); |
| 1454 |
goto error; |
| 1455 |
} |
| 1456 |
if (butPtr->state != STATE_DISABLED) { |
| 1457 |
for (i = 0; i < 4; i++) { |
| 1458 |
butPtr->state = (butPtr->state == STATE_NORMAL) |
| 1459 |
? STATE_ACTIVE : STATE_NORMAL; |
| 1460 |
Tk_SetBackgroundFromBorder(butPtr->tkwin, |
| 1461 |
(butPtr->state == STATE_ACTIVE && butPtr->activeBorder) ? butPtr->activeBorder |
| 1462 |
: butPtr->normalBorder); |
| 1463 |
DisplayButton(butPtr); |
| 1464 |
|
| 1465 |
/* |
| 1466 |
* Special note: must cancel any existing idle handler |
| 1467 |
* for DisplayButton; it's no longer needed, and DisplayButton |
| 1468 |
* cleared the REDRAW_PENDING flag. |
| 1469 |
*/ |
| 1470 |
|
| 1471 |
Tcl_CancelIdleCall(DisplayButton, butPtr); |
| 1472 |
#ifndef WIN32 |
| 1473 |
XFlush(butPtr->display); |
| 1474 |
#endif |
| 1475 |
Tcl_Sleep(50); |
| 1476 |
} |
| 1477 |
} |
| 1478 |
} else if ((c == 'i') && (strncmp(argv[1], "invoke", length) == 0) |
| 1479 |
&& (butPtr->type > TYPE_LABEL)) { |
| 1480 |
if (argc > 2) { |
| 1481 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1482 |
" invoke\"", (char *)NULL); |
| 1483 |
goto error; |
| 1484 |
} |
| 1485 |
if (butPtr->state != STATE_DISABLED) { |
| 1486 |
result = InvokeButton(butPtr); |
| 1487 |
} |
| 1488 |
} else if ((c == 's') && (strncmp(argv[1], "select", length) == 0) |
| 1489 |
&& (butPtr->type >= TYPE_CHECK_BUTTON) && (butPtr->type < TYPE_MENU_BUTTON)) { |
| 1490 |
if (argc > 2) { |
| 1491 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1492 |
" select\"", (char *)NULL); |
| 1493 |
goto error; |
| 1494 |
} |
| 1495 |
result = ButtonSetValue(butPtr, butPtr->onValue, 1); |
| 1496 |
} else if ((c == 't') && (strncmp(argv[1], "toggle", length) == 0) |
| 1497 |
&& (length >= 2) && (butPtr->type == TYPE_CHECK_BUTTON)) { |
| 1498 |
if (argc > 2) { |
| 1499 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1500 |
" toggle\"", (char *)NULL); |
| 1501 |
goto error; |
| 1502 |
} |
| 1503 |
if (butPtr->flags & SELECTED) { |
| 1504 |
result = ButtonSetValue(butPtr, butPtr->offValue, 0); |
| 1505 |
} else { |
| 1506 |
result = ButtonSetValue(butPtr, butPtr->onValue, 0); |
| 1507 |
} |
| 1508 |
} else { |
| 1509 |
Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be ", |
| 1510 |
optionStrings[butPtr->type], (char *)NULL); |
| 1511 |
goto error; |
| 1512 |
} |
| 1513 |
Tcl_Release(butPtr); |
| 1514 |
return result; |
| 1515 |
|
| 1516 |
error: |
| 1517 |
Tcl_Release(butPtr); |
| 1518 |
return TCL_ERROR; |
| 1519 |
} |
| 1520 |
|
| 1521 |
/* |
| 1522 |
*---------------------------------------------------------------------- |
| 1523 |
* |
| 1524 |
* DestroyButton -- |
| 1525 |
* |
| 1526 |
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release |
| 1527 |
* to clean up the internal structure of a button at a safe time |
| 1528 |
* (when no-one is using it anymore). |
| 1529 |
* |
| 1530 |
* Results: |
| 1531 |
* None. |
| 1532 |
* |
| 1533 |
* Side effects: |
| 1534 |
* Everything associated with the widget is freed up. |
| 1535 |
* |
| 1536 |
*---------------------------------------------------------------------- |
| 1537 |
*/ |
| 1538 |
|
| 1539 |
static void |
| 1540 |
DestroyButton(butPtr) |
| 1541 |
Button *butPtr; /* Info about button widget. */ |
| 1542 |
{ |
| 1543 |
int i; |
| 1544 |
/* |
| 1545 |
* Free up all the stuff that requires special handling, then |
| 1546 |
* let Tk_FreeOptions handle all the standard option-related |
| 1547 |
* stuff. |
| 1548 |
*/ |
| 1549 |
butPtr->flags = BUTTON_DELETED; |
| 1550 |
if (butPtr->image != NULL) { |
| 1551 |
Tk_FreeImage(butPtr->image); |
| 1552 |
} |
| 1553 |
if (butPtr->activeImage != NULL) { |
| 1554 |
Tk_FreeImage(butPtr->activeImage); |
| 1555 |
} |
| 1556 |
if (butPtr->disabledImage != NULL) { |
| 1557 |
Tk_FreeImage(butPtr->disabledImage); |
| 1558 |
} |
| 1559 |
if (butPtr->bdImage != NULL) { |
| 1560 |
Tk_FreeImage(butPtr->bdImage); |
| 1561 |
} |
| 1562 |
if (butPtr->activeBdImage != NULL) { |
| 1563 |
Tk_FreeImage(butPtr->activeBdImage); |
| 1564 |
} |
| 1565 |
if (butPtr->disabledBdImage != NULL) { |
| 1566 |
Tk_FreeImage(butPtr->disabledBdImage); |
| 1567 |
} |
| 1568 |
if (butPtr->bdImageSized != NULL) { |
| 1569 |
Tk_FreeImage(butPtr->bdImageSized); |
| 1570 |
} |
| 1571 |
if (butPtr->selectImage != NULL) { |
| 1572 |
Tk_FreeImage(butPtr->selectImage); |
| 1573 |
} |
| 1574 |
if (butPtr->normalTextGC != None) { |
| 1575 |
Tk_FreeGC(butPtr->display, butPtr->normalTextGC); |
| 1576 |
} |
| 1577 |
if (butPtr->focusGC != None) { |
| 1578 |
Blt_FreePrivateGC(butPtr->display, butPtr->focusGC); |
| 1579 |
} |
| 1580 |
if (butPtr->activeTextGC != None) { |
| 1581 |
Tk_FreeGC(butPtr->display, butPtr->activeTextGC); |
| 1582 |
} |
| 1583 |
if (butPtr->gray != None) { |
| 1584 |
Tk_FreeBitmap(butPtr->display, butPtr->gray); |
| 1585 |
} |
| 1586 |
if (butPtr->disabledGC != None) { |
| 1587 |
Tk_FreeGC(butPtr->display, butPtr->disabledGC); |
| 1588 |
} |
| 1589 |
if (butPtr->copyGC != None) { |
| 1590 |
Tk_FreeGC(butPtr->display, butPtr->copyGC); |
| 1591 |
} |
| 1592 |
if (butPtr->selVarName != NULL && butPtr->tree == NULL) { |
| 1593 |
Tcl_UntraceVar(butPtr->interp, butPtr->selVarName, |
| 1594 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 1595 |
ButtonVarProc, (ClientData)butPtr); |
| 1596 |
} |
| 1597 |
if (butPtr->textVarName != NULL && butPtr->tree == NULL) { |
| 1598 |
Tcl_UntraceVar(butPtr->interp, butPtr->textVarName, |
| 1599 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 1600 |
ButtonTextVarProc, butPtr); |
| 1601 |
} |
| 1602 |
if (butPtr->selTrace != NULL) { |
| 1603 |
Blt_TreeDeleteTrace(butPtr->selTrace); |
| 1604 |
} |
| 1605 |
if (butPtr->textTrace != NULL) { |
| 1606 |
Blt_TreeDeleteTrace(butPtr->textTrace); |
| 1607 |
} |
| 1608 |
if (butPtr->tree) { |
| 1609 |
Blt_TreeReleaseToken(butPtr->tree); |
| 1610 |
} |
| 1611 |
if (butPtr->inBdTile != NULL) { |
| 1612 |
Blt_FreeTile(butPtr->inBdTile); |
| 1613 |
} |
| 1614 |
if (butPtr->activeTile != NULL) { |
| 1615 |
Blt_FreeTile(butPtr->activeTile); |
| 1616 |
} |
| 1617 |
if (butPtr->disabledTile != NULL) { |
| 1618 |
Blt_FreeTile(butPtr->disabledTile); |
| 1619 |
} |
| 1620 |
if (butPtr->innerTile != NULL) { |
| 1621 |
Blt_FreeTile(butPtr->innerTile); |
| 1622 |
} |
| 1623 |
if (butPtr->activeInnerTile != NULL) { |
| 1624 |
Blt_FreeTile(butPtr->activeInnerTile); |
| 1625 |
} |
| 1626 |
if (butPtr->disabledInnerTile != NULL) { |
| 1627 |
Blt_FreeTile(butPtr->disabledInnerTile); |
| 1628 |
} |
| 1629 |
if (butPtr->tile != NULL) { |
| 1630 |
Blt_FreeTile(butPtr->tile); |
| 1631 |
} |
| 1632 |
if (butPtr->shadow.color != NULL) { |
| 1633 |
Tk_FreeColor(butPtr->shadow.color); |
| 1634 |
} |
| 1635 |
if (butPtr->activeShadow.color != NULL) { |
| 1636 |
Tk_FreeColor(butPtr->activeShadow.color); |
| 1637 |
} |
| 1638 |
|
| 1639 |
for (i = 0; i < 9; i++) { |
| 1640 |
if (butPtr->icons[i]) Tk_FreeImage(butPtr->icons[i]); |
| 1641 |
butPtr->icons[i] = NULL; |
| 1642 |
} |
| 1643 |
#if (TK_MAJOR_VERSION > 4) |
| 1644 |
if (butPtr->textLayout) { |
| 1645 |
Tk_FreeTextLayout(butPtr->textLayout); |
| 1646 |
} |
| 1647 |
#endif |
| 1648 |
Tk_FreeOptions(configSpecs, (char *)butPtr, butPtr->display, |
| 1649 |
configFlags[butPtr->type]); |
| 1650 |
Tcl_EventuallyFree((ClientData)butPtr, TCL_DYNAMIC); |
| 1651 |
} |
| 1652 |
|
| 1653 |
/*ARGSUSED*/ |
| 1654 |
static void |
| 1655 |
TileChangedProc(clientData, tile) |
| 1656 |
ClientData clientData; |
| 1657 |
Blt_Tile tile; /* Not used. */ |
| 1658 |
{ |
| 1659 |
Button *butPtr = clientData; |
| 1660 |
|
| 1661 |
if (butPtr->tkwin != NULL) { |
| 1662 |
/* |
| 1663 |
* Arrange for the button to be redisplayed. |
| 1664 |
*/ |
| 1665 |
if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) { |
| 1666 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 1667 |
butPtr->flags |= REDRAW_PENDING; |
| 1668 |
} |
| 1669 |
} |
| 1670 |
} |
| 1671 |
|
| 1672 |
/* |
| 1673 |
*---------------------------------------------------------------------- |
| 1674 |
* |
| 1675 |
* ConfigureButton -- |
| 1676 |
* |
| 1677 |
* This procedure is called to process an argv/argc list, plus |
| 1678 |
* the Tk option database, in order to configure (or |
| 1679 |
* reconfigure) a button widget. |
| 1680 |
* |
| 1681 |
* Results: |
| 1682 |
* The return value is a standard Tcl result. If TCL_ERROR is |
| 1683 |
* returned, then interp->result contains an error message. |
| 1684 |
* |
| 1685 |
* Side effects: |
| 1686 |
* Configuration information, such as text string, colors, font, |
| 1687 |
* etc. get set for butPtr; old resources get freed, if there |
| 1688 |
* were any. The button is redisplayed. |
| 1689 |
* |
| 1690 |
*---------------------------------------------------------------------- |
| 1691 |
*/ |
| 1692 |
|
| 1693 |
static int |
| 1694 |
ConfigureButton(interp, butPtr, argc, argv, flags) |
| 1695 |
Tcl_Interp *interp; /* Used for error reporting. */ |
| 1696 |
register Button *butPtr; /* Information about widget; may or may |
| 1697 |
* not already have values for some fields. */ |
| 1698 |
int argc; /* Number of valid entries in argv. */ |
| 1699 |
char **argv; /* Arguments. */ |
| 1700 |
int flags; /* Flags to pass to Tk_ConfigureWidget. */ |
| 1701 |
{ |
| 1702 |
XGCValues gcValues; |
| 1703 |
GC newGC; |
| 1704 |
unsigned long mask; |
| 1705 |
Tk_Image image; |
| 1706 |
char *oldTextVar, *oldSelVar; |
| 1707 |
Blt_Tree oldTree; |
| 1708 |
int oldNode, result = TCL_OK; |
| 1709 |
char * oldABdStr = butPtr->activeBdImageString; |
| 1710 |
char * oldDBStr = butPtr->disabledBdImageString; |
| 1711 |
char * oldBDStr = butPtr->bdImageString; |
| 1712 |
int oldState = butPtr->state, fmask; |
| 1713 |
Tk_FakeWin *winPtr; |
| 1714 |
|
| 1715 |
winPtr = (Tk_FakeWin *) (butPtr->tkwin); |
| 1716 |
oldTree = butPtr->tree; |
| 1717 |
oldNode = butPtr->node; |
| 1718 |
|
| 1719 |
if (oldTree == NULL) { |
| 1720 |
oldTextVar = (butPtr->textVarName?strdup(butPtr->textVarName):NULL); |
| 1721 |
oldSelVar = (butPtr->selVarName?strdup(butPtr->selVarName):NULL); |
| 1722 |
} |
| 1723 |
|
| 1724 |
if (Blt_ConfigureWidget(interp, butPtr->tkwin, configSpecs, |
| 1725 |
argc, argv, (char *)butPtr, flags) != TCL_OK) { |
| 1726 |
if (oldTextVar) ckfree(oldTextVar); |
| 1727 |
if (oldTextVar) ckfree(oldSelVar); |
| 1728 |
return TCL_ERROR; |
| 1729 |
} |
| 1730 |
/* |
| 1731 |
* Eliminate any existing trace on variables monitored by the button. |
| 1732 |
*/ |
| 1733 |
|
| 1734 |
if (oldTree == NULL) { |
| 1735 |
if (oldTextVar != NULL) { |
| 1736 |
Tcl_UntraceVar(interp, oldTextVar, |
| 1737 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 1738 |
ButtonTextVarProc, (ClientData)butPtr); |
| 1739 |
ckfree(oldTextVar); |
| 1740 |
} |
| 1741 |
if (oldSelVar != NULL) { |
| 1742 |
Tcl_UntraceVar(interp, oldSelVar, |
| 1743 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 1744 |
ButtonVarProc, (ClientData)butPtr); |
| 1745 |
ckfree(oldSelVar); |
| 1746 |
} |
| 1747 |
} else { |
| 1748 |
if (butPtr->textTrace != NULL) { |
| 1749 |
Blt_TreeDeleteTrace(butPtr->textTrace); |
| 1750 |
butPtr->textTrace = NULL; |
| 1751 |
} |
| 1752 |
if (butPtr->selTrace != NULL) { |
| 1753 |
Blt_TreeDeleteTrace(butPtr->selTrace); |
| 1754 |
butPtr->selTrace = NULL; |
| 1755 |
} |
| 1756 |
|
| 1757 |
|
| 1758 |
} |
| 1759 |
/* |
| 1760 |
* A few options need special processing, such as setting the |
| 1761 |
* background from a 3-D border, or filling in complicated |
| 1762 |
* defaults that couldn't be specified to Tk_ConfigureWidget. |
| 1763 |
*/ |
| 1764 |
|
| 1765 |
|
| 1766 |
if (butPtr->bgTileTop) { |
| 1767 |
winPtr->flags |= TK_BGTILE_TOP; |
| 1768 |
} else { |
| 1769 |
winPtr->flags &= ~TK_BGTILE_TOP; |
| 1770 |
} |
| 1771 |
|
| 1772 |
if ((butPtr->state == STATE_ACTIVE) && !Tk_StrictMotif(butPtr->tkwin)) { |
| 1773 |
Tk_SetBackgroundFromBorder(butPtr->tkwin, CHOOSE(butPtr->normalBorder,butPtr->activeBorder)); |
| 1774 |
} |
| 1775 |
|
| 1776 |
if (butPtr->highlightWidth < 0) { |
| 1777 |
butPtr->highlightWidth = 0; |
| 1778 |
} |
| 1779 |
fmask = 0; |
| 1780 |
if (butPtr->tkfont) { |
| 1781 |
fmask = (GCForeground | GCBackground | GCFont); |
| 1782 |
gcValues.font = Tk_FontId(butPtr->tkfont); |
| 1783 |
gcValues.foreground = butPtr->normalFg->pixel; |
| 1784 |
gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel; |
| 1785 |
} |
| 1786 |
if (butPtr->activeTile != NULL) { |
| 1787 |
Blt_SetTileChangedProc(butPtr->activeTile, TileChangedProc, |
| 1788 |
(ClientData)butPtr); |
| 1789 |
} |
| 1790 |
if (butPtr->disabledTile != NULL) { |
| 1791 |
Blt_SetTileChangedProc(butPtr->disabledTile, TileChangedProc, |
| 1792 |
(ClientData)butPtr); |
| 1793 |
} |
| 1794 |
if (butPtr->innerTile != NULL) { |
| 1795 |
Blt_SetTileChangedProc(butPtr->innerTile, TileChangedProc, |
| 1796 |
(ClientData)butPtr); |
| 1797 |
} |
| 1798 |
if (butPtr->activeInnerTile != NULL) { |
| 1799 |
Blt_SetTileChangedProc(butPtr->activeInnerTile, TileChangedProc, |
| 1800 |
(ClientData)butPtr); |
| 1801 |
} |
| 1802 |
if (butPtr->disabledInnerTile != NULL) { |
| 1803 |
Blt_SetTileChangedProc(butPtr->disabledInnerTile, TileChangedProc, |
| 1804 |
(ClientData)butPtr); |
| 1805 |
} |
| 1806 |
if (butPtr->tile != NULL) { |
| 1807 |
Blt_SetTileChangedProc(butPtr->tile, TileChangedProc, |
| 1808 |
(ClientData)butPtr); |
| 1809 |
} |
| 1810 |
/* |
| 1811 |
* Note: GraphicsExpose events are disabled in normalTextGC because it's |
| 1812 |
* used to copy stuff from an off-screen pixmap onto the screen (we know |
| 1813 |
* that there's no problem with obscured areas). |
| 1814 |
*/ |
| 1815 |
gcValues.graphics_exposures = False; |
| 1816 |
newGC = Tk_GetGC(butPtr->tkwin, |
| 1817 |
fmask | GCGraphicsExposures, |
| 1818 |
&gcValues); |
| 1819 |
if (butPtr->normalTextGC != None) { |
| 1820 |
Tk_FreeGC(butPtr->display, butPtr->normalTextGC); |
| 1821 |
} |
| 1822 |
butPtr->normalTextGC = newGC; |
| 1823 |
|
| 1824 |
mask = (GCForeground | GCLineWidth ); |
| 1825 |
gcValues.line_width = 1; |
| 1826 |
if (LineIsDashed(butPtr->dashes)) { |
| 1827 |
mask |= GCLineStyle; |
| 1828 |
gcValues.line_style = LineOnOffDash; |
| 1829 |
} |
| 1830 |
newGC = Blt_GetPrivateGC(butPtr->tkwin, mask, &gcValues); |
| 1831 |
if (LineIsDashed(butPtr->dashes)) { |
| 1832 |
butPtr->dashes.offset = 2; |
| 1833 |
Blt_SetDashes(butPtr->display, newGC, &(butPtr->dashes)); |
| 1834 |
} |
| 1835 |
if (butPtr->focusGC != None) { |
| 1836 |
Blt_FreePrivateGC(butPtr->display, butPtr->focusGC); |
| 1837 |
} |
| 1838 |
butPtr->focusGC = newGC; |
| 1839 |
|
| 1840 |
if (butPtr->activeFg != NULL && butPtr->tkfont) { |
| 1841 |
gcValues.font = Tk_FontId(butPtr->tkfont); |
| 1842 |
gcValues.foreground = butPtr->activeFg->pixel; |
| 1843 |
gcValues.background = Tk_3DBorderColor(CHOOSE(butPtr->normalBorder,butPtr->activeBorder))->pixel; |
| 1844 |
newGC = Tk_GetGC(butPtr->tkwin, |
| 1845 |
fmask, &gcValues); |
| 1846 |
if (butPtr->activeTextGC != None) { |
| 1847 |
Tk_FreeGC(butPtr->display, butPtr->activeTextGC); |
| 1848 |
} |
| 1849 |
butPtr->activeTextGC = newGC; |
| 1850 |
} |
| 1851 |
|
| 1852 |
if (butPtr->type > TYPE_LABEL) { |
| 1853 |
gcValues.font = Tk_FontId(butPtr->tkfont); |
| 1854 |
gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel; |
| 1855 |
if ((butPtr->disabledFg != NULL) && ((butPtr->imageString == NULL) || butPtr->compound != COMPOUND_NONE)) { |
| 1856 |
gcValues.foreground = butPtr->disabledFg->pixel; |
| 1857 |
mask = GCForeground | GCBackground | GCFont; |
| 1858 |
} else { |
| 1859 |
gcValues.foreground = gcValues.background; |
| 1860 |
mask = GCForeground; |
| 1861 |
if (butPtr->gray == None) { |
| 1862 |
butPtr->gray = Tk_GetBitmap(NULL, butPtr->tkwin, "gray50"); |
| 1863 |
} |
| 1864 |
if (butPtr->gray != None) { |
| 1865 |
gcValues.fill_style = FillStippled; |
| 1866 |
gcValues.stipple = butPtr->gray; |
| 1867 |
mask |= GCFillStyle | GCStipple; |
| 1868 |
} |
| 1869 |
} |
| 1870 |
newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues); |
| 1871 |
if (butPtr->disabledGC != None) { |
| 1872 |
Tk_FreeGC(butPtr->display, butPtr->disabledGC); |
| 1873 |
} |
| 1874 |
butPtr->disabledGC = newGC; |
| 1875 |
} |
| 1876 |
if (butPtr->copyGC == None) { |
| 1877 |
butPtr->copyGC = Tk_GetGC(butPtr->tkwin, 0, &gcValues); |
| 1878 |
} |
| 1879 |
if (butPtr->padX < 0) { |
| 1880 |
butPtr->padX = 0; |
| 1881 |
} |
| 1882 |
if (butPtr->padY < 0) { |
| 1883 |
butPtr->padY = 0; |
| 1884 |
} |
| 1885 |
if (butPtr->tree && butPtr->textVarName != NULL && strchr(butPtr->textVarName,'(') != NULL) { |
| 1886 |
Tcl_AppendResult(interp, "can not use array", 0); |
| 1887 |
ckfree(butPtr->textVarName); |
| 1888 |
butPtr->textVarName = NULL; |
| 1889 |
result = TCL_ERROR; |
| 1890 |
} |
| 1891 |
|
| 1892 |
if (butPtr->type >= TYPE_CHECK_BUTTON && (butPtr->type < TYPE_MENU_BUTTON)) { |
| 1893 |
CONST char *value; |
| 1894 |
|
| 1895 |
if (butPtr->tree && butPtr->selVarName != NULL && strchr(butPtr->selVarName,'(') != NULL) { |
| 1896 |
Tcl_AppendResult(interp, "can not use array", 0); |
| 1897 |
ckfree(butPtr->selVarName); |
| 1898 |
butPtr->selVarName = Blt_Malloc(strlen(Tk_Name(butPtr->tkwin)) + 1); |
| 1899 |
strcpy(butPtr->selVarName, Tk_Name(butPtr->tkwin)); |
| 1900 |
return TCL_ERROR; |
| 1901 |
} |
| 1902 |
|
| 1903 |
if (butPtr->selVarName == NULL) { |
| 1904 |
butPtr->selVarName = Blt_Malloc(strlen(Tk_Name(butPtr->tkwin)) + 1); |
| 1905 |
strcpy(butPtr->selVarName, Tk_Name(butPtr->tkwin)); |
| 1906 |
} |
| 1907 |
/* |
| 1908 |
* Select the button if the associated variable has the |
| 1909 |
* appropriate value, initialize the variable if it doesn't |
| 1910 |
* exist, then set a trace on the variable to monitor future |
| 1911 |
* changes to its value. |
| 1912 |
*/ |
| 1913 |
|
| 1914 |
butPtr->flags &= ~SELECTED; |
| 1915 |
if (butPtr->tree == NULL) { |
| 1916 |
value = Tcl_GetVar(interp, butPtr->selVarName, TCL_GLOBAL_ONLY); |
| 1917 |
if (value != NULL) { |
| 1918 |
if (strcmp(value, butPtr->onValue) == 0) { |
| 1919 |
butPtr->flags |= SELECTED; |
| 1920 |
} |
| 1921 |
} else { |
| 1922 |
if (Tcl_SetVar(interp, butPtr->selVarName, |
| 1923 |
(butPtr->type == TYPE_CHECK_BUTTON) ? butPtr->offValue : "", |
| 1924 |
TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) { |
| 1925 |
return TCL_ERROR; |
| 1926 |
} |
| 1927 |
} |
| 1928 |
Tcl_TraceVar(interp, butPtr->selVarName, |
| 1929 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 1930 |
ButtonVarProc, (ClientData)butPtr); |
| 1931 |
} else { |
| 1932 |
Tcl_Obj *valuePtr; |
| 1933 |
Blt_TreeNode nodePtr; |
| 1934 |
|
| 1935 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 1936 |
if (nodePtr == NULL) { |
| 1937 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 1938 |
} |
| 1939 |
if (nodePtr == NULL) { |
| 1940 |
return TCL_ERROR; |
| 1941 |
} |
| 1942 |
if (Blt_TreeGetValue(NULL, butPtr->tree, |
| 1943 |
nodePtr, butPtr->selVarName, &valuePtr) == TCL_OK) { |
| 1944 |
} else { |
| 1945 |
valuePtr = Tcl_NewStringObj(((butPtr->type == TYPE_CHECK_BUTTON) ? butPtr->offValue : ""),-1); |
| 1946 |
Tcl_IncrRefCount(valuePtr); |
| 1947 |
if (Blt_TreeSetValue(interp, butPtr->tree, |
| 1948 |
nodePtr, butPtr->selVarName, valuePtr) != TCL_OK) { |
| 1949 |
Tcl_DecrRefCount(valuePtr); |
| 1950 |
return TCL_ERROR; |
| 1951 |
} |
| 1952 |
Tcl_DecrRefCount(valuePtr); |
| 1953 |
} |
| 1954 |
value = (valuePtr?Tcl_GetString(valuePtr):""); |
| 1955 |
if (strcmp(value, butPtr->onValue) == 0) { |
| 1956 |
butPtr->flags |= SELECTED; |
| 1957 |
} |
| 1958 |
butPtr->selTrace = Blt_TreeCreateTrace(butPtr->tree, |
| 1959 |
nodePtr, butPtr->selVarName, NULL, |
| 1960 |
TREE_TRACE_UNSET|TREE_TRACE_WRITE, TreeTraceProc, (ClientData)butPtr); |
| 1961 |
} |
| 1962 |
} |
| 1963 |
/* |
| 1964 |
* Get the images for the widget, if there are any. Allocate the |
| 1965 |
* new images before freeing the old ones, so that the reference |
| 1966 |
* counts don't go to zero and cause image data to be discarded. |
| 1967 |
*/ |
| 1968 |
|
| 1969 |
if (oldABdStr != butPtr->activeBdImageString || |
| 1970 |
oldDBStr != butPtr->disabledBdImageString || |
| 1971 |
oldBDStr != butPtr->bdImageString || |
| 1972 |
oldState != butPtr->state) { |
| 1973 |
butPtr->flags |= BUTTON_DIRTYBD; |
| 1974 |
} |
| 1975 |
|
| 1976 |
if (butPtr->imageString != NULL) { |
| 1977 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 1978 |
butPtr->imageString, ButtonImageProc, (ClientData)butPtr); |
| 1979 |
if (image == NULL) { |
| 1980 |
return TCL_ERROR; |
| 1981 |
} |
| 1982 |
} else { |
| 1983 |
image = NULL; |
| 1984 |
} |
| 1985 |
if (butPtr->image != NULL) { |
| 1986 |
Tk_FreeImage(butPtr->image); |
| 1987 |
} |
| 1988 |
butPtr->image = image; |
| 1989 |
|
| 1990 |
if (butPtr->disabledImageString != NULL) { |
| 1991 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 1992 |
butPtr->disabledImageString, ButtonImageProc, (ClientData)butPtr); |
| 1993 |
if (image == NULL) { |
| 1994 |
return TCL_ERROR; |
| 1995 |
} |
| 1996 |
} else { |
| 1997 |
image = NULL; |
| 1998 |
} |
| 1999 |
if (butPtr->disabledImage != NULL) { |
| 2000 |
Tk_FreeImage(butPtr->disabledImage); |
| 2001 |
} |
| 2002 |
butPtr->disabledImage = image; |
| 2003 |
|
| 2004 |
if (butPtr->activeImageString != NULL) { |
| 2005 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2006 |
butPtr->activeImageString, ButtonImageProc, (ClientData)butPtr); |
| 2007 |
if (image == NULL) { |
| 2008 |
return TCL_ERROR; |
| 2009 |
} |
| 2010 |
} else { |
| 2011 |
image = NULL; |
| 2012 |
} |
| 2013 |
if (butPtr->activeImage != NULL) { |
| 2014 |
Tk_FreeImage(butPtr->activeImage); |
| 2015 |
} |
| 2016 |
butPtr->activeImage = image; |
| 2017 |
|
| 2018 |
if (butPtr->bdImageString != NULL) { |
| 2019 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2020 |
butPtr->bdImageString, ButtonImageBdProc, (ClientData)butPtr); |
| 2021 |
if (image == NULL) { |
| 2022 |
return TCL_ERROR; |
| 2023 |
} |
| 2024 |
} else { |
| 2025 |
image = NULL; |
| 2026 |
} |
| 2027 |
if (butPtr->bdImage != NULL) { |
| 2028 |
Tk_FreeImage(butPtr->bdImage); |
| 2029 |
} |
| 2030 |
butPtr->bdImage = image; |
| 2031 |
|
| 2032 |
if (butPtr->activeBdImageString != NULL) { |
| 2033 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2034 |
butPtr->activeBdImageString, ButtonImageBdProc, (ClientData)butPtr); |
| 2035 |
if (image == NULL) { |
| 2036 |
return TCL_ERROR; |
| 2037 |
} |
| 2038 |
} else { |
| 2039 |
image = NULL; |
| 2040 |
} |
| 2041 |
if (butPtr->activeBdImage != NULL) { |
| 2042 |
Tk_FreeImage(butPtr->activeBdImage); |
| 2043 |
} |
| 2044 |
butPtr->activeBdImage = image; |
| 2045 |
|
| 2046 |
if (butPtr->disabledBdImageString != NULL) { |
| 2047 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2048 |
butPtr->disabledBdImageString, ButtonImageBdProc, (ClientData)butPtr); |
| 2049 |
if (image == NULL) { |
| 2050 |
return TCL_ERROR; |
| 2051 |
} |
| 2052 |
} else { |
| 2053 |
image = NULL; |
| 2054 |
} |
| 2055 |
if (butPtr->disabledBdImage != NULL) { |
| 2056 |
Tk_FreeImage(butPtr->disabledBdImage); |
| 2057 |
} |
| 2058 |
butPtr->disabledBdImage = image; |
| 2059 |
|
| 2060 |
if (butPtr->selectImageString != NULL) { |
| 2061 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2062 |
butPtr->selectImageString, ButtonSelectImageProc, |
| 2063 |
(ClientData)butPtr); |
| 2064 |
if (image == NULL) { |
| 2065 |
return TCL_ERROR; |
| 2066 |
} |
| 2067 |
} else { |
| 2068 |
image = NULL; |
| 2069 |
} |
| 2070 |
if (butPtr->selectImage != NULL) { |
| 2071 |
Tk_FreeImage(butPtr->selectImage); |
| 2072 |
} |
| 2073 |
butPtr->selectImage = image; |
| 2074 |
|
| 2075 |
if (butPtr->tristateImageString != NULL) { |
| 2076 |
image = Tk_GetImage(butPtr->interp, butPtr->tkwin, |
| 2077 |
butPtr->tristateImageString, ButtonSelectImageProc, |
| 2078 |
(ClientData)butPtr); |
| 2079 |
if (image == NULL) { |
| 2080 |
return TCL_ERROR; |
| 2081 |
} |
| 2082 |
} else { |
| 2083 |
image = NULL; |
| 2084 |
} |
| 2085 |
if (butPtr->tristateImage != NULL) { |
| 2086 |
Tk_FreeImage(butPtr->tristateImage); |
| 2087 |
} |
| 2088 |
butPtr->tristateImage = image; |
| 2089 |
|
| 2090 |
if ((butPtr->textVarName != NULL)) { |
| 2091 |
/* |
| 2092 |
* The button must display the value of a variable: set up a trace |
| 2093 |
* on the variable's value, create the variable if it doesn't |
| 2094 |
* exist, and fetch its current value. |
| 2095 |
*/ |
| 2096 |
|
| 2097 |
CONST char *value; |
| 2098 |
|
| 2099 |
if (butPtr->tree == NULL) { |
| 2100 |
value = Tcl_GetVar(interp, butPtr->textVarName, TCL_GLOBAL_ONLY); |
| 2101 |
if (value == NULL) { |
| 2102 |
if (Tcl_SetVar(interp, butPtr->textVarName, butPtr->textPtr, |
| 2103 |
TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) { |
| 2104 |
return TCL_ERROR; |
| 2105 |
} |
| 2106 |
} else { |
| 2107 |
if (butPtr->textPtr != NULL) { |
| 2108 |
Blt_Free(butPtr->textPtr); |
| 2109 |
} |
| 2110 |
butPtr->textPtr = Blt_Malloc(strlen(value) + 1); |
| 2111 |
strcpy(butPtr->textPtr, value); |
| 2112 |
} |
| 2113 |
Tcl_TraceVar(interp, butPtr->textVarName, |
| 2114 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 2115 |
ButtonTextVarProc, (ClientData)butPtr); |
| 2116 |
} else { |
| 2117 |
Tcl_Obj *valuePtr; |
| 2118 |
Blt_TreeNode nodePtr; |
| 2119 |
|
| 2120 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 2121 |
if (nodePtr == NULL) { |
| 2122 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 2123 |
} |
| 2124 |
if (nodePtr == NULL) { |
| 2125 |
return TCL_ERROR; |
| 2126 |
} |
| 2127 |
if (Blt_TreeGetValue(NULL, butPtr->tree, |
| 2128 |
nodePtr, butPtr->textVarName, &valuePtr) == TCL_OK) { |
| 2129 |
} else { |
| 2130 |
valuePtr = Tcl_NewStringObj("",-1); |
| 2131 |
Tcl_IncrRefCount(valuePtr); |
| 2132 |
if (Blt_TreeSetValue(interp, butPtr->tree, |
| 2133 |
nodePtr, butPtr->textVarName, valuePtr) != TCL_OK) { |
| 2134 |
Tcl_DecrRefCount(valuePtr); |
| 2135 |
return TCL_ERROR; |
| 2136 |
} |
| 2137 |
Tcl_DecrRefCount(valuePtr); |
| 2138 |
} |
| 2139 |
|
| 2140 |
value = (valuePtr? Tcl_GetString(valuePtr):""); |
| 2141 |
if (butPtr->textPtr != NULL) { |
| 2142 |
Blt_Free(butPtr->textPtr); |
| 2143 |
} |
| 2144 |
butPtr->textPtr = Blt_Malloc(strlen(value) + 1); |
| 2145 |
strcpy(butPtr->textPtr, value); |
| 2146 |
|
| 2147 |
butPtr->textTrace = Blt_TreeCreateTrace(butPtr->tree, |
| 2148 |
nodePtr, butPtr->textVarName, NULL, |
| 2149 |
TREE_TRACE_UNSET|TREE_TRACE_WRITE, TreeTextTraceProc, (ClientData)butPtr); |
| 2150 |
} |
| 2151 |
} |
| 2152 |
|
| 2153 |
if ((butPtr->bitmap != None) || (butPtr->image != NULL)) { |
| 2154 |
if (Tk_GetPixels(interp, butPtr->tkwin, butPtr->widthString, |
| 2155 |
&butPtr->width) != TCL_OK) { |
| 2156 |
widthError: |
| 2157 |
Tcl_AddErrorInfo(interp, "\n (processing -width option)"); |
| 2158 |
return TCL_ERROR; |
| 2159 |
} |
| 2160 |
if (Tk_GetPixels(interp, butPtr->tkwin, butPtr->heightString, |
| 2161 |
&butPtr->height) != TCL_OK) { |
| 2162 |
heightError: |
| 2163 |
Tcl_AddErrorInfo(interp, "\n (processing -height option)"); |
| 2164 |
return TCL_ERROR; |
| 2165 |
} |
| 2166 |
} else { |
| 2167 |
if (Tcl_GetInt(interp, butPtr->widthString, &butPtr->width) |
| 2168 |
!= TCL_OK) { |
| 2169 |
goto widthError; |
| 2170 |
} |
| 2171 |
if (Tcl_GetInt(interp, butPtr->heightString, &butPtr->height) |
| 2172 |
!= TCL_OK) { |
| 2173 |
goto heightError; |
| 2174 |
} |
| 2175 |
} |
| 2176 |
ComputeButtonGeometry(butPtr); |
| 2177 |
|
| 2178 |
/* |
| 2179 |
* Lastly, arrange for the button to be redisplayed. |
| 2180 |
*/ |
| 2181 |
|
| 2182 |
if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) { |
| 2183 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 2184 |
butPtr->flags |= REDRAW_PENDING; |
| 2185 |
} |
| 2186 |
return result; |
| 2187 |
} |
| 2188 |
|
| 2189 |
/* |
| 2190 |
*---------------------------------------------------------------------- |
| 2191 |
* |
| 2192 |
* DisplayButton -- |
| 2193 |
* |
| 2194 |
* This procedure is invoked to display a button widget. It is |
| 2195 |
* normally invoked as an idle handler. |
| 2196 |
* |
| 2197 |
* Results: |
| 2198 |
* None. |
| 2199 |
* |
| 2200 |
* Side effects: |
| 2201 |
* Commands are output to X to display the button in its |
| 2202 |
* current mode. The REDRAW_PENDING flag is cleared. |
| 2203 |
* |
| 2204 |
*---------------------------------------------------------------------- |
| 2205 |
*/ |
| 2206 |
|
| 2207 |
static void |
| 2208 |
DisplayButton(clientData) |
| 2209 |
ClientData clientData; /* Information about widget. */ |
| 2210 |
{ |
| 2211 |
register Button *butPtr = clientData; |
| 2212 |
GC gc; |
| 2213 |
Tk_3DBorder border; |
| 2214 |
Pixmap pixmap; |
| 2215 |
int x = 0; /* Initialization only needed to stop |
| 2216 |
* compiler warning. */ |
| 2217 |
int y, relief; |
| 2218 |
register Tk_Window tkwin = butPtr->tkwin; |
| 2219 |
int offset = 0; /* 0 means this is a label widget. 1 means |
| 2220 |
* it is a flavor of button, so we offset |
| 2221 |
* the text to make the button appear to |
| 2222 |
* move up and down as the relief changes. */ |
| 2223 |
Blt_Tile tile, bgTile, inTile; |
| 2224 |
int borderWidth, drawBorder; |
| 2225 |
int textXOffset, textYOffset; |
| 2226 |
int haveImage = 0, haveText = 0; |
| 2227 |
int imageWidth, imageHeight; |
| 2228 |
int imageXOffset = 0, imageYOffset = 0; |
| 2229 |
int fullWidth, fullHeight; |
| 2230 |
int incFull = 0, xAdj = 0, yAdj = 0, inMirror = 0, dirty = 0, iSpc; |
| 2231 |
Tk_Image image, bdImage, curImage; |
| 2232 |
|
| 2233 |
bdImage = butPtr->bdImage; |
| 2234 |
if (butPtr->state == STATE_ACTIVE && butPtr->activeBdImage != NULL) { |
| 2235 |
bdImage = butPtr->activeBdImage; |
| 2236 |
} else if (butPtr->state == STATE_DISABLED && butPtr->disabledBdImage != NULL) { |
| 2237 |
bdImage = butPtr->disabledBdImage; |
| 2238 |
} |
| 2239 |
image = butPtr->image; |
| 2240 |
curImage = butPtr->image; |
| 2241 |
if (butPtr->state == STATE_DISABLED && butPtr->disabledImage != NULL) { |
| 2242 |
curImage = butPtr->disabledImage; |
| 2243 |
} |
| 2244 |
if (butPtr->state == STATE_ACTIVE && butPtr->activeImage != NULL) { |
| 2245 |
curImage = butPtr->activeImage; |
| 2246 |
} |
| 2247 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 2248 |
return; |
| 2249 |
} |
| 2250 |
if ((butPtr->flags & BUTTON_DIRTYBD)) { |
| 2251 |
butPtr->flags &= ~BUTTON_DIRTYBD; |
| 2252 |
dirty = 1; |
| 2253 |
} |
| 2254 |
|
| 2255 |
if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { |
| 2256 |
image = butPtr->selectImage; |
| 2257 |
} else if ((butPtr->tristateImage != NULL) && (butPtr->flags & TRISTATED)) { |
| 2258 |
image = butPtr->tristateImage; |
| 2259 |
} else { |
| 2260 |
image = curImage; |
| 2261 |
} |
| 2262 |
butPtr->flags &= ~REDRAW_PENDING; |
| 2263 |
if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { |
| 2264 |
return; |
| 2265 |
} |
| 2266 |
|
| 2267 |
if (butPtr->flags & BUTTON_LAYOUT) { |
| 2268 |
butPtr->flags &= ~BUTTON_LAYOUT; |
| 2269 |
ComputeButtonGeometry(butPtr); |
| 2270 |
} |
| 2271 |
|
| 2272 |
iSpc = butPtr->indicatorSpace; |
| 2273 |
if (butPtr->type == TYPE_MENU_BUTTON) { |
| 2274 |
iSpc = 0; |
| 2275 |
xAdj = butPtr->indicatorSpace; |
| 2276 |
} |
| 2277 |
|
| 2278 |
drawBorder = 1; |
| 2279 |
|
| 2280 |
if (image != NULL) { |
| 2281 |
Tk_SizeOfImage(image, &imageWidth, &imageHeight); |
| 2282 |
haveImage = 1; |
| 2283 |
} else if (butPtr->bitmap != None) { |
| 2284 |
Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &imageWidth, &imageHeight); |
| 2285 |
haveImage = 1; |
| 2286 |
} |
| 2287 |
haveText = (butPtr->textPtr != NULL && butPtr->textPtr[0]); |
| 2288 |
relief = butPtr->relief; |
| 2289 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && (butPtr->type < TYPE_MENU_BUTTON) && !butPtr->indicatorOn) { |
| 2290 |
if (butPtr->flags & SELECTED) { |
| 2291 |
relief = TK_RELIEF_SUNKEN; |
| 2292 |
} else if (butPtr->overRelief != relief) { |
| 2293 |
relief = butPtr->offRelief; |
| 2294 |
} |
| 2295 |
} |
| 2296 |
|
| 2297 |
if ((butPtr->type == TYPE_BUTTON) && (bdImage == NULL) && !Tk_StrictMotif(butPtr->tkwin)) { |
| 2298 |
offset = 1; |
| 2299 |
} |
| 2300 |
|
| 2301 |
#define TILECHOOSE(t2,t1) (Blt_HasTile(t1) ? t1 : (Blt_HasTile(t2) ? t2 : NULL)) |
| 2302 |
|
| 2303 |
tile = inTile = butPtr->innerTile; |
| 2304 |
bgTile =( Blt_HasTile(butPtr->tile) ? butPtr->tile : NULL); |
| 2305 |
if (butPtr->bdMaskColor == NULL) { |
| 2306 |
tile = TILECHOOSE(tile,butPtr->innerTile); |
| 2307 |
bgTile = TILECHOOSE(bgTile,butPtr->innerTile); |
| 2308 |
} |
| 2309 |
border = butPtr->normalBorder; |
| 2310 |
borderWidth = butPtr->borderWidth; |
| 2311 |
|
| 2312 |
gc = butPtr->normalTextGC; |
| 2313 |
|
| 2314 |
if (butPtr->state == STATE_DISABLED) { |
| 2315 |
if (Blt_HasTile(butPtr->disabledTile)) { |
| 2316 |
tile = butPtr->disabledTile; |
| 2317 |
bgTile = butPtr->disabledTile; |
| 2318 |
} |
| 2319 |
if (butPtr->disabledFg != NULL && butPtr->disabledGC) { |
| 2320 |
gc = butPtr->disabledGC; |
| 2321 |
} |
| 2322 |
if (Blt_HasTile(butPtr->disabledInnerTile)) { |
| 2323 |
inTile = butPtr->disabledInnerTile; |
| 2324 |
} |
| 2325 |
} else if ((butPtr->state == STATE_ACTIVE) && butPtr->activeFg != NULL |
| 2326 |
&& !Tk_StrictMotif(butPtr->tkwin)) { |
| 2327 |
gc = butPtr->activeTextGC; |
| 2328 |
border = CHOOSE(butPtr->normalBorder,butPtr->activeBorder); |
| 2329 |
tile = TILECHOOSE(tile,butPtr->activeTile); |
| 2330 |
bgTile = TILECHOOSE(bgTile,butPtr->activeTile); |
| 2331 |
if (Blt_HasTile(butPtr->activeInnerTile)) { |
| 2332 |
inTile = butPtr->activeInnerTile; |
| 2333 |
} |
| 2334 |
} |
| 2335 |
if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE) |
| 2336 |
&& (butPtr->selectBorder != NULL) && !butPtr->indicatorOn |
| 2337 |
&& butPtr->type != TYPE_MENU_BUTTON) { |
| 2338 |
border = butPtr->selectBorder; |
| 2339 |
} |
| 2340 |
/* |
| 2341 |
* Override the relief specified for the button if this is a |
| 2342 |
* checkbutton or radiobutton and there's no indicator. |
| 2343 |
*/ |
| 2344 |
|
| 2345 |
relief = butPtr->relief; |
| 2346 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && (butPtr->type < TYPE_MENU_BUTTON) && !butPtr->indicatorOn) { |
| 2347 |
relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN |
| 2348 |
: TK_RELIEF_RAISED; |
| 2349 |
} |
| 2350 |
|
| 2351 |
/* |
| 2352 |
* In order to avoid screen flashes, this procedure redraws |
| 2353 |
* the button in a pixmap, then copies the pixmap to the |
| 2354 |
* screen in a single operation. This means that there's no |
| 2355 |
* point in time where the on-sreen image has been cleared. |
| 2356 |
*/ |
| 2357 |
|
| 2358 |
pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin), |
| 2359 |
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); |
| 2360 |
|
| 2361 |
if (Blt_HasTile(bgTile)) { |
| 2362 |
Blt_SetTileOrigin(tkwin, bgTile, 0, 0); |
| 2363 |
Blt_TileRectangle(tkwin, pixmap, bgTile, 0, 0, Tk_Width(tkwin), |
| 2364 |
Tk_Height(tkwin)); |
| 2365 |
} else { |
| 2366 |
Tk_3DBorder curBorder = border; |
| 2367 |
Blt_Fill3DRectangle(tkwin, pixmap, curBorder, 0, 0, Tk_Width(tkwin), |
| 2368 |
Tk_Height(tkwin), 0, TK_RELIEF_FLAT); |
| 2369 |
} |
| 2370 |
if (bdImage) { |
| 2371 |
if (butPtr->bdImageSized == NULL) { |
| 2372 |
/* TODO: would be nice if we could get rid of Tcl visible image for photo */ |
| 2373 |
butPtr->bdImageSized = Blt_CreateTemporaryImage(butPtr->interp, tkwin, butPtr); |
| 2374 |
} |
| 2375 |
if (butPtr->bdImageSized != NULL) { |
| 2376 |
int width = 0, height = 0, bdWid = butPtr->borderWidth + butPtr->highlightWidth; |
| 2377 |
int wWidth = Tk_Width(tkwin)-bdWid*2, wHeight = Tk_Height(tkwin)-bdWid*2; |
| 2378 |
int result = TCL_OK; |
| 2379 |
Tk_SizeOfImage(butPtr->bdImageSized, &width, &height); |
| 2380 |
/*if (butPtr->bdHalo>=0 && butPtr->state != STATE_ACTIVE) { drawBorder = 0; } */ |
| 2381 |
if (width != wWidth || height != wHeight || dirty) { |
| 2382 |
Tk_PhotoHandle destPhoto; |
| 2383 |
char *dName, *sName; |
| 2384 |
dName = Blt_NameOfImage(butPtr->bdImageSized); |
| 2385 |
if (dName == NULL) { |
| 2386 |
Tk_FreeImage(butPtr->bdImageSized); |
| 2387 |
butPtr->bdImageSized = Blt_CreateTemporaryImage(butPtr->interp, tkwin, butPtr); |
| 2388 |
dName = Blt_NameOfImage(butPtr->bdImageSized); |
| 2389 |
} |
| 2390 |
sName = Blt_NameOfImage(bdImage); |
| 2391 |
destPhoto = Tk_FindPhoto(butPtr->interp, dName); |
| 2392 |
if (sName && dName && destPhoto) { |
| 2393 |
int nWidth, nHeight; |
| 2394 |
nWidth = ((wWidth+1) & ~0x1); |
| 2395 |
nHeight = ((wHeight+1) & ~0x1); |
| 2396 |
Tk_PhotoSetSize(destPhoto, nWidth, nHeight); |
| 2397 |
result = Blt_ImageMirror(butPtr->interp, sName, dName, butPtr->bdHalo<0?MIRROR_INNER:MIRROR_OUTER, butPtr->bdHalo<0?0:butPtr->bdHalo); |
| 2398 |
if (result == TCL_OK && butPtr->bdMaskColor && inTile) { |
| 2399 |
char *tName = Blt_NameOfTile(inTile); |
| 2400 |
result = Blt_ImageMergeInner(butPtr->interp, dName, tName, dName, butPtr->bdMaskColor, 0); |
| 2401 |
} |
| 2402 |
} |
| 2403 |
} |
| 2404 |
if (butPtr->bdHalo<0 && result == TCL_OK) { |
| 2405 |
inMirror = 1; |
| 2406 |
} |
| 2407 |
if (result == TCL_OK && inMirror == 0) { |
| 2408 |
Tk_RedrawImage(butPtr->bdImageSized, 0, 0, wWidth, wHeight, pixmap, bdWid, bdWid); |
| 2409 |
} |
| 2410 |
} |
| 2411 |
} |
| 2412 |
textXOffset = 0; |
| 2413 |
textYOffset = 0; |
| 2414 |
|
| 2415 |
if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 2416 |
fullWidth = 0; |
| 2417 |
fullHeight = 0; |
| 2418 |
|
| 2419 |
switch (butPtr->compound) { |
| 2420 |
case COMPOUND_TOP: |
| 2421 |
case COMPOUND_BOTTOM: |
| 2422 |
/* |
| 2423 |
* Image is above or below text. |
| 2424 |
*/ |
| 2425 |
|
| 2426 |
if (butPtr->compound == COMPOUND_TOP) { |
| 2427 |
textYOffset = imageHeight + butPtr->padY + butPtr->yOffset; |
| 2428 |
} else { |
| 2429 |
imageYOffset = butPtr->textHeight + butPtr->padY + butPtr->yOffset; |
| 2430 |
} |
| 2431 |
fullHeight = imageHeight + butPtr->textHeight + butPtr->padY; |
| 2432 |
fullWidth = (imageWidth > butPtr->textWidth ? imageWidth : butPtr->textWidth); |
| 2433 |
textXOffset = (fullWidth - butPtr->textWidth)/2 + butPtr->xOffset; |
| 2434 |
imageXOffset = (fullWidth - imageWidth)/2 + butPtr->xOffset; |
| 2435 |
break; |
| 2436 |
case COMPOUND_LEFT: |
| 2437 |
case COMPOUND_RIGHT: |
| 2438 |
/* |
| 2439 |
* Image is left or right of text. |
| 2440 |
*/ |
| 2441 |
|
| 2442 |
if (butPtr->compound == COMPOUND_LEFT) { |
| 2443 |
textXOffset = imageWidth + butPtr->padX + butPtr->xOffset; |
| 2444 |
} else { |
| 2445 |
imageXOffset = butPtr->textWidth + butPtr->padX + butPtr->xOffset; |
| 2446 |
} |
| 2447 |
fullWidth = butPtr->textWidth + butPtr->padX + imageWidth; |
| 2448 |
fullHeight = (imageHeight > butPtr->textHeight ? imageHeight : butPtr->textHeight); |
| 2449 |
textYOffset = (fullHeight - butPtr->textHeight)/2 + butPtr->yOffset; |
| 2450 |
imageYOffset = (fullHeight - imageHeight)/2 + butPtr->yOffset; |
| 2451 |
break; |
| 2452 |
case COMPOUND_CENTER: |
| 2453 |
/* |
| 2454 |
* Image and text are superimposed. |
| 2455 |
*/ |
| 2456 |
|
| 2457 |
fullWidth = (imageWidth > butPtr->textWidth ? imageWidth : |
| 2458 |
butPtr->textWidth); |
| 2459 |
fullHeight = (imageHeight > butPtr->textHeight ? imageHeight : |
| 2460 |
butPtr->textHeight); |
| 2461 |
textXOffset = (fullWidth - butPtr->textWidth)/2 + butPtr->xOffset; |
| 2462 |
imageXOffset = (fullWidth - imageWidth)/2 + butPtr->xOffset; |
| 2463 |
textYOffset = (fullHeight - butPtr->textHeight)/2 + butPtr->yOffset; |
| 2464 |
imageYOffset = (fullHeight - imageHeight)/2 + butPtr->yOffset; |
| 2465 |
break; |
| 2466 |
case COMPOUND_NONE: |
| 2467 |
imageXOffset += butPtr->xOffset; |
| 2468 |
imageYOffset += butPtr->yOffset; |
| 2469 |
break; |
| 2470 |
} |
| 2471 |
|
| 2472 |
ComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, |
| 2473 |
iSpc + fullWidth, fullHeight, &x, &y, xAdj, yAdj); |
| 2474 |
|
| 2475 |
x += iSpc; |
| 2476 |
|
| 2477 |
x += offset; |
| 2478 |
y += offset; |
| 2479 |
if (relief == TK_RELIEF_RAISED) { |
| 2480 |
x -= offset; |
| 2481 |
y -= offset; |
| 2482 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 2483 |
x += offset; |
| 2484 |
y += offset; |
| 2485 |
} |
| 2486 |
|
| 2487 |
imageXOffset += x; |
| 2488 |
imageYOffset += y; |
| 2489 |
|
| 2490 |
if (image != NULL) { |
| 2491 |
/* |
| 2492 |
* Do boundary clipping, so that Tk_RedrawImage is passed valid |
| 2493 |
* coordinates. [Bug 979239] |
| 2494 |
*/ |
| 2495 |
|
| 2496 |
if (imageXOffset < 0) { |
| 2497 |
imageXOffset = 0; |
| 2498 |
} |
| 2499 |
if (imageYOffset < 0) { |
| 2500 |
imageYOffset = 0; |
| 2501 |
} |
| 2502 |
if (imageWidth > Tk_Width(tkwin)) { |
| 2503 |
imageWidth = Tk_Width(tkwin); |
| 2504 |
} |
| 2505 |
if (imageHeight > Tk_Height(tkwin)) { |
| 2506 |
imageHeight = Tk_Height(tkwin); |
| 2507 |
} |
| 2508 |
if ((imageWidth + imageXOffset) > Tk_Width(tkwin)) { |
| 2509 |
imageXOffset = Tk_Width(tkwin) - imageWidth; |
| 2510 |
} |
| 2511 |
if ((imageHeight + imageYOffset) > Tk_Height(tkwin)) { |
| 2512 |
imageYOffset = Tk_Height(tkwin) - imageHeight; |
| 2513 |
} |
| 2514 |
|
| 2515 |
Tk_RedrawImage(image, 0, 0, imageWidth, imageHeight, pixmap, imageXOffset, |
| 2516 |
imageYOffset); |
| 2517 |
} else { |
| 2518 |
XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset); |
| 2519 |
XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, |
| 2520 |
0, 0, (unsigned int) imageWidth, (unsigned int) imageHeight, |
| 2521 |
imageXOffset, imageYOffset, 1); |
| 2522 |
XSetClipOrigin(butPtr->display, gc, 0, 0); |
| 2523 |
} |
| 2524 |
incFull = 1; |
| 2525 |
goto drawtext; |
| 2526 |
} else { |
| 2527 |
if (haveImage) { |
| 2528 |
ComputeAnchor(butPtr->anchor, tkwin, 0, 0, |
| 2529 |
iSpc + imageWidth, imageHeight, &x, &y, xAdj, yAdj); |
| 2530 |
x += iSpc; |
| 2531 |
|
| 2532 |
x += offset; |
| 2533 |
y += offset; |
| 2534 |
if (relief == TK_RELIEF_RAISED) { |
| 2535 |
x -= offset; |
| 2536 |
y -= offset; |
| 2537 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 2538 |
x += offset; |
| 2539 |
y += offset; |
| 2540 |
} |
| 2541 |
imageXOffset += (x + butPtr->xOffset); |
| 2542 |
imageYOffset += (y + butPtr->yOffset); |
| 2543 |
if (curImage != NULL) { |
| 2544 |
/* |
| 2545 |
* Do boundary clipping, so that Tk_RedrawImage is passed |
| 2546 |
* valid coordinates. [Bug 979239] |
| 2547 |
*/ |
| 2548 |
|
| 2549 |
if (imageXOffset < 0) { |
| 2550 |
imageXOffset = 0; |
| 2551 |
} |
| 2552 |
if (imageYOffset < 0) { |
| 2553 |
imageYOffset = 0; |
| 2554 |
} |
| 2555 |
if (imageWidth > Tk_Width(tkwin)) { |
| 2556 |
imageWidth = Tk_Width(tkwin); |
| 2557 |
} |
| 2558 |
if (imageHeight > Tk_Height(tkwin)) { |
| 2559 |
imageHeight = Tk_Height(tkwin); |
| 2560 |
} |
| 2561 |
if ((imageWidth + imageXOffset) > Tk_Width(tkwin)) { |
| 2562 |
imageXOffset = Tk_Width(tkwin) - imageWidth; |
| 2563 |
} |
| 2564 |
if ((imageHeight + imageYOffset) > Tk_Height(tkwin)) { |
| 2565 |
imageYOffset = Tk_Height(tkwin) - imageHeight; |
| 2566 |
} |
| 2567 |
|
| 2568 |
Tk_RedrawImage(image, 0, 0, imageWidth, imageHeight, pixmap, |
| 2569 |
imageXOffset, imageYOffset); |
| 2570 |
} else { |
| 2571 |
XSetClipOrigin(butPtr->display, gc, x, y); |
| 2572 |
XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, |
| 2573 |
(unsigned int) imageWidth, (unsigned int) imageHeight, x, y, 1); |
| 2574 |
XSetClipOrigin(butPtr->display, gc, 0, 0); |
| 2575 |
} |
| 2576 |
y += imageHeight/2; |
| 2577 |
} else { |
| 2578 |
ComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, |
| 2579 |
iSpc + butPtr->textWidth, |
| 2580 |
butPtr->textHeight, &x, &y, xAdj, yAdj); |
| 2581 |
|
| 2582 |
x += iSpc; |
| 2583 |
|
| 2584 |
x += offset; |
| 2585 |
y += offset; |
| 2586 |
if (relief == TK_RELIEF_RAISED) { |
| 2587 |
x -= offset; |
| 2588 |
y -= offset; |
| 2589 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 2590 |
x += offset; |
| 2591 |
y += offset; |
| 2592 |
} |
| 2593 |
if ((butPtr->type <= TYPE_LABEL)) { |
| 2594 |
x -= 2; |
| 2595 |
} |
| 2596 |
#if 1 |
| 2597 |
drawtext: |
| 2598 |
{ |
| 2599 |
TextStyle ts; |
| 2600 |
Shadow *shadowPtr; |
| 2601 |
int selected = 0, active = 0; |
| 2602 |
x += butPtr->xOffset; |
| 2603 |
y += butPtr->yOffset; |
| 2604 |
if (butPtr->state == STATE_ACTIVE) { |
| 2605 |
shadowPtr = &butPtr->activeShadow; |
| 2606 |
} else { |
| 2607 |
shadowPtr = &butPtr->shadow; |
| 2608 |
} |
| 2609 |
Blt_SetDrawTextStyle(&ts, butPtr->tkfont, gc ? gc : butPtr->normalTextGC, |
| 2610 |
(butPtr->state == STATE_DISABLED && butPtr->disabledFg) ? |
| 2611 |
butPtr->disabledFg: butPtr->normalFg, butPtr->activeFg, |
| 2612 |
shadowPtr->color, butPtr->rotate, TK_ANCHOR_NW, butPtr->justify, |
| 2613 |
0, shadowPtr->offset); |
| 2614 |
ts.underline = butPtr->underline; |
| 2615 |
ts.state = (butPtr->state==STATE_ACTIVE?STATE_ACTIVE:0); |
| 2616 |
ts.border = border; |
| 2617 |
ts.padX.side1 = ts.padX.side2 = 2; |
| 2618 |
if ((selected) || (active)) { |
| 2619 |
ts.state |= STATE_ACTIVE; |
| 2620 |
} |
| 2621 |
Blt_DrawText(butPtr->tkwin, pixmap, butPtr->textPtr, &ts, x + textXOffset, y + textYOffset); |
| 2622 |
if (incFull) { |
| 2623 |
y += fullHeight/2; |
| 2624 |
} else { |
| 2625 |
y = Tk_Height(tkwin)/2; |
| 2626 |
} |
| 2627 |
|
| 2628 |
} |
| 2629 |
#else |
| 2630 |
Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, |
| 2631 |
x, y, 0, -1); |
| 2632 |
Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, |
| 2633 |
butPtr->textLayout, x, y, butPtr->underline); |
| 2634 |
y += butPtr->textHeight/2; |
| 2635 |
#endif |
| 2636 |
|
| 2637 |
} |
| 2638 |
|
| 2639 |
} |
| 2640 |
|
| 2641 |
/* |
| 2642 |
* Draw the indicator for check buttons and radio buttons. At this |
| 2643 |
* point x and y refer to the top-left corner of the text or image |
| 2644 |
* or bitmap. |
| 2645 |
*/ |
| 2646 |
|
| 2647 |
if ((butPtr->type == TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 2648 |
int dim; |
| 2649 |
int bd = 1; /* butPtr->borderWidth */ |
| 2650 |
|
| 2651 |
if (butPtr->icons[0] && (butPtr->flags & HAS_ICONS)) { |
| 2652 |
goto drawInd; |
| 2653 |
} |
| 2654 |
dim = butPtr->indicatorDiameter; |
| 2655 |
x -= butPtr->indicatorSpace; |
| 2656 |
y -= dim / 2; |
| 2657 |
if (y < 2) { y = 2; } |
| 2658 |
if (dim > 2 * butPtr->borderWidth) { |
| 2659 |
Blt_Draw3DRectangle(tkwin, pixmap, border, x, y, dim, dim, |
| 2660 |
bd, |
| 2661 |
(butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN : |
| 2662 |
TK_RELIEF_RAISED); |
| 2663 |
x += bd; |
| 2664 |
y += bd; |
| 2665 |
dim -= 2 * bd; |
| 2666 |
if (butPtr->flags & SELECTED) { |
| 2667 |
GC borderGC; |
| 2668 |
|
| 2669 |
borderGC = Tk_3DBorderGC(tkwin, (butPtr->selectBorder != NULL) |
| 2670 |
? butPtr->selectBorder : butPtr->normalBorder, |
| 2671 |
TK_3D_FLAT_GC); |
| 2672 |
XFillRectangle(butPtr->display, pixmap, borderGC, x, y, |
| 2673 |
(unsigned int)dim, (unsigned int)dim); |
| 2674 |
} else { |
| 2675 |
Blt_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, x, y, |
| 2676 |
dim, dim, butPtr->borderWidth, TK_RELIEF_FLAT); |
| 2677 |
} |
| 2678 |
} |
| 2679 |
} else if ((butPtr->type == TYPE_RADIO_BUTTON) && butPtr->indicatorOn) { |
| 2680 |
XPoint points[4]; |
| 2681 |
int radius; |
| 2682 |
int bd = 1; /* butPtr->borderWidth */ |
| 2683 |
|
| 2684 |
if (butPtr->icons[0] && (butPtr->flags & HAS_ICONS)) { |
| 2685 |
goto drawInd; |
| 2686 |
} |
| 2687 |
radius = butPtr->indicatorDiameter / 2; |
| 2688 |
points[0].x = x - butPtr->indicatorSpace; |
| 2689 |
points[0].y = y; |
| 2690 |
points[1].x = points[0].x + radius; |
| 2691 |
points[1].y = points[0].y + radius; |
| 2692 |
points[2].x = points[1].x + radius; |
| 2693 |
points[2].y = points[0].y; |
| 2694 |
points[3].x = points[1].x; |
| 2695 |
points[3].y = points[0].y - radius; |
| 2696 |
if (butPtr->flags & SELECTED) { |
| 2697 |
GC borderGC; |
| 2698 |
|
| 2699 |
borderGC = Tk_3DBorderGC(tkwin, (butPtr->selectBorder != NULL) |
| 2700 |
? butPtr->selectBorder : butPtr->normalBorder, |
| 2701 |
TK_3D_FLAT_GC); |
| 2702 |
XFillPolygon(butPtr->display, pixmap, borderGC, points, 4, Convex, |
| 2703 |
CoordModeOrigin); |
| 2704 |
} else { |
| 2705 |
Tk_Fill3DPolygon(tkwin, pixmap, butPtr->normalBorder, points, |
| 2706 |
4, bd, TK_RELIEF_FLAT); |
| 2707 |
} |
| 2708 |
Tk_Draw3DPolygon(tkwin, pixmap, border, points, 4, bd, |
| 2709 |
(butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN : |
| 2710 |
TK_RELIEF_RAISED); |
| 2711 |
} |
| 2712 |
|
| 2713 |
if (butPtr->type == TYPE_MENU_BUTTON && butPtr->indicatorOn) { |
| 2714 |
int mborderWidth, bsub = 0; |
| 2715 |
|
| 2716 |
if (butPtr->icons[0] && (butPtr->flags & HAS_ICONS)) { |
| 2717 |
goto drawInd; |
| 2718 |
} |
| 2719 |
if (bdImage) { |
| 2720 |
bsub = 7; |
| 2721 |
} |
| 2722 |
mborderWidth = (butPtr->indicatorHeight + 1) / 3; |
| 2723 |
if (mborderWidth < 1) { |
| 2724 |
mborderWidth = 1; |
| 2725 |
} |
| 2726 |
|
| 2727 |
Blt_Fill3DRectangle(tkwin, pixmap, border, |
| 2728 |
Tk_Width(tkwin) - butPtr->inset - butPtr->indicatorWidth + 2 - bsub, |
| 2729 |
butPtr->inset + (Tk_Height(tkwin) - butPtr->highlightWidth - |
| 2730 |
butPtr->indicatorHeight)/2, |
| 2731 |
butPtr->indicatorWidth - mborderWidth - 2, |
| 2732 |
butPtr->indicatorHeight, |
| 2733 |
mborderWidth, TK_RELIEF_RAISED); |
| 2734 |
} |
| 2735 |
|
| 2736 |
goto goon; |
| 2737 |
|
| 2738 |
/* Handle drawing the indicator for Check/Radio/Menu buttons. */ |
| 2739 |
{ |
| 2740 |
Tk_Image icon; |
| 2741 |
int w1, h1, sind; |
| 2742 |
drawInd: |
| 2743 |
|
| 2744 |
sind = 0; |
| 2745 |
|
| 2746 |
if (butPtr->state == STATE_ACTIVE) { |
| 2747 |
sind = 3; |
| 2748 |
} else if (butPtr->state == STATE_DISABLED) { |
| 2749 |
sind = 6; |
| 2750 |
} |
| 2751 |
#define STATEICON(n) (butPtr->icons[sind+n] ? butPtr->icons[sind+n] : butPtr->icons[n]) |
| 2752 |
icon = NULL; |
| 2753 |
if ((butPtr->flags & SELECTED)) { |
| 2754 |
icon = STATEICON(1); |
| 2755 |
} else if (((butPtr->flags & TRISTATED))) { |
| 2756 |
icon = STATEICON(2); |
| 2757 |
} |
| 2758 |
if (icon == NULL) { |
| 2759 |
icon = STATEICON(0); |
| 2760 |
} |
| 2761 |
Tk_SizeOfImage(icon, &w1, &h1); |
| 2762 |
x -= butPtr->indicatorSpace; |
| 2763 |
y -= butPtr->indicatorSpace/2; |
| 2764 |
|
| 2765 |
Tk_RedrawImage(icon, 0, 0, w1, h1, pixmap, x, y); |
| 2766 |
} |
| 2767 |
|
| 2768 |
goon: |
| 2769 |
|
| 2770 |
/* |
| 2771 |
* If the button is disabled with a stipple rather than a special |
| 2772 |
* foreground color, generate the stippled effect. If the widget |
| 2773 |
* is selected and we use a different background color when selected, |
| 2774 |
* must temporarily modify the GC. |
| 2775 |
*/ |
| 2776 |
|
| 2777 |
if ((butPtr->state == STATE_DISABLED) && (Blt_HasTile(butPtr->disabledTile) == 0) |
| 2778 |
&& ((butPtr->disabledFg == NULL) || (curImage != NULL)) && |
| 2779 |
bdImage == NULL && Blt_HasTile(butPtr->tile) == 0) { |
| 2780 |
if ((butPtr->flags & SELECTED) && butPtr->indicatorOn == 0 |
| 2781 |
&& (butPtr->selectBorder != NULL)) { |
| 2782 |
XSetForeground(butPtr->display, butPtr->disabledGC, |
| 2783 |
Tk_3DBorderColor(butPtr->selectBorder)->pixel); |
| 2784 |
} |
| 2785 |
XFillRectangle(butPtr->display, pixmap, butPtr->disabledGC, |
| 2786 |
butPtr->inset, butPtr->inset, |
| 2787 |
(unsigned)(Tk_Width(tkwin) - 2 * butPtr->inset), |
| 2788 |
(unsigned)(Tk_Height(tkwin) - 2 * butPtr->inset)); |
| 2789 |
if ((butPtr->flags & SELECTED) && butPtr->indicatorOn == 0 |
| 2790 |
&& (butPtr->selectBorder != NULL)) { |
| 2791 |
XSetForeground(butPtr->display, butPtr->disabledGC, |
| 2792 |
Tk_3DBorderColor(butPtr->normalBorder)->pixel); |
| 2793 |
} |
| 2794 |
} |
| 2795 |
/* |
| 2796 |
* Draw the border and traversal highlight last. This way, if the |
| 2797 |
* button's contents overflow they'll be covered up by the border. |
| 2798 |
*/ |
| 2799 |
|
| 2800 |
if (relief != TK_RELIEF_FLAT && drawBorder && butPtr->type > TYPE_LABEL ) { |
| 2801 |
int inset = butPtr->highlightWidth; |
| 2802 |
if (butPtr->defaultState == STATE_ACTIVE) { |
| 2803 |
inset += 2; |
| 2804 |
Blt_Draw3DRectangle(tkwin, pixmap, border, inset, inset, |
| 2805 |
Tk_Width(tkwin) - 2 * inset, Tk_Height(tkwin) - 2 * inset, |
| 2806 |
1, TK_RELIEF_SUNKEN); |
| 2807 |
inset += 3; |
| 2808 |
} |
| 2809 |
Blt_Draw3DRectangle(tkwin, pixmap, border, inset, inset, |
| 2810 |
Tk_Width(tkwin) - 2 * inset, Tk_Height(tkwin) - 2 * inset, |
| 2811 |
butPtr->borderWidth, relief); |
| 2812 |
} |
| 2813 |
if (butPtr->highlightWidth > 0 && butPtr->highlightBgColorPtr != NULL && butPtr->type > TYPE_LABEL ) { |
| 2814 |
GC highlightGC; |
| 2815 |
|
| 2816 |
if (butPtr->flags & GOT_FOCUS) { |
| 2817 |
highlightGC = Tk_GCForColor(butPtr->highlightColorPtr, pixmap); |
| 2818 |
} else { |
| 2819 |
highlightGC = Tk_GCForColor(butPtr->highlightBgColorPtr, pixmap); |
| 2820 |
} |
| 2821 |
Tk_DrawFocusHighlight(tkwin, highlightGC, butPtr->highlightWidth, pixmap); |
| 2822 |
} |
| 2823 |
if ((butPtr->flags & GOT_FOCUS) && Tk_Width(tkwin) > 11 && Tk_Height(tkwin) > 11 && bdImage && butPtr->type > TYPE_LABEL ) { |
| 2824 |
int dx; |
| 2825 |
dx = 5 + butPtr->highlightWidth; |
| 2826 |
XDrawRectangle(butPtr->display, pixmap, butPtr->focusGC, |
| 2827 |
dx, dx, Tk_Width(tkwin) - 2*dx, Tk_Height(tkwin) - 2*dx); |
| 2828 |
} |
| 2829 |
/* |
| 2830 |
* Copy the information from the off-screen pixmap onto the screen, |
| 2831 |
* then delete the pixmap. |
| 2832 |
*/ |
| 2833 |
|
| 2834 |
XCopyArea(butPtr->display, pixmap, Tk_WindowId(tkwin), |
| 2835 |
butPtr->copyGC, 0, 0, (unsigned)Tk_Width(tkwin), |
| 2836 |
(unsigned)Tk_Height(tkwin), 0, 0); |
| 2837 |
Tk_FreePixmap(butPtr->display, pixmap); |
| 2838 |
} |
| 2839 |
|
| 2840 |
/* |
| 2841 |
*---------------------------------------------------------------------- |
| 2842 |
* |
| 2843 |
* ComputeButtonGeometry -- |
| 2844 |
* |
| 2845 |
* After changes in a button's text or bitmap, this procedure |
| 2846 |
* recomputes the button's geometry and passes this information |
| 2847 |
* along to the geometry manager for the window. |
| 2848 |
* |
| 2849 |
* Results: |
| 2850 |
* None. |
| 2851 |
* |
| 2852 |
* Side effects: |
| 2853 |
* The button's window may change size. |
| 2854 |
* |
| 2855 |
*---------------------------------------------------------------------- |
| 2856 |
*/ |
| 2857 |
#define STR(s) ((s)?s:"") |
| 2858 |
static void |
| 2859 |
ComputeButtonGeometry(butPtr) |
| 2860 |
register Button *butPtr; /* Button whose geometry may have changed. */ |
| 2861 |
{ |
| 2862 |
int width, height, avgWidth, txtWidth, txtHeight; |
| 2863 |
int haveImage = 0, haveText = 0, isRadio = 0; |
| 2864 |
Tk_FontMetrics fm; |
| 2865 |
Tk_Image curImage; |
| 2866 |
|
| 2867 |
curImage = butPtr->image; |
| 2868 |
butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth; |
| 2869 |
isRadio = (butPtr->type == TYPE_RADIO_BUTTON); |
| 2870 |
/* |
| 2871 |
* Leave room for the default ring if needed. |
| 2872 |
*/ |
| 2873 |
|
| 2874 |
if (butPtr->type == TYPE_CHECK_BUTTON && butPtr->tristateValue && |
| 2875 |
butPtr->selVarName) { |
| 2876 |
char *value; |
| 2877 |
|
| 2878 |
value = ButtonGetValue(butPtr); |
| 2879 |
|
| 2880 |
if (value == NULL) { |
| 2881 |
value = ""; |
| 2882 |
} |
| 2883 |
|
| 2884 |
if (strcmp(value,butPtr->tristateValue)==0) { |
| 2885 |
butPtr->flags |= TRISTATED; |
| 2886 |
} else { |
| 2887 |
butPtr->flags &= ~TRISTATED; |
| 2888 |
} |
| 2889 |
} |
| 2890 |
if (butPtr->defaultState != STATE_DISABLED) { |
| 2891 |
butPtr->inset += 5; |
| 2892 |
} |
| 2893 |
butPtr->indicatorSpace = 0; |
| 2894 |
|
| 2895 |
width = 0; |
| 2896 |
height = 0; |
| 2897 |
txtWidth = 0; |
| 2898 |
txtHeight = 0; |
| 2899 |
avgWidth = 0; |
| 2900 |
|
| 2901 |
if (butPtr->state == STATE_DISABLED && butPtr->disabledImage != NULL) { |
| 2902 |
curImage = butPtr->disabledImage; |
| 2903 |
} |
| 2904 |
if (butPtr->state == STATE_ACTIVE && butPtr->activeImage != NULL) { |
| 2905 |
curImage = butPtr->activeImage; |
| 2906 |
} |
| 2907 |
if (curImage != NULL) { |
| 2908 |
Tk_SizeOfImage(curImage, &width, &height); |
| 2909 |
haveImage = 1; |
| 2910 |
} else if (butPtr->bitmap != None) { |
| 2911 |
Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); |
| 2912 |
haveImage = 1; |
| 2913 |
} |
| 2914 |
|
| 2915 |
if (butPtr->type != TYPE_FRAME && (haveImage == 0 || butPtr->compound != COMPOUND_NONE)) { |
| 2916 |
|
| 2917 |
if (butPtr->rotate > 0.0) { |
| 2918 |
double rotWidth, rotHeight; |
| 2919 |
int labelWidth, labelHeight; |
| 2920 |
TextStyle ts; |
| 2921 |
|
| 2922 |
Blt_InitTextStyle(&ts); |
| 2923 |
ts.font = butPtr->tkfont; |
| 2924 |
if (butPtr->state == STATE_ACTIVE) { |
| 2925 |
ts.shadow.offset = butPtr->shadow.offset; |
| 2926 |
} else { |
| 2927 |
ts.shadow.offset = butPtr->activeShadow.offset; |
| 2928 |
} |
| 2929 |
ts.padX.side1 = ts.padX.side2 = 2; |
| 2930 |
|
| 2931 |
Blt_GetTextExtents(&ts, STR(butPtr->textPtr), &labelWidth, &labelHeight); |
| 2932 |
Blt_GetBoundingBox(labelWidth, labelHeight, butPtr->rotate, |
| 2933 |
&rotWidth, &rotHeight, (Point2D *)NULL); |
| 2934 |
butPtr->textWidth = ROUND(rotWidth); |
| 2935 |
butPtr->textHeight = ROUND(rotHeight); |
| 2936 |
|
| 2937 |
} else { |
| 2938 |
if (butPtr->textLayout) { |
| 2939 |
Tk_FreeTextLayout(butPtr->textLayout); |
| 2940 |
} |
| 2941 |
|
| 2942 |
butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, |
| 2943 |
STR(butPtr->textPtr), -1, butPtr->wrapLength, |
| 2944 |
butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight); |
| 2945 |
} |
| 2946 |
|
| 2947 |
txtWidth = butPtr->textWidth; |
| 2948 |
txtHeight = butPtr->textHeight; |
| 2949 |
avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1); |
| 2950 |
Tk_GetFontMetrics(butPtr->tkfont, &fm); |
| 2951 |
haveText = (txtWidth != 0 && txtHeight != 0); |
| 2952 |
} |
| 2953 |
|
| 2954 |
/* |
| 2955 |
* If the button is compound (i.e., it shows both an image and text), the |
| 2956 |
* new geometry is a combination of the image and text geometry. We only |
| 2957 |
* honor the compound bit if the button has both text and an image, |
| 2958 |
* because otherwise it is not really a compound button. |
| 2959 |
*/ |
| 2960 |
|
| 2961 |
if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 2962 |
int isVert = 0; |
| 2963 |
switch (butPtr->compound) { |
| 2964 |
case COMPOUND_TOP: |
| 2965 |
case COMPOUND_BOTTOM: |
| 2966 |
/* |
| 2967 |
* Image is above or below text. |
| 2968 |
*/ |
| 2969 |
isVert = 1; |
| 2970 |
height += txtHeight + butPtr->padY; |
| 2971 |
width = (width > txtWidth ? width : txtWidth); |
| 2972 |
break; |
| 2973 |
case COMPOUND_LEFT: |
| 2974 |
case COMPOUND_RIGHT: |
| 2975 |
/* |
| 2976 |
* Image is left or right of text. |
| 2977 |
*/ |
| 2978 |
|
| 2979 |
width += txtWidth + butPtr->padX; |
| 2980 |
height = (height > txtHeight ? height : txtHeight); |
| 2981 |
break; |
| 2982 |
case COMPOUND_CENTER: |
| 2983 |
/* |
| 2984 |
* Image and text are superimposed. |
| 2985 |
*/ |
| 2986 |
|
| 2987 |
width = (width > txtWidth ? width : txtWidth); |
| 2988 |
height = (height > txtHeight ? height : txtHeight); |
| 2989 |
break; |
| 2990 |
case COMPOUND_NONE: |
| 2991 |
break; |
| 2992 |
} |
| 2993 |
if (butPtr->width < 0) { |
| 2994 |
width = -butPtr->width; |
| 2995 |
} else if (butPtr->width > 0) { |
| 2996 |
width = butPtr->width; |
| 2997 |
} |
| 2998 |
if (butPtr->height < 0) { |
| 2999 |
height = -butPtr->height; |
| 3000 |
} else if (butPtr->height > 0) { |
| 3001 |
height = butPtr->height; |
| 3002 |
} |
| 3003 |
|
| 3004 |
|
| 3005 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 3006 |
if (butPtr->rotate <= 0 && isVert==0) { |
| 3007 |
butPtr->indicatorSpace = height; |
| 3008 |
} else { |
| 3009 |
if (butPtr->indicatorSize>0) { |
| 3010 |
butPtr->indicatorSpace = butPtr->indicatorSize+6; |
| 3011 |
} else { |
| 3012 |
butPtr->indicatorSpace = height; |
| 3013 |
} |
| 3014 |
} |
| 3015 |
if (butPtr->indicatorSize>0) { |
| 3016 |
butPtr->indicatorDiameter = butPtr->indicatorSize + (isRadio*2); |
| 3017 |
} else if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 3018 |
butPtr->indicatorDiameter = (65*height)/100; |
| 3019 |
} else { |
| 3020 |
butPtr->indicatorDiameter = (75*height)/100; |
| 3021 |
} |
| 3022 |
} |
| 3023 |
|
| 3024 |
width += 2*butPtr->padX; |
| 3025 |
height += 2*butPtr->padY; |
| 3026 |
} else { |
| 3027 |
if (haveImage) { |
| 3028 |
if (butPtr->width < 0) { |
| 3029 |
width = -butPtr->width; |
| 3030 |
} else if (butPtr->width > 0) { |
| 3031 |
width = butPtr->width; |
| 3032 |
} |
| 3033 |
if (butPtr->height < 0) { |
| 3034 |
height = -butPtr->height; |
| 3035 |
} else if (butPtr->height > 0) { |
| 3036 |
height = butPtr->height; |
| 3037 |
} |
| 3038 |
|
| 3039 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 3040 |
butPtr->indicatorSpace = height; |
| 3041 |
if (butPtr->indicatorSize>0) { |
| 3042 |
butPtr->indicatorDiameter = butPtr->indicatorSize + (isRadio*2); |
| 3043 |
} else if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 3044 |
butPtr->indicatorDiameter = (65*height)/100; |
| 3045 |
} else { |
| 3046 |
butPtr->indicatorDiameter = (75*height)/100; |
| 3047 |
} |
| 3048 |
} |
| 3049 |
} else { |
| 3050 |
width = txtWidth; |
| 3051 |
height = txtHeight; |
| 3052 |
|
| 3053 |
if (butPtr->width < 0) { |
| 3054 |
width = -butPtr->width; |
| 3055 |
} else if (butPtr->width > 0) { |
| 3056 |
if (butPtr->type >= TYPE_FRAME) { |
| 3057 |
width = butPtr->width; |
| 3058 |
} else { |
| 3059 |
width = butPtr->width * avgWidth; |
| 3060 |
} |
| 3061 |
} |
| 3062 |
if (butPtr->height < 0) { |
| 3063 |
height = -butPtr->height; |
| 3064 |
} else if (butPtr->height > 0) { |
| 3065 |
height = butPtr->height; |
| 3066 |
} |
| 3067 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 3068 |
if (butPtr->indicatorSize>0) { |
| 3069 |
butPtr->indicatorDiameter = butPtr->indicatorSize + (isRadio*2); |
| 3070 |
} else { |
| 3071 |
butPtr->indicatorDiameter = fm.linespace; |
| 3072 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 3073 |
butPtr->indicatorDiameter = |
| 3074 |
(80*butPtr->indicatorDiameter)/100; |
| 3075 |
} |
| 3076 |
} |
| 3077 |
butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth; |
| 3078 |
} |
| 3079 |
} |
| 3080 |
} |
| 3081 |
butPtr->flags &= ~HAS_ICONS; |
| 3082 |
|
| 3083 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn && butPtr->icons[0]) { |
| 3084 |
int h1, h2, h3, w1, w2, w3; |
| 3085 |
Tk_SizeOfImage(butPtr->icons[0], &w1, &h1); |
| 3086 |
Tk_SizeOfImage(butPtr->icons[1], &w2, &h2); |
| 3087 |
if (butPtr->icons[2]) { |
| 3088 |
Tk_SizeOfImage(butPtr->icons[2], &w3, &h3); |
| 3089 |
if (w3>w1) { w1 = w3; } |
| 3090 |
if (h3>h1) { h1 = h3; } |
| 3091 |
} |
| 3092 |
if (w1>0 && h1>0 && w2>0 && h2>0) { |
| 3093 |
butPtr->flags |= HAS_ICONS; |
| 3094 |
if (w2>w1) { w1 = w2; } |
| 3095 |
if (h2>h1) { h1 = h2; } |
| 3096 |
butPtr->indicatorSpace = w1; |
| 3097 |
if (h1>butPtr->indicatorSpace) { butPtr->indicatorSpace = h1; } |
| 3098 |
butPtr->indicatorSpace += 4; |
| 3099 |
} |
| 3100 |
|
| 3101 |
} |
| 3102 |
if (butPtr->type == TYPE_MENU_BUTTON) { |
| 3103 |
if (butPtr->indicatorOn) { |
| 3104 |
if (butPtr->indicatorOn) { |
| 3105 |
int mm, pixels; |
| 3106 |
mm = WidthMMOfScreen(Tk_Screen(butPtr->tkwin)); |
| 3107 |
pixels = WidthOfScreen(Tk_Screen(butPtr->tkwin)); |
| 3108 |
butPtr->indicatorHeight = (INDICATOR_HEIGHT * pixels) / (10 * mm); |
| 3109 |
butPtr->indicatorWidth = (INDICATOR_WIDTH * pixels) / (10 * mm) |
| 3110 |
+ 2 * butPtr->indicatorHeight; |
| 3111 |
butPtr->indicatorSpace = butPtr->indicatorWidth; |
| 3112 |
} else { |
| 3113 |
butPtr->indicatorHeight = 0; |
| 3114 |
butPtr->indicatorWidth = 0; |
| 3115 |
butPtr->indicatorSpace = 0; |
| 3116 |
} |
| 3117 |
} |
| 3118 |
} |
| 3119 |
|
| 3120 |
if ((curImage == NULL) && (butPtr->bitmap == None)) { |
| 3121 |
width += 2*butPtr->padX; |
| 3122 |
height += 2*butPtr->padY; |
| 3123 |
} |
| 3124 |
if ((butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin)) { |
| 3125 |
width += 2; |
| 3126 |
height += 2; |
| 3127 |
} |
| 3128 |
if ((butPtr->type <= TYPE_LABEL)) { |
| 3129 |
width += 4; |
| 3130 |
} |
| 3131 |
if (width%2) width++; |
| 3132 |
if (height%2) height++; |
| 3133 |
Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace |
| 3134 |
+ 2*butPtr->inset), (int) (height + 2*butPtr->inset)); |
| 3135 |
Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset); |
| 3136 |
} |
| 3137 |
|
| 3138 |
/* |
| 3139 |
*-------------------------------------------------------------- |
| 3140 |
* |
| 3141 |
* ButtonEventProc -- |
| 3142 |
* |
| 3143 |
* This procedure is invoked by the Tk dispatcher for various |
| 3144 |
* events on buttons. |
| 3145 |
* |
| 3146 |
* Results: |
| 3147 |
* None. |
| 3148 |
* |
| 3149 |
* Side effects: |
| 3150 |
* When the window gets deleted, internal structures get |
| 3151 |
* cleaned up. When it gets exposed, it is redisplayed. |
| 3152 |
* |
| 3153 |
*-------------------------------------------------------------- |
| 3154 |
*/ |
| 3155 |
|
| 3156 |
static void |
| 3157 |
ButtonEventProc(clientData, eventPtr) |
| 3158 |
ClientData clientData; /* Information about window. */ |
| 3159 |
XEvent *eventPtr; /* Information about event. */ |
| 3160 |
{ |
| 3161 |
Button *butPtr = clientData; |
| 3162 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3163 |
return; |
| 3164 |
} |
| 3165 |
|
| 3166 |
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) { |
| 3167 |
goto redraw; |
| 3168 |
} else if (eventPtr->type == ConfigureNotify) { |
| 3169 |
/* |
| 3170 |
* Must redraw after size changes, since layout could have changed |
| 3171 |
* and borders will need to be redrawn. |
| 3172 |
*/ |
| 3173 |
|
| 3174 |
goto redraw; |
| 3175 |
} else if (eventPtr->type == DestroyNotify) { |
| 3176 |
if (butPtr->tkwin != NULL) { |
| 3177 |
butPtr->tkwin = NULL; |
| 3178 |
Tcl_DeleteCommandFromToken(butPtr->interp, butPtr->widgetCmd); |
| 3179 |
} |
| 3180 |
if (butPtr->flags & REDRAW_PENDING) { |
| 3181 |
Tcl_CancelIdleCall(DisplayButton, (ClientData)butPtr); |
| 3182 |
} |
| 3183 |
/* This is a hack to workaround a bug in 8.3.3. */ |
| 3184 |
DestroyButton((ClientData)butPtr); |
| 3185 |
/* Tcl_EventuallyFree((ClientData)butPtr, (Tcl_FreeProc *)Blt_Free); */ |
| 3186 |
} else if (eventPtr->type == FocusIn) { |
| 3187 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 3188 |
butPtr->flags |= GOT_FOCUS; |
| 3189 |
if (1 || butPtr->highlightWidth > 0) { |
| 3190 |
goto redraw; |
| 3191 |
} |
| 3192 |
} |
| 3193 |
} else if (eventPtr->type == FocusOut) { |
| 3194 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 3195 |
butPtr->flags &= ~GOT_FOCUS; |
| 3196 |
if (1 || butPtr->highlightWidth > 0) { |
| 3197 |
goto redraw; |
| 3198 |
} |
| 3199 |
} |
| 3200 |
} |
| 3201 |
return; |
| 3202 |
|
| 3203 |
redraw: |
| 3204 |
if ((butPtr->tkwin != NULL) && !(butPtr->flags & REDRAW_PENDING)) { |
| 3205 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3206 |
butPtr->flags |= REDRAW_PENDING; |
| 3207 |
} |
| 3208 |
} |
| 3209 |
|
| 3210 |
/* |
| 3211 |
*---------------------------------------------------------------------- |
| 3212 |
* |
| 3213 |
* ButtonCmdDeletedProc -- |
| 3214 |
* |
| 3215 |
* This procedure is invoked when a widget command is deleted. If |
| 3216 |
* the widget isn't already in the process of being destroyed, |
| 3217 |
* this command destroys it. |
| 3218 |
* |
| 3219 |
* Results: |
| 3220 |
* None. |
| 3221 |
* |
| 3222 |
* Side effects: |
| 3223 |
* The widget is destroyed. |
| 3224 |
* |
| 3225 |
*---------------------------------------------------------------------- |
| 3226 |
*/ |
| 3227 |
|
| 3228 |
static void |
| 3229 |
ButtonCmdDeletedProc(clientData) |
| 3230 |
ClientData clientData; /* Pointer to widget record for widget. */ |
| 3231 |
{ |
| 3232 |
Button *butPtr = clientData; |
| 3233 |
Tk_Window tkwin = butPtr->tkwin; |
| 3234 |
|
| 3235 |
/* |
| 3236 |
* This procedure could be invoked either because the window was |
| 3237 |
* destroyed and the command was then deleted (in which case tkwin |
| 3238 |
* is NULL) or because the command was deleted, and then this procedure |
| 3239 |
* destroys the widget. |
| 3240 |
*/ |
| 3241 |
|
| 3242 |
if (tkwin != NULL) { |
| 3243 |
butPtr->tkwin = NULL; |
| 3244 |
#ifdef ITCL_NAMESPACES |
| 3245 |
Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL); |
| 3246 |
#endif |
| 3247 |
Tk_DestroyWindow(tkwin); |
| 3248 |
} |
| 3249 |
} |
| 3250 |
|
| 3251 |
/* |
| 3252 |
*---------------------------------------------------------------------- |
| 3253 |
* |
| 3254 |
* InvokeButton -- |
| 3255 |
* |
| 3256 |
* This procedure is called to carry out the actions associated |
| 3257 |
* with a button, such as invoking a Tcl command or setting a |
| 3258 |
* variable. This procedure is invoked, for example, when the |
| 3259 |
* button is invoked via the mouse. |
| 3260 |
* |
| 3261 |
* Results: |
| 3262 |
* A standard Tcl return value. Information is also left in |
| 3263 |
* interp->result. |
| 3264 |
* |
| 3265 |
* Side effects: |
| 3266 |
* Depends on the button and its associated command. |
| 3267 |
* |
| 3268 |
*---------------------------------------------------------------------- |
| 3269 |
*/ |
| 3270 |
|
| 3271 |
static int |
| 3272 |
InvokeButton(butPtr) |
| 3273 |
register Button *butPtr; /* Information about button. */ |
| 3274 |
{ |
| 3275 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3276 |
return TCL_OK; |
| 3277 |
} |
| 3278 |
|
| 3279 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 3280 |
if (butPtr->flags & SELECTED) { |
| 3281 |
if (ButtonSetValue(butPtr, butPtr->offValue, 1) != TCL_OK) { |
| 3282 |
return TCL_ERROR; |
| 3283 |
} |
| 3284 |
} else { |
| 3285 |
if (ButtonSetValue(butPtr, butPtr->onValue, 1) != TCL_OK) { |
| 3286 |
return TCL_ERROR; |
| 3287 |
} |
| 3288 |
} |
| 3289 |
} else if (butPtr->type == TYPE_RADIO_BUTTON) { |
| 3290 |
if (ButtonSetValue(butPtr, butPtr->onValue, 1) != TCL_OK) { |
| 3291 |
return TCL_ERROR; |
| 3292 |
} |
| 3293 |
} |
| 3294 |
if ((butPtr->type > TYPE_LABEL) && (butPtr->command != NULL)) { |
| 3295 |
return TkCopyAndGlobalEval(butPtr->interp, butPtr->command); |
| 3296 |
} |
| 3297 |
return TCL_OK; |
| 3298 |
} |
| 3299 |
|
| 3300 |
/* Trace tree operation. */ |
| 3301 |
static int TreeTraceProc(ClientData clientData, |
| 3302 |
Tcl_Interp *interp, Blt_TreeNode node, Blt_TreeKey key, |
| 3303 |
unsigned int flags) { |
| 3304 |
register Button *butPtr = clientData; |
| 3305 |
Blt_TreeNode nodePtr; |
| 3306 |
Tcl_Obj *valuePtr; |
| 3307 |
CONST char *value; |
| 3308 |
int doUpd = 0; |
| 3309 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 3310 |
/* printf("TRC(%d)\n", (flags & TREE_TRACE_UNSET)); */ |
| 3311 |
if (nodePtr == NULL) { |
| 3312 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 3313 |
} |
| 3314 |
if (nodePtr == NULL) { |
| 3315 |
return TCL_ERROR; |
| 3316 |
} |
| 3317 |
|
| 3318 |
if (flags & TREE_TRACE_UNSET) { |
| 3319 |
valuePtr = Tcl_NewStringObj("",-1); |
| 3320 |
Blt_TreeSetValue(NULL, butPtr->tree, |
| 3321 |
nodePtr, butPtr->selVarName, valuePtr); |
| 3322 |
Tcl_AppendResult(interp, "can not delete node", 0); |
| 3323 |
return TCL_ERROR; |
| 3324 |
/*goto redisplay; */ |
| 3325 |
} |
| 3326 |
|
| 3327 |
if (Blt_TreeGetValue(NULL, butPtr->tree, |
| 3328 |
nodePtr, butPtr->selVarName, &valuePtr) == TCL_OK) { |
| 3329 |
value = Tcl_GetString(valuePtr); |
| 3330 |
} else { |
| 3331 |
value = ""; |
| 3332 |
} |
| 3333 |
if (butPtr->type == TYPE_CHECK_BUTTON && butPtr->tristateValue && |
| 3334 |
strcmp(value,butPtr->tristateValue)==0) { |
| 3335 |
if ((butPtr->flags&TRISTATED) == 0) doUpd = 1; |
| 3336 |
butPtr->flags |= TRISTATED; |
| 3337 |
} else { |
| 3338 |
if ((butPtr->flags&TRISTATED) != 0) doUpd = 1; |
| 3339 |
butPtr->flags &= ~TRISTATED; |
| 3340 |
} |
| 3341 |
if (strcmp(value, butPtr->onValue) == 0) { |
| 3342 |
if (butPtr->flags & SELECTED) { |
| 3343 |
if (doUpd) goto redisplay; |
| 3344 |
return TCL_OK; |
| 3345 |
} |
| 3346 |
butPtr->flags |= SELECTED; |
| 3347 |
} else if (butPtr->flags & SELECTED) { |
| 3348 |
butPtr->flags &= ~SELECTED; |
| 3349 |
} else { |
| 3350 |
if (doUpd) goto redisplay; |
| 3351 |
return TCL_OK; |
| 3352 |
} |
| 3353 |
|
| 3354 |
redisplay: |
| 3355 |
if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin) |
| 3356 |
&& !(butPtr->flags & REDRAW_PENDING)) { |
| 3357 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3358 |
butPtr->flags |= REDRAW_PENDING; |
| 3359 |
} |
| 3360 |
return TCL_OK; |
| 3361 |
} |
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
/* |
| 3366 |
*-------------------------------------------------------------- |
| 3367 |
* |
| 3368 |
* ButtonVarProc -- |
| 3369 |
* |
| 3370 |
* This procedure is invoked when someone changes the |
| 3371 |
* state variable associated with a radio button. Depending |
| 3372 |
* on the new value of the button's variable, the button |
| 3373 |
* may be selected or deselected. |
| 3374 |
* |
| 3375 |
* Results: |
| 3376 |
* NULL is always returned. |
| 3377 |
* |
| 3378 |
* Side effects: |
| 3379 |
* The button may become selected or deselected. |
| 3380 |
* |
| 3381 |
*-------------------------------------------------------------- |
| 3382 |
*/ |
| 3383 |
|
| 3384 |
/* ARGSUSED */ |
| 3385 |
static char * |
| 3386 |
ButtonVarProc(clientData, interp, name1, name2, flags) |
| 3387 |
ClientData clientData; /* Information about button. */ |
| 3388 |
Tcl_Interp *interp; /* Interpreter containing variable. */ |
| 3389 |
char *name1; /* Name of variable. */ |
| 3390 |
char *name2; /* Second part of variable name. */ |
| 3391 |
int flags; /* Information about what happened. */ |
| 3392 |
{ |
| 3393 |
register Button *butPtr = clientData; |
| 3394 |
CONST char *value; |
| 3395 |
int doUpd = 0; |
| 3396 |
|
| 3397 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3398 |
return NULL; |
| 3399 |
} |
| 3400 |
|
| 3401 |
/* |
| 3402 |
* If the variable is being unset, then just re-establish the |
| 3403 |
* trace unless the whole interpreter is going away. |
| 3404 |
*/ |
| 3405 |
|
| 3406 |
if (flags & TCL_TRACE_UNSETS) { |
| 3407 |
butPtr->flags &= ~SELECTED; |
| 3408 |
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { |
| 3409 |
Tcl_TraceVar(interp, butPtr->selVarName, |
| 3410 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 3411 |
ButtonVarProc, clientData); |
| 3412 |
} |
| 3413 |
goto redisplay; |
| 3414 |
} |
| 3415 |
/* |
| 3416 |
* Use the value of the variable to update the selected status of |
| 3417 |
* the button. |
| 3418 |
*/ |
| 3419 |
|
| 3420 |
value = Tcl_GetVar(interp, butPtr->selVarName, TCL_GLOBAL_ONLY); |
| 3421 |
if (value == NULL) { |
| 3422 |
value = ""; |
| 3423 |
} |
| 3424 |
if (butPtr->type == TYPE_CHECK_BUTTON && butPtr->tristateValue && |
| 3425 |
strcmp(value,butPtr->tristateValue)==0) { |
| 3426 |
if ((butPtr->flags&TRISTATED) == 0) doUpd = 1; |
| 3427 |
butPtr->flags |= TRISTATED; |
| 3428 |
} else { |
| 3429 |
if ((butPtr->flags&TRISTATED) != 0) doUpd = 1; |
| 3430 |
butPtr->flags &= ~TRISTATED; |
| 3431 |
} |
| 3432 |
if (strcmp(value, butPtr->onValue) == 0) { |
| 3433 |
if (butPtr->flags & SELECTED) { |
| 3434 |
if (doUpd) goto redisplay; |
| 3435 |
return (char *) NULL; |
| 3436 |
} |
| 3437 |
butPtr->flags |= SELECTED; |
| 3438 |
} else if (butPtr->flags & SELECTED) { |
| 3439 |
butPtr->flags &= ~SELECTED; |
| 3440 |
} else { |
| 3441 |
if (doUpd) goto redisplay; |
| 3442 |
return (char *) NULL; |
| 3443 |
} |
| 3444 |
|
| 3445 |
redisplay: |
| 3446 |
if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin) |
| 3447 |
&& !(butPtr->flags & REDRAW_PENDING)) { |
| 3448 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3449 |
butPtr->flags |= REDRAW_PENDING; |
| 3450 |
} |
| 3451 |
return (char *) NULL; |
| 3452 |
} |
| 3453 |
/* Trace tree operation. */ |
| 3454 |
static int TreeTextTraceProc(ClientData clientData, |
| 3455 |
Tcl_Interp *interp, Blt_TreeNode node, Blt_TreeKey key, |
| 3456 |
unsigned int flags) { |
| 3457 |
register Button *butPtr = clientData; |
| 3458 |
Blt_TreeNode nodePtr; |
| 3459 |
Tcl_Obj *valuePtr; |
| 3460 |
CONST char *value; |
| 3461 |
|
| 3462 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3463 |
return TCL_OK; |
| 3464 |
} |
| 3465 |
|
| 3466 |
/* printf("TRC TXT(%d)\n", (flags & TREE_TRACE_UNSET)); */ |
| 3467 |
nodePtr = Blt_TreeGetNode(butPtr->tree, butPtr->node); |
| 3468 |
if (nodePtr == NULL) { |
| 3469 |
nodePtr = Blt_TreeCreateNode(butPtr->tree, Blt_TreeGetNode(butPtr->tree, 0), NULL, -1); |
| 3470 |
} |
| 3471 |
if (nodePtr == NULL) { |
| 3472 |
return TCL_ERROR; |
| 3473 |
} |
| 3474 |
|
| 3475 |
if (flags & TREE_TRACE_UNSET) { |
| 3476 |
Tcl_AppendResult(interp, "can not delete node", 0); |
| 3477 |
valuePtr = Tcl_NewStringObj(butPtr->textPtr,-1); |
| 3478 |
Blt_TreeSetValue(NULL, butPtr->tree, |
| 3479 |
nodePtr, butPtr->textVarName, valuePtr); |
| 3480 |
return TCL_ERROR; |
| 3481 |
/* goto redisplay; */ |
| 3482 |
} |
| 3483 |
|
| 3484 |
if (Blt_TreeGetValue(NULL, butPtr->tree, |
| 3485 |
nodePtr, butPtr->textVarName, &valuePtr) == TCL_OK) { |
| 3486 |
value = Tcl_GetString(valuePtr); |
| 3487 |
} else { |
| 3488 |
value = ""; |
| 3489 |
} |
| 3490 |
if (butPtr->textPtr != NULL) { |
| 3491 |
Blt_Free(butPtr->textPtr); |
| 3492 |
} |
| 3493 |
butPtr->textPtr = Blt_Malloc(strlen(value) + 1); |
| 3494 |
strcpy(butPtr->textPtr, value); |
| 3495 |
ComputeButtonGeometry(butPtr); |
| 3496 |
|
| 3497 |
|
| 3498 |
if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin) |
| 3499 |
&& !(butPtr->flags & REDRAW_PENDING)) { |
| 3500 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3501 |
butPtr->flags |= REDRAW_PENDING; |
| 3502 |
} |
| 3503 |
return TCL_OK; |
| 3504 |
} |
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
/* |
| 3509 |
*-------------------------------------------------------------- |
| 3510 |
* |
| 3511 |
* ButtonTextVarProc -- |
| 3512 |
* |
| 3513 |
* This procedure is invoked when someone changes the variable |
| 3514 |
* whose contents are to be displayed in a button. |
| 3515 |
* |
| 3516 |
* Results: |
| 3517 |
* NULL is always returned. |
| 3518 |
* |
| 3519 |
* Side effects: |
| 3520 |
* The text displayed in the button will change to match the |
| 3521 |
* variable. |
| 3522 |
* |
| 3523 |
*-------------------------------------------------------------- |
| 3524 |
*/ |
| 3525 |
|
| 3526 |
/* ARGSUSED */ |
| 3527 |
static char * |
| 3528 |
ButtonTextVarProc(clientData, interp, name1, name2, flags) |
| 3529 |
ClientData clientData; /* Information about button. */ |
| 3530 |
Tcl_Interp *interp; /* Interpreter containing variable. */ |
| 3531 |
char *name1; /* Not used. */ |
| 3532 |
char *name2; /* Not used. */ |
| 3533 |
int flags; /* Information about what happened. */ |
| 3534 |
{ |
| 3535 |
register Button *butPtr = clientData; |
| 3536 |
CONST char *value; |
| 3537 |
|
| 3538 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3539 |
return NULL; |
| 3540 |
} |
| 3541 |
|
| 3542 |
/* |
| 3543 |
* If the variable is unset, then immediately recreate it unless |
| 3544 |
* the whole interpreter is going away. |
| 3545 |
*/ |
| 3546 |
|
| 3547 |
if (flags & TCL_TRACE_UNSETS) { |
| 3548 |
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { |
| 3549 |
Tcl_SetVar(interp, butPtr->textVarName, butPtr->textPtr, |
| 3550 |
TCL_GLOBAL_ONLY); |
| 3551 |
Tcl_TraceVar(interp, butPtr->textVarName, |
| 3552 |
TCL_GLOBAL_ONLY | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, |
| 3553 |
ButtonTextVarProc, clientData); |
| 3554 |
} |
| 3555 |
return (char *) NULL; |
| 3556 |
} |
| 3557 |
value = Tcl_GetVar(interp, butPtr->textVarName, TCL_GLOBAL_ONLY); |
| 3558 |
if (value == NULL) { |
| 3559 |
value = ""; |
| 3560 |
} |
| 3561 |
if (butPtr->textPtr != NULL) { |
| 3562 |
Blt_Free(butPtr->textPtr); |
| 3563 |
} |
| 3564 |
butPtr->textPtr = Blt_Malloc(strlen(value) + 1); |
| 3565 |
strcpy(butPtr->textPtr, value); |
| 3566 |
ComputeButtonGeometry(butPtr); |
| 3567 |
|
| 3568 |
if ((butPtr->tkwin != NULL) && Tk_IsMapped(butPtr->tkwin) |
| 3569 |
&& !(butPtr->flags & REDRAW_PENDING)) { |
| 3570 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3571 |
butPtr->flags |= REDRAW_PENDING; |
| 3572 |
} |
| 3573 |
return (char *) NULL; |
| 3574 |
} |
| 3575 |
|
| 3576 |
/* |
| 3577 |
*---------------------------------------------------------------------- |
| 3578 |
* |
| 3579 |
* ButtonImageProc -- |
| 3580 |
* |
| 3581 |
* This procedure is invoked by the image code whenever the manager |
| 3582 |
* for an image does something that affects the size of contents |
| 3583 |
* of an image displayed in a button. |
| 3584 |
* |
| 3585 |
* Results: |
| 3586 |
* None. |
| 3587 |
* |
| 3588 |
* Side effects: |
| 3589 |
* Arranges for the button to get redisplayed. |
| 3590 |
* |
| 3591 |
*---------------------------------------------------------------------- |
| 3592 |
*/ |
| 3593 |
|
| 3594 |
/*ARGSUSED*/ |
| 3595 |
static void |
| 3596 |
ButtonImageProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 3597 |
ClientData clientData; /* Pointer to widget record. */ |
| 3598 |
int x, y; /* Upper left pixel (within image) |
| 3599 |
* that must be redisplayed. */ |
| 3600 |
int width, height; /* Dimensions of area to redisplay |
| 3601 |
* (may be <= 0). */ |
| 3602 |
int imgWidth, imgHeight; /* New dimensions of image. */ |
| 3603 |
{ |
| 3604 |
register Button *butPtr = clientData; |
| 3605 |
|
| 3606 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3607 |
return; |
| 3608 |
} |
| 3609 |
|
| 3610 |
if (butPtr->tkwin != NULL) { |
| 3611 |
ComputeButtonGeometry(butPtr); |
| 3612 |
if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) { |
| 3613 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3614 |
butPtr->flags |= REDRAW_PENDING; |
| 3615 |
} |
| 3616 |
} |
| 3617 |
} |
| 3618 |
static void |
| 3619 |
ButtonImageBdProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 3620 |
ClientData clientData; /* Pointer to widget record. */ |
| 3621 |
int x, y; /* Upper left pixel (within image) |
| 3622 |
* that must be redisplayed. */ |
| 3623 |
int width, height; /* Dimensions of area to redisplay |
| 3624 |
* (may be <= 0). */ |
| 3625 |
int imgWidth, imgHeight; /* New dimensions of image. */ |
| 3626 |
{ |
| 3627 |
register Button *butPtr = clientData; |
| 3628 |
|
| 3629 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3630 |
return; |
| 3631 |
} |
| 3632 |
|
| 3633 |
if (butPtr->tkwin != NULL) { |
| 3634 |
butPtr->flags |= BUTTON_DIRTYBD; |
| 3635 |
ComputeButtonGeometry(butPtr); |
| 3636 |
if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) { |
| 3637 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3638 |
butPtr->flags |= REDRAW_PENDING; |
| 3639 |
} |
| 3640 |
} |
| 3641 |
} |
| 3642 |
|
| 3643 |
/* |
| 3644 |
*---------------------------------------------------------------------- |
| 3645 |
* |
| 3646 |
* ButtonSelectImageProc -- |
| 3647 |
* |
| 3648 |
* This procedure is invoked by the image code whenever the manager |
| 3649 |
* for an image does something that affects the size of contents |
| 3650 |
* of the image displayed in a button when it is selected. |
| 3651 |
* |
| 3652 |
* Results: |
| 3653 |
* None. |
| 3654 |
* |
| 3655 |
* Side effects: |
| 3656 |
* May arrange for the button to get redisplayed. |
| 3657 |
* |
| 3658 |
*---------------------------------------------------------------------- |
| 3659 |
*/ |
| 3660 |
|
| 3661 |
/*ARGSUSED*/ |
| 3662 |
static void |
| 3663 |
ButtonSelectImageProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 3664 |
ClientData clientData; /* Pointer to widget record. */ |
| 3665 |
int x, y; /* Upper left pixel (within image) |
| 3666 |
* that must be redisplayed. */ |
| 3667 |
int width, height; /* Dimensions of area to redisplay |
| 3668 |
* (may be <= 0). */ |
| 3669 |
int imgWidth, imgHeight; /* New dimensions of image. */ |
| 3670 |
{ |
| 3671 |
register Button *butPtr = clientData; |
| 3672 |
|
| 3673 |
if ((butPtr->flags & BUTTON_DELETED)) { |
| 3674 |
return; |
| 3675 |
} |
| 3676 |
|
| 3677 |
/* |
| 3678 |
* Don't recompute geometry: it's controlled by the primary image. |
| 3679 |
*/ |
| 3680 |
|
| 3681 |
if ((butPtr->flags & SELECTED) && (butPtr->tkwin != NULL) |
| 3682 |
&& Tk_IsMapped(butPtr->tkwin) |
| 3683 |
&& !(butPtr->flags & REDRAW_PENDING)) { |
| 3684 |
Tcl_DoWhenIdle(DisplayButton, (ClientData)butPtr); |
| 3685 |
butPtr->flags |= REDRAW_PENDING; |
| 3686 |
} |
| 3687 |
} |
| 3688 |
|
| 3689 |
int |
| 3690 |
Blt_ButtonInit(interp) |
| 3691 |
Tcl_Interp *interp; |
| 3692 |
{ |
| 3693 |
static Blt_CmdSpec cmdSpecs[6] = |
| 3694 |
{ |
| 3695 |
{"frame", FrameCmd,}, |
| 3696 |
{"button", ButtonCmd,}, |
| 3697 |
{"checkbutton", CheckbuttonCmd,}, |
| 3698 |
{"radiobutton", RadiobuttonCmd,}, |
| 3699 |
{"label", LabelCmd,}, |
| 3700 |
{"menubutton", MenubuttonCmd,}, |
| 3701 |
}; |
| 3702 |
static Blt_CmdSpec cmdBSpecs[6] = |
| 3703 |
{ |
| 3704 |
{"frame", BFrameCmd,}, |
| 3705 |
{"button", BButtonCmd,}, |
| 3706 |
{"checkbutton", BCheckbuttonCmd,}, |
| 3707 |
{"radiobutton", BRadiobuttonCmd,}, |
| 3708 |
{"label", BLabelCmd,}, |
| 3709 |
{"menubutton", BMenubuttonCmd,}, |
| 3710 |
}; |
| 3711 |
int result; |
| 3712 |
tkNormalUid = Tk_GetUid("normal"); |
| 3713 |
tkDisabledUid = Tk_GetUid("disabled"); |
| 3714 |
tkActiveUid = Tk_GetUid("active"); |
| 3715 |
result = Blt_InitCmds(interp, "blt::tile", cmdSpecs, 6); |
| 3716 |
if (result == TCL_OK) { |
| 3717 |
result = Blt_InitCmds(interp, "blt::widget", cmdBSpecs, 6); |
| 3718 |
} |
| 3719 |
return result; |
| 3720 |
} |
| 3721 |
|
| 3722 |
#endif /* NO_TILEBUTTON */ |