jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
author alexsch
Fri, 22 May 2015 15:19:05 +0400
changeset 30944 b24bdcb53f5a
parent 30924 c8765f1fea21
child 32872 abca6234313d
permissions -rw-r--r--
8065739: [macosx] Frame warps to lower left of screen when 7124365: [macosx] setMaximizedBounds() should be implemented Reviewed-by: serb, azvegint
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
/*
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import "sun_lwawt_macosx_CPlatformWindow.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "com_apple_eawt_event_GestureHandler.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "com_apple_eawt_FullScreenHandler.h"
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
    33
#import "ApplicationDelegate.h"
12047
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 "AWTWindow.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#import "AWTView.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
#import "CMenu.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
#import "CMenuBar.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
#import "LWCToolkit.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
#import "GeomUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
#import "OSVersion.h"
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
#define MASK(KEY) \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
    (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
#define IS(BITS, KEY) \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
    ((BITS & MASK(KEY)) != 0)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
#define SET(BITS, KEY, VALUE) \
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    55
// Cocoa windowDidBecomeKey/windowDidResignKey notifications
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    56
// doesn't provide information about "opposite" window, so we
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    57
// have to do a bit of tracking. This variable points to a window
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    58
// which had been the key window just before a new key window
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
    59
// was set. It would be nil if the new key window isn't an AWT
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    60
// window or the app currently has no key window.
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    61
static AWTWindow* lastKeyWindow = nil;
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
    62
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    63
// --------------------------------------------------------------
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    64
// NSWindow/NSPanel descendants implementation
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    65
#define AWT_NS_WINDOW_IMPLEMENTATION                            \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    66
- (id) initWithDelegate:(AWTWindow *)delegate                   \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    67
              frameRect:(NSRect)contectRect                     \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    68
              styleMask:(NSUInteger)styleMask                   \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    69
            contentView:(NSView *)view                          \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    70
{                                                               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    71
    self = [super initWithContentRect:contectRect               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    72
                            styleMask:styleMask                 \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    73
                              backing:NSBackingStoreBuffered    \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    74
                                defer:NO];                      \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    75
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    76
    if (self == nil) return nil;                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    77
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    78
    [self setDelegate:delegate];                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    79
    [self setContentView:view];                                 \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    80
    [self setInitialFirstResponder:view];                       \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    81
    [self setReleasedWhenClosed:NO];                            \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    82
    [self setPreservesContentDuringLiveResize:YES];             \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    83
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    84
    return self;                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    85
}                                                               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    86
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    87
/* NSWindow overrides */                                        \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    88
- (BOOL) canBecomeKeyWindow {                                   \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    89
    return [(AWTWindow*)[self delegate] canBecomeKeyWindow];    \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    90
}                                                               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    91
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    92
- (BOOL) canBecomeMainWindow {                                  \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    93
    return [(AWTWindow*)[self delegate] canBecomeMainWindow];   \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    94
}                                                               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    95
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    96
- (BOOL) worksWhenModal {                                       \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    97
    return [(AWTWindow*)[self delegate] worksWhenModal];        \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    98
}                                                               \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
    99
                                                                \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   100
