src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m

Print this page




  50 #define SET(BITS, KEY, VALUE) \
  51     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  52 
  53 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  54 
  55 // Cocoa windowDidBecomeKey/windowDidResignKey notifications
  56 // doesn't provide information about "opposite" window, so we
  57 // have to do a bit of tracking. This variable points to a window
  58 // which had been the key window just before a new key window
  59 // was set. It would be nil if the new key window isn't an AWT
  60 // window or the app currently has no key window.
  61 static AWTWindow* lastKeyWindow = nil;
  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];             \
  83                                                                 \
  84     return self;                                                \
  85 }                                                               \
  86                                                                 \
  87 /* NSWindow overrides */                                        \
  88 - (BOOL) canBecomeKeyWindow {                                   \
  89     return [(AWTWindow*)[self delegate] canBecomeKeyWindow];    \
  90 }                                                               \
  91                                                                 \
  92 - (BOOL) canBecomeMainWindow {                                  \
  93     return [(AWTWindow*)[self delegate] canBecomeMainWindow];   \
  94 }                                                               \
  95                                                                 \
  96 - (BOOL) worksWhenModal {                                       \
  97     return [(AWTWindow*)[self delegate] worksWhenModal];        \


 252 
 253     if (IS(mask, DOCUMENT_MODIFIED)) {
 254         [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
 255     }
 256 
 257     if (IS(mask, FULLSCREENABLE) && [self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
 258         if (IS(bits, FULLSCREENABLE)) {
 259             [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
 260         } else {
 261             [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault];
 262         }
 263     }
 264 
 265 }
 266 
 267 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
 268                   ownerWindow:owner
 269                     styleBits:(jint)bits
 270                     frameRect:(NSRect)rect
 271                   contentView:(NSView *)view

 272 {
 273 AWT_ASSERT_APPKIT_THREAD;
 274 
 275     NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
 276     NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
 277     if (contentRect.size.width <= 0.0) {
 278         contentRect.size.width = 1.0;
 279     }
 280     if (contentRect.size.height <= 0.0) {
 281         contentRect.size.height = 1.0;
 282     }
 283 
 284     self = [super init];
 285 
 286     if (self == nil) return nil; // no hope
 287 
 288     if (IS(bits, UTILITY) ||
 289         IS(bits, NONACTIVATING) ||
 290         IS(bits, HUD) ||
 291         IS(bits, HIDES_ON_DEACTIVATE))
 292     {
 293         self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
 294                             frameRect:contentRect
 295                             styleMask:styleMask
 296                           contentView:view];

 297     }
 298     else
 299     {
 300         // These windows will appear in the window list in the dock icon menu
 301         self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
 302                             frameRect:contentRect
 303                             styleMask:styleMask
 304                           contentView:view];

 305     }
 306 
 307     if (self.nsWindow == nil) return nil; // no hope either
 308     [self.nsWindow release]; // the property retains the object already
 309 
 310     self.isEnabled = YES;
 311     self.javaPlatformWindow = platformWindow;
 312     self.styleBits = bits;
 313     self.ownerWindow = owner;
 314     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 315 
 316     if (IS(self.styleBits, IS_POPUP)) {
 317         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 318     }
 319 
 320     return self;
 321 }
 322 
 323 + (BOOL) isAWTWindow:(NSWindow *)window {
 324     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];


 766 }
 767 
 768 + (AWTWindow *) lastKeyWindow {
 769     return lastKeyWindow;
 770 }
 771 
 772 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
 773     return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
 774 }
 775 
 776 
 777 @end // AWTWindow
 778 
 779 
 780 /*
 781  * Class:     sun_lwawt_macosx_CPlatformWindow
 782  * Method:    nativeCreateNSWindow
 783  * Signature: (JJIIII)J
 784  */
 785 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
 786 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)

 787 {
 788     __block AWTWindow *window = nil;
 789 
 790 JNF_COCOA_ENTER(env);
 791 
 792     JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
 793     NSView *contentView = OBJC(contentViewPtr);
 794     NSRect frameRect = NSMakeRect(x, y, w, h);
 795     AWTWindow *owner = [OBJC(ownerPtr) delegate];
 796     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 797 
 798         window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
 799                                                ownerWindow:owner
 800                                                  styleBits:styleBits
 801                                                  frameRect:frameRect
 802                                                contentView:contentView];

 803         // the window is released is CPlatformWindow.nativeDispose()
 804 
 805         if (window) [window.nsWindow retain];
 806     }];
 807 
 808 JNF_COCOA_EXIT(env);
 809 
 810     return ptr_to_jlong(window ? window.nsWindow : nil);
 811 }
 812 
 813 /*
 814  * Class:     sun_lwawt_macosx_CPlatformWindow
 815  * Method:    nativeSetNSWindowStyleBits
 816  * Signature: (JII)V
 817  */
 818 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
 819 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
 820 {
 821 JNF_COCOA_ENTER(env);
 822 




  50 #define SET(BITS, KEY, VALUE) \
  51     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  52 
  53 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  54 
  55 // Cocoa windowDidBecomeKey/windowDidResignKey notifications
  56 // doesn't provide information about "opposite" window, so we
  57 // have to do a bit of tracking. This variable points to a window
  58 // which had been the key window just before a new key window
  59 // was set. It would be nil if the new key window isn't an AWT
  60 // window or the app currently has no key window.
  61 static AWTWindow* lastKeyWindow = nil;
  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             zoomed:(BOOL)zoomed                                 \
  71 {                                                               \
  72     self = [super initWithContentRect:contectRect               \
  73                             styleMask:styleMask                 \
  74                               backing:NSBackingStoreBuffered    \
  75                                 defer:NO];                      \
  76                                                                 \
  77     if (self == nil) return nil;                                \
  78                                                                 \
  79     if (zoomed) [self zoom:nil];                                \
  80     [self setDelegate:delegate];                                \
  81     [self setContentView:view];                                 \
  82     [self setInitialFirstResponder:view];                       \
  83     [self setReleasedWhenClosed:NO];                            \
  84     [self setPreservesContentDuringLiveResize:YES];             \
  85                                                                 \
  86     return self;                                                \
  87 }                                                               \
  88                                                                 \
  89 /* NSWindow overrides */                                        \
  90 - (BOOL) canBecomeKeyWindow {                                   \
  91     return [(AWTWindow*)[self delegate] canBecomeKeyWindow];    \
  92 }                                                               \
  93                                                                 \
  94 - (BOOL) canBecomeMainWindow {                                  \
  95     return [(AWTWindow*)[self delegate] canBecomeMainWindow];   \
  96 }                                                               \
  97                                                                 \
  98 - (BOOL) worksWhenModal {                                       \
  99     return [(AWTWindow*)[self delegate] worksWhenModal];        \


 254 
 255     if (IS(mask, DOCUMENT_MODIFIED)) {
 256         [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
 257     }
 258 
 259     if (IS(mask, FULLSCREENABLE) && [self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
 260         if (IS(bits, FULLSCREENABLE)) {
 261             [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
 262         } else {
 263             [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault];
 264         }
 265     }
 266 
 267 }
 268 
 269 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
 270                   ownerWindow:owner
 271                     styleBits:(jint)bits
 272                     frameRect:(NSRect)rect
 273                   contentView:(NSView *)view
 274                   zoomed:(BOOL)zoomed
 275 {
 276 AWT_ASSERT_APPKIT_THREAD;
 277 
 278     NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
 279     NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
 280     if (contentRect.size.width <= 0.0) {
 281         contentRect.size.width = 1.0;
 282     }
 283     if (contentRect.size.height <= 0.0) {
 284         contentRect.size.height = 1.0;
 285     }
 286 
 287     self = [super init];
 288 
 289     if (self == nil) return nil; // no hope
 290 
 291     if (IS(bits, UTILITY) ||
 292         IS(bits, NONACTIVATING) ||
 293         IS(bits, HUD) ||
 294         IS(bits, HIDES_ON_DEACTIVATE))
 295     {
 296         self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
 297                             frameRect:contentRect
 298                             styleMask:styleMask
 299                           contentView:view
 300                                zoomed:NO];
 301     }
 302     else
 303     {
 304         // These windows will appear in the window list in the dock icon menu
 305         self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
 306                             frameRect:contentRect
 307                             styleMask:styleMask
 308                             contentView:view
 309                             zoomed: zoomed];
 310     }
 311 
 312     if (self.nsWindow == nil) return nil; // no hope either
 313     [self.nsWindow release]; // the property retains the object already
 314 
 315     self.isEnabled = YES;
 316     self.javaPlatformWindow = platformWindow;
 317     self.styleBits = bits;
 318     self.ownerWindow = owner;
 319     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
 320 
 321     if (IS(self.styleBits, IS_POPUP)) {
 322         [self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/]; 
 323     }
 324 
 325     return self;
 326 }
 327 
 328 + (BOOL) isAWTWindow:(NSWindow *)window {
 329     return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];


 771 }
 772 
 773 + (AWTWindow *) lastKeyWindow {
 774     return lastKeyWindow;
 775 }
 776 
 777 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
 778     return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
 779 }
 780 
 781 
 782 @end // AWTWindow
 783 
 784 
 785 /*
 786  * Class:     sun_lwawt_macosx_CPlatformWindow
 787  * Method:    nativeCreateNSWindow
 788  * Signature: (JJIIII)J
 789  */
 790 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
 791 (JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits,
 792    jdouble x, jdouble y, jdouble w, jdouble h, jboolean zoomed)
 793 {
 794     __block AWTWindow *window = nil;
 795 
 796 JNF_COCOA_ENTER(env);
 797 
 798     JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
 799     NSView *contentView = OBJC(contentViewPtr);
 800     NSRect frameRect = NSMakeRect(x, y, w, h);
 801     AWTWindow *owner = [OBJC(ownerPtr) delegate];
 802     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 803 
 804         window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
 805                                                ownerWindow:owner
 806                                                  styleBits:styleBits
 807                                                  frameRect:frameRect
 808                                                contentView:contentView
 809                                                     zoomed: zoomed ? YES : NO];
 810         // the window is released is CPlatformWindow.nativeDispose()
 811 
 812         if (window) [window.nsWindow retain];
 813     }];
 814 
 815 JNF_COCOA_EXIT(env);
 816 
 817     return ptr_to_jlong(window ? window.nsWindow : nil);
 818 }
 819 
 820 /*
 821  * Class:     sun_lwawt_macosx_CPlatformWindow
 822  * Method:    nativeSetNSWindowStyleBits
 823  * Signature: (JII)V
 824  */
 825 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
 826 (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
 827 {
 828 JNF_COCOA_ENTER(env);
 829