author | ngthomas |
Tue, 15 Apr 2014 22:57:02 -0700 | |
changeset 24183 | db8b6b7d25c0 |
parent 24169 | 4efa892f600b |
parent 23921 | 1cb9d9ff4e61 |
child 24550 | cc2777fafab7 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18274
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#import <dlfcn.h> |
|
27 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
28 |
||
29 |
#include "jni_util.h" |
|
30 |
#import "CMenuBar.h" |
|
31 |
#import "InitIDs.h" |
|
32 |
#import "LWCToolkit.h" |
|
33 |
#import "ThreadUtilities.h" |
|
34 |
#import "AWT_debug.h" |
|
35 |
#import "CSystemColors.h" |
|
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
36 |
#import "NSApplicationAWT.h" |
12047 | 37 |
|
38 |
#import "sun_lwawt_macosx_LWCToolkit.h" |
|
39 |
||
18232 | 40 |
#import "sizecalc.h" |
41 |
||
12047 | 42 |
int gNumberOfButtons; |
43 |
jint* gButtonDownMasks; |
|
44 |
||
45 |
@implementation AWTToolkit |
|
46 |
||
47 |
static long eventCount; |
|
48 |
||
49 |
+ (long) getEventCount{ |
|
50 |
return eventCount; |
|
51 |
} |
|
52 |
||
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
53 |
+ (void) eventCountPlusPlus{ |
12047 | 54 |
eventCount++; |
55 |
} |
|
56 |
||
57 |
@end |
|
58 |
||
59 |
||
60 |
@interface AWTRunLoopObject : NSObject { |
|
61 |
BOOL _shouldEndRunLoop; |
|
62 |
} |
|
63 |
@end |
|
64 |
||
65 |
@implementation AWTRunLoopObject |
|
66 |
||
67 |
- (id) init { |
|
68 |
self = [super init]; |
|
69 |
if (self != nil) { |
|
70 |
_shouldEndRunLoop = NO; |
|
71 |
} |
|
72 |
return self; |
|
73 |
} |
|
74 |
||
75 |
- (BOOL) shouldEndRunLoop { |
|
76 |
return _shouldEndRunLoop; |
|
77 |
} |
|
78 |
||
79 |
- (void) endRunLoop { |
|
80 |
_shouldEndRunLoop = YES; |
|
81 |
} |
|
82 |
||
83 |
@end |
|
84 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
85 |
@interface JavaRunnable : NSObject { } |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
86 |
@property jobject runnable; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
87 |
- (id)initWithRunnable:(jobject)gRunnable; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
88 |
- (void)perform; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
89 |
@end |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
90 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
91 |
@implementation JavaRunnable |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
92 |
@synthesize runnable = _runnable; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
93 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
94 |
- (id)initWithRunnable:(jobject)gRunnable { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
95 |
if (self = [super init]) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
96 |
self.runnable = gRunnable; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
97 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
98 |
return self; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
99 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
100 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
101 |
- (void)dealloc { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
102 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
103 |
if (self.runnable) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
104 |
(*env)->DeleteGlobalRef(env, self.runnable); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
105 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
106 |
[super dealloc]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
107 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
108 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
109 |
- (void)perform { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
110 |
JNIEnv* env = [ThreadUtilities getJNIEnv]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
111 |
static JNF_CLASS_CACHE(sjc_Runnable, "java/lang/Runnable"); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
112 |
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
|
113 |
JNFCallVoidMethod(env, self.runnable, jm_Runnable_run); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
114 |
[self release]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
115 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
116 |
@end |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
117 |
|
12047 | 118 |
/* |
119 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
120 |
* Method: nativeSyncQueue |
|
121 |
* Signature: (J)Z |
|
122 |
*/ |
|
123 |
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue |
|
124 |
(JNIEnv *env, jobject self, jlong timeout) |
|
125 |
{ |
|
126 |
int currentEventNum = [AWTToolkit getEventCount]; |
|
127 |
||
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
128 |
NSApplication* sharedApp = [NSApplication sharedApplication]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
129 |
if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) { |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
130 |
NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
131 |
[theApp postDummyEvent]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
132 |
[theApp waitForDummyEvent]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
133 |
} else { |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
134 |
// 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
|
135 |
// 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
|
136 |
// 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
|
137 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}]; |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
138 |
} |
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
139 |
|
12047 | 140 |
if (([AWTToolkit getEventCount] - currentEventNum) != 0) { |
141 |
return JNI_TRUE; |
|
142 |
} |
|
13991
e62879b84a14
7124239: [macosx] sun.awt.SunToolkit.InfiniteLoop exception in realSync called from SwingTestHelper
leonidr
parents:
13004
diff
changeset
|
143 |
|
12047 | 144 |
return JNI_FALSE; |
145 |
} |
|
146 |
||
24169
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
147 |
/* |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
148 |
* Class: sun_lwawt_macosx_LWCToolkit |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
149 |
* Method: flushNativeSelectors |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
150 |
* Signature: ()J |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
151 |
*/ |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
152 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
153 |
(JNIEnv *env, jclass clz) |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
154 |
{ |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
155 |
JNF_COCOA_ENTER(env); |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
156 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){}]; |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
157 |
JNF_COCOA_EXIT(env); |
4efa892f600b
8038765: [macosx] Toolkit.sync should be implemented
serb
parents:
23681
diff
changeset
|
158 |
} |
12047 | 159 |
|
160 |
static JNF_CLASS_CACHE(jc_Component, "java/awt/Component"); |
|
161 |
static JNF_MEMBER_CACHE(jf_Component_appContext, jc_Component, "appContext", "Lsun/awt/AppContext;"); |
|
162 |
static JNF_CLASS_CACHE(jc_MenuComponent, "java/awt/MenuComponent"); |
|
163 |
static JNF_MEMBER_CACHE(jf_MenuComponent_appContext, jc_MenuComponent, "appContext", "Lsun/awt/AppContext;"); |
|
164 |
||
165 |
/* |
|
166 |
* Class: sun_awt_SunToolkit |
|
167 |
* Method: getAppContext |
|
168 |
* Signature: (Ljava/awt/Object;)Lsun/awt/AppContext; |
|
169 |
*/ |
|
170 |
JNIEXPORT jobject JNICALL |
|
171 |
Java_sun_awt_SunToolkit_getAppContext |
|
172 |
(JNIEnv *env, jclass cls, jobject obj) |
|
173 |
{ |
|
174 |
jobject appContext = NULL; |
|
175 |
||
176 |
JNF_COCOA_ENTER(env); |
|
177 |
||
178 |
if (JNFIsInstanceOf(env, obj, &jc_Component)) { |
|
179 |
appContext = JNFGetObjectField(env, obj, jf_Component_appContext); |
|
180 |
} else if (JNFIsInstanceOf(env, obj, &jc_MenuComponent)) { |
|
181 |
appContext = JNFGetObjectField(env, obj, jf_MenuComponent_appContext); |
|
182 |
} |
|
183 |
||
184 |
JNF_COCOA_EXIT(env); |
|
185 |
||
186 |
return appContext; |
|
187 |
} |
|
188 |
||
189 |
/* |
|
190 |
* Class: sun_awt_SunToolkit |
|
191 |
* Method: setAppContext |
|
192 |
* Signature: (Ljava/lang/Object;Lsun/awt/AppContext;)Z |
|
193 |
*/ |
|
194 |
JNIEXPORT jboolean JNICALL |
|
195 |
Java_sun_awt_SunToolkit_setAppContext |
|
196 |
(JNIEnv *env, jclass cls, jobject obj, jobject appContext) |
|
197 |
{ |
|
198 |
jboolean isComponent; |
|
199 |
||
200 |
JNF_COCOA_ENTER(env); |
|
201 |
||
202 |
if (JNFIsInstanceOf(env, obj, &jc_Component)) { |
|
203 |
JNFSetObjectField(env, obj, jf_Component_appContext, appContext); |
|
204 |
isComponent = JNI_TRUE; |
|
205 |
} else if (JNFIsInstanceOf(env, obj, &jc_MenuComponent)) { |
|
206 |
JNFSetObjectField(env, obj, jf_MenuComponent_appContext, appContext); |
|
207 |
isComponent = JNI_FALSE; |
|
208 |
} |
|
209 |
||
210 |
JNF_COCOA_EXIT(env); |
|
211 |
||
212 |
return isComponent; |
|
213 |
} |
|
214 |
||
215 |
/* |
|
216 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
217 |
* Method: beep |
|
218 |
* Signature: ()V |
|
219 |
*/ |
|
220 |
JNIEXPORT void JNICALL |
|
221 |
Java_sun_lwawt_macosx_LWCToolkit_beep |
|
222 |
(JNIEnv *env, jobject self) |
|
223 |
{ |
|
224 |
NSBeep(); // produces both sound and visual flash, if configured in System Preferences |
|
225 |
} |
|
226 |
||
227 |
/* |
|
228 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
229 |
* Method: initIDs |
|
230 |
* Signature: ()V |
|
231 |
*/ |
|
232 |
JNIEXPORT void JNICALL |
|
233 |
Java_sun_lwawt_macosx_LWCToolkit_initIDs |
|
234 |
(JNIEnv *env, jclass klass) { |
|
235 |
// set thread names |
|
23921
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
236 |
if (![ThreadUtilities isAWTEmbedded]) { |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
237 |
dispatch_async(dispatch_get_main_queue(), ^(void){ |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
238 |
[[NSThread currentThread] setName:@"AppKit Thread"]; |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
239 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
240 |
static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
241 |
static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
242 |
JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
243 |
}); |
1cb9d9ff4e61
8034870: Regression: On Mac, fx app can't be launched if setting a javaagent for it
pchelko
parents:
23893
diff
changeset
|
244 |
} |
23893 | 245 |
|
12047 | 246 |
gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS; |
247 |
||
248 |
jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent"); |
|
23301
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
249 |
CHECK_NULL(inputEventClazz); |
12047 | 250 |
jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I"); |
23301
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
251 |
CHECK_NULL(getButtonDownMasksID); |
12047 | 252 |
jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID); |
253 |
jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE); |
|
23301
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
254 |
CHECK_NULL(tmp); |
12047 | 255 |
|
18232 | 256 |
gButtonDownMasks = (jint*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), gNumberOfButtons); |
12047 | 257 |
if (gButtonDownMasks == NULL) { |
258 |
gNumberOfButtons = 0; |
|
23301
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
259 |
(*env)->ReleaseIntArrayElements(env, obj, tmp, JNI_ABORT); |
12047 | 260 |
JNU_ThrowOutOfMemoryError(env, NULL); |
261 |
return; |
|
262 |
} |
|
263 |
||
264 |
int i; |
|
265 |
for (i = 0; i < gNumberOfButtons; i++) { |
|
266 |
gButtonDownMasks[i] = tmp[i]; |
|
267 |
} |
|
268 |
||
269 |
(*env)->ReleaseIntArrayElements(env, obj, tmp, 0); |
|
270 |
(*env)->DeleteLocalRef(env, obj); |
|
271 |
} |
|
272 |
||
273 |
static UInt32 RGB(NSColor *c) { |
|
274 |
c = [c colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; |
|
275 |
if (c == nil) |
|
276 |
{ |
|
277 |
return -1; // opaque white |
|
278 |
} |
|
279 |
||
280 |
CGFloat r, g, b, a; |
|
281 |
[c getRed:&r green:&g blue:&b alpha:&a]; |
|
282 |
||
283 |
UInt32 ir = (UInt32) (r*255+0.5), |
|
284 |
ig = (UInt32) (g*255+0.5), |
|
285 |
ib = (UInt32) (b*255+0.5), |
|
286 |
ia = (UInt32) (a*255+0.5); |
|
287 |
||
288 |
// NSLog(@"%@ %d, %d, %d", c, ir, ig, ib); |
|
289 |
||
290 |
return ((ia & 0xFF) << 24) | ((ir & 0xFF) << 16) | ((ig & 0xFF) << 8) | ((ib & 0xFF) << 0); |
|
291 |
} |
|
292 |
||
23301
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
293 |
BOOL doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) { |
12047 | 294 |
jint len = (*env)->GetArrayLength(env, jColors); |
295 |
||
296 |
UInt32 colorsArray[len]; |
|
297 |
UInt32 *colors = colorsArray; |
|
298 |
||
299 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
300 |
NSUInteger i; |
|
301 |
for (i = 0; i < len; i++) { |
|
302 |
colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]); |
|
303 |
} |
|
304 |
}]; |
|
305 |
||
306 |
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
|
307 |
if (_colors == NULL) { |
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
308 |
return NO; |
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
309 |
} |
12047 | 310 |
memcpy(_colors, colors, len * sizeof(UInt32)); |
311 |
(*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
|
312 |
return YES; |
12047 | 313 |
} |
314 |
||
315 |
/** |
|
316 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
317 |
* Method: loadNativeColors |
|
318 |
* Signature: ([I[I)V |
|
319 |
*/ |
|
320 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors |
|
321 |
(JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors) |
|
322 |
{ |
|
323 |
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
|
324 |
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
|
325 |
doLoadNativeColors(env, jAppleColors, YES); |
618f7a6142c0
8034035: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/LWCToolkit.m
pchelko
parents:
18274
diff
changeset
|
326 |
} |
12047 | 327 |
JNF_COCOA_EXIT(env); |
328 |
} |
|
329 |
||
330 |
/* |
|
331 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
332 |
* Method: createAWTRunLoopMediator |
|
333 |
* Signature: ()J |
|
334 |
*/ |
|
335 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_LWCToolkit_createAWTRunLoopMediator |
|
336 |
(JNIEnv *env, jclass clz) |
|
337 |
{ |
|
338 |
AWT_ASSERT_APPKIT_THREAD; |
|
339 |
||
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
340 |
jlong result; |
12047 | 341 |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
342 |
JNF_COCOA_ENTER(env); |
12047 | 343 |
// We double retain because this object is owned by both main thread and "other" thread |
344 |
// 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
|
345 |
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
|
346 |
JNF_COCOA_EXIT(env); |
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
347 |
|
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
348 |
return result; |
12047 | 349 |
} |
350 |
||
351 |
/* |
|
352 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
17899 | 353 |
* Method: doAWTRunLoopImpl |
12047 | 354 |
* Signature: (JZZ)V |
355 |
*/ |
|
17899 | 356 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoopImpl |
357 |
(JNIEnv *env, jclass clz, jlong mediator, jboolean processEvents, jboolean inAWT) |
|
12047 | 358 |
{ |
359 |
AWT_ASSERT_APPKIT_THREAD; |
|
360 |
JNF_COCOA_ENTER(env); |
|
361 |
||
362 |
AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator); |
|
363 |
||
364 |
if (mediatorObject == nil) return; |
|
365 |
||
15985
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
366 |
// 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
|
367 |
BOOL isRunning = true; |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
368 |
while (![mediatorObject shouldEndRunLoop] && isRunning) { |
17899 | 369 |
isRunning = [[NSRunLoop currentRunLoop] runMode:(inAWT ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode) |
15985
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
370 |
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]]; |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
371 |
if (processEvents) { |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
372 |
//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
|
373 |
NSEvent *event; |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
374 |
if ((event = [NSApp nextEventMatchingMask:NSAnyEventMask |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
375 |
untilDate:nil |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
376 |
inMode:NSDefaultRunLoopMode |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
377 |
dequeue:YES]) != nil) { |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
378 |
[NSApp sendEvent:event]; |
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
379 |
} |
12047 | 380 |
|
381 |
} |
|
382 |
} |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
383 |
[mediatorObject release]; |
12047 | 384 |
JNF_COCOA_EXIT(env); |
385 |
} |
|
386 |
||
387 |
/* |
|
388 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
389 |
* Method: stopAWTRunLoop |
|
390 |
* Signature: (J)V |
|
391 |
*/ |
|
392 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop |
|
393 |
(JNIEnv *env, jclass clz, jlong mediator) |
|
394 |
{ |
|
395 |
JNF_COCOA_ENTER(env); |
|
396 |
||
397 |
AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator); |
|
398 |
||
15985
b9e25a486549
8006634: Unify LWCToolkit.invokeAndWait() and sun.awt.datatransfer.ToolkitThreadBlockedHandler
pchelko
parents:
15322
diff
changeset
|
399 |
[ThreadUtilities performOnMainThread:@selector(endRunLoop) on:mediatorObject withObject:nil waitUntilDone:NO]; |
12047 | 400 |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23328
diff
changeset
|
401 |
[mediatorObject release]; |
12047 | 402 |
|
403 |
JNF_COCOA_EXIT(env); |
|
404 |
} |
|
405 |
||
406 |
/* |
|
407 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
408 |
* Method: performOnMainThreadAfterDelay |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
409 |
* Signature: (Ljava/lang/Runnable;J)V |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
410 |
*/ |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
411 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_performOnMainThreadAfterDelay |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
412 |
(JNIEnv *env, jclass clz, jobject runnable, jlong delay) |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
413 |
{ |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
414 |
JNF_COCOA_ENTER(env); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
415 |
jobject gRunnable = (*env)->NewGlobalRef(env, runnable); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
416 |
CHECK_NULL(gRunnable); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
417 |
[ThreadUtilities performOnMainThreadWaiting:NO block:^() { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
418 |
JavaRunnable* performer = [[JavaRunnable alloc] initWithRunnable:gRunnable]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
419 |
[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
|
420 |
}]; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
421 |
JNF_COCOA_EXIT(env); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
422 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
423 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
424 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
425 |
/* |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23651
diff
changeset
|
426 |
* Class: sun_lwawt_macosx_LWCToolkit |
12047 | 427 |
* Method: isCapsLockOn |
428 |
* Signature: ()Z |
|
429 |
*/ |
|
430 |
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isCapsLockOn |
|
431 |
(JNIEnv *env, jobject self) |
|
432 |
{ |
|
433 |
__block jboolean isOn = JNI_FALSE; |
|
434 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
435 |
NSUInteger modifiers = [NSEvent modifierFlags]; |
|
436 |
isOn = (modifiers & NSAlphaShiftKeyMask) != 0; |
|
437 |
}]; |
|
438 |
||
439 |
return isOn; |
|
440 |
} |
|
441 |
||
442 |
/* |
|
443 |
* Class: sun_lwawt_macosx_LWCToolkit |
|
444 |
* Method: isApplicationActive |
|
445 |
* Signature: ()Z |
|
446 |
*/ |
|
447 |
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_isApplicationActive |
|
448 |
(JNIEnv *env, jclass clazz) |
|
449 |
{ |
|
12177
7b84ed7d0efa
7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents:
12047
diff
changeset
|
450 |
__block jboolean active = JNI_FALSE; |
12047 | 451 |
|
452 |
JNF_COCOA_ENTER(env); |
|
453 |
||
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
13991
diff
changeset
|
454 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^() { |
12177
7b84ed7d0efa
7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents:
12047
diff
changeset
|
455 |
active = (jboolean)[NSRunningApplication currentApplication].active; |
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
13991
diff
changeset
|
456 |
}]; |
12047 | 457 |
|
458 |
JNF_COCOA_EXIT(env); |
|
459 |
||
12177
7b84ed7d0efa
7150349: [macosx] Applets attempting to show popup menus activate the applet process
dcherepanov
parents:
12047
diff
changeset
|
460 |
return active; |
12047 | 461 |
} |
462 |
||
463 |
||
464 |
/* |
|
465 |
* Class: sun_awt_SunToolkit |
|
466 |
* Method: closeSplashScreen |
|
467 |
* Signature: ()V |
|
468 |
*/ |
|
469 |
JNIEXPORT void JNICALL |
|
470 |
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls) |
|
471 |
{ |
|
472 |
void *hSplashLib = dlopen(0, RTLD_LAZY); |
|
473 |
if (!hSplashLib) return; |
|
474 |
||
475 |
void (*splashClose)() = dlsym(hSplashLib, "SplashClose"); |
|
476 |
if (splashClose) { |
|
477 |
splashClose(); |
|
478 |
} |
|
479 |
dlclose(hSplashLib); |
|
480 |
} |
|
481 |
||
482 |
||
483 |
// TODO: definitely doesn't belong here (copied from fontpath.c in the |
|
484 |
// solaris tree)... |
|
485 |
||
486 |
JNIEXPORT jstring JNICALL |
|
487 |
Java_sun_font_FontManager_getFontPath |
|
488 |
(JNIEnv *env, jclass obj, jboolean noType1) |
|
489 |
{ |
|
490 |
return JNFNSToJavaString(env, @"/Library/Fonts"); |
|
491 |
} |
|
492 |
||
493 |
// This isn't yet used on unix, the implementation is added since shared |
|
494 |
// code calls this method in preparation for future use. |
|
495 |
JNIEXPORT void JNICALL |
|
496 |
Java_sun_font_FontManager_populateFontFileNameMap |
|
497 |
(JNIEnv *env, jclass obj, jobject fontToFileMap, jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale) |
|
498 |
{ |
|
499 |
||
500 |
} |