src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
author serb
Thu, 26 Oct 2017 19:45:37 -0700
changeset 47508 33da1153954c
parent 47216 71c04702a3d5
child 48751 54f355e65415
permissions -rw-r--r--
8187639: TrayIcon is not properly supported on macOS in multi-screen environment Reviewed-by: prr, ssadetsky
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
/*
46874
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import "NSApplicationAWT.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <objc/runtime.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "PropertiesUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
#import "QueuingApplicationDelegate.h"
13992
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
    34
#import "AWTIconData.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
    36
/*
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
    37
 * Declare library specific JNI_Onload entry if static build
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
    38
 */
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
    39
DEF_STATIC_JNI_OnLoad
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
static BOOL sUsingDefaultNIB = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
static id <NSApplicationDelegate> applicationDelegate = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
static QueuingApplicationDelegate * qad = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
// Flag used to indicate to the Plugin2 event synthesis code to do a postEvent instead of sendEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
BOOL postEventDuringEventSynthesis = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    49
/**
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    50
 * Subtypes of NSApplicationDefined, which are used for custom events.
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    51
 */
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    52
enum {
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    53
    ExecuteBlockEvent, NativeSyncQueueEvent
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    54
};
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
    55
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
@implementation NSApplicationAWT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
- (id) init
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    // Headless: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    // Embedded: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
    // Multiple Calls: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    //  Caller: +[NSApplication sharedApplication]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    fApplicationName = nil;
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
    67
    dummyEventTimestamp = 0.0;
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
    68
    seenDummyEventLock = nil;
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
    69
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
    // So, we need to call it ourselves to ensure the app is set up properly.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    [self registerWithProcessManager];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    return [super init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
