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

Print this page




  41 #import "OSVersion.h"
  42 
  43 #define MASK(KEY) \
  44     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  45 
  46 #define IS(BITS, KEY) \
  47     ((BITS & MASK(KEY)) != 0)
  48 
  49 #define SET(BITS, KEY, VALUE) \
  50     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  51 
  52 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  53 
  54 @implementation AWTWindow
  55 
  56 @synthesize javaPlatformWindow;
  57 @synthesize javaMenuBar;
  58 @synthesize javaMinSize;
  59 @synthesize javaMaxSize;
  60 @synthesize styleBits;

  61 
  62 - (void) updateMinMaxSize:(BOOL)resizable {
  63     if (resizable) {
  64         [self setMinSize:self.javaMinSize];
  65         [self setMaxSize:self.javaMaxSize];
  66     } else {
  67         NSRect currentFrame = [self frame];
  68         [self setMinSize:currentFrame.size];
  69         [self setMaxSize:currentFrame.size];
  70     }
  71 }
  72 
  73 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
  74 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
  75     NSUInteger type = 0;
  76     if (IS(styleBits, DECORATED)) {
  77         type |= NSTitledWindowMask;
  78         if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
  79         if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
  80         if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;


 140                   contentView:(NSView *)view
 141 {
 142 AWT_ASSERT_APPKIT_THREAD;
 143 
 144     NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
 145     NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
 146     if (contentRect.size.width <= 0.0) {
 147         contentRect.size.width = 1.0;
 148     }
 149     if (contentRect.size.height <= 0.0) {
 150         contentRect.size.height = 1.0;
 151     }
 152 
 153     self = [super initWithContentRect:contentRect
 154                             styleMask:styleMask
 155                               backing:NSBackingStoreBuffered
 156                                 defer:NO];
 157 
 158     if (self == nil) return nil; // no hope
 159 

 160     self.javaPlatformWindow = platformWindow;
 161     self.styleBits = bits;
 162     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 163 
 164     [self setDelegate:self];
 165     [self setContentView:view];
 166     [self setInitialFirstResponder:view];
 167     [self setReleasedWhenClosed:NO];
 168     [self setPreservesContentDuringLiveResize:YES];
 169 
 170     return self;
 171 }
 172 
 173 - (void) dealloc {
 174 AWT_ASSERT_APPKIT_THREAD;
 175 
 176     JNIEnv *env = [ThreadUtilities getJNIEnv];
 177     [self.javaPlatformWindow setJObject:nil withEnv:env];
 178 
 179     [super dealloc];
 180 }
 181 
 182 
 183 // NSWindow overrides
 184 - (BOOL) canBecomeKeyWindow {
 185 AWT_ASSERT_APPKIT_THREAD;
 186     return IS(self.styleBits, SHOULD_BECOME_KEY);
 187 }
 188 
 189 - (BOOL) canBecomeMainWindow {
 190 AWT_ASSERT_APPKIT_THREAD;
 191     return IS(self.styleBits, SHOULD_BECOME_MAIN);
 192 }
 193 
 194 - (BOOL) worksWhenModal {
 195 AWT_ASSERT_APPKIT_THREAD;
 196     return IS(self.styleBits, MODAL_EXCLUDED);
 197 }
 198 
 199 
 200 // Gesture support
 201 - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
 202 AWT_ASSERT_APPKIT_THREAD;
 203 
 204     JNIEnv *env = [ThreadUtilities getJNIEnv];
 205     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 206     if (platformWindow != NULL) {
 207         // extract the target AWT Window object out of the CPlatformWindow
 208         static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
 209         jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
 210         if (awtWindow != NULL) {
 211             // translate the point into Java coordinates


 956 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse
 957 (JNIEnv *env, jclass clazz, jlong windowPtr)
 958 {
 959     __block jboolean underMouse = JNI_FALSE;
 960 
 961 JNF_COCOA_ENTER(env);
 962 AWT_ASSERT_NOT_APPKIT_THREAD;
 963 
 964     AWTWindow *aWindow = OBJC(windowPtr);
 965     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() {
 966         AWT_ASSERT_APPKIT_THREAD;
 967 
 968         NSPoint pt = [aWindow mouseLocationOutsideOfEventStream];
 969         underMouse = [[aWindow contentView] hitTest:pt] != nil;
 970     }];
 971 
 972 JNF_COCOA_EXIT(env);
 973 
 974     return underMouse;
 975 }





















































  41 #import "OSVersion.h"
  42 
  43 #define MASK(KEY) \
  44     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  45 
  46 #define IS(BITS, KEY) \
  47     ((BITS & MASK(KEY)) != 0)
  48 
  49 #define SET(BITS, KEY, VALUE) \
  50     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  51 
  52 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  53 
  54 @implementation AWTWindow
  55 
  56 @synthesize javaPlatformWindow;
  57 @synthesize javaMenuBar;
  58 @synthesize javaMinSize;
  59 @synthesize javaMaxSize;
  60 @synthesize styleBits;
  61 @synthesize isModallyBlocked;
  62 
  63 - (void) updateMinMaxSize:(BOOL)resizable {
  64     if (resizable) {
  65         [self setMinSize:self.javaMinSize];
  66         [self setMaxSize:self.javaMaxSize];
  67     } else {
  68         NSRect currentFrame = [self frame];
  69         [self setMinSize:currentFrame.size];
  70         [self setMaxSize:currentFrame.size];
  71     }
  72 }
  73 
  74 // creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
  75 + (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
  76     NSUInteger type = 0;
  77     if (IS(styleBits, DECORATED)) {
  78         type |= NSTitledWindowMask;
  79         if (IS(styleBits, CLOSEABLE))   type |= NSClosableWindowMask;
  80         if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
  81         if (IS(styleBits, RESIZABLE))   type |= NSResizableWindowMask;


 141                   contentView:(NSView *)view
 142 {
 143 AWT_ASSERT_APPKIT_THREAD;
 144 
 145     NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
 146     NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
 147     if (contentRect.size.width <= 0.0) {
 148         contentRect.size.width = 1.0;
 149     }
 150     if (contentRect.size.height <= 0.0) {
 151         contentRect.size.height = 1.0;
 152     }
 153 
 154     self = [super initWithContentRect:contentRect
 155                             styleMask:styleMask
 156                               backing:NSBackingStoreBuffered
 157                                 defer:NO];
 158 
 159     if (self == nil) return nil; // no hope
 160 
 161     self.isModallyBlocked = NO;
 162     self.javaPlatformWindow = platformWindow;
 163     self.styleBits = bits;
 164     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 165 
 166     [self setDelegate:self];
 167     [self setContentView:view];
 168     [self setInitialFirstResponder:view];
 169     [self setReleasedWhenClosed:NO];
 170     [self setPreservesContentDuringLiveResize:YES];
 171 
 172     return self;
 173 }
 174 
 175 - (void) dealloc {
 176 AWT_ASSERT_APPKIT_THREAD;
 177 
 178     JNIEnv *env = [ThreadUtilities getJNIEnv];
 179     [self.javaPlatformWindow setJObject:nil withEnv:env];
 180 
 181     [super dealloc];
 182 }
 183 

 184 // NSWindow overrides
 185 - (BOOL) canBecomeKeyWindow {
 186 AWT_ASSERT_APPKIT_THREAD;
 187     return !self.isModallyBlocked && IS(self.styleBits, SHOULD_BECOME_KEY);
 188 }
 189 
 190 - (BOOL) canBecomeMainWindow {
 191 AWT_ASSERT_APPKIT_THREAD;
 192     return !self.isModallyBlocked && IS(self.styleBits, SHOULD_BECOME_MAIN);
 193 }
 194 
 195 - (BOOL) worksWhenModal {
 196 AWT_ASSERT_APPKIT_THREAD;
 197     return IS(self.styleBits, MODAL_EXCLUDED);
 198 }
 199 
 200 
 201 // Gesture support
 202 - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
 203 AWT_ASSERT_APPKIT_THREAD;
 204 
 205     JNIEnv *env = [ThreadUtilities getJNIEnv];
 206     jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
 207     if (platformWindow != NULL) {
 208         // extract the target AWT Window object out of the CPlatformWindow
 209         static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
 210         jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
 211         if (awtWindow != NULL) {
 212             // translate the point into Java coordinates


 957 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse
 958 (JNIEnv *env, jclass clazz, jlong windowPtr)
 959 {
 960     __block jboolean underMouse = JNI_FALSE;
 961 
 962 JNF_COCOA_ENTER(env);
 963 AWT_ASSERT_NOT_APPKIT_THREAD;
 964 
 965     AWTWindow *aWindow = OBJC(windowPtr);
 966     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^() {
 967         AWT_ASSERT_APPKIT_THREAD;
 968 
 969         NSPoint pt = [aWindow mouseLocationOutsideOfEventStream];
 970         underMouse = [[aWindow contentView] hitTest:pt] != nil;
 971     }];
 972 
 973 JNF_COCOA_EXIT(env);
 974 
 975     return underMouse;
 976 }
 977 
 978 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeModallyBlocked
 979 (JNIEnv *env, jclass clazz, jlong windowPtr)
 980 {
 981 JNF_COCOA_ENTER(env);
 982 
 983     AWTWindow *window = OBJC(windowPtr);
 984     if (IS(window.styleBits, MODAL_EXCLUDED)) {
 985         return;
 986     }
 987 
 988     window.isModallyBlocked = YES;
 989     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 990         [[window standardWindowButton:NSWindowCloseButton] setEnabled: NO];
 991         [[window standardWindowButton:NSWindowMiniaturizeButton] setEnabled: NO];
 992         [[window standardWindowButton:NSWindowZoomButton] setEnabled: NO];
 993 
 994         [window updateMinMaxSize:NO];
 995         [window setShowsResizeIndicator:NO];
 996     }];
 997 
 998 JNF_COCOA_EXIT(env);
 999 }
1000 
1001 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeModallyUnblocked
1002 (JNIEnv *env, jclass clazz, jlong windowPtr)
1003 {
1004 JNF_COCOA_ENTER(env);
1005 
1006     AWTWindow *window = OBJC(windowPtr);
1007     if (IS(window.styleBits, MODAL_EXCLUDED)) {
1008         return;
1009     }
1010 
1011     window.isModallyBlocked = NO;
1012     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
1013         [[window standardWindowButton:NSWindowCloseButton] setEnabled: IS(window.styleBits, CLOSEABLE)];
1014         [[window standardWindowButton:NSWindowMiniaturizeButton] setEnabled: IS(window.styleBits, MINIMIZABLE)];
1015         [[window standardWindowButton:NSWindowZoomButton] setEnabled: IS(window.styleBits, ZOOMABLE)];
1016 
1017         if (IS(window.styleBits, RESIZABLE)) {
1018             [window updateMinMaxSize:YES];
1019             [window setShowsResizeIndicator:YES];
1020         }
1021 
1022     }];
1023 
1024 JNF_COCOA_EXIT(env);
1025 }
1026 
1027