jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m
author prr
Fri, 19 Sep 2014 09:41:05 -0700
changeset 26751 70bac69b37c9
parent 25859 jdk/src/java.desktop/macosx/native/libawt_lwawt/sun/awt/LWCToolkit.m@3317bb8137f4
child 27272 cffe6690ee9d
permissions -rw-r--r--
8056216: Remove "sun" directory layer from libawt and common Reviewed-by: erikj, ihse, coffeys
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
25564
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
    58
// Indicates if awt toolkit is embedded into another UI toolkit
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
    59
static BOOL isEmbedded = NO;
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
    60
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    61
// 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
    62
static BOOL sAppKitStarted = NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    63
static pthread_mutex_t sAppKitStarted_mutex = PTHREAD_MUTEX_INITIALIZER;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    64
static pthread_cond_t sAppKitStarted_cv = PTHREAD_COND_INITIALIZER;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
    65
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
@implementation AWTToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
static long 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
+ (long) getEventCount{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    return eventCount;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
    74
+ (void) eventCountPlusPlus{    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    eventCount++;
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
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
@interface AWTRunLoopObject : NSObject {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    BOOL _shouldEndRunLoop;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
@implementation AWTRunLoopObject
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
- (id) init {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    self = [super init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    if (self != nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
        _shouldEndRunLoop = NO;
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
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
}
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
- (BOOL) shouldEndRunLoop {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    return _shouldEndRunLoop;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
}
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
- (void) endRunLoop {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    _shouldEndRunLoop = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
23681
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   106
@interface JavaRunnable : NSObject { }
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   107
@property jobject runnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   108
- (id)initWithRunnable:(jobject)gRunnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   109
- (void)perform;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   110
@end
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
@implementation JavaRunnable
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   113
@synthesize runnable = _runnable;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   114
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   115
- (id)initWithRunnable:(jobject)gRunnable {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   116
    if (self = [super init]) {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   117
        self.runnable = gRunnable;
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
    return self;
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   120
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   121
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   122
- (void)dealloc {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   123
    JNIEnv *env = [ThreadUtilities getJNIEnv];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   124
    if (self.runnable) {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   125
        (*env)->DeleteGlobalRef(env, self.runnable);
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
    [super dealloc];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   128
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   129
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   130
- (void)perform {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   131
    JNIEnv* env = [ThreadUtilities getJNIEnv];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   132
    static JNF_CLASS_CACHE(sjc_Runnable, "java/lang/Runnable");
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   133
    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
   134
    JNFCallVoidMethod(env, self.runnable, jm_Runnable_run);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   135
    [self release];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   136
}
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   137
@end
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   138
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   139
void setBusy(BOOL busy) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   140
    AWT_ASSERT_APPKIT_THREAD;
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
    JNIEnv *env = [ThreadUtilities getJNIEnv];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   143
    static JNF_CLASS_CACHE(jc_AWTAutoShutdown, "sun/awt/AWTAutoShutdown");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   144
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   145
    if (busy) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   146
        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
   147
        JNFCallStaticVoidMethod(env, jm_notifyBusyMethod);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   148
    } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   149
        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
   150
        JNFCallStaticVoidMethod(env, jm_notifyFreeMethod);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   151
    }
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
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   154
static void setUpAWTAppKit(BOOL installObservers)
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
    if (installObservers) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   157
        AWT_STARTUP_LOG(@"Setting up busy observers");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   158
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   159
        // 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
   160
        //  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
   161
        //  will not automatically shutdown.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   162
        CFRunLoopObserverRef busyObserver = CFRunLoopObserverCreateWithHandler(
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   163
                                               NULL,                        // CFAllocator
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   164
                                               kCFRunLoopAfterWaiting,      // CFOptionFlags
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   165
                                               true,                        // repeats
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   166
                                               NSIntegerMax,                // order
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   167
                                               ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   168
                                                   setBusy(YES);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   169
                                               });
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   170
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   171
        CFRunLoopObserverRef notBusyObserver = CFRunLoopObserverCreateWithHandler(
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   172
                                                NULL,                        // CFAllocator
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   173
                                                kCFRunLoopBeforeWaiting,     // CFOptionFlags
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   174
                                                true,                        // repeats
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   175
                                                NSIntegerMin,                // order
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   176
                                                ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   177
                                                    setBusy(NO);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   178
                                                });
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   179
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   180
        CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   181
        CFRunLoopAddObserver(runLoop, busyObserver, kCFRunLoopDefaultMode);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   182
        CFRunLoopAddObserver(runLoop, notBusyObserver, kCFRunLoopDefaultMode);
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
        CFRelease(busyObserver);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   185
        CFRelease(notBusyObserver);
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
        setBusy(YES);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   188
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   189
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   190
    JNIEnv* env = [ThreadUtilities getJNIEnv];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   191
    static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   192
    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
   193
    JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   194
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   195
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   196
BOOL isSWTInWebStart(JNIEnv* env) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   197
    NSString *swtWebStart = [PropertiesUtilities javaSystemPropertyForKey:@"com.apple.javaws.usingSWT" withEnv:env];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   198
    return [@"true" isCaseInsensitiveLike:swtWebStart];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   199
}
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
static void AWT_NSUncaughtExceptionHandler(NSException *exception) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   202
    NSLog(@"Apple AWT Internal Exception: %@", [exception description]);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   203
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   204
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   205
@interface AWTStarter : NSObject
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   206
+ (void)start:(BOOL)headless;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   207
+ (void)starter:(BOOL)onMainThread headless:(BOOL)headless;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   208
+ (void)appKitIsRunning:(id)arg;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   209
@end
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   210
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   211
@implementation AWTStarter
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   212
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   213
+ (BOOL) isConnectedToWindowServer {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   214
    SecuritySessionId session_id;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   215
    SessionAttributeBits session_info;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   216
    OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   217
    if (status != noErr) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   218
    if (!(session_info & sessionHasGraphicAccess)) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   219
    return YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   220
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   221
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   222
+ (BOOL) markAppAsDaemon {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   223
    id jrsAppKitAWTClass = objc_getClass("JRSAppKitAWT");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   224
    SEL markAppSel = @selector(markAppIsDaemon);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   225
    if (![jrsAppKitAWTClass respondsToSelector:markAppSel]) return NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   226
    return [jrsAppKitAWTClass performSelector:markAppSel] ? YES : NO;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   227
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   228
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   229
+ (void)appKitIsRunning:(id)arg {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   230
    AWT_ASSERT_APPKIT_THREAD;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   231
    AWT_STARTUP_LOG(@"About to message AppKit started");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   232
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   233
    // Signal that AppKit has started (or is already running).
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   234
    pthread_mutex_lock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   235
    sAppKitStarted = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   236
    pthread_cond_signal(&sAppKitStarted_cv);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   237
    pthread_mutex_unlock(&sAppKitStarted_mutex);
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
    AWT_STARTUP_LOG(@"Finished messaging AppKit started");
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
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   242
+ (void)start:(BOOL)headless
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   243
{
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   244
    // onMainThread is NOT the same at SWT mode!
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   245
    // 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
   246
    // 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
   247
    // need to throw AWT startup over to another thread.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   248
    BOOL onMainThread = [NSThread isMainThread];
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
    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
   251
    AWT_STARTUP_LOG(msg);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   252
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   253
    if (!headless)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   254
    {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   255
        // 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
   256
        //  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
   257
        //  the AppKit lock before the +[NSApplication sharedApplication] returns.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   258
        //  See <rdar://problem/3492666> for an example.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   259
        [[NSNotificationCenter defaultCenter] addObserver:[AWTStarter class]
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   260
                                                 selector:@selector(appKitIsRunning:)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   261
                                                     name:NSApplicationDidFinishLaunchingNotification
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   262
                                                   object:nil];
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
        AWT_STARTUP_LOG(@"+[AWTStarter start:::]: registered NSApplicationDidFinishLaunchingNotification");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   265
    }
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
    [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   268
        [AWTStarter starter:onMainThread headless:headless];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   269
    }];
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
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   272
    if (!headless && !onMainThread) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   273
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   274
        AWT_STARTUP_LOG(@"about to wait on AppKit startup mutex");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   275
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   276
        // 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
   277
        //  an already running NSApplication).
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   278
        pthread_mutex_lock(&sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   279
        while (sAppKitStarted == NO) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   280
            pthread_cond_wait(&sAppKitStarted_cv, &sAppKitStarted_mutex);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   281
        }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   282
        pthread_mutex_unlock(&sAppKitStarted_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
        // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   285
        AWT_STARTUP_LOG(@"got out of the AppKit startup mutex");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   286
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   287
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   288
    if (!headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   289
        // 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
   290
        // its finishLaunching has initialized it.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   291
        //  ApplicationDelegate is the support code for com.apple.eawt.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   292
        [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   293
            id<NSApplicationDelegate> delegate = [ApplicationDelegate sharedDelegate];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   294
            if (delegate != nil) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   295
                OSXAPP_SetApplicationDelegate(delegate);
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
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   299
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   300
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   301
+ (void)starter:(BOOL)wasOnMainThread headless:(BOOL)headless {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   302
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   303
    // Add the exception handler of last resort
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   304
    NSSetUncaughtExceptionHandler(AWT_NSUncaughtExceptionHandler);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   305
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   306
    // 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
   307
    if (headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   308
        // 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
   309
        // because we don't need them (see 7174704)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   310
        if (!forceEmbeddedMode) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   311
            setUpAWTAppKit(false);
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
        [AWTStarter markAppAsDaemon];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   314
        return;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   315
    }
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
    if (forceEmbeddedMode) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   318
        AWT_STARTUP_LOG(@"in SWT or SWT/WebStart mode");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   319
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   320
        // Init a default NSApplication instance instead of the NSApplicationAWT.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   321
        // Note that [NSApp isRunning] will return YES after that, though
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   322
        // this behavior isn't specified anywhere. We rely on that.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   323
        NSApplicationLoad();
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   324
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   325
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   326
    // 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
   327
    //  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
   328
    //  and -[NSApplication isRunning] returns YES, AWT is embedded inside another
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   329
    //  AppKit Application.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   330
    NSApplication *app = [NSApplicationAWT sharedApplication];
25564
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   331
    isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]];
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   332
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   333
    if (!isEmbedded) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   334
        // 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
   335
        setUpAWTAppKit(true);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   336
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   337
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   338
    // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   339
    if (![app isRunning]) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   340
        AWT_STARTUP_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   341
        // 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
   342
        [NSApplicationAWT runAWTLoopWithApp: app];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   343
    } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   344
        // We're either embedded, or showing a splash screen
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   345
        if (isEmbedded) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   346
            AWT_STARTUP_LOG(@"running embedded");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   347
            
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   348
            // 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
   349
            setBusy(NO);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   350
        } else {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   351
            AWT_STARTUP_LOG(@"running after showing a splash screen");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   352
        }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   353
        
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   354
        // Signal so that JNI_OnLoad can proceed.
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   355
        if (!wasOnMainThread) [AWTStarter appKitIsRunning:nil];
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
        // 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
   358
    }
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
    [pool drain];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   361
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   362
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   363
@end
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   364
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
 * Method:    nativeSyncQueue
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
 * Signature: (J)Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
(JNIEnv *env, jobject self, jlong timeout)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    int currentEventNum = [AWTToolkit getEventCount];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   375
    NSApplication* sharedApp = [NSApplication sharedApplication];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   376
    if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) {
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   377
        NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp;
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   378
        [theApp postDummyEvent];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   379
        [theApp waitForDummyEvent];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   380
    } else {
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   381
        // 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
   382
        // 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
   383
        // 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
   384
        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}];
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   385
    }
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   386
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    if (([AWTToolkit getEventCount] - currentEventNum) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
        return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
    }
13991
e62879b84a14 7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents: 13004
diff changeset
   390
        
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
24169
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   394
/*
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   395
 * Class:     sun_lwawt_macosx_LWCToolkit
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   396
 * Method:    flushNativeSelectors
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   397
 * Signature: ()J
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   398
 */
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   399
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   400
(JNIEnv *env, jclass clz)
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   401
{
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   402
JNF_COCOA_ENTER(env);
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   403
        [ThreadUtilities performOnMainThreadWaiting:YES block:^(){}];
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   404
JNF_COCOA_EXIT(env);
4efa892f600b 8038765: [macosx] Toolkit.sync should be implemented
serb
parents: 23681
diff changeset
   405
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
 * Method:    beep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
 * Signature: ()V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
Java_sun_lwawt_macosx_LWCToolkit_beep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
(JNIEnv *env, jobject self)
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
    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
   417
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
static UInt32 RGB(NSColor *c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    c = [c colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
    if (c == nil)
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
        return -1; // opaque white
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
    CGFloat r, g, b, a;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    [c getRed:&r green:&g blue:&b alpha:&a];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
    UInt32 ir = (UInt32) (r*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
    ig = (UInt32) (g*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
    ib = (UInt32) (b*255+0.5),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
    ia = (UInt32) (a*255+0.5);
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
    //    NSLog(@"%@ %d, %d, %d", c, ir, ig, ib);
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
    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
   437
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
23301
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   439
BOOL doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
    jint len = (*env)->GetArrayLength(env, jColors);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
    UInt32 colorsArray[len];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
    UInt32 *colors = colorsArray;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
        NSUInteger i;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
        for (i = 0; i < len; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
            colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]);
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
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
    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
   453
    if (_colors == NULL) {
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   454
        return NO;
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   455
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
    memcpy(_colors, colors, len * sizeof(UInt32));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
    (*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
   458
    return YES;
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
/**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
 * Method:    loadNativeColors
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
 * Signature: ([I[I)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
(JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
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
   470
    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
   471
        doLoadNativeColors(env, jAppleColors, YES);
618f7a6142c0 8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents: 18274
diff changeset
   472
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
JNF_COCOA_EXIT(env);
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
 * Method:    createAWTRunLoopMediator
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
 * Signature: ()J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_LWCToolkit_createAWTRunLoopMediator
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
(JNIEnv *env, jclass clz)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
AWT_ASSERT_APPKIT_THREAD;
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
    jlong result;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   488
JNF_COCOA_ENTER(env);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
    // 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
   490
    // 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
   491
    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
   492
JNF_COCOA_EXIT(env);
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   493
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   494
    return result;
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
 * Class:     sun_lwawt_macosx_LWCToolkit
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   499
 * Method:    doAWTRunLoopImpl
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
 * Signature: (JZZ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
 */
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   502
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoopImpl
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   503
(JNIEnv *env, jclass clz, jlong mediator, jboolean processEvents, jboolean inAWT)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
JNF_COCOA_ENTER(env);
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
    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
    if (mediatorObject == nil) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   512
    // 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
   513
    BOOL isRunning = true;
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   514
    while (![mediatorObject shouldEndRunLoop] && isRunning) {
17899
d3a864bdee7d 8015477: Support single threaded AWT/FX mode.
pchelko
parents: 15988
diff changeset
   515
        isRunning = [[NSRunLoop currentRunLoop] runMode:(inAWT ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode)
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   516
                                             beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]];
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   517
        if (processEvents) {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   518
            //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
   519
            NSEvent *event;
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   520
            if ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   521
                                           untilDate:nil
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   522
                                              inMode:NSDefaultRunLoopMode
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   523
                                             dequeue:YES]) != nil) {
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   524
                [NSApp sendEvent:event];
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   525
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
    }
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   529
    [mediatorObject release];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
JNF_COCOA_EXIT(env);
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
 * Method:    stopAWTRunLoop
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
 * Signature: (J)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
(JNIEnv *env, jclass clz, jlong mediator)
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
    AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
15985
b9e25a486549 8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents: 15322
diff changeset
   545
    [ThreadUtilities performOnMainThread:@selector(endRunLoop) on:mediatorObject withObject:nil waitUntilDone:NO];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23328
diff changeset
   547
    [mediatorObject release];
12047
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
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
 * Class:     sun_lwawt_macosx_LWCToolkit
23681
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   554
 * Method:    performOnMainThreadAfterDelay
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   555
 * Signature: (Ljava/lang/Runnable;J)V
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   556
 */
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   557
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_performOnMainThreadAfterDelay
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   558
(JNIEnv *env, jclass clz, jobject runnable, jlong delay)
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   559
{
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   560
JNF_COCOA_ENTER(env);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   561
    jobject gRunnable = (*env)->NewGlobalRef(env, runnable);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   562
    CHECK_NULL(gRunnable);
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   563
    [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   564
        JavaRunnable* performer = [[JavaRunnable alloc] initWithRunnable:gRunnable];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   565
        [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
   566
    }];
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   567
JNF_COCOA_EXIT(env);
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
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   571
/*
2044c9d2b681 8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents: 23651
diff changeset
   572
 * Class:     sun_lwawt_macosx_LWCToolkit
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
 * Method:    isCapsLockOn
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
 * Signature: ()Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
(JNIEnv *env, jobject self)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   579
    __block jboolean isOn = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   580
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
        NSUInteger modifiers = [NSEvent modifierFlags];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
        isOn = (modifiers & NSAlphaShiftKeyMask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
    }];
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
    return isOn;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
 * Class:     sun_lwawt_macosx_LWCToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
 * Method:    isApplicationActive
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
 * Signature: ()Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isApplicationActive
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   594
(JNIEnv *env, jclass clazz)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
{
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   596
    __block jboolean active = JNI_FALSE;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   598
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 13991
diff changeset
   600
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   601
        active = (jboolean)[NSRunningApplication currentApplication].active;
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 13991
diff changeset
   602
    }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
12177
7b84ed7d0efa 7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents: 12047
diff changeset
   606
    return active;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
 * Class:     sun_awt_SunToolkit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
 * Method:    closeSplashScreen
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
 * Signature: ()V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
    void *hSplashLib = dlopen(0, RTLD_LAZY);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
    if (!hSplashLib) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
    void (*splashClose)() = dlsym(hSplashLib, "SplashClose");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
    if (splashClose) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
        splashClose();
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
    dlclose(hSplashLib);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
// 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
   630
// solaris tree)...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
JNIEXPORT jstring JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
Java_sun_font_FontManager_getFontPath
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
(JNIEnv *env, jclass obj, jboolean noType1)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
    return JNFNSToJavaString(env, @"/Library/Fonts");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
// 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
   640
// code calls this method in preparation for future use.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
Java_sun_font_FontManager_populateFontFileNameMap
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
(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
   644
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
}
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   647
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   648
/*
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   649
 * Class:     sun_lwawt_macosx_LWCToolkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   650
 * Method:    initIDs
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   651
 * Signature: ()V
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   652
 */
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   653
JNIEXPORT void JNICALL
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   654
Java_sun_lwawt_macosx_LWCToolkit_initIDs
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   655
(JNIEnv *env, jclass klass) {
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
    JNF_COCOA_ENTER(env)
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
    gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   660
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   661
    jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   662
    CHECK_NULL(inputEventClazz);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   663
    jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   664
    CHECK_NULL(getButtonDownMasksID);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   665
    jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   666
    jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   667
    CHECK_NULL(tmp);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   668
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   669
    gButtonDownMasks = (jint*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), gNumberOfButtons);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   670
    if (gButtonDownMasks == NULL) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   671
        gNumberOfButtons = 0;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   672
        (*env)->ReleaseIntArrayElements(env, obj, tmp, JNI_ABORT);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   673
        JNU_ThrowOutOfMemoryError(env, NULL);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   674
        return;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   675
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   676
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   677
    int i;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   678
    for (i = 0; i < gNumberOfButtons; i++) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   679
        gButtonDownMasks[i] = tmp[i];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   680
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   681
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   682
    (*env)->ReleaseIntArrayElements(env, obj, tmp, 0);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   683
    (*env)->DeleteLocalRef(env, obj);
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
    JNF_COCOA_EXIT(env)
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
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   688
/*
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   689
 * Class:     sun_lwawt_macosx_LWCToolkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   690
 * Method:    initAppkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   691
 * Signature: (Ljava/lang/ThreadGroup;)V
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   692
 */
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   693
JNIEXPORT void JNICALL
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   694
Java_sun_lwawt_macosx_LWCToolkit_initAppkit
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   695
(JNIEnv *env, jclass klass, jobject appkitThreadGroup, jboolean headless) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   696
    JNF_COCOA_ENTER(env)
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
    [ThreadUtilities setAppkitThreadGroup:(*env)->NewGlobalRef(env, appkitThreadGroup)];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   699
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   700
    // Launcher sets this env variable if -XstartOnFirstThread is specified
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   701
    char envVar[80];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   702
    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
   703
    if (getenv(envVar) != NULL) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   704
        forceEmbeddedMode = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   705
        unsetenv(envVar);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   706
    }
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   707
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   708
    if (isSWTInWebStart(env)) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   709
        forceEmbeddedMode = YES;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   710
    }
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
    [AWTStarter start:headless ? YES : NO];
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
    JNF_COCOA_EXIT(env)
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   715
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   716
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   717
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   718
    OSXAPP_SetJavaVM(vm);
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   719
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   720
    // 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
   721
    if (![NSThread isMultiThreaded]) {
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   722
        [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil];
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   723
    }
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
    return JNI_VERSION_1_4;
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   726
}
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 24550
diff changeset
   727
25564
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   728
/*
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   729
 * Class:     sun_lwawt_macosx_LWCToolkit
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   730
 * Method:    isEmbedded
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   731
 * Signature: ()Z
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   732
 */
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   733
JNIEXPORT jboolean JNICALL
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   734
Java_sun_lwawt_macosx_LWCToolkit_isEmbedded
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   735
(JNIEnv *env, jclass klass) {
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   736
    return isEmbedded ? JNI_TRUE : JNI_FALSE;
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   737
}
871d3490f14d 8048549: [macosx] Disable usage of system menu bar if AWT is embedded in FX
pchelko
parents: 25563
diff changeset
   738