- (void)dealloc
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
{
47508
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
    80
    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
    81
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    [fApplicationName release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    fApplicationName = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
- (void)finishLaunching
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    // Get default nib file location
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    // NOTE: This should learn about the current java.version. Probably best thru
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    //  the Makefile system's -DFRAMEWORK_VERSION define. Need to be able to pass this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    //  thru to PB from the Makefile system and for local builds.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    NSString *defaultNibFile = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.nib" withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    if (!defaultNibFile) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
        NSBundle *javaBundle = [NSBundle bundleWithPath:SHARED_FRAMEWORK_BUNDLE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
        defaultNibFile = [javaBundle pathForResource:@"DefaultApp" ofType:@"nib"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
        sUsingDefaultNIB = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    [NSBundle loadNibFile:defaultNibFile externalNameTable: [NSDictionary dictionaryWithObject:self forKey:@"NSOwner"] withZone:nil];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    // Set user defaults to not try to parse application arguments.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    NSDictionary * noOpenDict = [NSDictionary dictionaryWithObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    [defs registerDefaults:noOpenDict];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    // Fix up the dock icon now that we are registered with CAS and the Dock.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    [self setDockIconWithEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    // If we are using our nib (the default application NIB) we need to put the app name into
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    // the application menu, which has placeholders for the name.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    if (sUsingDefaultNIB) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        NSUInteger i, itemCount;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
        NSMenu *theMainMenu = [NSApp mainMenu];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        // First submenu off the main menu is the application menu.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        NSMenuItem *appMenuItem = [theMainMenu itemAtIndex:0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
        NSMenu *appMenu = [appMenuItem submenu];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        itemCount = [appMenu numberOfItems];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        for (i = 0; i < itemCount; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
            NSMenuItem *anItem = [appMenu itemAtIndex:i];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
            NSString *oldTitle = [anItem title];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
            [anItem setTitle:[NSString stringWithFormat:oldTitle, fApplicationName]];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    if (applicationDelegate) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
        [self setDelegate:applicationDelegate];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
        qad = [QueuingApplicationDelegate sharedDelegate];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        [self setDelegate:qad];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    [super finishLaunching];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
47508
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   143
    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   144
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    // inform any interested parties that the AWT has arrived and is pumping
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    [[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
47508
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   149
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   150
     shouldPresentNotification:(NSUserNotification *)notification
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   151
{
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   152
    return YES; // We always show notifications to the user
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   153
}
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47216
diff changeset
   154
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
- (void) registerWithProcessManager
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
    // Headless: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    // Embedded: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    // Multiple Calls: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    //  Caller: -[NSApplicationAWT init]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    char envVar[80];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    // The following environment variable is set from the -Xdock:name param. It should be UTF8.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    char *appName = getenv(envVar);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
    if (appName != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
        fApplicationName = [NSString stringWithUTF8String:appName];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
        unsetenv(envVar);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    // If it wasn't specified as an argument, see if it was specified as a system property.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
        fApplicationName = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.name" withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
    // If we STILL don't have it, the app name is retrieved from an environment variable (set in java.c) It should be UTF8.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
        char mainClassEnvVar[80];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
        snprintf(mainClassEnvVar, sizeof(mainClassEnvVar), "JAVA_MAIN_CLASS_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
        char *mainClass = getenv(mainClassEnvVar);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
        if (mainClass != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
            fApplicationName = [NSString stringWithUTF8String:mainClass];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
            unsetenv(mainClassEnvVar);
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
            NSRange lastPeriod = [fApplicationName rangeOfString:@"." options:NSBackwardsSearch];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
            if (lastPeriod.location != NSNotFound) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
                fApplicationName = [fApplicationName substringFromIndex:lastPeriod.location + 1];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    // The dock name is nil for double-clickable Java apps (bundled and Web Start apps)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    // When that happens get the display name, and if that's not available fall back to
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    // CFBundleName.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    NSBundle *mainBundle = [NSBundle mainBundle];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
        fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
        if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
            fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
            if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
                fApplicationName = (NSString *)[mainBundle objectForInfoDictionaryKey: (NSString *)kCFBundleExecutableKey];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
                if (fApplicationName == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
                    // Name of last resort is the last part of the applicatoin name without the .app (consistent with CopyProcessName)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
                    fApplicationName = [[mainBundle bundlePath] lastPathComponent];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
                    if ([fApplicationName hasSuffix:@".app"]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
                        fApplicationName = [fApplicationName stringByDeletingPathExtension];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    // We're all done trying to determine the app name.  Hold on to it.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    [fApplicationName retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    NSDictionary *registrationOptions = [NSMutableDictionary dictionaryWithObject:fApplicationName forKey:@"JRSAppNameKey"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    NSString *launcherType = [PropertiesUtilities javaSystemPropertyForKey:@"sun.java.launcher" withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    if ([@"SUN_STANDARD" isEqualToString:launcherType]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsCommandLineKey"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    NSString *uiElementProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.UIElement" withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    if ([@"true" isCaseInsensitiveLike:uiElementProp]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsUIElementKey"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
    NSString *backgroundOnlyProp = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.BackgroundOnly" withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
    if ([@"true" isCaseInsensitiveLike:backgroundOnlyProp]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
        [registrationOptions setValue:[NSNumber numberWithBool:YES] forKey:@"JRSAppIsBackgroundOnlyKey"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
    }
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
    // TODO replace with direct call
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    // [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    // and remove below transform/activate/run hack
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
    id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    SEL registerSel = @selector(registerAWTAppWithOptions:);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    if ([jrsAppKitAWTClass respondsToSelector:registerSel]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
        [jrsAppKitAWTClass performSelector:registerSel withObject:registrationOptions];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
// HACK BEGIN
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    // The following is necessary to make the java process behave like a
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    // proper foreground application...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        ProcessSerialNumber psn;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        GetCurrentProcess(&psn);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
        TransformProcessType(&psn, kProcessTransformToForegroundApplication);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
        [NSApp activateIgnoringOtherApps:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        [NSApp run];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
// HACK END
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
- (void) setDockIconWithEnv:(JNIEnv *)env {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    NSString *theIconPath = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    // The following environment variable is set in java.c. It is probably UTF8.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    char envVar[80];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
    snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    char *appIcon = getenv(envVar);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
    if (appIcon != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        theIconPath = [NSString stringWithUTF8String:appIcon];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
        unsetenv(envVar);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    if (theIconPath == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
        theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env];
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
13992
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   282
    // Use the path specified to get the icon image
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   283
    NSImage* iconImage = nil;
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   284
    if (theIconPath != nil) {
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   285
        iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   286
    }
13992
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   287
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   288
    // If no icon file was specified or we failed to get the icon image
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   289
    // and there is no bundle's icon, then use the default icon
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   290
    if (iconImage == nil) {
13539
2a658e96e769 7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents: 12047
diff changeset
   291
        NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
2a658e96e769 7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents: 12047
diff changeset
   292
        if (bundleIcon == nil) {
13992
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   293
            NSData* iconData;
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   294
            iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO];
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   295
            iconImage = [[NSImage alloc] initWithData: iconData];
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   296
            [iconData release];
13539
2a658e96e769 7159381: [macosx] Dock Icon defaults to Generic Java Application Category
leonidr
parents: 12047
diff changeset
   297
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
13992
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   300
    // Set up the dock icon if we have an icon image.
d1b65c4e924c 7179349: [macosx] Java processes on Mac should not use default Apple icon
leonidr
parents: 13991
diff changeset
   301
    if (iconImage != nil) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
        [NSApp setApplicationIconImage:iconImage];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        [iconImage release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
+ (void) runAWTLoopWithApp:(NSApplication*)app {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
    // Make sure that when we run in AWTRunLoopMode we don't exit randomly
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
    [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
        @try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
            [app run];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
        } @catch (NSException* e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
            NSLog(@"Apple AWT Startup Exception: %@", [e description]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
            NSLog(@"Apple AWT Restarting Native Event Thread");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
            [app stop:app];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    } while (YES);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
    [pool drain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
- (BOOL)usingDefaultNib {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    return sUsingDefaultNIB;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
- (void)orderFrontStandardAboutPanelWithOptions:(NSDictionary *)optionsDictionary {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    if (!optionsDictionary) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
        optionsDictionary = [NSMutableDictionary dictionaryWithCapacity:2];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
        [optionsDictionary setValue:[[[[[NSApp mainMenu] itemAtIndex:0] submenu] itemAtIndex:0] title] forKey:@"ApplicationName"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
        if (![NSImage imageNamed:@"NSApplicationIcon"]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
            [optionsDictionary setValue:[NSApp applicationIconImage] forKey:@"ApplicationIcon"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
    [super orderFrontStandardAboutPanelWithOptions:optionsDictionary];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
#define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
46874
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   345
#if defined(MAC_OS_X_VERSION_10_12) && \
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   346
   MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12 && \
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   347
   __LP64__
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   348
   // 10.12 changed `mask` to NSEventMask (unsigned long long) for x86_64 builds.
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   349
- (NSEvent *)nextEventMatchingMask:(NSEventMask)mask
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   350
#else
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   351
- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   352
#endif
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41387
diff changeset
   353
untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
    if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
        postEventDuringEventSynthesis = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
    NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
    postEventDuringEventSynthesis = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
    return event;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   364
// NSTimeInterval has microseconds precision
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   365
#define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   366
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   367
- (void)sendEvent:(NSEvent *)event
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   368
{
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   369
    if ([event type] == NSApplicationDefined
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   370
            && TS_EQUAL([event timestamp], dummyEventTimestamp)
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   371
            && [event subtype] == NativeSyncQueueEvent) {
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   372
        [seenDummyEventLock lockWhenCondition:NO];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   373
        [seenDummyEventLock unlockWithCondition:YES];
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   374
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   375
    } else if ([event type] == NSApplicationDefined && [event subtype] == ExecuteBlockEvent) {
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   376
        void (^block)() = (void (^)()) [event data1];
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   377
        block();
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   378
        [block release];
21268
b3298f607368 8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents: 14342
diff changeset
   379
    } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) {
b3298f607368 8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents: 14342
diff changeset
   380
        // Cocoa won't send us key up event when releasing a key while Cmd is down,
b3298f607368 8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents: 14342
diff changeset
   381
        // so we have to do it ourselves.
b3298f607368 8020209: [macosx] Mac OS X key event confusion for "COMMAND PLUS"
leonidr
parents: 14342
diff changeset
   382
        [[self keyWindow] sendEvent:event];
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   383
    } else {
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   384
        [super sendEvent:event];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   385
    }
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   386
}
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   387
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   388
/*
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   389
 * Posts the block to the AppKit event queue which will be executed
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   390
 * on the main AppKit loop.
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   391
 * While running nested loops this event will be ignored.
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   392
 */
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   393
- (void)postRunnableEvent:(void (^)())block
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   394
{
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   395
    void (^copy)() = [block copy];
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   396
    NSInteger encode = (NSInteger) copy;
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   397
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   398
    NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   399
                                        location: NSMakePoint(0,0)
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   400
                                   modifierFlags: 0
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   401
                                       timestamp: 0
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   402
                                    windowNumber: 0
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   403
                                         context: nil
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   404
                                         subtype: ExecuteBlockEvent
31170
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   405
                                           data1: encode
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   406
                                           data2: 0];
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   407
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   408
    [NSApp postEvent: event atStart: NO];
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   409
    [pool drain];
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   410
}
4d414cfb92cc 8068886: IDEA IntelliJ crashes in objc_msgSend when an accessibility tool is enabled
anashaty
parents: 25859
diff changeset
   411
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   412
- (void)postDummyEvent:(bool)useCocoa {
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   413
    seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   414
    dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   415
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   416
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   417
    NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   418
                                        location: NSMakePoint(0,0)
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   419
                                   modifierFlags: 0
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   420
                                       timestamp: dummyEventTimestamp
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   421
                                    windowNumber: 0
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   422
                                         context: nil
31883
be405ebc8355 8129894: NSApplicationAWT.m:343:72: error: comparison of constant 777 with expression of type 'NSEventSubtype'
serb
parents: 31654
diff changeset
   423
                                         subtype: NativeSyncQueueEvent
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   424
                                           data1: 0
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   425
                                           data2: 0];
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   426
    if (useCocoa) {
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   427
        [NSApp postEvent:event atStart:NO];
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   428
    } else {
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   429
        ProcessSerialNumber psn;
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   430
        GetCurrentProcess(&psn);
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   431
        CGEventPostToPSN(&psn, [event CGEvent]);
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   432
    }
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   433
    [pool drain];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   434
}
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   435
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   436
- (void)waitForDummyEvent:(double)timeout {
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   437
    bool unlock = true;
31654
9f95289d9553 8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents: 31170
diff changeset
   438
    if (timeout >= 0) {
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   439
        double sec = timeout / 1000;
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   440
        unlock = [seenDummyEventLock lockWhenCondition:YES
31654
9f95289d9553 8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents: 31170
diff changeset
   441
                               beforeDate:[NSDate dateWithTimeIntervalSinceNow:sec]];
9f95289d9553 8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents: 31170
diff changeset
   442
    } else {
9f95289d9553 8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents: 31170
diff changeset
   443
        [seenDummyEventLock lockWhenCondition:YES];
9f95289d9553 8080504: [macosx] SunToolkit.realSync() may hang
anashaty
parents: 31170
diff changeset
   444
    }
32293
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   445
    if (unlock) {
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   446
        [seenDummyEventLock unlock];
269494f7adec 7124271: [macosx] RealSync test failure
serb
parents: 31883
diff changeset
   447
    }
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   448
    [seenDummyEventLock release];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   449
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   450
    seenDummyEventLock = nil;
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   451
}
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13539
diff changeset
   452
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
   456
void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> newdelegate)
12047
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
AWT_ASSERT_APPKIT_THREAD;
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 32293
diff changeset
   459
    applicationDelegate = newdelegate;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
    if (NSApp != nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
        [NSApp setDelegate: applicationDelegate];
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
        if (applicationDelegate && qad) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
            [qad processQueuedEventsWithTargetDelegate: applicationDelegate];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
            qad = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
        }
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
}