< prev index next >
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 678,688 ****
if (platformWindow != NULL) {
static JNF_MEMBER_CACHE(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
JNFCallVoidMethod(env, platformWindow, jm_windowWillMiniaturize);
(*env)->DeleteLocalRef(env, platformWindow);
}
! // Excplicitly make myself a key window to avoid possible
// negative visual effects during iconify operation
[self.nsWindow makeKeyAndOrderFront:self.nsWindow];
[self iconifyChildWindows:YES];
}
--- 678,688 ----
if (platformWindow != NULL) {
static JNF_MEMBER_CACHE(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
JNFCallVoidMethod(env, platformWindow, jm_windowWillMiniaturize);
(*env)->DeleteLocalRef(env, platformWindow);
}
! // Explicitly make myself a key window to avoid possible
// negative visual effects during iconify operation
[self.nsWindow makeKeyAndOrderFront:self.nsWindow];
[self iconifyChildWindows:YES];
}
*** 712,728 ****
(*env)->DeleteLocalRef(env, platformWindow);
(*env)->DeleteLocalRef(env, oppositeWindow);
}
}
- (void) windowDidBecomeKey: (NSNotification *) notification {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
AWTWindow *opposite = [AWTWindow lastKeyWindow];
! // Finds appropriate menubar in our hierarchy,
AWTWindow *awtWindow = self;
while (awtWindow.ownerWindow != nil) {
awtWindow = awtWindow.ownerWindow;
}
--- 712,762 ----
(*env)->DeleteLocalRef(env, platformWindow);
(*env)->DeleteLocalRef(env, oppositeWindow);
}
}
+ - (void) windowDidBecomeMain: (NSNotification *) notification {
+ AWT_ASSERT_APPKIT_THREAD;
+ [AWTToolkit eventCountPlusPlus];
+ #ifdef DEBUG
+ NSLog(@"became main: %d %@ %@", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow]);
+ #endif
+
+ if (![self.nsWindow isKeyWindow]) {
+ [self activateWindowMenuBar];
+ }
+
+ JNIEnv *env = [ThreadUtilities getJNIEnv];
+ jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
+ if (platformWindow != NULL) {
+ static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
+ JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
+ (*env)->DeleteLocalRef(env, platformWindow);
+ }
+ }
- (void) windowDidBecomeKey: (NSNotification *) notification {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
+ #ifdef DEBUG
+ NSLog(@"became key: %d %@ %@", [self.nsWindow isMainWindow], [self.nsWindow title], [self menuBarForWindow]);
+ #endif
AWTWindow *opposite = [AWTWindow lastKeyWindow];
! if (![self.nsWindow isMainWindow]) {
! [self activateWindowMenuBar];
! }
!
! [AWTWindow setLastKeyWindow:nil];
!
! [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
! [self orderChildWindows:YES];
! }
!
! - (void) activateWindowMenuBar {
! AWT_ASSERT_APPKIT_THREAD;
! // Finds appropriate menubar in our hierarchy
AWTWindow *awtWindow = self;
while (awtWindow.ownerWindow != nil) {
awtWindow = awtWindow.ownerWindow;
}
*** 737,766 ****
menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
isDisabled = NO;
}
[CMenuBar activate:menuBar modallyDisabled:isDisabled];
! [AWTWindow setLastKeyWindow:nil];
!
! [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
! [self orderChildWindows:YES];
}
- (void) windowDidResignKey: (NSNotification *) notification {
// TODO: check why sometimes at start is invoked *not* on AppKit main thread.
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
! [self.javaMenuBar deactivate];
! // In theory, this might cause flickering if the window gaining focus
! // has its own menu. However, I couldn't reproduce it on practice, so
! // perhaps this is a non issue.
! CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
! if (defaultMenu != nil) {
! [CMenuBar activate:defaultMenu modallyDisabled:NO];
}
// the new key window
NSWindow *keyWindow = [NSApp keyWindow];
AWTWindow *opposite = nil;
if ([AWTWindow isAWTWindow: keyWindow]) {
--- 771,822 ----
menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
isDisabled = NO;
}
[CMenuBar activate:menuBar modallyDisabled:isDisabled];
+ }
! #ifdef DEBUG
! - (CMenuBar *) menuBarForWindow {
! AWT_ASSERT_APPKIT_THREAD;
! AWTWindow *awtWindow = self;
! while (awtWindow.ownerWindow != nil) {
! awtWindow = awtWindow.ownerWindow;
! }
! return awtWindow.javaMenuBar;
}
+ #endif
- (void) windowDidResignKey: (NSNotification *) notification {
// TODO: check why sometimes at start is invoked *not* on AppKit main thread.
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
! #ifdef DEBUG
! NSLog(@"resigned key: %d %@ %@", [self.nsWindow isMainWindow], [self.nsWindow title], [self menuBarForWindow]);
! #endif
! if (![self.nsWindow isMainWindow]) {
! [self deactivateWindow];
! }
! }
! - (void) windowDidResignMain: (NSNotification *) notification {
! AWT_ASSERT_APPKIT_THREAD;
! [AWTToolkit eventCountPlusPlus];
! #ifdef DEBUG
! NSLog(@"resigned main: %d %@ %@", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow]);
! #endif
! if (![self.nsWindow isKeyWindow]) {
! [self deactivateWindow];
}
+ }
+
+ - (void) deactivateWindow {
+ AWT_ASSERT_APPKIT_THREAD;
+ #ifdef DEBUG
+ NSLog(@"deactivating window: %@", [self.nsWindow title]);
+ #endif
+ [self.javaMenuBar deactivate];
// the new key window
NSWindow *keyWindow = [NSApp keyWindow];
AWTWindow *opposite = nil;
if ([AWTWindow isAWTWindow: keyWindow]) {
*** 772,794 ****
[self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
[self orderChildWindows:NO];
}
- - (void) windowDidBecomeMain: (NSNotification *) notification {
- AWT_ASSERT_APPKIT_THREAD;
- [AWTToolkit eventCountPlusPlus];
-
- JNIEnv *env = [ThreadUtilities getJNIEnv];
- jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
- if (platformWindow != NULL) {
- static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
- JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
- (*env)->DeleteLocalRef(env, platformWindow);
- }
- }
-
- (BOOL)windowShouldClose:(id)sender {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
--- 828,837 ----
*** 1039,1060 ****
CMenuBar *menuBar = OBJC(menuBarPtr);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
! if ([nsWindow isKeyWindow]) {
[window.javaMenuBar deactivate];
}
window.javaMenuBar = menuBar;
CMenuBar* actualMenuBar = menuBar;
if (actualMenuBar == nil) {
actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
}
! if ([nsWindow isKeyWindow]) {
[CMenuBar activate:actualMenuBar modallyDisabled:NO];
}
}];
JNF_COCOA_EXIT(env);
--- 1082,1103 ----
CMenuBar *menuBar = OBJC(menuBarPtr);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
! if ([nsWindow isKeyWindow] || [nsWindow isMainWindow]) {
[window.javaMenuBar deactivate];
}
window.javaMenuBar = menuBar;
CMenuBar* actualMenuBar = menuBar;
if (actualMenuBar == nil) {
actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
}
! if ([nsWindow isKeyWindow] || [nsWindow isMainWindow]) {
[CMenuBar activate:actualMenuBar modallyDisabled:NO];
}
}];
JNF_COCOA_EXIT(env);
< prev index next >