Tk Source Code

Check-in [899361f8]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Adjust button metrics in HITheme instead of Tk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-6da617825e
Files: files | file ages | folders
SHA3-256: 899361f8b14ef5316a75e2fce69401b84ac5d5b0fd54a27429285eb1e03c7eff
User & Date: culler 2018-05-01 19:14:59
Original Comment: Adjust button methods in HITheme instead of Tk
References
2018-05-01
19:24 Ticket [6da61782] button-13.1 to -13.8 fail on macOS status still Open with 4 other changes artifact: 3f40397b user: marc_culler
Context
2018-05-01
22:32
Eliminate unnecessary offsets. This moves buttons down 1px, which is better. Closed-Leaf check-in: 82724e59 user: culler tags: bug-6da617825e
19:14
Adjust button metrics in HITheme instead of Tk. check-in: 899361f8 user: culler tags: bug-6da617825e
2018-04-30
15:53
Fix [6d5042069f]: tk inactive does not work on macOS (tk-6.5 fails) check-in: adb7926c user: culler tags: core-8-6-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXButton.c.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
...
392
393
394
395
396
397
398
399


400
401
402
403
404
405
406
...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659

#define FIRST_DRAW	    2
#define ACTIVE		    4


/*
 * Default insets for controls
 */

#define DEF_INSET_LEFT 12
#define DEF_INSET_RIGHT 12
#define DEF_INSET_TOP 1
#define DEF_INSET_BOTTOM 1

/*
 * Some defines used to control what type of control is drawn.
 */

................................................................................

    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(butPtr->textLayout);
	butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

	/*Remove extraneous padding around label widgets.*/
	txtWidth = butPtr->textWidth;
	txtHeight = butPtr->textHeight + DEF_INSET_BOTTOM + DEF_INSET_TOP;
	charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(butPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
    }

    if (haveImage && haveText) { /* Image and Text */
	switch ((enum compound) butPtr->compound) {
................................................................................

    if (TkMacOSXComputeButtonDrawParams(butPtr,&drawParams)) {
        HIRect tmpRect;
    	HIRect contBounds;
        int paddingx = 0;
        int paddingy = 0;

    	tmpRect = CGRectMake(0, 0, width, height);



        HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
        /* If the content region has a minimum height, match it. */
        if (height < contBounds.size.height) {
    	  height = contBounds.size.height;
        }

................................................................................
    } else { /* Text only */
        int x, y;
	TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
			butPtr->textWidth + butPtr->indicatorSpace,
			  butPtr->textHeight, &x, &y);
	x += butPtr->indicatorSpace;
	Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
			  x, y - DEF_INSET_BOTTOM, 0, -1);
    }

    /*
     * If the button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect.  If the widget
     * is selected and we use a different background color when selected,
     * must temporarily modify the GC so the stippling is the right color.






|


|
|







 







<

|







 







|
>
>







 







|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328
329
...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660

#define FIRST_DRAW	    2
#define ACTIVE		    4


/*
 * Default insets for controls - used to adjust button metrics.
 */

#define DEF_INSET_LEFT 0
#define DEF_INSET_RIGHT 0
#define DEF_INSET_TOP 1
#define DEF_INSET_BOTTOM 1

/*
 * Some defines used to control what type of control is drawn.
 */

................................................................................

    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(butPtr->textLayout);
	butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);


	txtWidth = butPtr->textWidth;
	txtHeight = butPtr->textHeight;
	charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(butPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
    }

    if (haveImage && haveText) { /* Image and Text */
	switch ((enum compound) butPtr->compound) {
................................................................................

    if (TkMacOSXComputeButtonDrawParams(butPtr,&drawParams)) {
        HIRect tmpRect;
    	HIRect contBounds;
        int paddingx = 0;
        int paddingy = 0;

    	tmpRect = CGRectMake(0, 0,
			     width + DEF_INSET_LEFT + DEF_INSET_RIGHT,
			     height + DEF_INSET_BOTTOM + DEF_INSET_TOP);

        HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
        /* If the content region has a minimum height, match it. */
        if (height < contBounds.size.height) {
    	  height = contBounds.size.height;
        }

................................................................................
    } else { /* Text only */
        int x, y;
	TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
			butPtr->textWidth + butPtr->indicatorSpace,
			  butPtr->textHeight, &x, &y);
	x += butPtr->indicatorSpace;
	Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
			  x + DEF_INSET_LEFT, y - DEF_INSET_BOTTOM, 0, -1);
    }

    /*
     * If the button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect.  If the widget
     * is selected and we use a different background color when selected,
     * must temporarily modify the GC so the stippling is the right color.