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  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 401  * Method:    screen
 402  * Signature: (J)J
 403  */
 404 JNIEXPORT jlong JNICALL
 405 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_screen
 406 (JNIEnv *env, jclass cls, jlong windowPtr)
 407 {
 408     __block jlong screenPtr = 0L;
 409 
 410 JNF_COCOA_ENTER(env);
 411 
 412     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
 413     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 414         const NSScreen *screen = [window screen];
 415         CFRetain(screen); // GC
 416         screenPtr = ptr_to_jlong(screen);
 417     }];
 418 
 419 JNF_COCOA_EXIT(env);
 420 
 421     return screenPtr;
 422 }
 423 
 424 /*
 425  * Method:    miniaturize
 426  * Signature: (J)V
 427  */
 428 JNIEXPORT void JNICALL
 429 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_miniaturize
 430 (JNIEnv *env, jclass cls, jlong windowPtr)
 431 {
 432 JNF_COCOA_ENTER(env);
 433 
 434     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 435     [ThreadUtilities performOnMainThread:@selector(miniaturize:)
 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:    deminiaturize
 446  * Signature: (J)V
 447  */
 448 JNIEXPORT void JNICALL
 449 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_deminiaturize
 450 (JNIEnv *env, jclass cls, jlong windowPtr)
 451 {
 452 JNF_COCOA_ENTER(env);
 453 
 454     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 455     [ThreadUtilities performOnMainThread:@selector(deminiaturize:)
 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:    zoom
 466  * Signature: (J)V
 467  */
 468 JNIEXPORT void JNICALL
 469 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_zoom
 470 (JNIEnv *env, jclass cls, jlong windowPtr)
 471 {
 472 JNF_COCOA_ENTER(env);
 473 
 474     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 475     [ThreadUtilities performOnMainThread:@selector(zoom:)
 476                                       on:window
 477                               withObject:nil
 478                            waitUntilDone:NO];
 479 
 480 JNF_COCOA_EXIT(env);
 481 }
 482 
 483 /*
 484  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
 485  * Method:    makeFirstResponder
 486  * Signature: (JJ)V
 487  */
 488 JNIEXPORT void JNICALL
 489 Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeFirstResponder
 490 (JNIEnv *env, jclass cls, jlong windowPtr, jlong responderPtr)
 491 {
 492 JNF_COCOA_ENTER(env);
 493 
 494     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
 495     NSResponder *responder = (NSResponder *)jlong_to_ptr(responderPtr);
 496     [ThreadUtilities performOnMainThread:@selector(makeFirstResponder:)
 497                                       on:window
 498                               withObject:responder
 499                            waitUntilDone:NO];
 500 
 501 JNF_COCOA_EXIT(env);
 502 }
 503 
 504 /*
 505  * Class:     sun_lwawt_macosx_CWrapper$NSView
 506  * Method:    addSubview
 507  * Signature: (JJ)V
 508  */
 509 JNIEXPORT void JNICALL
 510 Java_sun_lwawt_macosx_CWrapper_00024NSView_addSubview
 511 (JNIEnv *env, jclass cls, jlong viewPtr, jlong subviewPtr)
 512 {
 513 JNF_COCOA_ENTER(env);
 514 
 515     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 516     NSView *subview = (NSView *)jlong_to_ptr(subviewPtr);
 517     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 518         [view addSubview:subview];
 519     }];
 520 
 521 JNF_COCOA_EXIT(env);
 522 }
 523 
 524 /*
 525  * Class:     sun_lwawt_macosx_CWrapper$NSView
 526  * Method:    removeFromSuperview
 527  * Signature: (J)V
 528  */
 529 JNIEXPORT void JNICALL
 530 Java_sun_lwawt_macosx_CWrapper_00024NSView_removeFromSuperview
 531 (JNIEnv *env, jclass cls, jlong viewPtr)
 532 {
 533 JNF_COCOA_ENTER(env);
 534 
 535     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 536     [ThreadUtilities performOnMainThread:@selector(removeFromSuperview)
 537                                       on:view
 538                               withObject:nil
 539                            waitUntilDone:NO];
 540 
 541 JNF_COCOA_EXIT(env);
 542 }
 543 
 544 /*
 545  * Class:     sun_lwawt_macosx_CWrapper$NSView
 546  * Method:    setFrame
 547  * Signature: (JIIII)V
 548  */
 549 JNIEXPORT void JNICALL
 550 Java_sun_lwawt_macosx_CWrapper_00024NSView_setFrame
 551 (JNIEnv *env, jclass cls, jlong viewPtr, jint x, jint y, jint w, jint h)
 552 {
 553 JNF_COCOA_ENTER(env);
 554 
 555     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 556     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 557         [view setFrame:NSMakeRect(x, y, w, h)];
 558     }];
 559 
 560 JNF_COCOA_EXIT(env);
 561 }
 562 
 563 /*
 564  * Class:     sun_lwawt_macosx_CWrapper$NSView
 565  * Method:    frame
 566  * Signature: (J)Ljava/awt/Rectangle;
 567  */
 568 JNIEXPORT jobject JNICALL
 569 Java_sun_lwawt_macosx_CWrapper_00024NSView_frame
 570 (JNIEnv *env, jclass cls, jlong viewPtr)
 571 {
 572     jobject jRect = NULL;
 573 
 574 JNF_COCOA_ENTER(env);
 575 
 576     __block NSRect rect = NSZeroRect;
 577 
 578     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 579     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 580         rect = [view frame];
 581     }];
 582 
 583     jRect = NSToJavaRect(env, rect);
 584 
 585 JNF_COCOA_EXIT(env);
 586 
 587     return jRect;
 588 }
 589 
 590 /*
 591  * Class:     sun_lwawt_macosx_CWrapper$NSView
 592  * Method:    enterFullScreenMode
 593  * Signature: (J)V
 594  */
 595 JNIEXPORT void JNICALL
 596 Java_sun_lwawt_macosx_CWrapper_00024NSView_enterFullScreenMode
 597 (JNIEnv *env, jclass cls, jlong viewPtr)
 598 {
 599 JNF_COCOA_ENTER(env);
 600 
 601     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 602     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 603         NSScreen *screen = [[view window] screen];
 604         NSDictionary *opts = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], NSFullScreenModeAllScreens, nil];
 605         [view enterFullScreenMode:screen withOptions:opts];
 606     }];
 607 
 608 JNF_COCOA_EXIT(env);
 609 }
 610 
 611 /*
 612  * Class:     sun_lwawt_macosx_CWrapper$NSView
 613  * Method:    exitFullScreenMode
 614  * Signature: (J)V
 615  */
 616 JNIEXPORT void JNICALL
 617 Java_sun_lwawt_macosx_CWrapper_00024NSView_exitFullScreenMode
 618 (JNIEnv *env, jclass cls, jlong viewPtr)
 619 {
 620 JNF_COCOA_ENTER(env);
 621 
 622     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 623     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 624         [view exitFullScreenModeWithOptions:nil];
 625     }];
 626 
 627 JNF_COCOA_EXIT(env);
 628 }
 629 
 630 /*
 631  * Class:     sun_lwawt_macosx_CWrapper$NSView
 632  * Method:    window
 633  * Signature: (J)J
 634  */
 635 JNIEXPORT jlong JNICALL
 636 Java_sun_lwawt_macosx_CWrapper_00024NSView_window
 637 (JNIEnv *env, jclass cls, jlong viewPtr)
 638 {
 639     __block jlong windowPtr = 0L;
 640 
 641 JNF_COCOA_ENTER(env);
 642 
 643     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 644     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 645         windowPtr = ptr_to_jlong([view window]);
 646     }];
 647 
 648 JNF_COCOA_EXIT(env);
 649 
 650     return windowPtr;
 651 }
 652 
 653 /*
 654  * Class:     sun_lwawt_macosx_CWrapper$NSView
 655  * Method:    setHidden
 656  * Signature: (JZ)V
 657  */
 658 JNIEXPORT void JNICALL
 659 Java_sun_lwawt_macosx_CWrapper_00024NSView_setHidden
 660 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toHide)
 661 {    
 662     JNF_COCOA_ENTER(env);
 663     
 664     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
 665     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 666         [view setHidden:(BOOL)toHide];
 667     }];
 668     
 669     JNF_COCOA_EXIT(env);
 670 }
 671 
 672 
 673 /*
 674  * Class:     sun_lwawt_macosx_CWrapper$NSScreen
 675  * Method:    frame
 676  * Signature: (J)Ljava/awt/Rectangle;
 677  */
 678 JNIEXPORT jobject JNICALL
 679 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_frame
 680 (JNIEnv *env, jclass cls, jlong screenPtr)
 681 {
 682     jobject jRect = NULL;
 683 
 684 JNF_COCOA_ENTER(env);
 685 
 686     __block NSRect rect = NSZeroRect;
 687 
 688     NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
 689     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 690         rect = [screen frame];
 691     }];
 692 
 693     jRect = NSToJavaRect(env, rect);
 694 
 695 JNF_COCOA_EXIT(env);
 696 
 697     return jRect;
 698 }
 699 
 700 /*
 701  * Class:     sun_lwawt_macosx_CWrapper_NSScreen
 702  * Method:    visibleFrame
 703  * Signature: (J)Ljava/awt/geom/Rectangle2D;
 704  */
 705 JNIEXPORT jobject JNICALL
 706 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_visibleFrame
 707 (JNIEnv *env, jclass cls, jlong screenPtr)
 708 {
 709     jobject jRect = NULL;
 710 
 711 JNF_COCOA_ENTER(env);
 712 
 713     __block NSRect rect = NSZeroRect;
 714 
 715     NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
 716     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 717         rect = [screen visibleFrame];
 718     }];
 719 
 720     jRect = NSToJavaRect(env, rect);
 721 
 722 JNF_COCOA_EXIT(env);
 723 
 724     return jRect;
 725 }
 726 
 727 /*
 728  * Class:     sun_lwawt_macosx_CWrapper_NSScreen
 729  * Method:    screenByDisplayId
 730  * Signature: (J)J
 731  */
 732 JNIEXPORT jlong JNICALL
 733 Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screenByDisplayId
 734 (JNIEnv *env, jclass cls, jint displayID)
 735 {
 736     __block jlong screenPtr = 0L;
 737 
 738 JNF_COCOA_ENTER(env);
 739 
 740     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 741         NSArray *screens = [NSScreen screens];
 742         for (NSScreen *screen in screens) {
 743             NSDictionary *screenInfo = [screen deviceDescription];
 744             NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
 745             if ([screenID intValue] == displayID){
 746                 CFRetain(screen); // GC
 747                 screenPtr = ptr_to_jlong(screen);
 748                 break;
 749             }
 750         }
 751     }];
 752 
 753 JNF_COCOA_EXIT(env);
 754 
 755     return screenPtr;
 756 }
 757 
 758 /*
 759  * Class:     sun_lwawt_macosx_CWrapper$NSColor
 760  * Method:    clearColor
 761  * Signature: ()J
 762  */
 763 JNIEXPORT jlong JNICALL
 764 Java_sun_lwawt_macosx_CWrapper_00024NSColor_clearColor
 765 (JNIEnv *env, jclass cls)
 766 {
 767     __block jlong clearColorPtr = 0L;
 768 
 769 JNF_COCOA_ENTER(env);
 770 
 771     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 772         clearColorPtr = ptr_to_jlong([NSColor clearColor]);
 773     }];
 774 
 775 JNF_COCOA_EXIT(env);
 776 
 777     return clearColorPtr;
 778 }
 779 
--- EOF ---