< prev index next >

src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 // copy from awt.h
  27 #ifndef _WIN32_WINNT
  28 #define _WIN32_WINNT 0x0600
  29 #endif
  30 
  31 // copy from awt.h
  32 #ifndef _WIN32_IE
  33 #define _WIN32_IE 0x0600
  34 #endif
  35 
  36 #include "splashscreen_impl.h"
  37 #include <windowsx.h>
  38 #include <windows.h>
  39 #include <winuser.h>
  40 #include "sizecalc.h"
  41 
  42 #ifndef WS_EX_LAYERED
  43 #define WS_EX_LAYERED 0x80000
  44 #endif
  45 
  46 #ifndef ULW_ALPHA
  47 #define ULW_ALPHA               0x00000002
  48 #endif
  49 
  50 #ifndef AC_SRC_OVER
  51 #define AC_SRC_OVER                 0x00
  52 #endif
  53 
  54 #ifndef AC_SRC_ALPHA
  55 #define AC_SRC_ALPHA                0x01
  56 #endif
  57 
  58 #define WM_SPLASHUPDATE         WM_USER+1
  59 #define WM_SPLASHRECONFIGURE    WM_USER+2
  60 


  61 /* Could use npt but decided to cut down on linked code size */
  62 char* SplashConvertStringAlloc(const char* in, int *size) {
  63     int len, outChars, rc;
  64     WCHAR* buf;
  65     if (!in) {
  66         return NULL;
  67     }
  68     len = strlen(in);
  69     outChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
  70                                        NULL, 0);
  71     buf = (WCHAR*) SAFE_SIZE_ARRAY_ALLOC(malloc, outChars, sizeof(WCHAR));
  72     if (!buf) {
  73         return NULL;
  74     }
  75     rc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
  76                                  buf, outChars);
  77     if (rc==0) {
  78         free(buf);
  79         return NULL;
  80     } else {


 554 void
 555 SplashClosePlatform(Splash * splash)
 556 {
 557     PostMessage(splash->hWnd, WM_QUIT, 0, 0);
 558 }
 559 
 560 void
 561 SplashUpdate(Splash * splash)
 562 {
 563     PostMessage(splash->hWnd, WM_SPLASHUPDATE, 0, 0);
 564 }
 565 
 566 void
 567 SplashReconfigure(Splash * splash)
 568 {
 569     PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
 570 }
 571 
 572 SPLASHEXPORT char*
 573 SplashGetScaledImageName(const char* jarName, const char* fileName,
 574                            float *scaleFactor)
 575 {



































 576     *scaleFactor = 1;














 577     return NULL;
 578 }


  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 // copy from awt.h
  27 #ifndef _WIN32_WINNT
  28 #define _WIN32_WINNT 0x0600
  29 #endif
  30 
  31 // copy from awt.h
  32 #ifndef _WIN32_IE
  33 #define _WIN32_IE 0x0600
  34 #endif
  35 
  36 #include "splashscreen_impl.h"
  37 #include <windowsx.h>
  38 #include <windows.h>
  39 #include <winuser.h>
  40 #include "sizecalc.h"

  41 #ifndef WS_EX_LAYERED
  42 #define WS_EX_LAYERED 0x80000
  43 #endif
  44 
  45 #ifndef ULW_ALPHA
  46 #define ULW_ALPHA               0x00000002
  47 #endif
  48 
  49 #ifndef AC_SRC_OVER
  50 #define AC_SRC_OVER                 0x00
  51 #endif
  52 
  53 #ifndef AC_SRC_ALPHA
  54 #define AC_SRC_ALPHA                0x01
  55 #endif
  56 
  57 #define WM_SPLASHUPDATE         WM_USER+1
  58 #define WM_SPLASHRECONFIGURE    WM_USER+2
  59 
  60 #define BUFF_SIZE 1024
  61 
  62 /* Could use npt but decided to cut down on linked code size */
  63 char* SplashConvertStringAlloc(const char* in, int *size) {
  64     int len, outChars, rc;
  65     WCHAR* buf;
  66     if (!in) {
  67         return NULL;
  68     }
  69     len = strlen(in);
  70     outChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
  71                                        NULL, 0);
  72     buf = (WCHAR*) SAFE_SIZE_ARRAY_ALLOC(malloc, outChars, sizeof(WCHAR));
  73     if (!buf) {
  74         return NULL;
  75     }
  76     rc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
  77                                  buf, outChars);
  78     if (rc==0) {
  79         free(buf);
  80         return NULL;
  81     } else {


 555 void
 556 SplashClosePlatform(Splash * splash)
 557 {
 558     PostMessage(splash->hWnd, WM_QUIT, 0, 0);
 559 }
 560 
 561 void
 562 SplashUpdate(Splash * splash)
 563 {
 564     PostMessage(splash->hWnd, WM_SPLASHUPDATE, 0, 0);
 565 }
 566 
 567 void
 568 SplashReconfigure(Splash * splash)
 569 {
 570     PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
 571 }
 572 
 573 SPLASHEXPORT char*
 574 SplashGetScaledImageName(const char* jarName, const char* fileName,
 575 float *scaleFactor)
 576 {
 577     *scaleFactor = 1.0;
 578     float dpiScaleX = -1.0f;
 579     float dpiScaleY = -1.0f;
 580     GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY);
 581     *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor;
 582 
 583     if (*scaleFactor > 1.0) {
 584         char strDpi[BUFF_SIZE];
 585         _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX);
 586         char *dupFileName = strdup(fileName);
 587         char *fileExtension = strrchr(dupFileName, '.');
 588         char *scaledImgName = NULL;
 589         char *nameToAppend = ".scale-";
 590         size_t length = 0;
 591         /*File is missing extension */
 592         if (fileExtension == NULL) {
 593             length = strlen(dupFileName) + strlen(nameToAppend) +
 594                 strlen(strDpi) + 1;
 595             scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char));
 596             int retVal = _snprintf(scaledImgName, length, "%s%s%s", dupFileName,
 597                 nameToAppend, strDpi);
 598             if (retVal < 0 || (retVal != length - 1)) {
 599                 *scaleFactor = 1;
 600                 free(scaledImgName);
 601                 return NULL;
 602             }
 603         }
 604         else {
 605             size_t length_Without_Ext = fileExtension - dupFileName;
 606             length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) +
 607                 strlen(fileExtension) + 1;
 608             scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char));
 609             int retVal = _snprintf(scaledImgName, length, "%.*s%s%s%s",
 610                 length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension);
 611             if (retVal < 0 || (retVal != length - 1)) {
 612                 *scaleFactor = 1;
 613                 free(scaledImgName);
 614                 return NULL;
 615             }
 616         }
 617         free(dupFileName);
 618         FILE *fp = NULL;
 619         if (!(fp = fopen(scaledImgName, "r"))) {
 620             *scaleFactor = 1;
 621             free(scaledImgName);
 622             return NULL;
 623         }
 624         fclose(fp);
 625         return scaledImgName;
 626     }
 627     return NULL;
 628 }
< prev index next >