src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
author mhalder
Wed, 21 Mar 2018 12:08:16 +0530
changeset 49305 2f2b37908f91
parent 49225 e0b025915be8
child 49989 ecc7b10a1cca
permissions -rw-r--r--
7158623: Should an unfocusable maximized Frame be resizable Reviewed-by: prr, sveerabhadra
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
/*
44653
1f82cdcbaec6 8176490: [macosx] Sometimes NSWindow.isZoomed hangs
dmarkov
parents: 43204
diff changeset
     2
 * Copyright (c) 2011, 2017, 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.macosx;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    28
import java.awt.Color;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    29
import java.awt.Component;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    30
import java.awt.DefaultKeyboardFocusManager;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    31
import java.awt.Dialog;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.awt.Dialog.ModalityType;
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    33
import java.awt.Font;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    34
import java.awt.FontMetrics;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    35
import java.awt.Frame;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    36
import java.awt.GraphicsDevice;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    37
import java.awt.Insets;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    38
import java.awt.MenuBar;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    39
import java.awt.Point;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    40
import java.awt.Rectangle;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    41
import java.awt.Toolkit;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    42
import java.awt.Window;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    43
import java.awt.event.FocusEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    44
import java.awt.event.WindowEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    45
import java.beans.PropertyChangeEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    46
import java.beans.PropertyChangeListener;
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
    47
import java.lang.reflect.InvocationTargetException;
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
    48
import java.util.ArrayList;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
    49
import java.util.Arrays;
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
    50
import java.util.Comparator;
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
    51
import java.util.concurrent.atomic.AtomicBoolean;
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
    52
import java.util.concurrent.atomic.AtomicLong;
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
    53
import java.util.concurrent.atomic.AtomicReference;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    55
import javax.swing.JRootPane;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    56
import javax.swing.RootPaneContainer;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    57
import javax.swing.SwingUtilities;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    59
import com.apple.laf.ClientPropertyApplicator;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    60
import com.apple.laf.ClientPropertyApplicator.Property;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    61
import sun.awt.AWTAccessor;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
    62
import sun.awt.AWTAccessor.ComponentAccessor;
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
    63
import sun.awt.AWTAccessor.WindowAccessor;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
import sun.java2d.SurfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
import sun.java2d.opengl.CGLSurfaceData;
47827
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
    66
import sun.lwawt.LWLightweightFramePeer;
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    67
import sun.lwawt.LWToolkit;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    68
import sun.lwawt.LWWindowPeer;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    69
import sun.lwawt.LWWindowPeer.PeerType;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
    70
import sun.lwawt.PlatformWindow;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
import sun.util.logging.PlatformLogger;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
    73
public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18763
diff changeset
    74
    private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
39511
a7ad23d3d161 8025130: [macosx] Frame setLocationByPlatform has no effect under Mac OS X
dmarkov
parents: 38970
diff changeset
    79
    private static native void nativeSetNSWindowLocationByPlatform(long nsWindowPtr);
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
    80
    private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
    81
            double x, double y, double w, double h);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    private static native void nativePushNSWindowToBack(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    private static native void nativePushNSWindowToFront(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
    89
    private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    90
    private static native void nativeSynthesizeMouseEnteredExitedEvents();
40993
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
    91
    private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr, int eventType);
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
    92
    private static native void nativeDispose(long nsWindowPtr);
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21272
diff changeset
    93
    private static native void nativeEnterFullScreenMode(long nsWindowPtr);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21272
diff changeset
    94
    private static native void nativeExitFullScreenMode(long nsWindowPtr);
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 30469
diff changeset
    95
    static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    // Loger to report issues happened during execution but that do not affect functionality
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
    99
    private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
12047
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
    // for client properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
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
    public static final String WINDOW_ALPHA = "Window.alpha";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    public static final String WINDOW_SHADOW = "Window.shadow";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    public static final String WINDOW_STYLE = "Window.style";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    public static final String WINDOW_CLOSEABLE = "Window.closeable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    public static final String WINDOW_ZOOMABLE = "Window.zoomable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    public static final String WINDOW_HIDES_ON_DEACTIVATE="Window.hidesOnDeactivate";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    public static final String WINDOW_DOC_MODAL_SHEET = "apple.awt.documentModalSheet";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    public static final String WINDOW_FADE_DELEGATE = "apple.awt._windowFadeDelegate";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    public static final String WINDOW_FADE_IN = "apple.awt._windowFadeIn";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    public static final String WINDOW_FADE_OUT = "apple.awt._windowFadeOut";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
    public static final String WINDOW_FULLSCREENABLE = "apple.awt.fullscreenable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
    // Yeah, I know. But it's easier to deal with ints from JNI
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    static final int MODELESS = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
    static final int DOCUMENT_MODAL = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    static final int APPLICATION_MODAL = 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    static final int TOOLKIT_MODAL = 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
    // window style bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    static final int _RESERVED_FOR_DATA = 1 << 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    // corresponds to native style mask bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    static final int DECORATED = 1 << 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    static final int TEXTURED = 1 << 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    static final int UNIFIED = 1 << 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    static final int UTILITY = 1 << 4;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    static final int HUD = 1 << 5;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    static final int SHEET = 1 << 6;
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
    static final int CLOSEABLE = 1 << 7;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
    static final int MINIMIZABLE = 1 << 8;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    static final int RESIZABLE = 1 << 9; // both a style bit and prop bit
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   147
    static final int NONACTIVATING = 1 << 24;
17684
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   148
    static final int IS_DIALOG = 1 << 25;
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   149
    static final int IS_MODAL = 1 << 26;
25120
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 23670
diff changeset
   150
    static final int IS_POPUP = 1 << 27;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    static final int _STYLE_PROP_BITMASK = DECORATED | TEXTURED | UNIFIED | UTILITY | HUD | SHEET | CLOSEABLE | MINIMIZABLE | RESIZABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
    // corresponds to method-based properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    static final int HAS_SHADOW = 1 << 10;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
    static final int ZOOMABLE = 1 << 11;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    static final int ALWAYS_ON_TOP = 1 << 15;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    static final int HIDES_ON_DEACTIVATE = 1 << 17;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    static final int DRAGGABLE_BACKGROUND = 1 << 19;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    static final int DOCUMENT_MODIFIED = 1 << 21;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    static final int FULLSCREENABLE = 1 << 23;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    static final int _METHOD_PROP_BITMASK = RESIZABLE | HAS_SHADOW | ZOOMABLE | ALWAYS_ON_TOP | HIDES_ON_DEACTIVATE | DRAGGABLE_BACKGROUND | DOCUMENT_MODIFIED | FULLSCREENABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
    // corresponds to callback-based properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    static final int SHOULD_BECOME_KEY = 1 << 12;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    static final int SHOULD_BECOME_MAIN = 1 << 13;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    static final int MODAL_EXCLUDED = 1 << 16;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
    static final int _CALLBACK_PROP_BITMASK = SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | MODAL_EXCLUDED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    static int SET(final int bits, final int mask, final boolean value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
        if (value) return (bits | mask);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
        return bits & ~mask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    }
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
    static boolean IS(final int bits, final int mask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        return (bits & mask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
25762
c4a3548120c6 8044862: Fix raw and unchecked lint warnings in macosx specific code
henryjen
parents: 25196
diff changeset
   182
    @SuppressWarnings({"unchecked", "rawtypes"})
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    static ClientPropertyApplicator<JRootPane, CPlatformWindow> CLIENT_PROPERTY_APPLICATOR = new ClientPropertyApplicator<JRootPane, CPlatformWindow>(new Property[] {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
        new Property<CPlatformWindow>(WINDOW_DOCUMENT_MODIFIED) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
            c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        new Property<CPlatformWindow>(WINDOW_BRUSH_METAL_LOOK) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
            c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
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
        new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47388
diff changeset
   191
            c.target.setOpacity(value == null ? 1.0f : Float.parseFloat(value.toString()));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
        new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
            c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        new Property<CPlatformWindow>(WINDOW_MINIMIZABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
            c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
        new Property<CPlatformWindow>(WINDOW_CLOSEABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
            c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
        new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   203
            boolean zoomable = Boolean.parseBoolean(value.toString());
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   204
            if (c.target instanceof RootPaneContainer
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   205
                    && c.getPeer().getPeerType() == PeerType.FRAME) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   206
                if (c.isInFullScreen && !zoomable) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   207
                    c.toggleFullScreen();
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   208
                }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   209
            }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   210
            c.setStyleBits(ZOOMABLE, zoomable);
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
        new Property<CPlatformWindow>(WINDOW_FULLSCREENABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   213
            boolean fullscrenable = Boolean.parseBoolean(value.toString());
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   214
            if (c.target instanceof RootPaneContainer
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   215
                    && c.getPeer().getPeerType() == PeerType.FRAME) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   216
                if (c.isInFullScreen && !fullscrenable) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   217
                    c.toggleFullScreen();
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   218
                }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   219
            }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   220
            c.setStyleBits(FULLSCREENABLE, fullscrenable);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
        new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   223
            c.execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
            if (value == null || !(value instanceof java.io.File)) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   227
                c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, null));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
            final String filename = ((java.io.File)value).getAbsolutePath();
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   232
            c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, filename));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
        }}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    }) {
28235
0dfebfcb9f8a 8067086: Suppress mac-specific deprecation warnings in the java.desktop module
darcy
parents: 27504
diff changeset
   235
        @SuppressWarnings("deprecation")
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
        public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
            Component root = SwingUtilities.getRoot(p);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   238
            final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   239
            if (root == null || acc.getPeer(root) == null) return null;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   240
            return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    };
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   243
    private final Comparator<Window> siblingsComparator = (w1, w2) -> {
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   244
        if (w1 == w2) {
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   245
            return 0;
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   246
        }
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   247
        ComponentAccessor componentAccessor = AWTAccessor.getComponentAccessor();
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   248
        Object p1 = componentAccessor.getPeer(w1);
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   249
        Object p2 = componentAccessor.getPeer(w2);
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   250
        if (p1 instanceof LWWindowPeer && p2 instanceof LWWindowPeer) {
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   251
            return Long.compare(
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   252
                    ((CPlatformWindow) (((LWWindowPeer) p1).getPlatformWindow())).lastBecomeMainTime,
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   253
                    ((CPlatformWindow) (((LWWindowPeer) p2).getPlatformWindow())).lastBecomeMainTime);
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   254
        }
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   255
        return 0;
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   256
    };
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
    // Bounds of the native widget but in the Java coordinate system.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
    // In order to keep it up-to-date we will update them on
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
    // 1) setting native bounds via nativeSetBounds() call
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
    // 2) getting notification from the native level via deliverMoveResizeEvent()
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   262
    private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
   263
    private volatile boolean isFullScreenMode;
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
   264
    private boolean isFullScreenAnimationOn;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   266
    private volatile boolean isInFullScreen;
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
   267
    private volatile boolean isIconifyAnimationActive;
44653
1f82cdcbaec6 8176490: [macosx] Sometimes NSWindow.isZoomed hangs
dmarkov
parents: 43204
diff changeset
   268
    private volatile boolean isZoomed;
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   269
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    private Window target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
    private LWWindowPeer peer;
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   272
    protected CPlatformView contentView;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   273
    protected CPlatformWindow owner;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   274
    protected boolean visible = false; // visibility status from native perspective
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   275
    private boolean undecorated; // initialized in getInitialStyleBits()
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   276
    private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
12664
91828a78446f 7156191: [macosx] Can't type into applet demos in Pivot
dcherepanov
parents: 12647
diff changeset
   277
    private CPlatformResponder responder;
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
   278
    private long lastBecomeMainTime; // this is necessary to preserve right siblings order
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
   280
    public CPlatformWindow() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
        super(0, true);
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
     * Delegate initialization (create native window and all the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
     * related resources).
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
    public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   290
        initializeBase(_target, _peer, _owner, new CPlatformView());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        final int styleBits = getInitialStyleBits();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   294
        responder = createPlatformResponder();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   295
        contentView = createContentView();
12664
91828a78446f 7156191: [macosx] Can't type into applet demos in Pivot
dcherepanov
parents: 12647
diff changeset
   296
        contentView.initialize(peer, responder);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
21272
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   298
        Rectangle bounds;
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   299
        if (!IS(DECORATED, styleBits)) {
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   300
            // For undecorated frames the move/resize event does not come if the frame is centered on the screen
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   301
            // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   302
            bounds = new Rectangle(0, 0, 1, 1);
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   303
        } else {
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   304
            bounds = _peer.constrainBounds(_target.getBounds());
aac4dd1cd15d 8027025: [macosx] getLocationOnScreen returns 0 if parent invisible
pchelko
parents: 21248
diff changeset
   305
        }
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   306
        AtomicLong ref = new AtomicLong();
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   307
        contentView.execute(viewPtr -> {
45345
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   308
            boolean hasOwnerPtr = false;
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   309
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   310
            if (owner != null) {
45345
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   311
                hasOwnerPtr = 0L != owner.executeGet(ownerPtr -> {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   312
                    ref.set(nativeCreateNSWindow(viewPtr, ownerPtr, styleBits,
45345
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   313
                                                    bounds.x, bounds.y,
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   314
                                                    bounds.width, bounds.height));
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   315
                    return 1;
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   316
                });
45345
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   317
            }
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   318
f5223be944fa 8178996: [macos] JComboBox doesn't display popup in mixed JavaFX Swing Application on 8u131 and Mac OS 10.12
azvegint
parents: 44752
diff changeset
   319
            if (!hasOwnerPtr) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   320
                ref.set(nativeCreateNSWindow(viewPtr, 0,
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   321
                                             styleBits, bounds.x, bounds.y,
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   322
                                             bounds.width, bounds.height));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   323
            }
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   324
        });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   325
        setPtr(ref.get());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
        if (target instanceof javax.swing.RootPaneContainer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
            final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
            if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
                public void propertyChange(final PropertyChangeEvent evt) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
                    CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
                    rootpane.removePropertyChangeListener("ancestor", this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
            });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
        validateSurface();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   340
    protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   341
        this.peer = peer;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   342
        this.target = target;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   343
        if (owner instanceof CPlatformWindow) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   344
            this.owner = (CPlatformWindow)owner;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   345
        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   346
        this.contentView = view;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   347
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 15331
diff changeset
   348
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   349
    protected CPlatformResponder createPlatformResponder() {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   350
        return new CPlatformResponder(peer, false);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   351
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   352
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   353
    protected CPlatformView createContentView() {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   354
        return new CPlatformView();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   355
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   356
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   357
    protected int getInitialStyleBits() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
        // defaults style bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
        int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
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
        if (isNativelyFocusableWindow()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
            styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
            styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
        final boolean isFrame = (target instanceof Frame);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
        final boolean isDialog = (target instanceof Dialog);
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   368
        final boolean isPopup = (target.getType() == Window.Type.POPUP);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
        if (isDialog) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
            styleBits = SET(styleBits, MINIMIZABLE, false);
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
        // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
        {
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   375
            this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   376
            if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
        // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
            final boolean resizable = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
            styleBits = SET(styleBits, RESIZABLE, resizable);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
            if (!resizable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
                styleBits = SET(styleBits, ZOOMABLE, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
            }
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
        if (target.isAlwaysOnTop()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
            styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
        }
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
        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
            styleBits = SET(styleBits, MODAL_EXCLUDED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
        // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   397
        if (isPopup) {
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   398
            styleBits = SET(styleBits, TEXTURED, false);
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   399
            // Popups in applets don't activate applet's process
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   400
            styleBits = SET(styleBits, NONACTIVATING, true);
25120
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 23670
diff changeset
   401
            styleBits = SET(styleBits, IS_POPUP, true);
12047
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
12647
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   404
        if (Window.Type.UTILITY.equals(target.getType())) {
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   405
            styleBits = SET(styleBits, UTILITY, true);
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   406
        }
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   407
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
        if (target instanceof javax.swing.RootPaneContainer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
            javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
            Object prop = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
            prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
                styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
            if (isDialog && ((Dialog)target).getModalityType() == ModalityType.DOCUMENT_MODAL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
                prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
                if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
                    styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
            prop = rootpane.getClientProperty(WINDOW_STYLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
                if ("small".equals(prop))  {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
                    styleBits = SET(styleBits, UTILITY, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
                    if (target.isAlwaysOnTop() && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
                        styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true);
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
                if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
                if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
                if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
            }
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
            prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
                styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
            prop = rootpane.getClientProperty(WINDOW_CLOSEABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
                styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
            prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
                styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString()));
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
            prop = rootpane.getClientProperty(WINDOW_ZOOMABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
                styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
            prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
                styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
            prop = rootpane.getClientProperty(WINDOW_SHADOW);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
                styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
            prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
                styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
17684
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   473
        if (isDialog) {
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   474
            styleBits = SET(styleBits, IS_DIALOG, true);
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   475
            if (((Dialog) target).isModal()) {
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   476
                styleBits = SET(styleBits, IS_MODAL, true);
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   477
            }
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   478
        }
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 17151
diff changeset
   479
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   480
        peer.setTextured(IS(TEXTURED, styleBits));
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   481
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
        return styleBits;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
    // this is the counter-point to -[CWindow _nativeSetStyleBit:]
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14647
diff changeset
   486
    private void setStyleBits(final int mask, final boolean value) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   487
        execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   490
    private native void _toggleFullScreenMode(final long model);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   491
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   492
    public void toggleFullScreen() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   493
        execute(this::_toggleFullScreenMode);
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
    public void setMenuBar(MenuBar mb) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
        CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   499
        execute(nsWindowPtr->{
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   500
            if (mbPeer != null) {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   501
                mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   502
            } else {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   503
                nativeSetNSWindowMenuBar(nsWindowPtr, 0);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   504
            }
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   505
        });
12047
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 // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    public void dispose() {
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 13009
diff changeset
   510
        contentView.dispose();
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   511
        execute(CPlatformWindow::nativeDispose);
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 13009
diff changeset
   512
        CPlatformWindow.super.dispose();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
    public FontMetrics getFontMetrics(Font f) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   518
        (new RuntimeException("unimplemented")).printStackTrace();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
    }
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
    public Insets getInsets() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   524
        AtomicReference<Insets> ref = new AtomicReference<>();
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   525
        execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   526
            ref.set(nativeGetNSWindowInsets(ptr));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   527
        });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   528
        return ref.get() != null ? ref.get() : new Insets(0, 0, 0, 0);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
    public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
        return new Point(nativeBounds.x, nativeBounds.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   536
    @Override
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   537
    public GraphicsDevice getGraphicsDevice() {
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
   538
        return contentView.getGraphicsDevice();
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
    public SurfaceData getScreenSurface() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
    public SurfaceData replaceSurfaceData() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
        return contentView.replaceSurfaceData();
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
    public void setBounds(int x, int y, int w, int h) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   554
        execute(ptr -> nativeSetNSWindowBounds(ptr, x, y, w, h));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   557
    public void setMaximizedBounds(int x, int y, int w, int h) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   558
        execute(ptr -> nativeSetNSWindowStandardFrame(ptr, x, y, w, h));
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   559
    }
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   560
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   561
    private boolean isMaximized() {
20457
ecb935d774a3 8007219: [macosx] Frame size reverts meaning of maximized attribute if frame size close to display
alexsch
parents: 20135
diff changeset
   562
        return undecorated ? this.normalBounds != null
44653
1f82cdcbaec6 8176490: [macosx] Sometimes NSWindow.isZoomed hangs
dmarkov
parents: 43204
diff changeset
   563
                : isZoomed;
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   564
    }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   565
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   566
    private void maximize() {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   567
        if (peer == null || isMaximized()) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   568
            return;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   569
        }
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   570
        if (!undecorated) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   571
            execute(CWrapper.NSWindow::zoom);
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   572
        } else {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   573
            deliverZoom(true);
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   574
29519
53b8aa64c82d 8066436: Minimize can cause window to disappear on osx
alitvinov
parents: 28235
diff changeset
   575
            // We need an up to date size of the peer, so we flush the native events
53b8aa64c82d 8066436: Minimize can cause window to disappear on osx
alitvinov
parents: 28235
diff changeset
   576
            // to be sure that there are no setBounds requests in the queue.
53b8aa64c82d 8066436: Minimize can cause window to disappear on osx
alitvinov
parents: 28235
diff changeset
   577
            LWCToolkit.flushNativeSelectors();
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   578
            this.normalBounds = peer.getBounds();
32480
6d72f6be8202 8131339: [macosx] setMaximizedBounds() doesn't work for undecorated Frame
alexsch
parents: 31161
diff changeset
   579
            Rectangle maximizedBounds = peer.getMaximizedBounds();
6d72f6be8202 8131339: [macosx] setMaximizedBounds() doesn't work for undecorated Frame
alexsch
parents: 31161
diff changeset
   580
            setBounds(maximizedBounds.x, maximizedBounds.y,
6d72f6be8202 8131339: [macosx] setMaximizedBounds() doesn't work for undecorated Frame
alexsch
parents: 31161
diff changeset
   581
                    maximizedBounds.width, maximizedBounds.height);
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   582
        }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   583
    }
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   584
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   585
    private void unmaximize() {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   586
        if (!isMaximized()) {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   587
            return;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   588
        }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   589
        if (!undecorated) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   590
            execute(CWrapper.NSWindow::zoom);
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   591
        } else {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   592
            deliverZoom(false);
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   593
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   594
            Rectangle toBounds = this.normalBounds;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   595
            this.normalBounds = null;
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   596
            setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   597
        }
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   598
    }
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   599
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   600
    public boolean isVisible() {
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   601
        return this.visible;
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   602
    }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   603
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
    public void setVisible(boolean visible) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   606
        // Configure stuff
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
        updateIconImages();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
        updateFocusabilityForAutoRequestFocus(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   610
        boolean wasMaximized = isMaximized();
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   611
39511
a7ad23d3d161 8025130: [macosx] Frame setLocationByPlatform has no effect under Mac OS X
dmarkov
parents: 38970
diff changeset
   612
        if (visible && target.isLocationByPlatform()) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   613
            execute(CPlatformWindow::nativeSetNSWindowLocationByPlatform);
39511
a7ad23d3d161 8025130: [macosx] Frame setLocationByPlatform has no effect under Mac OS X
dmarkov
parents: 38970
diff changeset
   614
        }
a7ad23d3d161 8025130: [macosx] Frame setLocationByPlatform has no effect under Mac OS X
dmarkov
parents: 38970
diff changeset
   615
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   616
        // Actually show or hide the window
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   617
        LWWindowPeer blocker = (peer == null)? null : peer.getBlocker();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
        if (blocker == null || !visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
            // If it ain't blocked, or is being hidden, go regular way
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
            if (visible) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   621
                contentView.execute(viewPtr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   622
                    execute(ptr -> CWrapper.NSWindow.makeFirstResponder(ptr,
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   623
                                                                        viewPtr));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   624
                });
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   625
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   626
                boolean isPopup = (target.getType() == Window.Type.POPUP);
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   627
                execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   628
                    if (isPopup) {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   629
                        // Popups in applets don't activate applet's process
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   630
                        CWrapper.NSWindow.orderFrontRegardless(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   631
                    } else {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   632
                        CWrapper.NSWindow.orderFront(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   633
                    }
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   634
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   635
                    boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   636
                    if (!isKeyWindow) {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   637
                        CWrapper.NSWindow.makeKeyWindow(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   638
                    }
47827
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   639
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   640
                    if (owner != null
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   641
                            && owner.getPeer() instanceof LWLightweightFramePeer) {
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   642
                        LWLightweightFramePeer peer =
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   643
                                (LWLightweightFramePeer) owner.getPeer();
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   644
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   645
                        long ownerWindowPtr = peer.getOverriddenWindowHandle();
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   646
                        if (ownerWindowPtr != 0) {
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   647
                            //Place window above JavaFX stage
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   648
                            CWrapper.NSWindow.addChildWindow(
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   649
                                    ownerWindowPtr, ptr,
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   650
                                    CWrapper.NSWindow.NSWindowAbove);
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   651
                        }
f2238a5326e7 8187803: JDK part of JavaFX-Swing dialogs appearing behind main stage
azvegint
parents: 47516
diff changeset
   652
                    }
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   653
                });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
            } else {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   655
                execute(ptr->{
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   656
                    // immediately hide the window
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   657
                    CWrapper.NSWindow.orderOut(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   658
                    // process the close
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   659
                    CWrapper.NSWindow.close(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   660
                });
12047
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
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
            // otherwise, put it in a proper z-order
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   664
            CPlatformWindow bw
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   665
                    = (CPlatformWindow) blocker.getPlatformWindow();
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   666
            bw.execute(blockerPtr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   667
                execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   668
                    CWrapper.NSWindow.orderWindow(ptr,
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   669
                                                  CWrapper.NSWindow.NSWindowBelow,
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   670
                                                  blockerPtr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   671
                });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   672
            });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
        }
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   674
        this.visible = visible;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   676
        // Manage the extended state when showing
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
        if (visible) {
49225
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   678
            /* Frame or Dialog should be set property WINDOW_FULLSCREENABLE to true if the
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   679
            Frame or Dialog is resizable.
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   680
            **/
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   681
            final boolean resizable = (target instanceof Frame) ? ((Frame)target).isResizable() :
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   682
            ((target instanceof Dialog) ? ((Dialog)target).isResizable() : false);
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   683
            if (resizable) {
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   684
                setCanFullscreen(true);
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   685
            }
