diff --git a/src/macosx/classes/sun/lwawt/LWComponentPeer.java b/src/macosx/classes/sun/lwawt/LWComponentPeer.java index aa9b798c617df75d61f76b64120d89b89b84a9bc..301fbb476d8b80318297ff45a889f4eac8bf7ca7 100644 --- a/src/macosx/classes/sun/lwawt/LWComponentPeer.java +++ b/src/macosx/classes/sun/lwawt/LWComponentPeer.java @@ -439,7 +439,7 @@ public abstract class LWComponentPeer } @Override - public final Graphics getGraphics() { + public Graphics getGraphics() { final Graphics g = getOnscreenGraphics(); if (g != null) { synchronized (getPeerTreeLock()){ diff --git a/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java b/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java new file mode 100644 index 0000000000000000000000000000000000000000..90e2e88c44191bc66d644bde239950e56b6d3964 --- /dev/null +++ b/src/macosx/classes/sun/lwawt/LWLightweightFramePeer.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.lwawt; + +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Window; +import java.awt.dnd.DropTarget; + +import sun.awt.CausedFocusEvent; +import sun.awt.LightweightFrame; + +public class LWLightweightFramePeer extends LWWindowPeer { + + public LWLightweightFramePeer(LightweightFrame target, + PlatformComponent platformComponent, + PlatformWindow platformWindow) + { + super(target, platformComponent, platformWindow, LWWindowPeer.PeerType.LW_FRAME); + } + + private LightweightFrame getLwTarget() { + return (LightweightFrame)getTarget(); + } + + @Override + public Graphics getGraphics() { + return getLwTarget().getGraphics(); + } + + @Override + protected void setVisibleImpl(final boolean visible) { + } + + @Override + public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { + if (!focusAllowedFor()) { + return false; + } + if (getPlatformWindow().rejectFocusRequest(cause)) { + return false; + } + + Window opposite = LWKeyboardFocusManagerPeer.getInstance(). + getCurrentFocusedWindow(); + + changeFocusedWindow(true, opposite); + + return true; + } + + @Override + public Point getLocationOnScreen() { + Rectangle bounds = getBounds(); + return new Point(bounds.x, bounds.y); // todo + } + + @Override + public Insets getInsets() { + return new Insets(0, 0, 0, 0); + } + + @Override + public void setBounds(int x, int y, int w, int h, int op) { + setBounds(x, y, w, h, op, true, false); + } + + @Override + public void updateCursorImmediately() { + // TODO: tries to switch to the awt/fx toolkit thread and causes a deadlock on macosx + } + + @Override + public void addDropTarget(DropTarget dt) { + } + + @Override + public void removeDropTarget(DropTarget dt) { + } + + @Override + public void grab() { + getLwTarget().grabFocus(); + } + + @Override + public void ungrab() { + getLwTarget().ungrabFocus(); + } +} diff --git a/src/macosx/classes/sun/lwawt/LWToolkit.java b/src/macosx/classes/sun/lwawt/LWToolkit.java index 89f39fccbf8aadef63dc184902c93773891f2562..cad6e4353bafabe0b4fb6eaa084826b1c21b3cdf 100644 --- a/src/macosx/classes/sun/lwawt/LWToolkit.java +++ b/src/macosx/classes/sun/lwawt/LWToolkit.java @@ -218,6 +218,23 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { return peer; } + private LWLightweightFramePeer createDelegatedLwPeer(LightweightFrame target, + PlatformComponent platformComponent, + PlatformWindow platformWindow) + { + LWLightweightFramePeer peer = new LWLightweightFramePeer(target, platformComponent, platformWindow); + targetCreatedPeer(target, peer); + peer.initialize(); + return peer; + } + + @Override + public FramePeer createLightweightFrame(LightweightFrame target) { + PlatformComponent platformComponent = createLwPlatformComponent(); + PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.LW_FRAME); + return createDelegatedLwPeer(target, platformComponent, platformWindow); + } + @Override public WindowPeer createWindow(Window target) { PlatformComponent platformComponent = createPlatformComponent(); @@ -502,6 +519,8 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { protected abstract PlatformComponent createPlatformComponent(); + protected abstract PlatformComponent createLwPlatformComponent(); + protected abstract FileDialogPeer createFileDialogPeer(FileDialog target); // ---- UTILITY METHODS ---- // diff --git a/src/macosx/classes/sun/lwawt/LWWindowPeer.java b/src/macosx/classes/sun/lwawt/LWWindowPeer.java index 5b19788f2447489fc8644b1fc2d016a326ed4071..d50335f7cd5d9860e43aa05a02fb1c101e01e900 100644 --- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java +++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java @@ -48,7 +48,8 @@ public class LWWindowPeer FRAME, DIALOG, EMBEDDED_FRAME, - VIEW_EMBEDDED_FRAME + VIEW_EMBEDDED_FRAME, + LW_FRAME } private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer"); @@ -1090,7 +1091,7 @@ public class LWWindowPeer return platformWindow.requestWindowFocus(); } - private boolean focusAllowedFor() { + protected boolean focusAllowedFor() { Window window = getTarget(); // TODO: check if modal blocked return window.isVisible() && window.isEnabled() && isFocusableWindow(); @@ -1113,10 +1114,15 @@ public class LWWindowPeer return !(window instanceof Dialog || window instanceof Frame); } + @Override + public void emulateActivation(boolean activate) { + changeFocusedWindow(activate, null); + } + /* * Changes focused window on java level. */ - private void changeFocusedWindow(boolean becomesFocused, Window opposite) { + protected void changeFocusedWindow(boolean becomesFocused, Window opposite) { if (focusLog.isLoggable(PlatformLogger.FINE)) { focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this); } diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java index 370b930ea985a81e15ba44b7f36750b004a0857b..978f65c3c91079d2b77c8d52b59867b8e4ea0512 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java @@ -35,7 +35,7 @@ import sun.lwawt.PlatformWindow; * On OSX {@code CPlatformComponent} stores pointer to the native CAlayer which * can be used from JAWT. */ -final class CPlatformComponent extends CFRetainedResource +class CPlatformComponent extends CFRetainedResource implements PlatformComponent { private volatile PlatformWindow platformWindow; diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformLWComponent.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..fd76cf5c8987aed8ff2a9406e963ee66b32e9b89 --- /dev/null +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWComponent.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + + +package sun.lwawt.macosx; + +import sun.lwawt.PlatformWindow; + +class CPlatformLWComponent extends CPlatformComponent { + + CPlatformLWComponent() { + super(); + } + + @Override + public long getPointer() { + return 0; + } + + @Override + public void initialize(final PlatformWindow platformWindow) { + } + + @Override + public void setBounds(final int x, final int y, final int w, final int h) { + } + + @Override + public void dispose() { + } +} diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformLWView.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWView.java new file mode 100644 index 0000000000000000000000000000000000000000..e5d99678b1838b6e06d9543967ed665b6d0039fa --- /dev/null +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWView.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.lwawt.macosx; + +import sun.lwawt.LWWindowPeer; +import sun.java2d.SurfaceData; + +public class CPlatformLWView extends CPlatformView { + + public CPlatformLWView() { + super(); + } + + @Override + public void initialize(LWWindowPeer peer, CPlatformResponder responder) { + initializeBase(peer, responder); + } + + @Override + public long getAWTView() { + return 0; + } + + @Override + public boolean isOpaque() { + return true; + } + + @Override + public void setBounds(int x, int y, int width, int height) { + } + + @Override + public void enterFullScreenMode() { + } + + @Override + public void exitFullScreenMode() { + } + + @Override + public SurfaceData replaceSurfaceData() { + return null; + } + + @Override + public SurfaceData getSurfaceData() { + return null; + } + + @Override + public void dispose() { + } + + @Override + public long getWindowLayerPtr() { + return 0; + } +} diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java new file mode 100644 index 0000000000000000000000000000000000000000..d7a912643289b8712fdbdd60e562984c6baa1d71 --- /dev/null +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformLWWindow.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.lwawt.macosx; + +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.GraphicsDevice; +import java.awt.Insets; +import java.awt.MenuBar; +import java.awt.Point; +import java.awt.Window; +import sun.awt.CausedFocusEvent; +import sun.java2d.SurfaceData; +import sun.lwawt.LWWindowPeer; +import sun.lwawt.PlatformWindow; + +public class CPlatformLWWindow extends CPlatformWindow { + + @Override + public void initialize(Window target, LWWindowPeer peer, PlatformWindow owner) { + initializeBase(target, peer, owner, new CPlatformLWView()); + } + + @Override + public void toggleFullScreen() { + } + + @Override + public void setMenuBar(MenuBar mb) { + } + + @Override + public void dispose() { + } + + @Override + public FontMetrics getFontMetrics(Font f) { + return null; + } + + @Override + public Insets getInsets() { + return new Insets(0, 0, 0, 0); + } + + @Override + public Point getLocationOnScreen() { + return null; + } + + @Override + public GraphicsDevice getGraphicsDevice() { + return null; + } + + @Override + public SurfaceData getScreenSurface() { + return null; + } + + @Override + public SurfaceData replaceSurfaceData() { + return null; + } + + @Override + public void setBounds(int x, int y, int w, int h) { + if (getPeer() != null) { + getPeer().notifyReshape(x, y, w, h); + } + } + + @Override + public void setVisible(boolean visible) { + } + + @Override + public void setTitle(String title) { + } + + @Override + public void updateIconImages() { + } + + @Override + public long getNSWindowPtr() { + return 0; + } + + @Override + public SurfaceData getSurfaceData() { + return null; + } + + @Override + public void toBack() { + } + + @Override + public void toFront() { + } + + @Override + public void setResizable(final boolean resizable) { + } + + @Override + public void setSizeConstraints(int minW, int minH, int maxW, int maxH) { + } + + @Override + public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) { + return false; + } + + @Override + public boolean requestWindowFocus() { + return true; + } + + @Override + public boolean isActive() { + return true; + } + + @Override + public void updateFocusableWindowState() { + } + + @Override + public Graphics transformGraphics(Graphics g) { + return null; + } + + @Override + public void setAlwaysOnTop(boolean isAlwaysOnTop) { + } + + @Override + public PlatformWindow getTopmostPlatformWindowUnderMouse(){ + return null; + } + + @Override + public void setOpacity(float opacity) { + } + + @Override + public void setOpaque(boolean isOpaque) { + } + + @Override + public void enterFullScreenMode() { + } + + @Override + public void exitFullScreenMode() { + } + + @Override + public void setWindowState(int windowState) { + } + + @Override + public LWWindowPeer getPeer() { + return super.getPeer(); + } + + @Override + public CPlatformView getContentView() { + return super.getContentView(); + } + + @Override + public long getLayerPtr() { + return 0; + } +} diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java index 495657963bd69d972153be70552cd522951c271d..3a0bec48629631c8c7efaf37f5328463dfdc4284 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java @@ -54,8 +54,7 @@ public class CPlatformView extends CFRetainedResource { } public void initialize(LWWindowPeer peer, CPlatformResponder responder) { - this.peer = peer; - this.responder = responder; + initializeBase(peer, responder); if (!LWCToolkit.getSunAwtDisableCALayers()) { this.windowLayer = new CGLLayer(peer); @@ -63,6 +62,11 @@ public class CPlatformView extends CFRetainedResource { setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr())); } + protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) { + this.peer = peer; + this.responder = responder; + } + public long getAWTView() { return ptr; } diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java index 8f83702a209ee3390f8ac6647f1c4540ffc1cf58..dc51373cc1b9fe24e76db5f6ad872f92cadf015c 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java @@ -44,7 +44,7 @@ import com.apple.laf.*; import com.apple.laf.ClientPropertyApplicator.Property; import com.sun.awt.AWTUtilities; -public final class CPlatformWindow extends CFRetainedResource implements PlatformWindow { +public class CPlatformWindow extends CFRetainedResource implements PlatformWindow { private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h); private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data); private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr); @@ -218,11 +218,7 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor */ @Override // PlatformWindow public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) { - this.peer = _peer; - this.target = _target; - if (_owner instanceof CPlatformWindow) { - this.owner = (CPlatformWindow)_owner; - } + initializeBase(_target, _peer, _owner, new CPlatformView()); final int styleBits = getInitialStyleBits(); @@ -231,7 +227,6 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor String warningString = target.getWarningString(); responder = new CPlatformResponder(peer, false); - contentView = new CPlatformView(); contentView.initialize(peer, responder); final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), styleBits, 0, 0, 0, 0); @@ -253,6 +248,15 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor validateSurface(); } + protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) { + this.peer = peer; + this.target = target; + if (owner instanceof CPlatformWindow) { + this.owner = (CPlatformWindow)owner; + } + this.contentView = view; + } + private int getInitialStyleBits() { // defaults style bits int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE; diff --git a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index ae6a4f77662193ca9df730423b5893e68a8df75d..801c3d41605061e2ab33935f56d67682ca44e634 100644 --- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -160,6 +160,8 @@ public final class LWCToolkit extends LWToolkit { return new CPlatformEmbeddedFrame(); } else if (peerType == PeerType.VIEW_EMBEDDED_FRAME) { return new CViewPlatformEmbeddedFrame(); + } else if (peerType == PeerType.LW_FRAME) { + return new CPlatformLWWindow(); } else { assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME); return new CPlatformWindow(); @@ -171,6 +173,11 @@ public final class LWCToolkit extends LWToolkit { return new CPlatformComponent(); } + @Override + protected PlatformComponent createLwPlatformComponent() { + return new CPlatformLWComponent(); + } + @Override protected FileDialogPeer createFileDialogPeer(FileDialog target) { return new CFileDialog(target); diff --git a/src/share/classes/java/awt/peer/FramePeer.java b/src/share/classes/java/awt/peer/FramePeer.java index 8bb3b07add97e7cffcff5f5e4f32768829d2981f..e9d2b002fb0a1bd882298ca985d02e14b211c743 100644 --- a/src/share/classes/java/awt/peer/FramePeer.java +++ b/src/share/classes/java/awt/peer/FramePeer.java @@ -125,4 +125,10 @@ public interface FramePeer extends WindowPeer { // into an EmbeddedFramePeer which would extend FramePeer Rectangle getBoundsPrivate(); + /** + * Requests the peer to emulate window activation. + * + * @param activate activate or deactivate the window + */ + void emulateActivation(boolean activate); } diff --git a/src/share/classes/java/awt/peer/WindowPeer.java b/src/share/classes/java/awt/peer/WindowPeer.java index f2e8993e1016b8e135f5c6f5b34c5c283e461a5d..fca78b7eed42944dd73e2dbb865b898a885e0ba9 100644 --- a/src/share/classes/java/awt/peer/WindowPeer.java +++ b/src/share/classes/java/awt/peer/WindowPeer.java @@ -27,8 +27,6 @@ package java.awt.peer; import java.awt.*; -import java.awt.image.BufferedImage; - /** * The peer interface for {@link Window}. * diff --git a/src/share/classes/sun/awt/EmbeddedFrame.java b/src/share/classes/sun/awt/EmbeddedFrame.java index d05e30fe742e6c611782acf15b1290b00631b3a4..0ae1ec762dfb1239597b931f95cfbf3f62e66922 100644 --- a/src/share/classes/sun/awt/EmbeddedFrame.java +++ b/src/share/classes/sun/awt/EmbeddedFrame.java @@ -582,5 +582,8 @@ public abstract class EmbeddedFrame extends Frame public void repositionSecurityWarning() { } - } + + public void emulateActivation(boolean activate) { + } + } } // class EmbeddedFrame diff --git a/src/share/classes/sun/awt/HToolkit.java b/src/share/classes/sun/awt/HToolkit.java index 57217678bfc84bf5a8bcfad6d8ef73bd86589723..8671d8b5150c0c876814a7a49bf3f03c11132fc6 100644 --- a/src/share/classes/sun/awt/HToolkit.java +++ b/src/share/classes/sun/awt/HToolkit.java @@ -64,6 +64,11 @@ public class HToolkit extends SunToolkit throw new HeadlessException(); } + public FramePeer createLightweightFrame(LightweightFrame target) + throws HeadlessException { + throw new HeadlessException(); + } + public FramePeer createFrame(Frame target) throws HeadlessException { throw new HeadlessException(); diff --git a/src/share/classes/sun/awt/LightweightFrame.java b/src/share/classes/sun/awt/LightweightFrame.java new file mode 100644 index 0000000000000000000000000000000000000000..71e3dd30333817ba064fb864b0e724695996531e --- /dev/null +++ b/src/share/classes/sun/awt/LightweightFrame.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.awt; + +import java.awt.Container; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.MenuBar; +import java.awt.MenuComponent; +import java.awt.Toolkit; +import java.awt.peer.FramePeer; + +/** + * The class provides basic functionality for a lightweight frame + * implementation. A subclass is expected to provide painting to an + * offscreen image and access to it. Thus it can be used for lightweight + * embedding. + * + * @author Artem Ananiev + * @author Anton Tarasov + */ +@SuppressWarnings("serial") +public abstract class LightweightFrame extends Frame { + + /** + * Constructs a new, initially invisible {@code LightweightFrame} + * instance. + */ + public LightweightFrame() { + setUndecorated(true); + setResizable(true); + setEnabled(true); + } + + /** + * Blocks introspection of a parent window by this child. + * + * @return null + */ + @Override public final Container getParent() { return null; } + + @Override public Graphics getGraphics() { return null; } + + @Override public final boolean isResizable() { return true; } + + // Block modification of any frame attributes, since they aren't + // applicable for a lightweight frame. + + @Override public final void setTitle(String title) {} + @Override public final void setIconImage(Image image) {} + @Override public final void setIconImages(java.util.List icons) {} + @Override public final void setMenuBar(MenuBar mb) {} + @Override public final void setResizable(boolean resizable) {} + @Override public final void remove(MenuComponent m) {} + @Override public final void toFront() {} + @Override public final void toBack() {} + + @Override public void addNotify() { + synchronized (getTreeLock()) { + if (getPeer() == null) { + SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit(); + try { + setPeer(stk.createLightweightFrame(this)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + super.addNotify(); + } + } + + private void setPeer(final FramePeer p) { + AWTAccessor.getComponentAccessor().setPeer(this, p); + } + + /** + * Requests the peer to emulate activation or deactivation of the + * frame. Peers should override this method if they are to implement + * this functionality. + * + * @param activate if true, activates the frame; + * otherwise, deactivates the frame + */ + public void emulateActivation(boolean activate) { + ((FramePeer)getPeer()).emulateActivation(activate); + } + + /** + * Delegates the focus grab action to the client (embedding) application. + * The method is called by the AWT grab machinery. + * + * @see SunToolkit#grab(java.awt.Window) + */ + public abstract void grabFocus(); + + /** + * Delegates the focus ungrab action to the client (embedding) application. + * The method is called by the AWT grab machinery. + * + * @see SunToolkit#ungrab(java.awt.Window) + */ + public abstract void ungrabFocus(); +} diff --git a/src/share/classes/sun/awt/SunToolkit.java b/src/share/classes/sun/awt/SunToolkit.java index 4ae6a94f0dc5cf8bb184b2eded966e7c6c386685..8fc568913fbbae7af08242edd864e366c0263b0f 100644 --- a/src/share/classes/sun/awt/SunToolkit.java +++ b/src/share/classes/sun/awt/SunToolkit.java @@ -131,6 +131,9 @@ public abstract class SunToolkit extends Toolkit public abstract FramePeer createFrame(Frame target) throws HeadlessException; + public abstract FramePeer createLightweightFrame(LightweightFrame target) + throws HeadlessException; + public abstract DialogPeer createDialog(Dialog target) throws HeadlessException; diff --git a/src/share/classes/sun/swing/JLightweightFrame.java b/src/share/classes/sun/swing/JLightweightFrame.java new file mode 100644 index 0000000000000000000000000000000000000000..f7ea0aead1ecbcec2f326215d8ce0e995fb31ea6 --- /dev/null +++ b/src/share/classes/sun/swing/JLightweightFrame.java @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; + +import javax.swing.JLayeredPane; +import javax.swing.JPanel; +import javax.swing.JRootPane; +import javax.swing.LayoutFocusTraversalPolicy; +import javax.swing.RootPaneContainer; + +import sun.awt.LightweightFrame; + +/** + * The frame serves as a lightweight container which paints its content + * to an offscreen image and provides access to the image's data via the + * {@link LightweightContent} interface. Note, that it may not be shown + * as a standalone toplevel frame. Its purpose is to provide functionality + * for lightweight embedding. + * + * @author Artem Ananiev + * @author Anton Tarasov + */ +public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer { + + private final JRootPane rootPane = new JRootPane(); + + private LightweightContent content; + + private Component component; + private JPanel contentPane; + + private BufferedImage bbImage; + + /** + * Constructs a new, initially invisible {@code JLightweightFrame} + * instance. + */ + public JLightweightFrame() { + super(); + add(rootPane, BorderLayout.CENTER); + setBackground(new Color(0, 0, 0, 0)); + setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); + } + + /** + * Sets the {@link LightweightContent} instance for this frame. + * The {@code JComponent} object returned by the + * {@link LightweightContent#getComponent()} method is immediately + * added to the frame's content pane. + * + * @param content the {@link LightweightContent} instance + */ + public void setContent(LightweightContent content) { + this.content = content; + this.component = content.getComponent(); + + initInterior(); + } + + @Override + public Graphics getGraphics() { + if (bbImage == null) return null; + + Graphics2D g = bbImage.createGraphics(); + g.setBackground(getBackground()); + g.setColor(getForeground()); + g.setFont(getFont()); + return g; + } + + /** + * {@inheritDoc} + * + * @see LightweightContent#focusGrabbed() + */ + @Override + public void grabFocus() { + if (content != null) content.focusGrabbed(); + } + + /** + * {@inheritDoc} + * + * @see LightweightContent#focusUngrabbed() + */ + @Override + public void ungrabFocus() { + if (content != null) content.focusUngrabbed(); + } + + private void initInterior() { + contentPane = new JPanel() { + @Override + public void paint(Graphics g) { + content.paintLock(); + try { + super.paint(g); + + final Rectangle clip = g.getClipBounds() != null ? + g.getClipBounds() : new Rectangle(0, 0, contentPane.getWidth(), contentPane.getHeight()); + + clip.x = Math.max(0, clip.x); + clip.y = Math.max(0, clip.y); + clip.width = Math.min(contentPane.getWidth(), clip.width); + clip.height = Math.min(contentPane.getHeight(), clip.height); + + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + content.imageUpdated(clip.x, clip.y, clip.width, clip.height); + } + }); + } finally { + content.paintUnlock(); + } + } + @Override + protected boolean isPaintingOrigin() { + return true; + } + }; + contentPane.setLayout(new BorderLayout()); + contentPane.add(component); + setContentPane(contentPane); + } + + @SuppressWarnings("deprecation") + @Override public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + + if (width == 0 || height == 0) { + return; + } + + content.paintLock(); + try { + if ((bbImage == null) || (width != bbImage.getWidth()) || (height != bbImage.getHeight())) { + boolean createBB = true; + int newW = width; + int newH = height; + if (bbImage != null) { + int oldW = bbImage.getWidth(); + int oldH = bbImage.getHeight(); + if ((oldW >= newW) && (oldH >= newH)) { + createBB = false; + } else { + if (oldW >= newW) { + newW = oldW; + } else { + newW = Math.max((int)(oldW * 1.2), width); + } + if (oldH >= newH) { + newH = oldH; + } else { + newH = Math.max((int)(oldH * 1.2), height); + } + } + } + if (createBB) { + BufferedImage oldBB = bbImage; + bbImage = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB_PRE); + if (oldBB != null) { + Graphics g = bbImage.getGraphics(); + try { + g.drawImage(oldBB, 0, 0, newW, newH, null); + } finally { + g.dispose(); + oldBB.flush(); + } + } + DataBufferInt dataBuf = (DataBufferInt)bbImage.getRaster().getDataBuffer(); + content.imageBufferReset(dataBuf.getData(), 0, 0, width, height, bbImage.getWidth()); + } else { + content.imageReshaped(0, 0, width, height); + } + } + } finally { + content.paintUnlock(); + } + } + + @Override + public JRootPane getRootPane() { + return rootPane; + } + + @Override + public void setContentPane(Container contentPane) { + getRootPane().setContentPane(contentPane); + } + + @Override + public Container getContentPane() { + return getRootPane().getContentPane(); + } + + @Override + public void setLayeredPane(JLayeredPane layeredPane) { + getRootPane().setLayeredPane(layeredPane); + } + + @Override + public JLayeredPane getLayeredPane() { + return getRootPane().getLayeredPane(); + } + + @Override + public void setGlassPane(Component glassPane) { + getRootPane().setGlassPane(glassPane); + } + + @Override + public Component getGlassPane() { + return getRootPane().getGlassPane(); + } +} diff --git a/src/share/classes/sun/swing/LightweightContent.java b/src/share/classes/sun/swing/LightweightContent.java new file mode 100644 index 0000000000000000000000000000000000000000..2d443fba23ce1de9f9765df0b6727a56b6c4916e --- /dev/null +++ b/src/share/classes/sun/swing/LightweightContent.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.swing; + +import javax.swing.JComponent; + +/** + * The interface by means of which the {@link JLightweightFrame} class + * communicates to its client application. + *

+ * The client application implements this interface so it can response + * to requests and process notifications from {@code JLightweightFrame}. + * An implementation of this interface is associated with a {@code + * JLightweightFrame} instance via the {@link JLightweightFrame#setContent} + * method. + * + * A hierarchy of components contained in the {@code JComponent} instance + * returned by the {@link #getComponent} method should not contain any + * heavyweight components, otherwise {@code JLightweightFrame} may fail + * to paint it. + * + * @author Artem Ananiev + * @author Anton Tarasov + * @author Jim Graham + */ +public interface LightweightContent { + + /** + * The client application overrides this method to return the {@code + * JComponent} instance which the {@code JLightweightFrame} container + * will paint as its lightweight content. A hierarchy of components + * contained in this component should not contain any heavyweight objects. + * + * @return the component to paint + */ + public JComponent getComponent(); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that it acquires the paint lock. The client application + * should implement the locking mechanism in order to synchronize access + * to the content image data, shared between {@code JLightweightFrame} + * and the client application. + * + * @see #paintUnlock + */ + public void paintLock(); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that it releases the paint lock. The client application + * should implement the locking mechanism in order to synchronize access + * to the content image data, shared between {@code JLightweightFrame} + * and the client application. + * + * @see #paintLock + */ + public void paintUnlock(); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that a new data buffer has been set as a content pixel + * buffer. Typically this occurs when a buffer of a larger size is + * created in response to a content resize event. The method reports + * a reference to the pixel data buffer, the content image bounds + * within the buffer and the line stride of the buffer. These values + * have the following correlation. + *

+ * The {@code width} and {@code height} matches the size of the content + * (the component returned from the {@link #getComponent} method). The + * {@code x} and {@code y} is the origin of the content, {@code (0, 0)} + * in the coordinate space of the content, appearing at + * {@code data[y * linestride + x]} in the buffer. All indices + * {@code data[(y + j) * linestride + (x + i)]} where + * {@code (0 <= i < width)} and {@code (0 <= j < height)} will represent + * valid pixel data, {@code (i, j)} in the coordinate space of the content. + * + * @param data the content pixel data buffer of INT_ARGB_PRE type + * @param x the x coordinate of the image + * @param y the y coordinate of the image + * @param width the width of the image + * @param height the height of the image + * @param linestride the line stride of the pixel buffer + */ + public void imageBufferReset(int[] data, + int x, int y, + int width, int height, + int linestride); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that the content image bounds have been changed within the + * image's pixel buffer. + * + * @param x the x coordinate of the image + * @param y the y coordinate of the image + * @param width the width of the image + * @param height the height of the image + * + * @see #imageBufferReset + */ + public void imageReshaped(int x, int y, int width, int height); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that a part of the content image, or the whole image has + * been updated. The method reports bounds of the rectangular dirty region. + * The {@code dirtyX} and {@code dirtyY} is the origin of the dirty + * rectangle, which is relative to the origin of the content, appearing + * at {@code data[(y + dirtyY] * linestride + (x + dirtyX)]} in the pixel + * buffer (see {@link #imageBufferReset}). All indices + * {@code data[(y + dirtyY + j) * linestride + (x + dirtyX + i)]} where + * {@code (0 <= i < dirtyWidth)} and {@code (0 <= j < dirtyHeight)} + * will represent valid pixel data, {@code (i, j)} in the coordinate space + * of the dirty rectangle. + * + * @param dirtyX the x coordinate of the dirty rectangle, + * relative to the image origin + * @param dirtyY the y coordinate of the dirty rectangle, + * relative to the image origin + * @param dirtyWidth the width of the dirty rectangle + * @param dirtyHeight the height of the dirty rectangle + * + * @see #imageBufferReset + * @see #imageReshaped + */ + public void imageUpdated(int dirtyX, int dirtyY, + int dirtyWidth, int dirtyHeight); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that the frame has grabbed focus. + */ + public void focusGrabbed(); + + /** + * {@code JLightweightFrame} calls this method to notify the client + * application that the frame has ungrabbed focus. + */ + public void focusUngrabbed(); +} diff --git a/src/solaris/classes/sun/awt/X11/XFramePeer.java b/src/solaris/classes/sun/awt/X11/XFramePeer.java index fdefb1047ceda052c4227ee0c7e03e9cabe2242f..0c540b1785540d35b0f85ec9849144d0c4454884 100644 --- a/src/solaris/classes/sun/awt/X11/XFramePeer.java +++ b/src/solaris/classes/sun/awt/X11/XFramePeer.java @@ -641,4 +641,6 @@ class XFramePeer extends XDecoratedPeer implements FramePeer { public Rectangle getBoundsPrivate() { return getBounds(); } + + public void emulateActivation(boolean doActivate) {} } diff --git a/src/solaris/classes/sun/awt/X11/XToolkit.java b/src/solaris/classes/sun/awt/X11/XToolkit.java index 7c40e8260efba0a7990b84e2c5d543ba9e0a4b5d..b4fb9c76f179952f0efcb5260c9a4e8290ff39c3 100644 --- a/src/solaris/classes/sun/awt/X11/XToolkit.java +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java @@ -419,6 +419,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable { return peer; } + public FramePeer createLightweightFrame(LightweightFrame target) { + return null; + } + public FramePeer createFrame(Frame target) { FramePeer peer = new XFramePeer(target); targetCreatedPeer(target, peer); diff --git a/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java b/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java index b0f9cd3279d008c76d046b69d369709cbee61853..ba6ae8aefb2078c7d0e86f5da155a160a23d8e6f 100644 --- a/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java +++ b/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java @@ -226,15 +226,15 @@ public class WEmbeddedFrame extends EmbeddedFrame { } @SuppressWarnings("deprecation") - public void synthesizeWindowActivation(final boolean doActivate) { - if (!doActivate || EventQueue.isDispatchThread()) { - ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(doActivate); + public void synthesizeWindowActivation(final boolean activate) { + if (!activate || EventQueue.isDispatchThread()) { + ((WFramePeer)getPeer()).emulateActivation(activate); } else { // To avoid focus concurrence b/w IE and EmbeddedFrame // activation is postponed by means of posting it to EDT. EventQueue.invokeLater(new Runnable() { public void run() { - ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(true); + ((WFramePeer)getPeer()).emulateActivation(true); } }); } diff --git a/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java b/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java index 3b6d298bda812da3677f7d58a08d569d29df62da..ec551e30ced3be41af94524cad1a838749cc2da6 100644 --- a/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java +++ b/src/windows/classes/sun/awt/windows/WEmbeddedFramePeer.java @@ -65,8 +65,6 @@ public class WEmbeddedFramePeer extends WFramePeer { public native Rectangle getBoundsPrivate(); - public native void synthesizeWmActivate(boolean doActivate); - @Override public boolean isAccelCapable() { // REMIND: Temp workaround for issues with using HW acceleration diff --git a/src/windows/classes/sun/awt/windows/WFramePeer.java b/src/windows/classes/sun/awt/windows/WFramePeer.java index 368b8f60696cd20edb74fcb91f917ea8764a4175..588b3caebdd527a4b2b2d24fa49fe452e782f4a8 100644 --- a/src/windows/classes/sun/awt/windows/WFramePeer.java +++ b/src/windows/classes/sun/awt/windows/WFramePeer.java @@ -200,4 +200,11 @@ class WFramePeer extends WWindowPeer implements FramePeer { public Rectangle getBoundsPrivate() { return getBounds(); } + + // TODO: implement it in peers. WLightweightFramePeer may implement lw version. + public void emulateActivation(boolean activate) { + synthesizeWmActivate(activate); + } + + private native void synthesizeWmActivate(boolean activate); } diff --git a/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java b/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java new file mode 100644 index 0000000000000000000000000000000000000000..c2c1604bef45972da6bf08d6b42ebd95c2eaf17c --- /dev/null +++ b/src/windows/classes/sun/awt/windows/WLightweightFramePeer.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.awt.windows; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseEvent; + +import sun.awt.LightweightFrame; + +public class WLightweightFramePeer extends WFramePeer { + + public WLightweightFramePeer(LightweightFrame target) { + super(target); + } + + private LightweightFrame getLwTarget() { + return (LightweightFrame)target; + } + + @Override + public Graphics getGraphics() { + return getLwTarget().getGraphics(); + } + + @Override + public void show() { + super.show(); + postEvent(new ComponentEvent((Component)getTarget(), ComponentEvent.COMPONENT_SHOWN)); + } + + @Override + public void hide() { + super.hide(); + postEvent(new ComponentEvent((Component)getTarget(), ComponentEvent.COMPONENT_HIDDEN)); + } + + @Override + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + postEvent(new ComponentEvent((Component) getTarget(), ComponentEvent.COMPONENT_MOVED)); + postEvent(new ComponentEvent((Component) getTarget(), ComponentEvent.COMPONENT_RESIZED)); + } + + @Override + public void handleEvent(java.awt.AWTEvent e) { + if (e.getID() == MouseEvent.MOUSE_PRESSED) { + emulateActivation(true); + } + super.handleEvent(e); + } + + @Override + public void grab() { + getLwTarget().grabFocus(); + } + + @Override + public void ungrab() { + getLwTarget().ungrabFocus(); + } +} diff --git a/src/windows/classes/sun/awt/windows/WToolkit.java b/src/windows/classes/sun/awt/windows/WToolkit.java index afbdfa6c1f9c6a047b6d86c63f3d7aa44246ac6e..e87b0ad8c08ff9136c9a0281f723c65d90892882 100644 --- a/src/windows/classes/sun/awt/windows/WToolkit.java +++ b/src/windows/classes/sun/awt/windows/WToolkit.java @@ -37,6 +37,7 @@ import java.beans.PropertyChangeListener; import java.security.AccessController; import java.security.PrivilegedAction; import sun.awt.AWTAutoShutdown; +import sun.awt.LightweightFrame; import sun.awt.SunToolkit; import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsEnvironment; @@ -398,6 +399,12 @@ public class WToolkit extends SunToolkit implements Runnable { return peer; } + public FramePeer createLightweightFrame(LightweightFrame target) { + FramePeer peer = new WLightweightFramePeer(target); + targetCreatedPeer(target, peer); + return peer; + } + public CanvasPeer createCanvas(Canvas target) { CanvasPeer peer = new WCanvasPeer(target); targetCreatedPeer(target, peer); diff --git a/src/windows/native/sun/windows/awt_Frame.cpp b/src/windows/native/sun/windows/awt_Frame.cpp index da1df839535a4a85acc390e79cf7df2826d61b94..41c5624f001c72a61908c06b40aa3e3d775acd61 100644 --- a/src/windows/native/sun/windows/awt_Frame.cpp +++ b/src/windows/native/sun/windows/awt_Frame.cpp @@ -105,6 +105,7 @@ AwtFrame::AwtFrame() { m_parentWnd = NULL; menuBar = NULL; m_isEmbedded = FALSE; + m_isLightweight = FALSE; m_ignoreWmSize = FALSE; m_isMenuDropped = FALSE; m_isInputMethodWindow = FALSE; @@ -170,14 +171,13 @@ AwtFrame* AwtFrame::Create(jobject self, jobject parent) * area of the browser is a Java Frame for parenting purposes, but * really a Windows child window */ + BOOL isEmbeddedInstance = FALSE; + BOOL isEmbedded = FALSE; cls = env->FindClass("sun/awt/EmbeddedFrame"); - if (cls == NULL) { - return NULL; + if (cls) { + isEmbeddedInstance = env->IsInstanceOf(target, cls); } INT_PTR handle; - jboolean isEmbeddedInstance = env->IsInstanceOf(target, cls); - jboolean isEmbedded = FALSE; - if (isEmbeddedInstance) { handle = static_cast(env->GetLongField(target, AwtFrame::handleID)); if (handle != 0) { @@ -186,6 +186,13 @@ AwtFrame* AwtFrame::Create(jobject self, jobject parent) } frame->m_isEmbedded = isEmbedded; + BOOL isLightweight = FALSE; + cls = env->FindClass("sun/awt/LightweightFrame"); + if (cls) { + isLightweight = env->IsInstanceOf(target, cls); + } + frame->m_isLightweight = isLightweight; + if (isEmbedded) { hwndParent = (HWND)handle; RECT rect; @@ -230,6 +237,23 @@ AwtFrame* AwtFrame::Create(jobject self, jobject parent) rect.bottom-rect.top); frame->InitPeerGraphicsConfig(env, self); AwtToolkit::GetInstance().RegisterEmbedderProcessId(hwndParent); + } else if (isLightweight) { + frame->m_isUndecorated = true; + frame->m_peerObject = env->NewGlobalRef(self); + frame->RegisterClass(); + + DWORD exStyle = 0; + DWORD style = WS_POPUP; + + frame->CreateHWnd(env, L"", + style, + exStyle, + 0, 0, 0, 0, + 0, + NULL, + ::GetSysColor(COLOR_WINDOWTEXT), + ::GetSysColor(COLOR_WINDOWFRAME), + self); } else { jint state = env->CallIntMethod(self, AwtFrame::getExtendedStateMID); DWORD exStyle; @@ -345,16 +369,20 @@ LRESULT AwtFrame::ProxyWindowProc(UINT message, WPARAM wParam, LPARAM lParam, Ms case WM_SETFOCUS: if (sm_inSynthesizeFocus) break; // pass it up the WindowProc chain - if (!sm_suppressFocusAndActivation && IsEmbeddedFrame()) { - AwtSetActiveWindow(); + if (!sm_suppressFocusAndActivation) { + if (IsLightweightFrame() || IsEmbeddedFrame()) { + AwtSetActiveWindow(); + } } mr = mrConsume; break; case WM_KILLFOCUS: if (sm_inSynthesizeFocus) break; // pass it up the WindowProc chain - if (!sm_suppressFocusAndActivation && IsEmbeddedFrame()) { - AwtWindow::SynthesizeWmActivate(FALSE, GetHWnd(), NULL); + if (!sm_suppressFocusAndActivation) { + if (IsLightweightFrame() || IsEmbeddedFrame()) { + AwtWindow::SynthesizeWmActivate(FALSE, GetHWnd(), NULL); + } } else if (sm_restoreFocusAndActivation) { if (AwtComponent::GetFocusedWindow() != NULL) { @@ -640,6 +668,10 @@ AwtFrame::Show() HWND hwnd = GetHWnd(); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + if (IsLightweightFrame()) { + return; + } + DTRACE_PRINTLN3("AwtFrame::Show:%s%s%s", m_iconic ? " iconic" : "", m_zoomed ? " zoomed" : "", @@ -992,6 +1024,9 @@ BOOL AwtFrame::AwtSetActiveWindow(BOOL isMouseEventCause, UINT hittest) // b) focus is requested to some of the frame's child. m_actualFocusedWindow = NULL; } + if (IsLightweightFrame()) { + return TRUE; + } return AwtWindow::AwtSetActiveWindow(isMouseEventCause); } @@ -1873,7 +1908,7 @@ Java_sun_awt_windows_WEmbeddedFramePeer_getBoundsPrivate(JNIEnv *env, jobject se } JNIEXPORT void JNICALL -Java_sun_awt_windows_WEmbeddedFramePeer_synthesizeWmActivate(JNIEnv *env, jobject self, jboolean doActivate) +Java_sun_awt_windows_WFramePeer_synthesizeWmActivate(JNIEnv *env, jobject self, jboolean doActivate) { TRY; diff --git a/src/windows/native/sun/windows/awt_Frame.h b/src/windows/native/sun/windows/awt_Frame.h index f6d692b87eb359c9e1844a15751e3bb8b86d225b..e151c17c2a5b89c1456a18943c12322c2b1fb520 100644 --- a/src/windows/native/sun/windows/awt_Frame.h +++ b/src/windows/native/sun/windows/awt_Frame.h @@ -72,6 +72,8 @@ public: /* Returns whether this frame is embedded in an external native frame. */ INLINE BOOL IsEmbeddedFrame() { return m_isEmbedded; } + /* Returns whether this frame is lightweight. */ + INLINE virtual BOOL IsLightweightFrame() { return m_isLightweight; } INLINE BOOL IsSimpleWindow() { return FALSE; } @@ -169,6 +171,9 @@ private: /* The frame is an EmbeddedFrame. */ BOOL m_isEmbedded; + /* The frame is a LightweightFrame */ + BOOL m_isLightweight; + /* used so that calls to ::MoveWindow in SetMenuBar don't propogate because they are immediately followed by calls to Component.resize */ BOOL m_ignoreWmSize; diff --git a/src/windows/native/sun/windows/awt_Window.h b/src/windows/native/sun/windows/awt_Window.h index 8ad2b0902b2d5ac7aa219f2c9911917daf982961..0ee23322d4b16432efde613943fbc7fcb4501aae 100644 --- a/src/windows/native/sun/windows/awt_Window.h +++ b/src/windows/native/sun/windows/awt_Window.h @@ -143,6 +143,7 @@ public: INLINE HICON GetHIcon() {return m_hIcon;}; INLINE HICON GetHIconSm() {return m_hIconSm;}; INLINE BOOL IsIconInherited() {return m_iconInherited;}; + INLINE virtual BOOL IsLightweightFrame() {return FALSE;} /* Post events to the EventQueue */ void SendComponentEvent(jint eventId); @@ -193,8 +194,10 @@ public: // Execute on Toolkit only. INLINE static LRESULT SynthesizeWmActivate(BOOL doActivate, HWND targetHWnd, HWND oppositeHWnd) { + AwtWindow *win = static_cast(AwtComponent::GetComponent(targetHWnd)); if (doActivate && - (!::IsWindowVisible(targetHWnd) || ::IsIconic(::GetAncestor(targetHWnd, GA_ROOT)))) + (!::IsWindowVisible(targetHWnd) || ::IsIconic(::GetAncestor(targetHWnd, GA_ROOT))) && + (win == NULL || !win->IsLightweightFrame())) { // The activation is rejected if either: // - The toplevel is not visible