< prev index next >

src/windows/native/sun/windows/ShellFolder2.cpp

Print this page




 895         pIcon->Release();
 896     }
 897     return (jlong)hIcon;
 898 }
 899 
 900 
 901 /*
 902  * Class:     sun_awt_shell_Win32ShellFolder2
 903  * Method:    disposeIcon
 904  * Signature: (J)V
 905  */
 906 JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_disposeIcon
 907     (JNIEnv* env, jclass cls, jlong hicon)
 908 {
 909     fn_DestroyIcon((HICON)hicon);
 910 }
 911 
 912 /*
 913  * Class:     sun_awt_shell_Win32ShellFolder2
 914  * Method:    getIconBits
 915  * Signature: (JI)[I
 916  */
 917 JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconBits
 918     (JNIEnv* env, jclass cls, jlong hicon, jint iconSize)
 919 {


 920     jintArray iconBits = NULL;
 921 



 922     // Get the icon info
 923     ICONINFO iconInfo;
 924     if (fn_GetIconInfo((HICON)hicon, &iconInfo)) {
 925         // Get the screen DC
 926         HDC dc = GetDC(NULL);
 927         if (dc != NULL) {



















 928             // Set up BITMAPINFO
 929             BITMAPINFO bmi;
 930             memset(&bmi, 0, sizeof(BITMAPINFO));
 931             bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 932             bmi.bmiHeader.biWidth = iconSize;
 933             bmi.bmiHeader.biHeight = -iconSize;
 934             bmi.bmiHeader.biPlanes = 1;
 935             bmi.bmiHeader.biBitCount = 32;
 936             bmi.bmiHeader.biCompression = BI_RGB;
 937             // Extract the color bitmap
 938             int nBits = iconSize * iconSize;
 939             long colorBits[1024];
 940             GetDIBits(dc, iconInfo.hbmColor, 0, iconSize, colorBits, &bmi, DIB_RGB_COLORS);
 941             // XP supports alpha in some icons, and depending on device.
 942             // This should take precedence over the icon mask bits.
 943             BOOL hasAlpha = FALSE;
 944             if (IS_WINXP) {
 945                 for (int i = 0; i < nBits; i++) {
 946                     if ((colorBits[i] & 0xff000000) != 0) {
 947                         hasAlpha = TRUE;
 948                         break;
 949                     }
 950                 }
 951             }
 952             if (!hasAlpha) {
 953                 // Extract the mask bitmap
 954                 long maskBits[1024];
 955                 GetDIBits(dc, iconInfo.hbmMask, 0, iconSize, maskBits, &bmi, DIB_RGB_COLORS);
 956                 // Copy the mask alphas into the color bits
 957                 for (int i = 0; i < nBits; i++) {
 958                     if (maskBits[i] == 0) {
 959                         colorBits[i] |= 0xff000000;
 960                     }
 961                 }
 962             }
 963             // Release DC
 964             ReleaseDC(NULL, dc);
 965             // Create java array
 966             iconBits = env->NewIntArray(nBits);
 967             if (!(env->ExceptionCheck())) {
 968             // Copy values to java array
 969             env->SetIntArrayRegion(iconBits, 0, nBits, colorBits);
 970         }
 971         }
 972         // Fix 4745575 GDI Resource Leak
 973         // MSDN
 974         // GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO.


 987  */
 988 JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getStandardViewButton0
 989     (JNIEnv* env, jclass cls, jint iconIndex)
 990 {
 991     jintArray result = NULL;
 992 
 993     // Create a toolbar
 994     HWND hWndToolbar = ::CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
 995         0, 0, 0, 0, 0,
 996         NULL, NULL, NULL, NULL);
 997 
 998     if (hWndToolbar != NULL) {
 999         SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_VIEW_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1000 
1001         HIMAGELIST hImageList = (HIMAGELIST) SendMessage(hWndToolbar, TB_GETIMAGELIST, 0, 0);
1002 
1003         if (hImageList != NULL) {
1004             HICON hIcon = ImageList_GetIcon(hImageList, iconIndex, ILD_TRANSPARENT);
1005 
1006             if (hIcon != NULL) {
1007                 result = Java_sun_awt_shell_Win32ShellFolder2_getIconBits(env, cls, ptr_to_jlong(hIcon), 16);
1008 
1009                 DestroyIcon(hIcon);
1010             }
1011 
1012             ImageList_Destroy(hImageList);
1013         }
1014 
1015         DestroyWindow(hWndToolbar);
1016     }
1017 
1018     return result;
1019 }
1020 
1021 /*
1022  * Class:     sun_awt_shell_Win32ShellFolder2
1023  * Method:    getSystemIcon
1024  * Signature: (I)J
1025  */
1026 JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getSystemIcon
1027     (JNIEnv* env, jclass cls, jint iconID)




 895         pIcon->Release();
 896     }
 897     return (jlong)hIcon;
 898 }
 899 
 900 
 901 /*
 902  * Class:     sun_awt_shell_Win32ShellFolder2
 903  * Method:    disposeIcon
 904  * Signature: (J)V
 905  */
 906 JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_disposeIcon
 907     (JNIEnv* env, jclass cls, jlong hicon)
 908 {
 909     fn_DestroyIcon((HICON)hicon);
 910 }
 911 
 912 /*
 913  * Class:     sun_awt_shell_Win32ShellFolder2
 914  * Method:    getIconBits
 915  * Signature: (J)[I
 916  */
 917 JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconBits
 918     (JNIEnv* env, jclass cls, jlong hicon)
 919 {
 920     const int MAX_ICON_SIZE = 128;
 921     int iconSize = 0;
 922     jintArray iconBits = NULL;
 923 
 924     BITMAP bmp;
 925     memset(&bmp, 0, sizeof(BITMAP));
 926 
 927     // Get the icon info
 928     ICONINFO iconInfo;
 929     if (fn_GetIconInfo((HICON)hicon, &iconInfo)) {
 930         // Get the screen DC
 931         HDC dc = GetDC(NULL);
 932         if (dc != NULL) {
 933             // find out the icon size in order to deal with different sizes
 934             // delivered depending on HiDPI mode or SD DPI mode.
 935             if (iconInfo.hbmColor) {
 936                 const int nWrittenBytes = GetObject(iconInfo.hbmColor, sizeof(bmp), &bmp);
 937                 if(nWrittenBytes > 0) {
 938                     iconSize = bmp.bmWidth;
 939                 }
 940             } else if (iconInfo.hbmMask) {
 941                 // Icon has no color plane, image data stored in mask
 942                 const int nWrittenBytes = GetObject(iconInfo.hbmMask, sizeof(bmp), &bmp);
 943                 if (nWrittenBytes > 0) {
 944                     iconSize = bmp.bmWidth;
 945                 }
 946             }
 947             // limit iconSize to MAX_ICON_SIZE, so that the colorBits and maskBits
 948             // arrays are big enough.
 949             // (logic: rather show bad icons than overrun the array size)
 950             iconSize = iconSize > MAX_ICON_SIZE ? MAX_ICON_SIZE : iconSize;
 951 
 952             // Set up BITMAPINFO
 953             BITMAPINFO bmi;
 954             memset(&bmi, 0, sizeof(BITMAPINFO));
 955             bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 956             bmi.bmiHeader.biWidth = iconSize;
 957             bmi.bmiHeader.biHeight = -iconSize;
 958             bmi.bmiHeader.biPlanes = 1;
 959             bmi.bmiHeader.biBitCount = 32;
 960             bmi.bmiHeader.biCompression = BI_RGB;
 961             // Extract the color bitmap
 962             int nBits = iconSize * iconSize;
 963             long colorBits[MAX_ICON_SIZE * MAX_ICON_SIZE];
 964             GetDIBits(dc, iconInfo.hbmColor, 0, iconSize, colorBits, &bmi, DIB_RGB_COLORS);
 965             // XP supports alpha in some icons, and depending on device.
 966             // This should take precedence over the icon mask bits.
 967             BOOL hasAlpha = FALSE;
 968             if (IS_WINXP) {
 969                 for (int i = 0; i < nBits; i++) {
 970                     if ((colorBits[i] & 0xff000000) != 0) {
 971                         hasAlpha = TRUE;
 972                         break;
 973                     }
 974                 }
 975             }
 976             if (!hasAlpha) {
 977                 // Extract the mask bitmap
 978                 long maskBits[MAX_ICON_SIZE * MAX_ICON_SIZE];
 979                 GetDIBits(dc, iconInfo.hbmMask, 0, iconSize, maskBits, &bmi, DIB_RGB_COLORS);
 980                 // Copy the mask alphas into the color bits
 981                 for (int i = 0; i < nBits; i++) {
 982                     if (maskBits[i] == 0) {
 983                         colorBits[i] |= 0xff000000;
 984                     }
 985                 }
 986             }
 987             // Release DC
 988             ReleaseDC(NULL, dc);
 989             // Create java array
 990             iconBits = env->NewIntArray(nBits);
 991             if (!(env->ExceptionCheck())) {
 992                 // Copy values to java array
 993                 env->SetIntArrayRegion(iconBits, 0, nBits, colorBits);
 994             }
 995         }
 996         // Fix 4745575 GDI Resource Leak
 997         // MSDN
 998         // GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO.


1011  */
1012 JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getStandardViewButton0
1013     (JNIEnv* env, jclass cls, jint iconIndex)
1014 {
1015     jintArray result = NULL;
1016 
1017     // Create a toolbar
1018     HWND hWndToolbar = ::CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
1019         0, 0, 0, 0, 0,
1020         NULL, NULL, NULL, NULL);
1021 
1022     if (hWndToolbar != NULL) {
1023         SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_VIEW_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1024 
1025         HIMAGELIST hImageList = (HIMAGELIST) SendMessage(hWndToolbar, TB_GETIMAGELIST, 0, 0);
1026 
1027         if (hImageList != NULL) {
1028             HICON hIcon = ImageList_GetIcon(hImageList, iconIndex, ILD_TRANSPARENT);
1029 
1030             if (hIcon != NULL) {
1031                 result = Java_sun_awt_shell_Win32ShellFolder2_getIconBits(env, cls, ptr_to_jlong(hIcon));
1032 
1033                 DestroyIcon(hIcon);
1034             }
1035 
1036             ImageList_Destroy(hImageList);
1037         }
1038 
1039         DestroyWindow(hWndToolbar);
1040     }
1041 
1042     return result;
1043 }
1044 
1045 /*
1046  * Class:     sun_awt_shell_Win32ShellFolder2
1047  * Method:    getSystemIcon
1048  * Signature: (I)J
1049  */
1050 JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getSystemIcon
1051     (JNIEnv* env, jclass cls, jint iconID)


< prev index next >