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