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 <Cocoa/Cocoa.h>
27 #import <JavaNativeFoundation/JavaNativeFoundation.h>
28
29 static NSWindow *testWindow;
30 static NSColorPanel *colorPanel;
31
32 /*
33 * Class: TestMainKeyWindow
34 * Method: setup
35 * Signature: ()V
36 */
37 JNIEXPORT void JNICALL Java_TestMainKeyWindow_setup(JNIEnv *env, jclass cl)
38 {
39 JNF_COCOA_ENTER(env);
40
41 void (^block)() = ^(){
42 NSScreen *mainScreen = [NSScreen mainScreen];
43 NSRect screenFrame = [mainScreen frame];
44 NSRect frame = NSMakeRect(130, screenFrame.size.height - 280, 200, 100);
45
46 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
47 NSWindowStyleMask style = NSWindowStyleMaskTitled;
48 #else
49 NSInteger style = NSTitledWindowMask;
50 #endif
51
52 NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:style];
53 NSBackingStoreType bt = NSBackingStoreBuffered;
54 testWindow = [[[NSWindow alloc] initWithContentRect:rect styleMask:style backing:bt defer:NO] retain];
55 testWindow.title = @"NSWindow";
56 [testWindow setBackgroundColor:[NSColor blueColor]];
57 [testWindow makeKeyAndOrderFront:nil];
58 // Java coordinates are 100, 200
59
60 colorPanel = [[NSColorPanel sharedColorPanel] retain];
61 [colorPanel setReleasedWhenClosed: YES];
62 colorPanel.restorable = NO;
63 [colorPanel setFrameTopLeftPoint: NSMakePoint(130, screenFrame.size.height - 300)];
64 // Java coordinates are 100, 400
65 [colorPanel makeKeyAndOrderFront: nil];
66 };
67
68 if ([NSThread isMainThread]) {
69 block();
70 } else {
71 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
72 }
73
74 JNF_COCOA_EXIT(env);
75 }
76
77 /*
78 * Class: TestMainKeyWindow
79 * Method: takedown
80 * Signature: ()V
81 */
82 JNIEXPORT void JNICALL Java_TestMainKeyWindow_takedown(JNIEnv *env, jclass cl)
83 {
84 JNF_COCOA_ENTER(env);
85
86 void (^block)() = ^(){
87 if (testWindow != nil) {
88 [testWindow close];
89 testWindow = nil;
90 }
91 if (colorPanel != nil) {
92 [colorPanel orderOut:nil];
93 colorPanel = nil;
94 }
95 };
96
97 if ([NSThread isMainThread]) {
98 block();
99 } else {
100 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
101 }
102
103 JNF_COCOA_EXIT(env);
104 }
105
106 /*
107 * Class: TestMainKeyWindow
108 * Method: activateApplication
109 * Signature: ()V
110 */
111 JNIEXPORT void JNICALL Java_TestMainKeyWindow_activateApplication
112 (JNIEnv *env, jclass cl)
113 {
114 JNF_COCOA_ENTER(env);
115
116 void (^block)() = ^(){
117 [NSApp activateIgnoringOtherApps:YES];
118 };
119
120 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block];
121
122 JNF_COCOA_EXIT(env);
123 }
|
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 <Cocoa/Cocoa.h>
27 #import <jni_util.h>
28
29 static NSWindow *testWindow;
30 static NSColorPanel *colorPanel;
31
32 #define JNI_COCOA_ENTER(env) \
33 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
34 @try {
35
36 #define JNI_COCOA_EXIT(env) \
37 } \
38 @catch (NSException *e) { \
39 NSLog(@"%@", [e callStackSymbols]); \
40 } \
41 @finally { \
42 [pool drain]; \
43 };
44
45 /*
46 * Pass the block to a selector of a class that extends NSObject
47 * There is no need to copy the block since this class always waits.
48 */
49 @interface BlockRunner : NSObject { }
50
51 + (void)invokeBlock:(void (^)())block;
52 @end
53
54 @implementation BlockRunner
55
56 + (void)invokeBlock:(void (^)())block{
57 block();
58 }
59
60 + (void)performBlock:(void (^)())block {
61 [self performSelectorOnMainThread:@selector(invokeBlock:) withObject:block waitUntilDone:YES];
62 }
63
64 @end
65
66 /*
67 * Class: TestMainKeyWindow
68 * Method: setup
69 * Signature: ()V
70 */
71 JNIEXPORT void JNICALL Java_TestMainKeyWindow_setup(JNIEnv *env, jclass cl)
72 {
73 JNI_COCOA_ENTER(env);
74
75 void (^block)() = ^(){
76 NSScreen *mainScreen = [NSScreen mainScreen];
77 NSRect screenFrame = [mainScreen frame];
78 NSRect frame = NSMakeRect(130, screenFrame.size.height - 280, 200, 100);
79
80 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
81 NSWindowStyleMask style = NSWindowStyleMaskTitled;
82 #else
83 NSInteger style = NSTitledWindowMask;
84 #endif
85
86 NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:style];
87 NSBackingStoreType bt = NSBackingStoreBuffered;
88 testWindow = [[[NSWindow alloc] initWithContentRect:rect styleMask:style backing:bt defer:NO] retain];
89 testWindow.title = @"NSWindow";
90 [testWindow setBackgroundColor:[NSColor blueColor]];
91 [testWindow makeKeyAndOrderFront:nil];
92 // Java coordinates are 100, 200
93
94 colorPanel = [[NSColorPanel sharedColorPanel] retain];
95 [colorPanel setReleasedWhenClosed: YES];
96 colorPanel.restorable = NO;
97 [colorPanel setFrameTopLeftPoint: NSMakePoint(130, screenFrame.size.height - 300)];
98 // Java coordinates are 100, 400
99 [colorPanel makeKeyAndOrderFront: nil];
100 };
101
102 if ([NSThread isMainThread]) {
103 block();
104 } else {
105 [BlockRunner performBlock:block];
106 }
107
108 JNI_COCOA_EXIT(env);
109 }
110
111 /*
112 * Class: TestMainKeyWindow
113 * Method: takedown
114 * Signature: ()V
115 */
116 JNIEXPORT void JNICALL Java_TestMainKeyWindow_takedown(JNIEnv *env, jclass cl)
117 {
118 JNI_COCOA_ENTER(env);
119
120 void (^block)() = ^(){
121 if (testWindow != nil) {
122 [testWindow close];
123 testWindow = nil;
124 }
125 if (colorPanel != nil) {
126 [colorPanel orderOut:nil];
127 colorPanel = nil;
128 }
129 };
130
131 if ([NSThread isMainThread]) {
132 block();
133 } else {
134 [BlockRunner performBlock:block];
135 }
136
137 JNI_COCOA_EXIT(env);
138 }
139
140 /*
141 * Class: TestMainKeyWindow
142 * Method: activateApplication
143 * Signature: ()V
144 */
145 JNIEXPORT void JNICALL Java_TestMainKeyWindow_activateApplication
146 (JNIEnv *env, jclass cl)
147 {
148 JNI_COCOA_ENTER(env);
149
150 void (^block)() = ^(){
151 [NSApp activateIgnoringOtherApps:YES];
152 };
153
154 [BlockRunner performBlock:block];
155
156 JNI_COCOA_EXIT(env);
157 }
|