diff options
author | Silenio Quarti <silenio> | 2003-08-19 16:13:46 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2003-08-19 16:13:46 +0000 |
commit | 269136c6e1817baa3820883adccd7cdf58ac909f (patch) | |
tree | a3a7643a3f9b61ea96a419a4e76cbfb57eb6f73c | |
parent | d97d0d107ca082c524d75941f35387a2d09cd378 (diff) | |
download | eclipse.platform.swt-269136c6e1817baa3820883adccd7cdf58ac909f.tar.gz eclipse.platform.swt-269136c6e1817baa3820883adccd7cdf58ac909f.tar.xz eclipse.platform.swt-269136c6e1817baa3820883adccd7cdf58ac909f.zip |
*** empty log message ***
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT AWT/motif/org/eclipse/swt/internal/awt/SWT_AWT.java | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/motif/org/eclipse/swt/internal/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/motif/org/eclipse/swt/internal/awt/SWT_AWT.java index fd0fc9cc0d..3cf54280bb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/motif/org/eclipse/swt/internal/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/motif/org/eclipse/swt/internal/awt/SWT_AWT.java @@ -6,27 +6,108 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporanew_FramePI and implementation *******************************************************************************/ package org.eclipse.swt.internal.awt; + +import java.lang.reflect.Constructor; -import java.awt.Canvas; -import java.awt.Frame; - -import org.eclipse.swt.SWT; +/* SWT Imports */ +import org.eclipse.swt.*; +import org.eclipse.swt.internal.Library; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Event; + +/* AWT Imports */ +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Canvas; +import java.awt.Frame; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; public class SWT_AWT { + static { + System.loadLibrary("jawt"); + Library.loadLibrary("swt-awt"); + } + +static native final int getAWTHandle (Canvas canvas); + public static Frame new_Frame (final Composite parent) { - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - return null; + int handle = parent.embeddedHandle; + /* + * Some JREs have implemented the embedded frame constructor to take an integer + * and other JREs take a long. To handle this binary incompatability, use + * reflection to create the embedded frame. + */ + Class clazz = null; + try { + clazz = Class.forName("sun.awt.X11.XEmbeddedFrame"); + } catch (Throwable e) { + SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e); + } + Constructor constructor = null; + try { + constructor = clazz.getConstructor (new Class [] {int.class}); + } catch (Throwable e1) { + try { + constructor = clazz.getConstructor (new Class [] {long.class}); + } catch (Throwable e2) { + SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e2); + } + } + Object value = null; + try { + value = constructor.newInstance (new Object [] {new Integer (handle)}); + } catch (Throwable e) { + SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e); + } + final Frame frame = (Frame) value; + parent.getShell ().addListener (SWT.Move, new Listener () { + public void handleEvent (Event e) { + EventQueue.invokeLater(new Runnable () { + public void run () { + frame.dispatchEvent (new ComponentEvent (frame, ComponentEvent.COMPONENT_MOVED)); + } + }); + } + }); + parent.addListener (SWT.Dispose, new Listener () { + public void handleEvent (Event event) { + parent.setVisible(false); + frame.dispose (); + } + }); + return frame; } public static Shell new_Shell (Display display, final Canvas parent) { - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - return null; + int handle = 0; + try { + handle = getAWTHandle (parent); + } catch (Throwable e) { + SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e); + } + if (handle == 0) SWT.error (SWT.ERROR_NOT_IMPLEMENTED); + + final Shell shell = Shell.motif_new (display, handle); + final Display newDisplay = shell.getDisplay (); + parent.addComponentListener(new ComponentAdapter () { + public void componentResized (ComponentEvent e) { + newDisplay.syncExec (new Runnable () { + public void run () { + Dimension dim = parent.getSize (); + shell.setSize (dim.width, dim.height); + } + }); + } + }); + shell.setVisible (true); + return shell; } } |