Tk Source Code

Check-in [82724e59]
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:Eliminate unnecessary offsets. This moves buttons down 1px, which is better.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-6da617825e
Files: files | file ages | folders
SHA3-256: 82724e59c52c79e4d1ca77ce4a21219bbf3135191aa5d5027da56dd84c30e15c
User & Date: culler 2018-05-01 22:32:54
Context
2018-05-03
22:22
Fixed [6da617825e]: button-13.1 to -13.8 fail on macOS check-in: 5c15789c user: culler tags: core-8-6-branch
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXButton.c.

17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
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
...
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
...
907
908
909
910
911
912
913


914

915
916
917
918
919
920
921
 */

#include "tkMacOSXPrivate.h"
#include "tkButton.h"
#include "tkMacOSXFont.h"
#include "tkMacOSXDebug.h"


#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.
 */

#define DRAW_LABEL	0	/* Labels are treated genericly. */
#define DRAW_CONTROL	1	/* Draw using the Native control. */
................................................................................

    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.
................................................................................

        ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true);

	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}


	if (mbPtr->btnkind == kThemePushButton) {
	    /*
	     * For some reason, pushbuttons get drawn a bit
	     * too low, normally.  Correct for this.
	     */
	    if (cntrRect.size.height < 22) {
		cntrRect.origin.y -= 1;
	    } else if (cntrRect.size.height < 23) {
		cntrRect.origin.y -= 2;
	    }
	}

        hiinfo.version = 0;
        hiinfo.state = mbPtr->drawinfo.state;
        hiinfo.kind  = mbPtr->btnkind;
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
................................................................................
    TkButton  *butPtr = (TkButton *)ptr;
    Tk_Window  tkwin  = butPtr->tkwin;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }



    /*Overlay Tk elements over button native region: drawing elements within button boundaries/native region causes unpredictable metrics.*/

    DrawButtonImageAndText( butPtr);
}
 
/*
 *--------------------------------------------------------------
 *
 * ButtonEventProc --






<



<

>
|


|
<
|
<







 







|
<
<







 







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
|
>







17
18
19
20
21
22
23

24
25
26

27
28
29
30
31
32

33

34
35
36
37
38
39
40
...
388
389
390
391
392
393
394
395


396
397
398
399
400
401
402
...
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
...
778
779
780
781
782
783
784













785
786
787
788
789
790
791
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
 */

#include "tkMacOSXPrivate.h"
#include "tkButton.h"
#include "tkMacOSXFont.h"
#include "tkMacOSXDebug.h"


#define FIRST_DRAW	    2
#define ACTIVE		    4


/*
 * Extra padding used for computing the content size that should
 * be allowed when drawing the HITheme button.
 */

#define HI_PADX 0

#define HI_PADY 1


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

#define DRAW_LABEL	0	/* Labels are treated genericly. */
#define DRAW_CONTROL	1	/* Draw using the Native control. */
................................................................................

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

    	tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY);



        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, 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.
................................................................................

        ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true);

	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}














        hiinfo.version = 0;
        hiinfo.state = mbPtr->drawinfo.state;
        hiinfo.kind  = mbPtr->btnkind;
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
................................................................................
    TkButton  *butPtr = (TkButton *)ptr;
    Tk_Window  tkwin  = butPtr->tkwin;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }

    /*
     * Overlay Tk elements over button native region: drawing elements
     * within button boundaries/native region causes unpredictable metrics.
     */
    DrawButtonImageAndText( butPtr);
}
 
/*
 *--------------------------------------------------------------
 *
 * ButtonEventProc --