Tk Source Code

Changes On Branch bug-17b509d78f
Login

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

Changes In Branch bug-17b509d78f Excluding Merge-Ins

This is equivalent to a diff from 747c94e9 to fc822251

2025-05-29
07:59
Fix [17b509d78f]: wm iconbitmap does not support icon files with png images on Windows. check-in: b450c42d user: fvogel tags: core-8-6-branch
07:58
Remove unintended blank line. Closed-Leaf check-in: fc822251 user: fvogel tags: bug-17b509d78f
2025-05-25
16:37
If CreateIconFromResourceEx failed, try CreateIconFromResource as a fallback. Do this always, i.e.remove the condition on biBitCount != 16 since NT is now very obsolete. Also, remove debug printfs. check-in: eeaf3858 user: fvogel tags: bug-17b509d78f
2025-05-19
09:46
Fix [7231bf9941]: Setting ttk state may change the a variable passed by value check-in: 151d1e44 user: jan.nijtmans tags: core-8-6-branch
2025-05-17
20:43
Fix [17b509d78f]: wm iconbitmap does not support icon files with png images on Windows. check-in: 0176f7c0 user: fvogel tags: bug-17b509d78f
2025-04-29
21:55
Fix [9b23b6ca23]: [tk print] canvas with smooth lines crashes on windows. Fix [7716cb2f67]: [tk print] fails for canvas items with non integer widths. Patches by Emiliano Gavilan. check-in: 242958d6 user: jan.nijtmans tags: core-9-0-branch
2025-04-27
20:07
ubuntu-20.04 is removed from Github ACTIONS check-in: 747c94e9 user: jan.nijtmans tags: core-8-6-branch
2025-04-26
13:04
Fix [111f66c781]: Cannot minimize all windows on Aqua. check-in: d4ced03c user: culler tags: core-8-6-branch

Changes to win/tkWinWm.c.
674
675
676
677
678
679
680












































681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
 *	code.
 *
 * Results:
 *	BOOL - TRUE for success, FALSE for failure
 *
 *----------------------------------------------------------------------
 */













































static BOOL
AdjustIconImagePointers(
    LPICONIMAGE lpImage)
{
    /*
     * Sanity check.
     */

    if (lpImage == NULL) {
	return FALSE;
    }

    /*
     * BITMAPINFO is at beginning of bits.
     */

    lpImage->lpbi = (LPBITMAPINFO) lpImage->lpBits;

    /*
     * Width - simple enough.
     */

    lpImage->Width = lpImage->lpbi->bmiHeader.biWidth;

    /*
     * Icons are stored in funky format where height is doubled so account for
     * that.
     */

    lpImage->Height = (lpImage->lpbi->bmiHeader.biHeight)/2;

    /*
     * How many colors?
     */

    lpImage->Colors = lpImage->lpbi->bmiHeader.biPlanes
	    * lpImage->lpbi->bmiHeader.biBitCount;

    /*
     * XOR bits follow the header and color table.
     */

    lpImage->lpXOR = (LPBYTE) FindDIBBits((LPSTR) lpImage->lpbi);








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




















<
<
|
<
<
<
<
<


<
|
<
<
<
<
<
<







674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744


745





746
747

748






749
750
751
752
753
754
755
 *	code.
 *
 * Results:
 *	BOOL - TRUE for success, FALSE for failure
 *
 *----------------------------------------------------------------------
 */

static BOOL
SetSizeAndColorFromHICON(      /* Helper for AdjustIconImagePointers */
    HICON hicon,
    LPICONIMAGE lpImage)
{
    ICONINFO info;
    BOOL bRes;
    BITMAP bmp;

    memset(&info, 0, sizeof(info));

    bRes = GetIconInfo(hicon, &info);
    if (!bRes) {
	return FALSE;
    }

    if (info.hbmColor) {
	const int nWrittenBytes = GetObject(info.hbmColor, sizeof(bmp), &bmp);

	if (nWrittenBytes > 0) {
	    lpImage->Width = bmp.bmWidth;
	    lpImage->Height = bmp.bmHeight;
	    lpImage->Colors = bmp.bmBitsPixel;
	}
    } else if (info.hbmMask) {
	// Icon has no color plane, image data stored in mask
	const int nWrittenBytes = GetObject(info.hbmMask, sizeof(bmp), &bmp);

	if (nWrittenBytes > 0) {
	    lpImage->Width = bmp.bmWidth;
	    lpImage->Height = bmp.bmHeight / 2;
	    lpImage->Colors = 1;
	}
    }

    if (info.hbmColor) {
	DeleteObject(info.hbmColor);
    }
    if (info.hbmMask) {
	DeleteObject(info.hbmMask);
    }
    return TRUE;
}

static BOOL
AdjustIconImagePointers(
    LPICONIMAGE lpImage)
{
    /*
     * Sanity check.
     */

    if (lpImage == NULL) {
	return FALSE;
    }

    /*
     * BITMAPINFO is at beginning of bits.
     */

    lpImage->lpbi = (LPBITMAPINFO) lpImage->lpBits;

    /*


     * Width, height, and number of colors.





     */


    SetSizeAndColorFromHICON(lpImage->hIcon, lpImage);







    /*
     * XOR bits follow the header and color table.
     */

    lpImage->lpXOR = (LPBYTE) FindDIBBits((LPSTR) lpImage->lpbi);

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
	return NULL;
    }

    /*
     * Let the OS do the real work :)
     */

    hIcon = (HICON) CreateIconFromResourceEx(lpIcon->lpBits,
	    lpIcon->dwNumBytes, isIcon, 0x00030000,
	    (*(LPBITMAPINFOHEADER) lpIcon->lpBits).biWidth,
	    (*(LPBITMAPINFOHEADER) lpIcon->lpBits).biHeight/2, 0);

    /*
     * It failed, odds are good we're on NT so try the non-Ex way.
     */

    if (hIcon == NULL) {
	/*
	 * We would break on NT if we try with a 16bpp image.
	 */

	if (lpIcon->lpbi->bmiHeader.biBitCount != 16) {
	    hIcon = CreateIconFromResource(lpIcon->lpBits, lpIcon->dwNumBytes,
		    isIcon, 0x00030000);
	}
    }
    return hIcon;
}

