169 @implementation AWTWindow_Panel
170 AWT_NS_WINDOW_IMPLEMENTATION
171 @end
172 // END of NSWindow/NSPanel descendants implementation
173 // --------------------------------------------------------------
174
175
176 @implementation AWTWindow
177
178 @synthesize nsWindow;
179 @synthesize javaPlatformWindow;
180 @synthesize javaMenuBar;
181 @synthesize javaMinSize;
182 @synthesize javaMaxSize;
183 @synthesize styleBits;
184 @synthesize isEnabled;
185 @synthesize ownerWindow;
186 @synthesize preFullScreenLevel;
187 @synthesize standardFrame;
188 @synthesize isMinimizing;
189
190 - (void) updateMinMaxSize:(BOOL)resizable {
191 if (resizable) {
192 [self.nsWindow setMinSize:self.javaMinSize];
193 [self.nsWindow setMaxSize:self.javaMaxSize];
194 } else {
195 NSRect currentFrame = [self.nsWindow frame];
196 [self.nsWindow setMinSize:currentFrame.size];
197 [self.nsWindow setMaxSize:currentFrame.size];
198 }
199 }
200
201 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
202 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
203 NSUInteger type = 0;
204 if (IS(styleBits, DECORATED)) {
205 type |= NSTitledWindowMask;
206 if (IS(styleBits, CLOSEABLE)) type |= NSClosableWindowMask;
207 if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
208 if (IS(styleBits, RESIZABLE)) type |= NSResizableWindowMask;
302 IS(bits, HIDES_ON_DEACTIVATE) ||
303 IS(bits, SHEET))
304 {
305 self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
306 frameRect:contentRect
307 styleMask:styleMask
308 contentView:view];
309 }
310 else
311 {
312 // These windows will appear in the window list in the dock icon menu
313 self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
314 frameRect:contentRect
315 styleMask:styleMask
316 contentView:view];
317 }
318
319 if (self.nsWindow == nil) return nil; // no hope either
320 [self.nsWindow release]; // the property retains the object already
321
322 self.isEnabled = YES;
323 self.isMinimizing = NO;
324 self.javaPlatformWindow = platformWindow;
325 self.styleBits = bits;
326 self.ownerWindow = owner;
327 [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
328
329 if (IS(self.styleBits, IS_POPUP)) {
330 [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/];
331 }
332
333 if (IS(bits, SHEET) && owner != nil) {
334 [self.nsWindow setStyleMask: NSWindowStyleMaskDocModalWindow];
335 }
336
337 return self;
338 }
339
340 + (BOOL) isAWTWindow:(NSWindow *)window {
341 return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
730 }
731
732 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
733 //AWT_ASSERT_APPKIT_THREAD;
734 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
735 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
736 if (platformWindow != NULL) {
737 jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
738
739 static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
740 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
741 (*env)->DeleteLocalRef(env, platformWindow);
742 (*env)->DeleteLocalRef(env, oppositeWindow);
743 }
744 }
745
746 - (void) windowDidBecomeMain: (NSNotification *) notification {
747 AWT_ASSERT_APPKIT_THREAD;
748 [AWTToolkit eventCountPlusPlus];
749 #ifdef DEBUG
750 NSLog(@"became main: %d %@ %@", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow]);
751 #endif
752
753 if (![self.nsWindow isKeyWindow]) {
754 [self activateWindowMenuBar];
755 }
756
757 JNIEnv *env = [ThreadUtilities getJNIEnv];
758 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
759 if (platformWindow != NULL) {
760 static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
761 JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
762 (*env)->DeleteLocalRef(env, platformWindow);
763 }
764 }
765
766 - (void) windowDidBecomeKey: (NSNotification *) notification {
767 AWT_ASSERT_APPKIT_THREAD;
768 [AWTToolkit eventCountPlusPlus];
769 #ifdef DEBUG
770 NSLog(@"became key: %d %@ %@", [self.nsWindow isMainWindow], [self.nsWindow title], [self menuBarForWindow]);
771 #endif
772 AWTWindow *opposite = [AWTWindow lastKeyWindow];
773
774 if (![self.nsWindow isMainWindow]) {
775 [self activateWindowMenuBar];
776 }
777
778 [AWTWindow setLastKeyWindow:nil];
779
780 [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
781 [self orderChildWindows:YES];
782 }
783
784 - (void) activateWindowMenuBar {
785 AWT_ASSERT_APPKIT_THREAD;
786 // Finds appropriate menubar in our hierarchy
787 AWTWindow *awtWindow = self;
788 while (awtWindow.ownerWindow != nil) {
789 awtWindow = awtWindow.ownerWindow;
790 }
791
|
169 @implementation AWTWindow_Panel
170 AWT_NS_WINDOW_IMPLEMENTATION
171 @end
172 // END of NSWindow/NSPanel descendants implementation
173 // --------------------------------------------------------------
174
175
176 @implementation AWTWindow
177
178 @synthesize nsWindow;
179 @synthesize javaPlatformWindow;
180 @synthesize javaMenuBar;
181 @synthesize javaMinSize;
182 @synthesize javaMaxSize;
183 @synthesize styleBits;
184 @synthesize isEnabled;
185 @synthesize ownerWindow;
186 @synthesize preFullScreenLevel;
187 @synthesize standardFrame;
188 @synthesize isMinimizing;
189 @synthesize keyNotificationRecd;
190
191 - (void) updateMinMaxSize:(BOOL)resizable {
192 if (resizable) {
193 [self.nsWindow setMinSize:self.javaMinSize];
194 [self.nsWindow setMaxSize:self.javaMaxSize];
195 } else {
196 NSRect currentFrame = [self.nsWindow frame];
197 [self.nsWindow setMinSize:currentFrame.size];
198 [self.nsWindow setMaxSize:currentFrame.size];
199 }
200 }
201
202 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
203 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
204 NSUInteger type = 0;
205 if (IS(styleBits, DECORATED)) {
206 type |= NSTitledWindowMask;
207 if (IS(styleBits, CLOSEABLE)) type |= NSClosableWindowMask;
208 if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
209 if (IS(styleBits, RESIZABLE)) type |= NSResizableWindowMask;
303 IS(bits, HIDES_ON_DEACTIVATE) ||
304 IS(bits, SHEET))
305 {
306 self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
307 frameRect:contentRect
308 styleMask:styleMask
309 contentView:view];
310 }
311 else
312 {
313 // These windows will appear in the window list in the dock icon menu
314 self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
315 frameRect:contentRect
316 styleMask:styleMask
317 contentView:view];
318 }
319
320 if (self.nsWindow == nil) return nil; // no hope either
321 [self.nsWindow release]; // the property retains the object already
322
323 self.keyNotificationRecd = NO;
324 self.isEnabled = YES;
325 self.isMinimizing = NO;
326 self.javaPlatformWindow = platformWindow;
327 self.styleBits = bits;
328 self.ownerWindow = owner;
329 [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
330
331 if (IS(self.styleBits, IS_POPUP)) {
332 [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/];
333 }
334
335 if (IS(bits, SHEET) && owner != nil) {
336 [self.nsWindow setStyleMask: NSWindowStyleMaskDocModalWindow];
337 }
338
339 return self;
340 }
341
342 + (BOOL) isAWTWindow:(NSWindow *)window {
343 return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
732 }
733
734 - (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
735 //AWT_ASSERT_APPKIT_THREAD;
736 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
737 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
738 if (platformWindow != NULL) {
739 jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
740
741 static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
742 JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
743 (*env)->DeleteLocalRef(env, platformWindow);
744 (*env)->DeleteLocalRef(env, oppositeWindow);
745 }
746 }
747
748 - (void) windowDidBecomeMain: (NSNotification *) notification {
749 AWT_ASSERT_APPKIT_THREAD;
750 [AWTToolkit eventCountPlusPlus];
751 #ifdef DEBUG
752 NSLog(@"became main: %d %@ %@ %d", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow], self.keyNotificationRecd);
753 #endif
754
755 // if for some reason, no KEY notification is received but this main window is also a key window
756 // then we need to execute the KEY notification functionality.
757 if(self.keyNotificationRecd != YES && [self.nsWindow isKeyWindow]) {
758 [self doWindowDidBecomeKey];
759 }
760 self.keyNotificationRecd = NO;
761
762 if (![self.nsWindow isKeyWindow]) {
763 [self activateWindowMenuBar];
764 }
765
766 JNIEnv *env = [ThreadUtilities getJNIEnv];
767 jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
768 if (platformWindow != NULL) {
769 static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
770 JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
771 (*env)->DeleteLocalRef(env, platformWindow);
772 }
773 }
774
775 - (void) windowDidBecomeKey: (NSNotification *) notification {
776 AWT_ASSERT_APPKIT_THREAD;
777 [AWTToolkit eventCountPlusPlus];
778 #ifdef DEBUG
779 NSLog(@"became key: %d %@ %@", [self.nsWindow isMainWindow], [self.nsWindow title], [self menuBarForWindow]);
780 #endif
781 [self doWindowDidBecomeKey];
782 self.keyNotificationRecd = YES;
783 }
784
785 - (void) doWindowDidBecomeKey {
786 AWT_ASSERT_APPKIT_THREAD;
787 AWTWindow *opposite = [AWTWindow lastKeyWindow];
788
789 if (![self.nsWindow isMainWindow]) {
790 [self activateWindowMenuBar];
791 }
792
793 [AWTWindow setLastKeyWindow:nil];
794
795 [self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
796 [self orderChildWindows:YES];
797 }
798
799 - (void) activateWindowMenuBar {
800 AWT_ASSERT_APPKIT_THREAD;
801 // Finds appropriate menubar in our hierarchy
802 AWTWindow *awtWindow = self;
803 while (awtWindow.ownerWindow != nil) {
804 awtWindow = awtWindow.ownerWindow;
805 }
806
|