< prev index next >
src/windows/native/sun/windows/awt_DesktopProperties.cpp
Print this page
@@ -33,18 +33,10 @@
#include "awtmsg.h"
#include "zmouse.h"
#include <shellapi.h>
#include <shlobj.h>
-#include "math.h"
-
-#if defined(_MSC_VER) && _MSC_VER >= 1800
-# define ROUND_TO_INT(num) ((int) round(num))
-#else
-# define ROUND_TO_INT(num) ((int) floor((num) + 0.5))
-#endif
-
// WDesktopProperties fields
jfieldID AwtDesktopProperties::pDataID = 0;
jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
jmethodID AwtDesktopProperties::setStringPropertyID = 0;
@@ -85,39 +77,22 @@
if (IS_WINXP) {
GetXPStyleProperties();
}
}
-void getInvScale(float &invScaleX, float &invScaleY) {
- HWND hWnd = ::GetDesktopWindow();
- HDC hDC = ::GetDC(hWnd);
- int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
- int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
- ::ReleaseDC(hWnd, hDC);
- invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
- invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
-}
-
-int rescale(int value, float invScale){
- return invScale == 1.0f ? value : ROUND_TO_INT(value * invScale);
-}
-
void AwtDesktopProperties::GetSystemProperties() {
HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
if (dc != NULL) {
try {
- float invScaleX;
- float invScaleY;
- getInvScale(invScaleX, invScaleY);
- SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"), 1.0f);
- SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"), 1.0f);
- SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"), 1.0f);
- SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
- SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"), 1.0f);
- SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"), 1.0f);
- SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"), 1.0f);
+ SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
+ SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
+ SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
+ SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"));
+ SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
+ SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
+ SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
}
catch (std::bad_alloc&) {
DeleteDC(dc);
throw;
}
@@ -289,39 +264,35 @@
} else {
ncmetrics.cbSize = sizeof(ncmetrics);
}
VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
- float invScaleX;
- float invScaleY;
- getInvScale(invScaleX, invScaleY);
-
- SetFontProperty(TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont, invScaleY);
- SetIntegerProperty(TEXT("win.frame.captionHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
- SetIntegerProperty(TEXT("win.frame.captionButtonWidth"), rescale(ncmetrics.iCaptionWidth, invScaleX));
- SetIntegerProperty(TEXT("win.frame.captionButtonHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
- SetFontProperty(TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont, invScaleY);
- SetIntegerProperty(TEXT("win.frame.smallCaptionHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
- SetIntegerProperty(TEXT("win.frame.smallCaptionButtonWidth"), rescale(ncmetrics.iSmCaptionWidth, invScaleX));
- SetIntegerProperty(TEXT("win.frame.smallCaptionButtonHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
- SetIntegerProperty(TEXT("win.frame.sizingBorderWidth"), rescale(ncmetrics.iBorderWidth, invScaleX));
+ SetFontProperty( TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont );
+ SetIntegerProperty( TEXT("win.frame.captionHeight"), ncmetrics.iCaptionHeight );
+ SetIntegerProperty( TEXT("win.frame.captionButtonWidth"), ncmetrics.iCaptionWidth );
+ SetIntegerProperty( TEXT("win.frame.captionButtonHeight"), ncmetrics.iCaptionHeight );
+ SetFontProperty( TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont );
+ SetIntegerProperty( TEXT("win.frame.smallCaptionHeight"), ncmetrics.iSmCaptionHeight );
+ SetIntegerProperty( TEXT("win.frame.smallCaptionButtonWidth"), ncmetrics.iSmCaptionWidth );
+ SetIntegerProperty( TEXT("win.frame.smallCaptionButtonHeight"), ncmetrics.iSmCaptionHeight );
+ SetIntegerProperty( TEXT("win.frame.sizingBorderWidth"), ncmetrics.iBorderWidth );
// menu properties
- SetFontProperty(TEXT("win.menu.font"), ncmetrics.lfMenuFont, invScaleY);
- SetIntegerProperty(TEXT("win.menu.height"), rescale(ncmetrics.iMenuHeight, invScaleY));
- SetIntegerProperty(TEXT("win.menu.buttonWidth"), rescale(ncmetrics.iMenuWidth, invScaleX));
+ SetFontProperty( TEXT("win.menu.font"), ncmetrics.lfMenuFont );
+ SetIntegerProperty( TEXT("win.menu.height"), ncmetrics.iMenuHeight );
+ SetIntegerProperty( TEXT("win.menu.buttonWidth"), ncmetrics.iMenuWidth );
// scrollbar properties
- SetIntegerProperty(TEXT("win.scrollbar.width"), rescale(ncmetrics.iScrollWidth, invScaleX));
- SetIntegerProperty(TEXT("win.scrollbar.height"), rescale(ncmetrics.iScrollHeight, invScaleY));
+ SetIntegerProperty( TEXT("win.scrollbar.width"), ncmetrics.iScrollWidth );
+ SetIntegerProperty( TEXT("win.scrollbar.height"), ncmetrics.iScrollHeight );
// status bar and tooltip properties
- SetFontProperty(TEXT("win.status.font"), ncmetrics.lfStatusFont, invScaleY);
- SetFontProperty(TEXT("win.tooltip.font"), ncmetrics.lfStatusFont, invScaleY);
+ SetFontProperty( TEXT("win.status.font"), ncmetrics.lfStatusFont );
+ SetFontProperty( TEXT("win.tooltip.font"), ncmetrics.lfStatusFont );
// message box properties
- SetFontProperty(TEXT("win.messagebox.font"), ncmetrics.lfMessageFont, invScaleY);
+ SetFontProperty( TEXT("win.messagebox.font"), ncmetrics.lfMessageFont );
}
void AwtDesktopProperties::GetIconParameters() {
//
// icon properties
@@ -329,17 +300,14 @@
ICONMETRICS iconmetrics;
iconmetrics.cbSize = sizeof(iconmetrics);
VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
- float invScaleX;
- float invScaleY;
- getInvScale(invScaleX, invScaleY);
- SetIntegerProperty(TEXT("win.icon.hspacing"), rescale(iconmetrics.iHorzSpacing, invScaleX));
- SetIntegerProperty(TEXT("win.icon.vspacing"), rescale(iconmetrics.iVertSpacing, invScaleY));
+ SetIntegerProperty(TEXT("win.icon.hspacing"), iconmetrics.iHorzSpacing);
+ SetIntegerProperty(TEXT("win.icon.vspacing"), iconmetrics.iVertSpacing);
SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
- SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont, invScaleY);
+ SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont);
}
/*
Windows settings for these are also in the registry
They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
HKCU: HKEY_CURRENT_USER.
@@ -748,11 +716,10 @@
GetEnv()->DeleteLocalRef(jValue);
GetEnv()->DeleteLocalRef(key);
}
void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
-
jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self,
@@ -783,11 +750,11 @@
GetBValue(value));
GetEnv()->DeleteLocalRef(key);
}
void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
- LPCTSTR propName, float invScale) {
+ LPCTSTR propName) {
HGDIOBJ font = GetStockObject(fontID);
if (font != NULL && SelectObject(dc, font) != NULL) {
int length = GetTextFace(dc, 0, NULL);
if (length > 0) {
@@ -820,12 +787,12 @@
if (fontName == NULL) {
delete[] face;
throw std::bad_alloc();
}
- jint pointSize = rescale(metrics.tmHeight -
- metrics.tmInternalLeading, invScale);
+ jint pointSize = metrics.tmHeight -
+ metrics.tmInternalLeading;
jint style = java_awt_Font_PLAIN;
if (metrics.tmWeight >= FW_BOLD) {
style = java_awt_Font_BOLD;
}
@@ -849,12 +816,11 @@
delete[] face;
}
}
}
-void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font,
- float invScale) {
+void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) {
jstring fontName;
jint pointSize;
jint style;
fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
@@ -868,11 +834,11 @@
hdc = GetDC(NULL);
pointSize = (-font.lfHeight)*72/pixelsPerInch;
ReleaseDC(NULL, hdc);
#endif
// Java uses point sizes, but assumes 1 pixel = 1 point
- pointSize = rescale(-font.lfHeight, invScale);
+ pointSize = -font.lfHeight;
// convert Windows font style to Java style
style = java_awt_Font_PLAIN;
DTRACE_PRINTLN1("weight=%d", font.lfWeight);
if ( font.lfWeight >= FW_BOLD ) {
< prev index next >