1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   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 "CWrapper.h"
  27 
  28 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  29 
  30 #import "AWTWindow.h"
  31 #import "LWCToolkit.h"
  32 #import "GeomUtilities.h"
  33 #import "ThreadUtilities.h"
  34 
  35 #import "sun_lwawt_macosx_CWrapper_NSWindow.h"
  36 
  37 /*
  38  * Class:     sun_lwawt_macosx_CWrapper$NSObject
  39  * Method:    release
  40  * Signature: (J)V
  41  */
  42 JNIEXPORT void JNICALL
  43 Java_sun_lwawt_macosx_CWrapper_00024NSObject_release
  44 (JNIEnv *env, jclass cls, jlong objectPtr)
  45 {
  46 JNF_COCOA_ENTER(env);
  47 
  48     id obj = (id)jlong_to_ptr(objectPtr);
  49     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
  50         CFRelease(obj);
  51     }];
  52 
  53 JNF_COCOA_EXIT(env);
  54 }
  55 
  56 
  57 /*
  58  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
  59  * Method:    makeKeyAndOrderFront
  60  * Signature: (J)V
  61  */
  62 JNIEXPORT void JNICALL
  63 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeKeyAndOrderFront
  64 (JNIEnv *env, jclass cls, jlong windowPtr)
  65 {
  66 JNF_COCOA_ENTER(env);
  67 
  68     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
  69     [JNFRunLoop performOnMainThread:@selector(makeKeyAndOrderFront:)
  70                                  on:window
  71                          withObject:nil
  72                       waitUntilDone:NO];
  73 
  74 JNF_COCOA_EXIT(env);
  75 }
  76 
  77 /*
  78  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
  79  * Method:    makeMainWindow
  80  * Signature: (J)V
  81  */
  82 JNIEXPORT void JNICALL
  83 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeMainWindow
  84 (JNIEnv *env, jclass cls, jlong windowPtr)
  85 {
  86 JNF_COCOA_ENTER(env);
  87 
  88     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
  89     [JNFRunLoop performOnMainThread:@selector(makeMainWindow)
  90                                  on:window
  91                          withObject:nil
  92                       waitUntilDone:NO];
  93 
  94 JNF_COCOA_EXIT(env);
  95 }
  96 
  97 /*
  98  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
  99  * Method:    canBecomeMainWindow
 100  * Signature: (J)V
 101  */
 102 JNIEXPORT jboolean JNICALL
 103 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_canBecomeMainWindow
 104 (JNIEnv *env, jclass cls, jlong windowPtr)
 105 {
 106     __block jboolean canBecomeMainWindow = JNI_FALSE;
 107 
 108 JNF_COCOA_ENTER(env);
 109 
 110     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 111     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 112         canBecomeMainWindow = [window canBecomeMainWindow];
 113     }];
 114 
 115 JNF_COCOA_EXIT(env);
 116 
 117     return canBecomeMainWindow;
 118 }
 119 
 120 /*
 121  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 122  * Method:    isKeyWindow
 123  * Signature: (J)Z
 124  */
 125 JNIEXPORT jboolean JNICALL
 126 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_isKeyWindow
 127 (JNIEnv *env, jclass cls, jlong windowPtr)
 128 {
 129     __block jboolean isKeyWindow = JNI_FALSE;
 130 
 131 JNF_COCOA_ENTER(env);
 132 
 133     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 134     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 135         isKeyWindow = [window isKeyWindow];
 136     }];
 137 
 138 JNF_COCOA_EXIT(env);
 139 
 140     return isKeyWindow;
 141 }
 142 
 143 /*
 144  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 145  * Method:    orderFront
 146  * Signature: (J)V
 147  */
 148 JNIEXPORT void JNICALL
 149 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFront
 150 (JNIEnv *env, jclass cls, jlong windowPtr)
 151 {
 152 JNF_COCOA_ENTER(env);
 153 
 154     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 155     [JNFRunLoop performOnMainThread:@selector(orderFront:)
 156                                  on:window
 157                          withObject:window
 158                       waitUntilDone:NO];
 159 
 160 JNF_COCOA_EXIT(env);
 161 }
 162 
 163 /*
 164  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 165  * Method:    orderOut
 166  * Signature: (J)V
 167  */
 168 JNIEXPORT void JNICALL
 169 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderOut
 170 (JNIEnv *env, jclass cls, jlong windowPtr)
 171 {
 172 JNF_COCOA_ENTER(env);
 173 
 174     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 175     [JNFRunLoop performOnMainThread:@selector(orderOut:)
 176                                  on:window
 177                          withObject:window
 178                       waitUntilDone:NO];
 179 
 180 JNF_COCOA_EXIT(env);
 181 }
 182 
 183 /*
 184  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 185  * Method:    orderFrontRegardless
 186  * Signature: (J)V
 187  */
 188 JNIEXPORT void JNICALL
 189 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFrontRegardless
 190 (JNIEnv *env, jclass cls, jlong windowPtr)
 191 {
 192 JNF_COCOA_ENTER(env);
 193 
 194     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 195     [JNFRunLoop performOnMainThread:@selector(orderFrontRegardless)
 196                                  on:window
 197                          withObject:nil
 198                       waitUntilDone:NO];
 199 
 200 JNF_COCOA_EXIT(env);
 201 }
 202 
 203 /*
 204  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 205  * Method:    orderWindow
 206  * Signature: (JIJ)V
 207  */
 208 JNIEXPORT void JNICALL
 209 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderWindow
 210 (JNIEnv *env, jclass cls, jlong windowPtr, jint order, jlong relativeToPtr)
 211 {
 212 JNF_COCOA_ENTER(env);
 213 
 214     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 215     NSWindow *relativeTo = (NSWindow *)jlong_to_ptr(relativeToPtr);
 216     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 217         [window orderWindow:(NSWindowOrderingMode)order relativeTo:[relativeTo windowNumber]];
 218     }];
 219 
 220 JNF_COCOA_EXIT(env);
 221 }
 222 
 223 // Used for CWrapper.NSWindow.setLevel() (and level() which isn't implemented yet)
 224 static NSInteger LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS];
 225 static void initLevels()
 226 {
 227     static dispatch_once_t pred;
 228 
 229     dispatch_once(&pred, ^{
 230         LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSNormalWindowLevel] = NSNormalWindowLevel;
 231         LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSFloatingWindowLevel] = NSFloatingWindowLevel;
 232     });
 233 }
 234 
 235 /*
 236  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 237  * Method:    setLevel
 238  * Signature: (JI)V
 239  */
 240 JNIEXPORT void JNICALL
 241 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setLevel
 242 (JNIEnv *env, jclass cls, jlong windowPtr, jint level)
 243 {
 244 JNF_COCOA_ENTER(env);
 245 
 246     if (level >= 0 && level < sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS) {
 247         initLevels();
 248 
 249         NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 250         [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 251             [window setLevel: LEVELS[level]];
 252         }];
 253     } else {
 254         [JNFException raise:env as:kIllegalArgumentException reason:"unknown level"];
 255     }
 256 
 257 JNF_COCOA_EXIT(env);
 258 }
 259 
 260 /*
 261  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 262  * Method:    addChildWindow
 263  * Signature: (JJI)V
 264  */
 265 JNIEXPORT void JNICALL
 266 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_addChildWindow
 267 (JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr, jint order)
 268 {
 269 JNF_COCOA_ENTER(env);
 270 
 271     NSWindow *parent = (NSWindow *)jlong_to_ptr(parentPtr);
 272     NSWindow *child = (NSWindow *)jlong_to_ptr(childPtr);
 273     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 274         [parent addChildWindow:child ordered:order];
 275     }];
 276 
 277 JNF_COCOA_EXIT(env);
 278 }
 279 
 280 /*
 281  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 282  * Method:    removeChildWindow
 283  * Signature: (JJ)V
 284  */
 285 JNIEXPORT void JNICALL
 286 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_removeChildWindow
 287 (JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr)
 288 {
 289 JNF_COCOA_ENTER(env);
 290 
 291     AWTWindow *parent = (AWTWindow *)jlong_to_ptr(parentPtr);
 292     AWTWindow *child = (AWTWindow *)jlong_to_ptr(childPtr);
 293     [JNFRunLoop performOnMainThread:@selector(removeChildWindow:)
 294                                  on:parent
 295                          withObject:child
 296                       waitUntilDone:NO];
 297 
 298 JNF_COCOA_EXIT(env);
 299 }
 300 
 301 /*
 302  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 303  * Method:    setFrame
 304  * Signature: (JIIIIZ)V
 305  */
 306 JNIEXPORT void JNICALL
 307 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setFrame
 308 (JNIEnv *env, jclass cls, jlong windowPtr, jint x, jint y, jint w, jint h, jboolean display)
 309 {
 310 JNF_COCOA_ENTER(env);
 311 
 312     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 313     NSRect frame = NSMakeRect(x, y, w, h);
 314     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 315         [window setFrame:frame display:display];
 316     }];
 317 
 318 JNF_COCOA_EXIT(env);
 319 }
 320 
 321 /*
 322  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 323  * Method:    setAlphaValue
 324  * Signature: (JF)V
 325  */
 326 JNIEXPORT void JNICALL
 327 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setAlphaValue
 328 (JNIEnv *env, jclass cls, jlong windowPtr, jfloat alpha)
 329 {
 330 JNF_COCOA_ENTER(env);
 331 
 332     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 333     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 334         [window setAlphaValue:(CGFloat)alpha];
 335     }];
 336 
 337 JNF_COCOA_EXIT(env);
 338 }
 339 
 340 /*
 341  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 342  * Method:    setOpaque
 343  * Signature: (Z)V
 344  */
 345 JNIEXPORT void JNICALL
 346 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setOpaque
 347 (JNIEnv *env, jclass cls, jlong windowPtr, jboolean opaque)
 348 {
 349 JNF_COCOA_ENTER(env);
 350 
 351     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 352     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 353         [window setOpaque:(BOOL)opaque];
 354     }];
 355 
 356 JNF_COCOA_EXIT(env);
 357 }
 358 
 359 /*
 360  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 361  * Method:    setBackgroundColor
 362  * Signature: (J)V
 363  */
 364 JNIEXPORT void JNICALL
 365 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setBackgroundColor
 366 (JNIEnv *env, jclass cls, jlong windowPtr, jlong colorPtr)
 367 {
 368 JNF_COCOA_ENTER(env);
 369 
 370     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 371     NSColor *color = (NSColor *)jlong_to_ptr(colorPtr);
 372     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 373         [window setBackgroundColor:color];
 374     }];
 375 
 376 JNF_COCOA_EXIT(env);
 377 }
 378 
 379 /*
 380  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 381  * Method:    screen
 382  * Signature: (J)J
 383  */
 384 JNIEXPORT jlong JNICALL
 385 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_screen
 386 (JNIEnv *env, jclass cls, jlong windowPtr)
 387 {
 388     __block jlong screenPtr = 0L;
 389 
 390 JNF_COCOA_ENTER(env);
 391 
 392     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 393     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 394         const NSScreen *screen = [window screen];
 395         CFRetain(screen); // GC
 396         screenPtr = ptr_to_jlong(screen);
 397     }];
 398 
 399 JNF_COCOA_EXIT(env);
 400 
 401     return screenPtr;
 402 }
 403 
 404 /*
 405  * Method:    miniaturize
 406  * Signature: (J)V
 407  */
 408 JNIEXPORT void JNICALL
 409 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_miniaturize
 410 (JNIEnv *env, jclass cls, jlong windowPtr)
 411 {
 412 JNF_COCOA_ENTER(env);
 413 
 414     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 415     [JNFRunLoop performOnMainThread:@selector(miniaturize:)
 416                                  on:window
 417                          withObject:nil
 418                       waitUntilDone:NO];
 419 
 420 JNF_COCOA_EXIT(env);
 421 }
 422 
 423 /*
 424  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 425  * Method:    deminiaturize
 426  * Signature: (J)V
 427  */
 428 JNIEXPORT void JNICALL
 429 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_deminiaturize
 430 (JNIEnv *env, jclass cls, jlong windowPtr)
 431 {
 432 JNF_COCOA_ENTER(env);
 433 
 434     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 435     [JNFRunLoop performOnMainThread:@selector(deminiaturize:)
 436                                  on:window
 437                          withObject:nil
 438                       waitUntilDone:NO];
 439 
 440 JNF_COCOA_EXIT(env);
 441 }
 442 
 443 /*
 444  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 445  * Method:    zoom
 446  * Signature: (J)V
 447  */
 448 JNIEXPORT void JNICALL
 449 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_zoom
 450 (JNIEnv *env, jclass cls, jlong windowPtr)
 451 {
 452 JNF_COCOA_ENTER(env);
 453 
 454     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 455     [JNFRunLoop performOnMainThread:@selector(zoom:)
 456                                  on:window
 457                          withObject:nil
 458                       waitUntilDone:NO];
 459 
 460 JNF_COCOA_EXIT(env);
 461 }
 462 
 463 /*
 464  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 465  * Method:    makeFirstResponder
 466  * Signature: (JJ)V
 467  */
 468 JNIEXPORT void JNICALL
 469 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeFirstResponder
 470 (JNIEnv *env, jclass cls, jlong windowPtr, jlong responderPtr)
 471 {
 472 JNF_COCOA_ENTER(env);
 473 
 474     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 475     NSResponder *responder = (NSResponder *)jlong_to_ptr(responderPtr);
 476     [JNFRunLoop performOnMainThread:@selector(makeFirstResponder:)
 477                                  on:window
 478                          withObject:responder
 479                       waitUntilDone:NO];
 480 
 481 JNF_COCOA_EXIT(env);
 482 }
 483 
 484 /*
 485  * Class:     sun_lwawt_macosx_CWrapper$NSView
 486  * Method:    addSubview
 487  * Signature: (JJ)V
 488  */
 489 JNIEXPORT void JNICALL
 490 Java_sun_lwawt_macosx_CWrapper_00024NSView_addSubview
 491 (JNIEnv *env, jclass cls, jlong viewPtr, jlong subviewPtr)
 492 {
 493 JNF_COCOA_ENTER(env);
 494 
 495     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 496     NSView *subview = (NSView *)jlong_to_ptr(subviewPtr);
 497     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 498         [view addSubview:subview];
 499     }];
 500 
 501 JNF_COCOA_EXIT(env);
 502 }
 503 
 504 /*
 505  * Class:     sun_lwawt_macosx_CWrapper$NSView
 506  * Method:    removeFromSuperview
 507  * Signature: (J)V
 508  */
 509 JNIEXPORT void JNICALL
 510 Java_sun_lwawt_macosx_CWrapper_00024NSView_removeFromSuperview
 511 (JNIEnv *env, jclass cls, jlong viewPtr)
 512 {
 513 JNF_COCOA_ENTER(env);
 514 
 515     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 516     [JNFRunLoop performOnMainThread:@selector(removeFromSuperview)
 517                                  on:view
 518                          withObject:nil
 519                       waitUntilDone:NO];
 520 
 521 JNF_COCOA_EXIT(env);
 522 }
 523 
 524 /*
 525  * Class:     sun_lwawt_macosx_CWrapper$NSView
 526  * Method:    setFrame
 527  * Signature: (JIIII)V
 528  */
 529 JNIEXPORT void JNICALL
 530 Java_sun_lwawt_macosx_CWrapper_00024NSView_setFrame
 531 (JNIEnv *env, jclass cls, jlong viewPtr, jint x, jint y, jint w, jint h)
 532 {
 533 JNF_COCOA_ENTER(env);
 534 
 535     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 536     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 537         [view setFrame:NSMakeRect(x, y, w, h)];
 538     }];
 539 
 540 JNF_COCOA_EXIT(env);
 541 }
 542 
 543 /*
 544  * Class:     sun_lwawt_macosx_CWrapper$NSView
 545  * Method:    frame
 546  * Signature: (J)Ljava/awt/Rectangle;
 547  */
 548 JNIEXPORT jobject JNICALL
 549 Java_sun_lwawt_macosx_CWrapper_00024NSView_frame
 550 (JNIEnv *env, jclass cls, jlong viewPtr)
 551 {
 552     jobject jRect = NULL;
 553 
 554 JNF_COCOA_ENTER(env);
 555 
 556     __block NSRect rect = NSZeroRect;
 557 
 558     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 559     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 560         rect = [view frame];
 561     }];
 562 
 563     jRect = NSToJavaRect(env, rect);
 564 
 565 JNF_COCOA_EXIT(env);
 566 
 567     return jRect;
 568 }
 569 
 570 /*
 571  * Class:     sun_lwawt_macosx_CWrapper$NSView
 572  * Method:    enterFullScreenMode
 573  * Signature: (J)V
 574  */
 575 JNIEXPORT void JNICALL
 576 Java_sun_lwawt_macosx_CWrapper_00024NSView_enterFullScreenMode
 577 (JNIEnv *env, jclass cls, jlong viewPtr)
 578 {
 579 JNF_COCOA_ENTER(env);
 580 
 581     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 582     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 583         NSScreen *screen = [[view window] screen];
 584         NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], NSFullScreenModeAllScreens, nil];
 585         [view enterFullScreenMode:screen withOptions:opts];
 586     }];
 587 
 588 JNF_COCOA_EXIT(env);
 589 }
 590 
 591 /*
 592  * Class:     sun_lwawt_macosx_CWrapper$NSView
 593  * Method:    exitFullScreenMode
 594  * Signature: (J)V
 595  */
 596 JNIEXPORT void JNICALL
 597 Java_sun_lwawt_macosx_CWrapper_00024NSView_exitFullScreenMode
 598 (JNIEnv *env, jclass cls, jlong viewPtr)
 599 {
 600 JNF_COCOA_ENTER(env);
 601 
 602     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 603     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 604         [view exitFullScreenModeWithOptions:nil];
 605     }];
 606 
 607 JNF_COCOA_EXIT(env);
 608 }
 609 
 610 /*
 611  * Class:     sun_lwawt_macosx_CWrapper$NSView
 612  * Method:    window
 613  * Signature: (J)J
 614  */
 615 JNIEXPORT jlong JNICALL
 616 Java_sun_lwawt_macosx_CWrapper_00024NSView_window
 617 (JNIEnv *env, jclass cls, jlong viewPtr)
 618 {
 619     __block jlong windowPtr = 0L;
 620 
 621 JNF_COCOA_ENTER(env);
 622 
 623     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 624     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 625         windowPtr = ptr_to_jlong([view window]);
 626     }];
 627 
 628 JNF_COCOA_EXIT(env);
 629 
 630     return windowPtr;
 631 }
 632 
 633 /*
 634  * Class:     sun_lwawt_macosx_CWrapper$NSScreen
 635  * Method:    frame
 636  * Signature: (J)Ljava/awt/Rectangle;
 637  */
 638 JNIEXPORT jobject JNICALL
 639 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_frame
 640 (JNIEnv *env, jclass cls, jlong screenPtr)
 641 {
 642     jobject jRect = NULL;
 643 
 644 JNF_COCOA_ENTER(env);
 645 
 646     __block NSRect rect = NSZeroRect;
 647 
 648     NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
 649     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 650         rect = [screen frame];
 651     }];
 652 
 653     jRect = NSToJavaRect(env, rect);
 654 
 655 JNF_COCOA_EXIT(env);
 656 
 657     return jRect;
 658 }
 659 
 660 /*
 661  * Class:     sun_lwawt_macosx_CWrapper_NSScreen
 662  * Method:    visibleFrame
 663  * Signature: (J)Ljava/awt/geom/Rectangle2D;
 664  */
 665 JNIEXPORT jobject JNICALL
 666 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_visibleFrame
 667 (JNIEnv *env, jclass cls, jlong screenPtr)
 668 {
 669     jobject jRect = NULL;
 670 
 671 JNF_COCOA_ENTER(env);
 672 
 673     __block NSRect rect = NSZeroRect;
 674 
 675     NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
 676     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 677         rect = [screen visibleFrame];
 678     }];
 679 
 680     jRect = NSToJavaRect(env, rect);
 681 
 682 JNF_COCOA_EXIT(env);
 683 
 684     return jRect;
 685 }
 686 
 687 /*
 688  * Class:     sun_lwawt_macosx_CWrapper_NSScreen
 689  * Method:    screenByDisplayId
 690  * Signature: (J)J
 691  */
 692 JNIEXPORT jlong JNICALL
 693 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screenByDisplayId
 694 (JNIEnv *env, jclass cls, jint displayID)
 695 {
 696     __block jlong screenPtr = 0L;
 697 
 698 JNF_COCOA_ENTER(env);
 699 
 700     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 701         NSArray *screens = [NSScreen screens];
 702         for (NSScreen *screen in screens) {
 703             NSDictionary *screenInfo = [screen deviceDescription];
 704             NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
 705             if ([screenID intValue] == displayID){
 706                 CFRetain(screen); // GC
 707                 screenPtr = ptr_to_jlong(screen);
 708                 break;
 709             }
 710         }
 711     }];
 712 
 713 JNF_COCOA_EXIT(env);
 714 
 715     return screenPtr;
 716 }
 717 
 718 /*
 719  * Class:     sun_lwawt_macosx_CWrapper$NSColor
 720  * Method:    clearColor
 721  * Signature: ()J
 722  */
 723 JNIEXPORT jlong JNICALL
 724 Java_sun_lwawt_macosx_CWrapper_00024NSColor_clearColor
 725 (JNIEnv *env, jclass cls)
 726 {
 727     __block jlong clearColorPtr = 0L;
 728 
 729 JNF_COCOA_ENTER(env);
 730 
 731     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 732         clearColorPtr = ptr_to_jlong([NSColor clearColor]);
 733     }];
 734 
 735 JNF_COCOA_EXIT(env);
 736 
 737     return clearColorPtr;
 738 }
 739