< prev index next >
src/java.desktop/windows/native/libawt/windows/awt_DnDDS.cpp
Print this page
rev 58018 : 8238575: DragSourceEvent.getLocation() returns wrong value on HiDPI screens (Windows)
Reviewed-by: XXX
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -280,11 +280,11 @@
}
dragSource->m_dwPerformedDropEffect = DROPEFFECT_NONE;
call_dSCddfinished(env, peer, res == DRAGDROP_S_DROP && effects != DROPEFFECT_NONE,
convertDROPEFFECTToActions(effects),
- dragSource->m_dragPoint.x, dragSource->m_dragPoint.y);
+ dragSource->m_dragPoint);
env->DeleteLocalRef(peer);
DASSERT(AwtDropTarget::IsCurrentDnDDataObject(dragSource));
AwtDropTarget::SetCurrentDnDDataObject(NULL);
@@ -647,12 +647,11 @@
::GetCursorPos(&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);
+ call_dSCmouseMoved(env, m_peer, m_actions, modifiers, dragPoint);
JNU_CHECK_EXCEPTION_RETURN(env, E_UNEXPECTED);
m_dragPoint = dragPoint;
}
if ((modifiers & JAVA_BUTTON_MASK) == 0) {
@@ -660,12 +659,11 @@
} else if (m_initmods == 0) {
m_initmods = modifiers;
} else if ((modifiers & JAVA_BUTTON_MASK) != (m_initmods & JAVA_BUTTON_MASK)) {
return DRAGDROP_S_CANCEL;
} else if (m_lastmods != modifiers) {
- call_dSCchanged(env, m_peer,
- m_actions, modifiers, dragPoint.x, dragPoint.y);
+ call_dSCchanged(env, m_peer, m_actions, modifiers, dragPoint);
m_bRestoreNodropCustomCursor = TRUE;
}
m_lastmods = modifiers;
@@ -724,17 +722,17 @@
int invalid = (dwEffect == DROPEFFECT_NONE);
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);
}
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);
m_enterpending = FALSE;
}
if (m_droptarget != NULL) {
@@ -1174,79 +1172,96 @@
pmedium->pUnkForRelease = (IUnknown *)NULL;
return S_OK;
}
+static void ScaleDown(POINT &pt) {
+ HMONITOR monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
+ int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(monitor);
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
+ if (device) {
+ pt.x = device->ScaleDownX(pt.x);
+ pt.y = device->ScaleDownY(pt.y);
+ }
+}
+
DECLARE_JAVA_CLASS(dSCClazz, "sun/awt/windows/WDragSourceContextPeer")
void
AwtDragSource::call_dSCenter(JNIEnv* env, jobject self, jint targetActions,
- jint modifiers, jint x, jint y) {
+ jint modifiers, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCenter, dSCClazz, "dragEnter", "(IIII)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCenter, targetActions, modifiers, x, y);
+ env->CallVoidMethod(self, dSCenter, targetActions, modifiers, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
void
AwtDragSource::call_dSCmotion(JNIEnv* env, jobject self, jint targetActions,
- jint modifiers, jint x, jint y) {
+ jint modifiers, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCmotion, dSCClazz, "dragMotion", "(IIII)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCmotion, targetActions, modifiers, x, y);
+ env->CallVoidMethod(self, dSCmotion, targetActions, modifiers, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
void
AwtDragSource::call_dSCchanged(JNIEnv* env, jobject self, jint targetActions,
- jint modifiers, jint x, jint y) {
+ jint modifiers, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCchanged, dSCClazz, "operationChanged",
"(IIII)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCchanged, targetActions, modifiers, x, y);
+ env->CallVoidMethod(self, dSCchanged, targetActions, modifiers, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
void
-AwtDragSource::call_dSCexit(JNIEnv* env, jobject self, jint x, jint y) {
+AwtDragSource::call_dSCexit(JNIEnv* env, jobject self, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCexit, dSCClazz, "dragExit", "(II)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCexit, x, y);
+ env->CallVoidMethod(self, dSCexit, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
void
AwtDragSource::call_dSCddfinished(JNIEnv* env, jobject self, jboolean success,
- jint operations, jint x, jint y) {
+ jint operations, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCddfinished, dSCClazz, "dragDropFinished", "(ZIII)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCddfinished, success, operations, x, y);
+ env->CallVoidMethod(self, dSCddfinished, success, operations, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
void
AwtDragSource::call_dSCmouseMoved(JNIEnv* env, jobject self, jint targetActions,
- jint modifiers, jint x, jint y) {
+ jint modifiers, POINT pt) {
+ ScaleDown(pt);
DECLARE_VOID_JAVA_METHOD(dSCmouseMoved, dSCClazz, "dragMouseMoved",
"(IIII)V");
DASSERT(!JNU_IsNull(env, self));
- env->CallVoidMethod(self, dSCmouseMoved, targetActions, modifiers, x, y);
+ env->CallVoidMethod(self, dSCmouseMoved, targetActions, modifiers, pt.x, pt.y);
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
< prev index next >