e0b025915be8 8190767: if JFrame is maximized on OS X, all new JFrames will be maximized by default
mhalder
parents: 47827
diff changeset
   686
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   687
            // Apply the extended state as expected in shared code
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
            if (target instanceof Frame) {
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   689
                if (!wasMaximized && isMaximized()) {
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   690
                    // setVisible could have changed the native maximized state
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   691
                    deliverZoom(true);
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   692
                } else {
23309
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   693
                    int frameState = ((Frame)target).getExtendedState();
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   694
                    if ((frameState & Frame.ICONIFIED) != 0) {
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   695
                        // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   696
                        frameState = Frame.ICONIFIED;
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   697
                    }
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   698
                    switch (frameState) {
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   699
                        case Frame.ICONIFIED:
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   700
                            execute(CWrapper.NSWindow::miniaturize);
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   701
                            break;
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   702
                        case Frame.MAXIMIZED_BOTH:
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   703
                            maximize();
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   704
                            break;
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   705
                        default: // NORMAL
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   706
                            unmaximize(); // in case it was maximized, otherwise this is a no-op
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   707
                            break;
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
   708
                    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   713
        nativeSynthesizeMouseEnteredExitedEvents();
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12403
diff changeset
   714
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   715
        // Configure stuff #2
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   716
        updateFocusabilityForAutoRequestFocus(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   717
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   718
        // Manage parent-child relationship when showing
38970
aabcf4406038 8080729: [macosx] java 7 and 8 JDialogs on multiscreen jump to parent frame on focus
dmarkov
parents: 37700
diff changeset
   719
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
aabcf4406038 8080729: [macosx] java 7 and 8 JDialogs on multiscreen jump to parent frame on focus
dmarkov
parents: 37700
diff changeset
   720
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   721
        if (visible) {
38970
aabcf4406038 8080729: [macosx] java 7 and 8 JDialogs on multiscreen jump to parent frame on focus
dmarkov
parents: 37700
diff changeset
   722
            // Order myself above my parent
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   723
            if (owner != null && owner.isVisible()) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   724
                owner.execute(ownerPtr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   725
                    execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   726
                        CWrapper.NSWindow.orderWindow(ptr, CWrapper.NSWindow.NSWindowAbove, ownerPtr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   727
                    });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   728
                });
47388
19b912843392 8182638: [macosx] Active modal dialog is hidden by another non-active one
ssadetsky
parents: 47216
diff changeset
   729
                execute(CWrapper.NSWindow::orderFront);
23253
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
   730
                applyWindowLevel(target);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   731
            }
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   732
38970
aabcf4406038 8080729: [macosx] java 7 and 8 JDialogs on multiscreen jump to parent frame on focus
dmarkov
parents: 37700
diff changeset
   733
            // Order my own children above myself
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   734
            for (Window w : target.getOwnedWindows()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   735
                final Object p = acc.getPeer(w);
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   736
                if (p instanceof LWWindowPeer) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   737
                    CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   738
                    if (pw != null && pw.isVisible()) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   739
                        pw.execute(childPtr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   740
                            execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   741
                                CWrapper.NSWindow.orderWindow(childPtr, CWrapper.NSWindow.NSWindowAbove, ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   742
                            });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   743
                        });
23253
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
   744
                        pw.applyWindowLevel(w);
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   745
                    }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   746
                }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   747
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   750
        // Deal with the blocker of the window being shown
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
        if (blocker != null && visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
            // Make sure the blocker is above its siblings
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
            ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   754
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   755
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   756
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   757
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   758
    public void setTitle(String title) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   759
        execute(ptr -> nativeSetNSWindowTitle(ptr, title));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   760
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   761
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   762
    // Should be called on every window key property change.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   763
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
    public void updateIconImages() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
        final CImage cImage = getImageForTarget();
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   766
        execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   767
            if (cImage == null) {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   768
                nativeSetNSWindowMinimizedIcon(ptr, 0L);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   769
            } else {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   770
                cImage.execute(imagePtr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   771
                    nativeSetNSWindowMinimizedIcon(ptr, imagePtr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   772
                });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   773
            }
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   774
        });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   775
    }
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
    public SurfaceData getSurfaceData() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   778
        return contentView.getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   779
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   780
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   781
    @Override  // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   782
    public void toBack() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   783
        execute(CPlatformWindow::nativePushNSWindowToBack);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   784
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   785
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   786
    @Override  // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   787
    public void toFront() {
27272
cffe6690ee9d 8038919: Requesting focus to a modeless dialog doesn't work on Safari
mcherkas
parents: 27052
diff changeset
   788
        LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
cffe6690ee9d 8038919: Requesting focus to a modeless dialog doesn't work on Safari
mcherkas
parents: 27052
diff changeset
   789
        Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   790
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   791
        if( w != null && acc.getPeer(w) != null
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29519
diff changeset
   792
                && ((LWWindowPeer)acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
27272
cffe6690ee9d 8038919: Requesting focus to a modeless dialog doesn't work on Safari
mcherkas
parents: 27052
diff changeset
   793
                && !lwcToolkit.isApplicationActive()) {
cffe6690ee9d 8038919: Requesting focus to a modeless dialog doesn't work on Safari
mcherkas
parents: 27052
diff changeset
   794
            lwcToolkit.activateApplicationIgnoringOtherApps();
cffe6690ee9d 8038919: Requesting focus to a modeless dialog doesn't work on Safari
mcherkas
parents: 27052
diff changeset
   795
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
        updateFocusabilityForAutoRequestFocus(false);
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   797
        execute(CPlatformWindow::nativePushNSWindowToFront);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   798
        updateFocusabilityForAutoRequestFocus(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   799
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   800
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   801
    private void setCanFullscreen(final boolean canFullScreen) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   802
        if (target instanceof RootPaneContainer
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   803
                && getPeer().getPeerType() == PeerType.FRAME) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   804
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   805
            if (isInFullScreen && !canFullScreen) {
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   806
                toggleFullScreen();
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   807
            }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   808
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   809
            final RootPaneContainer rpc = (RootPaneContainer) target;
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   810
            rpc.getRootPane().putClientProperty(
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   811
                    CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen);
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   812
        }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   813
    }
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   814
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   815
    @Override
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14647
diff changeset
   816
    public void setResizable(final boolean resizable) {
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   817
        setCanFullscreen(resizable);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
        setStyleBits(RESIZABLE, resizable);
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
   819
        setStyleBits(ZOOMABLE, resizable);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   821
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   822
    @Override
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13235
diff changeset
   823
    public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   824
        execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   825
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   826
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   827
    @Override
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 32480
diff changeset
   828
    public boolean rejectFocusRequest(FocusEvent.Cause cause) {
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   829
        // Cross-app activation requests are not allowed.
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 32480
diff changeset
   830
        if (cause != FocusEvent.Cause.MOUSE_EVENT &&
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   831
            !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   832
        {
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   833
            focusLogger.fine("the app is inactive, so the request is rejected");
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   834
            return true;
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   835
        }
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   836
        return false;
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   837
    }
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   838
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   839
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   840
    public boolean requestWindowFocus() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   841
        execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   842
            if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   843
                CWrapper.NSWindow.makeMainWindow(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   844
            }
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   845
            CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   846
        });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   847
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   848
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   849
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   850
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   851
    public boolean isActive() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   852
        AtomicBoolean ref = new AtomicBoolean();
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   853
        execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   854
            ref.set(CWrapper.NSWindow.isKeyWindow(ptr));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   855
        });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   856
        return ref.get();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   857
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   858
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   859
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   860
    public void updateFocusableWindowState() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   861
        final boolean isFocusable = isNativelyFocusableWindow();
