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

Print this page




 106 AWT_NS_WINDOW_IMPLEMENTATION
 107 @end
 108 @implementation AWTWindow_Panel
 109 AWT_NS_WINDOW_IMPLEMENTATION
 110 @end
 111 // END of NSWindow/NSPanel descendants implementation
 112 // --------------------------------------------------------------
 113 
 114 
 115 @implementation AWTWindow
 116 
 117 @synthesize nsWindow;
 118 @synthesize javaPlatformWindow;
 119 @synthesize javaMenuBar;
 120 @synthesize javaMinSize;
 121 @synthesize javaMaxSize;
 122 @synthesize styleBits;
 123 @synthesize isEnabled;
 124 @synthesize ownerWindow;
 125 @synthesize preFullScreenLevel;

 126 
 127 - (void) updateMinMaxSize:(BOOL)resizable {
 128     if (resizable) {
 129         [self.nsWindow setMinSize:self.javaMinSize];
 130         [self.nsWindow setMaxSize:self.javaMaxSize];
 131     } else {
 132         NSRect currentFrame = [self.nsWindow frame];
 133         [self.nsWindow setMinSize:currentFrame.size];
 134         [self.nsWindow setMaxSize:currentFrame.size];
 135     }
 136 }
 137 
 138 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
 139 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
 140     NSUInteger type = 0;
 141     if (IS(styleBits, DECORATED)) {
 142         type |= NSTitledWindowMask;
 143         if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
 144         if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
 145         if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;


 234                             styleMask:styleMask
 235                           contentView:view];
 236     }
 237     else
 238     {
 239         // These windows will appear in the window list in the dock icon menu
 240         self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
 241                             frameRect:contentRect
 242                             styleMask:styleMask
 243                           contentView:view];
 244     }
 245 
 246     if (self.nsWindow == nil) return nil; // no hope either
 247     [self.nsWindow release]; // the property retains the object already
 248 
 249     self.isEnabled = YES;
 250     self.javaPlatformWindow = platformWindow;
 251     self.styleBits = bits;
 252     self.ownerWindow = owner;
 253     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];

 254 
 255     return self;
 256 }
 257 
 258 + (BOOL) isAWTWindow:(NSWindow *)window {
 259     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 260 }
 261 
 262 // returns id for the topmost window under mouse
 263 + (NSInteger) getTopmostWindowUnderMouseID {
 264 
 265     NSRect screenRect = [[NSScreen mainScreen] frame];
 266     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 267     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 268 
 269     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 270 
 271     for (NSDictionary *window in windows) {
 272         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 273         if (layer == 0) {


 749     if (IS(self.styleBits, RESIZABLE)) {
 750         [self updateMinMaxSize:flag];
 751         [self.nsWindow setShowsResizeIndicator:flag];
 752     }
 753 }
 754 
 755 + (void) setLastKeyWindow:(AWTWindow *)window {
 756     [window retain];
 757     [lastKeyWindow release];
 758     lastKeyWindow = window;
 759 }
 760 
 761 + (AWTWindow *) lastKeyWindow {
 762     return lastKeyWindow;
 763 }
 764 
 765 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
 766     return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
 767 }
 768 



































 769 
 770 @end // AWTWindow
 771 
 772 
 773 /*
 774  * Class:     sun_lwawt_macosx_CPlatformWindow
 775  * Method:    nativeCreateNSWindow
 776  * Signature: (JJIIII)J
 777  */
 778 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
 779 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
 780 {
 781     __block AWTWindow *window = nil;
 782 
 783 JNF_COCOA_ENTER(env);
 784 
 785     JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
 786     NSView *contentView = OBJC(contentViewPtr);
 787     NSRect frameRect = NSMakeRect(x, y, w, h);
 788     AWTWindow *owner = [OBJC(ownerPtr) delegate];


 962     NSWindow *nsWindow = OBJC(windowPtr);
 963     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 964 
 965         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
 966 
 967         NSSize min = { minW, minH };
 968         NSSize max = { maxW, maxH };
 969 
 970         [window constrainSize:&min];
 971         [window constrainSize:&max];
 972 
 973         window.javaMinSize = min;
 974         window.javaMaxSize = max;
 975         [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
 976     }];
 977 
 978 JNF_COCOA_EXIT(env);
 979 }
 980 
 981 /*

























 982  * Class:     sun_lwawt_macosx_CPlatformWindow
 983  * Method:    nativePushNSWindowToBack
 984  * Signature: (J)V
 985  */
 986 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
 987 (JNIEnv *env, jclass clazz, jlong windowPtr)
 988 {
 989 JNF_COCOA_ENTER(env);
 990 
 991     NSWindow *nsWindow = OBJC(windowPtr);
 992     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 993         [nsWindow orderBack:nil];
 994     }];
 995 
 996 JNF_COCOA_EXIT(env);
 997 }
 998 
 999 /*
1000  * Class:     sun_lwawt_macosx_CPlatformWindow
1001  * Method:    nativePushNSWindowToFront




 106 AWT_NS_WINDOW_IMPLEMENTATION
 107 @end
 108 @implementation AWTWindow_Panel
 109 AWT_NS_WINDOW_IMPLEMENTATION
 110 @end
 111 // END of NSWindow/NSPanel descendants implementation
 112 // --------------------------------------------------------------
 113 
 114 
 115 @implementation AWTWindow
 116 
 117 @synthesize nsWindow;
 118 @synthesize javaPlatformWindow;
 119 @synthesize javaMenuBar;
 120 @synthesize javaMinSize;
 121 @synthesize javaMaxSize;
 122 @synthesize styleBits;
 123 @synthesize isEnabled;
 124 @synthesize ownerWindow;
 125 @synthesize preFullScreenLevel;
 126 @synthesize javaMaximizedBounds = _javaMaximizedBounds;
 127 
 128 - (void) updateMinMaxSize:(BOOL)resizable {
 129     if (resizable) {
 130         [self.nsWindow setMinSize:self.javaMinSize];
 131         [self.nsWindow setMaxSize:self.javaMaxSize];
 132     } else {
 133         NSRect currentFrame = [self.nsWindow frame];
 134         [self.nsWindow setMinSize:currentFrame.size];
 135         [self.nsWindow setMaxSize:currentFrame.size];
 136     }
 137 }
 138 
 139 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
 140 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
 141     NSUInteger type = 0;
 142     if (IS(styleBits, DECORATED)) {
 143         type |= NSTitledWindowMask;
 144         if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
 145         if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
 146         if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;


 235                             styleMask:styleMask
 236                           contentView:view];
 237     }
 238     else
 239     {
 240         // These windows will appear in the window list in the dock icon menu
 241         self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
 242                             frameRect:contentRect
 243                             styleMask:styleMask
 244                           contentView:view];
 245     }
 246 
 247     if (self.nsWindow == nil) return nil; // no hope either
 248     [self.nsWindow release]; // the property retains the object already
 249 
 250     self.isEnabled = YES;
 251     self.javaPlatformWindow = platformWindow;
 252     self.styleBits = bits;
 253     self.ownerWindow = owner;
 254     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 255     self.javaMaximizedBounds = NSMakeRect(-1, -1, -1, -1);
 256 
 257     return self;
 258 }
 259 
 260 + (BOOL) isAWTWindow:(NSWindow *)window {
 261     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
 262 }
 263 
 264 // returns id for the topmost window under mouse
 265 + (NSInteger) getTopmostWindowUnderMouseID {
 266 
 267     NSRect screenRect = [[NSScreen mainScreen] frame];
 268     NSPoint nsMouseLocation = [NSEvent mouseLocation];
 269     CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
 270 
 271     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
 272 
 273     for (NSDictionary *window in windows) {
 274         NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
 275         if (layer == 0) {


 751     if (IS(self.styleBits, RESIZABLE)) {
 752         [self updateMinMaxSize:flag];
 753         [self.nsWindow setShowsResizeIndicator:flag];
 754     }
 755 }
 756 
 757 + (void) setLastKeyWindow:(AWTWindow *)window {
 758     [window retain];
 759     [lastKeyWindow release];
 760     lastKeyWindow = window;
 761 }
 762 
 763 + (AWTWindow *) lastKeyWindow {
 764     return lastKeyWindow;
 765 }
 766 
 767 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
 768     return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
 769 }
 770 
 771 - (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame {
 772     CGFloat newWidth;
 773     if (self.javaMaximizedBounds.size.width < 0) {
 774         newWidth = newFrame.size.width;
 775     } else {
 776         newWidth = self.javaMaximizedBounds.size.width;
 777         if (newWidth < self.javaMinSize.width) {
 778             newWidth = self.javaMinSize.width;
 779         }
 780         if (newWidth > self.javaMaxSize.width) {
 781             newWidth = self.javaMaxSize.width;
 782         }
 783     }
 784   
 785     CGFloat newHeight;
 786     if (self.javaMaximizedBounds.size.height < 0) {
 787         newHeight = newFrame.size.height;
 788     } else {
 789         newHeight = self.javaMaximizedBounds.size.height;
 790         if (newHeight < self.javaMinSize.height) {
 791             newHeight = self.javaMinSize.height;
 792         }
 793         if (newHeight > self.javaMaxSize.height) {
 794             newHeight = self.javaMaxSize.height;
 795         }
 796     }
 797     
 798     newFrame.size = NSMakeSize(newWidth, newHeight);
 799     newFrame.origin = NSMakePoint(self.javaMaximizedBounds.origin.x < 0 ? newFrame.origin.x
 800                                         : self.javaMaximizedBounds.origin.x,
 801                                   self.javaMaximizedBounds.origin.y < 0 ? newFrame.origin.y
 802                                         : self.javaMaximizedBounds.origin.y);
 803     return newFrame;
 804 }
 805 
 806 
 807 @end // AWTWindow
 808 
 809 
 810 /*
 811  * Class:     sun_lwawt_macosx_CPlatformWindow
 812  * Method:    nativeCreateNSWindow
 813  * Signature: (JJIIII)J
 814  */
 815 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
 816 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
 817 {
 818     __block AWTWindow *window = nil;
 819 
 820 JNF_COCOA_ENTER(env);
 821 
 822     JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
 823     NSView *contentView = OBJC(contentViewPtr);
 824     NSRect frameRect = NSMakeRect(x, y, w, h);
 825     AWTWindow *owner = [OBJC(ownerPtr) delegate];


 999     NSWindow *nsWindow = OBJC(windowPtr);
1000     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1001 
1002         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1003 
1004         NSSize min = { minW, minH };
1005         NSSize max = { maxW, maxH };
1006 
1007         [window constrainSize:&min];
1008         [window constrainSize:&max];
1009 
1010         window.javaMinSize = min;
1011         window.javaMaxSize = max;
1012         [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
1013     }];
1014 
1015 JNF_COCOA_EXIT(env);
1016 }
1017 
1018 /*
1019  *
1020  * Class:     sun_lwawt_macosx_CPlatformWindow
1021  * Method:    nativeSetMaximizedBounds
1022  * Signature: (JIIII)V
1023  */
1024 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetMaximizedBounds
1025 (JNIEnv *env, jclass clazz, jlong windowPtr, jint x, jint y, jint w, jint h)
1026 {
1027     JNF_COCOA_ENTER(env);
1028     
1029     NSWindow *nsWindow = OBJC(windowPtr);
1030     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1031         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1032         NSRect rect = NSMakeRect(x, y, w, h);
1033         if (y >= 0) {
1034             rect = ConvertNSScreenRect([ThreadUtilities getJNIEnv], rect);
1035         }
1036         window.javaMaximizedBounds = rect;
1037     }];
1038     
1039     JNF_COCOA_EXIT(env);
1040 }
1041 
1042 
1043 /*
1044  * Class:     sun_lwawt_macosx_CPlatformWindow
1045  * Method:    nativePushNSWindowToBack
1046  * Signature: (J)V
1047  */
1048 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
1049 (JNIEnv *env, jclass clazz, jlong windowPtr)
1050 {
1051 JNF_COCOA_ENTER(env);
1052 
1053     NSWindow *nsWindow = OBJC(windowPtr);
1054     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1055         [nsWindow orderBack:nil];
1056     }];
1057 
1058 JNF_COCOA_EXIT(env);
1059 }
1060 
1061 /*
1062  * Class:     sun_lwawt_macosx_CPlatformWindow
1063  * Method:    nativePushNSWindowToFront