Debian Codegraph @

pTk/mTk/unix/tkUnixButton.c

raw symbols SCIP
1 /*
2 * tkUnixButton.c --
3 *
4 * This file implements the Unix specific portion of the button
5 * widgets.
6 *
7 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * RCS: @(#) $Id: tkUnixButton.c,v 1.11.2.4 2003/10/10 20:20:47 hobbs Exp $
13 */
14
15 #include "tkButton.h"
16
17 /*
18 * Declaration of Unix specific button structure.
19 */
20
21 typedef struct UnixButton {
22 TkButton info; /* Generic button info. */
23 } UnixButton;
24
25 /*
26 * The class procedure table for the button widgets.
27 */
28
29 Tk_ClassProcs tkpButtonProcs = {
30 sizeof(Tk_ClassProcs), /* size */
31 TkButtonWorldChanged, /* worldChangedProc */
32 };
33
34 /*
35 *----------------------------------------------------------------------
36 *
37 * TkpCreateButton --
38 *
39 * Allocate a new TkButton structure.
40 *
41 * Results:
42 * Returns a newly allocated TkButton structure.
43 *
44 * Side effects:
45 * Registers an event handler for the widget.
46 *
47 *----------------------------------------------------------------------
48 */
49
50 TkButton *
51 TkpCreateButton(tkwin)
52 Tk_Window tkwin;
53 {
54 UnixButton *butPtr = (UnixButton *)ckalloc(sizeof(UnixButton));
55 return (TkButton *) butPtr;
56 }
57
58 /*
59 *----------------------------------------------------------------------
60 *
61 * TkpDisplayButton --
62 *
63 * This procedure is invoked to display a button widget. It is
64 * normally invoked as an idle handler.
65 *
66 * Results:
67 * None.
68 *
69 * Side effects:
70 * Commands are output to X to display the button in its
71 * current mode. The REDRAW_PENDING flag is cleared.
72 *
73 *----------------------------------------------------------------------
74 */
75
76 void
77 TkpDisplayButton(clientData)
78 ClientData clientData; /* Information about widget. */
79 {
80 register TkButton *butPtr = (TkButton *) clientData;
81 GC gc;
82 Tk_3DBorder border;
83 Pixmap pixmap;
84 int x = 0; /* Initialization only needed to stop
85 * compiler warning. */
86 int y, relief;
87 Tk_Window tkwin = butPtr->tkwin;
88 int width, height, fullWidth, fullHeight;
89 int textXOffset, textYOffset;
90 int haveImage = 0, haveText = 0;
91 int offset; /* 1 means this is a button widget, so we
92 * offset the text to make the button appear
93 * to move up and down as the relief changes.
94 */
95 int imageWidth, imageHeight;
96 int imageXOffset = 0, imageYOffset = 0; /* image information that will
97 * be used to restrict disabled
98 * pixmap as well */
99
100 butPtr->flags &= ~REDRAW_PENDING;
101 if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
102 return;
103 }
104
105 border = butPtr->normalBorder;
106 if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
107 gc = butPtr->disabledGC;
108 } else if ((butPtr->state == STATE_ACTIVE)
109 && !Tk_StrictMotif(butPtr->tkwin)) {
110 gc = butPtr->activeTextGC;
111 border = butPtr->activeBorder;
112 } else {
113 gc = butPtr->normalTextGC;
114 }
115 if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
116 && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
117 border = butPtr->selectBorder;
118 }
119
120 /*
121 * Override the relief specified for the button if this is a
122 * checkbutton or radiobutton and there's no indicator. The new
123 * relief is as follows:
124 * If the button is select --> "sunken"
125 * If relief==overrelief --> relief
126 * Otherwise --> overrelief
127 *
128 * The effect we are trying to achieve is as follows:
129 *
130 * value mouse-over? --> relief
131 * ------- ------------ --------
132 * off no flat
133 * off yes raised
134 * on no sunken
135 * on yes sunken
136 *
137 * This is accomplished by configuring the checkbutton or radiobutton
138 * like this:
139 *
140 * -indicatoron 0 -overrelief raised -offrelief flat
141 *
142 * Bindings (see library/button.tcl) will copy the -overrelief into
143 * -relief on mouseover. Hence, we can tell if we are in mouse-over by
144 * comparing relief against overRelief. This is an aweful kludge, but
145 * it gives use the desired behavior while keeping the code backwards
146 * compatible.
147 */
148
149 relief = butPtr->relief;
150 if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
151 if (butPtr->flags & SELECTED) {
152 relief = TK_RELIEF_SUNKEN;
153 } else if (butPtr->overRelief != relief) {
154 relief = butPtr->offRelief;
155 }
156 }
157
158 offset = (butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin);
159
160 /*
161 * In order to avoid screen flashes, this procedure redraws
162 * the button in a pixmap, then copies the pixmap to the
163 * screen in a single operation. This means that there's no
164 * point in time where the on-sreen image has been cleared.
165 */
166
167 pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin),
168 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
169 Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin),
170 Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
171
172 /*
173 * Display image or bitmap or text for button.
174 */
175
176 if (butPtr->image != NULL) {
177 Tk_SizeOfImage(butPtr->image, &width, &height);
178 haveImage = 1;
179 } else if (butPtr->bitmap != None) {
180 Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
181 haveImage = 1;
182 }
183 imageWidth = width;
184 imageHeight = height;
185
186 haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
187
188 if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
189 textXOffset = 0;
190 textYOffset = 0;
191 fullWidth = 0;
192 fullHeight = 0;
193
194 switch ((enum compound) butPtr->compound) {
195 case COMPOUND_TOP:
196 case COMPOUND_BOTTOM: {
197 /* Image is above or below text */
198 if (butPtr->compound == COMPOUND_TOP) {
199 textYOffset = height + butPtr->padY;
200 } else {
201 imageYOffset = butPtr->textHeight + butPtr->padY;
202 }
203 fullHeight = height + butPtr->textHeight + butPtr->padY;
204 fullWidth = (width > butPtr->textWidth ? width :
205 butPtr->textWidth);
206 textXOffset = (fullWidth - butPtr->textWidth)/2;
207 imageXOffset = (fullWidth - width)/2;
208 break;
209 }
210 case COMPOUND_LEFT:
211 case COMPOUND_RIGHT: {
212 /* Image is left or right of text */
213 if (butPtr->compound == COMPOUND_LEFT) {
214 textXOffset = width + butPtr->padX;
215 } else {
216 imageXOffset = butPtr->textWidth + butPtr->padX;
217 }
218 fullWidth = butPtr->textWidth + butPtr->padX + width;
219 fullHeight = (height > butPtr->textHeight ? height :
220 butPtr->textHeight);
221 textYOffset = (fullHeight - butPtr->textHeight)/2;
222 imageYOffset = (fullHeight - height)/2;
223 break;
224 }
225 case COMPOUND_CENTER: {
226 /* Image and text are superimposed */
227 fullWidth = (width > butPtr->textWidth ? width :
228 butPtr->textWidth);
229 fullHeight = (height > butPtr->textHeight ? height :
230 butPtr->textHeight);
231 textXOffset = (fullWidth - butPtr->textWidth)/2;
232 imageXOffset = (fullWidth - width)/2;
233 textYOffset = (fullHeight - butPtr->textHeight)/2;
234 imageYOffset = (fullHeight - height)/2;
235 break;
236 }
237 case COMPOUND_NONE: {break;}
238 }
239
240 TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
241 butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y);
242
243 x += butPtr->indicatorSpace;
244
245 x += offset;
246 y += offset;
247 if (relief == TK_RELIEF_RAISED) {
248 x -= offset;
249 y -= offset;
250 } else if (relief == TK_RELIEF_SUNKEN) {
251 x += offset;
252 y += offset;
253 }
254
255 imageXOffset += x;
256 imageYOffset += y;
257
258 if (butPtr->image != NULL) {
259 if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) {
260 Tk_RedrawImage(butPtr->selectImage, 0, 0,
261 width, height, pixmap, imageXOffset, imageYOffset);
262 } else {
263 Tk_RedrawImage(butPtr->image, 0, 0, width,
264 height, pixmap, imageXOffset, imageYOffset);
265 }
266 } else {
267 XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset);
268 XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc,
269 0, 0, (unsigned int) width, (unsigned int) height,
270 imageXOffset, imageYOffset, 1);
271 XSetClipOrigin(butPtr->display, gc, 0, 0);
272 }
273
274 Tk_DrawTextLayout(butPtr->display, pixmap, gc,
275 butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1);
276 Tk_UnderlineTextLayout(butPtr->display, pixmap, gc,
277 butPtr->textLayout, x + textXOffset, y + textYOffset,
278 butPtr->underline);
279 y += fullHeight/2;
280 } else {
281 if (haveImage) {
282 TkComputeAnchor(butPtr->anchor, tkwin, 0, 0,
283 butPtr->indicatorSpace + width, height, &x, &y);
284 x += butPtr->indicatorSpace;
285
286 x += offset;
287 y += offset;
288 if (relief == TK_RELIEF_RAISED) {
289 x -= offset;
290 y -= offset;
291 } else if (relief == TK_RELIEF_SUNKEN) {
292 x += offset;
293 y += offset;
294 }
295 imageXOffset += x;
296 imageYOffset += y;
297 if (butPtr->image != NULL) {
298 if ((butPtr->selectImage != NULL) &&
299 (butPtr->flags & SELECTED)) {
300 Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
301 height, pixmap, imageXOffset, imageYOffset);
302 } else {
303 Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap,
304 imageXOffset, imageYOffset);
305 }
306 } else {
307 XSetClipOrigin(butPtr->display, gc, x, y);
308 XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0,
309 (unsigned int) width, (unsigned int) height, x, y, 1);
310 XSetClipOrigin(butPtr->display, gc, 0, 0);
311 }
312 y += height/2;
313 } else {
314 TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
315 butPtr->indicatorSpace + butPtr->textWidth,
316 butPtr->textHeight, &x, &y);
317
318 x += butPtr->indicatorSpace;
319
320 x += offset;
321 y += offset;
322 if (relief == TK_RELIEF_RAISED) {
323 x -= offset;
324 y -= offset;
325 } else if (relief == TK_RELIEF_SUNKEN) {
326 x += offset;
327 y += offset;
328 }
329 Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout,
330 x, y, 0, -1);
331 Tk_UnderlineTextLayout(butPtr->display, pixmap, gc,
332 butPtr->textLayout, x, y, butPtr->underline);
333 y += butPtr->textHeight/2;
334 }
335 }
336
337 /*
338 * Draw the indicator for check buttons and radio buttons. At this
339 * point x and y refer to the top-left corner of the text or image
340 * or bitmap.
341 */
342
343 if ((butPtr->type == TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
344 int dim;
345
346 dim = butPtr->indicatorDiameter;
347 x -= butPtr->indicatorSpace;
348 y -= dim/2;
349 if (dim > 2*butPtr->borderWidth) {
350 Tk_Draw3DRectangle(tkwin, pixmap, border, x, y, dim, dim,
351 butPtr->borderWidth,
352 (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN :
353 TK_RELIEF_RAISED);
354 x += butPtr->borderWidth;
355 y += butPtr->borderWidth;
356 dim -= 2*butPtr->borderWidth;
357 if (butPtr->flags & SELECTED) {
358 GC gc;
359 if (butPtr->state != STATE_DISABLED) {
360 if (butPtr->selectBorder != NULL) {
361 gc = Tk_3DBorderGC(tkwin, butPtr->selectBorder,
362 TK_3D_FLAT_GC);
363 } else {
364 gc = Tk_3DBorderGC(tkwin, butPtr->normalBorder,
365 TK_3D_FLAT_GC);
366 }
367 } else {
368 if (butPtr->disabledFg != NULL) {
369 gc = butPtr->disabledGC;
370 } else {
371 gc = butPtr->normalTextGC;
372 XSetForeground(butPtr->display, butPtr->disabledGC,
373 Tk_3DBorderColor(butPtr->normalBorder)->pixel);
374 }
375 }
376
377 XFillRectangle(butPtr->display, pixmap, gc, x, y,
378 (unsigned int) dim, (unsigned int) dim);
379 } else {
380 Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, x, y,
381 dim, dim, butPtr->borderWidth, TK_RELIEF_FLAT);
382 }
383 }
384 } else if ((butPtr->type == TYPE_RADIO_BUTTON) && butPtr->indicatorOn) {
385 XPoint points[4];
386 int radius;
387
388 radius = butPtr->indicatorDiameter/2;
389 points[0].x = x - butPtr->indicatorSpace;
390 points[0].y = y;
391 points[1].x = points[0].x + radius;
392 points[1].y = points[0].y + radius;
393 points[2].x = points[1].x + radius;
394 points[2].y = points[0].y;
395 points[3].x = points[1].x;
396 points[3].y = points[0].y - radius;
397 if (butPtr->flags & SELECTED) {
398 GC gc;
399
400 if (butPtr->state != STATE_DISABLED) {
401 if (butPtr->selectBorder != NULL) {
402 gc = Tk_3DBorderGC(tkwin, butPtr->selectBorder,
403 TK_3D_FLAT_GC);
404 } else {
405 gc = Tk_3DBorderGC(tkwin, butPtr->normalBorder,
406 TK_3D_FLAT_GC);
407 }
408 } else {
409 if (butPtr->disabledFg != NULL) {
410 gc = butPtr->disabledGC;
411 } else {
412 gc = butPtr->normalTextGC;
413 XSetForeground(butPtr->display, butPtr->disabledGC,
414 Tk_3DBorderColor(butPtr->normalBorder)->pixel);
415 }
416 }
417
418 XFillPolygon(butPtr->display, pixmap, gc, points, 4, Convex,
419 CoordModeOrigin);
420 } else {
421 Tk_Fill3DPolygon(tkwin, pixmap, butPtr->normalBorder, points,
422 4, butPtr->borderWidth, TK_RELIEF_FLAT);
423 }
424 Tk_Draw3DPolygon(tkwin, pixmap, border, points, 4, butPtr->borderWidth,
425 (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN :
426 TK_RELIEF_RAISED);
427 }
428
429 /*
430 * If the button is disabled with a stipple rather than a special
431 * foreground color, generate the stippled effect. If the widget
432 * is selected and we use a different background color when selected,
433 * must temporarily modify the GC so the stippling is the right color.
434 */
435
436 if ((butPtr->state == STATE_DISABLED)
437 && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
438 if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
439 && (butPtr->selectBorder != NULL)) {
440 XSetForeground(butPtr->display, butPtr->stippleGC,
441 Tk_3DBorderColor(butPtr->selectBorder)->pixel);
442 }
443 /*
444 * Stipple the whole button if no disabledFg was specified,
445 * otherwise restrict stippling only to displayed image
446 */
447 if (butPtr->disabledFg == NULL) {
448 XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, 0, 0,
449 (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin));
450 } else {
451 XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC,
452 imageXOffset, imageYOffset,
453 (unsigned) imageWidth, (unsigned) imageHeight);
454 }
455 if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
456 && (butPtr->selectBorder != NULL)) {
457 XSetForeground(butPtr->display, butPtr->stippleGC,
458 Tk_3DBorderColor(butPtr->normalBorder)->pixel);
459 }
460 }
461
462 /*
463 * Draw the border and traversal highlight last. This way, if the
464 * button's contents overflow they'll be covered up by the border.
465 * This code is complicated by the possible combinations of focus
466 * highlight and default rings. We draw the focus and highlight rings
467 * using the highlight border and highlight foreground color.
468 */
469
470 if (relief != TK_RELIEF_FLAT) {
471 int inset = butPtr->highlightWidth;
472
473 if (butPtr->defaultState == DEFAULT_ACTIVE) {
474 /*
475 * Draw the default ring with 2 pixels of space between the
476 * default ring and the button and the default ring and the
477 * focus ring. Note that we need to explicitly draw the space
478 * in the highlightBorder color to ensure that we overwrite any
479 * overflow text and/or a different button background color.
480 */
481
482 Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
483 inset, Tk_Width(tkwin) - 2*inset,
484 Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT);
485 inset += 2;
486 Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
487 inset, Tk_Width(tkwin) - 2*inset,
488 Tk_Height(tkwin) - 2*inset, 1, TK_RELIEF_SUNKEN);
489 inset++;
490 Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset,
491 inset, Tk_Width(tkwin) - 2*inset,
492 Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT);
493
494 inset += 2;
495 } else if (butPtr->defaultState == DEFAULT_NORMAL) {
496 /*
497 * Leave room for the default ring and write over any text or
498 * background color.
499 */
500
501 Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0,
502 0, Tk_Width(tkwin), Tk_Height(tkwin), 5, TK_RELIEF_FLAT);
503 inset += 5;
504 }
505
506 /*
507 * Draw the button border.
508 */
509
510 Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset,
511 Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
512 butPtr->borderWidth, relief);
513 }
514 if (butPtr->highlightWidth > 0) {
515 GC gc;
516
517 if (butPtr->flags & GOT_FOCUS) {
518 gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
519 } else {
520 gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
521 pixmap);
522 }
523
524 /*
525 * Make sure the focus ring shrink-wraps the actual button, not the
526 * padding space left for a default ring.
527 */
528
529 if (butPtr->defaultState == DEFAULT_NORMAL) {
530 TkDrawInsetFocusHighlight(tkwin, gc, butPtr->highlightWidth,
531 pixmap, 5);
532 } else {
533 Tk_DrawFocusHighlight(tkwin, gc, butPtr->highlightWidth, pixmap);
534 }
535 }
536
537 /*
538 * Copy the information from the off-screen pixmap onto the screen,
539 * then delete the pixmap.
540 */
541
542 XCopyArea(butPtr->display, pixmap, Tk_WindowId(tkwin),
543 butPtr->copyGC, 0, 0, (unsigned) Tk_Width(tkwin),
544 (unsigned) Tk_Height(tkwin), 0, 0);
545 Tk_FreePixmap(butPtr->display, pixmap);
546 }
547
548 /*
549 *----------------------------------------------------------------------
550 *
551 * TkpComputeButtonGeometry --
552 *
553 * After changes in a button's text or bitmap, this procedure
554 * recomputes the button's geometry and passes this information
555 * along to the geometry manager for the window.
556 *
557 * Results:
558 * None.
559 *
560 * Side effects:
561 * The button's window may change size.
562 *
563 *----------------------------------------------------------------------
564 */
565
566 void
567 TkpComputeButtonGeometry(butPtr)
568 register TkButton *butPtr; /* Button whose geometry may have changed. */
569 {
570 int width, height, avgWidth, txtWidth, txtHeight;
571 int haveImage = 0, haveText = 0;
572 Tk_FontMetrics fm;
573
574 butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth;
575
576 /*
577 * Leave room for the default ring if needed.
578 */
579
580 if (butPtr->defaultState != DEFAULT_DISABLED) {
581 butPtr->inset += 5;
582 }
583 butPtr->indicatorSpace = 0;
584
585 width = 0;
586 height = 0;
587 txtWidth = 0;
588 txtHeight = 0;
589 avgWidth = 0;
590
591 if (butPtr->image != NULL) {
592 Tk_SizeOfImage(butPtr->image, &width, &height);
593 haveImage = 1;
594 } else if (butPtr->bitmap != None) {
595 Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
596 haveImage = 1;
597 }
598
599 if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
600 Tk_FreeTextLayout(butPtr->textLayout);
601
602 butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
603 Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
604 butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
605
606 txtWidth = butPtr->textWidth;
607 txtHeight = butPtr->textHeight;
608 avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
609 Tk_GetFontMetrics(butPtr->tkfont, &fm);
610 haveText = (txtWidth != 0 && txtHeight != 0);
611 }
612
613 /*
614 * If the button is compound (ie, it shows both an image and text),
615 * the new geometry is a combination of the image and text geometry.
616 * We only honor the compound bit if the button has both text and an
617 * image, because otherwise it is not really a compound button.
618 */
619
620 if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
621 switch ((enum compound) butPtr->compound) {
622 case COMPOUND_TOP:
623 case COMPOUND_BOTTOM: {
624 /* Image is above or below text */
625 height += txtHeight + butPtr->padY;
626 width = (width > txtWidth ? width : txtWidth);
627 break;
628 }
629 case COMPOUND_LEFT:
630 case COMPOUND_RIGHT: {
631 /* Image is left or right of text */
632 width += txtWidth + butPtr->padX;
633 height = (height > txtHeight ? height : txtHeight);
634 break;
635 }
636 case COMPOUND_CENTER: {
637 /* Image and text are superimposed */
638 width = (width > txtWidth ? width : txtWidth);
639 height = (height > txtHeight ? height : txtHeight);
640 break;
641 }
642 case COMPOUND_NONE: {break;}
643 }
644 if (butPtr->width > 0) {
645 width = butPtr->width;
646 }
647 if (butPtr->height > 0) {
648 height = butPtr->height;
649 }
650
651 if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
652 butPtr->indicatorSpace = height;
653 if (butPtr->type == TYPE_CHECK_BUTTON) {
654 butPtr->indicatorDiameter = (65*height)/100;
655 } else {
656 butPtr->indicatorDiameter = (75*height)/100;
657 }
658 }
659
660 width += 2*butPtr->padX;
661 height += 2*butPtr->padY;
662
663 } else {
664 if (haveImage) {
665 if (butPtr->width > 0) {
666 width = butPtr->width;
667 }
668 if (butPtr->height > 0) {
669 height = butPtr->height;
670 }
671
672 if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
673 butPtr->indicatorSpace = height;
674 if (butPtr->type == TYPE_CHECK_BUTTON) {
675 butPtr->indicatorDiameter = (65*height)/100;
676 } else {
677 butPtr->indicatorDiameter = (75*height)/100;
678 }
679 }
680 } else {
681 width = txtWidth;
682 height = txtHeight;
683
684 if (butPtr->width > 0) {
685 width = butPtr->width * avgWidth;
686 }
687 if (butPtr->height > 0) {
688 height = butPtr->height * fm.linespace;
689 }
690 if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
691 butPtr->indicatorDiameter = fm.linespace;
692 if (butPtr->type == TYPE_CHECK_BUTTON) {
693 butPtr->indicatorDiameter =
694 (80*butPtr->indicatorDiameter)/100;
695 }
696 butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
697 }
698 }
699 }
700
701 /*
702 * When issuing the geometry request, add extra space for the indicator,
703 * if any, and for the border and padding, plus two extra pixels so the
704 * display can be offset by 1 pixel in either direction for the raised
705 * or lowered effect.
706 */
707
708 if ((butPtr->image == NULL) && (butPtr->bitmap == None)) {
709 width += 2*butPtr->padX;
710 height += 2*butPtr->padY;
711 }
712 if ((butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin)) {
713 width += 2;
714 height += 2;
715 }
716 Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace
717 + 2*butPtr->inset), (int) (height + 2*butPtr->inset));
718 Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
719 }