src/macosx/native/sun/awt/AWTWindow.m

Print this page


   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


 519 }
 520 
 521 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
 522 //AWT_ASSERT_APPKIT_THREAD;
 523     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
 524     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 525     if (platformWindow != NULL) {
 526         jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
 527 
 528         static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
 529         JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
 530         (*env)->DeleteLocalRef(env, platformWindow);
 531         (*env)->DeleteLocalRef(env, oppositeWindow);
 532     }
 533 }
 534 
 535 
 536 - (void) windowDidBecomeKey: (NSNotification *) notification {
 537 AWT_ASSERT_APPKIT_THREAD;
 538     [AWTToolkit eventCountPlusPlus];
 539     [CMenuBar activate:self.javaMenuBar modallyDisabled:NO];
 540     AWTWindow *opposite = [AWTWindow lastKeyWindow];








 541     [AWTWindow setLastKeyWindow:nil];
 542 
 543     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
 544 }
 545 
 546 - (void) windowDidResignKey: (NSNotification *) notification {
 547     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
 548 AWT_ASSERT_APPKIT_THREAD;
 549     [AWTToolkit eventCountPlusPlus];
 550     [self.javaMenuBar deactivate];
 551 
 552     // the new key window
 553     NSWindow *keyWindow = [NSApp keyWindow];
 554     AWTWindow *opposite = nil;
 555     if ([AWTWindow isAWTWindow: keyWindow]) {
 556         opposite = (AWTWindow *)[keyWindow delegate];
 557         [AWTWindow setLastKeyWindow: self];
 558     } else {
 559         [AWTWindow setLastKeyWindow: nil];
 560     }


   1 /*
   2  * Copyright (c) 2013, 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


 519 }
 520 
 521 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
 522 //AWT_ASSERT_APPKIT_THREAD;
 523     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
 524     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 525     if (platformWindow != NULL) {
 526         jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
 527 
 528         static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
 529         JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
 530         (*env)->DeleteLocalRef(env, platformWindow);
 531         (*env)->DeleteLocalRef(env, oppositeWindow);
 532     }
 533 }
 534 
 535 
 536 - (void) windowDidBecomeKey: (NSNotification *) notification {
 537 AWT_ASSERT_APPKIT_THREAD;
 538     [AWTToolkit eventCountPlusPlus];
 539 
 540     AWTWindow *opposite = [AWTWindow lastKeyWindow];
 541     if (self.javaMenuBar != NULL) {
 542         [CMenuBar activate:self.javaMenuBar modallyDisabled:NO];
 543     } else {
 544         if (IS(self.styleBits, MODAL) && opposite != NULL) {
 545             [CMenuBar activate:opposite->javaMenuBar modallyDisabled:YES];
 546         }
 547     }
 548     
 549     [AWTWindow setLastKeyWindow:nil];
 550 
 551     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
 552 }
 553 
 554 - (void) windowDidResignKey: (NSNotification *) notification {
 555     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
 556 AWT_ASSERT_APPKIT_THREAD;
 557     [AWTToolkit eventCountPlusPlus];
 558     [self.javaMenuBar deactivate];
 559 
 560     // the new key window
 561     NSWindow *keyWindow = [NSApp keyWindow];
 562     AWTWindow *opposite = nil;
 563     if ([AWTWindow isAWTWindow: keyWindow]) {
 564         opposite = (AWTWindow *)[keyWindow delegate];
 565         [AWTWindow setLastKeyWindow: self];
 566     } else {
 567         [AWTWindow setLastKeyWindow: nil];
 568     }