jdk/src/macosx/native/sun/awt/LWCToolkit.m
author pchelko
Wed, 02 Jul 2014 17:04:04 +0400
changeset 25563 248400a88627
parent 24550 cc2777fafab7
child 25564 871d3490f14d
permissions -rw-r--r--
8033367: [macosx] Appletviewer was broken in jdk8 b124 Reviewed-by: anthony, serb
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
/*
24550
cc2777fafab7 8042585: [macosx] Unused code in LWCToolkit.m
pchelko
parents: 24183
diff changeset
     2
 * Copyright (c) 2011, 2014, 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 <dlfcn.h>
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    27
#import <pthread.h>
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    28
#import <objc/runtime.h>
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    29
#import <Cocoa/Cocoa.h>
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    30
#import <Security/AuthSession.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import <JavaNativeFoundation/JavaNativeFoundation.h>
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    32
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
#include "jni_util.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
#import "CMenuBar.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#import "InitIDs.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
#import "LWCToolkit.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
#import "AWT_debug.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
#import "CSystemColors.h"
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
    41
#import  "NSApplicationAWT.h"
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    42
#import "PropertiesUtilities.h"
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    43
#import "ApplicationDelegate.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
#import "sun_lwawt_macosx_LWCToolkit.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 15988
diff changeset
    47
#import "sizecalc.h"
b538b71fb429 8009071: Improve shape handling
anthony
parents: 15988
diff changeset
    48
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
int gNumberOfButtons;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
jint* gButtonDownMasks;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    52
// Indicates that the app has been started with -XstartOnFirstThread
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    53
// (directly or via WebStart settings), and AWT should not run its
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    54
// own event loop in this mode. Even if a loop isn't running yet,
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    55
// we expect an embedder (e.g. SWT) to start it some time later.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    56
static BOOL forceEmbeddedMode = NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    57
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    58
// This is the data necessary to have JNI_OnLoad wait for AppKit to start.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    59
static BOOL sAppKitStarted = NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    60
static pthread_mutex_t sAppKitStarted_mutex = PTHREAD_MUTEX_INITIALIZER;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    61
static pthread_cond_t sAppKitStarted_cv = PTHREAD_COND_INITIALIZER;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    62
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
@implementation AWTToolkit
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
static long eventCount;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
+ (long) getEventCount{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    return eventCount;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
    71
+ (void) eventCountPlusPlus{    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
    eventCount++;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
}
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
@end
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
@interface AWTRunLoopObject : NSObject {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    BOOL _shouldEndRunLoop;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
@implementation AWTRunLoopObject
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
- (id) init {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    self = [super init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    if (self != nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
        _shouldEndRunLoop = NO;
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
    return self;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
- (BOOL) shouldEndRunLoop {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    return _shouldEndRunLoop;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
- (void) endRunLoop {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    _shouldEndRunLoop = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
23681
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   103
@interface JavaRunnable : NSObject { }
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   104
@property jobject runnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   105
- (id)initWithRunnable:(jobject)gRunnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   106
- (void)perform;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   107
@end
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   108
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   109
@implementation JavaRunnable
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   110
@synthesize runnable = _runnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   111
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   112
- (id)initWithRunnable:(jobject)gRunnable {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   113
    if (self = [super init]) {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   114
        self.runnable = gRunnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   115
    }
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   116
    return self;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   117
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   118
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   119
- (void)dealloc {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   120
    JNIEnv *env = [ThreadUtilities getJNIEnv];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   121
    if (self.runnable) {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   122
        (*env)->DeleteGlobalRef(env, self.runnable);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   123
    }
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   124
    [super dealloc];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   125
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   126
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   127
- (void)perform {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   128
    JNIEnv* env = [ThreadUtilities getJNIEnv];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   129
    static JNF_CLASS_CACHE(sjc_Runnable, "java/lang/Runnable");
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   130
    static JNF_MEMBER_CACHE(jm_Runnable_run, sjc_Runnable, "run", "()V");
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   131
    JNFCallVoidMethod(env, self.runnable, jm_Runnable_run);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   132
    [self release];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   133
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   134
@end
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   135
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   136
void setBusy(BOOL busy) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   137
    AWT_ASSERT_APPKIT_THREAD;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   138
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   139
    JNIEnv *env = [ThreadUtilities getJNIEnv];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   140
    static JNF_CLASS_CACHE(jc_AWTAutoShutdown, "sun/awt/AWTAutoShutdown");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   141
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   142
    if (busy) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   143
        static JNF_STATIC_MEMBER_CACHE(jm_notifyBusyMethod, jc_AWTAutoShutdown, "notifyToolkitThreadBusy", "()V");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   144
        JNFCallStaticVoidMethod(env, jm_notifyBusyMethod);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   145
    } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   146
        static JNF_STATIC_MEMBER_CACHE(jm_notifyFreeMethod, jc_AWTAutoShutdown, "notifyToolkitThreadFree", "()V");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   147
        JNFCallStaticVoidMethod(env, jm_notifyFreeMethod);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   148
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   149
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   150
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   151
static void setUpAWTAppKit(BOOL installObservers)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   152
{
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   153
    if (installObservers) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   154
        AWT_STARTUP_LOG(@"Setting up busy observers");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   155
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   156
        // Add CFRunLoopObservers to call into AWT so that AWT knows that the
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   157
        //  AWT thread (which is the AppKit main thread) is alive. This way AWT
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   158
        //  will not automatically shutdown.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   159
        CFRunLoopObserverRef busyObserver = CFRunLoopObserverCreateWithHandler(
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   160
                                               NULL,                        // CFAllocator
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   161
                                               kCFRunLoopAfterWaiting,      // CFOptionFlags
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   162
                                               true,                        // repeats
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   163
                                               NSIntegerMax,                // order
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   164
                                               ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   165
                                                   setBusy(YES);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   166
                                               });
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   167
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   168
        CFRunLoopObserverRef notBusyObserver = CFRunLoopObserverCreateWithHandler(
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   169
                                                NULL,                        // CFAllocator
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   170
                                                kCFRunLoopBeforeWaiting,     // CFOptionFlags
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   171
                                                true,                        // repeats
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   172
                                                NSIntegerMin,                // order
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   173
                                                ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   174
                                                    setBusy(NO);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   175
                                                });
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   176
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   177
        CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   178
        CFRunLoopAddObserver(runLoop, busyObserver, kCFRunLoopDefaultMode);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   179
        CFRunLoopAddObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   180
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   181
        CFRelease(busyObserver);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   182
        CFRelease(notBusyObserver);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   183
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   184
        setBusy(YES);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   185
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   186
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   187
    JNIEnv* env = [ThreadUtilities getJNIEnv];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   188
    static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   189
    static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   190
    JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   191
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   192
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   193
BOOL isSWTInWebStart(JNIEnv* env) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   194
    NSString *swtWebStart = [PropertiesUtilities javaSystemPropertyForKey:@"com.apple.javaws.usingSWT" withEnv:env];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   195
    return [@"true" isCaseInsensitiveLike:swtWebStart];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   196
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   197
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   198
static void AWT_NSUncaughtExceptionHandler(NSException *exception) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   199
    NSLog(@"Apple AWT Internal Exception: %@", [exception description]);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   200
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   201
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   202
@interface AWTStarter : NSObject
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   203
+ (void)start:(BOOL)headless;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   204
+ (void)starter:(BOOL)onMainThread headless:(BOOL)headless;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   205
+ (void)appKitIsRunning:(id)arg;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   206
@end
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   207
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   208
@implementation AWTStarter
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   209
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   210
+ (BOOL) isConnectedToWindowServer {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   211
    SecuritySessionId session_id;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   212
    SessionAttributeBits session_info;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   213
    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   214
    if (status != noErr) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   215
    if (!(session_info & sessionHasGraphicAccess)) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   216
    return YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   217
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   218
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   219
+ (BOOL) markAppAsDaemon {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   220
    id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   221
    SEL markAppSel = @selector(markAppIsDaemon);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   222
    if (![jrsAppKitAWTClass respondsToSelector:markAppSel]) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   223
    return [jrsAppKitAWTClass performSelector:markAppSel] ? YES : NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   224
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   225
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   226
+ (void)appKitIsRunning:(id)arg {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   227
    AWT_ASSERT_APPKIT_THREAD;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   228
    AWT_STARTUP_LOG(@"About to message AppKit started");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   229
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   230
    // Signal that AppKit has started (or is already running).
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   231
    pthread_mutex_lock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   232
    sAppKitStarted = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   233
    pthread_cond_signal(&sAppKitStarted_cv);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   234
    pthread_mutex_unlock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   235
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   236
    AWT_STARTUP_LOG(@"Finished messaging AppKit started");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   237
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   238
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   239
+ (void)start:(BOOL)headless
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   240
{
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   241
    // onMainThread is NOT the same at SWT mode!
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   242
    // If the JVM was started on the first thread for SWT, but the SWT loads the AWT on a secondary thread,
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   243
    // onMainThread here will be false but SWT mode will be true.  If we are currently on the main thread, we don't
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   244
    // need to throw AWT startup over to another thread.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   245
    BOOL onMainThread = [NSThread isMainThread];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   246
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   247
    NSString* msg = [NSString stringWithFormat:@"+[AWTStarter start headless:%d] { onMainThread:%d }", headless, onMainThread];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   248
    AWT_STARTUP_LOG(msg);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   249
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   250
    if (!headless)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   251
    {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   252
        // Listen for the NSApp to start. This indicates that JNI_OnLoad can proceed.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   253
        //  It must wait because there is a chance that another java thread will grab
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   254
        //  the AppKit lock before the +[NSApplication sharedApplication] returns.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   255
        //  See <rdar://problem/3492666> for an example.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   256
        [[NSNotificationCenter defaultCenter] addObserver:[AWTStarter class]
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   257
                                                 selector:@selector(appKitIsRunning:)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   258
                                                     name:NSApplicationDidFinishLaunchingNotification
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   259
                                                   object:nil];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   260
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   261
        AWT_STARTUP_LOG(@"+[AWTStarter start:::]: registered NSApplicationDidFinishLaunchingNotification");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   262
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   263
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   264
    [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   265
        [AWTStarter starter:onMainThread headless:headless];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   266
    }];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   267
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   268
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   269
    if (!headless && !onMainThread) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   270
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   271
        AWT_STARTUP_LOG(@"about to wait on AppKit startup mutex");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   272
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   273
        // Wait here for AppKit to have started (or for AWT to have been loaded into
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   274
        //  an already running NSApplication).
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   275
        pthread_mutex_lock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   276
        while (sAppKitStarted == NO) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   277
            pthread_cond_wait(&sAppKitStarted_cv, &sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   278
        }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   279
        pthread_mutex_unlock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   280
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   281
        // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   282
        AWT_STARTUP_LOG(@"got out of the AppKit startup mutex");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   283
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   284
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   285
    if (!headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   286
        // Don't set the delegate until the NSApplication has been created and
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   287
        // its finishLaunching has initialized it.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   288
        //  ApplicationDelegate is the support code for com.apple.eawt.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   289
        [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   290
            id<NSApplicationDelegate> delegate = [ApplicationDelegate sharedDelegate];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   291
            if (delegate != nil) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   292
                OSXAPP_SetApplicationDelegate(delegate);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   293
            }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   294
        }];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   295
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   296
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   297
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   298
+ (void)starter:(BOOL)wasOnMainThread headless:(BOOL)headless {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   299
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   300
    // Add the exception handler of last resort
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   301
    NSSetUncaughtExceptionHandler(AWT_NSUncaughtExceptionHandler);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   302
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   303
    // Headless mode trumps either ordinary AWT or SWT-in-AWT mode.  Declare us a daemon and return.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   304
    if (headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   305
        // Note that we don't install run loop observers in headless mode
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   306
        // because we don't need them (see 7174704)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   307
        if (!forceEmbeddedMode) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   308
            setUpAWTAppKit(false);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   309
        }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   310
        [AWTStarter markAppAsDaemon];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   311
        return;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   312
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   313
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   314
    if (forceEmbeddedMode) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   315
        AWT_STARTUP_LOG(@"in SWT or SWT/WebStart mode");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   316
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   317
        // Init a default NSApplication instance instead of the NSApplicationAWT.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   318
        // Note that [NSApp isRunning] will return YES after that, though
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   319
        // this behavior isn't specified anywhere. We rely on that.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   320
        NSApplicationLoad();
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   321
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   322
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   323
    // This will create a NSApplicationAWT for standalone AWT programs, unless there is
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   324
    //  already a NSApplication instance. If there is already a NSApplication instance,
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   325
    //  and -[NSApplication isRunning] returns YES, AWT is embedded inside another
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   326
    //  AppKit Application.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   327
    NSApplication *app = [NSApplicationAWT sharedApplication];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   328
    BOOL isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   329
    [ThreadUtilities setAWTEmbedded:isEmbedded];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   330
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   331
    if (!isEmbedded) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   332
        // Install run loop observers and set the AppKit Java thread name
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   333
        setUpAWTAppKit(true);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   334
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   335
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   336
    // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   337
    if (![app isRunning]) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   338
        AWT_STARTUP_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   339
        // This is where the AWT AppKit thread parks itself to process events.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   340
        [NSApplicationAWT runAWTLoopWithApp: app];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   341
    } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   342
        // We're either embedded, or showing a splash screen
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   343
        if (isEmbedded) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   344
            AWT_STARTUP_LOG(@"running embedded");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   345
            
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   346
            // We don't track if the runloop is busy, so set it free to let AWT finish when it needs
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   347
            setBusy(NO);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   348
        } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   349
            AWT_STARTUP_LOG(@"running after showing a splash screen");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   350
        }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   351
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   352
        // Signal so that JNI_OnLoad can proceed.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   353
        if (!wasOnMainThread) [AWTStarter appKitIsRunning:nil];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   354
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   355
        // Proceed to exit this call as there is no reason to run the NSApplication event loop.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   356
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   357
    
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   358
    [pool drain];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   359
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   360
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   361
@end
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   362
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
 * Method:    nativeSyncQueue
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
 * Signature: (J)Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
(JNIEnv *env, jobject self, jlong timeout)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
    int currentEventNum = [AWTToolkit getEventCount];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   373
    NSApplication* sharedApp = [NSApplication sharedApplication];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   374
    if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) {
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   375
        NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp;
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   376
        [theApp postDummyEvent];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   377
        [theApp waitForDummyEvent];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   378
    } else {
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   379
        // could happen if we are embedded inside SWT application,
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   380
        // in this case just spin a single empty block through 
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   381
        // the event loop to give it a chance to process pending events
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   382
        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   383
    }
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   384
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
    if (([AWTToolkit getEventCount] - currentEventNum) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
        return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    }
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   388
        
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
24169
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   392
/*
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   393
 * Class:     sun_lwawt_macosx_LWCToolkit
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   394
 * Method:    flushNativeSelectors
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   395
 * Signature: ()J
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   396
 */
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   397
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   398
(JNIEnv *env, jclass clz)
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   399
{
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   400
JNF_COCOA_ENTER(env);
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   401
        [ThreadUtilities performOnMainThreadWaiting:YES block:^(){}];
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   402
JNF_COCOA_EXIT(env);
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   403
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
 * Method:    beep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
 * Signature: ()V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
Java_sun_lwawt_macosx_LWCToolkit_beep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
(JNIEnv *env, jobject self)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
    NSBeep(); // produces both sound and visual flash, if configured in System Preferences
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
static UInt32 RGB(NSColor *c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
    c = [c colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    if (c == nil)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
        return -1; // opaque white
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
    CGFloat r, g, b, a;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
    [c getRed:&r green:&g blue:&b alpha:&a];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    UInt32 ir = (UInt32) (r*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    ig = (UInt32) (g*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
    ib = (UInt32) (b*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
    ia = (UInt32) (a*255+0.5);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
    //    NSLog(@"%@ %d, %d, %d", c, ir, ig, ib);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
    return ((ia & 0xFF) << 24) | ((ir & 0xFF) << 16) | ((ig & 0xFF) << 8) | ((ib & 0xFF) << 0);
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
23301
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   437
BOOL doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
    jint len = (*env)->GetArrayLength(env, jColors);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
    UInt32 colorsArray[len];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
    UInt32 *colors = colorsArray;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
        NSUInteger i;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
        for (i = 0; i < len; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
            colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
    jint *_colors = (*env)->GetPrimitiveArrayCritical(env, jColors, 0);
23301
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   451
    if (_colors == NULL) {
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   452
        return NO;
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   453
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
    memcpy(_colors, colors, len * sizeof(UInt32));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
    (*env)->ReleasePrimitiveArrayCritical(env, jColors, _colors, 0);
23301
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   456
    return YES;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
/**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
 * Method:    loadNativeColors
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
 * Signature: ([I[I)V
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
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
(JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
JNF_COCOA_ENTER(env);
23301
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   468
    if (doLoadNativeColors(env, jSystemColors, NO)) {
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   469
        doLoadNativeColors(env, jAppleColors, YES);
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   470
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
 * Method:    createAWTRunLoopMediator
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
 * Signature: ()J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_LWCToolkit_createAWTRunLoopMediator
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
(JNIEnv *env, jclass clz)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   484
    jlong result;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   486
JNF_COCOA_ENTER(env);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
    // We double retain because this object is owned by both main thread and "other" thread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
    // We release in both doAWTRunLoop and stopAWTRunLoop
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   489
    result = ptr_to_jlong([[[AWTRunLoopObject alloc] init] retain]);
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   490
JNF_COCOA_EXIT(env);
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   491
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   492
    return result;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   493
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   494
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   495
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
 * Class:     sun_lwawt_macosx_LWCToolkit
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   497
 * Method:    doAWTRunLoopImpl
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
 * Signature: (JZZ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
 */
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   500
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoopImpl
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   501
(JNIEnv *env, jclass clz, jlong mediator, jboolean processEvents, jboolean inAWT)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
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
    if (mediatorObject == nil) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   510
    // Don't use acceptInputForMode because that doesn't setup autorelease pools properly
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   511
    BOOL isRunning = true;
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   512
    while (![mediatorObject shouldEndRunLoop] && isRunning) {
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   513
        isRunning = [[NSRunLoop currentRunLoop] runMode:(inAWT ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode)
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   514
                                             beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]];
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   515
        if (processEvents) {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   516
            //We do not spin a runloop here as date is nil, so does not matter which mode to use
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   517
            NSEvent *event;
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   518
            if ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   519
                                           untilDate:nil
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   520
                                              inMode:NSDefaultRunLoopMode
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   521
                                             dequeue:YES]) != nil) {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   522
                [NSApp sendEvent:event];
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   523
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
    }
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   527
    [mediatorObject release];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
JNF_COCOA_EXIT(env);
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
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
 * Method:    stopAWTRunLoop
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
(JNIEnv *env, jclass clz, jlong mediator)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
JNF_COCOA_ENTER(env);
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
    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   543
    [ThreadUtilities performOnMainThread:@selector(endRunLoop) on:mediatorObject withObject:nil waitUntilDone:NO];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   545
    [mediatorObject release];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
 * Class:     sun_lwawt_macosx_LWCToolkit
23681
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   552
 * Method:    performOnMainThreadAfterDelay
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   553
 * Signature: (Ljava/lang/Runnable;J)V
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   554
 */
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   555
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_performOnMainThreadAfterDelay
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   556
(JNIEnv *env, jclass clz, jobject runnable, jlong delay)
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   557
{
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   558
JNF_COCOA_ENTER(env);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   559
    jobject gRunnable = (*env)->NewGlobalRef(env, runnable);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   560
    CHECK_NULL(gRunnable);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   561
    [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   562
        JavaRunnable* performer = [[JavaRunnable alloc] initWithRunnable:gRunnable];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   563
        [performer performSelector:@selector(perform) withObject:nil afterDelay:(delay/1000.0)];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   564
    }];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   565
JNF_COCOA_EXIT(env);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   566
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   567
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   568
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   569
/*
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   570
 * Class:     sun_lwawt_macosx_LWCToolkit
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   571
 * Method:    isCapsLockOn
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   572
 * Signature: ()Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
(JNIEnv *env, jobject self)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
    __block jboolean isOn = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   579
        NSUInteger modifiers = [NSEvent modifierFlags];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   580
        isOn = (modifiers & NSAlphaShiftKeyMask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
    return isOn;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
 * Method:    isApplicationActive
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
 * Signature: ()Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isApplicationActive
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
(JNIEnv *env, jclass clazz)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
{
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   594
    __block jboolean active = JNI_FALSE;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 13991
diff changeset
   598
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   599
        active = (jboolean)[NSRunningApplication currentApplication].active;
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 13991
diff changeset
   600
    }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   604
    return active;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
 * Class:     sun_awt_SunToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
 * Method:    closeSplashScreen
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
 * Signature: ()V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls)
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 *hSplashLib = dlopen(0, RTLD_LAZY);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
    if (!hSplashLib) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
    void (*splashClose)() = dlsym(hSplashLib, "SplashClose");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
    if (splashClose) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
        splashClose();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
    dlclose(hSplashLib);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
// TODO: definitely doesn't belong here (copied from fontpath.c in the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
// solaris tree)...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
JNIEXPORT jstring JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
Java_sun_font_FontManager_getFontPath
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
(JNIEnv *env, jclass obj, jboolean noType1)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
    return JNFNSToJavaString(env, @"/Library/Fonts");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
// This isn't yet used on unix, the implementation is added since shared
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
// code calls this method in preparation for future use.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
Java_sun_font_FontManager_populateFontFileNameMap
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
(JNIEnv *env, jclass obj, jobject fontToFileMap, jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
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
}
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   645
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   646
/*
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   647
 * Class:     sun_lwawt_macosx_LWCToolkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   648
 * Method:    initIDs
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   649
 * Signature: ()V
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   650
 */
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   651
JNIEXPORT void JNICALL
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   652
Java_sun_lwawt_macosx_LWCToolkit_initIDs
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   653
(JNIEnv *env, jclass klass) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   654
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   655
    JNF_COCOA_ENTER(env)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   656
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   657
    gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   658
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   659
    jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   660
    CHECK_NULL(inputEventClazz);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   661
    jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   662
    CHECK_NULL(getButtonDownMasksID);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   663
    jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   664
    jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   665
    CHECK_NULL(tmp);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   666
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   667
    gButtonDownMasks = (jint*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), gNumberOfButtons);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   668
    if (gButtonDownMasks == NULL) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   669
        gNumberOfButtons = 0;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   670
        (*env)->ReleaseIntArrayElements(env, obj, tmp, JNI_ABORT);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   671
        JNU_ThrowOutOfMemoryError(env, NULL);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   672
        return;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   673
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   674
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   675
    int i;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   676
    for (i = 0; i < gNumberOfButtons; i++) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   677
        gButtonDownMasks[i] = tmp[i];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   678
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   679
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   680
    (*env)->ReleaseIntArrayElements(env, obj, tmp, 0);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   681
    (*env)->DeleteLocalRef(env, obj);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   682
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   683
    JNF_COCOA_EXIT(env)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   684
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   685
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   686
/*
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   687
 * Class:     sun_lwawt_macosx_LWCToolkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   688
 * Method:    initAppkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   689
 * Signature: (Ljava/lang/ThreadGroup;)V
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   690
 */
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   691
JNIEXPORT void JNICALL
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   692
Java_sun_lwawt_macosx_LWCToolkit_initAppkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   693
(JNIEnv *env, jclass klass, jobject appkitThreadGroup, jboolean headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   694
    JNF_COCOA_ENTER(env)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   695
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   696
    [ThreadUtilities setAppkitThreadGroup:(*env)->NewGlobalRef(env, appkitThreadGroup)];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   697
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   698
    // Launcher sets this env variable if -XstartOnFirstThread is specified
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   699
    char envVar[80];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   700
    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   701
    if (getenv(envVar) != NULL) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   702
        forceEmbeddedMode = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   703
        unsetenv(envVar);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   704
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   705
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   706
    if (isSWTInWebStart(env)) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   707
        forceEmbeddedMode = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   708
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   709
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   710
    [AWTStarter start:headless ? YES : NO];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   711
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   712
    JNF_COCOA_EXIT(env)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   713
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   714
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   715
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   716
    OSXAPP_SetJavaVM(vm);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   717
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   718
    // We need to let Foundation know that this is a multithreaded application, if it isn't already.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   719
    if (![NSThread isMultiThreaded]) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   720
        [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   721
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   722
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   723
    return JNI_VERSION_1_4;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   724
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   725