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 "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 // WDesktopProperties fields
39 jfieldID AwtDesktopProperties::pDataID = 0;
40 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
41 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
42 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
43 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
44 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
45 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
46
47 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
48 this->self = GetEnv()->NewGlobalRef(self);
49 GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
50 ptr_to_jlong(this) );
51 }
52
53 AwtDesktopProperties::~AwtDesktopProperties() {
54 GetEnv()->DeleteGlobalRef(self);
55 }
56
57 //
62 if (GetEnv()->EnsureLocalCapacity(MAX_PROPERTIES) < 0) {
63 DASSERT(0);
64 return;
65 }
66 // this number defines the set of properties available, it is incremented
67 // whenever more properties are added (in a public release of course)
68 // for example, version 1 defines the properties available in Java SDK version 1.3.
69 SetIntegerProperty( TEXT("win.properties.version"), AWT_DESKTOP_PROPERTIES_VERSION);
70 GetNonClientParameters();
71 GetIconParameters();
72 GetColorParameters();
73 GetCaretParameters();
74 GetOtherParameters();
75 GetSoundEvents();
76 GetSystemProperties();
77 if (IS_WINXP) {
78 GetXPStyleProperties();
79 }
80 }
81
82 void AwtDesktopProperties::GetSystemProperties() {
83 HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
84
85 if (dc != NULL) {
86 try {
87 SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
88 SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
89 SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
90 SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"));
91 SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
92 SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
93 SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
94 }
95 catch (std::bad_alloc&) {
96 DeleteDC(dc);
97 throw;
98 }
99 DeleteDC(dc);
100 }
101 }
102
103
104 // Does the actual lookup for shell dialog font (MS Shell Dlg). fontName
105 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
106 // handle contains a reference toe the registry entry to look in.
107 // This will return NULL or a pointer to the resolved name.
108 // Note that it uses malloc() and returns the pointer to allocated
109 // memory, so remember to use free() when you are done with its
110 // result.
249 //
250 // general window properties
251 //
252 NONCLIENTMETRICS ncmetrics;
253
254 // Fix for 6944516: specify correct size for ncmetrics on WIN2K/XP
255 // Microsoft recommend to subtract the size of 'iPaddedBorderWidth' field
256 // when running on XP. However this can't be referenced at compile time
257 // with the older SDK, so there use 'lfMessageFont' plus its size.
258 if (!IS_WINVISTA) {
259 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
260 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
261 #else
262 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS,lfMessageFont) + sizeof(LOGFONT);
263 #endif
264 } else {
265 ncmetrics.cbSize = sizeof(ncmetrics);
266 }
267 VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
268
269 SetFontProperty( TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont );
270 SetIntegerProperty( TEXT("win.frame.captionHeight"), ncmetrics.iCaptionHeight );
271 SetIntegerProperty( TEXT("win.frame.captionButtonWidth"), ncmetrics.iCaptionWidth );
272 SetIntegerProperty( TEXT("win.frame.captionButtonHeight"), ncmetrics.iCaptionHeight );
273 SetFontProperty( TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont );
274 SetIntegerProperty( TEXT("win.frame.smallCaptionHeight"), ncmetrics.iSmCaptionHeight );
275 SetIntegerProperty( TEXT("win.frame.smallCaptionButtonWidth"), ncmetrics.iSmCaptionWidth );
276 SetIntegerProperty( TEXT("win.frame.smallCaptionButtonHeight"), ncmetrics.iSmCaptionHeight );
277 SetIntegerProperty( TEXT("win.frame.sizingBorderWidth"), ncmetrics.iBorderWidth );
278
279 // menu properties
280 SetFontProperty( TEXT("win.menu.font"), ncmetrics.lfMenuFont );
281 SetIntegerProperty( TEXT("win.menu.height"), ncmetrics.iMenuHeight );
282 SetIntegerProperty( TEXT("win.menu.buttonWidth"), ncmetrics.iMenuWidth );
283
284 // scrollbar properties
285 SetIntegerProperty( TEXT("win.scrollbar.width"), ncmetrics.iScrollWidth );
286 SetIntegerProperty( TEXT("win.scrollbar.height"), ncmetrics.iScrollHeight );
287
288 // status bar and tooltip properties
289 SetFontProperty( TEXT("win.status.font"), ncmetrics.lfStatusFont );
290 SetFontProperty( TEXT("win.tooltip.font"), ncmetrics.lfStatusFont );
291
292 // message box properties
293 SetFontProperty( TEXT("win.messagebox.font"), ncmetrics.lfMessageFont );
294 }
295
296 void AwtDesktopProperties::GetIconParameters() {
297 //
298 // icon properties
299 //
300 ICONMETRICS iconmetrics;
301
302 iconmetrics.cbSize = sizeof(iconmetrics);
303 VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
304
305 SetIntegerProperty(TEXT("win.icon.hspacing"), iconmetrics.iHorzSpacing);
306 SetIntegerProperty(TEXT("win.icon.vspacing"), iconmetrics.iVertSpacing);
307 SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
308 SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont);
309 }
310 /*
311 Windows settings for these are also in the registry
312 They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
313 HKCU: HKEY_CURRENT_USER.
314 HKCU\Control Panel\Desktop\FontSmoothing : "0=OFF", "2=ON"
315 HKCU\Control Panel\Desktop\FontSmoothingType: 1=Standard, 2=LCD
316 HKCU\Control Panel\Desktop\FontSmoothingGamma: 1000->2200
317 HKCU\Control Panel\Desktop\FontSmoothingOrientation: 0=BGR, 1=RGB
318
319 SystemParametersInfo supplies the first three of these but does not
320 however expose the Orientation. That has to come from the registry.
321
322 We go to some small lengths in here to not make queries we don't need.
323 Eg if we previously were using standard font smoothing and we still are
324 then its unlikely that any change in gamma will have occurred except
325 by a program which changed it, and even if it did, we don't need to pick
326 it up until someone turns on the LCD option.
327 To do: this loop is called once per top-level window so an app with
328 N windows will get notified N times. It would save us a small amount of
701 }
702
703 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
704 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
705 if (key == NULL) {
706 throw std::bad_alloc();
707 }
708 jstring jValue = JNU_NewStringPlatform(GetEnv(), value);
709 if (jValue == NULL) {
710 GetEnv()->DeleteLocalRef(key);
711 throw std::bad_alloc();
712 }
713 GetEnv()->CallVoidMethod(self,
714 AwtDesktopProperties::setStringPropertyID,
715 key, jValue);
716 GetEnv()->DeleteLocalRef(jValue);
717 GetEnv()->DeleteLocalRef(key);
718 }
719
720 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
721 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
722 if (key == NULL) {
723 throw std::bad_alloc();
724 }
725 GetEnv()->CallVoidMethod(self,
726 AwtDesktopProperties::setIntegerPropertyID,
727 key, (jint)value);
728 GetEnv()->DeleteLocalRef(key);
729 }
730
731 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
732 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
733 if (key == NULL) {
734 throw std::bad_alloc();
735 }
736 GetEnv()->CallVoidMethod(self,
737 AwtDesktopProperties::setBooleanPropertyID,
738 key, value ? JNI_TRUE : JNI_FALSE);
739 GetEnv()->DeleteLocalRef(key);
740 }
741
742 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
743 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
744 if (key == NULL) {
745 throw std::bad_alloc();
746 }
747 GetEnv()->CallVoidMethod(self,
748 AwtDesktopProperties::setColorPropertyID,
749 key, GetRValue(value), GetGValue(value),
750 GetBValue(value));
751 GetEnv()->DeleteLocalRef(key);
752 }
753
754 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
755 LPCTSTR propName) {
756 HGDIOBJ font = GetStockObject(fontID);
757 if (font != NULL && SelectObject(dc, font) != NULL) {
758 int length = GetTextFace(dc, 0, NULL);
759
760 if (length > 0) {
761 LPTSTR face = new TCHAR[length];
762
763 if (GetTextFace(dc, length, face) > 0) {
764 TEXTMETRIC metrics;
765
766 if (GetTextMetrics(dc, &metrics) > 0) {
767 jstring fontName = NULL;
768 if (!wcscmp(face, L"MS Shell Dlg")) {
769 // MS Shell Dlg is an indirect font name, find the
770 // real face name from the registry.
771 LPTSTR shellDialogFace = resolveShellDialogFont();
772 if (shellDialogFace != NULL) {
773 fontName = JNU_NewStringPlatform(GetEnv(),
774 shellDialogFace);
775 free(shellDialogFace);
776 }
777 else {
778 // Couldn't determine mapping for MS Shell Dlg,
779 // fall back to Microsoft Sans Serif
780 fontName = JNU_NewStringPlatform(GetEnv(),
781 L"Microsoft Sans Serif");
782 }
783 }
784 else {
785 fontName = JNU_NewStringPlatform(GetEnv(), face);
786 }
787 if (fontName == NULL) {
788 delete[] face;
789 throw std::bad_alloc();
790 }
791
792 jint pointSize = metrics.tmHeight -
793 metrics.tmInternalLeading;
794 jint style = java_awt_Font_PLAIN;
795
796 if (metrics.tmWeight >= FW_BOLD) {
797 style = java_awt_Font_BOLD;
798 }
799 if (metrics.tmItalic ) {
800 style |= java_awt_Font_ITALIC;
801 }
802
803 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
804 if (key == NULL) {
805 GetEnv()->DeleteLocalRef(fontName);
806 delete[] face;
807 throw std::bad_alloc();
808 }
809 GetEnv()->CallVoidMethod(self,
810 AwtDesktopProperties::setFontPropertyID,
811 key, fontName, style, pointSize);
812 GetEnv()->DeleteLocalRef(key);
813 GetEnv()->DeleteLocalRef(fontName);
814 }
815 }
816 delete[] face;
817 }
818 }
819 }
820
821 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) {
822 jstring fontName;
823 jint pointSize;
824 jint style;
825
826 fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
827 if (fontName == NULL) {
828 throw std::bad_alloc();
829 }
830 #if 0
831 HDC hdc;
832 int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
833 // convert font size specified in pixels to font size in points
834 hdc = GetDC(NULL);
835 pointSize = (-font.lfHeight)*72/pixelsPerInch;
836 ReleaseDC(NULL, hdc);
837 #endif
838 // Java uses point sizes, but assumes 1 pixel = 1 point
839 pointSize = -font.lfHeight;
840
841 // convert Windows font style to Java style
842 style = java_awt_Font_PLAIN;
843 DTRACE_PRINTLN1("weight=%d", font.lfWeight);
844 if ( font.lfWeight >= FW_BOLD ) {
845 style = java_awt_Font_BOLD;
846 }
847 if ( font.lfItalic ) {
848 style |= java_awt_Font_ITALIC;
849 }
850
851 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
852 if (key == NULL) {
853 GetEnv()->DeleteLocalRef(fontName);
854 throw std::bad_alloc();
855 }
856 GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
857 key, fontName, style, pointSize);
858 GetEnv()->DeleteLocalRef(key);
859 GetEnv()->DeleteLocalRef(fontName);
|
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 "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 //
64 if (GetEnv()->EnsureLocalCapacity(MAX_PROPERTIES) < 0) {
65 DASSERT(0);
66 return;
67 }
68 // this number defines the set of properties available, it is incremented
69 // whenever more properties are added (in a public release of course)
70 // for example, version 1 defines the properties available in Java SDK version 1.3.
71 SetIntegerProperty( TEXT("win.properties.version"), AWT_DESKTOP_PROPERTIES_VERSION);
72 GetNonClientParameters();
73 GetIconParameters();
74 GetColorParameters();
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"));
107 SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
108 SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
109 SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
110 SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
111 SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
112 SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
113 }
114 catch (std::bad_alloc&) {
115 DeleteDC(dc);
116 throw;
117 }
118 DeleteDC(dc);
119 }
120 }
121
122
123 // Does the actual lookup for shell dialog font (MS Shell Dlg). fontName
124 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
125 // handle contains a reference toe the registry entry to look in.
126 // This will return NULL or a pointer to the resolved name.
127 // Note that it uses malloc() and returns the pointer to allocated
128 // memory, so remember to use free() when you are done with its
129 // result.
268 //
269 // general window properties
270 //
271 NONCLIENTMETRICS ncmetrics;
272
273 // Fix for 6944516: specify correct size for ncmetrics on WIN2K/XP
274 // Microsoft recommend to subtract the size of 'iPaddedBorderWidth' field
275 // when running on XP. However this can't be referenced at compile time
276 // with the older SDK, so there use 'lfMessageFont' plus its size.
277 if (!IS_WINVISTA) {
278 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
279 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
280 #else
281 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS,lfMessageFont) + sizeof(LOGFONT);
282 #endif
283 } else {
284 ncmetrics.cbSize = sizeof(ncmetrics);
285 }
286 VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
287
288 float invScaleX;
289 float invScaleY;
290 getInvScale(invScaleX, invScaleY);
291
292 SetFontProperty(TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont, invScaleY);
293 SetIntegerProperty(TEXT("win.frame.captionHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
294 SetIntegerProperty(TEXT("win.frame.captionButtonWidth"), rescale(ncmetrics.iCaptionWidth, invScaleX));
295 SetIntegerProperty(TEXT("win.frame.captionButtonHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
296 SetFontProperty(TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont, invScaleY);
297 SetIntegerProperty(TEXT("win.frame.smallCaptionHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
298 SetIntegerProperty(TEXT("win.frame.smallCaptionButtonWidth"), rescale(ncmetrics.iSmCaptionWidth, invScaleX));
299 SetIntegerProperty(TEXT("win.frame.smallCaptionButtonHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
300 SetIntegerProperty(TEXT("win.frame.sizingBorderWidth"), rescale(ncmetrics.iBorderWidth, 1.0f / invScaleX));
301
302 // menu properties
303 SetFontProperty(TEXT("win.menu.font"), ncmetrics.lfMenuFont, invScaleY);
304 SetIntegerProperty(TEXT("win.menu.height"), rescale(ncmetrics.iMenuHeight, invScaleY));
305 SetIntegerProperty(TEXT("win.menu.buttonWidth"), rescale(ncmetrics.iMenuWidth, invScaleX));
306
307 // scrollbar properties
308 SetIntegerProperty(TEXT("win.scrollbar.width"), rescale(ncmetrics.iScrollWidth, invScaleX));
309 SetIntegerProperty(TEXT("win.scrollbar.height"), rescale(ncmetrics.iScrollHeight, invScaleY));
310
311 // status bar and tooltip properties
312 SetFontProperty(TEXT("win.status.font"), ncmetrics.lfStatusFont, invScaleY);
313 SetFontProperty(TEXT("win.tooltip.font"), ncmetrics.lfStatusFont, invScaleY);
314
315 // message box properties
316 SetFontProperty(TEXT("win.messagebox.font"), ncmetrics.lfMessageFont, invScaleY);
317 }
318
319 void AwtDesktopProperties::GetIconParameters() {
320 //
321 // icon properties
322 //
323 ICONMETRICS iconmetrics;
324
325 iconmetrics.cbSize = sizeof(iconmetrics);
326 VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
327
328 float invScaleX;
329 float invScaleY;
330 getInvScale(invScaleX, invScaleY);
331 SetIntegerProperty(TEXT("win.icon.hspacing"), rescale(iconmetrics.iHorzSpacing, invScaleX));
332 SetIntegerProperty(TEXT("win.icon.vspacing"), rescale(iconmetrics.iVertSpacing, invScaleY));
333 SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
334 SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont, invScaleY);
335 }
336 /*
337 Windows settings for these are also in the registry
338 They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
339 HKCU: HKEY_CURRENT_USER.
340 HKCU\Control Panel\Desktop\FontSmoothing : "0=OFF", "2=ON"
341 HKCU\Control Panel\Desktop\FontSmoothingType: 1=Standard, 2=LCD
342 HKCU\Control Panel\Desktop\FontSmoothingGamma: 1000->2200
343 HKCU\Control Panel\Desktop\FontSmoothingOrientation: 0=BGR, 1=RGB
344
345 SystemParametersInfo supplies the first three of these but does not
346 however expose the Orientation. That has to come from the registry.
347
348 We go to some small lengths in here to not make queries we don't need.
349 Eg if we previously were using standard font smoothing and we still are
350 then its unlikely that any change in gamma will have occurred except
351 by a program which changed it, and even if it did, we don't need to pick
352 it up until someone turns on the LCD option.
353 To do: this loop is called once per top-level window so an app with
354 N windows will get notified N times. It would save us a small amount of
727 }
728
729 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
730 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
731 if (key == NULL) {
732 throw std::bad_alloc();
733 }
734 jstring jValue = JNU_NewStringPlatform(GetEnv(), value);
735 if (jValue == NULL) {
736 GetEnv()->DeleteLocalRef(key);
737 throw std::bad_alloc();
738 }
739 GetEnv()->CallVoidMethod(self,
740 AwtDesktopProperties::setStringPropertyID,
741 key, jValue);
742 GetEnv()->DeleteLocalRef(jValue);
743 GetEnv()->DeleteLocalRef(key);
744 }
745
746 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
747
748 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
749 if (key == NULL) {
750 throw std::bad_alloc();
751 }
752 GetEnv()->CallVoidMethod(self,
753 AwtDesktopProperties::setIntegerPropertyID,
754 key, (jint)value);
755 GetEnv()->DeleteLocalRef(key);
756 }
757
758 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
759 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
760 if (key == NULL) {
761 throw std::bad_alloc();
762 }
763 GetEnv()->CallVoidMethod(self,
764 AwtDesktopProperties::setBooleanPropertyID,
765 key, value ? JNI_TRUE : JNI_FALSE);
766 GetEnv()->DeleteLocalRef(key);
767 }
768
769 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
770 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
771 if (key == NULL) {
772 throw std::bad_alloc();
773 }
774 GetEnv()->CallVoidMethod(self,
775 AwtDesktopProperties::setColorPropertyID,
776 key, GetRValue(value), GetGValue(value),
777 GetBValue(value));
778 GetEnv()->DeleteLocalRef(key);
779 }
780
781 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
782 LPCTSTR propName) {
783 AwtDesktopProperties::SetFontProperty(dc, fontID, propName, 1.0f);
784 }
785
786 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
787 LPCTSTR propName, float invScale) {
788 HGDIOBJ font = GetStockObject(fontID);
789 if (font != NULL && SelectObject(dc, font) != NULL) {
790 int length = GetTextFace(dc, 0, NULL);
791
792 if (length > 0) {
793 LPTSTR face = new TCHAR[length];
794
795 if (GetTextFace(dc, length, face) > 0) {
796 TEXTMETRIC metrics;
797
798 if (GetTextMetrics(dc, &metrics) > 0) {
799 jstring fontName = NULL;
800 if (!wcscmp(face, L"MS Shell Dlg")) {
801 // MS Shell Dlg is an indirect font name, find the
802 // real face name from the registry.
803 LPTSTR shellDialogFace = resolveShellDialogFont();
804 if (shellDialogFace != NULL) {
805 fontName = JNU_NewStringPlatform(GetEnv(),
806 shellDialogFace);
807 free(shellDialogFace);
808 }
809 else {
810 // Couldn't determine mapping for MS Shell Dlg,
811 // fall back to Microsoft Sans Serif
812 fontName = JNU_NewStringPlatform(GetEnv(),
813 L"Microsoft Sans Serif");
814 }
815 }
816 else {
817 fontName = JNU_NewStringPlatform(GetEnv(), face);
818 }
819 if (fontName == NULL) {
820 delete[] face;
821 throw std::bad_alloc();
822 }
823
824 jint pointSize = rescale(metrics.tmHeight -
825 metrics.tmInternalLeading, invScale);
826 jint style = java_awt_Font_PLAIN;
827
828 if (metrics.tmWeight >= FW_BOLD) {
829 style = java_awt_Font_BOLD;
830 }
831 if (metrics.tmItalic ) {
832 style |= java_awt_Font_ITALIC;
833 }
834
835 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
836 if (key == NULL) {
837 GetEnv()->DeleteLocalRef(fontName);
838 delete[] face;
839 throw std::bad_alloc();
840 }
841 GetEnv()->CallVoidMethod(self,
842 AwtDesktopProperties::setFontPropertyID,
843 key, fontName, style, pointSize);
844 GetEnv()->DeleteLocalRef(key);
845 GetEnv()->DeleteLocalRef(fontName);
846 }
847 }
848 delete[] face;
849 }
850 }
851 }
852
853 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) {
854 AwtDesktopProperties::SetFontProperty(propName, font, 1.0f);
855 }
856
857 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font,
858 float invScale) {
859 jstring fontName;
860 jint pointSize;
861 jint style;
862
863 fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
864 if (fontName == NULL) {
865 throw std::bad_alloc();
866 }
867 #if 0
868 HDC hdc;
869 int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
870 // convert font size specified in pixels to font size in points
871 hdc = GetDC(NULL);
872 pointSize = (-font.lfHeight)*72/pixelsPerInch;
873 ReleaseDC(NULL, hdc);
874 #endif
875 // Java uses point sizes, but assumes 1 pixel = 1 point
876 pointSize = rescale(-font.lfHeight, invScale);
877
878 // convert Windows font style to Java style
879 style = java_awt_Font_PLAIN;
880 DTRACE_PRINTLN1("weight=%d", font.lfWeight);
881 if ( font.lfWeight >= FW_BOLD ) {
882 style = java_awt_Font_BOLD;
883 }
884 if ( font.lfItalic ) {
885 style |= java_awt_Font_ITALIC;
886 }
887
888 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
889 if (key == NULL) {
890 GetEnv()->DeleteLocalRef(fontName);
891 throw std::bad_alloc();
892 }
893 GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
894 key, fontName, style, pointSize);
895 GetEnv()->DeleteLocalRef(key);
896 GetEnv()->DeleteLocalRef(fontName);
|