< prev index next >

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

Print this page




  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 "awt.h"
  27 #include "mmsystem.h"
  28 #include "jlong.h"
  29 #include "awt_DesktopProperties.h"
  30 #include "awt_Toolkit.h"
  31 #include "sun_awt_windows_WDesktopProperties.h"
  32 #include "java_awt_Font.h"
  33 #include "awtmsg.h"
  34 #include "zmouse.h"
  35 #include <shellapi.h>
  36 #include <shlobj.h>
  37 
  38 #include "math.h"
  39 


  40 // WDesktopProperties fields
  41 jfieldID AwtDesktopProperties::pDataID = 0;
  42 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
  43 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
  44 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
  45 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
  46 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
  47 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
  48 
  49 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
  50     this->self = GetEnv()->NewGlobalRef(self);
  51     GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
  52                             ptr_to_jlong(this) );
  53 }
  54 
  55 AwtDesktopProperties::~AwtDesktopProperties() {
  56     GetEnv()->DeleteGlobalRef(self);
  57 }
  58 
  59 //


  75     GetCaretParameters();
  76     GetOtherParameters();
  77     GetSoundEvents();
  78     GetSystemProperties();
  79     if (IS_WINXP) {
  80         GetXPStyleProperties();
  81     }
  82 }
  83 
  84 void getInvScale(float &invScaleX, float &invScaleY) {
  85     HWND hWnd = ::GetDesktopWindow();
  86     HDC hDC = ::GetDC(hWnd);
  87     int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
  88     int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
  89     ::ReleaseDC(hWnd, hDC);
  90     invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
  91     invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
  92 }
  93 
  94 int rescale(int value, float invScale){
  95     return invScale == 1.0f ? value : (int)round(value * invScale);
  96 }
  97 
  98 void AwtDesktopProperties::GetSystemProperties() {
  99     HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
 100 
 101     if (dc != NULL) {
 102         try {
 103             float invScaleX;
 104             float invScaleY;
 105             getInvScale(invScaleX, invScaleY);
 106             SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"), 1.0f);
 107             SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"), 1.0f);
 108             SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"), 1.0f);
 109             SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
 110             SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"), 1.0f);
 111             SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"), 1.0f);
 112             SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"), 1.0f);
 113         }
 114         catch (std::bad_alloc&) {
 115             DeleteDC(dc);




  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 "awt.h"
  27 #include "mmsystem.h"
  28 #include "jlong.h"
  29 #include "awt_DesktopProperties.h"
  30 #include "awt_Toolkit.h"
  31 #include "sun_awt_windows_WDesktopProperties.h"
  32 #include "java_awt_Font.h"
  33 #include "awtmsg.h"
  34 #include "zmouse.h"
  35 #include <shellapi.h>
  36 #include <shlobj.h>
  37 
  38 #include "math.h"
  39 
  40 #define ROUND_TO_INT(num)    ((int) floor((num) + 0.5))
  41 
  42 // WDesktopProperties fields
  43 jfieldID AwtDesktopProperties::pDataID = 0;
  44 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
  45 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
  46 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
  47 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
  48 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
  49 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
  50 
  51 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
  52     this->self = GetEnv()->NewGlobalRef(self);
  53     GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
  54                             ptr_to_jlong(this) );
  55 }
  56 
  57 AwtDesktopProperties::~AwtDesktopProperties() {
  58     GetEnv()->DeleteGlobalRef(self);
  59 }
  60 
  61 //


  77     GetCaretParameters();
  78     GetOtherParameters();
  79     GetSoundEvents();
  80     GetSystemProperties();
  81     if (IS_WINXP) {
  82         GetXPStyleProperties();
  83     }
  84 }
  85 
  86 void getInvScale(float &invScaleX, float &invScaleY) {
  87     HWND hWnd = ::GetDesktopWindow();
  88     HDC hDC = ::GetDC(hWnd);
  89     int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
  90     int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
  91     ::ReleaseDC(hWnd, hDC);
  92     invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
  93     invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
  94 }
  95 
  96 int rescale(int value, float invScale){
  97     return invScale == 1.0f ? value : ROUND_TO_INT(value * invScale);
  98 }
  99 
 100 void AwtDesktopProperties::GetSystemProperties() {
 101     HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
 102 
 103     if (dc != NULL) {
 104         try {
 105             float invScaleX;
 106             float invScaleY;
 107             getInvScale(invScaleX, invScaleY);
 108             SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"), 1.0f);
 109             SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"), 1.0f);
 110             SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"), 1.0f);
 111             SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
 112             SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"), 1.0f);
 113             SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"), 1.0f);
 114             SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"), 1.0f);
 115         }
 116         catch (std::bad_alloc&) {
 117             DeleteDC(dc);


< prev index next >