< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Cursor.cpp

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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


 458  */
 459 
 460 /*
 461  * Class:     sun_awt_windows_WGlobalCursorManager
 462  * Method:    getCursorPos
 463  * Signature: (Ljava/awt/Point;)V
 464  */
 465 JNIEXPORT void JNICALL
 466 Java_sun_awt_windows_WGlobalCursorManager_getCursorPos(JNIEnv *env,
 467                                                        jobject,
 468                                                        jobject point)
 469 {
 470     TRY;
 471 
 472     POINT p;
 473     ::GetCursorPos(&p);
 474     HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTOPRIMARY);
 475     int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(monitor);
 476     Devices::InstanceAccess devices;
 477     AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
 478     int x = (device == NULL) ? p.x : device->ScaleDownX(p.x);
 479     int y = (device == NULL) ? p.y : device->ScaleDownY(p.y);
 480     env->SetIntField(point, AwtCursor::pointXID, x);
 481     env->SetIntField(point, AwtCursor::pointYID, y);
 482 
 483     CATCH_BAD_ALLOC;
 484 }
 485 
 486 struct GlobalSetCursorStruct {
 487     jobject cursor;
 488     jboolean u;
 489 };
 490 
 491 static void GlobalSetCursor(void* pStruct) {
 492     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 493     jobject cursor  = ((GlobalSetCursorStruct*)pStruct)->cursor;
 494     jboolean u      = ((GlobalSetCursorStruct*)pStruct)->u;
 495     jlong pData = env->GetLongField(cursor, AwtCursor::pDataID);
 496     AwtCursor *awtCursor = (AwtCursor *)jlong_to_ptr(pData);
 497 
 498     if (awtCursor == NULL) {
 499         awtCursor = AwtCursor::CreateSystemCursor(cursor);


   1 /*
   2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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


 458  */
 459 
 460 /*
 461  * Class:     sun_awt_windows_WGlobalCursorManager
 462  * Method:    getCursorPos
 463  * Signature: (Ljava/awt/Point;)V
 464  */
 465 JNIEXPORT void JNICALL
 466 Java_sun_awt_windows_WGlobalCursorManager_getCursorPos(JNIEnv *env,
 467                                                        jobject,
 468                                                        jobject point)
 469 {
 470     TRY;
 471 
 472     POINT p;
 473     ::GetCursorPos(&p);
 474     HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTOPRIMARY);
 475     int screen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(monitor);
 476     Devices::InstanceAccess devices;
 477     AwtWin32GraphicsDevice *device = devices->GetDevice(screen);
 478     int x = (device == NULL) ? p.x : device->ScaleDownAbsX(p.x);
 479     int y = (device == NULL) ? p.y : device->ScaleDownAbsY(p.y);
 480     env->SetIntField(point, AwtCursor::pointXID, x);
 481     env->SetIntField(point, AwtCursor::pointYID, y);
 482 
 483     CATCH_BAD_ALLOC;
 484 }
 485 
 486 struct GlobalSetCursorStruct {
 487     jobject cursor;
 488     jboolean u;
 489 };
 490 
 491 static void GlobalSetCursor(void* pStruct) {
 492     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 493     jobject cursor  = ((GlobalSetCursorStruct*)pStruct)->cursor;
 494     jboolean u      = ((GlobalSetCursorStruct*)pStruct)->u;
 495     jlong pData = env->GetLongField(cursor, AwtCursor::pDataID);
 496     AwtCursor *awtCursor = (AwtCursor *)jlong_to_ptr(pData);
 497 
 498     if (awtCursor == NULL) {
 499         awtCursor = AwtCursor::CreateSystemCursor(cursor);


< prev index next >