Bug 418245 - [SWT_AWT] Embedded SWT in AWT broken on Mac with Java 7

In Java 7 and later, AWT widgets are backed by CALayer and not NSView.
This makes it impossible to embed NSView-backed SWT widgets into AWT
widgets. Make the limitation clear by throwing ERROR_NOT_IMPLEMENTED.

Since JAWT is no longer used, don't link to JavaVM framework.

Change-Id: Ic9932cd726ed98887bd12501729e9dc4994ff291
Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
index ddb2e96..7a02052 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c
@@ -16,54 +16,8 @@
 #include "swt.h"
 #include "jawt_md.h"
 
-#ifdef __OBJC__
-#import <AppKit/NSView.h>
-#endif
-
 #define SWT_AWT_NATIVE(func) Java_org_eclipse_swt_awt_SWT_1AWT_##func
 
-/*
- * JAWT version 1.7 does not define the type JAWT_MacOSXDrawingSurfaceInfo.
- */
-#ifdef JAWT_VERSION_1_7
-// Legacy NSView-based rendering
-typedef struct JAWT_MacOSXDrawingSurfaceInfo {
-    NSView *cocoaViewRef; // the view is guaranteed to be valid only for the duration of Component.paint method
-}
-JAWT_MacOSXDrawingSurfaceInfo;
-#endif /* #ifdef JAWT_VERSION_1_7 */
-
-
-#ifndef NO_getAWTHandle
-JNIEXPORT jlong JNICALL SWT_AWT_NATIVE(getAWTHandle)
-	(JNIEnv *env, jclass that, jobject canvas)
-{
-	jlong result = 0;
-	JAWT awt;
-	JAWT_DrawingSurface* ds;
-	JAWT_DrawingSurfaceInfo* dsi;
-	JAWT_MacOSXDrawingSurfaceInfo* dsi_cocoa;
-	jint lock;
-
-	awt.version = JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER;
-	if (JAWT_GetAWT(env, &awt) != 0) {
-		ds = awt.GetDrawingSurface(env, canvas);
-		if (ds != NULL) {
-			lock = ds->Lock(ds);
-		 	if ((lock & JAWT_LOCK_ERROR) == 0) {
-			 	dsi = ds->GetDrawingSurfaceInfo(ds);
-				dsi_cocoa = (JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
-				result = (jlong)dsi_cocoa->cocoaViewRef;
-				ds->FreeDrawingSurfaceInfo(dsi);
-				ds->Unlock(ds);
-			}
-		}
-		awt.FreeDrawingSurface(ds);
-	}
-	return result;
-}
-#endif
-
 #ifndef NO_initFrame
 JNIEXPORT jobject JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_initFrame
 	(JNIEnv *env, jclass that, jlong handle, const char *className)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
index 4a5cb86..6c474f7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java
@@ -58,7 +58,6 @@
 
 	static boolean loaded, swingInitialized;
 
-	static native final long getAWTHandle (Canvas canvas);
 	static native final Object initFrame (long handle, String className);
 	static native final void validateWithBounds (Frame frame, int x, int y, int w, int h);
 	static native final void synthesizeWindowActivation (Frame frame, boolean doActivate);
@@ -67,15 +66,6 @@
 		if (loaded) return;
 		loaded = true;
 		Toolkit.getDefaultToolkit();
-		/*
-		 * Note that the jawt library is loaded explicitly
-		 * because it cannot be found by the library loader.
-		 * All exceptions are caught because the library may
-		 * have been loaded already.
-		 */
-		try {
-			System.loadLibrary("jawt");
-		} catch (Throwable e) {}
 		Library.loadLibrary("swt-awt");
 	}
 
@@ -311,30 +301,8 @@
 public static Shell new_Shell(final Display display, final Canvas parent) {
 	if (display == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
 	if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
-	long handle = 0;
-
-	try {
-		loadLibrary ();
-		handle = getAWTHandle (parent);
-	} catch (Throwable e) {
-		SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e);
-	}
-	if (handle == 0) SWT.error (SWT.ERROR_INVALID_ARGUMENT, null, " [peer not created]");
-
-	final Shell shell = Shell.cocoa_new (display, handle);
-	final ComponentListener listener = new ComponentAdapter () {
-		@Override
-		public void componentResized (ComponentEvent e) {
-			display.asyncExec (() -> {
-				if (shell.isDisposed()) return;
-				Dimension dim = parent.getSize ();
-				shell.setSize (dim.width, dim.height);
-			});
-		}
-	};
-	parent.addComponentListener(listener);
-	shell.addListener(SWT.Dispose, event -> parent.removeComponentListener(listener));
-	shell.setVisible (true);
-	return shell;
+	// Since Java 7, AWT widgets don't have a backing NSView, making embedding impossible
+	SWT.error(SWT.ERROR_NOT_IMPLEMENTED, null, "[Embedding SWT in AWT isn't supported on macOS]");
+	return null;
 }
 }
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/make_macosx.mak b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/make_macosx.mak
index 3a74d90..080c642 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/make_macosx.mak
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/make_macosx.mak
@@ -35,7 +35,7 @@
 	$(CFLAGS_JAVA_VM) \
 	-I /System/Library/Frameworks/Cocoa.framework/Headers \
 	-I /System/Library/Frameworks/JavaScriptCore.framework/Headers
-LFLAGS = -bundle $(ARCHS) -framework JavaVM -framework Cocoa -framework WebKit -framework CoreServices -framework JavaScriptCore -framework Security -framework SecurityInterface
+LFLAGS = -bundle $(ARCHS) -framework Cocoa -framework WebKit -framework CoreServices -framework JavaScriptCore -framework Security -framework SecurityInterface
 SWT_OBJECTS = swt.o c.o c_stats.o callback.o
 SWTPI_OBJECTS = swt.o os.o os_structs.o os_stats.o os_custom.o