aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tarasov <anton.tarasov@jetbrains.com>2016-12-27 15:58:18 +0300
committerAnton Tarasov <anton.tarasov@jetbrains.com>2016-12-27 15:59:07 +0300
commit5d3f454b4209d4b8271020c92a13daca2012e6f4 (patch)
treec4df964a063b5f284a081840c45616c2daef2ab4 /src
parent5b7f4b73a3a22d7a336dc6811328176285b5ee05 (diff)
downloadjdk8u_jdk-5d3f454b4209d4b8271020c92a13daca2012e6f4.tar.gz
JRE-153 [hidpi] monitors bounds can overlap in multi-dpi envjb8u112-b645
Diffstat (limited to 'src')
-rw-r--r--src/share/classes/sun/awt/GlobalCursorManager.java5
-rw-r--r--src/share/classes/sun/swing/SwingUtilities2.java25
-rw-r--r--src/windows/native/sun/windows/MouseInfo.cpp12
-rw-r--r--src/windows/native/sun/windows/awt_Component.cpp71
-rw-r--r--src/windows/native/sun/windows/awt_Component.h4
-rw-r--r--src/windows/native/sun/windows/awt_Cursor.cpp1
-rw-r--r--src/windows/native/sun/windows/awt_DnDDS.cpp16
-rw-r--r--src/windows/native/sun/windows/awt_Robot.cpp13
-rw-r--r--src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp5
-rw-r--r--src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp52
-rw-r--r--src/windows/native/sun/windows/awt_Win32GraphicsDevice.h22
-rw-r--r--src/windows/native/sun/windows/awt_Window.cpp27
12 files changed, 155 insertions, 98 deletions
diff --git a/src/share/classes/sun/awt/GlobalCursorManager.java b/src/share/classes/sun/awt/GlobalCursorManager.java
index 89286db6c0..5337b1956e 100644
--- a/src/share/classes/sun/awt/GlobalCursorManager.java
+++ b/src/share/classes/sun/awt/GlobalCursorManager.java
@@ -25,8 +25,6 @@
package sun.awt;
-import sun.swing.SwingUtilities2;
-
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.InvocationEvent;
@@ -190,8 +188,7 @@ public abstract class GlobalCursorManager {
}
if (p != null) {
queryPos = new Point();
- getCursorPos(queryPos); // gets the pos in 1x scale
- queryPos.setLocation(SwingUtilities2.scalePoint(null, queryPos, comp));
+ getCursorPos(queryPos);
Component c = AWTAccessor.getContainerAccessor().
findComponentAt((Container) comp,
queryPos.x - p.x, queryPos.y - p.y, false);
diff --git a/src/share/classes/sun/swing/SwingUtilities2.java b/src/share/classes/sun/swing/SwingUtilities2.java
index 65331325d2..64e370016f 100644
--- a/src/share/classes/sun/swing/SwingUtilities2.java
+++ b/src/share/classes/sun/swing/SwingUtilities2.java
@@ -2090,29 +2090,4 @@ public class SwingUtilities2 {
public interface RepaintListener {
void repaintPerformed(JComponent c, int x, int y, int w, int h);
}
-
- /**
- * Scales a point, given in a scale of the source source component's graphics device,
- * into the destination component's graphics device scale.
- *
- * @param source the source component
- * @param p the point to scale
- * @param dest the destination component
- * @return the scaled point
- */
- public static Point scalePoint(Component source, Point p, Component dest) {
- double fromScaleX = 1.0f;
- double fromScaleY = 1.0f;
- double toScaleX = 1.0f;
- double toScaleY = 1.0f;
- if (source != null) {
- fromScaleX = source.getGraphicsConfiguration().getDefaultTransform().getScaleX();
- fromScaleY = source.getGraphicsConfiguration().getDefaultTransform().getScaleY();
- }
- if (dest != null) {
- toScaleX = dest.getGraphicsConfiguration().getDefaultTransform().getScaleX();
- toScaleY = dest.getGraphicsConfiguration().getDefaultTransform().getScaleY();
- }
- return new Point((int)(p.x * fromScaleX / toScaleX), (int)(p.y * fromScaleY / toScaleY));
- }
}
diff --git a/src/windows/native/sun/windows/MouseInfo.cpp b/src/windows/native/sun/windows/MouseInfo.cpp
index e43f6ea3f5..17e0769e95 100644
--- a/src/windows/native/sun/windows/MouseInfo.cpp
+++ b/src/windows/native/sun/windows/MouseInfo.cpp
@@ -85,6 +85,7 @@ Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls, j
POINT pt;
VERIFY(::GetCursorPos(&pt));
+ AwtWin32GraphicsDevice::ScaleDownDPoint(&pt);
if (pointClass == NULL) {
jclass pointClassLocal = env->FindClass("java/awt/Point");
DASSERT(pointClassLocal != NULL);
@@ -95,20 +96,13 @@ Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls, j
env->DeleteLocalRef(pointClassLocal);
}
- int screen = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
- Devices::InstanceAccess devices;
- AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
-
xID = env->GetFieldID(pointClass, "x", "I");
CHECK_NULL_RETURN(xID, (jint)0);
yID = env->GetFieldID(pointClass, "y", "I");
CHECK_NULL_RETURN(yID, (jint)0);
- int x = (device == NULL) ? pt.x : device->ScaleDownX(pt.x);
- int y = (device == NULL) ? pt.y : device->ScaleDownY(pt.y);
-
- env->SetIntField(point, xID, x);
- env->SetIntField(point, yID, y);
+ env->SetIntField(point, xID, pt.x);
+ env->SetIntField(point, yID, pt.y);
// Always return 0 on Windows: we assume there's always a
// virtual screen device used.
diff --git a/src/windows/native/sun/windows/awt_Component.cpp b/src/windows/native/sun/windows/awt_Component.cpp
index 762b9be3f9..832ccff981 100644
--- a/src/windows/native/sun/windows/awt_Component.cpp
+++ b/src/windows/native/sun/windows/awt_Component.cpp
@@ -45,6 +45,7 @@
#include "awt_Toolkit.h"
#include "awt_Window.h"
#include "awt_Win32GraphicsDevice.h"
+#include "awt_Win32GraphicsConfig.h"
#include "Hashtable.h"
#include "ComCtl32Util.h"
@@ -980,20 +981,12 @@ void AwtComponent::Reshape(int x, int y, int w, int h)
DTRACE_PRINTLN4("AwtComponent::Reshape from %d, %d, %d, %d", rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);
#endif
- int userW = w;
- int userH = h;
+ AwtWin32GraphicsDevice* device = AwtWin32GraphicsDevice::GetDeviceByBounds(RECT_BOUNDS(x, y, w, h), GetHWnd());
+ x = device->ScaleUpDX(x);
+ y = device->ScaleUpDY(y);
+ w = device->ScaleUpX(w);
+ h = device->ScaleUpY(h);
- // new location may fall into another device and therefor should be scaled in its coordinate space
- AwtWin32GraphicsDevice* device = AwtWin32GraphicsDevice::getDeviceByPoint(x, y);
- x = device != NULL ? device->ScaleUpX(x) : ScaleUpX(x);
- y = device != NULL ? device->ScaleUpX(y) : ScaleUpX(y);
-
- // until the window is moved we don't know its new scale, so leave the size in its current scale
- w = ScaleUpX(w);
- h = ScaleUpY(h);
-
- int sysW = w;
- int sysH = h;
AwtWindow* container = GetContainer();
AwtComponent* parent = GetParent();
@@ -1029,13 +1022,6 @@ void AwtComponent::Reshape(int x, int y, int w, int h)
* We should use SetWindowPlacement instead.
*/
SetWindowPos(GetHWnd(), 0, x, y, w, h, flags);
-
- // now recalculate size with the new window scale
- w = ScaleUpX(userW);
- h = ScaleUpY(userH);
- if (w != sysW || h != sysH) {
- SetWindowPos(GetHWnd(), 0, x, y, w, h, flags);
- }
}
}
@@ -4692,6 +4678,13 @@ int AwtComponent::ScaleUpX(int x) {
return device == NULL ? x : device->ScaleUpX(x);
}
+int AwtComponent::ScaleUpDX(int x) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? x : device->ScaleUpDX(x);
+}
+
int AwtComponent::ScaleUpY(int y) {
int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
Devices::InstanceAccess devices;
@@ -4699,6 +4692,13 @@ int AwtComponent::ScaleUpY(int y) {
return device == NULL ? y : device->ScaleUpY(y);
}
+int AwtComponent::ScaleUpDY(int y) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? y : device->ScaleUpDY(y);
+}
+
int AwtComponent::ScaleDownX(int x) {
int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
Devices::InstanceAccess devices;
@@ -4706,6 +4706,13 @@ int AwtComponent::ScaleDownX(int x) {
return device == NULL ? x : device->ScaleDownX(x);
}
+int AwtComponent::ScaleDownDX(int x) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? x : device->ScaleDownDX(x);
+}
+
int AwtComponent::ScaleDownY(int y) {
int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
Devices::InstanceAccess devices;
@@ -4713,6 +4720,13 @@ int AwtComponent::ScaleDownY(int y) {
return device == NULL ? y : device->ScaleDownY(y);
}
+int AwtComponent::ScaleDownDY(int y) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? y : device->ScaleDownDY(y);
+}
+
jintArray AwtComponent::CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha) {
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
@@ -5008,7 +5022,7 @@ void AwtComponent::SendMouseEvent(jint id, jlong when, jint x, jint y,
id, when, modifiers,
ScaleDownX(x + insets.left),
ScaleDownY(y + insets.top),
- ScaleDownX(xAbs), ScaleDownY(yAbs),
+ ScaleDownDX(xAbs), ScaleDownDY(yAbs),
clickCount, popupTrigger, button);
if (safe_ExceptionOccurred(env)) {
@@ -5066,15 +5080,16 @@ AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
}
jobject target = GetTarget(env);
DTRACE_PRINTLN("creating MWE in JNI");
-
+ DWORD curMousePos = ::GetMessagePos();
+ int xAbs = GET_X_LPARAM(curMousePos);
+ int yAbs = GET_Y_LPARAM(curMousePos);
jobject mouseWheelEvent = env->NewObject(mouseWheelEventCls,
mouseWheelEventConst,
target,
id, when, modifiers,
ScaleDownX(x + insets.left),
ScaleDownY(y + insets.top),
- ScaleDownX(0/*tav todo: xAbs*/),
- ScaleDownY(0/*tav todo: yAbs*/),
+ ScaleDownDX(xAbs), ScaleDownDY(yAbs),
clickCount, popupTrigger,
scrollType, scrollAmount,
roundedWheelRotation, preciseWheelRotation);
@@ -5584,8 +5599,8 @@ jobject AwtComponent::_GetLocationOnScreen(void *param)
RECT rect;
VERIFY(::GetWindowRect(p->GetHWnd(),&rect));
result = JNU_NewObjectByName(env, "java/awt/Point", "(II)V",
- p->ScaleDownX(rect.left),
- p->ScaleDownY(rect.top));
+ p->ScaleDownDX(rect.left),
+ p->ScaleDownDY(rect.top));
}
ret:
env->DeleteGlobalRef(self);
@@ -7173,8 +7188,8 @@ void AwtComponent::VerifyState()
target = parent;
}
- x = ScaleUpX(x);
- y = ScaleUpY(y);
+ x = ScaleUpDX(x);
+ y = ScaleUpDY(y);
width = ScaleUpX(width);
height = ScaleUpY(height);
diff --git a/src/windows/native/sun/windows/awt_Component.h b/src/windows/native/sun/windows/awt_Component.h
index 2f2a6d4134..3caf5085cd 100644
--- a/src/windows/native/sun/windows/awt_Component.h
+++ b/src/windows/native/sun/windows/awt_Component.h
@@ -724,6 +724,10 @@ public:
int ScaleUpY(int y);
int ScaleDownX(int x);
int ScaleDownY(int y);
+ int ScaleUpDX(int x);
+ int ScaleUpDY(int y);
+ int ScaleDownDX(int x);
+ int ScaleDownDY(int y);
protected:
static AwtComponent* GetComponentImpl(HWND hWnd);
diff --git a/src/windows/native/sun/windows/awt_Cursor.cpp b/src/windows/native/sun/windows/awt_Cursor.cpp
index 3cdf9d8d64..1dccd4815a 100644
--- a/src/windows/native/sun/windows/awt_Cursor.cpp
+++ b/src/windows/native/sun/windows/awt_Cursor.cpp
@@ -473,6 +473,7 @@ Java_sun_awt_windows_WGlobalCursorManager_getCursorPos(JNIEnv *env,
POINT p;
::GetCursorPos(&p);
+ AwtWin32GraphicsDevice::ScaleDownDPoint(&p);
env->SetIntField(point, AwtCursor::pointXID, (jint)p.x);
env->SetIntField(point, AwtCursor::pointYID, (jint)p.y);
diff --git a/src/windows/native/sun/windows/awt_DnDDS.cpp b/src/windows/native/sun/windows/awt_DnDDS.cpp
index 27999b6b55..7b8521bb46 100644
--- a/src/windows/native/sun/windows/awt_DnDDS.cpp
+++ b/src/windows/native/sun/windows/awt_DnDDS.cpp
@@ -263,6 +263,8 @@ void AwtDragSource::_DoDragDrop(void* param) {
AwtDropTarget::SetCurrentDnDDataObject(dragSource);
::GetCursorPos(&dragSource->m_dragPoint);
+ POINT dragPoint = {dragSource->m_dragPoint.x, dragSource->m_dragPoint.y};
+ AwtWin32GraphicsDevice::ScaleDownDPoint(&dragPoint);
dragSource->Signal();
@@ -279,7 +281,7 @@ void AwtDragSource::_DoDragDrop(void* param) {
call_dSCddfinished(env, peer, res == DRAGDROP_S_DROP && effects != DROPEFFECT_NONE,
convertDROPEFFECTToActions(effects),
- dragSource->m_dragPoint.x, dragSource->m_dragPoint.y);
+ dragPoint.x, dragPoint.y);
env->DeleteLocalRef(peer);
@@ -638,11 +640,13 @@ HRESULT __stdcall AwtDragSource::QueryContinueDrag(BOOL fEscapeKeyPressed, DWOR
POINT dragPoint;
::GetCursorPos(&dragPoint);
+ POINT _dragPoint = {dragPoint.x, dragPoint.y};
+ AwtWin32GraphicsDevice::ScaleDownDPoint(&_dragPoint);
if ( (dragPoint.x != m_dragPoint.x || dragPoint.y != m_dragPoint.y) &&
m_lastmods == modifiers) {//cannot move before cursor change
call_dSCmouseMoved(env, m_peer,
- m_actions, modifiers, dragPoint.x, dragPoint.y);
+ m_actions, modifiers, _dragPoint.x, _dragPoint.y);
JNU_CHECK_EXCEPTION_RETURN(env, E_UNEXPECTED);
m_dragPoint = dragPoint;
}
@@ -655,7 +659,7 @@ HRESULT __stdcall AwtDragSource::QueryContinueDrag(BOOL fEscapeKeyPressed, DWOR
return DRAGDROP_S_CANCEL;
} else if (m_lastmods != modifiers) {
call_dSCchanged(env, m_peer,
- m_actions, modifiers, dragPoint.x, dragPoint.y);
+ m_actions, modifiers, _dragPoint.x, _dragPoint.y);
m_bRestoreNodropCustomCursor = TRUE;
}
@@ -709,6 +713,8 @@ HRESULT __stdcall AwtDragSource::GiveFeedback(DWORD dwEffect) {
POINT curs;
::GetCursorPos(&curs);
+ POINT _curs = {curs.x, curs.y};
+ AwtWin32GraphicsDevice::ScaleDownDPoint(&_curs);
m_droptarget = ::WindowFromPoint(curs);
@@ -717,13 +723,13 @@ HRESULT __stdcall AwtDragSource::GiveFeedback(DWORD dwEffect) {
if (invalid) {
// Don't call dragExit if dragEnter and dragOver haven't been called.
if (!m_enterpending) {
- call_dSCexit(env, m_peer, curs.x, curs.y);
+ call_dSCexit(env, m_peer, _curs.x, _curs.y);
}
m_droptarget = (HWND)NULL;
m_enterpending = TRUE;
} else if (m_droptarget != NULL) {
(*(m_enterpending ? call_dSCenter : call_dSCmotion))
- (env, m_peer, m_actions, modifiers, curs.x, curs.y);
+ (env, m_peer, m_actions, modifiers, _curs.x, _curs.y);
m_enterpending = FALSE;
}
diff --git a/src/windows/native/sun/windows/awt_Robot.cpp b/src/windows/native/sun/windows/awt_Robot.cpp
index 0528148e23..88cb497c98 100644
--- a/src/windows/native/sun/windows/awt_Robot.cpp
+++ b/src/windows/native/sun/windows/awt_Robot.cpp
@@ -80,12 +80,9 @@ void AwtRobot::MouseMove( jint x, jint y)
(PVOID)newSpeed,
SPIF_SENDCHANGE);
- int primaryIndex = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
- Devices::InstanceAccess devices;
- AwtWin32GraphicsDevice *device = devices->GetDevice(primaryIndex);
-
- x = (device == NULL) ? x : device->ScaleUpX(x);
- y = (device == NULL) ? y : device->ScaleUpY(y);
+ AwtWin32GraphicsDevice *device = AwtWin32GraphicsDevice::GetDeviceByBounds(RECT_BOUNDS(x, y, 0, 0));
+ x = device == NULL ? x : device->ScaleUpDX(x);
+ y = device == NULL ? y : device->ScaleUpDY(y);
POINT curPos;
::GetCursorPos(&curPos);
@@ -236,8 +233,8 @@ void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray p
VERIFY(::BitBlt(hdcMem, 0, 0, width, height, hdcScreen, x, y,
SRCCOPY | CAPTUREBLT) != 0);
} else {
- int sX = (device == NULL) ? x : device->ScaleUpX(x);
- int sY = (device == NULL) ? y : device->ScaleUpY(y);
+ int sX = (device == NULL) ? x : device->ScaleUpDX(x);
+ int sY = (device == NULL) ? y : device->ScaleUpDY(y);
VERIFY(::StretchBlt(hdcMem, 0, 0, width, height,
hdcScreen, sX, sY, sWidth, sHeight,
SRCCOPY | CAPTUREBLT) != 0);
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp b/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp
index 205508a856..5e0e6ac358 100644
--- a/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp
+++ b/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp
@@ -84,8 +84,9 @@ RECT AwtWin32GraphicsConfig::getMonitorBounds(int screen)
AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
if (TRUE == MonitorBounds(AwtWin32GraphicsDevice::GetMonitor(screen), &rRW)) {
- int x = (device == NULL) ? rRW.left : device->ScaleDownX(rRW.left);
- int y = (device == NULL) ? rRW.top : device->ScaleDownY(rRW.top);
+ // don't scale xy to avoid overlapping of the multi-dpi-monitors bounds in the user space
+ int x = rRW.left;
+ int y = rRW.top;
int w = (device == NULL) ? rRW.right - rRW.left
: device->ScaleDownX(rRW.right - rRW.left);
int h = (device == NULL) ? rRW.bottom - rRW.top
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
index 36cab5745d..eddfb290ef 100644
--- a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
+++ b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
@@ -639,21 +639,63 @@ int AwtWin32GraphicsDevice::ScaleUpX(int x)
return (int)ceil(x * scaleX);
}
+// scale up the delta [x - device.x]
+int AwtWin32GraphicsDevice::ScaleUpDX(int x)
+{
+ RECT devBounds = AwtWin32GraphicsConfig::getMonitorBounds(screen);
+ return devBounds.left + (int)ceil((x - devBounds.left) * scaleX);
+}
+
int AwtWin32GraphicsDevice::ScaleUpY(int y)
{
return (int)ceil(y * scaleY);
}
+// scale up the delta [y - device.y]
+int AwtWin32GraphicsDevice::ScaleUpDY(int y)
+{
+ RECT devBounds = AwtWin32GraphicsConfig::getMonitorBounds(screen);
+ return devBounds.top + (int)ceil((y - devBounds.top) * scaleY);
+}
+
int AwtWin32GraphicsDevice::ScaleDownX(int x)
{
return (int)ceil(x / scaleX);
}
+// scale down the delta [x - device.x]
+int AwtWin32GraphicsDevice::ScaleDownDX(int x)
+{
+ RECT devBounds = AwtWin32GraphicsConfig::getMonitorBounds(screen);
+ return devBounds.left + (int)ceil((x - devBounds.left) / scaleX);
+}
+
int AwtWin32GraphicsDevice::ScaleDownY(int y)
{
return (int)ceil(y / scaleY);
}
+// scale down the delta [y - device.y]
+int AwtWin32GraphicsDevice::ScaleDownDY(int y)
+{
+ RECT devBounds = AwtWin32GraphicsConfig::getMonitorBounds(screen);
+ return devBounds.top + (int)ceil((y - devBounds.top) / scaleY);
+}
+
+// scale down the delta [pt.xy - device.xy]
+void AwtWin32GraphicsDevice::ScaleDownDPoint(POINT *pt)
+{
+ HMONITOR hmon = ::MonitorFromPoint(*pt, MONITOR_DEFAULTTONEAREST);
+ DASSERT(hmon != NULL);
+ int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hmon);
+ DASSERT(screen > -1);
+
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ pt->x = device == NULL ? pt->x : device->ScaleDownDX(pt->x);
+ pt->y = device == NULL ? pt->y : device->ScaleDownDY(pt->y);
+}
+
void AwtWin32GraphicsDevice::InitDesktopScales(bool fractionalScaleEnabled)
{
unsigned x = 0;
@@ -943,18 +985,18 @@ BOOL AwtWin32GraphicsDevice::IsUiScaleEnabled()
return (BOOL)env->CallStaticBooleanMethod(cls, isUIScaleEnabledID);
}
-AwtWin32GraphicsDevice* AwtWin32GraphicsDevice::getDeviceByPoint(int x, int y) // xy in user space
+AwtWin32GraphicsDevice* AwtWin32GraphicsDevice::GetDeviceByBounds(RECT_BOUNDS bounds, HWND hwnd) // bounds in user space
{
Devices::InstanceAccess devices;
+ POINT center = {bounds.x + bounds.width / 2, bounds.y + bounds.height / 2};
for (int i = 0; i < devices->GetNumDevices(); i++) {
RECT rect = AwtWin32GraphicsConfig::getMonitorBounds(i); // rect in user space
- POINT pt = {x, y};
-
- if (::PtInRect(&rect, pt)) {
+ if (::PtInRect(&rect, center)) {
return devices->GetDevice(i);
}
}
- return NULL;
+ // default to the hwnd's device
+ return hwnd != NULL ? devices->GetDevice(AwtWin32GraphicsDevice::DeviceIndexForWindow(hwnd)) : NULL;
}
const DWORD REQUIRED_FLAGS = ( //Flags which must be set in
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
index b05e70a8a0..a391bf3d5c 100644
--- a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
+++ b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
@@ -34,6 +34,14 @@ extern "C" {
#include "awt_Palette.h"
#include "Devices.h"
+struct RECT_BOUNDS {
+ int x;
+ int y;
+ int width;
+ int height;
+ RECT_BOUNDS(int _x, int _y, int _w, int _h) : x(_x), y(_y), width(_w), height(_h) {}
+};
+
class AwtPalette;
class Devices;
@@ -74,7 +82,12 @@ public:
int ScaleUpY(int y);
int ScaleDownX(int x);
int ScaleDownY(int y);
+ int ScaleUpDX(int x);
+ int ScaleUpDY(int y);
+ int ScaleDownDX(int x);
+ int ScaleDownDY(int y);
+ static void ScaleDownDPoint(POINT *pt);
static int DeviceIndexForWindow(HWND hWnd);
static jobject GetColorModel(JNIEnv *env, jboolean dynamic,
int deviceIndex);
@@ -94,7 +107,14 @@ public:
static HDC GetDCFromScreen(int screen);
static int GetScreenFromHMONITOR(HMONITOR mon);
static BOOL IsUiScaleEnabled(); // if not, be dpi-unaware (backward compatible behaviour)
- static AwtWin32GraphicsDevice* getDeviceByPoint(int x, int y); // xy in user space
+ static AwtWin32GraphicsDevice* GetDeviceByBounds(RECT_BOUNDS bounds , HWND hwnd = NULL); // bounds in user space
+
+ inline static RECT_BOUNDS GetWindowRect(HWND hwnd)
+ {
+ RECT r;
+ ::GetWindowRect(hwnd, &r);
+ return RECT_BOUNDS(r.left, r.top, r.right - r.left, r.bottom - r.top);
+ }
static int primaryIndex;
static BOOL primaryPalettized;
diff --git a/src/windows/native/sun/windows/awt_Window.cpp b/src/windows/native/sun/windows/awt_Window.cpp
index 629d603432..152194a337 100644
--- a/src/windows/native/sun/windows/awt_Window.cpp
+++ b/src/windows/native/sun/windows/awt_Window.cpp
@@ -935,6 +935,10 @@ MsgRouting AwtWindow::WmTimer(UINT_PTR timerID)
}
MsgRouting AwtWindow::WmDPIChanged(UINT xDPI, UINT yDPI, RECT* bounds) {
+ if (!::IsWindowVisible(GetHWnd())) {
+ // may diverge with Component::Reshape in this state
+ return mrDoDefault;
+ }
::SetWindowPos(GetHWnd(), NULL,
bounds->left, bounds->top,
bounds->right - bounds->left, bounds->bottom - bounds->top,
@@ -1740,13 +1744,13 @@ MsgRouting AwtWindow::WmMove(int x, int y)
jobject peer = GetPeer(env);
jobject target = env->GetObjectField(peer, AwtObject::targetID);
- RECT rect;
- ::GetWindowRect(GetHWnd(), &rect);
+ RECT_BOUNDS rect = AwtWin32GraphicsDevice::GetWindowRect(GetHWnd());
+ AwtWin32GraphicsDevice* device = AwtWin32GraphicsDevice::GetDeviceByBounds(rect, GetHWnd());
- (env)->SetIntField(target, AwtComponent::xID, ScaleDownX(rect.left));
- (env)->SetIntField(target, AwtComponent::yID, ScaleDownY(rect.top));
- (env)->SetIntField(peer, AwtWindow::sysXID, ScaleDownX(rect.left));
- (env)->SetIntField(peer, AwtWindow::sysYID, ScaleDownY(rect.top));
+ (env)->SetIntField(target, AwtComponent::xID, device->ScaleDownDX(rect.x));
+ (env)->SetIntField(target, AwtComponent::yID, device->ScaleDownDY(rect.y));
+ (env)->SetIntField(peer, AwtWindow::sysXID, rect.x);
+ (env)->SetIntField(peer, AwtWindow::sysYID, rect.y);
SendComponentEvent(java_awt_event_ComponentEvent_COMPONENT_MOVED);
env->DeleteLocalRef(target);
@@ -1810,13 +1814,14 @@ MsgRouting AwtWindow::WmSize(UINT type, int w, int h)
BOOL insetsChanged = UpdateInsets(NULL);
int newWidth = w + m_insets.left + m_insets.right;
int newHeight = h + m_insets.top + m_insets.bottom;
-
- (env)->SetIntField(target, AwtComponent::widthID, ScaleDownX(newWidth));
- (env)->SetIntField(target, AwtComponent::heightID, ScaleDownY(newHeight));
+ RECT_BOUNDS rect = AwtWin32GraphicsDevice::GetWindowRect(GetHWnd());
+ AwtWin32GraphicsDevice* device = AwtWin32GraphicsDevice::GetDeviceByBounds(rect, GetHWnd());
+ (env)->SetIntField(target, AwtComponent::widthID, device->ScaleDownX(newWidth));
+ (env)->SetIntField(target, AwtComponent::heightID, device->ScaleDownY(newHeight));
jobject peer = GetPeer(env);
- (env)->SetIntField(peer, AwtWindow::sysWID, ScaleDownX(newWidth));
- (env)->SetIntField(peer, AwtWindow::sysHID, ScaleDownY(newHeight));
+ (env)->SetIntField(peer, AwtWindow::sysWID, newWidth);
+ (env)->SetIntField(peer, AwtWindow::sysHID, newHeight);
if (!AwtWindow::IsResizing()) {
WindowResized();