49305
2f2b37908f91 7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents: 49225
diff changeset
   862
        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | RESIZABLE, isFocusable); // set bits at once
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   863
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   864
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   865
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   866
    public void setAlwaysOnTop(boolean isAlwaysOnTop) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   867
        setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   868
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   869
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   870
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   871
    public void setOpacity(float opacity) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   872
        execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   873
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   874
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   875
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   876
    public void setOpaque(boolean isOpaque) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   877
        execute(ptr -> CWrapper.NSWindow.setOpaque(ptr, isOpaque));
25196
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   878
        boolean isTextured = (peer == null) ? false : peer.isTextured();
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   879
        if (!isTextured) {
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   880
            if (!isOpaque) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   881
                execute(ptr -> CWrapper.NSWindow.setBackgroundColor(ptr, 0));
25196
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   882
            } else if (peer != null) {
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   883
                Color color = peer.getBackground();
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   884
                if (color != null) {
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   885
                    int rgb = color.getRGB();
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   886
                    execute(ptr->CWrapper.NSWindow.setBackgroundColor(ptr, rgb));
25196
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   887
                }
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   888
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   889
        }
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   890
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   891
        //This is a temporary workaround. Looks like after 7124236 will be fixed
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   892
        //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
25196
48d9cfe3f138 8033786: White flashing when opening Dialogs and Menus using Nimbus with dark background
serb
parents: 25120
diff changeset
   893
        SwingUtilities.invokeLater(this::invalidateShadow);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   894
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   895
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   896
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   897
    public void enterFullScreenMode() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   898
        isFullScreenMode = true;
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   899
        execute(CPlatformWindow::nativeEnterFullScreenMode);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   900
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   901
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   902
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   903
    public void exitFullScreenMode() {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   904
        execute(CPlatformWindow::nativeExitFullScreenMode);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   905
        isFullScreenMode = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   906
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   907
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   908
    @Override
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   909
    public boolean isFullScreenMode() {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   910
        return isFullScreenMode;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   911
    }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   912
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   913
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
    public void setWindowState(int windowState) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
   915
        if (peer == null || !peer.isVisible()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   916
            // setVisible() applies the state
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   917
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   918
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   919
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   920
        int prevWindowState = peer.getState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   921
        if (prevWindowState == windowState) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   922
23309
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   923
        if ((windowState & Frame.ICONIFIED) != 0) {
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   924
            // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   925
            windowState = Frame.ICONIFIED;
f5604dd7b274 8032078: [macosx] CPlatformWindow.setWindowState throws RuntimeException, if windowState=ICONIFIED|MAXIMIZED_BOTH
alitvinov
parents: 23253
diff changeset
   926
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
        switch (windowState) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   928
            case Frame.ICONIFIED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   929
                if (prevWindowState == Frame.MAXIMIZED_BOTH) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   930
                    // let's return into the normal states first
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   931
                    // the zoom call toggles between the normal and the max states
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   932
                    unmaximize();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   933
                }
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   934
                execute(CWrapper.NSWindow::miniaturize);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   935
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   936
            case Frame.MAXIMIZED_BOTH:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   937
                if (prevWindowState == Frame.ICONIFIED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   938
                    // let's return into the normal states first
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   939
                    execute(CWrapper.NSWindow::deminiaturize);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   940
                }
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   941
                maximize();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   942
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   943
            case Frame.NORMAL:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   944
                if (prevWindowState == Frame.ICONIFIED) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   945
                    execute(CWrapper.NSWindow::deminiaturize);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   946
                } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   947
                    // the zoom call toggles between the normal and the max states
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   948
                    unmaximize();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   949
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   950
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   951
            default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   952
                throw new RuntimeException("Unknown window state: " + windowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   953
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   954
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   955
        // NOTE: the SWP.windowState field gets updated to the newWindowState
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   956
        //       value when the native notification comes to us
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   957
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   958
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   959
    @Override
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   960
    public void setModalBlocked(boolean blocked) {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   961
        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   962
            return;
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   963
        }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   964
40993
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   965
        if (blocked) {
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   966
            // We are going to show a modal window. Previously displayed window will be
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   967
            // blocked/disabled. So we have to send mouse exited event to it now, since
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   968
            // all mouse events are discarded for blocked/disabled windows.
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   969
            execute(ptr -> nativeSynthesizeMouseEnteredExitedEvents(ptr, CocoaConstants.NSMouseExited));
40993
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   970
        }
a24dc7d0dd28 8050478: [macosx] Cursor not updating correctly after closing a modal dialog
dmarkov
parents: 39511
diff changeset
   971
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   972
        execute(ptr -> nativeSetEnabled(ptr, !blocked));
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19179
diff changeset
   973
        checkBlockingAndOrder();
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   974
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   975
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   976
    public final void invalidateShadow() {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
   977
        execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   978
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   979
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   980
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   981
    //                          UTILITY METHODS
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   982
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   983
19179
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   984
    /**
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   985
     * Find image to install into Title or into Application icon. First try
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   986
     * icons installed for toplevel. Null is returned, if there is no icon and
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   987
     * default Duke image should be used.
12047
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
    private CImage getImageForTarget() {
19179
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   990
        CImage icon = null;
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   991
        try {
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   992
            icon = CImage.getCreator().createFromImages(target.getIconImages());
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   993
        } catch (Exception ignored) {
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   994
            // Perhaps the icon passed into Java is broken. Skipping this icon.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   995
        }
19179
b59142223aac 7124339: [macosx] setIconImage is not endlessly tolerant to the broken image-arguments
serb
parents: 19021
diff changeset
   996
        return icon;
12047
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
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
     * Returns LWWindowPeer associated with this delegate.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1001
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1002
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1003
    public LWWindowPeer getPeer() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1004
        return peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1005
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1006
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
  1007
    @Override
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
  1008
    public boolean isUnderMouse() {
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
  1009
        return contentView.isUnderMouse();
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
  1010
    }
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14651
diff changeset
  1011
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1012
    public CPlatformView getContentView() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1013
        return contentView;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1014
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1015
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1016
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1017
    public long getLayerPtr() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1018
        return contentView.getWindowLayerPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1019
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1020
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1021
    private void validateSurface() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1022
        SurfaceData surfaceData = getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1023
        if (surfaceData instanceof CGLSurfaceData) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1024
            ((CGLSurfaceData)surfaceData).validate();
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1027
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16710
diff changeset
  1028
    void flushBuffers() {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 16710
diff changeset
  1029
        if (isVisible() && !nativeBounds.isEmpty() && !isFullScreenMode) {
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1030
            try {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1031
                LWCToolkit.invokeAndWait(new Runnable() {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1032
                    @Override
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1033
                    public void run() {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1034
                        //Posting an empty to flush the EventQueue without blocking the main thread
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1035
                    }
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1036
                }, target);
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 20457
diff changeset
  1037
            } catch (InvocationTargetException e) {
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1038
                e.printStackTrace();
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15983
diff changeset
  1039
            }
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
  1040
        }
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
  1041
    }
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
  1042
16710
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1043
    /**
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1044
     * Helper method to get a pointer to the native view from the PlatformWindow.
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1045
     */
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1046
    static long getNativeViewPtr(PlatformWindow platformWindow) {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1047
        long nativePeer = 0L;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1048
        if (platformWindow instanceof CPlatformWindow) {
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1049
            nativePeer = ((CPlatformWindow) platformWindow).getContentView().getAWTView();
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1050
        } else if (platformWindow instanceof CViewPlatformEmbeddedFrame){
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1051
            nativePeer = ((CViewPlatformEmbeddedFrame) platformWindow).getNSViewPtr();
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1052
        }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1053
        return nativePeer;
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1054
    }
f041f82cdeac 8006941: [macosx] Deadlock in drag and drop
pchelko
parents: 15985
diff changeset
  1055
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1056
    /*************************************************************
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1057
     * Callbacks from the AWTWindow and AWTView objc classes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1058
     *************************************************************/
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1059
    private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
  1060
        // Fix for 7150349: ingore "gained" notifications when the app is inactive.
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
  1061
        if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
  1062
            focusLogger.fine("the app is inactive, so the notification is ignored");
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
  1063
            return;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
  1064
        }
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1065
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1066
        LWWindowPeer oppositePeer = (opposite == null)? null : opposite.getPeer();
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
  1067
        responder.handleWindowFocusEvent(gained, oppositePeer);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1068
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1069
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1070
    protected void deliverMoveResizeEvent(int x, int y, int width, int height,
14651
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
  1071
                                        boolean byUser) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1072
        AtomicBoolean ref = new AtomicBoolean();
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1073
        execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1074
            ref.set(CWrapper.NSWindow.isZoomed(ptr));
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1075
        });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1076
        isZoomed = ref.get();
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1077
        checkZoom();
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1078
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
  1079
        final Rectangle oldB = nativeBounds;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1080
        nativeBounds = new Rectangle(x, y, width, height);
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1081
        if (peer != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1082
            peer.notifyReshape(x, y, width, height);
18762
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1083
            // System-dependent appearance optimization.
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1084
            if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1085
                    || isFullScreenAnimationOn) {
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1086
                flushBuffers();
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1087
            }
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
  1088
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1089
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1090
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1091
    private void deliverWindowClosingEvent() {
18762
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1092
        if (peer != null && peer.getBlocker() == null) {
eb4a26b2cd7f 8020298: [macosx] Incorrect merge in the lwawt code
serb
parents: 18759
diff changeset
  1093
            peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1094
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1095
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1096
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1097
    private void deliverIconify(final boolean iconify) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1098
        if (peer != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1099
            peer.notifyIconify(iconify);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1100
        }
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1101
        if (iconify) {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1102
            isIconifyAnimationActive = false;
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1103
        }
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1106
    private void deliverZoom(final boolean isZoomed) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1107
        if (peer != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1108
            peer.notifyZoom(isZoomed);
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1109
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1110
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1111
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1112
    private void checkZoom() {
31161
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1113
        if (peer != null) {
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1114
            int state = peer.getState();
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1115
            if (state != Frame.MAXIMIZED_BOTH && isMaximized()) {
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1116
                deliverZoom(true);
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1117
            } else if (state == Frame.MAXIMIZED_BOTH && !isMaximized()) {
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1118
                deliverZoom(false);
a93cd7e29b8c 8081019: Check peer to null in CPlatformWindow.checkZoom()
alexsch
parents: 30944
diff changeset
  1119
            }
21248
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1120
        }
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1121
    }
aa402f9056a5 8026143: [macosx] Maximized state could be inconsistent between peer and frame
pchelko
parents: 21246
diff changeset
  1122
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1123
    private void deliverNCMouseDown() {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1124
        if (peer != null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1125
            peer.notifyNCMouseDown();
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1126
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1127
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1128
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1129
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1130
     * Our focus model is synthetic and only non-simple window
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1131
     * may become natively focusable window.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1132
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1133
    private boolean isNativelyFocusableWindow() {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1134
        if (peer == null) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1135
            return false;
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1136
        }
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1137
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1138
        return !peer.isSimpleWindow() && target.getFocusableWindowState();
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
42744
a2fcebac9799 8165428: Security Warning dialog should be always on the top when multiple applets with APPLICATION_MODAL dialog launched in a browser
dmarkov
parents: 42731
diff changeset
  1141
    private boolean isBlocked() {
a2fcebac9799 8165428: Security Warning dialog should be always on the top when multiple applets with APPLICATION_MODAL dialog launched in a browser
dmarkov
parents: 42731
diff changeset
  1142
        LWWindowPeer blocker = (peer != null) ? peer.getBlocker() : null;
a2fcebac9799 8165428: Security Warning dialog should be always on the top when multiple applets with APPLICATION_MODAL dialog launched in a browser
dmarkov
parents: 42731
diff changeset
  1143
        return (blocker != null);
a2fcebac9799 8165428: Security Warning dialog should be always on the top when multiple applets with APPLICATION_MODAL dialog launched in a browser
dmarkov
parents: 42731
diff changeset
  1144
    }
a2fcebac9799 8165428: Security Warning dialog should be always on the top when multiple applets with APPLICATION_MODAL dialog launched in a browser
dmarkov
parents: 42731
diff changeset
  1145
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1146
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1147
     * An utility method for the support of the auto request focus.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1148
     * Updates the focusable state of the window under certain
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1149
     * circumstances.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1150
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1151
    private void updateFocusabilityForAutoRequestFocus(boolean isFocusable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1152
        if (target.isAutoRequestFocus() || !isNativelyFocusableWindow()) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1153
        setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1154
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1155
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19179
diff changeset
  1156
    private boolean checkBlockingAndOrder() {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 15331
diff changeset
  1157
        LWWindowPeer blocker = (peer == null)? null : peer.getBlocker();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1158
        if (blocker == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1159
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1160
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1161
15328
65d946035fa9 8005997: [macosx] Printer Dialog opens an additional title bar
serb
parents: 15322
diff changeset
  1162
        if (blocker instanceof CPrinterDialogPeer) {
65d946035fa9 8005997: [macosx] Printer Dialog opens an additional title bar
serb
parents: 15322
diff changeset
  1163
            return true;
65d946035fa9 8005997: [macosx] Printer Dialog opens an additional title bar
serb
parents: 15322
diff changeset
  1164
        }
65d946035fa9 8005997: [macosx] Printer Dialog opens an additional title bar
serb
parents: 15322
diff changeset
  1165
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1166
        CPlatformWindow pWindow = (CPlatformWindow)blocker.getPlatformWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1167
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1168
        pWindow.orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1169
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1170
        pWindow.execute(ptr -> {
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1171
            CWrapper.NSWindow.orderFrontRegardless(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1172
            CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1173
            CWrapper.NSWindow.makeMainWindow(ptr);
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1174
        });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1175
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1176
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1177
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1178
    private boolean isIconified() {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1179
        boolean isIconified = false;
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1180
        if (target instanceof Frame) {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1181
            int state = ((Frame)target).getExtendedState();
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1182
            if ((state & Frame.ICONIFIED) != 0) {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1183
                isIconified = true;
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1184
            }
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1185
        }
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1186
        return isIconifyAnimationActive || isIconified;
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1187
    }
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1188
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1189
    private boolean isOneOfOwnersOrSelf(CPlatformWindow window) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1190
        while (window != null) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1191
            if (this == window) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1192
                return true;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1193
            }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1194
            window = window.owner;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1195
        }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1196
        return false;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1197
    }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1198
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1199
    private CPlatformWindow getRootOwner() {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1200
        CPlatformWindow rootOwner = this;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1201
        while (rootOwner.owner != null) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1202
            rootOwner = rootOwner.owner;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1203
        }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1204
        return rootOwner;
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1205
    }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1206
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1207
    private void orderAboveSiblings() {
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1208
        // Recursively pop up the windows from the very bottom, (i.e. root owner) so that
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1209
        // the windows are ordered above their nearest owner; ancestors of the window,
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1210
        // which is going to become 'main window', are placed above their siblings.
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1211
        CPlatformWindow rootOwner = getRootOwner();
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1212
        if (rootOwner.isVisible() && !rootOwner.isIconified()) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1213
            rootOwner.execute(CWrapper.NSWindow::orderFront);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1214
        }
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1215
        // Do not order child windows of iconified owner.
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1216
        if (!rootOwner.isIconified()) {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1217
            final WindowAccessor windowAccessor = AWTAccessor.getWindowAccessor();
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1218
            orderAboveSiblingsImpl(windowAccessor.getOwnedWindows(rootOwner.target));
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1219
        }
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1220
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1221
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1222
    private void orderAboveSiblingsImpl(Window[] windows) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1223
        ArrayList<Window> childWindows = new ArrayList<Window>();
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1224
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1225
        final ComponentAccessor componentAccessor = AWTAccessor.getComponentAccessor();
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1226
        final WindowAccessor windowAccessor = AWTAccessor.getWindowAccessor();
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1227
        Arrays.sort(windows, siblingsComparator);
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1228
        // Go through the list of windows and perform ordering.
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1229
        CPlatformWindow pwUnder = null;
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1230
        for (Window w : windows) {
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1231
            boolean iconified = false;
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1232
            final Object p = componentAccessor.getPeer(w);
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1233
            if (p instanceof LWWindowPeer) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1234
                CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1235
                iconified = isIconified();
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1236
                if (pw != null && pw.isVisible() && !iconified) {
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1237
                    // If the window is one of ancestors of 'main window' or is going to become main by itself,
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1238
                    // the window should be ordered above its siblings; otherwise the window is just ordered
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1239
                    // above its nearest parent.
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1240
                    if (pw.isOneOfOwnersOrSelf(this)) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1241
                        pw.execute(CWrapper.NSWindow::orderFront);
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1242
                    } else {
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1243
                        if (pwUnder == null) {
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1244
                            pwUnder = pw.owner;
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1245
                        }
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1246
                        pwUnder.execute(underPtr -> {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1247
                            pw.execute(ptr -> {
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1248
                                CWrapper.NSWindow.orderWindow(ptr, CWrapper.NSWindow.NSWindowAbove, underPtr);
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1249
                            });
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1250
                        });
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1251
                        pwUnder = pw;
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1252
                    }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1253
                    pw.applyWindowLevel(w);
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1254
                }
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1255
            }
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1256
            // Retrieve the child windows for each window from the list except iconified ones
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1257
            // and store them for future use.
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1258
            // Note: we collect data about child windows even for invisible owners, since they may have
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1259
            // visible children.
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1260
            if (!iconified) {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1261
                childWindows.addAll(Arrays.asList(windowAccessor.getOwnedWindows(w)));
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1262
            }
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
  1263
        }
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1264
        // If some windows, which have just been ordered, have any child windows, let's start new iteration
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1265
        // and order these child windows.
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1266
        if (!childWindows.isEmpty()) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1267
            orderAboveSiblingsImpl(childWindows.toArray(new Window[0]));
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 42190
diff changeset
  1268
        }
23253
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
  1269
    }
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
  1270
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
  1271
    protected void applyWindowLevel(Window target) {
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
  1272
        if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1273
            execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSFloatingWindowLevel));
