diff options
author | Scott Kovatch <skovatch> | 2009-09-21 17:26:06 +0000 |
---|---|---|
committer | Scott Kovatch <skovatch> | 2009-09-21 17:26:06 +0000 |
commit | f735e96c5f274596870c6e7656dfa81cdc99b43a (patch) | |
tree | cde34b3c7e84b6454bffb2513fc158a015909539 /bundles/org.eclipse.swt/Eclipse SWT AWT | |
parent | 8e70a2fd959c494ba8bd65fbe0be155b1733c20f (diff) | |
download | eclipse.platform.swt-f735e96c5f274596870c6e7656dfa81cdc99b43a.tar.gz eclipse.platform.swt-f735e96c5f274596870c6e7656dfa81cdc99b43a.tar.xz eclipse.platform.swt-f735e96c5f274596870c6e7656dfa81cdc99b43a.zip |
246929 - Added SWT_AWT.new_Shell for Cocoa
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT AWT')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/library/swt_awt.c | 5 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT AWT/cocoa/org/eclipse/swt/awt/SWT_AWT.java | 313 |
2 files changed, 157 insertions, 161 deletions
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 1bb23d911c..dc8fcb261d 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 @@ -1,12 +1,15 @@ /******************************************************************************* * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2009 Adobe Systems Inc. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API + * Adobe Systems, Inc. - initial implementation *******************************************************************************/ #include "swt.h" 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 64cab44bee..35dc0d7710 100755 --- 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 @@ -11,20 +11,17 @@ *******************************************************************************/ package org.eclipse.swt.awt; +import java.awt.*; import java.awt.Canvas; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.Toolkit; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; +import java.awt.event.*; +import java.lang.reflect.*; -import org.eclipse.swt.SWT; -import org.eclipse.swt.internal.Library; +import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.cocoa.*; +import org.eclipse.swt.widgets.*; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; /** * This class provides a bridge between SWT and AWT, so that it @@ -36,27 +33,27 @@ import org.eclipse.swt.widgets.Shell; * @since 3.0 */ public class SWT_AWT { - + /** * The name of the embedded Frame class. The default class name * for the platform will be used if <code>null</code>. */ public static String embeddedFrameClass; - + /** * Key for looking up the embedded frame for a Composite using * getData(). */ static String EMBEDDED_FRAME_KEY = "org.eclipse.swt.awt.SWT_AWT.embeddedFrame"; - + static { System.setProperty("apple.awt.usingSWT", "true"); } - + static boolean loaded, swingInitialized; - + static native final int /*long*/ getAWTHandle (Canvas canvas); - + static synchronized void loadLibrary () { if (loaded) return; loaded = true; @@ -72,7 +69,7 @@ public class SWT_AWT { } catch (Throwable e) {} Library.loadLibrary("swt-awt"); } - + static synchronized void initializeSwing() { if (swingInitialized) return; swingInitialized = true; @@ -85,155 +82,151 @@ public class SWT_AWT { if (method != null) method.invoke(clazz, emptyObject); } catch (Throwable e) {} } - -/** - * Returns a <code>java.awt.Frame</code> which is the embedded frame - * associated with the specified composite. - * - * @param parent the parent <code>Composite</code> of the <code>java.awt.Frame</code> - * @return a <code>java.awt.Frame</code> the embedded frame or <code>null</code>. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * - * @since 3.2 - */ -public static Frame getFrame(Composite parent) { - if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if ((parent.getStyle() & SWT.EMBEDDED) == 0) return null; - return (Frame) parent.getData(EMBEDDED_FRAME_KEY); -} - -/** - * Creates a new <code>java.awt.Frame</code>. This frame is the root for - * the AWT components that will be embedded within the composite. In order - * for the embedding to succeed, the composite must have been created - * with the SWT.EMBEDDED style. - * <p> - * IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. - * When a lightweight component is added as a child of the embedded frame, - * the cursor does not change. In order to work around both these problems, it is - * strongly recommended that a heavyweight component such as <code>java.awt.Panel</code> - * be added to the frame as the root of all components. - * </p> - * - * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code> - * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style</li> - * </ul> - * - * @since 3.0 - */ -public static Frame new_Frame(final Composite parent) { - if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if ((parent.getStyle() & SWT.EMBEDDED) == 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); + + /** + * Returns a <code>java.awt.Frame</code> which is the embedded frame + * associated with the specified composite. + * + * @param parent the parent <code>Composite</code> of the <code>java.awt.Frame</code> + * @return a <code>java.awt.Frame</code> the embedded frame or <code>null</code>. + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * + * @since 3.2 + */ + public static Frame getFrame(Composite parent) { + if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if ((parent.getStyle() & SWT.EMBEDDED) == 0) return null; + return (Frame) parent.getData(EMBEDDED_FRAME_KEY); } - - final int /*long*/ handle = parent.view.id; - - Class clazz = null; - try { - String className = embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame"; - if (embeddedFrameClass == null) { - clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader()); - } else { - clazz = Class.forName(className); + + /** + * Creates a new <code>java.awt.Frame</code>. This frame is the root for + * the AWT components that will be embedded within the composite. In order + * for the embedding to succeed, the composite must have been created + * with the SWT.EMBEDDED style. + * <p> + * IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. + * When a lightweight component is added as a child of the embedded frame, + * the cursor does not change. In order to work around both these problems, it is + * strongly recommended that a heavyweight component such as <code>java.awt.Panel</code> + * be added to the frame as the root of all components. + * </p> + * + * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code> + * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style</li> + * </ul> + * + * @since 3.0 + */ + public static Frame new_Frame(final Composite parent) { + if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if ((parent.getStyle() & SWT.EMBEDDED) == 0) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - } catch (ClassNotFoundException cne) { - SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne); - } catch (Throwable e) { - SWT.error (SWT.ERROR_UNSPECIFIED , e, " [Error while starting AWT]"); - } - - Object value = null; - Constructor constructor = null; - try { - constructor = clazz.getConstructor (new Class [] {long.class}); - value = constructor.newInstance (new Object [] {new Long(handle)}); - } catch (Throwable e) { - SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e); + + final int /*long*/ handle = parent.view.id; + + Class clazz = null; + try { + String className = embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame"; + if (embeddedFrameClass == null) { + clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader()); + } else { + clazz = Class.forName(className); + } + } catch (ClassNotFoundException cne) { + SWT.error (SWT.ERROR_NOT_IMPLEMENTED, cne); + } catch (Throwable e) { + SWT.error (SWT.ERROR_UNSPECIFIED , e, " [Error while starting AWT]"); + } + + Object value = null; + Constructor constructor = null; + try { + constructor = clazz.getConstructor (new Class [] {long.class}); + value = constructor.newInstance (new Object [] {new Long(handle)}); + } catch (Throwable e) { + SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e); + } + final Frame frame = (Frame) value; + parent.setData(EMBEDDED_FRAME_KEY, frame); + + Listener listener = new Listener() { + public void handleEvent(Event e) { + switch (e.type) { + case SWT.Dispose: { + parent.setVisible(false); + EventQueue.invokeLater(new Runnable () { + public void run () { + frame.dispose (); + } + }); + break; + } + } + } + }; + + parent.addListener(SWT.Dispose, listener); + + return frame; } - final Frame frame = (Frame) value; - parent.setData(EMBEDDED_FRAME_KEY, frame); - - Listener listener = new Listener() { - public void handleEvent(Event e) { - switch (e.type) { - case SWT.Dispose: { - parent.setVisible(false); - EventQueue.invokeLater(new Runnable () { + + /** + * Creates a new <code>Shell</code>. This Shell is the root for + * the SWT widgets that will be embedded within the AWT canvas. + * + * @param display the display for the new Shell + * @param parent the parent <code>java.awt.Canvas</code> of the new Shell + * @return a <code>Shell</code> to be the parent of the embedded SWT widgets + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the display is null</li> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the parent's peer is not created</li> + * </ul> + * + * @since 3.0 + */ + 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); + int /*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 () { + public void componentResized (ComponentEvent e) { + display.asyncExec (new Runnable () { public void run () { - frame.dispose (); + if (shell.isDisposed()) return; + Dimension dim = parent.getSize (); + shell.setSize (dim.width, dim.height); } }); - break; } + }; + parent.addComponentListener(listener); + shell.addListener(SWT.Dispose, new Listener() { + public void handleEvent(Event event) { + parent.removeComponentListener(listener); } - } - }; - - parent.addListener(SWT.Dispose, listener); - - return frame; -} - -/** - * Creates a new <code>Shell</code>. This Shell is the root for - * the SWT widgets that will be embedded within the AWT canvas. - * - * @param display the display for the new Shell - * @param parent the parent <code>java.awt.Canvas</code> of the new Shell - * @return a <code>Shell</code> to be the parent of the embedded SWT widgets - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the display is null</li> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parent's peer is not created</li> - * </ul> - * - * @since 3.0 - */ -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); - SWT.error(SWT.ERROR_NOT_IMPLEMENTED); - return null; - -// TODO: Uncomment this code once Display/Shell related issues are ironed out. -// int /*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 () { -// public void componentResized (ComponentEvent e) { -// display.asyncExec (new Runnable () { -// public void run () { -// if (shell.isDisposed()) return; -// Dimension dim = parent.getSize (); -// shell.setSize (dim.width, dim.height); -// } -// }); -// } -// }; -// parent.addComponentListener(listener); -// shell.addListener(SWT.Dispose, new Listener() { -// public void handleEvent(Event event) { -// parent.removeComponentListener(listener); -// } -// }); -// shell.setVisible (true); -// return shell; -} + }); + shell.setVisible (true); + return shell; + } }
\ No newline at end of file |