changeset 15382:0e34c2d67363

8148109: [SWT] Provide a supported mechanism to use EmbeddedFrame Reviewed-by: alanb, prr
author serb
date Sat, 20 Aug 2016 18:35:37 +0300
parents 82d35714476e
children e32729a8e1d8
files make/mapfiles/libawt/mapfile-mawt-vers make/mapfiles/libawt/mapfile-vers-linux make/mapfiles/libawt_xawt/mapfile-vers src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m src/java.desktop/macosx/native/libjawt/jawt.m src/java.desktop/share/native/include/jawt.h src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c src/java.desktop/unix/native/libjawt/jawt.c src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h src/java.desktop/windows/native/libjawt/jawt.cpp
diffstat 12 files changed, 245 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/make/mapfiles/libawt/mapfile-mawt-vers	Fri Aug 19 16:48:53 2016 +0400
+++ b/make/mapfiles/libawt/mapfile-mawt-vers	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2001, 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
@@ -238,6 +238,10 @@
 	        awt_GetDrawingSurface;
 	        awt_FreeDrawingSurface;
 	        awt_GetComponent;
+        awt_CreateEmbeddedFrame;
+        awt_SetBounds;
+        awt_SynthesizeWindowActivation;
+
 
 		X11SurfaceData_GetOps;
 		getDefaultConfig;
--- a/make/mapfiles/libawt/mapfile-vers-linux	Fri Aug 19 16:48:53 2016 +0400
+++ b/make/mapfiles/libawt/mapfile-vers-linux	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2002, 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
@@ -264,6 +264,10 @@
 	        awt_GetDrawingSurface;
 	        awt_FreeDrawingSurface;
 	        awt_GetComponent;
+        awt_CreateEmbeddedFrame;
+        awt_SetBounds;
+        awt_SynthesizeWindowActivation;
+
 
 		X11SurfaceData_GetOps;
 		getDefaultConfig;
--- a/make/mapfiles/libawt_xawt/mapfile-vers	Fri Aug 19 16:48:53 2016 +0400
+++ b/make/mapfiles/libawt_xawt/mapfile-vers	Sat Aug 20 18:35:37 2016 +0300
@@ -458,6 +458,9 @@
         awt_Unlock;
         awt_Lock;
         awt_GetComponent;
+        awt_CreateEmbeddedFrame;
+        awt_SetBounds;
+        awt_SynthesizeWindowActivation;
 
         #XAWT entry point for CDE
         Java_sun_awt_motif_XsessionWMcommand;
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -27,6 +27,8 @@
 
 #import "AWTSurfaceLayers.h"
 
+#import "jni_util.h"
+
 JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL awt_DrawingSurface_GetDrawingSurfaceInfo
 (JAWT_DrawingSurface* ds)
 {
@@ -130,3 +132,47 @@
     // TODO: implement
     return NULL;
 }
+
+// EmbeddedFrame support
+
+static char *const embeddedClassName = "sun/lwawt/macosx/CViewEmbeddedFrame";
+
+JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame
+(JNIEnv* env, void* platformInfo)
+{
+    static jmethodID mid = NULL;
+    static jclass cls;
+    if (mid == NULL) {
+        cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL_RETURN(cls, NULL);
+        mid = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
+        CHECK_NULL_RETURN(mid, NULL);
+    }
+    return (*env)->NewObject(env, cls, mid, platformInfo);
+}
+
+JNIEXPORT void JNICALL awt_SetBounds
+(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL(cls);
+        mid = (*env)->GetMethodID(env, cls, "setBoundsPrivate", "(IIII)V");
+        CHECK_NULL(mid);
+    }
+    (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h);
+}
+
+JNIEXPORT void JNICALL awt_SynthesizeWindowActivation
+(JNIEnv *env, jobject embeddedFrame, jboolean doActivate)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL(cls);
+        mid = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
+        CHECK_NULL(mid);
+    }
+    (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate);
+}
--- a/src/java.desktop/macosx/native/libjawt/jawt.m	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/macosx/native/libjawt/jawt.m	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -46,8 +46,9 @@
         return JNI_FALSE;
     }
 
-    if (awt->version != (JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER) &&
-        awt->version != JAWT_VERSION_1_7)
+    if (awt->version != (JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER)
+        && awt->version != JAWT_VERSION_1_7
+        && awt->version != JAWT_VERSION_9)
     {
         return JNI_FALSE;
     }
@@ -58,6 +59,11 @@
         awt->Lock = awt_Lock;
         awt->Unlock = awt_Unlock;
         awt->GetComponent = awt_GetComponent;
+        if (awt->version >= JAWT_VERSION_9) {
+            awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame;
+            awt->SetBounds = awt_SetBounds;
+            awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation;
+        }
     }
 
     return JNI_TRUE;
