Debian Codegraph @

generic/tkButton.c

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