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
564 }
565
566 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
567 //AWT_ASSERT_APPKIT_THREAD;
568 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
569 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
570 if (platformWindow != NULL) {
571 jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
572
573 static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
574 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
575 (*env)->DeleteLocalRef(env, platformWindow);
576 (*env)->DeleteLocalRef(env, oppositeWindow);
577 }
578 }
579
580
581 - (void) windowDidBecomeKey: (NSNotification *) notification {
582 AWT_ASSERT_APPKIT_THREAD;
583 [AWTToolkit eventCountPlusPlus];
584 [CMenuBar activate:self.javaMenuBar modallyDisabled:NO];
585 AWTWindow *opposite = [AWTWindow lastKeyWindow];
586 [AWTWindow setLastKeyWindow:nil];
587
588 [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
589 }
590
591 - (void) windowDidResignKey: (NSNotification *) notification {
592 // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
593 AWT_ASSERT_APPKIT_THREAD;
594 [AWTToolkit eventCountPlusPlus];
595 [self.javaMenuBar deactivate];
596
597 // the new key window
598 NSWindow *keyWindow = [NSApp keyWindow];
599 AWTWindow *opposite = nil;
600 if ([AWTWindow isAWTWindow: keyWindow]) {
601 opposite = (AWTWindow *)[keyWindow delegate];
602 [AWTWindow setLastKeyWindow: self];
603 } else {
604 [AWTWindow setLastKeyWindow: nil];
605 }
|
1 /*
2 * Copyright (c) 2011, 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
564 }
565
566 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
567 //AWT_ASSERT_APPKIT_THREAD;
568 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
569 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
570 if (platformWindow != NULL) {
571 jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
572
573 static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
574 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
575 (*env)->DeleteLocalRef(env, platformWindow);
576 (*env)->DeleteLocalRef(env, oppositeWindow);
577 }
578 }
579
580
581 - (void) windowDidBecomeKey: (NSNotification *) notification {
582 AWT_ASSERT_APPKIT_THREAD;
583 [AWTToolkit eventCountPlusPlus];
584 AWTWindow *opposite = [AWTWindow lastKeyWindow];
585 if (!IS(self.styleBits, IS_DIALOG)) {
586 [CMenuBar activate:self.javaMenuBar modallyDisabled:NO];
587 } else if ((opposite != NULL) && IS(self.styleBits, IS_MODAL)) {
588 [CMenuBar activate:opposite->javaMenuBar modallyDisabled:YES];
589 }
590 [AWTWindow setLastKeyWindow:nil];
591
592 [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
593 }
594
595 - (void) windowDidResignKey: (NSNotification *) notification {
596 // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
597 AWT_ASSERT_APPKIT_THREAD;
598 [AWTToolkit eventCountPlusPlus];
599 [self.javaMenuBar deactivate];
600
601 // the new key window
602 NSWindow *keyWindow = [NSApp keyWindow];
603 AWTWindow *opposite = nil;
604 if ([AWTWindow isAWTWindow: keyWindow]) {
605 opposite = (AWTWindow *)[keyWindow delegate];
606 [AWTWindow setLastKeyWindow: self];
607 } else {
608 [AWTWindow setLastKeyWindow: nil];
609 }
|