--- a/src/java.desktop/share/native/include/jawt.h	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/share/native/include/jawt.h	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -33,7 +33,7 @@
 #endif
 
 /*
- * AWT native interface (new in JDK 1.3)
+ * AWT native interface.
  *
  * The AWT native interface allows a native C or C++ application a means
  * by which to access native structures in AWT.  This is to facilitate moving
@@ -279,6 +279,50 @@
      */
     jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
 
+    /**
+     * Since 9
+     * Creates a java.awt.Frame placed in a native container. Container is
+     * referenced by the native platform handle. For example on Windows this
+     * corresponds to an HWND. For other platforms, see the appropriate
+     * machine-dependent header file for a description. The reference returned
+     * by this function is a local reference that is only valid in this
+     * environment. This function returns a NULL reference if no frame could be
+     * created with matching platform information.
+     */
+    jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo);
+
+    /**
+     * Since 9
+     * Moves and resizes the embedded frame. The new location of the top-left
+     * corner is specified by x and y parameters relative to the native parent
+     * component. The new size is specified by width and height.
+     *
+     * The embedded frame should be created by CreateEmbeddedFrame() method, or
+     * this function will not have any effect.
+     *
+     * java.awt.Component.setLocation() and java.awt.Component.setBounds() for
+     * EmbeddedFrame really don't move it within the native parent. These
+     * methods always locate the embedded frame at (0, 0) for backward
+     * compatibility. To allow moving embedded frames this method was
+     * introduced, and it works just the same way as setLocation() and
+     * setBounds() for usual, non-embedded components.
+     *
+     * Using usual get/setLocation() and get/setBounds() together with this new
+     * method is not recommended.
+     */
+    void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame,
+            jint x, jint y, jint w, jint h);
+    /**
+     * Since 9
+     * Synthesize a native message to activate or deactivate an EmbeddedFrame
+     * window depending on the value of parameter doActivate, if "true"
+     * activates the window; otherwise, deactivates the window.
+     *
+     * The embedded frame should be created by CreateEmbeddedFrame() method, or
+     * this function will not have any effect.
+     */
+    void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env,
+            jobject embeddedFrame, jboolean doActivate);
 } JAWT;
 
 /*
@@ -291,6 +335,7 @@
 #define JAWT_VERSION_1_3 0x00010003
 #define JAWT_VERSION_1_4 0x00010004
 #define JAWT_VERSION_1_7 0x00010007
+#define JAWT_VERSION_9 0x00090000
 
 #ifdef __cplusplus
 } /* extern "C" */
--- a/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -28,7 +28,6 @@
 
 #include <jawt.h>
 #include <jni.h>
-#include <jni_util.h>
 
 _JNI_IMPORT_OR_EXPORT_ JAWT_DrawingSurface* JNICALL
     awt_GetDrawingSurface(JNIEnv* env, jobject target);
@@ -45,4 +44,14 @@
 _JNI_IMPORT_OR_EXPORT_ jobject JNICALL
     awt_GetComponent(JNIEnv* env, void* platformInfo);
 
+_JNI_IMPORT_OR_EXPORT_ jobject JNICALL
+    awt_CreateEmbeddedFrame(JNIEnv* env, void* platformInfo);
+
+_JNI_IMPORT_OR_EXPORT_ void JNICALL
+    awt_SetBounds(JNIEnv *env, jobject embeddedFrame, jint x, jint y,
+                  jint w, jint h);
+
+_JNI_IMPORT_OR_EXPORT_ void JNICALL
+    awt_SynthesizeWindowActivation(JNIEnv *env, jobject embeddedFrame,
+                                   jboolean doActivate);
 #endif /* !_AWT_DRAWING_SURFACE_H_ */
--- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c	Sat Aug 20 18:35:37 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
@@ -383,3 +383,48 @@
 
     return target;
 }
+
+// EmbeddedFrame support
+
+static char *const embeddedClassName = "sun/awt/X11/XEmbeddedFrame";
+
+JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame
+(JNIEnv* env, void* platformInfo)
+{
+    static jmethodID mid = NULL;
+    static jclass cls;
+    if (mid == NULL) {
+        cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL_RETURN(cls, NULL);
+        mid = (*env)->GetMethodID(env, cls, "<init>", "(JZ)V");
+        CHECK_NULL_RETURN(mid, NULL);
+    }
+    return (*env)->NewObject(env, cls, mid, platformInfo, JNI_TRUE);
+}
+
+
+JNIEXPORT void JNICALL awt_SetBounds
+(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL(cls);
+        mid = (*env)->GetMethodID(env, cls, "setBoundsPrivate", "(IIII)V");
+        CHECK_NULL(mid);
+    }
+    (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h);
+}
+
+JNIEXPORT void JNICALL awt_SynthesizeWindowActivation
+(JNIEnv *env, jobject embeddedFrame, jboolean doActivate)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = (*env)->FindClass(env, embeddedClassName);
+        CHECK_NULL(cls);
+        mid = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
+        CHECK_NULL(mid);
+    }
+    (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate);
+}
--- a/src/java.desktop/unix/native/libjawt/jawt.c	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/unix/native/libjawt/jawt.c	Sat Aug 20 18:35:37 2016 +0300
@@ -45,7 +45,8 @@
 
     if (awt->version != JAWT_VERSION_1_3
         && awt->version != JAWT_VERSION_1_4
-        && awt->version != JAWT_VERSION_1_7) {
+        && awt->version != JAWT_VERSION_1_7
+        && awt->version != JAWT_VERSION_9) {
         return JNI_FALSE;
     }
 