- (void)sendEvent:(NSEvent *)event {                            \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   101
    [(AWTWindow*)[self delegate] sendEvent:event];              \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   102
    [super sendEvent:event];                                    \
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   103
}
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   104
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   105
@implementation AWTWindow_Normal
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   106
AWT_NS_WINDOW_IMPLEMENTATION
28227
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   107
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   108
// Gesture support
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   109
- (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   110
    AWT_ASSERT_APPKIT_THREAD;
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   111
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   112
    JNIEnv *env = [ThreadUtilities getJNIEnv];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   113
    jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   114
    if (platformWindow != NULL) {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   115
        // extract the target AWT Window object out of the CPlatformWindow
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   116
        static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   117
        jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   118
        if (awtWindow != NULL) {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   119
            // translate the point into Java coordinates
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   120
            NSPoint loc = [event locationInWindow];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   121
            loc.y = [self frame].size.height - loc.y;
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   122
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   123
            // send up to the GestureHandler to recursively dispatch on the AWT event thread
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   124
            static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler");
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   125
            static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V");
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   126
            JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b);
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   127
            (*env)->DeleteLocalRef(env, awtWindow);
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   128
        }
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   129
        (*env)->DeleteLocalRef(env, platformWindow);
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   130
    }
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   131
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   132
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   133
- (void)beginGestureWithEvent:(NSEvent *)event {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   134
    [self postGesture:event
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   135
                   as:com_apple_eawt_event_GestureHandler_PHASE
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   136
                    a:-1.0
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   137
                    b:0.0];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   138
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   139
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   140
- (void)endGestureWithEvent:(NSEvent *)event {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   141
    [self postGesture:event
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   142
                   as:com_apple_eawt_event_GestureHandler_PHASE
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   143
                    a:1.0
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   144
                    b:0.0];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   145
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   146
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   147
- (void)magnifyWithEvent:(NSEvent *)event {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   148
    [self postGesture:event
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   149
                   as:com_apple_eawt_event_GestureHandler_MAGNIFY
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   150
                    a:[event magnification]
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   151
                    b:0.0];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   152
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   153
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   154
- (void)rotateWithEvent:(NSEvent *)event {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   155
    [self postGesture:event
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   156
                   as:com_apple_eawt_event_GestureHandler_ROTATE
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   157
                    a:[event rotation]
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   158
                    b:0.0];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   159
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   160
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   161
- (void)swipeWithEvent:(NSEvent *)event {
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   162
    [self postGesture:event
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   163
                   as:com_apple_eawt_event_GestureHandler_SWIPE
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   164
                    a:[event deltaX]
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   165
                    b:[event deltaY]];
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   166
}
157ebec4d375 8057788: [macosx] "Pinch to zoom" does not work since jdk7
denis
parents: 26751
diff changeset
   167
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   168
@end
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   169
@implementation AWTWindow_Panel
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   170
AWT_NS_WINDOW_IMPLEMENTATION
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   171
@end
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   172
// END of NSWindow/NSPanel descendants implementation
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   173
// --------------------------------------------------------------
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   174
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   175
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
@implementation AWTWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   178
@synthesize nsWindow;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
@synthesize javaPlatformWindow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
@synthesize javaMenuBar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
@synthesize javaMinSize;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
@synthesize javaMaxSize;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
@synthesize styleBits;
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   184
@synthesize isEnabled;
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   185
@synthesize ownerWindow;
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
   186
@synthesize preFullScreenLevel;
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   187
@synthesize standardFrame;
12047
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
- (void) updateMinMaxSize:(BOOL)resizable {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
    if (resizable) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   191
        [self.nsWindow setMinSize:self.javaMinSize];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   192
        [self.nsWindow setMaxSize:self.javaMaxSize];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    } else {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   194
        NSRect currentFrame = [self.nsWindow frame];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   195
        [self.nsWindow setMinSize:currentFrame.size];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   196
        [self.nsWindow setMaxSize:currentFrame.size];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
// creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
+ (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
    NSUInteger type = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    if (IS(styleBits, DECORATED)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
        type |= NSTitledWindowMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
        if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
        if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
        type |= NSBorderlessWindowMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   212
    if (IS(styleBits, TEXTURED))      type |= NSTexturedBackgroundWindowMask;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   213
    if (IS(styleBits, UNIFIED))       type |= NSUnifiedTitleAndToolbarWindowMask;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   214
    if (IS(styleBits, UTILITY))       type |= NSUtilityWindowMask;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   215
    if (IS(styleBits, HUD))           type |= NSHUDWindowMask;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   216
    if (IS(styleBits, SHEET))         type |= NSDocModalWindowMask;
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   217
    if (IS(styleBits, NONACTIVATING)) type |= NSNonactivatingPanelMask;
12047
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
    return type;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
// updates _METHOD_PROP_BITMASK based properties on the window
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
- (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    if (IS(mask, RESIZABLE)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        BOOL resizable = IS(bits, RESIZABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
        [self updateMinMaxSize:resizable];
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   227
        [self.nsWindow setShowsResizeIndicator:resizable];
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14311
diff changeset
   228
        // Zoom button should be disabled, if the window is not resizable,
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14311
diff changeset
   229
        // otherwise button should be restored to initial state.
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14311
diff changeset
   230
        BOOL zoom = resizable && IS(bits, ZOOMABLE);
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14311
diff changeset
   231
        [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:zoom];
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    if (IS(mask, HAS_SHADOW)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   235
        [self.nsWindow setHasShadow:IS(bits, HAS_SHADOW)];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
    if (IS(mask, ZOOMABLE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   239
        [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)];
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    if (IS(mask, ALWAYS_ON_TOP)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   243
        [self.nsWindow setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    if (IS(mask, HIDES_ON_DEACTIVATE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   247
        [self.nsWindow setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
    if (IS(mask, DRAGGABLE_BACKGROUND)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   251
        [self.nsWindow setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
    }
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
    if (IS(mask, DOCUMENT_MODIFIED)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   255
        [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
12047
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
13777
c94cf7e1bac2 7197320: [macosx] Full Screen option missing when Window.documentModified
alexsch
parents: 13647
diff changeset
   258
    if (IS(mask, FULLSCREENABLE) && [self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
c94cf7e1bac2 7197320: [macosx] Full Screen option missing when Window.documentModified
alexsch
parents: 13647
diff changeset
   259
        if (IS(bits, FULLSCREENABLE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   260
            [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        } else {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   262
            [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault];
12047
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
}
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
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   269
                  ownerWindow:owner
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
                    styleBits:(jint)bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
                    frameRect:(NSRect)rect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
                  contentView:(NSView *)view
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
AWT_ASSERT_APPKIT_THREAD;
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
    NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    if (contentRect.size.width <= 0.0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
        contentRect.size.width = 1.0;
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
    if (contentRect.size.height <= 0.0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
        contentRect.size.height = 1.0;
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
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   285
    self = [super init];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
    if (self == nil) return nil; // no hope
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   289
    if (IS(bits, UTILITY) ||
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   290
        IS(bits, NONACTIVATING) ||
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   291
        IS(bits, HUD) ||
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   292
        IS(bits, HIDES_ON_DEACTIVATE))
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   293
    {
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   294
        self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   295
                            frameRect:contentRect
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   296
                            styleMask:styleMask
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   297
                          contentView:view];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   298
    }
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   299
    else
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   300
    {
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   301
        // These windows will appear in the window list in the dock icon menu
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   302
        self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   303
                            frameRect:contentRect
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   304
                            styleMask:styleMask
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   305
                          contentView:view];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   306
    }
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   307
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   308
    if (self.nsWindow == nil) return nil; // no hope either
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
   309
    [self.nsWindow release]; // the property retains the object already
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   310
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   311
    self.isEnabled = YES;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
    self.javaPlatformWindow = platformWindow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    self.styleBits = bits;
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   314
    self.ownerWindow = owner;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
    [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
25120
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 24534
diff changeset
   317
    if (IS(self.styleBits, IS_POPUP)) {
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 24534
diff changeset
   318
        [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 24534
diff changeset
   319
    }
8b6a41c3752f 8042465: Applet menus not rendering when browser is full screen on Mac
dmarkov
parents: 24534
diff changeset
   320
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   324
+ (BOOL) isAWTWindow:(NSWindow *)window {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   325
    return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   326
}
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   327
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   328
// returns id for the topmost window under mouse
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   329
+ (NSInteger) getTopmostWindowUnderMouseID {
24534
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   330
    NSInteger result = -1;
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   331
    
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   332
    NSRect screenRect = [[NSScreen mainScreen] frame];
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   333
    NSPoint nsMouseLocation = [NSEvent mouseLocation];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   334
    CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   335
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   336
    NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   337
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   338
    for (NSDictionary *window in windows) {
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   339
        NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   340
        if (layer == 0) {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   341
            CGRect rect;
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   342
            CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   343
            if (CGRectContainsPoint(rect, cgMouseLocation)) {
24534
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   344
                result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   345
                break;
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   346
            }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   347
        }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   348
    }
24534
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   349
    [windows release];
07cf38b730b5 8041572: [macosx] huge native memory leak in AWTWindow.m
pchelko
parents: 24134
diff changeset
   350
    return result;
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   351
}
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   352
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   353
// checks that this window is under the mouse cursor and this point is not overlapped by others windows
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   354
- (BOOL) isTopmostWindowUnderMouse {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   355
    return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   356
}
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   357
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   358
+ (AWTWindow *) getTopmostWindowUnderMouse {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   359
    NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   360
    NSWindow *window;
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   361
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   362
    NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   363
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   364
    while ((window = [windowEnumerator nextObject]) != nil) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   365
        if ([window windowNumber] == topmostWindowUnderMouseID) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   366
            BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   367
            return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   368
        }
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   369
    }
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   370
    return nil;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   371
}
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   372
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   373
+ (void) synthesizeMouseEnteredExitedEvents:(NSWindow*)window withType:(NSEventType)eventType {
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   374
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   375
    NSPoint screenLocation = [NSEvent mouseLocation];
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   376
    NSPoint windowLocation = [window convertScreenToBase: screenLocation];
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   377
    int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   378
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   379
    NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   380
                                                 location: windowLocation
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   381
                                            modifierFlags: modifierFlags
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   382
                                                timestamp: 0
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   383
                                             windowNumber: [window windowNumber]
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   384
                                                  context: nil
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   385
                                              eventNumber: 0
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   386
                                           trackingNumber: 0
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   387
                                                 userData: nil
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   388
                           ];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   389
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   390
    [[window contentView] deliverJavaMouseEvent: mouseEvent];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   391
}
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   392
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   393
+ (void) synthesizeMouseEnteredExitedEventsForAllWindows {
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   394
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   395
    NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   396
    NSArray *windows = [NSApp windows];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   397
    NSWindow *window;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   398
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   399
    NSEnumerator *windowEnumerator = [windows objectEnumerator];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   400
    while ((window = [windowEnumerator nextObject]) != nil) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   401
        if ([AWTWindow isAWTWindow: window]) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   402
            BOOL isUnderMouse = ([window windowNumber] == topmostWindowUnderMouseID);
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   403
            BOOL mouseIsOver = [[window contentView] mouseIsOver];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   404
            if (isUnderMouse && !mouseIsOver) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   405
                [AWTWindow synthesizeMouseEnteredExitedEvents:window withType:NSMouseEntered];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   406
            } else if (!isUnderMouse && mouseIsOver) {
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   407
                [AWTWindow synthesizeMouseEnteredExitedEvents:window withType:NSMouseExited];
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   408
            }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   409
        }
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
   410
    }
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   411
}
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
   412
14165
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   413
+ (NSNumber *) getNSWindowDisplayID_AppKitThread:(NSWindow *)window {
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   414
    AWT_ASSERT_APPKIT_THREAD;
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   415
    NSScreen *screen = [window screen];
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   416
    NSDictionary *deviceDescription = [screen deviceDescription];
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   417
    return [deviceDescription objectForKey:@"NSScreenNumber"];
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   418
}
dcb1f9388f85 7175707: [macosx] PIT: 8 b43 Not running on AppKit thread issue again
alexsch
parents: 13777
diff changeset
   419
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
- (void) dealloc {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
20139
53e1e07a811e 8024779: [macosx] SwingNode crashes on exit
pchelko
parents: 20135
diff changeset
   423
    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
    [self.javaPlatformWindow setJObject:nil withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   426
    self.nsWindow = nil;
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   427
    self.ownerWindow = nil;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
// NSWindow overrides
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
- (BOOL) canBecomeKeyWindow {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
AWT_ASSERT_APPKIT_THREAD;
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   434
    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
- (BOOL) canBecomeMainWindow {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
AWT_ASSERT_APPKIT_THREAD;
20456
91f08f6b7871 8025438: [macosx] right JNFCall* method should be used in JDK-8008728 fix
alexsch
parents: 20139
diff changeset
   439
    if (!self.isEnabled) {
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   440
        // Native system can bring up the NSWindow to
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   441
        // the top even if the window is not main.
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   442
        // We should bring up the modal dialog manually
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   443
        [AWTToolkit eventCountPlusPlus];
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   444
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   445
        JNIEnv *env = [ThreadUtilities getJNIEnv];
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   446
        jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   447
        if (platformWindow != NULL) {
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   448
            static JNF_MEMBER_CACHE(jm_checkBlockingAndOrder, jc_CPlatformWindow,
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   449
                                    "checkBlockingAndOrder", "()Z");
20456
91f08f6b7871 8025438: [macosx] right JNFCall* method should be used in JDK-8008728 fix
alexsch
parents: 20139
diff changeset
   450
            JNFCallBooleanMethod(env, platformWindow, jm_checkBlockingAndOrder);
20135
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   451
            (*env)->DeleteLocalRef(env, platformWindow);
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   452
        }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   453
    }
f6edca5afe49 8008728: [macosx] Swing. JDialog. Modal dialog goes to background
alexsch
parents: 19022
diff changeset
   454
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   455
    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
- (BOOL) worksWhenModal {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
    return IS(self.styleBits, MODAL_EXCLUDED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
// NSWindowDelegate methods
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
- (void) _deliverMoveResizeEvent {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
    // deliver the event if this is a user-initiated live resize or as a side-effect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
    // of a Java initiated resize, because AppKit can override the bounds and force
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
    // the bounds of the window to avoid the Dock or remain on screen.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
    [AWTToolkit eventCountPlusPlus];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
    if (platformWindow == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
        // TODO: create generic AWT assert
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   479
    NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
14651
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   481
    static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
    JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
                      (jint)frame.origin.x,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
                      (jint)frame.origin.y,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
                      (jint)frame.size.width,
14651
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   486
                      (jint)frame.size.height,
f032406c1e48 8002308: [macosx] 7198229 should be applied to the user action only
serb
parents: 14648
diff changeset
   487
                      (jboolean)[self.nsWindow inLiveResize]);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
    (*env)->DeleteLocalRef(env, platformWindow);
21788
38ffbbef9235 8028485: [macosx] java/awt/Mouse/EnterExitEvents/FullscreenEnterEventTest.java fails
pchelko
parents: 21282
diff changeset
   489
38ffbbef9235 8028485: [macosx] java/awt/Mouse/EnterExitEvents/FullscreenEnterEventTest.java fails
pchelko
parents: 21282
diff changeset
   490
    [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   491
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   492
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   493
- (void)windowDidMove:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   494
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   495
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
    [self _deliverMoveResizeEvent];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
- (void)windowDidResize:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
    [self _deliverMoveResizeEvent];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
- (void)windowDidExpose:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
    [AWTToolkit eventCountPlusPlus];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    // TODO: don't see this callback invoked anytime so we track
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
    // window exposing in _setVisible:(BOOL)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   513
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   514
                        defaultFrame:(NSRect)newFrame {
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   515
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   516
    return [self standardFrame];
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   517
}
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   518
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
- (void) _deliverIconify:(BOOL)iconify {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
    [AWTToolkit eventCountPlusPlus];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
        static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
        JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
- (void)windowDidMiniaturize:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
    [self _deliverIconify:JNI_TRUE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
- (void)windowDidDeminiaturize:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   540
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
    [self _deliverIconify:JNI_FALSE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   544
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
//AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
    if (platformWindow != NULL) {
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   549
        jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   550
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   551
        static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   552
        JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
        (*env)->DeleteLocalRef(env, platformWindow);
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   554
        (*env)->DeleteLocalRef(env, oppositeWindow);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   559
- (void) windowDidBecomeKey: (NSNotification *) notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   560
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   561
    [AWTToolkit eventCountPlusPlus];
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   562
    AWTWindow *opposite = [AWTWindow lastKeyWindow];
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   563
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   564
    // Finds appropriate menubar in our hierarchy,
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   565
    AWTWindow *awtWindow = self;
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   566
    while (awtWindow.ownerWindow != nil) {
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   567
        awtWindow = awtWindow.ownerWindow;
17684
fc7f8dbe87b4 8010721: [macosx] In JDK7 the menu bar disappears when a Dialog is shown
vkarnauk
parents: 15505
diff changeset
   568
    }
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   569
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   570
    CMenuBar *menuBar = nil;
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   571
    BOOL isDisabled = NO;
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   572
    if ([awtWindow.nsWindow isVisible]){
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   573
        menuBar = awtWindow.javaMenuBar;
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   574
        isDisabled = !awtWindow.isEnabled;
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   575
    }
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   576
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   577
    if (menuBar == nil) {
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   578
        menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   579
        isDisabled = NO;
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   580
    }
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   581
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   582
    [CMenuBar activate:menuBar modallyDisabled:isDisabled];
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   583
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   584
    [AWTWindow setLastKeyWindow:nil];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   585
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   586
    [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
- (void) windowDidResignKey: (NSNotification *) notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
    // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
    [AWTToolkit eventCountPlusPlus];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
    [self.javaMenuBar deactivate];
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   594
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   595
    // In theory, this might cause flickering if the window gaining focus
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   596
    // has its own menu. However, I couldn't reproduce it on practice, so
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   597
    // perhaps this is a non issue.
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   598
    CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   599
    if (defaultMenu != nil) {
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   600
        [CMenuBar activate:defaultMenu modallyDisabled:NO];
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   601
    }
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   602
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   603
    // the new key window
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   604
    NSWindow *keyWindow = [NSApp keyWindow];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   605
    AWTWindow *opposite = nil;
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   606
    if ([AWTWindow isAWTWindow: keyWindow]) {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   607
        opposite = (AWTWindow *)[keyWindow delegate];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   608
        [AWTWindow setLastKeyWindow: self];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   609
    } else {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   610
        [AWTWindow setLastKeyWindow: nil];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   611
    }
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   612
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   613
    [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
12047
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
- (void) windowDidBecomeMain: (NSNotification *) notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
    [AWTToolkit eventCountPlusPlus];
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
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
        static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
        JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
    }
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
- (BOOL)windowShouldClose:(id)sender {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
    [AWTToolkit eventCountPlusPlus];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
        static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
        JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
        (*env)->DeleteLocalRef(env, platformWindow);
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
    // The window will be closed (if allowed) as result of sending Java event
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
    return NO;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
- (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
    static JNF_CLASS_CACHE(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
    static JNF_STATIC_MEMBER_CACHE(jm_notifyFullScreenOperation, jc_FullScreenHandler, "handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
    static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
        jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
        if (awtWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
            JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
            (*env)->DeleteLocalRef(env, awtWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
        (*env)->DeleteLocalRef(env, platformWindow);
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
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
    static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   664
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
        JNFCallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   669
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   670
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   671
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   672
    static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
        JNFCallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
    }
18129
614a4d36d8c7 8013468: [macosx] Cursor does not update properly when in fullscreen mode on Mac
pchelko
parents: 17904
diff changeset
   680
    [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
- (void)windowWillExitFullScreen:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
    static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
        JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
- (void)windowDidExitFullScreen:(NSNotification *)notification {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
    static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
    jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
    if (platformWindow != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
        JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   700
        [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
        (*env)->DeleteLocalRef(env, platformWindow);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   702
    }
18129
614a4d36d8c7 8013468: [macosx] Cursor does not update properly when in fullscreen mode on Mac
pchelko
parents: 17904
diff changeset
   703
    [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
- (void)sendEvent:(NSEvent *)event {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
        if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
            NSPoint p = [NSEvent mouseLocation];
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   710
            NSRect frame = [self.nsWindow frame];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   711
            NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   713
            // Check if the click happened in the non-client area (title bar)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   714
            if (p.y >= (frame.origin.y + contentRect.size.height)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   715
                JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   716
                jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   717
                // Currently, no need to deliver the whole NSEvent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
                static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
                JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown);
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
}
12402
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   723
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   724
- (void)constrainSize:(NSSize*)size {
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   725
    float minWidth = 0.f, minHeight = 0.f;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   726
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   727
    if (IS(self.styleBits, DECORATED)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   728
        NSRect frame = [self.nsWindow frame];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   729
        NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self.nsWindow styleMask]];
12402
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   730
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   731
        float top = frame.size.height - contentRect.size.height;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   732
        float left = contentRect.origin.x - frame.origin.x;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   733
        float bottom = contentRect.origin.y - frame.origin.y;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   734
        float right = frame.size.width - (contentRect.size.width + left);
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   735
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   736
        // Speculative estimation: 80 - enough for window decorations controls
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   737
        minWidth += left + right + 80;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   738
        minHeight += top + bottom;
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   739
    }
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   740
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   741
    minWidth = MAX(1.f, minWidth);
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   742
    minHeight = MAX(1.f, minHeight);
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   743
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   744
    size->width = MAX(size->width, minWidth);
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   745
    size->height = MAX(size->height, minHeight);
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   746
}
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   747
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   748
- (void) setEnabled: (BOOL)flag {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   749
    self.isEnabled = flag;
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   750
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   751
    if (IS(self.styleBits, CLOSEABLE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   752
        [[self.nsWindow standardWindowButton:NSWindowCloseButton] setEnabled: flag];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   753
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   754
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   755
    if (IS(self.styleBits, MINIMIZABLE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   756
        [[self.nsWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   757
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   758
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   759
    if (IS(self.styleBits, ZOOMABLE)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   760
        [[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled: flag];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   761
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   762
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   763
    if (IS(self.styleBits, RESIZABLE)) {
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   764
        [self updateMinMaxSize:flag];
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   765
        [self.nsWindow setShowsResizeIndicator:flag];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   766
    }
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   767
}
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
   768
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   769
+ (void) setLastKeyWindow:(AWTWindow *)window {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   770
    [window retain];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   771
    [lastKeyWindow release];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   772
    lastKeyWindow = window;
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   773
}
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   774
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   775
+ (AWTWindow *) lastKeyWindow {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   776
    return lastKeyWindow;
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   777
}
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   778
24134
46d80fad2e48 8032595: [macosx] setResizable(false) makes a frame slide down
pchelko
parents: 23651
diff changeset
   779
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
46d80fad2e48 8032595: [macosx] setResizable(false) makes a frame slide down
pchelko
parents: 23651
diff changeset
   780
    return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
46d80fad2e48 8032595: [macosx] setResizable(false) makes a frame slide down
pchelko
parents: 23651
diff changeset
   781
}
46d80fad2e48 8032595: [macosx] setResizable(false) makes a frame slide down
pchelko
parents: 23651
diff changeset
   782
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
   783
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   784
@end // AWTWindow
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   787
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   788
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   789
 * Method:    nativeCreateNSWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   790
 * Signature: (JJIIII)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   791
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   792
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   793
(JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   794
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   795
    __block AWTWindow *window = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   797
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   798
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   799
    JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   800
    NSView *contentView = OBJC(contentViewPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   801
    NSRect frameRect = NSMakeRect(x, y, w, h);
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   802
    AWTWindow *owner = [OBJC(ownerPtr) delegate];
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
   803
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   804
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   805
        window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
19021
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   806
                                               ownerWindow:owner
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   807
                                                 styleBits:styleBits
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   808
                                                 frameRect:frameRect
8a5340b88ee5 8017189: [macosx] AWT program menu disabled on Mac
serb
parents: 18129
diff changeset
   809
                                               contentView:contentView];
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
   810
        // the window is released is CPlatformWindow.nativeDispose()
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   811
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 21790
diff changeset
   812
        if (window) [window.nsWindow retain];
12047
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
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   816
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   817
    return ptr_to_jlong(window ? window.nsWindow : nil);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   819
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   821
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   822
 * Method:    nativeSetNSWindowStyleBits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   823
 * Signature: (JII)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   824
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   825
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   826
(JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   829
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   830
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
   831
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   832
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   833
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   834
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   835
        // scans the bit field, and only updates the values requested by the mask
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   836
        // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   837
        jint newBits = window.styleBits & ~mask | bits & mask;
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
        // resets the NSWindow's style mask if the mask intersects any of those bits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   840
        if (mask & MASK(_STYLE_PROP_BITMASK)) {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   841
            [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   842
        }
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
        // calls methods on NSWindow to change other properties, based on the mask
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   845
        if (mask & MASK(_METHOD_PROP_BITMASK)) {
14648
2ef7c7edb4b0 7193214: Consider simplifying CPlatformWindow.setResizable()
serb
parents: 14311
diff changeset
   846
            [window setPropertiesForStyleBits:newBits mask:mask];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   847
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   848
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   849
        window.styleBits = newBits;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   852
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   853
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   854
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   855
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   856
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   857
 * Method:    nativeSetNSWindowMenuBar
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   858
 * Signature: (JJ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   859
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   860
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   861
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   862
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   863
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   864
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   865
    NSWindow *nsWindow = OBJC(windowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   866
    CMenuBar *menuBar = OBJC(menuBarPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
   867
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   868
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   869
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   870
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   871
        if ([nsWindow isKeyWindow]) {
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   872
            [window.javaMenuBar deactivate];
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   873
        }
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   874
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   875
        window.javaMenuBar = menuBar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   876
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   877
        CMenuBar* actualMenuBar = menuBar;
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   878
        if (actualMenuBar == nil) {
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   879
            actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   880
        }
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   881
15505
f31ab5cb8bb9 8007006: [macosx] Closing subwindow loses main window menus
leonidr
parents: 15322
diff changeset
   882
        if ([nsWindow isKeyWindow]) {
19022
4d36c6935abb 8007267: [macosx] com.apple.eawt.Application.setDefaultMenuBar is not working
leonidr
parents: 19021
diff changeset
   883
            [CMenuBar activate:actualMenuBar modallyDisabled:NO];
15505
f31ab5cb8bb9 8007006: [macosx] Closing subwindow loses main window menus
leonidr
parents: 15322
diff changeset
   884
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   885
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   886
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   887
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   888
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   889
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
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   892
 * Method:    nativeGetNSWindowInsets
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   893
 * Signature: (J)Ljava/awt/Insets;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   894
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   895
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   896
(JNIEnv *env, jclass clazz, jlong windowPtr)
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
    jobject ret = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   899
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   900
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   901
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   902
    NSWindow *nsWindow = OBJC(windowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   903
    __block NSRect contentRect = NSZeroRect;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   904
    __block NSRect frame = NSZeroRect;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   905
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
   906
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   907
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   908
        frame = [nsWindow frame];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   909
        contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   910
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   911
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   912
    jint top = (jint)(frame.size.height - contentRect.size.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   913
    jint left = (jint)(contentRect.origin.x - frame.origin.x);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
    jint bottom = (jint)(contentRect.origin.y - frame.origin.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   915
    jint right = (jint)(frame.size.width - (contentRect.size.width + left));
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
    static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   918
    static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   919
    ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   920
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   921
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   922
    return ret;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   923
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   924
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   925
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   926
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
 * Method:    nativeSetNSWindowBounds
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   928
 * Signature: (JDDDD)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   929
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   930
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   931
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height)
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   934
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   935
    NSRect jrect = NSMakeRect(originX, originY, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   936
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   937
    // TODO: not sure we need displayIfNeeded message in our view
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   938
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
   939
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   940
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   941
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   942
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   943
        NSRect rect = ConvertNSScreenRect(NULL, jrect);
12402
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   944
        [window constrainSize:&rect.size];
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
   945
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   946
        [nsWindow setFrame:rect display:YES];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   947
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   948
        // only start tracking events if pointer is above the toplevel
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   949
        // TODO: should post an Entered event if YES.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   950
        NSPoint mLocation = [NSEvent mouseLocation];
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
   951
        [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   952
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   953
        // ensure we repaint the whole window after the resize operation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   954
        // (this will also re-enable screen updates, which were disabled above)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   955
        // TODO: send PaintEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   956
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   957
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   958
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   959
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   960
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   961
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   962
 * Class:     sun_lwawt_macosx_CPlatformWindow
30944
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   963
 * Method:    nativeSetNSWindowStandardFrame
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   964
 * Signature: (JDDDD)V
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   965
 */
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   966
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStandardFrame
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   967
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY,
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   968
     jdouble width, jdouble height)
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   969
{
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   970
    JNF_COCOA_ENTER(env);
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   971
    
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   972
    NSRect jrect = NSMakeRect(originX, originY, width, height);
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   973
    
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   974
    NSWindow *nsWindow = OBJC(windowPtr);
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   975
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   976
        
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   977
        NSRect rect = ConvertNSScreenRect(NULL, jrect);
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   978
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   979
        window.standardFrame = rect;
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   980
    }];
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   981
    
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   982
    JNF_COCOA_EXIT(env);
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   983
}
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   984
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   985
/*
b24bdcb53f5a 8065739: [macosx] Frame warps to lower left of screen when
alexsch
parents: 30924
diff changeset
   986
 * Class:     sun_lwawt_macosx_CPlatformWindow
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   987
 * Method:    nativeSetNSWindowMinMax
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   988
 * Signature: (JDDDD)V
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
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   991
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   994
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   995
    if (minW < 1) minW = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   996
    if (minH < 1) minH = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   997
    if (maxW < 1) maxW = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   998
    if (maxH < 1) maxH = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   999
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1000
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1001
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1002
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1003
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1004
12402
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1005
        NSSize min = { minW, minH };
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1006
        NSSize max = { maxW, maxH };
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1007
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1008
        [window constrainSize:&min];
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1009
        [window constrainSize:&max];
f3903de3fd9e 7124553: [macosx] Need minimum size for titled Frames and JFrames
anthony
parents: 12177
diff changeset
  1010
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1011
        window.javaMinSize = min;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1012
        window.javaMaxSize = max;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1013
        [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1014
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1015
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1016
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1017
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1018
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1019
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1020
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1021
 * Method:    nativePushNSWindowToBack
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1022
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1023
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1024
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1025
(JNIEnv *env, jclass clazz, jlong windowPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1026
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1027
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1028
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1029
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1030
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1031
        [nsWindow orderBack:nil];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1032
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1033
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1034
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1035
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1036
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1037
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1038
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1039
 * Method:    nativePushNSWindowToFront
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1040
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1041
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1042
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1043
(JNIEnv *env, jclass clazz, jlong windowPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1044
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1045
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1046
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1047
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1048
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1049
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1050
        if (![nsWindow isKeyWindow]) {
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1051
            [nsWindow makeKeyAndOrderFront:nsWindow];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1052
        } else {
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1053
            [nsWindow orderFront:nsWindow];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1054
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1055
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1056
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1057
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1058
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1059
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1060
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1061
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1062
 * Method:    nativeSetNSWindowTitle
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1063
 * Signature: (JLjava/lang/String;)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1064
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1065
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1066
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1067
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1068
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1069
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1070
    NSWindow *nsWindow = OBJC(windowPtr);
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1071
    [nsWindow performSelectorOnMainThread:@selector(setTitle:)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1072
                              withObject:JNFJavaToNSString(env, jtitle)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1073
                           waitUntilDone:NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1074
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1075
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1076
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1077
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1078
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1079
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1080
 * Method:    nativeRevalidateNSWindowShadow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1081
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1082
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1083
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1084
(JNIEnv *env, jclass clazz, jlong windowPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1085
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1086
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1087
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1088
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1089
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
13233
4d45f7ebc0d7 7124244: [macosx] Shaped windows support
serb
parents: 13143
diff changeset
  1090
        [nsWindow invalidateShadow];
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1091
    }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1092
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1093
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1094
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1095
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1096
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1097
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1098
 * Method:    nativeScreenOn_AppKitThread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1099
 * Signature: (J)I
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1100
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1101
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1102
(JNIEnv *env, jclass clazz, jlong windowPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1103
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1104
    jint ret = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1105
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1106
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1107
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1108
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1109
    NSWindow *nsWindow = OBJC(windowPtr);
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1110
    NSDictionary *props = [[nsWindow screen] deviceDescription];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1111
    ret = [[props objectForKey:@"NSScreenNumber"] intValue];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1112
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1113
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1114
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1115
    return ret;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1116
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1117
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1118
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1119
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1120
 * Method:    nativeSetNSWindowMinimizedIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1121
 * Signature: (JJ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1122
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1123
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1124
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1125
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1126
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1127
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1128
    NSWindow *nsWindow = OBJC(windowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1129
    NSImage *image = OBJC(nsImagePtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1130
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1131
        [nsWindow setMiniwindowImage:image];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1132
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1133
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1134
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1135
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1136
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1137
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1138
 * Class:     sun_lwawt_macosx_CPlatformWindow
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1139
 * Method:    nativeSetNSWindowRepresentedFilename
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1140
 * Signature: (JLjava/lang/String;)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1141
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1142
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1143
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1144
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1145
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1146
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1147
    NSWindow *nsWindow = OBJC(windowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1148
    NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)];
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1149
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1150
        [nsWindow setRepresentedURL:url];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1151
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1152
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1153
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1154
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1155
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1156
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1157
 * Class:     sun_lwawt_macosx_CPlatformWindow
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1158
 * Method:    nativeGetTopmostPlatformWindowUnderMouse
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1159
 * Signature: (J)V
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1160
 */
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1161
JNIEXPORT jobject
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1162
JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1163
(JNIEnv *env, jclass clazz)
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1164
{
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1165
    __block jobject topmostWindowUnderMouse = nil;
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1166
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1167
    JNF_COCOA_ENTER(env);
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1168
30924
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1169
    [ThreadUtilities performOnMainThreadWaiting:YES block:^{
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1170
        AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1171
        if (awtWindow != nil) {
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1172
            topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1173
        }
c8765f1fea21 8035568: [macosx] Cursor management unification
pchelko
parents: 28227
diff changeset
  1174
    }];
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1175
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1176
    JNF_COCOA_EXIT(env);
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1177
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1178
    return topmostWindowUnderMouse;
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1179
}
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1180
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1181
/*
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1182
 * Class:     sun_lwawt_macosx_CPlatformWindow
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1183
 * Method:    nativeSynthesizeMouseEnteredExitedEvents
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1184
 * Signature: (J)V
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1185
 */
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1186
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1187
(JNIEnv *env, jclass clazz)
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1188
{
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1189
    JNF_COCOA_ENTER(env);
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1190
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1191
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
13647
de61414bbcf2 7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents: 13233
diff changeset
  1192
        [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1193
    }];
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1194
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1195
    JNF_COCOA_EXIT(env);
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1196
}
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1197
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1198
/*
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 12402
diff changeset
  1199
 * Class:     sun_lwawt_macosx_CPlatformWindow
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1200
 * Method:    _toggleFullScreenMode
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1201
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1202
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1203
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1204
(JNIEnv *env, jobject peer, jlong windowPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1205
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1206
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1207
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1208
    NSWindow *nsWindow = OBJC(windowPtr);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1209
    SEL toggleFullScreenSelector = @selector(toggleFullScreen:);
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1210
    if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1211
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1212
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1213
        [nsWindow performSelector:toggleFullScreenSelector withObject:nil];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1214
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1215
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1216
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1217
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
  1218
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1219
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1220
(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1221
{
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1222
JNF_COCOA_ENTER(env);
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1223
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1224
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1225
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12648
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1226
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
00c38c393e11 7149062: [macosx] dock menu don't show available frames
anthony
parents: 12640
diff changeset
  1227
12640
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1228
        [window setEnabled: isEnabled];
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1229
    }];
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1230
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1231
JNF_COCOA_EXIT(env);
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1232
}
5ea775607d72 7124376: [macosx] Modal dialog lost focus
leonidr
parents: 12535
diff changeset
  1233
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1234
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1235
(JNIEnv *env, jclass clazz, jlong windowPtr)
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1236
{
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1237
JNF_COCOA_ENTER(env);
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1238
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1239
    NSWindow *nsWindow = OBJC(windowPtr);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14753
diff changeset
  1240
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1241
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1242
14311
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
  1243
        if ([AWTWindow lastKeyWindow] == window) {
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
  1244
            [AWTWindow setLastKeyWindow: nil];
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
  1245
        }
b2492ea8d08e 7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents: 14165
diff changeset
  1246
13009
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1247
        // AWTWindow holds a reference to the NSWindow in its nsWindow
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1248
        // property. Unsetting the delegate allows it to be deallocated
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1249
        // which releases the reference. This, in turn, allows the window
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1250
        // itself be deallocated.
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1251
        [nsWindow setDelegate: nil];
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1252
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1253
        [window release];
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1254
    }];
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1255
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1256
JNF_COCOA_EXIT(env);
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1257
}
f409e6ef0185 7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
anthony
parents: 12816
diff changeset
  1258
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1259
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeEnterFullScreenMode
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1260
(JNIEnv *env, jclass clazz, jlong windowPtr)
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1261
{
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1262
JNF_COCOA_ENTER(env);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1263
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1264
    NSWindow *nsWindow = OBJC(windowPtr);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1265
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1266
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1267
        NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1268
        CGDirectDisplayID aID = [screenID intValue];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1269
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1270
        if (CGDisplayCapture(aID) == kCGErrorSuccess) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1271
            // remove window decoration
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1272
            NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1273
            [nsWindow setStyleMask:(styleMask & ~NSTitledWindowMask) | NSBorderlessWindowMask];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1274
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1275
            int shieldLevel = CGShieldingWindowLevel();
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1276
            window.preFullScreenLevel = [nsWindow level];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1277
            [nsWindow setLevel: shieldLevel];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1278
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1279
            NSRect screenRect = [[nsWindow screen] frame];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1280
            [nsWindow setFrame:screenRect display:YES];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1281
        } else {
21790
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1282
            [JNFException raise:[ThreadUtilities getJNIEnv]
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1283
                             as:kRuntimeException
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1284
                         reason:"Failed to enter full screen."];
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1285
        }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1286
    }];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1287
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1288
JNF_COCOA_EXIT(env);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1289
}
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1290
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1291
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeExitFullScreenMode
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1292
(JNIEnv *env, jclass clazz, jlong windowPtr)
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1293
{
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1294
JNF_COCOA_ENTER(env);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1295
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1296
    NSWindow *nsWindow = OBJC(windowPtr);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1297
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1298
        AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1299
        NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1300
        CGDirectDisplayID aID = [screenID intValue];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1301
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1302
        if (CGDisplayRelease(aID) == kCGErrorSuccess) {
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1303
            NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1304
            [nsWindow setStyleMask:styleMask]; 
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1305
            [nsWindow setLevel: window.preFullScreenLevel];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1306
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1307
            // GraphicsDevice takes care of restoring pre full screen bounds
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1308
        } else {
21790
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1309
            [JNFException raise:[ThreadUtilities getJNIEnv]
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1310
                             as:kRuntimeException
dae43c3c462d 8028512: [macosx] Crash in full screen api if incorrect display mode is used
serb
parents: 21788
diff changeset
  1311
                         reason:"Failed to exit full screen."];
21282
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1312
        }
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1313
    }];
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1314
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1315
JNF_COCOA_EXIT(env);
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1316
}
1bef38644939 8013581: [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
leonidr
parents: 21248
diff changeset
  1317