jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
changeset 38970 aabcf4406038
parent 32872 abca6234313d
child 38987 ffe8b158dd6a
equal deleted inserted replaced
38416:dd0b515bc286 38970:aabcf4406038
   178 @synthesize styleBits;
   178 @synthesize styleBits;
   179 @synthesize isEnabled;
   179 @synthesize isEnabled;
   180 @synthesize ownerWindow;
   180 @synthesize ownerWindow;
   181 @synthesize preFullScreenLevel;
   181 @synthesize preFullScreenLevel;
   182 @synthesize standardFrame;
   182 @synthesize standardFrame;
       
   183 @synthesize isMinimizing;
   183 
   184 
   184 - (void) updateMinMaxSize:(BOOL)resizable {
   185 - (void) updateMinMaxSize:(BOOL)resizable {
   185     if (resizable) {
   186     if (resizable) {
   186         [self.nsWindow setMinSize:self.javaMinSize];
   187         [self.nsWindow setMinSize:self.javaMinSize];
   187         [self.nsWindow setMaxSize:self.javaMaxSize];
   188         [self.nsWindow setMaxSize:self.javaMaxSize];
   302 
   303 
   303     if (self.nsWindow == nil) return nil; // no hope either
   304     if (self.nsWindow == nil) return nil; // no hope either
   304     [self.nsWindow release]; // the property retains the object already
   305     [self.nsWindow release]; // the property retains the object already
   305 
   306 
   306     self.isEnabled = YES;
   307     self.isEnabled = YES;
       
   308     self.isMinimizing = NO;
   307     self.javaPlatformWindow = platformWindow;
   309     self.javaPlatformWindow = platformWindow;
   308     self.styleBits = bits;
   310     self.styleBits = bits;
   309     self.ownerWindow = owner;
   311     self.ownerWindow = owner;
   310     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
   312     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
   311 
   313 
   421     self.nsWindow = nil;
   423     self.nsWindow = nil;
   422     self.ownerWindow = nil;
   424     self.ownerWindow = nil;
   423     [super dealloc];
   425     [super dealloc];
   424 }
   426 }
   425 
   427 
       
   428 // Tests wheather the corresponding Java paltform window is visible or not
       
   429 + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
       
   430     BOOL isVisible = NO;
       
   431     
       
   432     if ([AWTWindow isAWTWindow:window] && [window delegate] != nil) {
       
   433         AWTWindow *awtWindow = (AWTWindow *)[window delegate];
       
   434         [AWTToolkit eventCountPlusPlus];
       
   435         
       
   436         JNIEnv *env = [ThreadUtilities getJNIEnv];
       
   437         jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
       
   438         if (platformWindow != NULL) {
       
   439             static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z");
       
   440             isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO;
       
   441             (*env)->DeleteLocalRef(env, platformWindow);
       
   442             
       
   443         }
       
   444     }
       
   445     return isVisible;
       
   446 }
       
   447 
       
   448 // Orders window's childs based on the current focus state
       
   449 - (void) orderChildWindows:(BOOL)focus {
       
   450 AWT_ASSERT_APPKIT_THREAD;
       
   451 
       
   452     if (self.isMinimizing) {
       
   453         // Do not perform any ordering, if iconify is in progress
       
   454         return;
       
   455     }
       
   456 
       
   457     NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator];
       
   458     NSWindow *window;
       
   459     while ((window = [windowEnumerator nextObject]) != nil) {
       
   460         if ([AWTWindow isJavaPlatformWindowVisible:window]) {
       
   461             AWTWindow *awtWindow = (AWTWindow *)[window delegate];
       
   462             AWTWindow *owner = awtWindow.ownerWindow;
       
   463             if (IS(awtWindow.styleBits, ALWAYS_ON_TOP)) {
       
   464                 // Do not order 'always on top' windows
       
   465                 continue;
       
   466             }
       
   467             while (awtWindow.ownerWindow != nil) {
       
   468                 if (awtWindow.ownerWindow == self) {
       
   469                     if (focus) {
       
   470                         // Move the childWindow to floating level
       
   471                         // so it will appear in front of its
       
   472                         // parent which owns the focus
       
   473                         [window setLevel:NSFloatingWindowLevel];
       
   474                     } else {
       
   475                         // Focus owner has changed, move the childWindow
       
   476                         // back to normal window level
       
   477                         [window setLevel:NSNormalWindowLevel];
       
   478                     }
       
   479                     // The childWindow should be displayed in front of
       
   480                     // its nearest parentWindow
       
   481                     [window orderWindow:NSWindowAbove relativeTo:[owner.nsWindow windowNumber]];
       
   482                     break;
       
   483                 }
       
   484                 awtWindow = awtWindow.ownerWindow;
       
   485             }
       
   486         }
       
   487     }
       
   488 }
       
   489 
   426 // NSWindow overrides
   490 // NSWindow overrides
   427 - (BOOL) canBecomeKeyWindow {
   491 - (BOOL) canBecomeKeyWindow {
   428 AWT_ASSERT_APPKIT_THREAD;
   492 AWT_ASSERT_APPKIT_THREAD;
   429     return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
   493     return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
   430 }
   494 }
   509                         defaultFrame:(NSRect)newFrame {
   573                         defaultFrame:(NSRect)newFrame {
   510 
   574 
   511     return [self standardFrame];
   575     return [self standardFrame];
   512 }
   576 }
   513 
   577 
       
   578 // Hides/shows window's childs during iconify/de-iconify operation
       
   579 - (void) iconifyChildWindows:(BOOL)iconify {
       
   580 AWT_ASSERT_APPKIT_THREAD;
       
   581 
       
   582     NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator];
       
   583     NSWindow *window;
       
   584     while ((window = [windowEnumerator nextObject]) != nil) {
       
   585         if ([AWTWindow isJavaPlatformWindowVisible:window]) {
       
   586             AWTWindow *awtWindow = (AWTWindow *)[window delegate];
       
   587             while (awtWindow.ownerWindow != nil) {
       
   588                 if (awtWindow.ownerWindow == self) {
       
   589                     if (iconify) {
       
   590                         [window orderOut:window];
       
   591                     } else {
       
   592                         [window orderFront:window];
       
   593                     }
       
   594                     break;
       
   595                 }
       
   596                 awtWindow = awtWindow.ownerWindow;
       
   597             }
       
   598         }
       
   599     }
       
   600 }
       
   601 
   514 - (void) _deliverIconify:(BOOL)iconify {
   602 - (void) _deliverIconify:(BOOL)iconify {
   515 AWT_ASSERT_APPKIT_THREAD;
   603 AWT_ASSERT_APPKIT_THREAD;
   516 
   604 
   517     [AWTToolkit eventCountPlusPlus];
   605     [AWTToolkit eventCountPlusPlus];
   518     JNIEnv *env = [ThreadUtilities getJNIEnv];
   606     JNIEnv *env = [ThreadUtilities getJNIEnv];
   522         JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
   610         JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
   523         (*env)->DeleteLocalRef(env, platformWindow);
   611         (*env)->DeleteLocalRef(env, platformWindow);
   524     }
   612     }
   525 }
   613 }
   526 
   614 
       
   615 - (void)windowWillMiniaturize:(NSNotification *)notification {
       
   616 AWT_ASSERT_APPKIT_THREAD;
       
   617 
       
   618     self.isMinimizing = YES;
       
   619     // Excplicitly make myself a key window to avoid possible
       
   620     // negative visual effects during iconify operation
       
   621     [self.nsWindow makeKeyAndOrderFront:self.nsWindow];
       
   622     [self iconifyChildWindows:YES];
       
   623 }
       
   624 
   527 - (void)windowDidMiniaturize:(NSNotification *)notification {
   625 - (void)windowDidMiniaturize:(NSNotification *)notification {
   528 AWT_ASSERT_APPKIT_THREAD;
   626 AWT_ASSERT_APPKIT_THREAD;
   529 
   627 
   530     [self _deliverIconify:JNI_TRUE];
   628     [self _deliverIconify:JNI_TRUE];
       
   629     self.isMinimizing = NO;
   531 }
   630 }
   532 
   631 
   533 - (void)windowDidDeminiaturize:(NSNotification *)notification {
   632 - (void)windowDidDeminiaturize:(NSNotification *)notification {
   534 AWT_ASSERT_APPKIT_THREAD;
   633 AWT_ASSERT_APPKIT_THREAD;
   535 
   634 
   536     [self _deliverIconify:JNI_FALSE];
   635     [self _deliverIconify:JNI_FALSE];
       
   636     [self iconifyChildWindows:NO];
   537 }
   637 }
   538 
   638 
   539 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
   639 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
   540 //AWT_ASSERT_APPKIT_THREAD;
   640 //AWT_ASSERT_APPKIT_THREAD;
   541     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
   641     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
   577     [CMenuBar activate:menuBar modallyDisabled:isDisabled];
   677     [CMenuBar activate:menuBar modallyDisabled:isDisabled];
   578 
   678 
   579     [AWTWindow setLastKeyWindow:nil];
   679     [AWTWindow setLastKeyWindow:nil];
   580 
   680 
   581     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
   681     [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
       
   682     [self orderChildWindows:YES];
   582 }
   683 }
   583 
   684 
   584 - (void) windowDidResignKey: (NSNotification *) notification {
   685 - (void) windowDidResignKey: (NSNotification *) notification {
   585     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
   686     // TODO: check why sometimes at start is invoked *not* on AppKit main thread.
   586 AWT_ASSERT_APPKIT_THREAD;
   687 AWT_ASSERT_APPKIT_THREAD;
   604     } else {
   705     } else {
   605         [AWTWindow setLastKeyWindow: nil];
   706         [AWTWindow setLastKeyWindow: nil];
   606     }
   707     }
   607 
   708 
   608     [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
   709     [self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
       
   710     [self orderChildWindows:NO];
   609 }
   711 }
   610 
   712 
   611 - (void) windowDidBecomeMain: (NSNotification *) notification {
   713 - (void) windowDidBecomeMain: (NSNotification *) notification {
   612 AWT_ASSERT_APPKIT_THREAD;
   714 AWT_ASSERT_APPKIT_THREAD;
   613     [AWTToolkit eventCountPlusPlus];
   715     [AWTToolkit eventCountPlusPlus];