aboutsummaryrefslogtreecommitdiff
path: root/src/windows/classes/sun
diff options
context:
space:
mode:
authorlana <none@none>2009-04-09 13:12:58 -0700
committerlana <none@none>2009-04-09 13:12:58 -0700
commiteb3b76ea51e2441625f57b66bb7b5814d9abb341 (patch)
treec3297c6d46ecd0d9570ca67090122aa0299a286f /src/windows/classes/sun
parent016dd007e21e20d9b59186ffbd4857acbf430237 (diff)
parent9ef44fa316c87f58aabdb936a5a3c9eb89f89099 (diff)
Merge
Diffstat (limited to 'src/windows/classes/sun')
-rw-r--r--src/windows/classes/sun/awt/Win32GraphicsConfig.java10
-rw-r--r--src/windows/classes/sun/awt/Win32GraphicsDevice.java1
-rw-r--r--src/windows/classes/sun/awt/Win32GraphicsEnvironment.java9
-rw-r--r--src/windows/classes/sun/awt/windows/TranslucentWindowPainter.java398
-rw-r--r--src/windows/classes/sun/awt/windows/WCanvasPeer.java65
-rw-r--r--src/windows/classes/sun/awt/windows/WChoicePeer.java36
-rw-r--r--src/windows/classes/sun/awt/windows/WComponentPeer.java208
-rw-r--r--src/windows/classes/sun/awt/windows/WFileDialogPeer.java20
-rw-r--r--src/windows/classes/sun/awt/windows/WFramePeer.java29
-rw-r--r--src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java75
-rw-r--r--src/windows/classes/sun/awt/windows/WPanelPeer.java28
-rw-r--r--src/windows/classes/sun/awt/windows/WPrintDialogPeer.java20
-rw-r--r--src/windows/classes/sun/awt/windows/WScrollPanePeer.java6
-rw-r--r--src/windows/classes/sun/awt/windows/WToolkit.java38
-rw-r--r--src/windows/classes/sun/awt/windows/WWindowPeer.java297
-rw-r--r--src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java17
-rw-r--r--src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java12
17 files changed, 1034 insertions, 235 deletions
diff --git a/src/windows/classes/sun/awt/Win32GraphicsConfig.java b/src/windows/classes/sun/awt/Win32GraphicsConfig.java
index d24ce0eb1..2eefb33f1 100644
--- a/src/windows/classes/sun/awt/Win32GraphicsConfig.java
+++ b/src/windows/classes/sun/awt/Win32GraphicsConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. 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
@@ -331,4 +331,12 @@ public class Win32GraphicsConfig extends GraphicsConfiguration
}
// the rest of the flip actions are not supported
}
+
+ /*
+ @Override
+ */
+ public boolean isTranslucencyCapable() {
+ //XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
+ return true;
+ }
}
diff --git a/src/windows/classes/sun/awt/Win32GraphicsDevice.java b/src/windows/classes/sun/awt/Win32GraphicsDevice.java
index ba4769813..1da339ce9 100644
--- a/src/windows/classes/sun/awt/Win32GraphicsDevice.java
+++ b/src/windows/classes/sun/awt/Win32GraphicsDevice.java
@@ -380,7 +380,6 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
// fix for 4868278
peer.updateGC();
- peer.resetTargetGC();
}
}
diff --git a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
index 73b73dbb0..69723c113 100644
--- a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
+++ b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. 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
@@ -398,4 +398,11 @@ public class Win32GraphicsEnvironment
public boolean isDisplayLocal() {
return true;
}
+
+ /**
+ * Used to find out if the OS is Windows Vista or later.
+ *
+ * @return {@code true} if the OS is Vista or later, {@code false} otherwise
+ */
+ public static native boolean isVistaOS();
}
diff --git a/src/windows/classes/sun/awt/windows/TranslucentWindowPainter.java b/src/windows/classes/sun/awt/windows/TranslucentWindowPainter.java
new file mode 100644
index 000000000..9f8193f99
--- /dev/null
+++ b/src/windows/classes/sun/awt/windows/TranslucentWindowPainter.java
@@ -0,0 +1,398 @@
+/*
+ * Copyright 2008-2009 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package sun.awt.windows;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.Window;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferInt;
+import java.awt.image.VolatileImage;
+import java.lang.ref.WeakReference;
+import java.security.AccessController;
+import sun.awt.image.BufImgSurfaceData;
+import sun.java2d.DestSurfaceProvider;
+import sun.java2d.InvalidPipeException;
+import sun.java2d.Surface;
+import sun.java2d.pipe.RenderQueue;
+import sun.java2d.pipe.hw.AccelGraphicsConfig;
+import sun.java2d.pipe.hw.AccelSurface;
+import sun.security.action.GetPropertyAction;
+
+import static java.awt.image.VolatileImage.*;
+import static java.awt.Transparency.*;
+import static sun.java2d.pipe.hw.AccelSurface.*;
+import static sun.java2d.pipe.hw.ContextCapabilities.*;
+
+/**
+ * This class handles the updates of the non-opaque windows.
+ * The window associated with the peer is updated either given an image or
+ * the window is repainted to an internal buffer which is then used to update
+ * the window.
+ *
+ * Note: this class does not attempt to be thread safe, it is expected to be
+ * called from a single thread (EDT).
+ */
+public abstract class TranslucentWindowPainter {
+
+ protected Window window;
+ protected WWindowPeer peer;
+
+ // REMIND: we probably would want to remove this later
+ private static final boolean forceOpt =
+ Boolean.valueOf(AccessController.doPrivileged(
+ new GetPropertyAction("sun.java2d.twp.forceopt", "false")));
+ private static final boolean forceSW =
+ Boolean.valueOf(AccessController.doPrivileged(
+ new GetPropertyAction("sun.java2d.twp.forcesw", "false")));
+
+ /**
+ * Creates an instance of the painter for particular peer.
+ */
+ public static TranslucentWindowPainter createInstance(WWindowPeer peer) {
+ GraphicsConfiguration gc = peer.getGraphicsConfiguration();
+ if (!forceSW && gc instanceof AccelGraphicsConfig) {
+ String gcName = gc.getClass().getSimpleName();
+ AccelGraphicsConfig agc = (AccelGraphicsConfig)gc;
+ // this is a heuristic to check that we have a pcix board
+ // (those have higher transfer rate from gpu to cpu)
+ if ((agc.getContextCapabilities().getCaps() & CAPS_PS30) != 0 ||
+ forceOpt)
+ {
+ // we check for name to avoid loading classes unnecessarily if
+ // a pipeline isn't enabled
+ if (gcName.startsWith("D3D")) {
+ return new VIOptD3DWindowPainter(peer);
+ } else if (forceOpt && gcName.startsWith("WGL")) {
+ // on some boards (namely, ATI, even on pcix bus) ogl is
+ // very slow reading pixels back so for now it is disabled
+ // unless forced
+ return new VIOptWGLWindowPainter(peer);
+ }
+ }
+ }
+ return new BIWindowPainter(peer);
+ }
+
+ protected TranslucentWindowPainter(WWindowPeer peer) {
+ this.peer = peer;
+ this.window = (Window)peer.getTarget();
+ }
+
+ /**
+ * Creates (if needed), clears and returns the buffer for this painter.
+ */
+ protected abstract Image getBackBuffer();
+
+ /**
+ * Updates the the window associated with this painter with the contents
+ * of the passed image.
+ * The image can not be null, and NPE will be thrown if it is.
+ */
+ protected abstract boolean update(Image bb);
+
+ /**
+ * Flushes the resources associated with the painter. They will be
+ * recreated as needed.
+ */
+ public abstract void flush();
+
+ /**
+ * Updates the window associated with the painter given the passed image.
+ * If the passed image is null the painter will use its own buffer for
+ * rendering the contents of the window into it and updating the window.
+ *
+ * If the passed buffer has dimensions different from the window, it is
+ * copied into the internal buffer first and the latter is used to update
+ * the window.
+ *
+ * @param bb the image to update the non opaque window with, or null.
+ * If not null, the image must be of ARGB_PRE type.
+ */
+ public void updateWindow(Image bb) {
+ boolean done = false;
+ if (bb != null && (window.getWidth() != bb.getWidth(null) ||
+ window.getHeight() != bb.getHeight(null)))
+ {
+ Image ourBB = getBackBuffer();
+ Graphics2D g = (Graphics2D)ourBB.getGraphics();
+ g.drawImage(bb, 0, 0, null);
+ g.dispose();
+ bb = ourBB;
+ }
+ do {
+ if (bb == null) {
+ bb = getBackBuffer();
+ Graphics2D g = (Graphics2D)bb.getGraphics();
+ try {
+ window.paintAll(g);
+ } finally {
+ g.dispose();
+ }
+ }
+
+ peer.paintAppletWarning((Graphics2D)bb.getGraphics(),
+ bb.getWidth(null), bb.getHeight(null));
+
+ done = update(bb);
+ // in case they passed us a lost VI, next time around we'll use our
+ // own bb because we can not validate and restore the contents of
+ // their VI
+ if (!done) {
+ bb = null;
+ }
+ } while (!done);
+ }
+
+ private static final Image clearImage(Image bb) {
+ Graphics2D g = (Graphics2D)bb.getGraphics();
+ int w = bb.getWidth(null);
+ int h = bb.getHeight(null);
+
+ g.setComposite(AlphaComposite.Src);
+ g.setColor(new Color(0, 0, 0, 0));
+ g.fillRect(0, 0, w, h);
+
+ return bb;
+ }
+
+ /**
+ * A painter which uses BufferedImage as the internal buffer. The window
+ * is painted into this buffer, and the contents then are uploaded
+ * into the layered window.
+ *
+ * This painter handles all types of images passed to its paint(Image)
+ * method (VI, BI, regular Images).
+ */
+ private static class BIWindowPainter extends TranslucentWindowPainter {
+ private WeakReference<BufferedImage> biRef;
+
+ protected BIWindowPainter(WWindowPeer peer) {
+ super(peer);
+ }
+
+ private BufferedImage getBIBackBuffer() {
+ int w = window.getWidth();
+ int h = window.getHeight();
+ BufferedImage bb = biRef == null ? null : biRef.get();
+ if (bb == null || bb.getWidth() != w || bb.getHeight() != h) {
+ if (bb != null) {
+ bb.flush();
+ bb = null;
+ }
+ bb = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
+ biRef = new WeakReference<BufferedImage>(bb);
+ }
+ return (BufferedImage)clearImage(bb);
+ }
+
+ @Override
+ protected Image getBackBuffer() {
+ return getBIBackBuffer();
+ }
+
+ @Override
+ protected boolean update(Image bb) {
+ VolatileImage viBB = null;
+
+ if (bb instanceof BufferedImage) {
+ BufferedImage bi = (BufferedImage)bb;
+ int data[] =
+ ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
+ peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
+ return true;
+ } else if (bb instanceof VolatileImage) {
+ viBB = (VolatileImage)bb;
+ if (bb instanceof DestSurfaceProvider) {
+ Surface s = ((DestSurfaceProvider)bb).getDestSurface();
+ if (s instanceof BufImgSurfaceData) {
+ // the image is probably lost, upload the data from the
+ // backup surface to avoid creating another heap-based
+ // image (the parent's buffer)
+ int w = viBB.getWidth();
+ int h = viBB.getHeight();
+ BufImgSurfaceData bisd = (BufImgSurfaceData)s;
+ int data[] = ((DataBufferInt)bisd.getRaster(0,0,w,h).
+ getDataBuffer()).getData();
+ peer.updateWindowImpl(data, w, h);
+ return true;
+ }
+ }
+ }
+
+ // copy the passed image into our own buffer, then upload
+ BufferedImage bi = getBIBackBuffer();
+ Graphics2D g = (Graphics2D)bi.getGraphics();
+ g.setComposite(AlphaComposite.Src);
+ g.drawImage(bb, 0, 0, null);
+
+ int data[] =
+ ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
+ peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
+
+ return (viBB != null ? !viBB.contentsLost() : true);
+ }
+
+ public void flush() {
+ if (biRef != null) {
+ biRef.clear();
+ }
+ }
+ }
+
+ /**
+ * A version of the painter which uses VolatileImage as the internal buffer.
+ * The window is painted into this VI and then copied into the parent's
+ * Java heap-based buffer (which is then uploaded to the layered window)
+ */
+ private static class VIWindowPainter extends BIWindowPainter {
+ private WeakReference<VolatileImage> viRef;
+
+ protected VIWindowPainter(WWindowPeer peer) {
+ super(peer);
+ }
+
+ @Override
+ protected Image getBackBuffer() {
+ int w = window.getWidth();
+ int h = window.getHeight();
+ GraphicsConfiguration gc = peer.getGraphicsConfiguration();
+
+ VolatileImage viBB = viRef == null ? null : viRef.get();
+
+ if (viBB == null || viBB.getWidth() != w || viBB.getHeight() != h ||
+ viBB.validate(gc) == IMAGE_INCOMPATIBLE)
+ {
+ if (viBB != null) {
+ viBB.flush();
+ viBB = null;
+ }
+
+ if (gc instanceof AccelGraphicsConfig) {
+ AccelGraphicsConfig agc = ((AccelGraphicsConfig)gc);
+ viBB = agc.createCompatibleVolatileImage(w, h,
+ TRANSLUCENT,
+ RT_PLAIN);
+ }
+ if (viBB == null) {
+ viBB = gc.createCompatibleVolatileImage(w, h, TRANSLUCENT);
+ }
+ viBB.validate(gc);
+ viRef = new WeakReference<VolatileImage>(viBB);
+ }
+
+ return clearImage(viBB);
+ }
+
+ @Override
+ public void flush() {
+ if (viRef != null) {
+ VolatileImage viBB = viRef.get();
+ if (viBB != null) {
+ viBB.flush();
+ viBB = null;
+ }
+ viRef.clear();
+ }
+ }
+ }
+
+ /**
+ * Optimized version of hw painter. Uses VolatileImages for the
+ * buffer, and uses an optimized path to pull the data from those into
+ * the layered window, bypassing Java heap-based image.
+ */
+ private abstract static class VIOptWindowPainter extends VIWindowPainter {
+
+ protected VIOptWindowPainter(WWindowPeer peer) {
+ super(peer);
+ }
+
+ protected abstract boolean updateWindowAccel(long psdops, int w, int h);
+
+ @Override
+ protected boolean update(Image bb) {
+ if (bb instanceof DestSurfaceProvider) {
+ Surface s = ((DestSurfaceProvider)bb).getDestSurface();
+ if (s instanceof AccelSurface) {
+ final int w = bb.getWidth(null);
+ final int h = bb.getHeight(null);
+ final boolean arr[] = { false };
+ final AccelSurface as = (AccelSurface)s;
+ RenderQueue rq = as.getContext().getRenderQueue();
+ rq.lock();
+ try {
+ as.getContext().validateContext(as);
+ rq.flushAndInvokeNow(new Runnable() {
+ public void run() {
+ long psdops = as.getNativeOps();
+ arr[0] = updateWindowAccel(psdops, w, h);
+ }
+ });
+ } catch (InvalidPipeException e) {
+ // ignore, false will be returned
+ } finally {
+ rq.unlock();
+ }
+ return arr[0];
+ }
+ }
+ return super.update(bb);
+ }
+ }
+
+ private static class VIOptD3DWindowPainter extends VIOptWindowPainter {
+
+ protected VIOptD3DWindowPainter(WWindowPeer peer) {
+ super(peer);
+ }
+
+ @Override
+ protected boolean updateWindowAccel(long psdops, int w, int h) {
+ // note: this method is executed on the toolkit thread, no sync is
+ // necessary at the native level, and a pointer to peer can be used
+ return sun.java2d.d3d.D3DSurfaceData.
+ updateWindowAccelImpl(psdops, peer.getData(), w, h);
+ }
+ }
+
+ private static class VIOptWGLWindowPainter extends VIOptWindowPainter {
+
+ protected VIOptWGLWindowPainter(WWindowPeer peer) {
+ super(peer);
+ }
+
+ @Override
+ protected boolean updateWindowAccel(long psdops, int w, int h) {
+ // note: part of this method which deals with GDI will be on the
+ // toolkit thread
+ return sun.java2d.opengl.WGLSurfaceData.
+ updateWindowAccelImpl(psdops, peer, w, h);
+ }
+ }
+}
diff --git a/src/windows/classes/sun/awt/windows/WCanvasPeer.java b/src/windows/classes/sun/awt/windows/WCanvasPeer.java
index 5d88a0c37..b97a3787b 100644
--- a/src/windows/classes/sun/awt/windows/WCanvasPeer.java
+++ b/src/windows/classes/sun/awt/windows/WCanvasPeer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc. 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,6 +28,7 @@ import java.awt.*;
import java.awt.peer.*;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
+import sun.awt.AWTAccessor;
import sun.awt.ComponentAccessor;
import sun.awt.SunToolkit;
import sun.awt.Win32GraphicsDevice;
@@ -37,44 +38,12 @@ class WCanvasPeer extends WComponentPeer implements CanvasPeer {
private boolean eraseBackground;
- Method resetGCMethod;
-
// Toolkit & peer internals
WCanvasPeer(Component target) {
super(target);
}
- /*
- * From the DisplayChangedListener interface.
- *
- * Overrides WComponentPeer version because Canvases can be created with
- * a non-defulat GraphicsConfiguration, which is no longer valid.
- * Up-called for other windows peer instances (WPanelPeer, WWindowPeer).
- */
- public void displayChanged() {
- clearLocalGC();
- resetTargetGC();
- super.displayChanged();
- }
-
- /*
- * Reset the graphicsConfiguration member of our target Component.
- * Component.resetGC() is a package-private method, so we have to call it
- * through reflection.
- */
- public void resetTargetGC() {
- ComponentAccessor.resetGC((Component)target);
- }
-
- /*
- * Clears the peer's winGraphicsConfig member.
- * Overridden by WWindowPeer, which shouldn't have a null winGraphicsConfig.
- */
- void clearLocalGC() {
- winGraphicsConfig = null;
- }
-
native void create(WComponentPeer parent);
void initialize() {
@@ -110,16 +79,20 @@ class WCanvasPeer extends WComponentPeer implements CanvasPeer {
}
public void print(Graphics g) {
- Dimension d = ((Component)target).getSize();
- if (g instanceof Graphics2D ||
- g instanceof sun.awt.Graphics2Delegate) {
- // background color is setup correctly, so just use clearRect
- g.clearRect(0, 0, d.width, d.height);
- } else {
- // emulate clearRect
- g.setColor(((Component)target).getBackground());
- g.fillRect(0, 0, d.width, d.height);
- g.setColor(((Component)target).getForeground());
+ if (!(target instanceof Window) ||
+ AWTAccessor.getWindowAccessor().isOpaque((Window)target))
+ {
+ Dimension d = ((Component)target).getSize();
+ if (g instanceof Graphics2D ||
+ g instanceof sun.awt.Graphics2Delegate) {
+ // background color is setup correctly, so just use clearRect
+ g.clearRect(0, 0, d.width, d.height);
+ } else {
+ // emulate clearRect
+ g.setColor(((Component)target).getBackground());
+ g.fillRect(0, 0, d.width, d.height);
+ g.setColor(((Component)target).getForeground());
+ }
}
super.print(g);
}
@@ -147,4 +120,10 @@ class WCanvasPeer extends WComponentPeer implements CanvasPeer {
*/
private native void setNativeBackgroundErase(boolean doErase,
boolean doEraseOnResize);
+
+ public GraphicsConfiguration getAppropriateGraphicsConfiguration(
+ GraphicsConfiguration gc)
+ {
+ return gc;
+ }
}
diff --git a/src/windows/classes/sun/awt/windows/WChoicePeer.java b/src/windows/classes/sun/awt/windows/WChoicePeer.java
index 20ab610ff..b72e6f741 100644
--- a/src/windows/classes/sun/awt/windows/WChoicePeer.java
+++ b/src/windows/classes/sun/awt/windows/WChoicePeer.java
@@ -27,6 +27,10 @@ package sun.awt.windows;
import java.awt.*;
import java.awt.peer.*;
import java.awt.event.ItemEvent;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.awt.event.WindowAdapter;
+import sun.awt.SunToolkit;
class WChoicePeer extends WComponentPeer implements ChoicePeer {
@@ -70,6 +74,8 @@ class WChoicePeer extends WComponentPeer implements ChoicePeer {
public synchronized native void reshape(int x, int y, int width, int height);
+ private WindowListener windowListener;
+
// Toolkit & peer internals
WChoicePeer(Choice target) {
@@ -91,9 +97,38 @@ class WChoicePeer extends WComponentPeer implements ChoicePeer {
select(opt.getSelectedIndex());
}
}
+
+ Window parentWindow = SunToolkit.getContainingWindow((Component)target);
+ if (parentWindow != null) {
+ WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
+ if (wpeer != null) {
+ windowListener = new WindowAdapter() {
+ public void windowIconified(WindowEvent e) {
+ closeList();
+ }
+ public void windowClosing(WindowEvent e) {
+ closeList();
+ }
+ };
+ wpeer.addWindowListener(windowListener);
+ }
+ }
super.initialize();
}
+ protected void disposeImpl() {
+ // TODO: we should somehow reset the listener when the choice
+ // is moved to another toplevel without destroying its peer.
+ Window parentWindow = SunToolkit.getContainingWindow((Component)target);
+ if (parentWindow != null) {
+ WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
+ if (wpeer != null) {
+ wpeer.removeWindowListener(windowListener);
+ }
+ }
+ super.disposeImpl();
+ }
+
// native callbacks
void handleAction(final int index) {
@@ -121,4 +156,5 @@ class WChoicePeer extends WComponentPeer implements ChoicePeer {
return getMinimumSize();
}
+ native void closeList();
}
diff --git a/src/windows/classes/sun/awt/windows/WComponentPeer.java b/src/windows/classes/sun/awt/windows/WComponentPeer.java
index afbd170cc..6ad608452 100644
--- a/src/windows/classes/sun/awt/windows/WComponentPeer.java
+++ b/src/windows/classes/sun/awt/windows/WComponentPeer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc. 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
@@ -38,27 +38,32 @@ import java.awt.image.ColorModel;
import java.awt.event.PaintEvent;
import java.awt.event.InvocationEvent;
import java.awt.event.KeyEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.InputEvent;
import sun.awt.Win32GraphicsConfig;
+import sun.awt.Win32GraphicsEnvironment;
import sun.java2d.InvalidPipeException;
import sun.java2d.SurfaceData;
-import sun.java2d.d3d.D3DScreenUpdateManager;
-import static sun.java2d.d3d.D3DSurfaceData.*;
import sun.java2d.ScreenUpdateManager;
+import sun.java2d.d3d.D3DSurfaceData;
import sun.java2d.opengl.OGLSurfaceData;
+import sun.java2d.pipe.Region;
import sun.awt.DisplayChangedListener;
import sun.awt.PaintEventDispatcher;
+import sun.awt.SunToolkit;
import sun.awt.event.IgnorePaintEvent;
import java.awt.dnd.DropTarget;
import java.awt.dnd.peer.DropTargetPeer;
import sun.awt.ComponentAccessor;
-
import java.util.logging.*;
public abstract class WComponentPeer extends WObjectPeer
- implements ComponentPeer, DropTargetPeer, DisplayChangedListener
+ implements ComponentPeer, DropTargetPeer
{
/**
* Handle to native window
@@ -67,6 +72,7 @@ public abstract class WComponentPeer extends WObjectPeer
private static final Logger log = Logger.getLogger("sun.awt.windows.WComponentPeer");
private static final Logger shapeLog = Logger.getLogger("sun.awt.windows.shape.WComponentPeer");
+ private static final Logger focusLog = Logger.getLogger("sun.awt.windows.focus.WComponentPeer");
// ComponentPeer implementation
SurfaceData surfaceData;
@@ -186,7 +192,7 @@ public abstract class WComponentPeer extends WObjectPeer
cont.invalidate();
cont.validate();
- if (surfaceData instanceof D3DWindowSurfaceData ||
+ if (surfaceData instanceof D3DSurfaceData.D3DWindowSurfaceData ||
surfaceData instanceof OGLSurfaceData)
{
// When OGL or D3D is enabled, it is necessary to
@@ -258,7 +264,7 @@ public abstract class WComponentPeer extends WObjectPeer
int[] pix = createPrintedPixels(0, startY, totalW, h);
if (pix != null) {
BufferedImage bim = new BufferedImage(totalW, h,
- BufferedImage.TYPE_INT_RGB);
+ BufferedImage.TYPE_INT_ARGB);
bim.setRGB(0, 0, totalW, h, pix, 0, totalW);
g.drawImage(bim, 0, startY, null);
bim.flush();
@@ -295,14 +301,35 @@ public abstract class WComponentPeer extends WObjectPeer
// on handling '\n' to prevent it from being passed to native code
public boolean handleJavaKeyEvent(KeyEvent e) { return false; }
+ public void handleJavaMouseEvent(MouseEvent e) {
+ switch (e.getID()) {
+ case MouseEvent.MOUSE_PRESSED:
+ // Note that Swing requests focus in its own mouse event handler.
+ if (target == e.getSource() &&
+ !((Component)target).isFocusOwner() &&
+ WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
+ {
+ WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
+ CausedFocusEvent.Cause.MOUSE_EVENT);
+ }
+ break;
+ }
+ }
+
native void nativeHandleEvent(AWTEvent e);
public void handleEvent(AWTEvent e) {
int id = e.getID();
- if (((Component)target).isEnabled() && (e instanceof KeyEvent) && !((KeyEvent)e).isConsumed()) {
- if (handleJavaKeyEvent((KeyEvent)e)) {
- return;
+ if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() &&
+ ((Component)target).isEnabled())
+ {
+ if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) {
+ handleJavaMouseEvent((MouseEvent) e);
+ } else if (e instanceof KeyEvent) {
+ if (handleJavaKeyEvent((KeyEvent)e)) {
+ return;
+ }
}
}
@@ -318,6 +345,9 @@ public abstract class WComponentPeer extends WObjectPeer
paintArea.paint(target,shouldClearRectBeforePaint());
}
return;
+ case FocusEvent.FOCUS_LOST:
+ case FocusEvent.FOCUS_GAINED:
+ handleJavaFocusEvent((FocusEvent)e);
default:
break;
}
@@ -326,6 +356,13 @@ public abstract class WComponentPeer extends WObjectPeer
nativeHandleEvent(e);
}
+ void handleJavaFocusEvent(FocusEvent fe) {
+ if (focusLog.isLoggable(Level.FINER)) focusLog.finer(fe.toString());
+ setFocus(fe.getID() == FocusEvent.FOCUS_GAINED);
+ }
+
+ native void setFocus(boolean doSetFocus);
+
public Dimension getMinimumSize() {
return ((Component)target).getSize();
}
@@ -451,15 +488,8 @@ public abstract class WComponentPeer extends WObjectPeer
}
}
- /**
- * From the DisplayChangedListener interface.
- *
- * Called after a change in the display mode. This event
- * triggers replacing the surfaceData object (since that object
- * reflects the current display depth information, which has
- * just changed).
- */
- public void displayChanged() {
+ public void updateGraphicsData(GraphicsConfiguration gc) {
+ winGraphicsConfig = (Win32GraphicsConfig)gc;
try {
replaceSurfaceData();
} catch (InvalidPipeException e) {
@@ -467,13 +497,6 @@ public abstract class WComponentPeer extends WObjectPeer
}
}
- /**
- * Part of the DisplayChangedListener interface: components
- * do not need to react to this event
- */
- public void paletteChanged() {
- }
-
//This will return null for Components not yet added to a Container
public ColorModel getColorModel() {
GraphicsConfiguration gc = getGraphicsConfiguration();
@@ -585,22 +608,64 @@ public abstract class WComponentPeer extends WObjectPeer
WGlobalCursorManager.getCursorManager().updateCursorImmediately();
}
- native static boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant,
- boolean temporary, boolean focusedWindowChangeAllowed,
- long time);
- public boolean requestFocus
- (Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) {
- if (processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
- focusedWindowChangeAllowed, time)) {
+ // TODO: consider moving it to KeyboardFocusManagerPeerImpl
+ public boolean requestFocus(Component lightweightChild, boolean temporary,
+ boolean focusedWindowChangeAllowed, long time,
+ CausedFocusEvent.Cause cause)
+ {
+ if (WKeyboardFocusManagerPeer.
+ processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
+ focusedWindowChangeAllowed, time))
+ {
return true;
- } else {
- return _requestFocus(lightweightChild, temporary, focusedWindowChangeAllowed, time, cause);
}
+
+ int result = WKeyboardFocusManagerPeer
+ .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
+ temporary, focusedWindowChangeAllowed,
+ time, cause);
+
+ switch (result) {
+ case WKeyboardFocusManagerPeer.SNFH_FAILURE:
+ return false;
+ case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
+ if (focusLog.isLoggable(Level.FINER)) {
+ focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
+ }
+ Window parentWindow = SunToolkit.getContainingWindow((Component)target);
+ if (parentWindow == null) {
+ return rejectFocusRequestHelper("WARNING: Parent window is null");
+ }
+ WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
+ if (wpeer == null) {
+ return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
+ }
+ boolean res = wpeer.requestWindowFocus(cause);
+
+ if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Requested window focus: " + res);
+ // If parent window can be made focused and has been made focused(synchronously)
+ // then we can proceed with children, otherwise we retreat.
+ if (!(res && parentWindow.isFocused())) {
+ return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
+ }
+ return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
+ (Component)target,
+ temporary,
+ focusedWindowChangeAllowed,
+ time, cause);
+
+ case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
+ // Either lightweight or excessive request - all events are generated.
+ return true;
+ }
+ return false;
+ }
+
+ private boolean rejectFocusRequestHelper(String logMsg) {
+ if (focusLog.isLoggable(Level.FINER)) focusLog.finer(logMsg);
+ WKeyboardFocusManagerPeer.removeLastFocusRequest((Component)target);
+ return false;
}
- public native boolean _requestFocus
- (Component lightweightChild, boolean temporary,
- boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause);
public Image createImage(ImageProducer producer) {
return new ToolkitImage(producer);
@@ -713,7 +778,7 @@ public abstract class WComponentPeer extends WObjectPeer
* NOTE: This is called on the privileged toolkit thread. Do not
* call directly into user code using this thread!
*/
- void handlePaint(int x, int y, int w, int h) {
+ public void handlePaint(int x, int y, int w, int h) {
postPaintIfNecessary(x, y, w, h);
}
@@ -731,9 +796,12 @@ public abstract class WComponentPeer extends WObjectPeer
* Post an event. Queue it for execution by the callback thread.
*/
void postEvent(AWTEvent event) {
+ preprocessPostEvent(event);
WToolkit.postEvent(WToolkit.targetToAppContext(target), event);
}
+ void preprocessPostEvent(AWTEvent event) {}
+
// Routines to support deferred window positioning.
public void beginLayout() {
// Skip all painting till endLayout
@@ -895,25 +963,6 @@ public abstract class WComponentPeer extends WObjectPeer
public void setBoundsOperation(int operation) {
}
-
- native void setRectangularShape(int lox, int loy, int hix, int hiy,
- sun.java2d.pipe.Region region);
-
-
- // REMIND: Temp workaround for issues with using HW acceleration
- // in the browser on Vista when DWM is enabled.
- // @return true if the toplevel container is not an EmbeddedFrame or
- // if this EmbeddedFrame is acceleration capable, false otherwise
- private static final boolean isContainingTopLevelAccelCapable(Component c) {
- while (c != null && !(c instanceof WEmbeddedFrame)) {
- c = c.getParent();
- }
- if (c == null) {
- return true;
- }
- return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
- }
-
/**
* Returns whether this component is capable of being hw accelerated.
* More specifically, whether rendering to this component or a
@@ -928,28 +977,36 @@ public abstract class WComponentPeer extends WObjectPeer
* @see com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT
*/
public boolean isAccelCapable() {
- // REMIND: Temp workaround for issues with using HW acceleration
- // in the browser on Vista when DWM is enabled
- if (!isContainingTopLevelAccelCapable((Component)target)) {
- return false;
- }
-
- // REMIND: translucent windows support-related
-/*
boolean isTranslucent =
SunToolkit.isContainingTopLevelTranslucent((Component)target);
// D3D/OGL and translucent windows interacted poorly in Windows XP;
// these problems are no longer present in Vista
return !isTranslucent || Win32GraphicsEnvironment.isVistaOS();
-*/
- return true;
+ }
+
+ native void setRectangularShape(int lox, int loy, int hix, int hiy,
+ Region region);
+
+
+ // REMIND: Temp workaround for issues with using HW acceleration
+ // in the browser on Vista when DWM is enabled.
+ // @return true if the toplevel container is not an EmbeddedFrame or
+ // if this EmbeddedFrame is acceleration capable, false otherwise
+ private static final boolean isContainingTopLevelAccelCapable(Component c) {
+ while (c != null && !(c instanceof WEmbeddedFrame)) {
+ c = c.getParent();
+ }
+ if (c == null) {
+ return true;
+ }
+ return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
}
/**
* Applies the shape to the native component window.
* @since 1.7
*/
- public void applyShape(sun.java2d.pipe.Region shape) {
+ public void applyShape(Region shape) {
if (shapeLog.isLoggable(Level.FINER)) {
shapeLog.finer(
"*** INFO: Setting shape: PEER: " + this
@@ -965,4 +1022,15 @@ public abstract class WComponentPeer extends WObjectPeer
}
}
+ /**
+ * Lowers this component at the bottom of the above component. If the above parameter
+ * is null then the method places this component at the top of the Z-order.
+ */
+ public void setZOrder(ComponentPeer above) {
+ long aboveHWND = (above != null) ? ((WComponentPeer)above).getHWnd() : 0;
+
+ setZOrder(aboveHWND);
+ }
+
+ private native void setZOrder(long above);
}
diff --git a/src/windows/classes/sun/awt/windows/WFileDialogPeer.java b/src/windows/classes/sun/awt/windows/WFileDialogPeer.java
index 548dc3d41..1c90ae2e5 100644
--- a/src/windows/classes/sun/awt/windows/WFileDialogPeer.java
+++ b/src/windows/classes/sun/awt/windows/WFileDialogPeer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc. 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
@@ -231,17 +231,9 @@ public class WFileDialogPeer extends WWindowPeer implements FileDialogPeer {
*/
private static native void initIDs();
- /**
- * WFileDialogPeer doesn't have native pData so we don't do restack on it
- * @see java.awt.peer.ContainerPeer#restack
- */
- public void restack() {
- }
-
- /**
- * @see java.awt.peer.ContainerPeer#isRestackSupported
- */
- public boolean isRestackSupported() {
- return false;
- }
+ // The effects are not supported for system dialogs.
+ public void applyShape(sun.java2d.pipe.Region shape) {}
+ public void setOpacity(float opacity) {}
+ public void setOpaque(boolean isOpaque) {}
+ public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
}
diff --git a/src/windows/classes/sun/awt/windows/WFramePeer.java b/src/windows/classes/sun/awt/windows/WFramePeer.java
index 2353daf3d..79bf6b77e 100644
--- a/src/windows/classes/sun/awt/windows/WFramePeer.java
+++ b/src/windows/classes/sun/awt/windows/WFramePeer.java
@@ -25,27 +25,46 @@
package sun.awt.windows;
import java.util.Vector;
+
import java.awt.*;
import java.awt.peer.*;
import java.awt.image.ImageObserver;
-import sun.awt.image.ImageRepresentation;
-import sun.awt.image.IntegerComponentRaster;
-import sun.awt.image.ToolkitImage;
+
import java.awt.image.Raster;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.BufferedImage;
-import sun.awt.im.*;
-import sun.awt.Win32GraphicsDevice;
+
import java.awt.image.ColorModel;
+import sun.awt.image.ImageRepresentation;
+import sun.awt.image.IntegerComponentRaster;
+import sun.awt.image.ToolkitImage;
+import sun.awt.im.*;
+import sun.awt.Win32GraphicsDevice;
+import sun.awt.AWTAccessor;
class WFramePeer extends WWindowPeer implements FramePeer {
+ static {
+ initIDs();
+ }
+
+ // initialize JNI field and method IDs
+ private static native void initIDs();
+
// FramePeer implementation
public native void setState(int state);
public native int getState();
+ // sync target and peer
+ public void setExtendedState(int state) {
+ AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
+ }
+ public int getExtendedState() {
+ return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target);
+ }
+
// Convenience methods to save us from trouble of extracting
// Rectangle fields in native code.
private native void setMaximizedBounds(int x, int y, int w, int h);
diff --git a/src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java b/src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java
new file mode 100644
index 000000000..892899603
--- /dev/null
+++ b/src/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package sun.awt.windows;
+
+import java.awt.KeyboardFocusManager;
+import java.awt.Window;
+import java.awt.Component;
+import java.awt.peer.ComponentPeer;
+import sun.awt.KeyboardFocusManagerPeerImpl;
+import sun.awt.CausedFocusEvent;
+
+class WKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
+ static native void setNativeFocusOwner(ComponentPeer peer);
+ static native Component getNativeFocusOwner();
+ static native Window getNativeFocusedWindow();
+
+ WKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
+ super(manager);
+ }
+
+ @Override
+ public void setCurrentFocusOwner(Component comp) {
+ setNativeFocusOwner(comp != null ? comp.getPeer() : null);
+ }
+
+ @Override
+ public Component getCurrentFocusOwner() {
+ return getNativeFocusOwner();
+ }
+
+ @Override
+ public Window getCurrentFocusedWindow() {
+ return getNativeFocusedWindow();
+ }
+
+ public static boolean deliverFocus(Component lightweightChild,
+ Component target,
+ boolean temporary,
+ boolean focusedWindowChangeAllowed,
+ long time,
+ CausedFocusEvent.Cause cause)
+ {
+ // TODO: do something to eliminate this forwarding
+ return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
+ target,
+ temporary,
+ focusedWindowChangeAllowed,
+ time,
+ cause,
+ getNativeFocusOwner());
+ }
+}
diff --git a/src/windows/classes/sun/awt/windows/WPanelPeer.java b/src/windows/classes/sun/awt/windows/WPanelPeer.java
index 8a0d7ffbc..10ca42314 100644
--- a/src/windows/classes/sun/awt/windows/WPanelPeer.java
+++ b/src/windows/classes/sun/awt/windows/WPanelPeer.java
@@ -100,34 +100,6 @@ class WPanelPeer extends WCanvasPeer implements PanelPeer {
return getInsets();
}
- /*
- * From the DisplayChangedListener interface. Often is
- * up-called from a WWindowPeer instance.
- */
- public void displayChanged() {
- super.displayChanged();
- displayChanged((Container)target);
- }
-
- /*
- * Recursively iterates through all the HW and LW children
- * of the container and calls displayChanged() for HW peers.
- * Iteration through children peers only is not enough as the
- * displayChanged notification may not be propagated to HW
- * components inside LW containers, see 4452373 for details.
- */
- private static void displayChanged(Container target) {
- Component children[] = ((Container)target).getComponents();
- for (Component child : children) {
- ComponentPeer cpeer = child.getPeer();
- if (cpeer instanceof WComponentPeer) {
- ((WComponentPeer)cpeer).displayChanged();
- } else if (child instanceof Container) {
- displayChanged((Container)child);
- }
- }
- }
-
private native void pRestack(Object[] peers);
private void restack(Container cont, Vector peers) {
for (int i = 0; i < cont.getComponentCount(); i++) {
diff --git a/src/windows/classes/sun/awt/windows/WPrintDialogPeer.java b/src/windows/classes/sun/awt/windows/WPrintDialogPeer.java
index c1e06f53c..90ca88279 100644
--- a/src/windows/classes/sun/awt/windows/WPrintDialogPeer.java
+++ b/src/windows/classes/sun/awt/windows/WPrintDialogPeer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1999-2009 Sun Microsystems, Inc. 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
@@ -143,17 +143,9 @@ public class WPrintDialogPeer extends WWindowPeer implements DialogPeer {
*/
private static native void initIDs();
- /**
- * WPrintDialogPeer doesn't have native pData so we don't do restack on it
- * @see java.awt.peer.ContainerPeer#restack
- */
- public void restack() {
- }
-
- /**
- * @see java.awt.peer.ContainerPeer#isRestackSupported
- */
- public boolean isRestackSupported() {
- return false;
- }
+ // The effects are not supported for system dialogs.
+ public void applyShape(sun.java2d.pipe.Region shape) {}
+ public void setOpacity(float opacity) {}
+ public void setOpaque(boolean isOpaque) {}
+ public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
}
diff --git a/src/windows/classes/sun/awt/windows/WScrollPanePeer.java b/src/windows/classes/sun/awt/windows/WScrollPanePeer.java
index 70b3725cf..2e8c5e60b 100644
--- a/src/windows/classes/sun/awt/windows/WScrollPanePeer.java
+++ b/src/windows/classes/sun/awt/windows/WScrollPanePeer.java
@@ -269,10 +269,4 @@ class WScrollPanePeer extends WPanelPeer implements ScrollPanePeer {
}
}
- /**
- * @see java.awt.peer.ContainerPeer#restack
- */
- public void restack() {
- // Since ScrollPane can only have one child its restacking does nothing.
- }
}
diff --git a/src/windows/classes/sun/awt/windows/WToolkit.java b/src/windows/classes/sun/awt/windows/WToolkit.java
index 55c1dde09..62011b9b8 100644
--- a/src/windows/classes/sun/awt/windows/WToolkit.java
+++ b/src/windows/classes/sun/awt/windows/WToolkit.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc. 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
@@ -494,6 +494,12 @@ public class WToolkit extends SunToolkit implements Runnable {
return true;
}
+ public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
+ throws HeadlessException
+ {
+ return new WKeyboardFocusManagerPeer(manager);
+ }
+
protected native void setDynamicLayoutNative(boolean b);
public void setDynamicLayout(boolean b) {
@@ -975,4 +981,34 @@ public class WToolkit extends SunToolkit implements Runnable {
public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
return areExtraMouseButtonsEnabled;
}
+
+ @Override
+ public boolean isWindowOpacitySupported() {
+ // supported in Win2K and later
+ return true;
+ }
+
+ @Override
+ public boolean isWindowShapingSupported() {
+ return true;
+ }
+
+ @Override
+ public boolean isWindowTranslucencySupported() {
+ // supported in Win2K and later
+ return true;
+ }
+
+ @Override
+ public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
+ //XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
+ return true;
+ }
+
+ // On MS Windows one must use the peer.updateWindow() to implement
+ // non-opaque windows.
+ @Override
+ public boolean needUpdateWindow() {
+ return true;
+ }
}
diff --git a/src/windows/classes/sun/awt/windows/WWindowPeer.java b/src/windows/classes/sun/awt/windows/WWindowPeer.java
index 6afdb2be6..3c6240209 100644
--- a/src/windows/classes/sun/awt/windows/WWindowPeer.java
+++ b/src/windows/classes/sun/awt/windows/WWindowPeer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc. 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
@@ -31,19 +31,19 @@ import java.awt.peer.*;
import java.beans.*;
-import java.lang.ref.*;
import java.lang.reflect.*;
-import java.security.*;
-
import java.util.*;
import java.util.List;
import java.util.logging.*;
import sun.awt.*;
-import sun.awt.image.*;
-public class WWindowPeer extends WPanelPeer implements WindowPeer {
+import sun.java2d.pipe.Region;
+
+public class WWindowPeer extends WPanelPeer implements WindowPeer,
+ DisplayChangedListener
+{
private static final Logger log = Logger.getLogger("sun.awt.windows.WWindowPeer");
private static final Logger screenLog = Logger.getLogger("sun.awt.windows.screen.WWindowPeer");
@@ -52,6 +52,10 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
// extends WWindowPeer, not WDialogPeer
private WWindowPeer modalBlocker = null;
+ private boolean isOpaque;
+
+ private volatile TranslucentWindowPainter painter;
+
/*
* A key used for storing a list of active windows in AppContext. The value
* is a list of windows, sorted by the time of activation: later a window is
@@ -73,6 +77,12 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
private final static PropertyChangeListener guiDisposedListener =
new GuiDisposedListener();
+ /*
+ * Called (on the Toolkit thread) before the appropriate
+ * WindowStateEvent is posted to the EventQueue.
+ */
+ private WindowListener windowListener;
+
/**
* Initialize JNI field IDs
*/
@@ -91,9 +101,18 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
l.remove(this);
}
}
+
// Remove ourself from the Map of DisplayChangeListeners
GraphicsConfiguration gc = getGraphicsConfiguration();
((Win32GraphicsDevice)gc.getDevice()).removeDisplayChangedListener(this);
+
+ TranslucentWindowPainter currentPainter = painter;
+ if (currentPainter != null) {
+ currentPainter.flush();
+ // don't set the current one to null here; reduces the chances of
+ // MT issues (like NPEs)
+ }
+
super.disposeImpl();
}
@@ -158,6 +177,10 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
initActiveWindowsTracking((Window)target);
updateIconImages();
+
+ updateShape();
+ updateOpacity();
+ updateOpaque();
}
native void createAwtWindow(WComponentPeer parent);
@@ -183,7 +206,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
// super.displayChanged() in WWindowPeer.displayChanged() regardless of whether
// GraphicsDevice was really changed, or not. So we need to track it here.
updateGC();
- resetTargetGC();
realShow();
updateMinimumSize();
@@ -191,6 +213,8 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
if (((Window)target).isAlwaysOnTopSupported() && alwaysOnTop) {
setAlwaysOnTop(alwaysOnTop);
}
+
+ updateWindow(null);
}
// Synchronize the insets members (here & in helper) with actual window
@@ -214,27 +238,64 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
int[] smallIconRaster, int smw, int smh);
synchronized native void reshapeFrame(int x, int y, int width, int height);
- public boolean requestWindowFocus() {
- // Win32 window doesn't need this
- return false;
+
+ public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
+ if (!focusAllowedFor()) {
+ return false;
+ }
+ return requestWindowFocus(cause == CausedFocusEvent.Cause.MOUSE_EVENT);
}
+ public native boolean requestWindowFocus(boolean isMouseEventCause);
public boolean focusAllowedFor() {
- Window target = (Window)this.target;
- if (!target.isVisible() ||
- !target.isEnabled() ||
- !target.isFocusable())
+ Window window = (Window)this.target;
+ if (!window.isVisible() ||
+ !window.isEnabled() ||
+ !window.isFocusableWindow())
{
return false;
}
-
if (isModalBlocked()) {
return false;
}
-
return true;
}
+ public void hide() {
+ WindowListener listener = windowListener;
+ if (listener != null) {
+ // We're not getting WINDOW_CLOSING from the native code when hiding
+ // the window programmatically. So, create it and notify the listener.
+ listener.windowClosing(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
+ }
+ super.hide();
+ }
+
+ // WARNING: it's called on the Toolkit thread!
+ void preprocessPostEvent(AWTEvent event) {
+ if (event instanceof WindowEvent) {
+ WindowListener listener = windowListener;
+ if (listener != null) {
+ switch(event.getID()) {
+ case WindowEvent.WINDOW_CLOSING:
+ listener.windowClosing((WindowEvent)event);
+ break;
+ case WindowEvent.WINDOW_ICONIFIED:
+ listener.windowIconified((WindowEvent)event);
+ break;
+ }
+ }
+ }
+ }
+
+ synchronized void addWindowListener(WindowListener l) {
+ windowListener = AWTEventMulticaster.add(windowListener, l);
+ }
+
+ synchronized void removeWindowListener(WindowListener l) {
+ windowListener = AWTEventMulticaster.remove(windowListener, l);
+ }
+
public void updateMinimumSize() {
Dimension minimumSize = null;
if (((Component)target).isMinimumSizeSet()) {
@@ -273,6 +334,31 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
}
}
+ private void updateShape() {
+ // Shape shape = ((Window)target).getShape();
+ Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
+ if (shape != null) {
+ applyShape(Region.getInstance(shape, null));
+ }
+ }
+
+ private void updateOpacity() {
+ // float opacity = ((Window)target).getOpacity();
+ float opacity = AWTAccessor.getWindowAccessor().getOpacity((Window)target);
+ if (opacity < 1.0f) {
+ setOpacity(opacity);
+ }
+ }
+
+ private void updateOpaque() {
+ this.isOpaque = true;
+ // boolean opaque = ((Window)target).isOpaque();
+ boolean opaque = AWTAccessor.getWindowAccessor().isOpaque((Window)target);
+ if (!opaque) {
+ setOpaque(opaque);
+ }
+ }
+
native void setMinSize(int width, int height);
/*
@@ -358,14 +444,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
});
}
-
- /*
- * Called from WCanvasPeer.displayChanged().
- * Override to do nothing - Window and WWindowPeer GC must never be set to
- * null!
- */
- void clearLocalGC() {}
-
public void updateGC() {
int scrn = getScreenImOn();
if (screenLog.isLoggable(Level.FINER)) {
@@ -404,18 +482,36 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
oldDev.removeDisplayChangedListener(this);
newDev.addDisplayChangedListener(this);
}
+
+ SunToolkit.executeOnEventHandlerThread((Component)target,
+ new Runnable() {
+ public void run() {
+ AWTAccessor.getComponentAccessor().
+ setGraphicsConfiguration((Component)target, winGraphicsConfig);
+ }
+ });
}
- /*
- * From the DisplayChangedListener interface
+ /**
+ * From the DisplayChangedListener interface.
*
* This method handles a display change - either when the display settings
* are changed, or when the window has been dragged onto a different
* display.
+ * Called after a change in the display mode. This event
+ * triggers replacing the surfaceData object (since that object
+ * reflects the current display depth information, which has
+ * just changed).
*/
public void displayChanged() {
updateGC();
- super.displayChanged();
+ }
+
+ /**
+ * Part of the DisplayChangedListener interface: components
+ * do not need to react to this event
+ */
+ public void paletteChanged() {
}
private native int getScreenImOn();
@@ -451,8 +547,10 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
private volatile int sysH = 0;
Rectangle constrainBounds(int x, int y, int width, int height) {
+ GraphicsConfiguration gc = this.winGraphicsConfig;
+
// We don't restrict the setBounds() operation if the code is trusted.
- if (!hasWarningWindow()) {
+ if (!hasWarningWindow() || gc == null) {
return new Rectangle(x, y, width, height);
}
@@ -461,24 +559,24 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
int newW = width;
int newH = height;
- GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
- Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
+ Insets sIn = Toolkit.getDefaultToolkit().getScreenInsets(gc);
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// If it's undecorated or is not currently visible
- if (!((Window)target).isVisible() || isTargetUndecorated()) {
+ if (!AWTAccessor.getComponentAccessor().isVisible_NoClientCode(
+ (Component)target) || isTargetUndecorated())
+ {
// Now check each point is within the visible part of the screen
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
- // First make sure the size is withing the visible part of the screen
+ // First make sure the size is within the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
-
if (newH > screenH) {
newH = screenH;
}
@@ -489,7 +587,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
-
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
@@ -504,7 +601,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
if (newW > maxW) {
newW = maxW;
}
-
if (newH > maxH) {
newH = maxH;
}
@@ -513,6 +609,8 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
return new Rectangle(newX, newY, newW, newH);
}
+ public native void repositionSecurityWarning();
+
@Override
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
@@ -525,6 +623,135 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer {
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
}
+ @Override
+ public void print(Graphics g) {
+ // We assume we print the whole frame,
+ // so we expect no clip was set previously
+ Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
+ if (shape != null) {
+ g.setClip(shape);
+ }
+ super.print(g);
+ }
+
+ private void replaceSurfaceDataRecursively(Component c) {
+ if (c instanceof Container) {
+ for (Component child : ((Container)c).getComponents()) {
+ replaceSurfaceDataRecursively(child);
+ }
+ }
+ ComponentPeer cp = c.getPeer();
+ if (cp instanceof WComponentPeer) {
+ ((WComponentPeer)cp).replaceSurfaceDataLater();
+ }
+ }
+
+ private native void setOpacity(int iOpacity);
+
+ public void setOpacity(float opacity) {
+ if (!((SunToolkit)((Window)target).getToolkit()).
+ isWindowOpacitySupported())
+ {
+ return;
+ }
+
+ replaceSurfaceDataRecursively((Component)getTarget());
+
+ final int maxOpacity = 0xff;
+ int iOpacity = (int)(opacity * maxOpacity);
+ if (iOpacity < 0) {
+ iOpacity = 0;
+ }
+ if (iOpacity > maxOpacity) {
+ iOpacity = maxOpacity;
+ }
+
+ setOpacity(iOpacity);
+ updateWindow(null);
+ }
+
+ private native void setOpaqueImpl(boolean isOpaque);
+
+ public void setOpaque(boolean isOpaque) {
+ Window target = (Window)getTarget();
+
+ SunToolkit sunToolkit = (SunToolkit)target.getToolkit();
+ if (!sunToolkit.isWindowTranslucencySupported() ||
+ !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration()))
+ {
+ return;
+ }
+
+ boolean opaqueChanged = this.isOpaque != isOpaque;
+ boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS();
+
+ if (opaqueChanged && !isVistaOS){
+ // non-Vista OS: only replace the surface data if the opacity
+ // status changed (see WComponentPeer.isAccelCapable() for more)
+ replaceSurfaceDataRecursively(target);
+ }
+
+ this.isOpaque = isOpaque;
+
+ setOpaqueImpl(isOpaque);
+
+ if (opaqueChanged) {
+ if (isOpaque) {
+ TranslucentWindowPainter currentPainter = painter;
+ if (currentPainter != null) {
+ currentPainter.flush();
+ painter = null;
+ }
+ } else {
+ painter = TranslucentWindowPainter.createInstance(this);
+ }
+ }
+
+ if (opaqueChanged && isVistaOS) {
+ // On Vista: setting the window non-opaque makes the window look
+ // rectangular, though still catching the mouse clicks within
+ // its shape only. To restore the correct visual appearance
+ // of the window (i.e. w/ the correct shape) we have to reset
+ // the shape.
+ Shape shape = AWTAccessor.getWindowAccessor().getShape(target);
+ if (shape != null) {
+ AWTAccessor.getWindowAccessor().setShape(target, shape);
+ }
+ }
+
+ updateWindow(null);
+ }
+
+ public native void updateWindowImpl(int[] data, int width, int height);
+
+ public void updateWindow(BufferedImage backBuffer) {
+ if (isOpaque) {
+ return;
+ }
+
+ TranslucentWindowPainter currentPainter = painter;
+ if (currentPainter != null) {
+ currentPainter.updateWindow(backBuffer);
+ } else if (log.isLoggable(Level.FINER)) {
+ log.log(Level.FINER,
+ "Translucent window painter is null in updateWindow");
+ }
+ }
+
+ /**
+ * Paints the Applet Warning into the passed Graphics2D. This method is
+ * called by the TranslucentWindowPainter before updating the layered
+ * window.
+ *
+ * @param g Graphics context to paint the warning to
+ * @param w the width of the area
+ * @param h the height of the area
+ * @see TranslucentWindowPainter
+ */
+ public void paintAppletWarning(Graphics2D g, int w, int h) {
+ // REMIND: the applet warning needs to be painted here
+ }
+
/*
* The method maps the list of the active windows to the window's AppContext,
* then the method registers ActiveWindowListener, GuiDisposedListener listeners;
diff --git a/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java b/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java
index b3b0fa8d5..53ae895dd 100644
--- a/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java
+++ b/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2007-2009 Sun Microsystems, Inc. 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
@@ -37,6 +37,7 @@ import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import sun.awt.SunToolkit;
+import sun.awt.AWTAccessor;
import sun.awt.Win32GraphicsConfig;
import sun.awt.windows.WComponentPeer;
import sun.java2d.InvalidPipeException;
@@ -284,14 +285,12 @@ public class D3DScreenUpdateManager extends ScreenUpdateManager
* @param peer for which target's the repaint should be issued
*/
private void repaintPeerTarget(WComponentPeer peer) {
- // we don't want to call user code on our priveleged
- // thread, delegate to EDT
- final Component target = (Component)peer.getTarget();
- SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
- public void run() {
- target.repaint();
- }
- });
+ Component target = (Component)peer.getTarget();
+ Rectangle bounds = AWTAccessor.getComponentAccessor().getBounds(target);
+ // the system-level painting operations should call the handlePaint()
+ // method of the WComponentPeer class to repaint the component;
+ // calling repaint() forces AWT to make call to update()
+ peer.handlePaint(0, 0, bounds.width, bounds.height);
}
/**
diff --git a/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java b/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
index 27997aa8c..4164264a1 100644
--- a/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
+++ b/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2004-2009 Sun Microsystems, Inc. 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
@@ -72,9 +72,8 @@ public abstract class WGLSurfaceData extends OGLSurfaceData {
// the OGL pipeline can render directly to the screen and interfere
// with layered windows, which is why we don't allow accelerated
// surfaces in this case
- if (!peer.isAccelCapable())
- // REMIND: commented until toplevel translucency is implemented
-// || !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
+ if (!peer.isAccelCapable() ||
+ !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
{
return null;
}
@@ -93,9 +92,8 @@ public abstract class WGLSurfaceData extends OGLSurfaceData {
// the OGL pipeline can render directly to the screen and interfere
// with layered windows, which is why we don't allow accelerated
// surfaces in this case
- if (!peer.isAccelCapable())
- // REMIND: commented until toplevel translucency is implemented
-// || !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
+ if (!peer.isAccelCapable() ||
+ !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
{
return null;
}