< prev index next >

src/java.desktop/windows/native/libawt/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 // 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,


 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) {




  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,


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


< prev index next >