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


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


< prev index next >