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 #if defined(_MSC_VER) && _MSC_VER >= 1800
41 # define ROUND_TO_INT(num) ((int) round(num))
42 #else
43 # define ROUND_TO_INT(num) ((int) floor((num) + 0.5))
44 #endif
45
46 // WDesktopProperties fields
47 jfieldID AwtDesktopProperties::pDataID = 0;
48 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
49 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
50 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
51 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
52 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
53 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
54
55 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
56 this->self = GetEnv()->NewGlobalRef(self);
57 GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
58 ptr_to_jlong(this) );
59 }
60
61 AwtDesktopProperties::~AwtDesktopProperties() {
62 GetEnv()->DeleteGlobalRef(self);
63 }
64
65 //
81 GetCaretParameters();
82 GetOtherParameters();
83 GetSoundEvents();
84 GetSystemProperties();
85 if (IS_WINXP) {
86 GetXPStyleProperties();
87 }
88 }
89
90 void getInvScale(float &invScaleX, float &invScaleY) {
91 HWND hWnd = ::GetDesktopWindow();
92 HDC hDC = ::GetDC(hWnd);
93 int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
94 int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
95 ::ReleaseDC(hWnd, hDC);
96 invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
97 invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
98 }
99
100 int rescale(int value, float invScale){
101 return invScale == 1.0f ? value : ROUND_TO_INT(value * invScale);
102 }
103
104 void AwtDesktopProperties::GetSystemProperties() {
105 HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
106
107 if (dc != NULL) {
108 try {
109 float invScaleX;
110 float invScaleY;
111 getInvScale(invScaleX, invScaleY);
112 SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"), 1.0f);
113 SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"), 1.0f);
114 SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"), 1.0f);
115 SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
116 SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"), 1.0f);
117 SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"), 1.0f);
118 SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"), 1.0f);
119 }
120 catch (std::bad_alloc&) {
121 DeleteDC(dc);
|