721 722 + (AWTWindow *) lastKeyWindow { 723 return lastKeyWindow; 724 } 725 726 727 @end // AWTWindow 728 729 730 /* 731 * Class: sun_lwawt_macosx_CPlatformWindow 732 * Method: nativeCreateNSWindow 733 * Signature: (JJIIII)J 734 */ 735 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow 736 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h) 737 { 738 __block AWTWindow *window = nil; 739 740 JNF_COCOA_ENTER(env); 741 AWT_ASSERT_NOT_APPKIT_THREAD; 742 743 JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; 744 NSView *contentView = OBJC(contentViewPtr); 745 NSRect frameRect = NSMakeRect(x, y, w, h); 746 747 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 748 AWT_ASSERT_APPKIT_THREAD; 749 750 window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow 751 styleBits:styleBits 752 frameRect:frameRect 753 contentView:contentView]; 754 // the window is released is CPlatformWindow.nativeDispose() 755 756 if (window) CFRetain(window.nsWindow); 757 }]; 758 759 JNF_COCOA_EXIT(env); 760 761 return ptr_to_jlong(window ? window.nsWindow : nil); 762 } 763 764 /* 765 * Class: sun_lwawt_macosx_CPlatformWindow 766 * Method: nativeSetNSWindowStyleBits 767 * Signature: (JII)V 768 */ 769 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits 770 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) 771 { 772 JNF_COCOA_ENTER(env); 773 AWT_ASSERT_NOT_APPKIT_THREAD; 774 775 NSWindow *nsWindow = OBJC(windowPtr); 776 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 777 AWT_ASSERT_APPKIT_THREAD; 778 779 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 780 781 // scans the bit field, and only updates the values requested by the mask 782 // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) 783 jint newBits = window.styleBits & ~mask | bits & mask; 784 785 // resets the NSWindow's style mask if the mask intersects any of those bits 786 if (mask & MASK(_STYLE_PROP_BITMASK)) { 787 [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; 788 } 789 790 // calls methods on NSWindow to change other properties, based on the mask 791 if (mask & MASK(_METHOD_PROP_BITMASK)) { 792 [window setPropertiesForStyleBits:newBits mask:mask]; 793 } 794 795 window.styleBits = newBits; 796 }]; 797 798 JNF_COCOA_EXIT(env); 799 } 800 801 /* 802 * Class: sun_lwawt_macosx_CPlatformWindow 803 * Method: nativeSetNSWindowMenuBar 804 * Signature: (JJ)V 805 */ 806 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar 807 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) 808 { 809 JNF_COCOA_ENTER(env); 810 AWT_ASSERT_NOT_APPKIT_THREAD; 811 812 NSWindow *nsWindow = OBJC(windowPtr); 813 CMenuBar *menuBar = OBJC(menuBarPtr); 814 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 815 AWT_ASSERT_APPKIT_THREAD; 816 817 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 818 819 if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; 820 window.javaMenuBar = menuBar; 821 822 // if ([self isKeyWindow]) { 823 [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; 824 // } 825 }]; 826 827 JNF_COCOA_EXIT(env); 828 } 829 830 /* 831 * Class: sun_lwawt_macosx_CPlatformWindow 832 * Method: nativeGetNSWindowInsets 833 * Signature: (J)Ljava/awt/Insets; 834 */ 835 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets 836 (JNIEnv *env, jclass clazz, jlong windowPtr) 837 { 838 jobject ret = NULL; 839 840 JNF_COCOA_ENTER(env); 841 AWT_ASSERT_NOT_APPKIT_THREAD; 842 843 NSWindow *nsWindow = OBJC(windowPtr); 844 __block NSRect contentRect = NSZeroRect; 845 __block NSRect frame = NSZeroRect; 846 847 [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ 848 AWT_ASSERT_APPKIT_THREAD; 849 850 frame = [nsWindow frame]; 851 contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]]; 852 }]; 853 854 jint top = (jint)(frame.size.height - contentRect.size.height); 855 jint left = (jint)(contentRect.origin.x - frame.origin.x); 856 jint bottom = (jint)(contentRect.origin.y - frame.origin.y); 857 jint right = (jint)(frame.size.width - (contentRect.size.width + left)); 858 859 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); 860 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); 861 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); 862 863 JNF_COCOA_EXIT(env); 864 return ret; 865 } 866 867 /* 868 * Class: sun_lwawt_macosx_CPlatformWindow 869 * Method: nativeSetNSWindowBounds 870 * Signature: (JDDDD)V 871 */ 872 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds 873 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) 874 { 875 JNF_COCOA_ENTER(env); 876 AWT_ASSERT_NOT_APPKIT_THREAD; 877 878 NSRect jrect = NSMakeRect(originX, originY, width, height); 879 880 // TODO: not sure we need displayIfNeeded message in our view 881 NSWindow *nsWindow = OBJC(windowPtr); 882 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 883 AWT_ASSERT_APPKIT_THREAD; 884 885 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 886 887 NSRect rect = ConvertNSScreenRect(NULL, jrect); 888 [window constrainSize:&rect.size]; 889 890 [nsWindow setFrame:rect display:YES]; 891 892 // only start tracking events if pointer is above the toplevel 893 // TODO: should post an Entered event if YES. 894 NSPoint mLocation = [NSEvent mouseLocation]; 895 [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; 896 897 // ensure we repaint the whole window after the resize operation 898 // (this will also re-enable screen updates, which were disabled above) 899 // TODO: send PaintEvent 900 901 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 902 }]; 903 904 JNF_COCOA_EXIT(env); 905 } 906 907 /* 908 * Class: sun_lwawt_macosx_CPlatformWindow 909 * Method: nativeSetNSWindowMinMax 910 * Signature: (JDDDD)V 911 */ 912 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 913 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 914 { 915 JNF_COCOA_ENTER(env); 916 AWT_ASSERT_NOT_APPKIT_THREAD; 917 918 if (minW < 1) minW = 1; 919 if (minH < 1) minH = 1; 920 if (maxW < 1) maxW = 1; 921 if (maxH < 1) maxH = 1; 922 923 NSWindow *nsWindow = OBJC(windowPtr); 924 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 925 AWT_ASSERT_APPKIT_THREAD; 926 927 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 928 929 NSSize min = { minW, minH }; 930 NSSize max = { maxW, maxH }; 931 932 [window constrainSize:&min]; 933 [window constrainSize:&max]; 934 935 window.javaMinSize = min; 936 window.javaMaxSize = max; 937 [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; 938 }]; 939 940 JNF_COCOA_EXIT(env); 941 } 942 943 /* 944 * Class: sun_lwawt_macosx_CPlatformWindow 945 * Method: nativePushNSWindowToBack 946 * Signature: (J)V 947 */ 948 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack 949 (JNIEnv *env, jclass clazz, jlong windowPtr) 950 { 951 JNF_COCOA_ENTER(env); 952 AWT_ASSERT_NOT_APPKIT_THREAD; 953 954 NSWindow *nsWindow = OBJC(windowPtr); 955 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 956 AWT_ASSERT_APPKIT_THREAD; 957 958 [nsWindow orderBack:nil]; 959 }]; 960 961 JNF_COCOA_EXIT(env); 962 } 963 964 /* 965 * Class: sun_lwawt_macosx_CPlatformWindow 966 * Method: nativePushNSWindowToFront 967 * Signature: (J)V 968 */ 969 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront 970 (JNIEnv *env, jclass clazz, jlong windowPtr) 971 { 972 JNF_COCOA_ENTER(env); 973 AWT_ASSERT_NOT_APPKIT_THREAD; 974 975 NSWindow *nsWindow = OBJC(windowPtr); 976 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 977 AWT_ASSERT_APPKIT_THREAD; 978 979 if (![nsWindow isKeyWindow]) { 980 [nsWindow makeKeyAndOrderFront:nsWindow]; 981 } else { 982 [nsWindow orderFront:nsWindow]; 983 } 984 }]; 985 986 JNF_COCOA_EXIT(env); 987 } 988 989 /* 990 * Class: sun_lwawt_macosx_CPlatformWindow 991 * Method: nativeSetNSWindowTitle 992 * Signature: (JLjava/lang/String;)V 993 */ 994 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle 995 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) 996 { 997 JNF_COCOA_ENTER(env); 998 AWT_ASSERT_NOT_APPKIT_THREAD; 999 1000 NSWindow *nsWindow = OBJC(windowPtr); 1001 [nsWindow performSelectorOnMainThread:@selector(setTitle:) 1002 withObject:JNFJavaToNSString(env, jtitle) 1003 waitUntilDone:NO]; 1004 1005 JNF_COCOA_EXIT(env); 1006 } 1007 1008 /* 1009 * Class: sun_lwawt_macosx_CPlatformWindow 1010 * Method: nativeRevalidateNSWindowShadow 1011 * Signature: (J)V 1012 */ 1013 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow 1014 (JNIEnv *env, jclass clazz, jlong windowPtr) 1015 { 1016 JNF_COCOA_ENTER(env); 1017 1018 NSWindow *nsWindow = OBJC(windowPtr); 1019 if ([NSThread isMainThread]) { 1020 [nsWindow invalidateShadow]; 1021 } else { 1022 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1023 AWT_ASSERT_APPKIT_THREAD; 1024 1025 [nsWindow invalidateShadow]; 1026 }]; 1027 } 1028 1029 JNF_COCOA_EXIT(env); 1030 } 1031 1032 /* 1033 * Class: sun_lwawt_macosx_CPlatformWindow 1034 * Method: nativeScreenOn_AppKitThread 1035 * Signature: (J)I 1036 */ 1037 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread 1038 (JNIEnv *env, jclass clazz, jlong windowPtr) 1039 { 1040 jint ret = 0; 1041 1042 JNF_COCOA_ENTER(env); 1043 AWT_ASSERT_APPKIT_THREAD; 1044 1045 NSWindow *nsWindow = OBJC(windowPtr); 1046 NSDictionary *props = [[nsWindow screen] deviceDescription]; 1047 ret = [[props objectForKey:@"NSScreenNumber"] intValue]; 1048 1049 JNF_COCOA_EXIT(env); 1050 1051 return ret; 1052 } 1053 1054 /* 1055 * Class: sun_lwawt_macosx_CPlatformWindow 1056 * Method: nativeSetNSWindowMinimizedIcon 1057 * Signature: (JJ)V 1058 */ 1059 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon 1060 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) 1061 { 1062 JNF_COCOA_ENTER(env); 1063 AWT_ASSERT_NOT_APPKIT_THREAD; 1064 1065 NSWindow *nsWindow = OBJC(windowPtr); 1066 NSImage *image = OBJC(nsImagePtr); 1067 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1068 AWT_ASSERT_APPKIT_THREAD; 1069 1070 [nsWindow setMiniwindowImage:image]; 1071 }]; 1072 1073 JNF_COCOA_EXIT(env); 1074 } 1075 1076 /* 1077 * Class: sun_lwawt_macosx_CPlatformWindow 1078 * Method: nativeSetNSWindowRepresentedFilename 1079 * Signature: (JLjava/lang/String;)V 1080 */ 1081 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename 1082 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) 1083 { 1084 JNF_COCOA_ENTER(env); 1085 AWT_ASSERT_NOT_APPKIT_THREAD; 1086 1087 NSWindow *nsWindow = OBJC(windowPtr); 1088 NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; 1089 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1090 AWT_ASSERT_APPKIT_THREAD; 1091 1092 [nsWindow setRepresentedURL:url]; 1093 }]; 1094 1095 JNF_COCOA_EXIT(env); 1096 } 1097 1098 /* 1099 * Class: sun_lwawt_macosx_CPlatformWindow 1100 * Method: nativeSetNSWindowSecurityWarningPositioning 1101 * Signature: (JDDFF)V 1102 */ 1103 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowSecurityWarningPositioning 1104 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble x, jdouble y, jfloat biasX, jfloat biasY) 1105 { 1106 JNF_COCOA_ENTER(env); 1107 AWT_ASSERT_NOT_APPKIT_THREAD; 1108 1109 [JNFException raise:env as:kRuntimeException reason:"unimplemented"]; 1110 1111 JNF_COCOA_EXIT(env); 1112 } 1113 1114 /* 1115 * Class: sun_lwawt_macosx_CPlatformWindow 1116 * Method: nativeGetTopmostPlatformWindowUnderMouse 1117 * Signature: (J)V 1118 */ 1119 JNIEXPORT jobject 1120 JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse 1121 (JNIEnv *env, jclass clazz) 1122 { 1123 jobject topmostWindowUnderMouse = nil; 1124 1125 JNF_COCOA_ENTER(env); 1126 AWT_ASSERT_APPKIT_THREAD; 1127 1128 AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; 1129 if (awtWindow != nil) { 1130 topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject]; 1131 } 1132 1133 JNF_COCOA_EXIT(env); 1134 1135 return topmostWindowUnderMouse; 1136 } 1137 1138 /* 1139 * Class: sun_lwawt_macosx_CPlatformWindow 1140 * Method: nativeSynthesizeMouseEnteredExitedEvents 1141 * Signature: (J)V 1142 */ 1143 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents 1144 (JNIEnv *env, jclass clazz) 1145 { 1146 JNF_COCOA_ENTER(env); 1147 AWT_ASSERT_NOT_APPKIT_THREAD; 1148 1149 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1150 AWT_ASSERT_APPKIT_THREAD; 1151 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 1152 }]; 1153 1154 JNF_COCOA_EXIT(env); 1155 } 1156 1157 /* 1158 * Class: sun_lwawt_macosx_CPlatformWindow 1159 * Method: _toggleFullScreenMode 1160 * Signature: (J)V 1161 */ 1162 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode 1163 (JNIEnv *env, jobject peer, jlong windowPtr) 1164 { 1165 JNF_COCOA_ENTER(env); 1166 1167 NSWindow *nsWindow = OBJC(windowPtr); 1168 SEL toggleFullScreenSelector = @selector(toggleFullScreen:); 1169 if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return; 1170 1171 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1172 [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; 1173 }]; 1174 1175 JNF_COCOA_EXIT(env); 1176 } 1177 1178 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled 1179 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) 1180 { 1181 JNF_COCOA_ENTER(env); 1182 1183 NSWindow *nsWindow = OBJC(windowPtr); 1184 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1185 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1186 1187 [window setEnabled: isEnabled]; 1188 }]; 1189 1190 JNF_COCOA_EXIT(env); 1191 } 1192 1193 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose 1194 (JNIEnv *env, jclass clazz, jlong windowPtr) 1195 { 1196 JNF_COCOA_ENTER(env); 1197 1198 NSWindow *nsWindow = OBJC(windowPtr); 1199 [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ 1200 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1201 1202 if ([AWTWindow lastKeyWindow] == window) { 1203 [AWTWindow setLastKeyWindow: nil]; 1204 } 1205 1206 // AWTWindow holds a reference to the NSWindow in its nsWindow 1207 // property. Unsetting the delegate allows it to be deallocated 1208 // which releases the reference. This, in turn, allows the window 1209 // itself be deallocated. 1210 [nsWindow setDelegate: nil]; 1211 1212 [window release]; 1213 }]; 1214 1215 JNF_COCOA_EXIT(env); 1216 } 1217 | 721 722 + (AWTWindow *) lastKeyWindow { 723 return lastKeyWindow; 724 } 725 726 727 @end // AWTWindow 728 729 730 /* 731 * Class: sun_lwawt_macosx_CPlatformWindow 732 * Method: nativeCreateNSWindow 733 * Signature: (JJIIII)J 734 */ 735 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow 736 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h) 737 { 738 __block AWTWindow *window = nil; 739 740 JNF_COCOA_ENTER(env); 741 742 JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; 743 NSView *contentView = OBJC(contentViewPtr); 744 NSRect frameRect = NSMakeRect(x, y, w, h); 745 746 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 747 748 window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow 749 styleBits:styleBits 750 frameRect:frameRect 751 contentView:contentView]; 752 // the window is released is CPlatformWindow.nativeDispose() 753 754 if (window) CFRetain(window.nsWindow); 755 }]; 756 757 JNF_COCOA_EXIT(env); 758 759 return ptr_to_jlong(window ? window.nsWindow : nil); 760 } 761 762 /* 763 * Class: sun_lwawt_macosx_CPlatformWindow 764 * Method: nativeSetNSWindowStyleBits 765 * Signature: (JII)V 766 */ 767 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits 768 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) 769 { 770 JNF_COCOA_ENTER(env); 771 772 NSWindow *nsWindow = OBJC(windowPtr); 773 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 774 775 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 776 777 // scans the bit field, and only updates the values requested by the mask 778 // (this implicity handles the _CALLBACK_PROP_BITMASK case, since those are passive reads) 779 jint newBits = window.styleBits & ~mask | bits & mask; 780 781 // resets the NSWindow's style mask if the mask intersects any of those bits 782 if (mask & MASK(_STYLE_PROP_BITMASK)) { 783 [nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]]; 784 } 785 786 // calls methods on NSWindow to change other properties, based on the mask 787 if (mask & MASK(_METHOD_PROP_BITMASK)) { 788 [window setPropertiesForStyleBits:newBits mask:mask]; 789 } 790 791 window.styleBits = newBits; 792 }]; 793 794 JNF_COCOA_EXIT(env); 795 } 796 797 /* 798 * Class: sun_lwawt_macosx_CPlatformWindow 799 * Method: nativeSetNSWindowMenuBar 800 * Signature: (JJ)V 801 */ 802 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar 803 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) 804 { 805 JNF_COCOA_ENTER(env); 806 807 NSWindow *nsWindow = OBJC(windowPtr); 808 CMenuBar *menuBar = OBJC(menuBarPtr); 809 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 810 811 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 812 813 if ([nsWindow isKeyWindow]) [window.javaMenuBar deactivate]; 814 window.javaMenuBar = menuBar; 815 816 // if ([self isKeyWindow]) { 817 [CMenuBar activate:window.javaMenuBar modallyDisabled:NO]; 818 // } 819 }]; 820 821 JNF_COCOA_EXIT(env); 822 } 823 824 /* 825 * Class: sun_lwawt_macosx_CPlatformWindow 826 * Method: nativeGetNSWindowInsets 827 * Signature: (J)Ljava/awt/Insets; 828 */ 829 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets 830 (JNIEnv *env, jclass clazz, jlong windowPtr) 831 { 832 jobject ret = NULL; 833 834 JNF_COCOA_ENTER(env); 835 836 NSWindow *nsWindow = OBJC(windowPtr); 837 __block NSRect contentRect = NSZeroRect; 838 __block NSRect frame = NSZeroRect; 839 840 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 841 842 frame = [nsWindow frame]; 843 contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]]; 844 }]; 845 846 jint top = (jint)(frame.size.height - contentRect.size.height); 847 jint left = (jint)(contentRect.origin.x - frame.origin.x); 848 jint bottom = (jint)(contentRect.origin.y - frame.origin.y); 849 jint right = (jint)(frame.size.width - (contentRect.size.width + left)); 850 851 static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); 852 static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); 853 ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); 854 855 JNF_COCOA_EXIT(env); 856 return ret; 857 } 858 859 /* 860 * Class: sun_lwawt_macosx_CPlatformWindow 861 * Method: nativeSetNSWindowBounds 862 * Signature: (JDDDD)V 863 */ 864 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds 865 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) 866 { 867 JNF_COCOA_ENTER(env); 868 869 NSRect jrect = NSMakeRect(originX, originY, width, height); 870 871 // TODO: not sure we need displayIfNeeded message in our view 872 NSWindow *nsWindow = OBJC(windowPtr); 873 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 874 875 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 876 877 NSRect rect = ConvertNSScreenRect(NULL, jrect); 878 [window constrainSize:&rect.size]; 879 880 [nsWindow setFrame:rect display:YES]; 881 882 // only start tracking events if pointer is above the toplevel 883 // TODO: should post an Entered event if YES. 884 NSPoint mLocation = [NSEvent mouseLocation]; 885 [nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)]; 886 887 // ensure we repaint the whole window after the resize operation 888 // (this will also re-enable screen updates, which were disabled above) 889 // TODO: send PaintEvent 890 891 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 892 }]; 893 894 JNF_COCOA_EXIT(env); 895 } 896 897 /* 898 * Class: sun_lwawt_macosx_CPlatformWindow 899 * Method: nativeSetNSWindowMinMax 900 * Signature: (JDDDD)V 901 */ 902 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax 903 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) 904 { 905 JNF_COCOA_ENTER(env); 906 907 if (minW < 1) minW = 1; 908 if (minH < 1) minH = 1; 909 if (maxW < 1) maxW = 1; 910 if (maxH < 1) maxH = 1; 911 912 NSWindow *nsWindow = OBJC(windowPtr); 913 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 914 915 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 916 917 NSSize min = { minW, minH }; 918 NSSize max = { maxW, maxH }; 919 920 [window constrainSize:&min]; 921 [window constrainSize:&max]; 922 923 window.javaMinSize = min; 924 window.javaMaxSize = max; 925 [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; 926 }]; 927 928 JNF_COCOA_EXIT(env); 929 } 930 931 /* 932 * Class: sun_lwawt_macosx_CPlatformWindow 933 * Method: nativePushNSWindowToBack 934 * Signature: (J)V 935 */ 936 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack 937 (JNIEnv *env, jclass clazz, jlong windowPtr) 938 { 939 JNF_COCOA_ENTER(env); 940 941 NSWindow *nsWindow = OBJC(windowPtr); 942 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 943 [nsWindow orderBack:nil]; 944 }]; 945 946 JNF_COCOA_EXIT(env); 947 } 948 949 /* 950 * Class: sun_lwawt_macosx_CPlatformWindow 951 * Method: nativePushNSWindowToFront 952 * Signature: (J)V 953 */ 954 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront 955 (JNIEnv *env, jclass clazz, jlong windowPtr) 956 { 957 JNF_COCOA_ENTER(env); 958 959 NSWindow *nsWindow = OBJC(windowPtr); 960 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 961 962 if (![nsWindow isKeyWindow]) { 963 [nsWindow makeKeyAndOrderFront:nsWindow]; 964 } else { 965 [nsWindow orderFront:nsWindow]; 966 } 967 }]; 968 969 JNF_COCOA_EXIT(env); 970 } 971 972 /* 973 * Class: sun_lwawt_macosx_CPlatformWindow 974 * Method: nativeSetNSWindowTitle 975 * Signature: (JLjava/lang/String;)V 976 */ 977 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle 978 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) 979 { 980 JNF_COCOA_ENTER(env); 981 982 NSWindow *nsWindow = OBJC(windowPtr); 983 [nsWindow performSelectorOnMainThread:@selector(setTitle:) 984 withObject:JNFJavaToNSString(env, jtitle) 985 waitUntilDone:NO]; 986 987 JNF_COCOA_EXIT(env); 988 } 989 990 /* 991 * Class: sun_lwawt_macosx_CPlatformWindow 992 * Method: nativeRevalidateNSWindowShadow 993 * Signature: (J)V 994 */ 995 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow 996 (JNIEnv *env, jclass clazz, jlong windowPtr) 997 { 998 JNF_COCOA_ENTER(env); 999 1000 NSWindow *nsWindow = OBJC(windowPtr); 1001 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1002 [nsWindow invalidateShadow]; 1003 }]; 1004 1005 JNF_COCOA_EXIT(env); 1006 } 1007 1008 /* 1009 * Class: sun_lwawt_macosx_CPlatformWindow 1010 * Method: nativeScreenOn_AppKitThread 1011 * Signature: (J)I 1012 */ 1013 JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread 1014 (JNIEnv *env, jclass clazz, jlong windowPtr) 1015 { 1016 jint ret = 0; 1017 1018 JNF_COCOA_ENTER(env); 1019 AWT_ASSERT_APPKIT_THREAD; 1020 1021 NSWindow *nsWindow = OBJC(windowPtr); 1022 NSDictionary *props = [[nsWindow screen] deviceDescription]; 1023 ret = [[props objectForKey:@"NSScreenNumber"] intValue]; 1024 1025 JNF_COCOA_EXIT(env); 1026 1027 return ret; 1028 } 1029 1030 /* 1031 * Class: sun_lwawt_macosx_CPlatformWindow 1032 * Method: nativeSetNSWindowMinimizedIcon 1033 * Signature: (JJ)V 1034 */ 1035 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon 1036 (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) 1037 { 1038 JNF_COCOA_ENTER(env); 1039 1040 NSWindow *nsWindow = OBJC(windowPtr); 1041 NSImage *image = OBJC(nsImagePtr); 1042 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1043 [nsWindow setMiniwindowImage:image]; 1044 }]; 1045 1046 JNF_COCOA_EXIT(env); 1047 } 1048 1049 /* 1050 * Class: sun_lwawt_macosx_CPlatformWindow 1051 * Method: nativeSetNSWindowRepresentedFilename 1052 * Signature: (JLjava/lang/String;)V 1053 */ 1054 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename 1055 (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) 1056 { 1057 JNF_COCOA_ENTER(env); 1058 1059 NSWindow *nsWindow = OBJC(windowPtr); 1060 NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; 1061 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1062 [nsWindow setRepresentedURL:url]; 1063 }]; 1064 1065 JNF_COCOA_EXIT(env); 1066 } 1067 1068 /* 1069 * Class: sun_lwawt_macosx_CPlatformWindow 1070 * Method: nativeGetTopmostPlatformWindowUnderMouse 1071 * Signature: (J)V 1072 */ 1073 JNIEXPORT jobject 1074 JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse 1075 (JNIEnv *env, jclass clazz) 1076 { 1077 jobject topmostWindowUnderMouse = nil; 1078 1079 JNF_COCOA_ENTER(env); 1080 AWT_ASSERT_APPKIT_THREAD; 1081 1082 AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; 1083 if (awtWindow != nil) { 1084 topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject]; 1085 } 1086 1087 JNF_COCOA_EXIT(env); 1088 1089 return topmostWindowUnderMouse; 1090 } 1091 1092 /* 1093 * Class: sun_lwawt_macosx_CPlatformWindow 1094 * Method: nativeSynthesizeMouseEnteredExitedEvents 1095 * Signature: (J)V 1096 */ 1097 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents 1098 (JNIEnv *env, jclass clazz) 1099 { 1100 JNF_COCOA_ENTER(env); 1101 1102 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1103 [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; 1104 }]; 1105 1106 JNF_COCOA_EXIT(env); 1107 } 1108 1109 /* 1110 * Class: sun_lwawt_macosx_CPlatformWindow 1111 * Method: _toggleFullScreenMode 1112 * Signature: (J)V 1113 */ 1114 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode 1115 (JNIEnv *env, jobject peer, jlong windowPtr) 1116 { 1117 JNF_COCOA_ENTER(env); 1118 1119 NSWindow *nsWindow = OBJC(windowPtr); 1120 SEL toggleFullScreenSelector = @selector(toggleFullScreen:); 1121 if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return; 1122 1123 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1124 [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; 1125 }]; 1126 1127 JNF_COCOA_EXIT(env); 1128 } 1129 1130 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled 1131 (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) 1132 { 1133 JNF_COCOA_ENTER(env); 1134 1135 NSWindow *nsWindow = OBJC(windowPtr); 1136 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1137 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1138 1139 [window setEnabled: isEnabled]; 1140 }]; 1141 1142 JNF_COCOA_EXIT(env); 1143 } 1144 1145 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose 1146 (JNIEnv *env, jclass clazz, jlong windowPtr) 1147 { 1148 JNF_COCOA_ENTER(env); 1149 1150 NSWindow *nsWindow = OBJC(windowPtr); 1151 [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ 1152 AWTWindow *window = (AWTWindow*)[nsWindow delegate]; 1153 1154 if ([AWTWindow lastKeyWindow] == window) { 1155 [AWTWindow setLastKeyWindow: nil]; 1156 } 1157 1158 // AWTWindow holds a reference to the NSWindow in its nsWindow 1159 // property. Unsetting the delegate allows it to be deallocated 1160 // which releases the reference. This, in turn, allows the window 1161 // itself be deallocated. 1162 [nsWindow setDelegate: nil]; 1163 1164 [window release]; 1165 }]; 1166 1167 JNF_COCOA_EXIT(env); 1168 } 1169 |