38 39 #define MASK(KEY) \ 40 (sun_lwawt_macosx_CPlatformWindow_ ## KEY) 41 42 #define IS(BITS, KEY) \ 43 ((BITS & MASK(KEY)) != 0) 44 45 #define SET(BITS, KEY, VALUE) \ 46 BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) 47 48 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); 49 50 // Cocoa windowDidBecomeKey/windowDidResignKey notifications 51 // doesn't provide information about "opposite" window, so we 52 // have to do a bit of tracking. This variable points to a window 53 // which had been the key window just before a new key window 54 // was set. It would be nil if the new key window isn't an AWT 55 // window or the app currently has no key window. 56 static AWTWindow* lastKeyWindow = nil; 57 58 // -------------------------------------------------------------- 59 // NSWindow/NSPanel descendants implementation 60 #define AWT_NS_WINDOW_IMPLEMENTATION \ 61 - (id) initWithDelegate:(AWTWindow *)delegate \ 62 frameRect:(NSRect)contectRect \ 63 styleMask:(NSUInteger)styleMask \ 64 contentView:(NSView *)view \ 65 { \ 66 self = [super initWithContentRect:contectRect \ 67 styleMask:styleMask \ 68 backing:NSBackingStoreBuffered \ 69 defer:NO]; \ 70 \ 71 if (self == nil) return nil; \ 72 \ 73 [self setDelegate:delegate]; \ 74 [self setContentView:view]; \ 75 [self setInitialFirstResponder:view]; \ 76 [self setReleasedWhenClosed:NO]; \ 77 [self setPreservesContentDuringLiveResize:YES]; \ 1067 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, 1068 jdouble width, jdouble height) 1069 { 1070 JNF_COCOA_ENTER(env); 1071 1072 NSRect jrect = NSMakeRect(originX, originY, width, height); 1073 1074 NSWindow *nsWindow = OBJC(windowPtr); 1075 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1076 1077 NSRect rect = ConvertNSScreenRect(NULL, jrect); 1078 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1079 window.standardFrame = rect; 1080 }]; 1081 1082 JNF_COCOA_EXIT(env); 1083 } 1084 1085 /* 1086 * Class: sun_lwawt_macosx_CPlatformWindow 1087 * Method: nativeSetNSWindowMinMax 1088 * Signature: (JDDDD)V 1089 */ 1090 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 1091 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 1092 { 1093 JNF_COCOA_ENTER(env); 1094 1095 if (minW < 1) minW = 1; 1096 if (minH < 1) minH = 1; 1097 if (maxW < 1) maxW = 1; 1098 if (maxH < 1) maxH = 1; 1099 1100 NSWindow *nsWindow = OBJC(windowPtr); 1101 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1102 1103 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1104 1105 NSSize min = { minW, minH }; 1106 NSSize max = { maxW, maxH }; | 38 39 #define MASK(KEY) \ 40 (sun_lwawt_macosx_CPlatformWindow_ ## KEY) 41 42 #define IS(BITS, KEY) \ 43 ((BITS & MASK(KEY)) != 0) 44 45 #define SET(BITS, KEY, VALUE) \ 46 BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) 47 48 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); 49 50 // Cocoa windowDidBecomeKey/windowDidResignKey notifications 51 // doesn't provide information about "opposite" window, so we 52 // have to do a bit of tracking. This variable points to a window 53 // which had been the key window just before a new key window 54 // was set. It would be nil if the new key window isn't an AWT 55 // window or the app currently has no key window. 56 static AWTWindow* lastKeyWindow = nil; 57 58 // This variable contains coordinates of a window's top left 59 // which was positioned via java.awt.Window.setLocationByPlatform. 60 // It would be NSZeroPoint if 'Location by Platform' is not used. 61 static NSPoint lastTopLeftPoint; 62 63 // -------------------------------------------------------------- 64 // NSWindow/NSPanel descendants implementation 65 #define AWT_NS_WINDOW_IMPLEMENTATION \ 66 - (id) initWithDelegate:(AWTWindow *)delegate \ 67 frameRect:(NSRect)contectRect \ 68 styleMask:(NSUInteger)styleMask \ 69 contentView:(NSView *)view \ 70 { \ 71 self = [super initWithContentRect:contectRect \ 72 styleMask:styleMask \ 73 backing:NSBackingStoreBuffered \ 74 defer:NO]; \ 75 \ 76 if (self == nil) return nil; \ 77 \ 78 [self setDelegate:delegate]; \ 79 [self setContentView:view]; \ 80 [self setInitialFirstResponder:view]; \ 81 [self setReleasedWhenClosed:NO]; \ 82 [self setPreservesContentDuringLiveResize:YES]; \ 1072 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, 1073 jdouble width, jdouble height) 1074 { 1075 JNF_COCOA_ENTER(env); 1076 1077 NSRect jrect = NSMakeRect(originX, originY, width, height); 1078 1079 NSWindow *nsWindow = OBJC(windowPtr); 1080 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1081 1082 NSRect rect = ConvertNSScreenRect(NULL, jrect); 1083 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1084 window.standardFrame = rect; 1085 }]; 1086 1087 JNF_COCOA_EXIT(env); 1088 } 1089 1090 /* 1091 * Class: sun_lwawt_macosx_CPlatformWindow 1092 * Method: nativeSetNSWindowLocationByPlatform 1093 * Signature: (J)V 1094 */ 1095 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform 1096 (JNIEnv *env, jclass clazz, jlong windowPtr) 1097 { 1098 JNF_COCOA_ENTER(env); 1099 1100 NSWindow *nsWindow = OBJC(windowPtr); 1101 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1102 1103 if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) { 1104 // This is the first usage of lastTopLeftPoint. So invoke cascadeTopLeftFromPoint 1105 // twice to avoid positioning the window's top left to zero-point, since it may 1106 // cause negative user experience. 1107 lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint]; 1108 } 1109 lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint]; 1110 }]; 1111 1112 JNF_COCOA_EXIT(env); 1113 } 1114 1115 /* 1116 * Class: sun_lwawt_macosx_CPlatformWindow 1117 * Method: nativeSetNSWindowMinMax 1118 * Signature: (JDDDD)V 1119 */ 1120 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 1121 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 1122 { 1123 JNF_COCOA_ENTER(env); 1124 1125 if (minW < 1) minW = 1; 1126 if (minH < 1) minH = 1; 1127 if (maxW < 1) maxW = 1; 1128 if (maxH < 1) maxH = 1; 1129 1130 NSWindow *nsWindow = OBJC(windowPtr); 1131 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1132 1133 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1134 1135 NSSize min = { minW, minH }; 1136 NSSize max = { maxW, maxH }; |