< prev index next >

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

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX

@@ -601,11 +601,11 @@
     }
 
     /*
       * Fix for 4046446.
       */
-    SetWindowPos(GetHWnd(), 0, x, y, w, h, SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOACTIVATE);
+    Reshape(x, y, w, h);
 
     /* Set default colors. */
     m_colorForeground = colorForeground;
     m_colorBackground = colorBackground;
 

@@ -1085,10 +1085,11 @@
         WIN_MSG(WM_NULL)
         WIN_MSG(WM_CREATE)
         WIN_MSG(WM_DESTROY)
         WIN_MSG(WM_MOVE)
         WIN_MSG(WM_SIZE)
+        WIN_MSG(WM_DPICHANGED)
         WIN_MSG(WM_ACTIVATE)
         WIN_MSG(WM_SETFOCUS)
         WIN_MSG(WM_KILLFOCUS)
         WIN_MSG(WM_ENABLE)
         WIN_MSG(WM_SETREDRAW)

@@ -1503,13 +1504,13 @@
           break;
       }
       case WM_SIZE:
       {
           RECT r;
-          // fix 4128317 : use GetClientRect for full 32-bit int precision and
+          // fix 4128317 : use GetWindowRect for full 32-bit int precision and
           // to avoid negative client area dimensions overflowing 16-bit params - robi
-          ::GetClientRect( GetHWnd(), &r );
+          ::GetWindowRect(GetHWnd(), &r);
           mr = WmSize(static_cast<UINT>(wParam), r.right - r.left, r.bottom - r.top);
           //mr = WmSize(wParam, LOWORD(lParam), HIWORD(lParam));
           SetCompositionWindow(r);
           break;
       }

@@ -3886,12 +3887,12 @@
     if (!::IsWindowVisible(hWnd)) {
         return;
     }
     HWND hTop = GetTopLevelParentForWindow(hWnd);
     ::ClientToScreen(hTop, &p);
-    int sx = ScaleUpX(x) - p.x;
-    int sy = ScaleUpY(y) - p.y;
+    int sx = ScaleUpAbsX(x) - p.x;
+    int sy = ScaleUpAbsY(y) - p.y;
     if (!m_bitsCandType) {
         SetCandidateWindow(m_bitsCandType, sx, sy);
         return;
     }
     for (int iCandType=0; iCandType<32; iCandType++, bits<<=1) {

@@ -4765,38 +4766,75 @@
             ((BYTE*)(dest++))[3] = alpha;
         }
     }
 }
 
+int AwtComponent::GetScreenImOn() {
+    HWND hWindow = GetAncestor(GetHWnd(), GA_ROOT);
+    AwtComponent *comp = AwtComponent::GetComponent(hWindow);
+    if (comp && comp->IsTopLevel()) {
+        return comp->GetScreenImOn();
+    }
+    return AwtWin32GraphicsDevice::DeviceIndexForWindow(hWindow);
+}
+
 int AwtComponent::ScaleUpX(int x) {
-    int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+    int screen = GetScreenImOn();
     Devices::InstanceAccess devices;
     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
     return device == NULL ? x : device->ScaleUpX(x);
 }
 
+int AwtComponent::ScaleUpAbsX(int x) {
+    int screen = GetScreenImOn();
+    Devices::InstanceAccess devices;
+    AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+    return device == NULL ? x : device->ScaleUpAbsX(x);
+}
+
 int AwtComponent::ScaleUpY(int y) {
-    int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+    int screen = GetScreenImOn();
     Devices::InstanceAccess devices;
     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
     return device == NULL ? y : device->ScaleUpY(y);
 }
 
+int AwtComponent::ScaleUpAbsY(int y) {
+    int screen = GetScreenImOn();
+    Devices::InstanceAccess devices;
+    AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+    return device == NULL ? y : device->ScaleUpAbsY(y);
+}
+
 int AwtComponent::ScaleDownX(int x) {
-    int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+    int screen = GetScreenImOn();
     Devices::InstanceAccess devices;
     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
     return device == NULL ? x : device->ScaleDownX(x);
 }
 
+int AwtComponent::ScaleDownAbsX(int x) {
+    int screen = GetScreenImOn();
+    Devices::InstanceAccess devices;
+    AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+    return device == NULL ? x : device->ScaleDownAbsX(x);
+}
+
 int AwtComponent::ScaleDownY(int y) {
-    int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
+    int screen = GetScreenImOn();
     Devices::InstanceAccess devices;
     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
     return device == NULL ? y : device->ScaleDownY(y);
 }
 
+int AwtComponent::ScaleDownAbsY(int y) {
+    int screen = GetScreenImOn();
+    Devices::InstanceAccess devices;
+    AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+    return device == NULL ? y : device->ScaleDownAbsY(y);
+}
+
 jintArray AwtComponent::CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha) {
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     if (!::IsWindowVisible(GetHWnd())) {
         return NULL;

@@ -5088,11 +5126,11 @@
     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
                                         target,
                                         id, when, modifiers,
                                         ScaleDownX(x + insets.left),
                                         ScaleDownY(y + insets.top),
-                                        ScaleDownX(xAbs), ScaleDownY(yAbs),
+                                        ScaleDownAbsX(xAbs), ScaleDownAbsY(yAbs),
                                         clickCount, popupTrigger, button);
 
     if (safe_ExceptionOccurred(env)) {
         env->ExceptionDescribe();
         env->ExceptionClear();

@@ -5161,12 +5199,12 @@
                                              mouseWheelEventConst,
                                              target,
                                              id, when, modifiers,
                                              ScaleDownX(x + insets.left),
                                              ScaleDownY(y + insets.top),
-                                             ScaleDownX(xAbs),
-                                             ScaleDownY(yAbs),
+                                             ScaleDownAbsX(xAbs),
+                                             ScaleDownAbsY(yAbs),
                                              clickCount, popupTrigger,
                                              scrollType, scrollAmount,
                                              roundedWheelRotation, preciseWheelRotation);
 
     DASSERT(mouseWheelEvent != NULL);

@@ -5672,12 +5710,12 @@
     if (::IsWindow(p->GetHWnd()))
     {
         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->ScaleDownAbsX(rect.left),
+                                     p->ScaleDownAbsY(rect.top));
     }
 ret:
     env->DeleteGlobalRef(self);
 
     if (result != NULL)
< prev index next >