< prev index next >

src/windows/native/sun/windows/ThemeReader.cpp

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  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 #include "sun_awt_windows_ThemeReader.h"
  27 #include <string.h>
  28 
  29 #include "awt.h"
  30 #include "awt_Toolkit.h"
  31 #include "awt_Object.h"
  32 #include "awt_Component.h"
  33 
  34 #include "math.h"
  35 
  36 // Important note about VC6 and VC7 (or XP Platform SDK)   !
  37 //
  38 // These type definitions have been imported from UxTheme.h
  39 // They have been imported instead of including them, because
  40 // currently we don't require Platform SDK for building J2SE and
  41 // VC6 includes do not have UxTheme.h. When we move to VC7
  42 // we should remove these imports and just include
  43 //
  44 //  Uncomment these when we start using VC 7 (or XP Platform SDK)
  45 //
  46 //  #include <uxtheme.h>
  47 //  #incldue <tmschema.h>
  48 
  49 
  50 // Remove everyting inside this ifdef when we start using VC 7 (or XP Platform SDK)
  51 #ifndef  _UXTHEME_H_
  52 typedef HANDLE HTHEME;          // handle to a section of theme data for class
  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);


 735             CHECK_NULL_RETURN(dimClassIDLocal, NULL);
 736             dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
 737             env->DeleteLocalRef(dimClassIDLocal);
 738         }
 739         if (dimMID == NULL) {
 740             dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
 741             CHECK_NULL_RETURN(dimMID, NULL);
 742         }
 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) {
 788                 jclass dimClassIDLocal = env->FindClass("java/awt/Dimension");
 789                 CHECK_NULL_RETURN(dimClassIDLocal, NULL);
 790                 dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
 791                 env->DeleteLocalRef(dimClassIDLocal);
 792             }
 793             if (dimMID == NULL) {
 794                 dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
 795                 CHECK_NULL_RETURN(dimMID, NULL);
 796             }
 797 
 798             rescale(&size);
 799             jobject dimObj = env->NewObject(dimClassID, dimMID, size.cx, size.cy);
 800             if (safe_ExceptionOccurred(env)) {
 801                 env->ExceptionDescribe();
 802                 env->ExceptionClear();
 803             }
 804 
 805             return dimObj;
 806         }
 807     }
 808     return NULL;
 809 }
 810 
 811 /*
 812  * Class:     sun_awt_windows_ThemeReader
 813  * Method:    getThemeBackgroundContentMargins
 814  * Signature: (JIIII)Ljava/awt/Insets;
 815  */
 816 JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getThemeBackgroundContentMargins
 817 (JNIEnv *env, jclass klass, jlong hTheme, jint part, jint state,
 818 jint boundingWidth, jint boundingHeight) {




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  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 #include "sun_awt_windows_ThemeReader.h"
  27 #include <string.h>
  28 
  29 #include "awt.h"
  30 #include "awt_Toolkit.h"
  31 #include "awt_Object.h"
  32 #include "awt_Component.h"
  33 


  34 // Important note about VC6 and VC7 (or XP Platform SDK)   !
  35 //
  36 // These type definitions have been imported from UxTheme.h
  37 // They have been imported instead of including them, because
  38 // currently we don't require Platform SDK for building J2SE and
  39 // VC6 includes do not have UxTheme.h. When we move to VC7
  40 // we should remove these imports and just include
  41 //
  42 //  Uncomment these when we start using VC 7 (or XP Platform SDK)
  43 //
  44 //  #include <uxtheme.h>
  45 //  #incldue <tmschema.h>
  46 
  47 
  48 // Remove everyting inside this ifdef when we start using VC 7 (or XP Platform SDK)
  49 #ifndef  _UXTHEME_H_
  50 typedef HANDLE HTHEME;          // handle to a section of theme data for class
  51 
  52 typedef enum {
  53     TS_MIN,
  54     TS_TRUE,
  55     TS_DRAW
  56 } THEME_SIZE;
  57 
  58 
  59 // Remove these when we start using VC 7 (or XP Platform SDK)
  60 typedef struct _MARGINS
  61 {
  62     int cxLeftWidth;      // width of left border that retains its size
  63     int cxRightWidth;     // width of right border that retains its size
  64     int cyTopHeight;      // height of top border that retains its size
  65     int cyBottomHeight;   // height of bottom border that retains its size
  66 } MARGINS, *PMARGINS;
  67 
  68 #define TMT_TRANSPARENT 2201
  69 #endif // _UXTHEME_H_
  70 





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


 728             CHECK_NULL_RETURN(dimClassIDLocal, NULL);
 729             dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
 730             env->DeleteLocalRef(dimClassIDLocal);
 731         }
 732         if (dimMID == NULL) {
 733             dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
 734             CHECK_NULL_RETURN(dimMID, NULL);
 735         }
 736         jobject dimObj = env->NewObject(dimClassID, dimMID, point.x, point.y);
 737 
 738         if (safe_ExceptionOccurred(env)) {
 739             env->ExceptionDescribe();
 740             env->ExceptionClear();
 741         }
 742 
 743         return dimObj;
 744     }
 745     return NULL;
 746 }
 747 

















 748 /*
 749  * Class:     sun_awt_windows_ThemeReader
 750  * Method:    getPartSize
 751  * Signature: (JII)Ljava/awt/Dimension;
 752  */
 753 JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getPartSize
 754 (JNIEnv *env, jclass klass, jlong theme, jint part, jint state) {
 755     if (theme != NULL) {
 756         SIZE size;
 757 
 758         if (SUCCEEDED(GetThemePartSize((HTHEME)theme, NULL, part, state,
 759            NULL, TS_TRUE, &size)) && (env->EnsureLocalCapacity(2) >= 0)) {
 760 
 761             static jmethodID dimMID = NULL;
 762             static jclass dimClassID = NULL;
 763             if (dimClassID == NULL) {
 764                 jclass dimClassIDLocal = env->FindClass("java/awt/Dimension");
 765                 CHECK_NULL_RETURN(dimClassIDLocal, NULL);
 766                 dimClassID = (jclass)env->NewGlobalRef(dimClassIDLocal);
 767                 env->DeleteLocalRef(dimClassIDLocal);
 768             }
 769             if (dimMID == NULL) {
 770                 dimMID = env->GetMethodID(dimClassID, "<init>", "(II)V");
 771                 CHECK_NULL_RETURN(dimMID, NULL);
 772             }


 773             jobject dimObj = env->NewObject(dimClassID, dimMID, size.cx, size.cy);
 774             if (safe_ExceptionOccurred(env)) {
 775                 env->ExceptionDescribe();
 776                 env->ExceptionClear();
 777             }
 778 
 779             return dimObj;
 780         }
 781     }
 782     return NULL;
 783 }
 784 
 785 /*
 786  * Class:     sun_awt_windows_ThemeReader
 787  * Method:    getThemeBackgroundContentMargins
 788  * Signature: (JIIII)Ljava/awt/Insets;
 789  */
 790 JNIEXPORT jobject JNICALL Java_sun_awt_windows_ThemeReader_getThemeBackgroundContentMargins
 791 (JNIEnv *env, jclass klass, jlong hTheme, jint part, jint state,
 792 jint boundingWidth, jint boundingHeight) {


< prev index next >