jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
author serb
Tue, 27 Nov 2012 17:03:19 +0400
changeset 14651 f032406c1e48
parent 14648 2ef7c7edb4b0
child 14753 a56a685d137f
permissions -rw-r--r--
8002308: [macosx] 7198229 should be applied to the user action only Reviewed-by: anthony, skovatch
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
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import java.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.awt.Dialog.ModalityType;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.awt.event.*;
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
    31
import java.awt.peer.WindowPeer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.beans.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.util.List;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import javax.swing.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import sun.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import sun.java2d.SurfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import sun.java2d.opengl.CGLSurfaceData;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
import sun.lwawt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import sun.lwawt.LWWindowPeer.PeerType;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
import sun.util.logging.PlatformLogger;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
import com.apple.laf.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
import com.apple.laf.ClientPropertyApplicator.Property;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
import com.sun.awt.AWTUtilities;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
    48
public final class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
    private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
    private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
    private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
    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
    55
    private static native void nativePushNSWindowToBack(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    private static native void nativePushNSWindowToFront(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
    private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
    62
    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
    63
    private static native void nativeSynthesizeMouseEnteredExitedEvents();
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
    64
    private static native void nativeDispose(long nsWindowPtr);
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
    65
    private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
14165
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13647
diff changeset
    67
    private static native int nativeGetNSWindowDisplayID(long nsWindowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    // 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
    70
    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
    71
    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
    72
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    // for client properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    public static final String WINDOW_ALPHA = "Window.alpha";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    public static final String WINDOW_SHADOW = "Window.shadow";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    public static final String WINDOW_STYLE = "Window.style";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    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
    82
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    public static final String WINDOW_CLOSEABLE = "Window.closeable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    public static final String WINDOW_ZOOMABLE = "Window.zoomable";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    public static final String WINDOW_HIDES_ON_DEACTIVATE="Window.hidesOnDeactivate";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    public static final String WINDOW_DOC_MODAL_SHEET = "apple.awt.documentModalSheet";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    public static final String WINDOW_FADE_DELEGATE = "apple.awt._windowFadeDelegate";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    public static final String WINDOW_FADE_IN = "apple.awt._windowFadeIn";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    public static final String WINDOW_FADE_OUT = "apple.awt._windowFadeOut";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    public static final String WINDOW_FULLSCREENABLE = "apple.awt.fullscreenable";
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    // 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
    99
    static final int MODELESS = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    static final int DOCUMENT_MODAL = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    static final int APPLICATION_MODAL = 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    static final int TOOLKIT_MODAL = 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    // window style bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    static final int _RESERVED_FOR_DATA = 1 << 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    // corresponds to native style mask bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    static final int DECORATED = 1 << 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    static final int TEXTURED = 1 << 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    static final int UNIFIED = 1 << 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    static final int UTILITY = 1 << 4;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    static final int HUD = 1 << 5;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    static final int SHEET = 1 << 6;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    static final int CLOSEABLE = 1 << 7;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    static final int MINIMIZABLE = 1 << 8;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    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
   119
    static final int NONACTIVATING = 1 << 24;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    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
   122
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
    // corresponds to method-based properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    static final int HAS_SHADOW = 1 << 10;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
    static final int ZOOMABLE = 1 << 11;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    static final int ALWAYS_ON_TOP = 1 << 15;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
    static final int HIDES_ON_DEACTIVATE = 1 << 17;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    static final int DRAGGABLE_BACKGROUND = 1 << 19;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    static final int DOCUMENT_MODIFIED = 1 << 21;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    static final int FULLSCREENABLE = 1 << 23;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    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
   134
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    // corresponds to callback-based properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    static final int SHOULD_BECOME_KEY = 1 << 12;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    static final int SHOULD_BECOME_MAIN = 1 << 13;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    static final int MODAL_EXCLUDED = 1 << 16;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    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
   141
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
    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
   143
        if (value) return (bits | mask);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
        return bits & ~mask;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    static boolean IS(final int bits, final int mask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
        return (bits & mask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    @SuppressWarnings("unchecked")
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    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
   153
        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
   154
            c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
        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
   157
            c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
        new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
            AWTUtilities.setWindowOpacity(c.target, value == null ? 1.0f : Float.parseFloat(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
        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
   163
            c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
        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
   166
            c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
        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
   169
            c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
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
        new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
            c.setStyleBits(ZOOMABLE, Boolean.parseBoolean(value.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
        new Property<CPlatformWindow>(WINDOW_FULLSCREENABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
            c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString()));
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
        new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
            nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        }},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        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
   181
            if (value == null || !(value instanceof java.io.File)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
                nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
            final String filename = ((java.io.File)value).getAbsolutePath();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
            nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
        }}
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
        public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
            Component root = SwingUtilities.getRoot(p);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
            if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
            return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
        }
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    // Bounds of the native widget but in the Java coordinate system.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    // 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
   199
    // 1) setting native bounds via nativeSetBounds() call
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    // 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
   201
    private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
    private volatile boolean isFullScreenMode = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
    private Window target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    private LWWindowPeer peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    private CPlatformView contentView;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
    private CPlatformWindow owner;
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   208
    private 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
   209
    private boolean undecorated; // initialized in getInitialStyleBits()
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   210
    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
   211
    private CPlatformResponder responder;
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   212
    private volatile boolean zoomed = false; // from native perspective
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
    public CPlatformWindow(final PeerType peerType) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
        super(0, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
        assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
     * Delegate initialization (create native window and all the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
     * related resources).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        this.peer = _peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
        this.target = _target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
        if (_owner instanceof CPlatformWindow) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
            this.owner = (CPlatformWindow)_owner;
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 int styleBits = getInitialStyleBits();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
        // TODO: handle these misc properties
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
        final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
        String warningString = target.getWarningString();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
12664
91828a78446f 7156191: [macosx] Can't type into applet demos in Pivot
dcherepanov
parents: 12647
diff changeset
   237
        responder = new CPlatformResponder(peer, false);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
        contentView = new CPlatformView();
12664
91828a78446f 7156191: [macosx] Can't type into applet demos in Pivot
dcherepanov
parents: 12647
diff changeset
   239
        contentView.initialize(peer, responder);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
        final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), styleBits, 0, 0, 0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
        setPtr(nativeWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
        // TODO: implement on top of JObjC bridged class
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    //    NSWindow window = JObjC.getInstance().AppKit().NSWindow().getInstance(nativeWindowPtr, JObjCRuntime.getInstance());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
        if (target instanceof javax.swing.RootPaneContainer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
            final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
            if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
                public void propertyChange(final PropertyChangeEvent evt) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
                    CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
                    rootpane.removePropertyChangeListener("ancestor", this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
            });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        validateSurface();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14647
diff changeset
   260
    private int getInitialStyleBits() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        // defaults style bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
        int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        if (isNativelyFocusableWindow()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
            styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
            styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
        final boolean isFrame = (target instanceof Frame);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
        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
   271
        final boolean isPopup = (target.getType() == Window.Type.POPUP);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
        if (isDialog) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
            styleBits = SET(styleBits, MINIMIZABLE, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        // 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
   277
        {
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   278
            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
   279
            if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
        // 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
   283
        {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
            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
   285
            styleBits = SET(styleBits, RESIZABLE, resizable);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
            if (!resizable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
                styleBits = SET(styleBits, ZOOMABLE, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
        if (target.isAlwaysOnTop()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
            styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
            styleBits = SET(styleBits, MODAL_EXCLUDED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
        // If 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
   300
        if (isPopup) {
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   301
            styleBits = SET(styleBits, TEXTURED, false);
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   302
            // 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
   303
            styleBits = SET(styleBits, NONACTIVATING, true);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
12647
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   306
        if (Window.Type.UTILITY.equals(target.getType())) {
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   307
            styleBits = SET(styleBits, UTILITY, true);
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   308
        }
f9991bc4fdde 7166437: [macosx] Support for Window.Type.UTILITY on the Mac
anthony
parents: 12640
diff changeset
   309
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
        if (target instanceof javax.swing.RootPaneContainer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
            javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
            Object prop = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
            prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
                styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
            if (isDialog && ((Dialog)target).getModalityType() == ModalityType.DOCUMENT_MODAL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
                prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
                if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
                    styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
            prop = rootpane.getClientProperty(WINDOW_STYLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
                if ("small".equals(prop))  {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
                    styleBits = SET(styleBits, UTILITY, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
                    if (target.isAlwaysOnTop() && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
                        styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
                    }
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
                if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
                if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
                if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
            }
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
            prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
                styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
            prop = rootpane.getClientProperty(WINDOW_CLOSEABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
                styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
            prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
                styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
            prop = rootpane.getClientProperty(WINDOW_ZOOMABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
                styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
            prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
            prop = rootpane.getClientProperty(WINDOW_SHADOW);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
                styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
            prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
            if (prop != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
                styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
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
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   375
        peer.setTextured(IS(TEXTURED, styleBits));
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   376
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
        return styleBits;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
    // this is the counter-point to -[CWindow _nativeSetStyleBit:]
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14647
diff changeset
   381
    private void setStyleBits(final int mask, final boolean value) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
        nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
    private native void _toggleFullScreenMode(final long model);
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
    public void toggleFullScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
        _toggleFullScreenMode(getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    }
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
    public void setMenuBar(MenuBar mb) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
        CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
        if (mbPeer != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
            nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
            nativeSetNSWindowMenuBar(nsWindowPtr, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
    public void dispose() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
        if (owner != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
            CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
        }
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 13009
diff changeset
   407
        contentView.dispose();
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 13009
diff changeset
   408
        nativeDispose(getNSWindowPtr());
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 13009
diff changeset
   409
        CPlatformWindow.super.dispose();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
    }
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
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
    public FontMetrics getFontMetrics(Font f) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
        (new RuntimeException("unimplemented")).printStackTrace();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    public Insets getInsets() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
        final Insets insets = nativeGetNSWindowInsets(getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
        return insets;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
    public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
        return new Point(nativeBounds.x, nativeBounds.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   430
    @Override
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   431
    public GraphicsDevice getGraphicsDevice() {
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   432
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   433
        CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
14165
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13647
diff changeset
   434
        int displayID = nativeGetNSWindowDisplayID(getNSWindowPtr());
12816
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   435
        GraphicsDevice gd = cge.getScreenDevice(displayID);
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   436
        if (gd == null) {
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   437
            // this could possibly happen during device removal
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   438
            // use the default screen device in this case
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   439
            gd = ge.getDefaultScreenDevice();
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   440
        }
b4cabffcb0de 7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents: 12664
diff changeset
   441
        return gd;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
    public SurfaceData getScreenSurface() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
        // TODO: not implemented
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
    public SurfaceData replaceSurfaceData() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
        return contentView.replaceSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
    public void setBounds(int x, int y, int w, int h) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
//        assert CThreading.assertEventQueue();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
        nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   461
    private boolean isMaximized() {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   462
        return undecorated ? this.normalBounds != null : zoomed;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   463
    }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   464
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   465
    private void maximize() {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   466
        if (isMaximized()) {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   467
            return;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   468
        }
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   469
        if (!undecorated) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   470
            zoomed = true;
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   471
            CWrapper.NSWindow.zoom(getNSWindowPtr());
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   472
        } else {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   473
            deliverZoom(true);
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   474
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   475
            this.normalBounds = peer.getBounds();
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   476
            long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   477
            Rectangle toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   478
            // Flip the y coordinate
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   479
            Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   480
            toBounds.y = frame.height - toBounds.y - toBounds.height;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   481
            setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   482
        }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   483
    }
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   484
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   485
    private void unmaximize() {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   486
        if (!isMaximized()) {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   487
            return;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   488
        }
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   489
        if (!undecorated) {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   490
            zoomed = false;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   491
            CWrapper.NSWindow.zoom(getNSWindowPtr());
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   492
        } else {
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   493
            deliverZoom(false);
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   494
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   495
            Rectangle toBounds = this.normalBounds;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   496
            this.normalBounds = null;
12284
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   497
            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
   498
        }
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   499
    }
3f2477ebb708 7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows
anthony
parents: 12177
diff changeset
   500
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   501
    private boolean isVisible() {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   502
        return this.visible;
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   503
    }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   504
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
    public void setVisible(boolean visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   509
        // Process parent-child relationship when hiding
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   510
        if (!visible) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   511
            // Unparent my children
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   512
            for (Window w : target.getOwnedWindows()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   513
                WindowPeer p = (WindowPeer)w.getPeer();
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   514
                if (p instanceof LWWindowPeer) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   515
                    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
   516
                    if (pw != null && pw.isVisible()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   517
                        CWrapper.NSWindow.removeChildWindow(nsWindowPtr, pw.getNSWindowPtr());
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   518
                    }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   519
                }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   520
            }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   521
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   522
            // Unparent myself
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   523
            if (owner != null && owner.isVisible()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
                CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   528
        // Configure stuff
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
        updateIconImages();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
        updateFocusabilityForAutoRequestFocus(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   532
        // Actually show or hide the window
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
        LWWindowPeer blocker = peer.getBlocker();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
        if (blocker == null || !visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
            // 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
   536
            if (visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
                CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   538
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   539
                boolean isPopup = (target.getType() == Window.Type.POPUP);
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   540
                if (isPopup) {
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   541
                    // 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
   542
                    CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   543
                } else {
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   544
                    CWrapper.NSWindow.orderFront(nsWindowPtr);
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   545
                }
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   546
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
                boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
                if (!isKeyWindow) {
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   549
                    CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
12047
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
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
                CWrapper.NSWindow.orderOut(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   554
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
            // otherwise, put it in a proper z-order
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
            CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
                    ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
        }
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   559
        this.visible = visible;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
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
        // Manage the extended state when showing
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   562
        if (visible) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   563
            // Apply the extended state as expected in shared code
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   564
            if (target instanceof Frame) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   565
                switch (((Frame)target).getExtendedState()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   566
                    case Frame.ICONIFIED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   567
                        CWrapper.NSWindow.miniaturize(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   568
                        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   569
                    case Frame.MAXIMIZED_BOTH:
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   570
                        maximize();
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   571
                        break;
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   572
                    default: // NORMAL
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   573
                        unmaximize(); // in case it was maximized, otherwise this is a no-op
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
                        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   579
        nativeSynthesizeMouseEnteredExitedEvents();
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12403
diff changeset
   580
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   581
        // Configure stuff #2
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
        updateFocusabilityForAutoRequestFocus(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   584
        // Manage parent-child relationship when showing
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   585
        if (visible) {
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   586
            // Add myself as a child
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   587
            if (owner != null && owner.isVisible()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
                CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
                if (target.isAlwaysOnTop()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
                    CWrapper.NSWindow.setLevel(nsWindowPtr, CWrapper.NSWindow.NSFloatingWindowLevel);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
            }
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   593
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   594
            // Add my own children to myself
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   595
            for (Window w : target.getOwnedWindows()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   596
                WindowPeer p = (WindowPeer)w.getPeer();
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   597
                if (p instanceof LWWindowPeer) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   598
                    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
   599
                    if (pw != null && pw.isVisible()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   600
                        CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   601
                        if (w.isAlwaysOnTop()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   602
                            CWrapper.NSWindow.setLevel(pw.getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   603
                        }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   604
                    }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   605
                }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   606
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   609
        // Deal with the blocker of the window being shown
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
        if (blocker != null && visible) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
            // Make sure the blocker is above its siblings
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
            ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
    public void setTitle(String title) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
        nativeSetNSWindowTitle(getNSWindowPtr(), title);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
    // Should be called on every window key property change.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
    @Override // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
    public void updateIconImages() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
        final CImage cImage = getImageForTarget();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
        nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
    public long getNSWindowPtr() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
        final long nsWindowPtr = ptr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
        if (nsWindowPtr == 0L) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
            if(logger.isLoggable(PlatformLogger.FINE)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
                logger.fine("NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
        return nsWindowPtr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
    public SurfaceData getSurfaceData() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
        return contentView.getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
    @Override  // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
    public void toBack() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
        nativePushNSWindowToBack(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
    @Override  // PlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
    public void toFront() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
        updateFocusabilityForAutoRequestFocus(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
        nativePushNSWindowToFront(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
        updateFocusabilityForAutoRequestFocus(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   656
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
    @Override
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14647
diff changeset
   658
    public void setResizable(final boolean resizable) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
        setStyleBits(RESIZABLE, resizable);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
    @Override
13550
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13235
diff changeset
   663
    public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
648dd6fa0dee 7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents: 13235
diff changeset
   664
        nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
    @Override
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   668
    public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   669
        // Cross-app activation requests are not allowed.
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   670
        if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   671
            !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   672
        {
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   673
            focusLogger.fine("the app is inactive, so the request is rejected");
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   674
            return true;
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   675
        }
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   676
        return false;
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   677
    }
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   678
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   679
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
    public boolean requestWindowFocus() {
12176
fc690f855620 7150345: [macosx] Can't type into applets
dcherepanov
parents: 12047
diff changeset
   681
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
        long ptr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
        if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
            CWrapper.NSWindow.makeMainWindow(ptr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
        CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
    public boolean isActive() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
        long ptr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
        return CWrapper.NSWindow.isKeyWindow(ptr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
    public void updateFocusableWindowState() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
        final boolean isFocusable = isNativelyFocusableWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
        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
   700
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   702
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
    public Graphics transformGraphics(Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
        // is this where we can inject a transform for HiDPI?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
        return g;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
    public void setAlwaysOnTop(boolean isAlwaysOnTop) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
        setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
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
    public PlatformWindow getTopmostPlatformWindowUnderMouse(){
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   714
        return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   715
    }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   716
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   717
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
    public void setOpacity(float opacity) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
        CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   720
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   721
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   722
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   723
    public void setOpaque(boolean isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   724
        CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
13234
9437e5985d73 7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents: 13233
diff changeset
   725
        if (!isOpaque && !peer.isTextured()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   726
            long clearColor = CWrapper.NSColor.clearColor();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   727
            CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   728
        }
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   729
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   730
        //This is a temporary workaround. Looks like after 7124236 will be fixed
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   731
        //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   732
        SwingUtilities.invokeLater(new Runnable() {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   733
            @Override
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   734
            public void run() {
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   735
                invalidateShadow();
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   736
            }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   737
        });
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   738
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   739
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   740
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   741
    public void enterFullScreenMode() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   742
        isFullScreenMode = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   743
        contentView.enterFullScreenMode(getNSWindowPtr());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   744
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   745
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   746
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   747
    public void exitFullScreenMode() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
        contentView.exitFullScreenMode();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
        isFullScreenMode = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   750
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
    public void setWindowState(int windowState) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   754
        if (!peer.isVisible()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   755
            // setVisible() applies the state
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   756
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   757
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   758
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   759
        int prevWindowState = peer.getState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   760
        if (prevWindowState == windowState) return;
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
        final long nsWindowPtr = getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   763
        switch (windowState) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
            case Frame.ICONIFIED:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
                if (prevWindowState == Frame.MAXIMIZED_BOTH) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   766
                    // let's return into the normal states first
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   767
                    // 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
   768
                    unmaximize();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   769
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   770
                CWrapper.NSWindow.miniaturize(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   771
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   772
            case Frame.MAXIMIZED_BOTH:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   773
                if (prevWindowState == Frame.ICONIFIED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   774
                    // let's return into the normal states first
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   775
                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   776
                }
13235
d51095485728 7177173: [macosx] JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH) not working as expected in JDK 7
anthony
parents: 13234
diff changeset
   777
                maximize();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   778
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   779
            case Frame.NORMAL:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   780
                if (prevWindowState == Frame.ICONIFIED) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   781
                    CWrapper.NSWindow.deminiaturize(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   782
                } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   783
                    // 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
   784
                    unmaximize();
12047
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
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   787
            default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   788
                throw new RuntimeException("Unknown window state: " + windowState);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   789
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   790
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13550
diff changeset
   791
        nativeSynthesizeMouseEnteredExitedEvents();
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12403
diff changeset
   792
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   793
        // NOTE: the SWP.windowState field gets updated to the newWindowState
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   794
        //       value when the native notification comes to us
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   795
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   797
    @Override
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   798
    public void setModalBlocked(boolean blocked) {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   799
        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   800
            return;
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   801
        }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   802
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   803
        nativeSetEnabled(getNSWindowPtr(), !blocked);
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   804
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   805
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   806
    public final void invalidateShadow(){
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   807
        nativeRevalidateNSWindowShadow(getNSWindowPtr());
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   808
    }
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
   809
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   810
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   811
    //                          UTILITY METHODS
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   812
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   813
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   814
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   815
     * Find image to install into Title or into Application icon.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   816
     * First try icons installed for toplevel. If there is no icon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   817
     * use default Duke image.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
     * This method shouldn't return null.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   819
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
    private CImage getImageForTarget() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   821
        List<Image> icons = target.getIconImages();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   822
        if (icons == null || icons.size() == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   823
            return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   824
        }
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12402
diff changeset
   825
        return CImage.getCreator().createFromImages(icons);
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   828
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   829
     * Returns LWWindowPeer associated with this delegate.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   830
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   831
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   832
    public LWWindowPeer getPeer() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   833
        return peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   834
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   835
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   836
    public CPlatformView getContentView() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   837
        return contentView;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   838
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   839
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   840
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   841
    public long getLayerPtr() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   842
        return contentView.getWindowLayerPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   843
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   844
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   845
    private void validateSurface() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   846
        SurfaceData surfaceData = getSurfaceData();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   847
        if (surfaceData instanceof CGLSurfaceData) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   848
            ((CGLSurfaceData)surfaceData).validate();
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   851
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   852
    private void flushBuffers() {
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   853
        if (isVisible() && !nativeBounds.isEmpty()) {
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   854
            LWCToolkit.getLWCToolkit().flushPendingEventsOnAppkit(target);
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   855
        }
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   856
    }
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   857
12047
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
     * Callbacks from the AWTWindow and AWTView objc classes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   860
     *************************************************************/
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   861
    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
   862
        // 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
   863
        if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   864
            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
   865
            return;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12176
diff changeset
   866
        }
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   867
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   868
        LWWindowPeer oppositePeer = (opposite == null)? null : opposite.getPeer();
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14306
diff changeset
   869
        responder.handleWindowFocusEvent(gained, oppositePeer);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   870
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   871
14651
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   872
    private void deliverMoveResizeEvent(int x, int y, int width, int height,
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   873
                                        boolean byUser) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   874
        // when the content view enters the full-screen mode, the native
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   875
        // move/resize notifications contain a bounds smaller than
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   876
        // the whole screen and therefore we ignore the native notifications
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   877
        // and the content view itself creates correct synthetic notifications
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   878
        if (isFullScreenMode) {
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   879
            return;
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   880
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   881
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   882
        final Rectangle oldB = nativeBounds;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   883
        nativeBounds = new Rectangle(x, y, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   884
        peer.notifyReshape(x, y, width, height);
14651
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   885
        if (byUser && !oldB.getSize().equals(nativeBounds.getSize())) {
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   886
            flushBuffers();
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 14165
diff changeset
   887
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   888
        //TODO validateSurface already called from notifyReshape
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   889
        validateSurface();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   890
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   891
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   892
    private void deliverWindowClosingEvent() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   893
        if (peer.getBlocker() == null)  {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   894
            peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   897
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   898
    private void deliverIconify(final boolean iconify) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   899
        peer.notifyIconify(iconify);
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
    private void deliverZoom(final boolean isZoomed) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   903
        peer.notifyZoom(isZoomed);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   904
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   905
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   906
    private void deliverNCMouseDown() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   907
        peer.notifyNCMouseDown();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   908
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   909
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   910
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   911
     * Our focus model is synthetic and only non-simple window
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   912
     * may become natively focusable window.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   913
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
    private boolean isNativelyFocusableWindow() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   915
        return !peer.isSimpleWindow() && target.getFocusableWindowState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   916
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   917
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
     * An utility method for the support of the auto request focus.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   920
     * Updates the focusable state of the window under certain
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   921
     * circumstances.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   922
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   923
    private void updateFocusabilityForAutoRequestFocus(boolean isFocusable) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   924
        if (target.isAutoRequestFocus() || !isNativelyFocusableWindow()) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   925
        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
   926
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   928
    private boolean checkBlocking() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   929
        LWWindowPeer blocker = peer.getBlocker();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   930
        if (blocker == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   931
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   932
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   933
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   934
        CPlatformWindow pWindow = (CPlatformWindow)blocker.getPlatformWindow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   935
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   936
        pWindow.orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   937
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   938
        final long nsWindowPtr = pWindow.getNSWindowPtr();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   939
        CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   940
        CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   941
        CWrapper.NSWindow.makeMainWindow(nsWindowPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   942
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   943
        return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   944
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   945
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   946
    private void orderAboveSiblings() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   947
        if (owner == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   948
            return;
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
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   951
        // NOTE: the logic will fail if we have a hierarchy like:
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   952
        //       visible root owner
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   953
        //          invisible owner
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   954
        //              visible dialog
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   955
        // However, this is an unlikely scenario for real life apps
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   956
        if (owner.isVisible()) {
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   957
            // Recursively pop up the windows from the very bottom so that only
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   958
            // the very top-most one becomes the main window
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   959
            owner.orderAboveSiblings();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   960
12286
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   961
            // Order the window to front of the stack of child windows
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   962
            final long nsWindowSelfPtr = getNSWindowPtr();
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   963
            final long nsWindowOwnerPtr = owner.getNSWindowPtr();
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   964
            CWrapper.NSWindow.removeChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr);
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   965
            CWrapper.NSWindow.addChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove);
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   966
        }
9e40486e227e 7154177: [macosx] An invisible owner frame becomes visible upon clicking a child window
anthony
parents: 12284
diff changeset
   967
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   968
        if (target.isAlwaysOnTop()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   969
            CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   970
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   971
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   972
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   973
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   974
    //                          NATIVE CALLBACKS
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   975
    // ----------------------------------------------------------------------
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   976
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   977
    private void windowDidBecomeMain() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   978
        assert CThreading.assertAppKit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   979
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   980
        if (checkBlocking()) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   981
        // 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
   982
        orderAboveSiblings();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   983
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   984
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   985
    private void updateDisplay() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   986
        EventQueue.invokeLater(new Runnable() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   987
            public void run() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   988
                validateSurface();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   989
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   990
        });
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   991
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   992
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   993
    private void updateWindowContent() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   994
        ComponentEvent resizeEvent = new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   995
        SunToolkit.postEvent(SunToolkit.targetToAppContext(target), resizeEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   996
    }
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
    private void windowWillEnterFullScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   999
        updateWindowContent();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1000
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1001
    private void windowDidEnterFullScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1002
        updateDisplay();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1003
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1004
    private void windowWillExitFullScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1005
        updateWindowContent();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1006
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1007
    private void windowDidExitFullScreen() {}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1008
}