8157163: AWT FileDialog does not inherit icon image from parent Frame
Reviewed-by: alexsch, serb
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java Mon May 30 10:50:32 2016 +0300
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WFileDialogPeer.java Mon May 30 11:08:27 2016 +0300
@@ -328,4 +328,7 @@
FileDialog fileDialog = (FileDialog)target;
return AWTAccessor.getFileDialogAccessor().isMultipleMode(fileDialog);
}
+
+ @Override
+ public native Point getLocationOnScreen();
}
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_FileDialog.cpp Mon May 30 10:50:32 2016 +0300
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_FileDialog.cpp Mon May 30 11:08:27 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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
@@ -107,6 +107,9 @@
}
break;
}
+ case WM_SETICON: {
+ return 0;
+ }
}
WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hWnd, NativeDialogWndProcProp));
@@ -140,6 +143,11 @@
::SendMessage(parent, WM_SETICON, (WPARAM)ICON_BIG,
(LPARAM)AwtToolkit::GetInstance().GetAwtIcon());
} else {
+ AwtWindow *awtWindow = (AwtWindow *)JNI_GET_PDATA(awtParent);
+ ::SendMessage(parent, WM_SETICON, (WPARAM)ICON_BIG,
+ (LPARAM)(awtWindow->GetHIcon()));
+ ::SendMessage(parent, WM_SETICON, (WPARAM)ICON_SMALL,
+ (LPARAM)(awtWindow->GetHIconSm()));
env->DeleteLocalRef(awtParent);
}
@@ -644,4 +652,72 @@
CATCH_BAD_ALLOC;
}
+int ScaleDownX(int x, HWND hwnd) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(hwnd);
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? x : device->ScaleDownX(x);
+}
+
+int ScaleDownY(int y, HWND hwnd) {
+ int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(hwnd);
+ Devices::InstanceAccess devices;
+ AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
+ return device == NULL ? y : device->ScaleDownY(y);
+}
+
+jobject AwtFileDialog::_GetLocationOnScreen(void *param)
+{
+ JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+
+ jobject result = NULL;
+ HWND hwnd = (HWND)env->GetLongField((jobject)param, AwtComponent::hwndID);
+
+ if (::IsWindow(hwnd))
+ {
+ RECT rect;
+ VERIFY(::GetWindowRect(hwnd, &rect));
+ result = JNU_NewObjectByName(env, "java/awt/Point", "(II)V",
+ ScaleDownX(rect.left, hwnd), ScaleDownY(rect.top, hwnd));
+ }
+
+ if (result != NULL)
+ {
+ jobject resultRef = env->NewGlobalRef(result);
+ env->DeleteLocalRef(result);
+ return resultRef;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*
+ * Class: sun_awt_windows_WFileDialogPeer
+ * Method: getLocationOnScreen
+ * Signature: ()Ljava/awt/Point;
+ */
+JNIEXPORT jobject JNICALL
+Java_sun_awt_windows_WFileDialogPeer_getLocationOnScreen(JNIEnv *env,
+ jobject peer) {
+ TRY;
+
+ jobject peerRef = env->NewGlobalRef(peer);
+ jobject resultRef = (jobject)AwtToolkit::GetInstance().SyncCall(
+ (void*(*)(void*))AwtFileDialog::_GetLocationOnScreen, (void *)peerRef);
+ env->DeleteLocalRef(peerRef);
+
+ if (resultRef != NULL)
+ {
+ jobject result = env->NewLocalRef(resultRef);
+ env->DeleteGlobalRef(resultRef);
+ return result;
+ }
+
+ return NULL;
+
+ CATCH_BAD_ALLOC_RET(NULL);
+}
+
} /* extern "C" */
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_FileDialog.h Mon May 30 10:50:32 2016 +0300
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_FileDialog.h Mon May 30 11:08:27 2016 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, 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
@@ -69,6 +69,7 @@
static void _DisposeOrHide(void *param);
static void _ToFront(void *param);
static void _ToBack(void *param);
+ static jobject _GetLocationOnScreen(void *param);
private:
static UINT GetBufferLength(LPTSTR buffer, UINT limit);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java Mon May 30 11:08:27 2016 +0300
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2016, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8157163
+ * @summary AWT FileDialog does not inherit icon image from parent Frame
+ * @requires os.family=="windows"
+ * @run main FileDialogIconTest
+ */
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.lang.reflect.InvocationTargetException;
+
+public class FileDialogIconTest {
+ private static Frame frame;
+ private static Dialog dialog;
+
+ public static void main(final String[] args) throws InterruptedException, InvocationTargetException, AWTException {
+ Robot robot;
+ Point p;
+ try {
+ frame = new Frame();
+ frame.setIconImage(createImage());
+ frame.setVisible(true);
+ robot = new Robot();
+ robot.waitForIdle();
+ robot.delay(200);
+
+ dialog = new FileDialog(frame, "Dialog");
+ dialog.setModal(false);
+ dialog.setVisible(true);
+ robot.waitForIdle();
+ robot.delay(200);
+
+ p = new Point(10, 10);
+ SwingUtilities.convertPointToScreen(p, dialog);
+ Color color = robot.getPixelColor(p.x, p.y);
+ if (!Color.RED.equals(color)) {
+ throw new RuntimeException("Dialog icon was not inherited from " +
+ "owning window. Wrong color: " + color);
+ }
+ } finally {
+ dialog.dispose();
+ frame.dispose();
+ }
+ }
+
+ private static Image createImage() {
+ BufferedImage image = new BufferedImage(64, 64,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics g = image.getGraphics();
+ g.setColor(Color.RED);
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());
+ g.dispose();
+ return image;
+ }
+
+}