4632N/A/*
5990N/A * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage sun.lwawt;
4632N/A
4632N/Aimport java.awt.*;
4632N/Aimport java.awt.event.*;
4632N/Aimport java.awt.image.BufferedImage;
4632N/Aimport java.awt.peer.*;
4632N/Aimport java.util.List;
4632N/A
4632N/Aimport javax.swing.*;
4632N/A
4632N/Aimport sun.awt.*;
4632N/Aimport sun.java2d.*;
4639N/Aimport sun.java2d.loops.Blit;
4639N/Aimport sun.java2d.loops.CompositeType;
5232N/Aimport sun.java2d.pipe.Region;
4717N/Aimport sun.util.logging.PlatformLogger;
4632N/A
4632N/Apublic class LWWindowPeer
4632N/A extends LWContainerPeer<Window, JComponent>
6407N/A implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
4632N/A{
4632N/A public static enum PeerType {
4632N/A SIMPLEWINDOW,
4632N/A FRAME,
4632N/A DIALOG,
5555N/A EMBEDDED_FRAME,
5555N/A VIEW_EMBEDDED_FRAME
4632N/A }
4632N/A
4886N/A private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
4717N/A
6060N/A private final PlatformWindow platformWindow;
4632N/A
4632N/A // Window bounds reported by the native system (as opposed to
4632N/A // regular bounds inherited from LWComponentPeer which are
4632N/A // requested by user and may haven't been applied yet because
4632N/A // of asynchronous requests to the windowing system)
4632N/A private int sysX;
4632N/A private int sysY;
4632N/A private int sysW;
4632N/A private int sysH;
4632N/A
4639N/A private static final int MINIMUM_WIDTH = 1;
4639N/A private static final int MINIMUM_HEIGHT = 1;
4639N/A
4632N/A private Insets insets = new Insets(0, 0, 0, 0);
4632N/A
5041N/A private GraphicsDevice graphicsDevice;
4632N/A private GraphicsConfiguration graphicsConfig;
4632N/A
4632N/A private SurfaceData surfaceData;
4686N/A private final Object surfaceDataLock = new Object();
4632N/A
4632N/A private int backBufferCount;
4632N/A private BufferCapabilities backBufferCaps;
4632N/A
4632N/A // The back buffer is used for two purposes:
4632N/A // 1. To render all the lightweight peers
4632N/A // 2. To provide user with a BufferStrategy
4632N/A // Need to check if a single back buffer can be used for both
4632N/A// TODO: VolatileImage
4632N/A// private VolatileImage backBuffer;
4632N/A private volatile BufferedImage backBuffer;
4632N/A
4632N/A private volatile int windowState = Frame.NORMAL;
4632N/A
4632N/A // A peer where the last mouse event came to. Used to generate
4632N/A // MOUSE_ENTERED/EXITED notifications and by cursor manager to
4632N/A // find the component under cursor
4632N/A private static volatile LWComponentPeer lastMouseEventPeer = null;
4632N/A
4632N/A // Peers where all dragged/released events should come to,
4632N/A // depending on what mouse button is being dragged according to Cocoa
4632N/A private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
4632N/A
4632N/A // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
4632N/A // on MOUSE_RELEASE. Click events are only generated if there were no drag
4632N/A // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
4632N/A private static int mouseClickButtons = 0;
4632N/A
4691N/A private volatile boolean isOpaque = true;
4632N/A
4691N/A private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
4639N/A
4665N/A private static LWWindowPeer grabbingWindow;
4665N/A
4717N/A private volatile boolean skipNextFocusChange;
4717N/A
5232N/A private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
5232N/A
5233N/A private volatile boolean textured;
5233N/A
5555N/A private final PeerType peerType;
5555N/A
6323N/A private final SecurityWarningWindow warningWindow;
6323N/A
4632N/A /**
4632N/A * Current modal blocker or null.
4632N/A *
4632N/A * Synchronization: peerTreeLock.
4632N/A */
4632N/A private LWWindowPeer blocker;
4632N/A
4632N/A public LWWindowPeer(Window target, PlatformComponent platformComponent,
5555N/A PlatformWindow platformWindow, PeerType peerType)
4632N/A {
4632N/A super(target, platformComponent);
4632N/A this.platformWindow = platformWindow;
5555N/A this.peerType = peerType;
4632N/A
4632N/A Window owner = target.getOwner();
4632N/A LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
4632N/A PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
4632N/A
4632N/A // The delegate.initialize() needs a non-null GC on X11.
4632N/A GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
4632N/A synchronized (getStateLock()) {
4632N/A // graphicsConfig should be updated according to the real window
4632N/A // bounds when the window is shown, see 4868278
4632N/A this.graphicsConfig = gc;
4632N/A }
4632N/A
4691N/A if (!target.isFontSet()) {
4691N/A target.setFont(DEFAULT_FONT);
4691N/A }
4691N/A
4691N/A if (!target.isBackgroundSet()) {
4691N/A target.setBackground(SystemColor.window);
4691N/A } else {
4691N/A // first we check if user provided alpha for background. This is
4691N/A // similar to what Apple's Java do.
4691N/A // Since JDK7 we should rely on setOpacity() only.
4691N/A // this.opacity = c.getAlpha();
4691N/A }
4691N/A
4691N/A if (!target.isForegroundSet()) {
4691N/A target.setForeground(SystemColor.windowText);
4691N/A // we should not call setForeground because it will call a repaint
4691N/A // which the peer may not be ready to do yet.
4691N/A }
4691N/A
4632N/A platformWindow.initialize(target, this, ownerDelegate);
6323N/A
6323N/A // Init warning window(for applets)
6323N/A SecurityWarningWindow warn = null;
6323N/A if (((Window)target).getWarningString() != null) {
6323N/A // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
6323N/A // and TrayIcon balloon windows without a warning window.
6323N/A if (!AWTAccessor.getWindowAccessor().isTrayIconWindow((Window)target)) {
6323N/A LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
6323N/A warn = toolkit.createSecurityWarning(target, this);
6323N/A }
6323N/A }
6323N/A
6323N/A warningWindow = warn;
4632N/A }
4632N/A
4632N/A @Override
5166N/A void initializeImpl() {
5166N/A super.initializeImpl();
4632N/A if (getTarget() instanceof Frame) {
5166N/A setTitle(((Frame) getTarget()).getTitle());
5166N/A setState(((Frame) getTarget()).getExtendedState());
4632N/A } else if (getTarget() instanceof Dialog) {
5166N/A setTitle(((Dialog) getTarget()).getTitle());
4632N/A }
4632N/A
5879N/A updateAlwaysOnTopState();
4632N/A updateMinimumSize();
4632N/A
5232N/A final Shape shape = getTarget().getShape();
5232N/A if (shape != null) {
5232N/A applyShape(Region.getInstance(shape, null));
5232N/A }
5232N/A
5166N/A final float opacity = getTarget().getOpacity();
5166N/A if (opacity < 1.0f) {
5166N/A setOpacity(opacity);
5166N/A }
5166N/A
4639N/A setOpaque(getTarget().isOpaque());
4632N/A
4767N/A updateInsets(platformWindow.getInsets());
5166N/A if (getSurfaceData() == null) {
5232N/A replaceSurfaceData(false);
5166N/A }
6093N/A activateDisplayListener();
4632N/A }
4632N/A
4632N/A // Just a helper method
4632N/A public PlatformWindow getPlatformWindow() {
4632N/A return platformWindow;
4632N/A }
4632N/A
4632N/A @Override
4632N/A protected LWWindowPeer getWindowPeerOrSelf() {
4632N/A return this;
4632N/A }
4632N/A
4632N/A @Override
4632N/A protected void initializeContainerPeer() {
4632N/A // No-op as LWWindowPeer doesn't have any containerPeer
4632N/A }
4632N/A
4632N/A // ---- PEER METHODS ---- //
4632N/A
4632N/A @Override
4632N/A protected void disposeImpl() {
6093N/A deactivateDisplayListener();
4639N/A SurfaceData oldData = getSurfaceData();
4686N/A synchronized (surfaceDataLock){
4686N/A surfaceData = null;
4686N/A }
4632N/A if (oldData != null) {
4632N/A oldData.invalidate();
4632N/A }
4665N/A if (isGrabbing()) {
4665N/A ungrab();
4665N/A }
6323N/A if (warningWindow != null) {
6323N/A warningWindow.dispose();
6323N/A }
4693N/A destroyBuffers();
4632N/A platformWindow.dispose();
4632N/A super.disposeImpl();
4632N/A }
4632N/A
4632N/A @Override
5166N/A protected void setVisibleImpl(final boolean visible) {
6323N/A if (!visible && warningWindow != null) {
6323N/A warningWindow.setVisible(false, false);
6323N/A }
6323N/A
5166N/A super.setVisibleImpl(visible);
4632N/A // TODO: update graphicsConfig, see 4868278
5166N/A platformWindow.setVisible(visible);
5166N/A if (isSimpleWindow()) {
5336N/A KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
4632N/A
5166N/A if (visible) {
5166N/A if (!getTarget().isAutoRequestFocus()) {
5166N/A return;
5166N/A } else {
5166N/A requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
5166N/A }
5336N/A } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
5166N/A // Transfer focus to the owner.
5166N/A LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
5166N/A if (owner != null) {
5166N/A owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
4632N/A }
4632N/A }
5166N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public GraphicsConfiguration getGraphicsConfiguration() {
4632N/A return graphicsConfig;
4632N/A }
4632N/A
4632N/A @Override
4632N/A public boolean updateGraphicsData(GraphicsConfiguration gc) {
4632N/A setGraphicsConfig(gc);
4632N/A return false;
4632N/A }
4632N/A
4686N/A protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
4639N/A if (getSurfaceData() == null) {
4639N/A return null;
4639N/A }
4632N/A if (fg == null) {
4632N/A fg = SystemColor.windowText;
4632N/A }
4632N/A if (bg == null) {
4632N/A bg = SystemColor.window;
4632N/A }
4632N/A if (f == null) {
4632N/A f = DEFAULT_FONT;
4632N/A }
4639N/A return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void createBuffers(int numBuffers, BufferCapabilities caps)
4632N/A throws AWTException
4632N/A {
4632N/A try {
4632N/A // Assume this method is never called with numBuffers <= 1, as 0 is
4632N/A // unsupported, and 1 corresponds to a SingleBufferStrategy which
4632N/A // doesn't depend on the peer. Screen is considered as a separate
4632N/A // "buffer", that's why numBuffers - 1
4632N/A assert numBuffers > 1;
4632N/A
5232N/A replaceSurfaceData(numBuffers - 1, caps, false);
4632N/A } catch (InvalidPipeException z) {
4632N/A throw new AWTException(z.toString());
4632N/A }
4632N/A }
4632N/A
4632N/A @Override
4693N/A public final Image getBackBuffer() {
4693N/A synchronized (getStateLock()) {
4693N/A return backBuffer;
4693N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void flip(int x1, int y1, int x2, int y2,
4632N/A BufferCapabilities.FlipContents flipAction)
4632N/A {
4869N/A final BufferedImage buffer = (BufferedImage)getBackBuffer();
4869N/A if (buffer == null) {
4869N/A throw new IllegalStateException("Buffers have not been created");
4869N/A }
4869N/A final Graphics g = getGraphics();
4869N/A try {
4869N/A g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
4869N/A } finally {
4869N/A g.dispose();
4869N/A }
4869N/A if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
4869N/A final Graphics2D bg = (Graphics2D) buffer.getGraphics();
4869N/A try {
4869N/A bg.setBackground(getBackground());
4869N/A bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
4869N/A } finally {
4869N/A bg.dispose();
4869N/A }
4869N/A }
4632N/A }
4632N/A
4632N/A @Override
4693N/A public final void destroyBuffers() {
4693N/A final Image oldBB = getBackBuffer();
4693N/A synchronized (getStateLock()) {
4693N/A backBuffer = null;
4693N/A }
4693N/A if (oldBB != null) {
4693N/A oldBB.flush();
4693N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setBounds(int x, int y, int w, int h, int op) {
5555N/A
5555N/A if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEW_EMBEDDED_FRAME) {
5555N/A return;
5555N/A }
5555N/A
4632N/A if ((op & SET_CLIENT_SIZE) != 0) {
4632N/A // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
4632N/A // instead of pulling 'insets' field up to LWComponentPeer
4632N/A // no need to add insets since Window's notion of width and height includes insets.
4632N/A op &= ~SET_CLIENT_SIZE;
4632N/A op |= SET_SIZE;
4632N/A }
4632N/A
4639N/A if (w < MINIMUM_WIDTH) {
4639N/A w = MINIMUM_WIDTH;
4639N/A }
4639N/A if (h < MINIMUM_HEIGHT) {
4639N/A h = MINIMUM_HEIGHT;
4639N/A }
4632N/A
5570N/A if (graphicsConfig instanceof TextureSizeConstraining) {
5570N/A final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
5570N/A final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
5570N/A
5570N/A if (w > maxW) {
5570N/A w = maxW;
5570N/A }
5570N/A if (h > maxH) {
5570N/A h = maxH;
5570N/A }
5570N/A }
5570N/A
4632N/A // Don't post ComponentMoved/Resized and Paint events
4632N/A // until we've got a notification from the delegate
4639N/A setBounds(x, y, w, h, op, false, false);
4632N/A // Get updated bounds, so we don't have to handle 'op' here manually
4632N/A Rectangle r = getBounds();
4632N/A platformWindow.setBounds(r.x, r.y, r.width, r.height);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public Point getLocationOnScreen() {
4632N/A return platformWindow.getLocationOnScreen();
4632N/A }
4632N/A
4639N/A /**
4632N/A * Overridden from LWContainerPeer to return the correct insets.
4632N/A * Insets are queried from the delegate and are kept up to date by
4632N/A * requiering when needed (i.e. when the window geometry is changed).
4632N/A */
4632N/A @Override
4632N/A public Insets getInsets() {
4632N/A synchronized (getStateLock()) {
4632N/A return insets;
4632N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public FontMetrics getFontMetrics(Font f) {
4632N/A // TODO: check for "use platform metrics" settings
4632N/A return platformWindow.getFontMetrics(f);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void toFront() {
4632N/A platformWindow.toFront();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void toBack() {
4632N/A platformWindow.toBack();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setZOrder(ComponentPeer above) {
4632N/A throw new RuntimeException("not implemented");
4632N/A }
4632N/A
4632N/A @Override
5879N/A public void updateAlwaysOnTopState() {
5879N/A platformWindow.setAlwaysOnTop(getTarget().isAlwaysOnTop());
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateFocusableWindowState() {
4632N/A platformWindow.updateFocusableWindowState();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setModalBlocked(Dialog blocker, boolean blocked) {
4632N/A synchronized (getPeerTreeLock()) {
4802N/A if(blocked && blocker.getPeer() instanceof LWWindowPeer) {
4802N/A this.blocker = (LWWindowPeer)blocker.getPeer();
4802N/A } else {
4802N/A this.blocker = null;
4802N/A }
4632N/A }
4996N/A
4996N/A platformWindow.setModalBlocked(blocked);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateMinimumSize() {
5570N/A final Dimension min;
4632N/A if (getTarget().isMinimumSizeSet()) {
5570N/A min = getTarget().getMinimumSize();
5570N/A min.width = Math.max(min.width, MINIMUM_WIDTH);
5570N/A min.height = Math.max(min.height, MINIMUM_HEIGHT);
5570N/A } else {
5570N/A min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
4632N/A }
5570N/A
5570N/A final int maxW, maxH;
5570N/A if (graphicsConfig instanceof TextureSizeConstraining) {
5570N/A maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
5570N/A maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
5570N/A } else {
5570N/A maxW = maxH = Integer.MAX_VALUE;
4632N/A }
5570N/A
5570N/A final Dimension max;
5570N/A if (getTarget().isMaximumSizeSet()) {
5570N/A max = getTarget().getMaximumSize();
5570N/A max.width = Math.min(max.width, maxW);
5570N/A max.height = Math.min(max.height, maxH);
5570N/A } else {
5570N/A max = new Dimension(maxW, maxH);
5570N/A }
5570N/A
5570N/A platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateIconImages() {
4632N/A getPlatformWindow().updateIconImages();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setOpacity(float opacity) {
4632N/A getPlatformWindow().setOpacity(opacity);
4767N/A repaintPeer();
4632N/A }
4632N/A
4632N/A @Override
4767N/A public final void setOpaque(final boolean isOpaque) {
4639N/A if (this.isOpaque != isOpaque) {
4639N/A this.isOpaque = isOpaque;
5232N/A updateOpaque();
4639N/A }
4639N/A }
4639N/A
5232N/A private void updateOpaque() {
5232N/A getPlatformWindow().setOpaque(!isTranslucent());
5232N/A replaceSurfaceData(false);
5232N/A repaintPeer();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateWindow() {
5232N/A }
5232N/A
5233N/A public final boolean isTextured() {
5233N/A return textured;
5233N/A }
5233N/A
5233N/A public final void setTextured(final boolean isTextured) {
5233N/A textured = isTextured;
5233N/A }
5233N/A
5232N/A public final boolean isTranslucent() {
5232N/A synchronized (getStateLock()) {
5233N/A /*
5233N/A * Textured window is a special case of translucent window.
5233N/A * The difference is only in nswindow background. So when we set
5233N/A * texture property our peer became fully translucent. It doesn't
5233N/A * fill background, create non opaque backbuffers and layer etc.
5233N/A */
5233N/A return !isOpaque || isShaped() || isTextured();
5232N/A }
5232N/A }
5232N/A
5232N/A @Override
5232N/A final void applyShapeImpl(final Region shape) {
5232N/A super.applyShapeImpl(shape);
5232N/A updateOpaque();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void repositionSecurityWarning() {
6323N/A if (warningWindow != null) {
6323N/A AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
6323N/A Window target = getTarget();
6323N/A int x = compAccessor.getX(target);
6323N/A int y = compAccessor.getY(target);
6323N/A int width = compAccessor.getWidth(target);
6323N/A int height = compAccessor.getHeight(target);
6323N/A warningWindow.reposition(x, y, width, height);
6323N/A }
4632N/A }
4632N/A
4632N/A // ---- FRAME PEER METHODS ---- //
4632N/A
4632N/A @Override // FramePeer and DialogPeer
4632N/A public void setTitle(String title) {
4632N/A platformWindow.setTitle(title == null ? "" : title);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setMenuBar(MenuBar mb) {
4632N/A platformWindow.setMenuBar(mb);
4632N/A }
4632N/A
4632N/A @Override // FramePeer and DialogPeer
4632N/A public void setResizable(boolean resizable) {
4632N/A platformWindow.setResizable(resizable);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setState(int state) {
4632N/A platformWindow.setWindowState(state);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public int getState() {
4632N/A return windowState;
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setMaximizedBounds(Rectangle bounds) {
4632N/A // TODO: not implemented
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setBoundsPrivate(int x, int y, int width, int height) {
4655N/A setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public Rectangle getBoundsPrivate() {
4632N/A throw new RuntimeException("not implemented");
4632N/A }
4632N/A
4632N/A // ---- DIALOG PEER METHODS ---- //
4632N/A
4632N/A @Override
4632N/A public void blockWindows(List<Window> windows) {
4632N/A //TODO: LWX will probably need some collectJavaToplevels to speed this up
4632N/A for (Window w : windows) {
4632N/A WindowPeer wp = (WindowPeer)w.getPeer();
4632N/A if (wp != null) {
4632N/A wp.setModalBlocked((Dialog)getTarget(), true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A // ---- PEER NOTIFICATIONS ---- //
4632N/A
6323N/A @Override
4632N/A public void notifyIconify(boolean iconify) {
4632N/A //The toplevel target is Frame and states are applicable to it.
4632N/A //Otherwise, the target is Window and it don't have state property.
4632N/A //Hopefully, no such events are posted in the queue so consider the
4632N/A //target as Frame in all cases.
4632N/A
4632N/A // REMIND: should we send it anyway if the state not changed since last
4632N/A // time?
4632N/A WindowEvent iconifyEvent = new WindowEvent(getTarget(),
4632N/A iconify ? WindowEvent.WINDOW_ICONIFIED
4632N/A : WindowEvent.WINDOW_DEICONIFIED);
4632N/A postEvent(iconifyEvent);
4632N/A
4632N/A int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL;
4632N/A postWindowStateChangedEvent(newWindowState);
4632N/A
4632N/A // REMIND: RepaintManager doesn't repaint iconified windows and
4632N/A // hence ignores any repaint request during deiconification.
4632N/A // So, we need to repaint window explicitly when it becomes normal.
4632N/A if (!iconify) {
4632N/A repaintPeer();
4632N/A }
4632N/A }
4632N/A
6323N/A @Override
4632N/A public void notifyZoom(boolean isZoomed) {
4632N/A int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
4632N/A postWindowStateChangedEvent(newWindowState);
4632N/A }
4632N/A
4639N/A /**
6056N/A * Called by the {@code PlatformWindow} when any part of the window should
6056N/A * be repainted.
4632N/A */
6323N/A @Override
6056N/A public final void notifyExpose(final Rectangle r) {
6056N/A repaintPeer(r);
4632N/A }
4632N/A
4639N/A /**
6056N/A * Called by the {@code PlatformWindow} when this window is moved/resized by
6060N/A * user or window insets are changed. There's no notifyReshape() in
6060N/A * LWComponentPeer as the only components which could be resized by user are
6060N/A * top-level windows.
4632N/A */
6323N/A @Override
4639N/A public final void notifyReshape(int x, int y, int w, int h) {
6056N/A final boolean moved;
6056N/A final boolean resized;
6060N/A final boolean invalid = updateInsets(platformWindow.getInsets());
4632N/A synchronized (getStateLock()) {
4632N/A moved = (x != sysX) || (y != sysY);
4632N/A resized = (w != sysW) || (h != sysH);
4632N/A sysX = x;
4632N/A sysY = y;
4632N/A sysW = w;
4632N/A sysH = h;
4632N/A }
4632N/A
4632N/A // Check if anything changed
6060N/A if (!moved && !resized && !invalid) {
4632N/A return;
4632N/A }
4632N/A // First, update peer's bounds
4639N/A setBounds(x, y, w, h, SET_BOUNDS, false, false);
4632N/A
4632N/A // Second, update the graphics config and surface data
6084N/A final boolean isNewDevice = updateGraphicsDevice();
6084N/A if (resized || isNewDevice) {
4632N/A replaceSurfaceData();
4632N/A }
4632N/A
6056N/A // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
6060N/A if (moved || invalid) {
4639N/A handleMove(x, y, true);
4632N/A }
6084N/A if (resized || invalid || isNewDevice) {
6056N/A handleResize(w, h, true);
6056N/A repaintPeer();
4639N/A }
6323N/A
6323N/A repositionSecurityWarning();
4639N/A }
4639N/A
4639N/A private void clearBackground(final int w, final int h) {
4639N/A final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
4639N/A getFont());
4639N/A if (g != null) {
4639N/A try {
5232N/A if (g instanceof Graphics2D) {
5232N/A ((Graphics2D) g).setComposite(AlphaComposite.Src);
5232N/A }
5232N/A if (isTranslucent()) {
5232N/A g.setColor(nonOpaqueBackground);
5232N/A g.fillRect(0, 0, w, h);
5232N/A }
5233N/A if (!isTextured()) {
5233N/A if (g instanceof SunGraphics2D) {
6084N/A ((SunGraphics2D) g).constrain(0, 0, w, h, getRegion());
5233N/A }
5233N/A g.setColor(getBackground());
5233N/A g.fillRect(0, 0, w, h);
5232N/A }
4639N/A } finally {
4639N/A g.dispose();
4639N/A }
4632N/A }
4632N/A }
4632N/A
6323N/A @Override
4632N/A public void notifyUpdateCursor() {
4632N/A getLWToolkit().getCursorManager().updateCursorLater(this);
4632N/A }
4632N/A
6323N/A @Override
6078N/A public void notifyActivation(boolean activation, LWWindowPeer opposite) {
6078N/A Window oppositeWindow = (opposite == null)? null : opposite.getTarget();
6078N/A changeFocusedWindow(activation, oppositeWindow);
4632N/A }
4632N/A
4665N/A // MouseDown in non-client area
6323N/A @Override
4665N/A public void notifyNCMouseDown() {
4665N/A // Ungrab except for a click on a Dialog with the grabbing owner
4665N/A if (grabbingWindow != null &&
4722N/A grabbingWindow != getOwnerFrameDialog(this))
4665N/A {
4665N/A grabbingWindow.ungrab();
4665N/A }
4665N/A }
4665N/A
4632N/A // ---- EVENTS ---- //
4632N/A
4632N/A /*
4632N/A * Called by the delegate to dispatch the event to Java. Event
4632N/A * coordinates are relative to non-client window are, i.e. the top-left
4632N/A * point of the client area is (insets.top, insets.left).
4632N/A */
6323N/A @Override
6323N/A public void notifyMouseEvent(int id, long when, int button,
6323N/A int x, int y, int screenX, int screenY,
6323N/A int modifiers, int clickCount, boolean popupTrigger,
6323N/A byte[] bdata)
4632N/A {
4632N/A // TODO: fill "bdata" member of AWTEvent
4632N/A Rectangle r = getBounds();
4632N/A // findPeerAt() expects parent coordinates
4632N/A LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
4632N/A LWWindowPeer lastWindowPeer =
4632N/A (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
4632N/A LWWindowPeer curWindowPeer =
4632N/A (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
4632N/A
4632N/A if (id == MouseEvent.MOUSE_EXITED) {
4632N/A // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
4632N/A // to a peer from another window. So we must first check if this peer is
4632N/A // the same as lastWindowPeer
4632N/A if (lastWindowPeer == this) {
4632N/A if (isEnabled()) {
4632N/A Point lp = lastMouseEventPeer.windowToLocal(x, y,
4632N/A lastWindowPeer);
6323N/A Component target = lastMouseEventPeer.getTarget();
6407N/A postMouseEnteredExitedEvent(target, id, when, modifiers, lp,
6323N/A screenX, screenY, clickCount, popupTrigger, button);
4632N/A }
4632N/A lastMouseEventPeer = null;
4632N/A }
4632N/A } else {
4632N/A if (targetPeer != lastMouseEventPeer) {
5295N/A // lastMouseEventPeer may be null if mouse was out of Java windows
5295N/A if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
5295N/A // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
5295N/A // later), in which case lastWindowPeer is another window
5295N/A if (lastWindowPeer != this) {
5295N/A Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
5295N/A // Additionally translate from this to lastWindowPeer coordinates
5295N/A Rectangle lr = lastWindowPeer.getBounds();
5295N/A oldp.x += r.x - lr.x;
5295N/A oldp.y += r.y - lr.y;
6407N/A Component target = lastMouseEventPeer.getTarget();
6407N/A postMouseEnteredExitedEvent(target, id, when, modifiers, oldp,
6407N/A screenX, screenY, clickCount, popupTrigger, button);
5295N/A } else {
5295N/A Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
6407N/A Component target = lastMouseEventPeer.getTarget();
6407N/A postMouseEnteredExitedEvent(target, id, when, modifiers, oldp,
6323N/A screenX, screenY, clickCount, popupTrigger, button);
4632N/A }
4632N/A }
4632N/A lastMouseEventPeer = targetPeer;
5295N/A if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
5295N/A Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
6407N/A Component target = targetPeer.getTarget();
6407N/A postMouseEnteredExitedEvent(target, id, when, modifiers, newp,
6407N/A screenX, screenY, clickCount, popupTrigger, button);
5295N/A }
4632N/A }
4632N/A // TODO: fill "bdata" member of AWTEvent
4632N/A
4734N/A int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
4734N/A int otherButtonsPressed = modifiers & ~eventButtonMask;
4734N/A
4734N/A // For pressed/dragged/released events OS X treats other
4632N/A // mouse buttons as if they were BUTTON2, so we do the same
4734N/A int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
4632N/A
4632N/A // MOUSE_ENTERED/EXITED are generated for the components strictly under
4632N/A // mouse even when dragging. That's why we first update lastMouseEventPeer
4632N/A // based on initial targetPeer value and only then recalculate targetPeer
4632N/A // for MOUSE_DRAGGED/RELEASED events
4632N/A if (id == MouseEvent.MOUSE_PRESSED) {
4665N/A
4665N/A // Ungrab only if this window is not an owned window of the grabbing one.
4665N/A if (!isGrabbing() && grabbingWindow != null &&
4722N/A grabbingWindow != getOwnerFrameDialog(this))
4665N/A {
4665N/A grabbingWindow.ungrab();
4665N/A }
4632N/A if (otherButtonsPressed == 0) {
4632N/A mouseClickButtons = eventButtonMask;
4632N/A } else {
4632N/A mouseClickButtons |= eventButtonMask;
4632N/A }
4632N/A
4632N/A mouseDownTarget[targetIdx] = targetPeer;
4632N/A } else if (id == MouseEvent.MOUSE_DRAGGED) {
4632N/A // Cocoa dragged event has the information about which mouse
4632N/A // button is being dragged. Use it to determine the peer that
4632N/A // should receive the dragged event.
4632N/A targetPeer = mouseDownTarget[targetIdx];
4734N/A mouseClickButtons &= ~modifiers;
4632N/A } else if (id == MouseEvent.MOUSE_RELEASED) {
4632N/A // TODO: currently, mouse released event goes to the same component
4632N/A // that received corresponding mouse pressed event. For most cases,
4632N/A // it's OK, however, we need to make sure that our behavior is consistent
4632N/A // with 1.6 for cases where component in question have been
4632N/A // hidden/removed in between of mouse pressed/released events.
4632N/A targetPeer = mouseDownTarget[targetIdx];
4632N/A
4734N/A if ((modifiers & eventButtonMask) == 0) {
4632N/A mouseDownTarget[targetIdx] = null;
4632N/A }
4632N/A
4632N/A // mouseClickButtons is updated below, after MOUSE_CLICK is sent
4632N/A }
4632N/A
4632N/A // check if we receive mouseEvent from outside the window's bounds
4632N/A // it can be either mouseDragged or mouseReleased
4632N/A if (curWindowPeer == null) {
4632N/A //TODO This can happen if this window is invisible. this is correct behavior in this case?
4632N/A curWindowPeer = this;
4632N/A }
4632N/A if (targetPeer == null) {
4632N/A //TODO This can happen if this window is invisible. this is correct behavior in this case?
4632N/A targetPeer = this;
4632N/A }
4632N/A
4632N/A
4632N/A Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
4632N/A if (targetPeer.isEnabled()) {
6323N/A if (id == MouseEvent.MOUSE_ENTERED || id == MouseEvent.MOUSE_EXITED) {
6323N/A postMouseEnteredExitedEvent(targetPeer.getTarget(), id,
6323N/A when, modifiers, lp, screenX, screenY,
6323N/A clickCount, popupTrigger, button);
6407N/A
6407N/A } else {
6323N/A MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
4632N/A when, modifiers, lp.x, lp.y,
4632N/A screenX, screenY, clickCount,
4632N/A popupTrigger, button);
6323N/A postEvent(event);
6323N/A }
4632N/A }
4632N/A
4632N/A if (id == MouseEvent.MOUSE_RELEASED) {
4632N/A if ((mouseClickButtons & eventButtonMask) != 0
4632N/A && targetPeer.isEnabled()) {
4632N/A postEvent(new MouseEvent(targetPeer.getTarget(),
4632N/A MouseEvent.MOUSE_CLICKED,
4632N/A when, modifiers,
4632N/A lp.x, lp.y, screenX, screenY,
4632N/A clickCount, popupTrigger, button));
4632N/A }
4632N/A mouseClickButtons &= ~eventButtonMask;
4632N/A }
4632N/A }
5137N/A notifyUpdateCursor();
4632N/A }
4632N/A
6323N/A private void postMouseEnteredExitedEvent(
6323N/A Component target, int id, long when, int modifiers,
6323N/A Point loc, int xAbs, int yAbs,
6323N/A int clickCount, boolean popupTrigger, int button) {
6323N/A
6323N/A updateSecurityWarningVisibility();
6323N/A
6323N/A postEvent(new MouseEvent(target, id, when, modifiers, loc.x, loc.y,
6323N/A xAbs, yAbs, clickCount, popupTrigger, button));
6323N/A }
6323N/A
6323N/A @Override
6323N/A public void notifyMouseWheelEvent(long when, int x, int y, int modifiers,
6323N/A int scrollType, int scrollAmount,
6323N/A int wheelRotation, double preciseWheelRotation,
6323N/A byte[] bdata)
4632N/A {
4632N/A // TODO: could we just use the last mouse event target here?
4632N/A Rectangle r = getBounds();
4632N/A // findPeerAt() expects parent coordinates
4632N/A final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
4632N/A if (targetPeer == null || !targetPeer.isEnabled()) {
4632N/A return;
4632N/A }
4632N/A
4632N/A Point lp = targetPeer.windowToLocal(x, y, this);
4632N/A // TODO: fill "bdata" member of AWTEvent
4632N/A // TODO: screenX/screenY
4632N/A postEvent(new MouseWheelEvent(targetPeer.getTarget(),
4632N/A MouseEvent.MOUSE_WHEEL,
4632N/A when, modifiers,
4632N/A lp.x, lp.y,
4632N/A 0, 0, /* screenX, Y */
4632N/A 0 /* clickCount */, false /* popupTrigger */,
4632N/A scrollType, scrollAmount,
4632N/A wheelRotation, preciseWheelRotation));
4632N/A }
4632N/A
4632N/A /*
4632N/A * Called by the delegate when a key is pressed.
4632N/A */
6323N/A @Override
6323N/A public void notifyKeyEvent(int id, long when, int modifiers,
6323N/A int keyCode, char keyChar, int keyLocation)
4632N/A {
5642N/A LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
5336N/A Component focusOwner = kfmPeer.getCurrentFocusOwner();
4632N/A
5642N/A if (focusOwner == null) {
5642N/A focusOwner = kfmPeer.getCurrentFocusedWindow();
5642N/A if (focusOwner == null) {
5642N/A focusOwner = this.getTarget();
5642N/A }
4632N/A }
5642N/A postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation));
4632N/A }
4632N/A
4632N/A
4632N/A // ---- UTILITY METHODS ---- //
4632N/A
6093N/A private void activateDisplayListener() {
6093N/A final GraphicsEnvironment ge =
6093N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
6093N/A ((SunGraphicsEnvironment) ge).addDisplayChangedListener(this);
6093N/A }
6093N/A
6093N/A private void deactivateDisplayListener() {
6093N/A final GraphicsEnvironment ge =
6093N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
6093N/A ((SunGraphicsEnvironment) ge).removeDisplayChangedListener(this);
6093N/A }
6093N/A
4632N/A private void postWindowStateChangedEvent(int newWindowState) {
4632N/A if (getTarget() instanceof Frame) {
4632N/A AWTAccessor.getFrameAccessor().setExtendedState(
4632N/A (Frame)getTarget(), newWindowState);
4632N/A }
4639N/A WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
4632N/A WindowEvent.WINDOW_STATE_CHANGED,
4632N/A windowState, newWindowState);
4632N/A postEvent(stateChangedEvent);
4632N/A windowState = newWindowState;
6323N/A
6323N/A updateSecurityWarningVisibility();
4632N/A }
4632N/A
4632N/A private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
4632N/A // TODO: this method can be implemented in a more
4632N/A // efficient way by forwarding to the delegate
4632N/A GraphicsDevice gd = gc.getDevice();
4632N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
4632N/A GraphicsDevice[] gds = ge.getScreenDevices();
4632N/A for (int i = 0; i < gds.length; i++) {
4632N/A if (gds[i] == gd) {
4632N/A return i;
4632N/A }
4632N/A }
4632N/A // Should never happen if gc is a screen device config
4632N/A return 0;
4632N/A }
4632N/A
4632N/A /*
4632N/A * This method is called when window's graphics config is changed from
4632N/A * the app code (e.g. when the window is made non-opaque) or when
4632N/A * the window is moved to another screen by user.
4632N/A *
4632N/A * Returns true if the graphics config has been changed, false otherwise.
4632N/A */
4632N/A private boolean setGraphicsConfig(GraphicsConfiguration gc) {
4632N/A synchronized (getStateLock()) {
4632N/A if (graphicsConfig == gc) {
4632N/A return false;
4632N/A }
4632N/A // If window's graphics config is changed from the app code, the
4632N/A // config correspond to the same device as before; when the window
6084N/A // is moved by user, graphicsDevice is updated in notifyReshape().
4632N/A // In either case, there's nothing to do with screenOn here
4632N/A graphicsConfig = gc;
4632N/A }
4632N/A // SurfaceData is replaced later in updateGraphicsData()
4632N/A return true;
4632N/A }
4632N/A
6084N/A /**
6084N/A * Returns true if the GraphicsDevice has been changed, false otherwise.
6084N/A */
6084N/A public boolean updateGraphicsDevice() {
5041N/A GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
4632N/A synchronized (getStateLock()) {
5041N/A if (graphicsDevice == newGraphicsDevice) {
6084N/A return false;
4632N/A }
5041N/A graphicsDevice = newGraphicsDevice;
4632N/A }
4632N/A
5041N/A final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
5041N/A
6084N/A if (!setGraphicsConfig(newGC)) return false;
4632N/A
4632N/A SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
4632N/A public void run() {
4632N/A AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
4632N/A }
4632N/A });
6084N/A return true;
4632N/A }
4632N/A
6093N/A @Override
6093N/A public final void displayChanged() {
6093N/A updateGraphicsDevice();
6093N/A // Replace surface unconditionally, because internal state of the
6093N/A // GraphicsDevice could be changed.
6093N/A replaceSurfaceData();
6093N/A repaintPeer();
6093N/A }
6093N/A
6093N/A @Override
6093N/A public final void paletteChanged() {
6093N/A // components do not need to react to this event.
4632N/A }
4632N/A
4632N/A /*
4632N/A * May be called by delegate to provide SD to Java2D code.
4632N/A */
4686N/A public SurfaceData getSurfaceData() {
4686N/A synchronized (surfaceDataLock) {
4686N/A return surfaceData;
4686N/A }
4632N/A }
4632N/A
4632N/A private void replaceSurfaceData() {
5232N/A replaceSurfaceData(true);
5232N/A }
5232N/A
5232N/A private void replaceSurfaceData(boolean blit) {
5232N/A replaceSurfaceData(backBufferCount, backBufferCaps, blit);
4632N/A }
4632N/A
4686N/A private void replaceSurfaceData(int newBackBufferCount,
5232N/A BufferCapabilities newBackBufferCaps,
5232N/A boolean blit) {
4686N/A synchronized (surfaceDataLock) {
4686N/A final SurfaceData oldData = getSurfaceData();
4686N/A surfaceData = platformWindow.replaceSurfaceData();
4686N/A // TODO: volatile image
4686N/A // VolatileImage oldBB = backBuffer;
4686N/A BufferedImage oldBB = backBuffer;
4686N/A backBufferCount = newBackBufferCount;
4686N/A backBufferCaps = newBackBufferCaps;
4686N/A final Rectangle size = getSize();
4686N/A if (getSurfaceData() != null && oldData != getSurfaceData()) {
4686N/A clearBackground(size.width, size.height);
4686N/A }
5232N/A
5232N/A if (blit) {
5232N/A blitSurfaceData(oldData, getSurfaceData());
5232N/A }
4639N/A
4686N/A if (oldData != null && oldData != getSurfaceData()) {
4686N/A // TODO: drop oldData for D3D/WGL pipelines
4686N/A // This can only happen when this peer is being created
4686N/A oldData.flush();
4686N/A }
4639N/A
4686N/A // TODO: volatile image
4686N/A // backBuffer = (VolatileImage)delegate.createBackBuffer();
4686N/A backBuffer = (BufferedImage) platformWindow.createBackBuffer();
4686N/A if (backBuffer != null) {
4686N/A Graphics g = backBuffer.getGraphics();
4686N/A try {
4686N/A Rectangle r = getBounds();
5166N/A if (g instanceof Graphics2D) {
5166N/A ((Graphics2D) g).setComposite(AlphaComposite.Src);
5166N/A }
5232N/A g.setColor(nonOpaqueBackground);
4686N/A g.fillRect(0, 0, r.width, r.height);
5232N/A if (g instanceof SunGraphics2D) {
6084N/A ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion());
5232N/A }
5233N/A if (!isTextured()) {
5233N/A g.setColor(getBackground());
5233N/A g.fillRect(0, 0, r.width, r.height);
5233N/A }
4686N/A if (oldBB != null) {
4686N/A // Draw the old back buffer to the new one
4686N/A g.drawImage(oldBB, 0, 0, null);
4686N/A oldBB.flush();
4686N/A }
4686N/A } finally {
4686N/A g.dispose();
4632N/A }
4632N/A }
4632N/A }
6084N/A flushOnscreenGraphics();
4632N/A }
4632N/A
4639N/A private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
4639N/A //TODO blit. proof-of-concept
4639N/A if (src != dst && src != null && dst != null
4639N/A && !(dst instanceof NullSurfaceData)
4639N/A && !(src instanceof NullSurfaceData)
6084N/A && src.getSurfaceType().equals(dst.getSurfaceType())
6084N/A && src.getDefaultScale() == dst.getDefaultScale()) {
6084N/A final Rectangle size = src.getBounds();
4639N/A final Blit blit = Blit.locate(src.getSurfaceType(),
4639N/A CompositeType.Src,
4639N/A dst.getSurfaceType());
4639N/A if (blit != null) {
6084N/A blit.Blit(src, dst, AlphaComposite.Src, null, 0, 0, 0, 0,
6084N/A size.width, size.height);
4639N/A }
4639N/A }
4639N/A }
4639N/A
4632N/A public int getBackBufferCount() {
4632N/A return backBufferCount;
4632N/A }
4632N/A
4632N/A public BufferCapabilities getBackBufferCaps() {
4632N/A return backBufferCaps;
4632N/A }
4632N/A
6060N/A /**
6060N/A * Request the window insets from the delegate and compares it with the
6060N/A * current one. This method is mostly called by the delegate, e.g. when the
6060N/A * window state is changed and insets should be recalculated.
6060N/A * <p/>
4632N/A * This method may be called on the toolkit thread.
4632N/A */
6060N/A public final boolean updateInsets(final Insets newInsets) {
4632N/A synchronized (getStateLock()) {
6060N/A if (insets.equals(newInsets)) {
6060N/A return false;
6060N/A }
4632N/A insets = newInsets;
4632N/A }
6060N/A return true;
4632N/A }
4632N/A
4632N/A public static LWWindowPeer getWindowUnderCursor() {
4632N/A return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
4632N/A }
4632N/A
5137N/A public static LWComponentPeer<?, ?> getPeerUnderCursor() {
5137N/A return lastMouseEventPeer;
5137N/A }
5137N/A
4886N/A /*
4886N/A * Requests platform to set native focus on a frame/dialog.
4886N/A * In case of a simple window, triggers appropriate java focus change.
4886N/A */
4632N/A public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4717N/A focusLog.fine("requesting native focus to " + this);
4717N/A }
4717N/A
4632N/A if (!focusAllowedFor()) {
4717N/A focusLog.fine("focus is not allowed");
4717N/A return false;
4717N/A }
4717N/A
4858N/A if (platformWindow.rejectFocusRequest(cause)) {
4632N/A return false;
4632N/A }
4717N/A
4717N/A Window currentActive = KeyboardFocusManager.
4717N/A getCurrentKeyboardFocusManager().getActiveWindow();
4717N/A
6078N/A Window opposite = LWKeyboardFocusManagerPeer.getInstance().
6078N/A getCurrentFocusedWindow();
6078N/A
4717N/A // Make the owner active window.
4717N/A if (isSimpleWindow()) {
4722N/A LWWindowPeer owner = getOwnerFrameDialog(this);
4717N/A
4717N/A // If owner is not natively active, request native
4717N/A // activation on it w/o sending events up to java.
4722N/A if (owner != null && !owner.platformWindow.isActive()) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4722N/A focusLog.fine("requesting native focus to the owner " + owner);
4717N/A }
4717N/A LWWindowPeer currentActivePeer = (currentActive != null ?
4717N/A (LWWindowPeer)currentActive.getPeer() : null);
4717N/A
4717N/A // Ensure the opposite is natively active and suppress sending events.
4717N/A if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4717N/A focusLog.fine("the opposite is " + currentActivePeer);
4717N/A }
4717N/A currentActivePeer.skipNextFocusChange = true;
4717N/A }
4722N/A owner.skipNextFocusChange = true;
4717N/A
4722N/A owner.platformWindow.requestWindowFocus();
4717N/A }
4717N/A
4717N/A // DKFM will synthesize all the focus/activation events correctly.
6078N/A changeFocusedWindow(true, opposite);
4717N/A return true;
4717N/A
4717N/A // In case the toplevel is active but not focused, change focus directly,
4717N/A // as requesting native focus on it will not have effect.
4717N/A } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
4717N/A
6078N/A changeFocusedWindow(true, opposite);
4717N/A return true;
4717N/A }
6078N/A
4717N/A return platformWindow.requestWindowFocus();
4632N/A }
4632N/A
4632N/A private boolean focusAllowedFor() {
4632N/A Window window = getTarget();
4632N/A // TODO: check if modal blocked
4878N/A return window.isVisible() && window.isEnabled() && isFocusableWindow();
4878N/A }
4878N/A
4878N/A private boolean isFocusableWindow() {
4878N/A boolean focusable = getTarget().isFocusableWindow();
4878N/A if (isSimpleWindow()) {
4878N/A LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
4878N/A if (ownerPeer == null) {
4878N/A return false;
4878N/A }
4878N/A return focusable && ownerPeer.getTarget().isFocusableWindow();
4878N/A }
4878N/A return focusable;
4632N/A }
4632N/A
4632N/A public boolean isSimpleWindow() {
4632N/A Window window = getTarget();
4632N/A return !(window instanceof Dialog || window instanceof Frame);
4632N/A }
4632N/A
4632N/A /*
4886N/A * Changes focused window on java level.
4632N/A */
6078N/A private void changeFocusedWindow(boolean becomesFocused, Window opposite) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4717N/A focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
4717N/A }
4886N/A if (skipNextFocusChange) {
4717N/A focusLog.fine("skipping focus change");
4717N/A skipNextFocusChange = false;
4632N/A return;
4632N/A }
4878N/A if (!isFocusableWindow() && becomesFocused) {
4878N/A focusLog.fine("the window is not focusable");
4632N/A return;
4632N/A }
4632N/A if (becomesFocused) {
4632N/A synchronized (getPeerTreeLock()) {
4632N/A if (blocker != null) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINEST)) {
4717N/A focusLog.finest("the window is blocked by " + blocker);
4717N/A }
4632N/A return;
4632N/A }
4632N/A }
4632N/A }
4632N/A
4665N/A // Note, the method is not called:
4665N/A // - when the opposite (gaining focus) window is an owned/owner window.
4665N/A // - for a simple window in any case.
4665N/A if (!becomesFocused &&
4722N/A (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
4665N/A {
4717N/A focusLog.fine("ungrabbing on " + grabbingWindow);
4665N/A // ungrab a simple window if its owner looses activation.
4665N/A grabbingWindow.ungrab();
4665N/A }
4665N/A
6078N/A KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
5336N/A kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
4632N/A
4632N/A int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
6078N/A WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, opposite);
4632N/A
4632N/A // TODO: wrap in SequencedEvent
4632N/A postEvent(windowEvent);
4632N/A }
4632N/A
4886N/A static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
4665N/A Window owner = (peer != null ? peer.getTarget().getOwner() : null);
4665N/A while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
4665N/A owner = owner.getOwner();
4665N/A }
4722N/A return owner != null ? (LWWindowPeer)owner.getPeer() : null;
4665N/A }
4665N/A
4632N/A /**
4632N/A * Returns the foremost modal blocker of this window, or null.
4632N/A */
4632N/A public LWWindowPeer getBlocker() {
4632N/A synchronized (getPeerTreeLock()) {
4632N/A LWWindowPeer blocker = this.blocker;
4632N/A if (blocker == null) {
4632N/A return null;
4632N/A }
4632N/A while (blocker.blocker != null) {
4632N/A blocker = blocker.blocker;
4632N/A }
4632N/A return blocker;
4632N/A }
4632N/A }
4632N/A
4632N/A public void enterFullScreenMode() {
4632N/A platformWindow.enterFullScreenMode();
6323N/A updateSecurityWarningVisibility();
4632N/A }
4632N/A
4632N/A public void exitFullScreenMode() {
4632N/A platformWindow.exitFullScreenMode();
6323N/A updateSecurityWarningVisibility();
4632N/A }
4655N/A
4655N/A public long getLayerPtr() {
4655N/A return getPlatformWindow().getLayerPtr();
4655N/A }
4665N/A
4665N/A void grab() {
4665N/A if (grabbingWindow != null && !isGrabbing()) {
4665N/A grabbingWindow.ungrab();
4665N/A }
4665N/A grabbingWindow = this;
4665N/A }
4665N/A
5990N/A final void ungrab(boolean doPost) {
4665N/A if (isGrabbing()) {
4665N/A grabbingWindow = null;
5990N/A if (doPost) {
5990N/A postEvent(new UngrabEvent(getTarget()));
5990N/A }
4665N/A }
4665N/A }
4665N/A
5990N/A void ungrab() {
5990N/A ungrab(true);
5990N/A }
5990N/A
4665N/A private boolean isGrabbing() {
4665N/A return this == grabbingWindow;
4665N/A }
4717N/A
5555N/A public PeerType getPeerType() {
5555N/A return peerType;
5555N/A }
5555N/A
6323N/A public void updateSecurityWarningVisibility() {
6323N/A if (warningWindow == null) {
6323N/A return;
6323N/A }
6323N/A
6323N/A if (!isVisible()) {
6323N/A return; // The warning window should already be hidden.
6323N/A }
6323N/A
6323N/A boolean show = false;
6323N/A
6323N/A if (!platformWindow.isFullScreenMode()) {
6323N/A if (isVisible()) {
6407N/A if (LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() ==
6323N/A getTarget()) {
6323N/A show = true;
6323N/A }
6323N/A
6323N/A if (platformWindow.isUnderMouse() || warningWindow.isUnderMouse()) {
6323N/A show = true;
6323N/A }
6323N/A }
6323N/A }
6323N/A
6323N/A warningWindow.setVisible(show, true);
6323N/A }
6323N/A
4717N/A @Override
4717N/A public String toString() {
4717N/A return super.toString() + " [target is " + getTarget() + "]";
4717N/A }
4632N/A}