/*
 *----------------------------------------------------------------------
 *







|
|
<
<


|



<
<
<
<
<
|
|
<







791
792
793
794
795
796
797
798
799


800
801
802
803
804
805





806
807

808
809
810
811
812
813
814
	return NULL;
    }

    /*
     * Let the OS do the real work :)
     */

    hIcon = (HICON)CreateIconFromResourceEx(lpIcon->lpBits,
	    lpIcon->dwNumBytes, isIcon, 0x00030000, 0, 0, 0);



    /*
     * It failed, the non-Ex way might work as a fallback.
     */

    if (hIcon == NULL) {





        hIcon = CreateIconFromResource(lpIcon->lpBits, lpIcon->dwNumBytes,
		isIcon, 0x00030000);

    }
    return hIcon;
}

/*
 *----------------------------------------------------------------------
 *
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685


1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
	if (dwBytesRead != lpIDE[i].dwBytesInRes) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading file: %s", Tcl_PosixError(interp)));
	    goto readError;
	}

	/*
	 * Set the internal pointers appropriately.
	 */



	if (!AdjustIconImagePointers(&lpIR->IconImages[i])) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Error converting to internal format", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICON", "FORMAT", NULL);
	    goto readError;
	}
	lpIR->IconImages[i].hIcon =
		MakeIconOrCursorFromResource(&lpIR->IconImages[i], isIcon);
    }

    /*
     * Clean up
     */

    ckfree(lpIDE);







|


>
>






<
<







1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715


1716
1717
1718
1719
1720
1721
1722
	if (dwBytesRead != lpIDE[i].dwBytesInRes) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading file: %s", Tcl_PosixError(interp)));
	    goto readError;
	}

	/*
	 * Create the icon from the resource, and set the internal pointers appropriately.
	 */

	lpIR->IconImages[i].hIcon =
		MakeIconOrCursorFromResource(&lpIR->IconImages[i], isIcon);
	if (!AdjustIconImagePointers(&lpIR->IconImages[i])) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Error converting to internal format", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICON", "FORMAT", NULL);
	    goto readError;
	}


    }

    /*
     * Clean up
     */

    ckfree(lpIDE);