< prev index next >

src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp

Print this page




  53 
  54 typedef enum {
  55     TS_MIN,
  56     TS_TRUE,
  57     TS_DRAW
  58 } THEME_SIZE;
  59 
  60 
  61 // Remove these when we start using VC 7 (or XP Platform SDK)
  62 typedef struct _MARGINS
  63 {
  64     int cxLeftWidth;      // width of left border that retains its size
  65     int cxRightWidth;     // width of right border that retains its size
  66     int cyTopHeight;      // height of top border that retains its size
  67     int cyBottomHeight;   // height of bottom border that retains its size
  68 } MARGINS, *PMARGINS;
  69 
  70 #define TMT_TRANSPARENT 2201
  71 #endif // _UXTHEME_H_
  72 





  73 
  74 #define ALPHA_MASK 0xff000000
  75 #define RED_MASK 0xff0000
  76 #define GREEN_MASK 0xff00
  77 #define BLUE_MASK 0xff
  78 #define ALPHA_SHIFT 24
  79 #define RED_SHIFT 16
  80 #define GREEN_SHIFT 8
  81 
  82 
  83 typedef HRESULT(__stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme);
  84 
  85 typedef HRESULT(__stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc,
  86         int iPartId, int iStateId, const RECT *pRect,  const RECT *pClipRect);
  87 
  88 typedef HTHEME(__stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList);
  89 
  90 typedef HRESULT (__stdcall *PFNDRAWTHEMETEXT)(HTHEME hTheme, HDC hdc,
  91           int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
  92           DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect);


 738         jobject dimObj = env->NewObject(dimClassID, dimMID, point.x, point.y);
 739 
 740         if (safe_ExceptionOccurred(env)) {
 741             env->ExceptionDescribe();
 742             env->ExceptionClear();
 743         }
 744 
 745         return dimObj;
 746     }
 747     return NULL;
 748 }
 749 
 750 void rescale(SIZE *size) {
 751     HWND hWnd = ::GetDesktopWindow();
 752     HDC hDC = ::GetDC(hWnd);
 753     int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
 754     int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
 755 
 756     if (dpiX !=0 && dpiX != 96) {
 757         float invScaleX = 96.0f / dpiX;
 758         size->cx = (int)round(size->cx * invScaleX);
 759     }
 760     if (dpiY != 0 && dpiY != 96) {
 761         float invScaleY = 96.0f / dpiY;
 762         size->cy = (int)round(size->cy * invScaleY);
 763     }
 764     ::ReleaseDC(hWnd, hDC);
 765 }
 766 
 767 /*
 768  * Class:     sun_awt_windows_ThemeReader
 769  * Method:    getPartSize
 770  * Signature: (JII)Ljava/awt/Dimension;
 771  */
 772 JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getPartSize
 773 (JNIEnv *env, jclass klass, jlong theme, jint part, jint state) {
 774     if (theme != NULL) {
 775         SIZE size;
 776 
 777         if (SUCCEEDED(GetThemePartSize((HTHEME)theme, NULL, part, state,
 778            NULL, TS_TRUE, &size)) && (env->EnsureLocalCapacity(2) >= 0)) {
 779 
 780             static jmethodID dimMID = NULL;
 781             static jclass dimClassID = NULL;
 782             if (dimClassID == NULL) {




  53 
  54 typedef enum {
  55     TS_MIN,
  56     TS_TRUE,
  57     TS_DRAW
  58 } THEME_SIZE;
  59 
  60 
  61 // Remove these when we start using VC 7 (or XP Platform SDK)
  62 typedef struct _MARGINS
  63 {
  64     int cxLeftWidth;      // width of left border that retains its size
  65     int cxRightWidth;     // width of right border that retains its size
  66     int cyTopHeight;      // height of top border that retains its size
  67     int cyBottomHeight;   // height of bottom border that retains its size
  68 } MARGINS, *PMARGINS;
  69 
  70 #define TMT_TRANSPARENT 2201
  71 #endif // _UXTHEME_H_
  72 
  73 #if defined(_MSC_VER) && _MSC_VER >= 1800
  74 #  define ROUND_TO_INT(num)    ((int) round(num))
  75 #else
  76 #  define ROUND_TO_INT(num)    ((int) floor((num) + 0.5))
  77 #endif
  78 
  79 #define ALPHA_MASK 0xff000000
  80 #define RED_MASK 0xff0000
  81 #define GREEN_MASK 0xff00
  82 #define BLUE_MASK 0xff
  83 #define ALPHA_SHIFT 24
  84 #define RED_SHIFT 16
  85 #define GREEN_SHIFT 8
  86 
  87 
  88 typedef HRESULT(__stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme);
  89 
  90 typedef HRESULT(__stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc,
  91         int iPartId, int iStateId, const RECT *pRect,  const RECT *pClipRect);
  92 
  93 typedef HTHEME(__stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList);
  94 
  95 typedef HRESULT (__stdcall *PFNDRAWTHEMETEXT)(HTHEME hTheme, HDC hdc,
  96           int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
  97           DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect);


 743         jobject dimObj = env->NewObject(dimClassID, dimMID, point.x, point.y);
 744 
 745         if (safe_ExceptionOccurred(env)) {
 746             env->ExceptionDescribe();
 747             env->ExceptionClear();
 748         }
 749 
 750         return dimObj;
 751     }
 752     return NULL;
 753 }
 754 
 755 void rescale(SIZE *size) {
 756     HWND hWnd = ::GetDesktopWindow();
 757     HDC hDC = ::GetDC(hWnd);
 758     int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
 759     int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
 760 
 761     if (dpiX !=0 && dpiX != 96) {
 762         float invScaleX = 96.0f / dpiX;
 763         size->cx = ROUND_TO_INT(size->cx * invScaleX);
 764     }
 765     if (dpiY != 0 && dpiY != 96) {
 766         float invScaleY = 96.0f / dpiY;
 767         size->cy = ROUND_TO_INT(size->cy * invScaleY);
 768     }
 769     ::ReleaseDC(hWnd, hDC);
 770 }
 771 
 772 /*
 773  * Class:     sun_awt_windows_ThemeReader
 774  * Method:    getPartSize
 775  * Signature: (JII)Ljava/awt/Dimension;
 776  */
 777 JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getPartSize
 778 (JNIEnv *env, jclass klass, jlong theme, jint part, jint state) {
 779     if (theme != NULL) {
 780         SIZE size;
 781 
 782         if (SUCCEEDED(GetThemePartSize((HTHEME)theme, NULL, part, state,
 783            NULL, TS_TRUE, &size)) && (env->EnsureLocalCapacity(2) >= 0)) {
 784 
 785             static jmethodID dimMID = NULL;
 786             static jclass dimClassID = NULL;
 787             if (dimClassID == NULL) {


< prev index next >