23253
55425a62017f 7154841: [macosx] Popups appear behind taskbar
pchelko
parents: 21282
diff changeset
  1274
        } else if (target.getType() == Window.Type.POPUP) {
44752
97a2817b5a9b 8165626: Improved window framing
serb
parents: 44653
diff changeset
  1275
            execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSPopUpMenuWindowLevel));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1276
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1277
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1278
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1279
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1280
    //                          NATIVE CALLBACKS
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
43083
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1283
    private void windowWillMiniaturize() {
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1284
        isIconifyAnimationActive = true;
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1285
    }
8ca2c0fc9537 8171949: [macosx] AWT_ZoomFrame Automated tests fail with error: The bitwise mask Frame.ICONIFIED is not setwhen the frame is in ICONIFIED state
dmarkov
parents: 42744
diff changeset
  1286
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1287
    private void windowDidBecomeMain() {
47516
3ce28db4393e 8190230: [macosx] Order of overlapping of modal dialogs is wrong
ssadetsky
parents: 47510
diff changeset
  1288
        lastBecomeMainTime = System.currentTimeMillis();
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19179
diff changeset
  1289
        if (checkBlockingAndOrder()) return;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1290
        // If it's not blocked, make sure it's above its siblings
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1291
        orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1292
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1293
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1294
    private void windowWillEnterFullScreen() {
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1295
        isFullScreenAnimationOn = true;
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1296
    }
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1297
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1298
    private void windowDidEnterFullScreen() {
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
  1299
        isInFullScreen = true;
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1300
        isFullScreenAnimationOn = false;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1301
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1302
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1303
    private void windowWillExitFullScreen() {
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1304
        isFullScreenAnimationOn = true;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1305
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1306
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1307
    private void windowDidExitFullScreen() {
42190
26d4a824fdea 8143914: Provide Mac-specific fullscreen support
azvegint
parents: 40993
diff changeset
  1308
        isInFullScreen = false;
15331
410070becfef 8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents: 15328
diff changeset
  1309
        isFullScreenAnimationOn = false;
12047
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
}