jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
author serb
Mon, 23 Sep 2013 16:17:26 +0400
changeset 20153 d5bf90bfcb6d
parent 20109 e568ad7e1bf3
child 20445 9440dd9e78d1
permissions -rw-r--r--
8005255: [macosx] Cleanup warnings in sun.lwawt Reviewed-by: alexsch, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
15323
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.lwawt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import java.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.awt.event.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.awt.peer.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.util.List;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import javax.swing.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import sun.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import sun.java2d.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import sun.java2d.loops.Blit;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import sun.java2d.loops.CompositeType;
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
    39
import sun.java2d.pipe.Region;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
import sun.util.logging.PlatformLogger;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
public class LWWindowPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
    extends LWContainerPeer<Window, JComponent>
18249
chegar
parents: 18247 17151
diff changeset
    44
    implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
{
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    46
    public enum PeerType {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
        SIMPLEWINDOW,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
        FRAME,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
        DIALOG,
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
    50
        EMBEDDED_FRAME,
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
    51
        VIEW_EMBEDDED_FRAME,
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
    52
        LW_FRAME
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
    55
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
    57
    private final PlatformWindow platformWindow;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    // Window bounds reported by the native system (as opposed to
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    // regular bounds inherited from LWComponentPeer which are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    // requested by user and may haven't been applied yet because
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
    // of asynchronous requests to the windowing system)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    private int sysX;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    private int sysY;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    private int sysW;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    private int sysH;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    private static final int MINIMUM_WIDTH = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    private static final int MINIMUM_HEIGHT = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    private Insets insets = new Insets(0, 0, 0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
    73
    private GraphicsDevice graphicsDevice;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    private GraphicsConfiguration graphicsConfig;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    private SurfaceData surfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    private final Object surfaceDataLock = new Object();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    private volatile int windowState = Frame.NORMAL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    81
    // check that the mouse is over the window
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    82
    private volatile boolean isMouseOver = false;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    83
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    84
    // A peer where the last mouse event came to. Used by cursor manager to
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    85
    // find the component under cursor
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    86
    private static volatile LWComponentPeer<?, ?> lastCommonMouseEventPeer;
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    87
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    // A peer where the last mouse event came to. Used to generate
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    89
    // MOUSE_ENTERED/EXITED notifications
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    90
    private volatile LWComponentPeer<?, ?> lastMouseEventPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    // Peers where all dragged/released events should come to,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    // depending on what mouse button is being dragged according to Cocoa
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
    94
    private static final LWComponentPeer<?, ?>[] mouseDownTarget = new LWComponentPeer<?, ?>[3];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    // on MOUSE_RELEASE. Click events are only generated if there were no drag
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    private static int mouseClickButtons = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    private volatile boolean isOpaque = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    private static LWWindowPeer grabbingWindow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    private volatile boolean skipNextFocusChange;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   109
    private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   110
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   111
    private volatile boolean textured;
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   112
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   113
    private final PeerType peerType;
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   114
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   115
    private final SecurityWarningWindow warningWindow;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   116
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
     * Current modal blocker or null.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
     * Synchronization: peerTreeLock.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    private LWWindowPeer blocker;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    public LWWindowPeer(Window target, PlatformComponent platformComponent,
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   125
                        PlatformWindow platformWindow, PeerType peerType)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        super(target, platformComponent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
        this.platformWindow = platformWindow;
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   129
        this.peerType = peerType;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
        Window owner = target.getOwner();
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   132
        LWWindowPeer ownerPeer = owner == null ? null :
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   133
             (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
        PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
        // The delegate.initialize() needs a non-null GC on X11.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
        GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
            // graphicsConfig should be updated according to the real window
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
            // bounds when the window is shown, see 4868278
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
            this.graphicsConfig = gc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
        if (!target.isFontSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
            target.setFont(DEFAULT_FONT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
        if (!target.isBackgroundSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
            target.setBackground(SystemColor.window);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
            // first we check if user provided alpha for background. This is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
            // similar to what Apple's Java do.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
            // Since JDK7 we should rely on setOpacity() only.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
            // this.opacity = c.getAlpha();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
        if (!target.isForegroundSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
            target.setForeground(SystemColor.windowText);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
            // we should not call setForeground because it will call a repaint
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
            // which the peer may not be ready to do yet.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
        platformWindow.initialize(target, this, ownerDelegate);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   164
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   165
        // Init warning window(for applets)
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   166
        SecurityWarningWindow warn = null;
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   167
        if (target.getWarningString() != null) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   168
            // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   169
            // and TrayIcon balloon windows without a warning window.
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   170
            if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   171
                LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   172
                warn = toolkit.createSecurityWarning(target, this);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   173
            }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   174
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   175
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   176
        warningWindow = warn;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
    @Override
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   180
    void initializeImpl() {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   181
        super.initializeImpl();
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   182
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   183
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
        if (getTarget() instanceof Frame) {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   185
            setTitle(((Frame) getTarget()).getTitle());
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   186
            setState(((Frame) getTarget()).getExtendedState());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        } else if (getTarget() instanceof Dialog) {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   188
            setTitle(((Dialog) getTarget()).getTitle());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
16892
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 15983
diff changeset
   191
        updateAlwaysOnTopState();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
        updateMinimumSize();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   194
        final Shape shape = getTarget().getShape();
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   195
        if (shape != null) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   196
            applyShape(Region.getInstance(shape, null));
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   197
        }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   198
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   199
        final float opacity = getTarget().getOpacity();
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   200
        if (opacity < 1.0f) {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   201
            setOpacity(opacity);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   202
        }
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   203
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
        setOpaque(getTarget().isOpaque());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
        updateInsets(platformWindow.getInsets());
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   207
        if (getSurfaceData() == null) {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   208
            replaceSurfaceData(false);
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   209
        }
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   210
        activateDisplayListener();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    // Just a helper method
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   214
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    public PlatformWindow getPlatformWindow() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
        return platformWindow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
    protected LWWindowPeer getWindowPeerOrSelf() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        return this;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    // ---- PEER METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    protected void disposeImpl() {
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   228
        deactivateDisplayListener();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
        SurfaceData oldData = getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
        synchronized (surfaceDataLock){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
            surfaceData = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
        if (oldData != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
            oldData.invalidate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
        if (isGrabbing()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
            ungrab();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
        }
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   239
        if (warningWindow != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   240
            warningWindow.dispose();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   241
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   242
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
        platformWindow.dispose();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
        super.disposeImpl();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    @Override
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   248
    protected void setVisibleImpl(final boolean visible) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   249
        if (!visible && warningWindow != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   250
            warningWindow.setVisible(false, false);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   251
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   252
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   253
        super.setVisibleImpl(visible);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
        // TODO: update graphicsConfig, see 4868278
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   255
        platformWindow.setVisible(visible);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   256
        if (isSimpleWindow()) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13647
diff changeset
   257
            KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   259
            if (visible) {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   260
                if (!getTarget().isAutoRequestFocus()) {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   261
                    return;
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   262
                } else {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   263
                    requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   264
                }
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   265
            // Focus the owner in case this window is focused.
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13647
diff changeset
   266
            } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   267
                // Transfer focus to the owner.
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   268
                LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   269
                if (owner != null) {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   270
                    owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
            }
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12816
diff changeset
   273
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
    @Override
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   277
    public final GraphicsConfiguration getGraphicsConfiguration() {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   278
        synchronized (getStateLock()) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   279
            return graphicsConfig;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   280
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
    public boolean updateGraphicsData(GraphicsConfiguration gc) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
        setGraphicsConfig(gc);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
    protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
        if (getSurfaceData() == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        if (fg == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
            fg = SystemColor.windowText;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        if (bg == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
            bg = SystemColor.window;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
        if (f == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
            f = DEFAULT_FONT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
        return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    public void setBounds(int x, int y, int w, int h, int op) {
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   307
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   308
        if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEW_EMBEDDED_FRAME) {
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   309
            return;
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   310
        }
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
   311
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
        if ((op & SET_CLIENT_SIZE) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
            // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
            // instead of pulling 'insets' field up to LWComponentPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
            // no need to add insets since Window's notion of width and height includes insets.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
            op &= ~SET_CLIENT_SIZE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
            op |= SET_SIZE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
        if (w < MINIMUM_WIDTH) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
            w = MINIMUM_WIDTH;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
        if (h < MINIMUM_HEIGHT) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
            h = MINIMUM_HEIGHT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   327
        final int maxW = getLWGC().getMaxTextureWidth();
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   328
        final int maxH = getLWGC().getMaxTextureHeight();
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   329
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   330
        if (w > maxW) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   331
            w = maxW;
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   332
        }
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   333
        if (h > maxH) {
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   334
            h = maxH;
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   335
        }
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   336
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
        // Don't post ComponentMoved/Resized and Paint events
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
        // until we've got a notification from the delegate
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
        setBounds(x, y, w, h, op, false, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
        // Get updated bounds, so we don't have to handle 'op' here manually
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
        Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
        platformWindow.setBounds(r.x, r.y, r.width, r.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
    public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
        return platformWindow.getLocationOnScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
     * Overridden from LWContainerPeer to return the correct insets.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
     * Insets are queried from the delegate and are kept up to date by
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
     * requiering when needed (i.e. when the window geometry is changed).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
    public Insets getInsets() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
            return insets;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
    public FontMetrics getFontMetrics(Font f) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
        // TODO: check for "use platform metrics" settings
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
        return platformWindow.getFontMetrics(f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    public void toFront() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
        platformWindow.toFront();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
    public void toBack() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
        platformWindow.toBack();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
    public void setZOrder(ComponentPeer above) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
        throw new RuntimeException("not implemented");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
    @Override
16892
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 15983
diff changeset
   384
    public void updateAlwaysOnTopState() {
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 15983
diff changeset
   385
        platformWindow.setAlwaysOnTop(getTarget().isAlwaysOnTop());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    public void updateFocusableWindowState() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
        platformWindow.updateFocusableWindowState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
    public void setModalBlocked(Dialog blocker, boolean blocked) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
        synchronized (getPeerTreeLock()) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   396
            this.blocker = !blocked ? null :
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   397
            (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(blocker);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
        }
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   399
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   400
        platformWindow.setModalBlocked(blocked);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
    public void updateMinimumSize() {
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   405
        final Dimension min;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
        if (getTarget().isMinimumSizeSet()) {
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   407
            min = getTarget().getMinimumSize();
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   408
            min.width = Math.max(min.width, MINIMUM_WIDTH);
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   409
            min.height = Math.max(min.height, MINIMUM_HEIGHT);
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   410
        } else {
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   411
            min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
        }
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   413
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   414
        final Dimension max;
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   415
        if (getTarget().isMaximumSizeSet()) {
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   416
            max = getTarget().getMaximumSize();
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   417
            max.width = Math.min(max.width, getLWGC().getMaxTextureWidth());
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   418
            max.height = Math.min(max.height, getLWGC().getMaxTextureHeight());
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   419
        } else {
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   420
            max = new Dimension(getLWGC().getMaxTextureWidth(),
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
   421
                                getLWGC().getMaxTextureHeight());
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   422
        }
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   423
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13234
diff changeset
   424
        platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    public void updateIconImages() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
        getPlatformWindow().updateIconImages();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
    public void setOpacity(float opacity) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
        getPlatformWindow().setOpacity(opacity);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
        repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
    public final void setOpaque(final boolean isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
        if (this.isOpaque != isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
            this.isOpaque = isOpaque;
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   442
            updateOpaque();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   446
    private void updateOpaque() {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   447
        getPlatformWindow().setOpaque(!isTranslucent());
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   448
        replaceSurfaceData(false);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   449
        repaintPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
    public void updateWindow() {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   454
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   455
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   456
    public final boolean isTextured() {
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   457
        return textured;
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   458
    }
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   459
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   460
    public final void setTextured(final boolean isTextured) {
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   461
        textured = isTextured;
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   462
    }
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   463
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   464
    @Override
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   465
    public final boolean isTranslucent() {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   466
        synchronized (getStateLock()) {
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   467
            /*
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   468
             * Textured window is a special case of translucent window.
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   469
             * The difference is only in nswindow background. So when we set
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   470
             * texture property our peer became fully translucent. It doesn't
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   471
             * fill background, create non opaque backbuffers and layer etc.
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   472
             */
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   473
            return !isOpaque || isShaped() || isTextured();
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   474
        }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   475
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   476
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   477
    @Override
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   478
    final void applyShapeImpl(final Region shape) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   479
        super.applyShapeImpl(shape);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   480
        updateOpaque();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
    public void repositionSecurityWarning() {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   485
        if (warningWindow != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   486
            AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   487
            Window target = getTarget();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   488
            int x = compAccessor.getX(target);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   489
            int y = compAccessor.getY(target);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   490
            int width = compAccessor.getWidth(target);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   491
            int height = compAccessor.getHeight(target);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   492
            warningWindow.reposition(x, y, width, height);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   493
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   494
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   495
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
    // ---- FRAME PEER METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
    @Override // FramePeer and DialogPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
    public void setTitle(String title) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
        platformWindow.setTitle(title == null ? "" : title);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
    public void setMenuBar(MenuBar mb) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
         platformWindow.setMenuBar(mb);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
    @Override // FramePeer and DialogPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    public void setResizable(boolean resizable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
        platformWindow.setResizable(resizable);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
    public void setState(int state) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
        platformWindow.setWindowState(state);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   518
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
    public int getState() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
        return windowState;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
    public void setMaximizedBounds(Rectangle bounds) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
    public void setBoundsPrivate(int x, int y, int width, int height) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
        setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
    public Rectangle getBoundsPrivate() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
        throw new RuntimeException("not implemented");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
    // ---- DIALOG PEER METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   540
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
    public void blockWindows(List<Window> windows) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
        //TODO: LWX will probably need some collectJavaToplevels to speed this up
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
        for (Window w : windows) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   544
            WindowPeer wp =
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   545
                    (WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
            if (wp != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
                wp.setModalBlocked((Dialog)getTarget(), true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
    // ---- PEER NOTIFICATIONS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   554
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
    public void notifyIconify(boolean iconify) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
        //The toplevel target is Frame and states are applicable to it.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
        //Otherwise, the target is Window and it don't have state property.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
        //Hopefully, no such events are posted in the queue so consider the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   559
        //target as Frame in all cases.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   560
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   561
        // REMIND: should we send it anyway if the state not changed since last
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   562
        // time?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   563
        WindowEvent iconifyEvent = new WindowEvent(getTarget(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   564
                iconify ? WindowEvent.WINDOW_ICONIFIED
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   565
                        : WindowEvent.WINDOW_DEICONIFIED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   566
        postEvent(iconifyEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   567
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   568
        int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   569
        postWindowStateChangedEvent(newWindowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   570
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   571
        // REMIND: RepaintManager doesn't repaint iconified windows and
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   572
        // hence ignores any repaint request during deiconification.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
        // So, we need to repaint window explicitly when it becomes normal.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
        if (!iconify) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
            repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   579
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   580
    public void notifyZoom(boolean isZoomed) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
        int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
        postWindowStateChangedEvent(newWindowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
    /**
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   586
     * Called by the {@code PlatformWindow} when any part of the window should
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   587
     * be repainted.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   589
    @Override
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   590
    public void notifyExpose(final Rectangle r) {
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   591
        repaintPeer(r);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   594
    /**
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   595
     * Called by the {@code PlatformWindow} when this window is moved/resized by
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   596
     * user or window insets are changed. There's no notifyReshape() in
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   597
     * LWComponentPeer as the only components which could be resized by user are
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   598
     * top-level windows.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   600
    @Override
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   601
    public void notifyReshape(int x, int y, int w, int h) {
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   602
        final boolean moved;
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   603
        final boolean resized;
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   604
        final boolean invalid = updateInsets(platformWindow.getInsets());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
            moved = (x != sysX) || (y != sysY);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
            resized = (w != sysW) || (h != sysH);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
            sysX = x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
            sysY = y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
            sysW = w;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
            sysH = h;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
        // Check if anything changed
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   615
        if (!moved && !resized && !invalid) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
        // First, update peer's bounds
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
        setBounds(x, y, w, h, SET_BOUNDS, false, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
        // Second, update the graphics config and surface data
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
   622
        final boolean isNewDevice = updateGraphicsDevice();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
   623
        if (resized || isNewDevice) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
            replaceSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   627
        // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
   628
        if (moved || invalid) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
            handleMove(x, y, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
        }
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
   631
        if (resized || invalid || isNewDevice) {
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   632
            handleResize(w, h, true);
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 13652
diff changeset
   633
            repaintPeer();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
        }
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   635
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   636
        repositionSecurityWarning();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
    private void clearBackground(final int w, final int h) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
        final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
                                               getFont());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
        if (g != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
            try {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   644
                if (g instanceof Graphics2D) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   645
                    ((Graphics2D) g).setComposite(AlphaComposite.Src);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   646
                }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   647
                if (isTranslucent()) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   648
                    g.setColor(nonOpaqueBackground);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   649
                    g.fillRect(0, 0, w, h);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   650
                }
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   651
                if (!isTextured()) {
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   652
                    if (g instanceof SunGraphics2D) {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
   653
                        ((SunGraphics2D) g).constrain(0, 0, w, h, getRegion());
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   654
                    }
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   655
                    g.setColor(getBackground());
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   656
                    g.fillRect(0, 0, w, h);
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   657
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
            } finally {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
                g.dispose();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   664
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
    public void notifyUpdateCursor() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
        getLWToolkit().getCursorManager().updateCursorLater(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   669
    @Override
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   670
    public void notifyActivation(boolean activation, LWWindowPeer opposite) {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   671
        Window oppositeWindow = (opposite == null)? null : opposite.getTarget();
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   672
        changeFocusedWindow(activation, oppositeWindow);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
    // MouseDown in non-client area
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   676
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
    public void notifyNCMouseDown() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
        // Ungrab except for a click on a Dialog with the grabbing owner
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
        if (grabbingWindow != null &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
            grabbingWindow != getOwnerFrameDialog(this))
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
            grabbingWindow.ungrab();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
    // ---- EVENTS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
     * Called by the delegate to dispatch the event to Java. Event
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
     * coordinates are relative to non-client window are, i.e. the top-left
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
     * point of the client area is (insets.top, insets.left).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   693
    @Override
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   694
    public void notifyMouseEvent(int id, long when, int button,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   695
                                 int x, int y, int screenX, int screenY,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   696
                                 int modifiers, int clickCount, boolean popupTrigger,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   697
                                 byte[] bdata)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
        // TODO: fill "bdata" member of AWTEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   700
        Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
        // findPeerAt() expects parent coordinates
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   702
        LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
        if (id == MouseEvent.MOUSE_EXITED) {
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   705
            isMouseOver = false;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   706
            if (lastMouseEventPeer != null) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   707
                if (lastMouseEventPeer.isEnabled()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
                    Point lp = lastMouseEventPeer.windowToLocal(x, y,
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   709
                            this);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   710
                    Component target = lastMouseEventPeer.getTarget();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   711
                    postMouseExitedEvent(target, when, modifiers, lp,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   712
                            screenX, screenY, clickCount, popupTrigger, button);
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   713
                }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   714
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   715
                // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   716
                // to a peer from another window. So we must first check if this peer is
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   717
                // the same as lastWindowPeer
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   718
                if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   719
                    lastCommonMouseEventPeer = null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   720
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   721
                lastMouseEventPeer = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   722
            }
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   723
        } else if(id == MouseEvent.MOUSE_ENTERED) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   724
            isMouseOver = true;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   725
            if (targetPeer != null) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   726
                if (targetPeer.isEnabled()) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   727
                    Point lp = targetPeer.windowToLocal(x, y, this);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   728
                    Component target = targetPeer.getTarget();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   729
                    postMouseEnteredEvent(target, when, modifiers, lp,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   730
                            screenX, screenY, clickCount, popupTrigger, button);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   731
                }
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   732
                lastCommonMouseEventPeer = targetPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   733
                lastMouseEventPeer = targetPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   734
            }
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   735
        } else {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   736
            PlatformWindow topmostPlatforWindow =
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   737
                    platformWindow.getTopmostPlatformWindowUnderMouse();
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   738
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   739
            LWWindowPeer topmostWindowPeer =
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   740
                    topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   741
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   742
            // topmostWindowPeer == null condition is added for the backward
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   743
            // compatibility with applets. It can be removed when the
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   744
            // getTopmostPlatformWindowUnderMouse() method will be properly
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   745
            // implemented in CPlatformEmbeddedFrame class
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   746
            if (topmostWindowPeer == this || topmostWindowPeer == null) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   747
                generateMouseEnterExitEventsForComponents(when, button, x, y,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   748
                        screenX, screenY, modifiers, clickCount, popupTrigger,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   749
                        targetPeer);
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   750
            } else {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   751
                LWComponentPeer<?, ?> topmostTargetPeer =
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   752
                        topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   753
                topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   754
                        screenX, screenY, modifiers, clickCount, popupTrigger,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   755
                        topmostTargetPeer);
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   756
            }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   757
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   758
            // TODO: fill "bdata" member of AWTEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   759
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   760
            int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   761
            int otherButtonsPressed = modifiers & ~eventButtonMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   762
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   763
            // For pressed/dragged/released events OS X treats other
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
            // mouse buttons as if they were BUTTON2, so we do the same
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
            int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   766
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   767
            // MOUSE_ENTERED/EXITED are generated for the components strictly under
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   768
            // mouse even when dragging. That's why we first update lastMouseEventPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   769
            // based on initial targetPeer value and only then recalculate targetPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   770
            // for MOUSE_DRAGGED/RELEASED events
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   771
            if (id == MouseEvent.MOUSE_PRESSED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   772
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   773
                // Ungrab only if this window is not an owned window of the grabbing one.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   774
                if (!isGrabbing() && grabbingWindow != null &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   775
                    grabbingWindow != getOwnerFrameDialog(this))
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   776
                {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   777
                    grabbingWindow.ungrab();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   778
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   779
                if (otherButtonsPressed == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   780
                    mouseClickButtons = eventButtonMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   781
                } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   782
                    mouseClickButtons |= eventButtonMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   783
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   784
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   785
                // The window should be focused on mouse click. If it gets activated by the native platform,
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   786
                // this request will be no op. It will take effect when:
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   787
                // 1. A simple not focused window is clicked.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   788
                // 2. An active but not focused owner frame/dialog is clicked.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   789
                // The mouse event then will trigger a focus request "in window" to the component, so the window
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   790
                // should gain focus before.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   791
                requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   792
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   793
                mouseDownTarget[targetIdx] = targetPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   794
            } else if (id == MouseEvent.MOUSE_DRAGGED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   795
                // Cocoa dragged event has the information about which mouse
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
                // button is being dragged. Use it to determine the peer that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   797
                // should receive the dragged event.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   798
                targetPeer = mouseDownTarget[targetIdx];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   799
                mouseClickButtons &= ~modifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   800
            } else if (id == MouseEvent.MOUSE_RELEASED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   801
                // TODO: currently, mouse released event goes to the same component
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   802
                // that received corresponding mouse pressed event. For most cases,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   803
                // it's OK, however, we need to make sure that our behavior is consistent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   804
                // with 1.6 for cases where component in question have been
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   805
                // hidden/removed in between of mouse pressed/released events.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   806
                targetPeer = mouseDownTarget[targetIdx];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   807
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   808
                if ((modifiers & eventButtonMask) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   809
                    mouseDownTarget[targetIdx] = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   810
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   811
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   812
                // mouseClickButtons is updated below, after MOUSE_CLICK is sent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   813
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   814
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   815
            if (targetPeer == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   816
                //TODO This can happen if this window is invisible. this is correct behavior in this case?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   817
                targetPeer = this;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   819
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   821
            Point lp = targetPeer.windowToLocal(x, y, this);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   822
            if (targetPeer.isEnabled()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   823
                MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   824
                                                  when, modifiers, lp.x, lp.y,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   825
                                                  screenX, screenY, clickCount,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   826
                                                  popupTrigger, button);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   827
                postEvent(event);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   828
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   829
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   830
            if (id == MouseEvent.MOUSE_RELEASED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   831
                if ((mouseClickButtons & eventButtonMask) != 0
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   832
                    && targetPeer.isEnabled()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   833
                    postEvent(new MouseEvent(targetPeer.getTarget(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   834
                                             MouseEvent.MOUSE_CLICKED,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   835
                                             when, modifiers,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   836
                                             lp.x, lp.y, screenX, screenY,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   837
                                             clickCount, popupTrigger, button));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   838
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   839
                mouseClickButtons &= ~eventButtonMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   840
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   841
        }
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12176
diff changeset
   842
        notifyUpdateCursor();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   843
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   844
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   845
    private void generateMouseEnterExitEventsForComponents(long when,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   846
            int button, int x, int y, int screenX, int screenY,
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   847
            int modifiers, int clickCount, boolean popupTrigger,
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   848
            final LWComponentPeer<?, ?> targetPeer) {
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   849
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   850
        if (!isMouseOver || targetPeer == lastMouseEventPeer) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   851
            return;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   852
        }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   853
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   854
        // Generate Mouse Exit for components
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   855
        if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   856
            Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   857
            Component target = lastMouseEventPeer.getTarget();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   858
            postMouseExitedEvent(target, when, modifiers, oldp, screenX, screenY,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   859
                    clickCount, popupTrigger, button);
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   860
        }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   861
        lastCommonMouseEventPeer = targetPeer;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   862
        lastMouseEventPeer = targetPeer;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   863
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   864
        // Generate Mouse Enter for components
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   865
        if (targetPeer != null && targetPeer.isEnabled()) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   866
            Point newp = targetPeer.windowToLocal(x, y, this);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   867
            Component target = targetPeer.getTarget();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   868
            postMouseEnteredEvent(target, when, modifiers, newp, screenX, screenY, clickCount, popupTrigger, button);
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   869
        }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   870
    }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   871
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   872
    private void postMouseEnteredEvent(Component target, long when, int modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   873
                                       Point loc, int xAbs, int yAbs,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   874
                                       int clickCount, boolean popupTrigger, int button) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   875
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   876
        updateSecurityWarningVisibility();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   877
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   878
        postEvent(new MouseEvent(target,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   879
                MouseEvent.MOUSE_ENTERED,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   880
                when, modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   881
                loc.x, loc.y, xAbs, yAbs,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   882
                clickCount, popupTrigger, button));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   883
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   884
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   885
    private void postMouseExitedEvent(Component target, long when, int modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   886
                                      Point loc, int xAbs, int yAbs,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   887
                                      int clickCount, boolean popupTrigger, int button) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   888
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   889
        updateSecurityWarningVisibility();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   890
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   891
        postEvent(new MouseEvent(target,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   892
                MouseEvent.MOUSE_EXITED,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   893
                when, modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   894
                loc.x, loc.y, xAbs, yAbs,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   895
                clickCount, popupTrigger, button));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   896
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   897
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   898
    @Override
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   899
    public void notifyMouseWheelEvent(long when, int x, int y, int modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   900
                                      int scrollType, int scrollAmount,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   901
                                      int wheelRotation, double preciseWheelRotation,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   902
                                      byte[] bdata)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   903
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   904
        // TODO: could we just use the last mouse event target here?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   905
        Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   906
        // findPeerAt() expects parent coordinates
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
   907
        final LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   908
        if (targetPeer == null || !targetPeer.isEnabled()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   909
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   910
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   911
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   912
        Point lp = targetPeer.windowToLocal(x, y, this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   913
        // TODO: fill "bdata" member of AWTEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
        // TODO: screenX/screenY
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   915
        postEvent(new MouseWheelEvent(targetPeer.getTarget(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   916
                                      MouseEvent.MOUSE_WHEEL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   917
                                      when, modifiers,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   918
                                      lp.x, lp.y,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   919
                                      0, 0, /* screenX, Y */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   920
                                      0 /* clickCount */, false /* popupTrigger */,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   921
                                      scrollType, scrollAmount,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   922
                                      wheelRotation, preciseWheelRotation));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   923
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   924
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   925
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   926
     * Called by the delegate when a key is pressed.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   928
    @Override
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   929
    public void notifyKeyEvent(int id, long when, int modifiers,
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   930
                               int keyCode, char keyChar, int keyLocation)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   931
    {
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   932
        LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13647
diff changeset
   933
        Component focusOwner = kfmPeer.getCurrentFocusOwner();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   934
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   935
        if (focusOwner == null) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   936
            focusOwner = kfmPeer.getCurrentFocusedWindow();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   937
            if (focusOwner == null) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   938
                focusOwner = this.getTarget();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13648
diff changeset
   939
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   940
        }
20109
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   941
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   942
        KeyEvent keyEvent = new KeyEvent(focusOwner, id, when, modifiers,
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   943
            keyCode, keyChar, keyLocation);
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   944
        AWTAccessor.getKeyEventAccessor().setExtendedKeyCode(keyEvent,
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   945
            ExtendedKeyCodes.getExtendedKeyCodeForChar(keyChar));
e568ad7e1bf3 8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents: 18275
diff changeset
   946
        postEvent(keyEvent);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   947
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   948
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   949
    // ---- UTILITY METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   950
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   951
    private void activateDisplayListener() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   952
        final GraphicsEnvironment ge =
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   953
                GraphicsEnvironment.getLocalGraphicsEnvironment();
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   954
        ((SunGraphicsEnvironment) ge).addDisplayChangedListener(this);
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   955
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   956
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   957
    private void deactivateDisplayListener() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   958
        final GraphicsEnvironment ge =
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   959
                GraphicsEnvironment.getLocalGraphicsEnvironment();
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   960
        ((SunGraphicsEnvironment) ge).removeDisplayChangedListener(this);
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   961
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
   962
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   963
    private void postWindowStateChangedEvent(int newWindowState) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   964
        if (getTarget() instanceof Frame) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   965
            AWTAccessor.getFrameAccessor().setExtendedState(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   966
                    (Frame)getTarget(), newWindowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   967
        }
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   968
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   969
        WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   970
                WindowEvent.WINDOW_STATE_CHANGED,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   971
                windowState, newWindowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   972
        postEvent(stateChangedEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   973
        windowState = newWindowState;
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   974
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   975
        updateSecurityWarningVisibility();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   976
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   977
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   978
    private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   979
        // TODO: this method can be implemented in a more
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   980
        // efficient way by forwarding to the delegate
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   981
        GraphicsDevice gd = gc.getDevice();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   982
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   983
        GraphicsDevice[] gds = ge.getScreenDevices();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   984
        for (int i = 0; i < gds.length; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   985
            if (gds[i] == gd) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   986
                return i;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   987
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   988
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   989
        // Should never happen if gc is a screen device config
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   990
        return 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   991
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   992
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   993
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   994
     * This method is called when window's graphics config is changed from
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   995
     * the app code (e.g. when the window is made non-opaque) or when
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   996
     * the window is moved to another screen by user.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   997
     *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   998
     * Returns true if the graphics config has been changed, false otherwise.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   999
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1000
    private boolean setGraphicsConfig(GraphicsConfiguration gc) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1001
        synchronized (getStateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1002
            if (graphicsConfig == gc) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1003
                return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1004
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1005
            // If window's graphics config is changed from the app code, the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1006
            // config correspond to the same device as before; when the window
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1007
            // is moved by user, graphicsDevice is updated in notifyReshape().
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1008
            // In either case, there's nothing to do with screenOn here
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1009
            graphicsConfig = gc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1010
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1011
        // SurfaceData is replaced later in updateGraphicsData()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1012
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1013
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1014
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1015
    /**
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1016
     * Returns true if the GraphicsDevice has been changed, false otherwise.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1017
     */
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1018
    public boolean updateGraphicsDevice() {
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
  1019
        GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1020
        synchronized (getStateLock()) {
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
  1021
            if (graphicsDevice == newGraphicsDevice) {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1022
                return false;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1023
            }
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
  1024
            graphicsDevice = newGraphicsDevice;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1025
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1026
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
  1027
        final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12663
diff changeset
  1028
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1029
        if (!setGraphicsConfig(newGC)) return false;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1030
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1031
        SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1032
            public void run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1033
                AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1034
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1035
        });
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1036
        return true;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1037
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1038
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1039
    @Override
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1040
    public final void displayChanged() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1041
        updateGraphicsDevice();
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1042
        // Replace surface unconditionally, because internal state of the
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1043
        // GraphicsDevice could be changed.
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1044
        replaceSurfaceData();
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1045
        repaintPeer();
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1046
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1047
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1048
    @Override
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1049
    public final void paletteChanged() {
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1050
        // components do not need to react to this event.
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1051
    }
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 17150
diff changeset
  1052
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1053
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1054
     * May be called by delegate to provide SD to Java2D code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1055
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1056
    public SurfaceData getSurfaceData() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1057
        synchronized (surfaceDataLock) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1058
            return surfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1059
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1060
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1061
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1062
    private void replaceSurfaceData() {
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1063
        replaceSurfaceData(true);
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1064
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1065
14647
bacc2d4f4b27 7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents: 14311
diff changeset
  1066
    private void replaceSurfaceData(final boolean blit) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1067
        synchronized (surfaceDataLock) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1068
            final SurfaceData oldData = getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1069
            surfaceData = platformWindow.replaceSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1070
            final Rectangle size = getSize();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1071
            if (getSurfaceData() != null && oldData != getSurfaceData()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1072
                clearBackground(size.width, size.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1073
            }
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1074
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1075
            if (blit) {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1076
                blitSurfaceData(oldData, getSurfaceData());
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1077
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1078
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1079
            if (oldData != null && oldData != getSurfaceData()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1080
                // TODO: drop oldData for D3D/WGL pipelines
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1081
                // This can only happen when this peer is being created
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1082
                oldData.flush();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1083
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1084
        }
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1085
        flushOnscreenGraphics();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1086
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1087
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1088
    private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1089
        //TODO blit. proof-of-concept
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1090
        if (src != dst && src != null && dst != null
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1091
            && !(dst instanceof NullSurfaceData)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1092
            && !(src instanceof NullSurfaceData)
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1093
            && src.getSurfaceType().equals(dst.getSurfaceType())
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1094
            && src.getDefaultScale() == dst.getDefaultScale()) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1095
            final Rectangle size = src.getBounds();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1096
            final Blit blit = Blit.locate(src.getSurfaceType(),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1097
                                          CompositeType.Src,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1098
                                          dst.getSurfaceType());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1099
            if (blit != null) {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1100
                blit.Blit(src, dst, AlphaComposite.Src, null, 0, 0, 0, 0,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16839
diff changeset
  1101
                          size.width, size.height);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1102
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1103
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1104
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1105
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1106
    /**
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1107
     * Request the window insets from the delegate and compares it with the
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1108
     * current one. This method is mostly called by the delegate, e.g. when the
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1109
     * window state is changed and insets should be recalculated.
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1110
     * <p/>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1111
     * This method may be called on the toolkit thread.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1112
     */
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1113
    public final boolean updateInsets(final Insets newInsets) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1114
        synchronized (getStateLock()) {
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1115
            if (insets.equals(newInsets)) {
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1116
                return false;
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1117
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1118
            insets = newInsets;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1119
        }
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15323
diff changeset
  1120
        return true;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1121
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1122
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1123
    public static LWWindowPeer getWindowUnderCursor() {
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
  1124
        return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1125
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1126
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12176
diff changeset
  1127
    public static LWComponentPeer<?, ?> getPeerUnderCursor() {
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
  1128
        return lastCommonMouseEventPeer;
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12176
diff changeset
  1129
    }
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12176
diff changeset
  1130
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1131
    /*
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1132
     * Requests platform to set native focus on a frame/dialog.
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1133
     * In case of a simple window, triggers appropriate java focus change.
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1134
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1135
    public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1136
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1137
            focusLog.fine("requesting native focus to " + this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1138
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1139
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1140
        if (!focusAllowedFor()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1141
            focusLog.fine("focus is not allowed");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1142
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1143
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1144
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
  1145
        if (platformWindow.rejectFocusRequest(cause)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1146
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1147
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1148
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1149
        Window currentActive = KeyboardFocusManager.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1150
            getCurrentKeyboardFocusManager().getActiveWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1151
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1152
        Window opposite = LWKeyboardFocusManagerPeer.getInstance().
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1153
            getCurrentFocusedWindow();
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1154
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1155
        // Make the owner active window.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1156
        if (isSimpleWindow()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1157
            LWWindowPeer owner = getOwnerFrameDialog(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1158
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1159
            // If owner is not natively active, request native
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1160
            // activation on it w/o sending events up to java.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1161
            if (owner != null && !owner.platformWindow.isActive()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1162
                if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1163
                    focusLog.fine("requesting native focus to the owner " + owner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1164
                }
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1165
                LWWindowPeer currentActivePeer = currentActive == null ? null :
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1166
                (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1167
                        currentActive);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1168
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1169
                // Ensure the opposite is natively active and suppress sending events.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1170
                if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1171
                    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1172
                        focusLog.fine("the opposite is " + currentActivePeer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1173
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1174
                    currentActivePeer.skipNextFocusChange = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1175
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1176
                owner.skipNextFocusChange = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1177
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1178
                owner.platformWindow.requestWindowFocus();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1179
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1180
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1181
            // DKFM will synthesize all the focus/activation events correctly.
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1182
            changeFocusedWindow(true, opposite);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1183
            return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1184
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1185
        // In case the toplevel is active but not focused, change focus directly,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1186
        // as requesting native focus on it will not have effect.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1187
        } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1188
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1189
            changeFocusedWindow(true, opposite);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1190
            return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1191
        }
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1192
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1193
        return platformWindow.requestWindowFocus();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1194
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1195
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1196
    protected boolean focusAllowedFor() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1197
        Window window = getTarget();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1198
        // TODO: check if modal blocked
12663
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1199
        return window.isVisible() && window.isEnabled() && isFocusableWindow();
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1200
    }
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1201
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1202
    private boolean isFocusableWindow() {
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1203
        boolean focusable = getTarget().isFocusableWindow();
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1204
        if (isSimpleWindow()) {
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1205
            LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1206
            if (ownerPeer == null) {
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1207
                return false;
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1208
            }
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1209
            return focusable && ownerPeer.getTarget().isFocusableWindow();
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1210
        }
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1211
        return focusable;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1212
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1213
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1214
    public boolean isSimpleWindow() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1215
        Window window = getTarget();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1216
        return !(window instanceof Dialog || window instanceof Frame);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1217
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1218
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1219
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1220
    public void emulateActivation(boolean activate) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1221
        changeFocusedWindow(activate, null);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1222
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1223
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1224
    /*
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1225
     * Changes focused window on java level.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1226
     */
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
  1227
    protected void changeFocusedWindow(boolean becomesFocused, Window opposite) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1228
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1229
            focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1230
        }
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1231
        if (skipNextFocusChange) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1232
            focusLog.fine("skipping focus change");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1233
            skipNextFocusChange = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1234
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1235
        }
12663
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1236
        if (!isFocusableWindow() && becomesFocused) {
58d40d4a87b3 7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents: 12662
diff changeset
  1237
            focusLog.fine("the window is not focusable");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1238
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1239
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1240
        if (becomesFocused) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1241
            synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1242
                if (blocker != null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1243
                    if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1244
                        focusLog.finest("the window is blocked by " + blocker);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1245
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1246
                    return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1247
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1248
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1249
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1250
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1251
        // Note, the method is not called:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1252
        // - when the opposite (gaining focus) window is an owned/owner window.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1253
        // - for a simple window in any case.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1254
        if (!becomesFocused &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1255
            (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1256
        {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17151
diff changeset
  1257
            if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15983
diff changeset
  1258
                focusLog.fine("ungrabbing on " + grabbingWindow);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15983
diff changeset
  1259
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1260
            // ungrab a simple window if its owner looses activation.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1261
            grabbingWindow.ungrab();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1262
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1263
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1264
        KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 13647
diff changeset
  1265
        kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1266
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1267
        int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1268
        WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1269
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1270
        // TODO: wrap in SequencedEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1271
        postEvent(windowEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1272
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1273
12662
184d8d3b7fff 7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents: 12640
diff changeset
  1274
    static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1275
        Window owner = (peer != null ? peer.getTarget().getOwner() : null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1276
        while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1277
            owner = owner.getOwner();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1278
        }
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1279
        return owner == null ? null :
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1280
               (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1281
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1283
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1284
     * Returns the foremost modal blocker of this window, or null.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1285
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1286
    public LWWindowPeer getBlocker() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1287
        synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1288
            LWWindowPeer blocker = this.blocker;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1289
            if (blocker == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1290
                return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1291
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1292
            while (blocker.blocker != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1293
                blocker = blocker.blocker;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1294
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1295
            return blocker;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1296
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1297
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1298
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1299
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1300
    public void enterFullScreenMode() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1301
        platformWindow.enterFullScreenMode();
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1302
        updateSecurityWarningVisibility();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1303
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1304
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 20109
diff changeset
  1305
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1306
    public void exitFullScreenMode() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1307
        platformWindow.exitFullScreenMode();
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1308
        updateSecurityWarningVisibility();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1309
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1310
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1311
    public long getLayerPtr() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1312
        return getPlatformWindow().getLayerPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1313
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1314
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1315
    void grab() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1316
        if (grabbingWindow != null && !isGrabbing()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1317
            grabbingWindow.ungrab();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1318
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1319
        grabbingWindow = this;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1320
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1321
15323
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1322
    final void ungrab(boolean doPost) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1323
        if (isGrabbing()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1324
            grabbingWindow = null;
15323
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1325
            if (doPost) {
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1326
                postEvent(new UngrabEvent(getTarget()));
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1327
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1328
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1329
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1330
15323
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1331
    void ungrab() {
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1332
        ungrab(true);
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1333
    }
9087838098e6 8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents: 14753
diff changeset
  1334
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1335
    private boolean isGrabbing() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1336
        return this == grabbingWindow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1337
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1338
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
  1339
    public PeerType getPeerType() {
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
  1340
        return peerType;
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
  1341
    }
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14647
diff changeset
  1342
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1343
    public void updateSecurityWarningVisibility() {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1344
        if (warningWindow == null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1345
            return;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1346
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1347
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1348
        if (!isVisible()) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1349
            return; // The warning window should already be hidden.
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1350
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1351
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1352
        boolean show = false;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1353
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1354
        if (!platformWindow.isFullScreenMode()) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1355
            if (isVisible()) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1356
                if (LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() ==
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1357
                        getTarget()) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1358
                    show = true;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1359
                }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1360
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1361
                if (platformWindow.isUnderMouse() || warningWindow.isUnderMouse()) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1362
                    show = true;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1363
                }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1364
            }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1365
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1366
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1367
        warningWindow.setVisible(show, true);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1368
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1369
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1370
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1371
    public String toString() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1372
        return super.toString() + " [target is " + getTarget() + "]";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1373
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1374
}