@@ -55,6 +56,11 @@
         awt->Lock = awt_Lock;
         awt->Unlock = awt_Unlock;
         awt->GetComponent = awt_GetComponent;
+        if (awt->version >= JAWT_VERSION_9) {
+            awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame;
+            awt->SetBounds = awt_SetBounds;
+            awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation;
+        }
     }
 
     return JNI_TRUE;
--- a/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2008, 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
@@ -272,3 +272,47 @@
 {
     // Do nothing on Windows
 }
+
+// EmbeddedFrame support
+
+static char *const embeddedClassName = "sun/awt/windows/WEmbeddedFrame";
+
+JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame
+(JNIEnv* env, void* platformInfo)
+{
+    static jmethodID mid = NULL;
+    static jclass cls;
+    if (mid == NULL) {
+        cls = env->FindClass(embeddedClassName);
+        CHECK_NULL_RETURN(cls, NULL);
+        mid = env->GetMethodID(cls, "<init>", "(J)V");
+        CHECK_NULL_RETURN(mid, NULL);
+    }
+    return env->NewObject(cls, mid, platformInfo);
+}
+
+JNIEXPORT void JNICALL awt_SetBounds
+(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = env->FindClass(embeddedClassName);
+        CHECK_NULL(cls);
+        mid = env->GetMethodID(cls, "setBoundsPrivate", "(IIII)V");
+        CHECK_NULL(mid);
+    }
+    env->CallVoidMethod(embeddedFrame, mid, x, y, w, h);
+}
+
+JNIEXPORT void JNICALL awt_SynthesizeWindowActivation
+(JNIEnv *env, jobject embeddedFrame, jboolean doActivate)
+{
+    static jmethodID mid = NULL;
+    if (mid == NULL) {
+        jclass cls = env->FindClass(embeddedClassName);
+        CHECK_NULL(cls);
+        mid = env->GetMethodID(cls, "synthesizeWindowActivation", "(Z)V");
+        CHECK_NULL(mid);
+    }
+    env->CallVoidMethod(embeddedFrame, mid, doActivate);
+}
--- a/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h	Sat Aug 20 18:35:37 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
@@ -162,6 +162,16 @@
     jobject JNICALL DSGetComponent(
         JNIEnv* env, void* platformInfo);
 
+    _JNI_IMPORT_OR_EXPORT_ jobject JNICALL
+        awt_CreateEmbeddedFrame(JNIEnv* env, void* platformInfo);
+
+    _JNI_IMPORT_OR_EXPORT_ void JNICALL
+        awt_SetBounds(JNIEnv *env, jobject embeddedFrame, jint x,
+                      jint y, jint w, jint h);
+
+    _JNI_IMPORT_OR_EXPORT_ void JNICALL
+        awt_SynthesizeWindowActivation(JNIEnv *env, jobject embeddedFrame,
+                                       jboolean doActivate);
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
--- a/src/java.desktop/windows/native/libjawt/jawt.cpp	Fri Aug 19 16:48:53 2016 +0400
+++ b/src/java.desktop/windows/native/libjawt/jawt.cpp	Sat Aug 20 18:35:37 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -46,7 +46,9 @@
     }
 
     if (awt->version != JAWT_VERSION_1_3
-        && awt->version != JAWT_VERSION_1_4) {
+        && awt->version != JAWT_VERSION_1_4
+        && awt->version != JAWT_VERSION_1_7
+        && awt->version != JAWT_VERSION_9) {
         return JNI_FALSE;
     }
 
@@ -56,6 +58,11 @@
         awt->Lock = DSLockAWT;
         awt->Unlock = DSUnlockAWT;
         awt->GetComponent = DSGetComponent;
+        if (awt->version >= JAWT_VERSION_9) {
+            awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame;
+            awt->SetBounds = awt_SetBounds;
+            awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation;
+        }
     }
 
     return JNI_TRUE;