modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m

Print this page




  33 #import "GlassMacros.h"
  34 #import "GlassWindow+Java.h"
  35 #import "GlassScreen.h"
  36 
  37 //#define VERBOSE
  38 #ifndef VERBOSE
  39 #define LOG(MSG, ...)
  40 #else
  41 #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
  42 #endif
  43 
  44 static NSWindow *s_grabWindow = nil;
  45 
  46 @interface NSWindow (External)
  47 
  48 - (void)_startLiveResize;
  49 - (void)_endLiveResize;
  50 
  51 @end
  52 







  53 @implementation GlassWindow (Java)
  54 
  55 #pragma mark --- Callbacks
  56 
  57 - (void)_sendJavaWindowMoveToAnotherScreenEventIfNeeded
  58 {
  59     NSScreen *newScreen = [self->nsWindow screen];
  60     
  61     // Update only if the newScreen isn't nil
  62     if (self->currentScreen != newScreen && newScreen != nil)
  63     {
  64         self->currentScreen = newScreen;
  65         
  66         GET_MAIN_JENV;
  67         (*env)->CallVoidMethod(env, jWindow, jWindowNotifyMoveToAnotherScreen, createJavaScreen(env, newScreen));
  68     }
  69 }
  70 
  71 - (void)_sendJavaWindowMoveEventForFrame:(NSRect)frame
  72 {


 279     
 280     if (self->isFocusable == YES && self->isEnabled == YES)
 281     {
 282         [self->nsWindow makeMainWindow];
 283         [self->nsWindow makeKeyAndOrderFront:nil];
 284     }
 285     else
 286     {
 287         [self->nsWindow orderFront:nil];
 288     }
 289     
 290     if ((self->owner != nil) && ([self->nsWindow parentWindow] == nil))
 291     {
 292         [self->owner addChildWindow:self->nsWindow ordered:NSWindowAbove];
 293     }
 294 }
 295 
 296 - (void)_setWindowFrameWithRect:(NSRect)rect withDisplay:(jboolean)display withAnimate:(jboolean)animate
 297 {
 298     NSRect frame = [self _constrainFrame:rect];

 299     [self _setFlipFrame:frame display:(BOOL)display animate:(BOOL)animate];
 300 
 301 }
 302 
 303 - (void)_setBounds:(jint)x y:(jint)y xSet:(jboolean)xSet ySet:(jboolean)ySet w:(jint)w h:(jint)h cw:(jint)cw ch:(jint)ch

 304 {
 305     NSPoint origin = [self _flipFrame].origin;
 306     NSSize size = [self->nsWindow frame].size;
 307     NSSize sizeForClient = [NSWindow frameRectForContentRect:NSMakeRect(0.0, 0.0, cw > 0 ? cw : 0.0, ch > 0 ? ch : 0.0) styleMask:[self->nsWindow styleMask]].size;
 308 
 309     jint newX = xSet == JNI_TRUE ? x : (jint)origin.x;
 310     jint newY = ySet == JNI_TRUE ? y : (jint)origin.y;
 311 
 312     jint newW = (w > 0) ? w : (cw > 0) ? (jint)sizeForClient.width : (jint)size.width;
 313     jint newH = (h > 0) ? h : (ch > 0) ? (jint)sizeForClient.height : (jint)size.height;
 314 
 315     [self _setWindowFrameWithRect:NSMakeRect(newX, newY, newW, newH) withDisplay:JNI_TRUE withAnimate:JNI_FALSE];


 316 }
 317 
 318 - (void)_restorePreZoomedRect
 319 {
 320     [self _setWindowFrameWithRect:NSMakeRect(self->preZoomedRect.origin.x, self->preZoomedRect.origin.y, self->preZoomedRect.size.width, self->preZoomedRect.size.height) withDisplay:JNI_TRUE withAnimate:JNI_TRUE];
 321     [self _sendJavaWindowMoveEventForFrame:[self _flipFrame]];
 322     [self _sendJavaWindowResizeEvent:com_sun_glass_events_WindowEvent_RESTORE forFrame:[self _flipFrame]];
 323 }
 324 
 325 - (NSScreen*)_getScreen
 326 {
 327     NSScreen *screen = [self->nsWindow screen];
 328     if (screen == nil)
 329     {
 330         screen = self->currentScreen;
 331     }
 332     if (screen == nil)
 333     {
 334         screen = [[NSScreen screens] objectAtIndex: 0];
 335     }
 336     return screen;
 337 }
 338 
 339 #pragma mark --- Flip
 340      
 341 - (void)_setFlipFrame:(NSRect)frameRect display:(BOOL)displayFlag animate:(BOOL)animateFlag
 342 {
 343     //NSLog(@"_setFlipFrame:   %.2f,%.2f %.2fx%.2f", frameRect.origin.x, frameRect.origin.y, frameRect.size.width, frameRect.size.height);

 344     NSScreen * screen = [[NSScreen screens] objectAtIndex: 0];
 345     NSRect screenFrame = screen.frame;
 346     //NSLog(@"            screenFrame: %.2f,%.2f %.2fx%.2f", screenFrame.origin.x, screenFrame.origin.y, screenFrame.size.width, screenFrame.size.height);
 347     
 348     frameRect.origin.y = screenFrame.size.height - frameRect.size.height - frameRect.origin.y;
 349     //NSLog(@"            set to frameRect:%.2f,%.2f %.2fx%.2f", frameRect.origin.x, frameRect.origin.y, frameRect.size.width, frameRect.size.height);









 350     
 351     [self->nsWindow setFrame:frameRect display:displayFlag animate:animateFlag];
 352     
 353     //frameRect = [self _flipFrame];
 354     //NSLog(@"            _flipFrame:%.2f,%.2f %.2fx%.2f", frameRect.origin.x, frameRect.origin.y, frameRect.size.width, frameRect.size.height);
 355     //frameRect = [super frame];
 356     //NSLog(@"            frame:%.2f,%.2f %.2fx%.2f", frameRect.origin.x, frameRect.origin.y, frameRect.size.width, frameRect.size.height);
 357 }
 358 
 359 - (NSRect)_flipFrame
 360 {
 361     NSScreen * screen = [[NSScreen screens] objectAtIndex: 0];
 362     NSRect screenFrame = screen.frame;
 363     
 364     NSRect frame = [self->nsWindow frame];
 365     //NSLog(@"_flipFrame: v.s.h=%.2f f.s.h=%.2f f.o.y=%.2f", screenFrame.size.height, frame.size.height, frame.origin.y);



 366     frame.origin.y = screenFrame.size.height - frame.size.height - frame.origin.y;
 367     //NSLog(@"                            result: f.o.y=%.2f", frame.origin.y);


 368     
 369     //NSLog(@"_flipFrame:   %.2f,%.2f %.2fx%.2f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
 370     return frame;
 371 }
 372 
 373 @end


  33 #import "GlassMacros.h"
  34 #import "GlassWindow+Java.h"
  35 #import "GlassScreen.h"
  36 
  37 //#define VERBOSE
  38 #ifndef VERBOSE
  39 #define LOG(MSG, ...)
  40 #else
  41 #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
  42 #endif
  43 
  44 static NSWindow *s_grabWindow = nil;
  45 
  46 @interface NSWindow (External)
  47 
  48 - (void)_startLiveResize;
  49 - (void)_endLiveResize;
  50 
  51 @end
  52 
  53 //#define VERBOSE
  54 #ifndef VERBOSE
  55 #define LOG(MSG, ...)
  56 #else
  57 #define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
  58 #endif
  59 
  60 @implementation GlassWindow (Java)
  61 
  62 #pragma mark --- Callbacks
  63 
  64 - (void)_sendJavaWindowMoveToAnotherScreenEventIfNeeded
  65 {
  66     NSScreen *newScreen = [self->nsWindow screen];
  67     
  68     // Update only if the newScreen isn't nil
  69     if (self->currentScreen != newScreen && newScreen != nil)
  70     {
  71         self->currentScreen = newScreen;
  72         
  73         GET_MAIN_JENV;
  74         (*env)->CallVoidMethod(env, jWindow, jWindowNotifyMoveToAnotherScreen, createJavaScreen(env, newScreen));
  75     }
  76 }
  77 
  78 - (void)_sendJavaWindowMoveEventForFrame:(NSRect)frame
  79 {


 286     
 287     if (self->isFocusable == YES && self->isEnabled == YES)
 288     {
 289         [self->nsWindow makeMainWindow];
 290         [self->nsWindow makeKeyAndOrderFront:nil];
 291     }
 292     else
 293     {
 294         [self->nsWindow orderFront:nil];
 295     }
 296     
 297     if ((self->owner != nil) && ([self->nsWindow parentWindow] == nil))
 298     {
 299         [self->owner addChildWindow:self->nsWindow ordered:NSWindowAbove];
 300     }
 301 }
 302 
 303 - (void)_setWindowFrameWithRect:(NSRect)rect withDisplay:(jboolean)display withAnimate:(jboolean)animate
 304 {
 305     NSRect frame = [self _constrainFrame:rect];
 306     LOG("GlassWindow _setWindowFrameWithRect: constrained (%s)", [NSStringFromRect(frame) UTF8String]);
 307     [self _setFlipFrame:frame display:(BOOL)display animate:(BOOL)animate];
 308 
 309 }
 310 
 311 - (void)_setBounds:(jint)x y:(jint)y xSet:(jboolean)xSet ySet:(jboolean)ySet
 312                  w:(jint)w h:(jint)h cw:(jint)cw ch:(jint)ch
 313 {
 314     NSPoint origin = [self _flipFrame].origin;
 315     NSSize size = [self->nsWindow frame].size;
 316     NSSize sizeForClient = [NSWindow frameRectForContentRect:NSMakeRect(0.0, 0.0, cw > 0 ? cw : 0.0, ch > 0 ? ch : 0.0) styleMask:[self->nsWindow styleMask]].size;
 317 
 318     jint newX = xSet == JNI_TRUE ? x : (jint)origin.x;
 319     jint newY = ySet == JNI_TRUE ? y : (jint)origin.y;
 320 
 321     jint newW = (w > 0) ? w : (cw > 0) ? (jint)sizeForClient.width : (jint)size.width;
 322     jint newH = (h > 0) ? h : (ch > 0) ? (jint)sizeForClient.height : (jint)size.height;
 323 
 324     [self _setWindowFrameWithRect:NSMakeRect(newX, newY, newW, newH) withDisplay:JNI_TRUE withAnimate:JNI_FALSE];
 325 
 326     LOG("GlassWindow _setBounds(w: %d h %d)", newW, newH);
 327 }
 328 
 329 - (void)_restorePreZoomedRect
 330 {
 331     [self _setWindowFrameWithRect:NSMakeRect(self->preZoomedRect.origin.x, self->preZoomedRect.origin.y, self->preZoomedRect.size.width, self->preZoomedRect.size.height) withDisplay:JNI_TRUE withAnimate:JNI_TRUE];
 332     [self _sendJavaWindowMoveEventForFrame:[self _flipFrame]];
 333     [self _sendJavaWindowResizeEvent:com_sun_glass_events_WindowEvent_RESTORE forFrame:[self _flipFrame]];
 334 }
 335 
 336 - (NSScreen*)_getScreen
 337 {
 338     NSScreen *screen = [self->nsWindow screen];
 339     if (screen == nil)
 340     {
 341         screen = self->currentScreen;
 342     }
 343     if (screen == nil)
 344     {
 345         screen = [[NSScreen screens] objectAtIndex: 0];
 346     }
 347     return screen;
 348 }
 349 
 350 #pragma mark --- Flip
 351      
 352 - (void)_setFlipFrame:(NSRect)frameRect display:(BOOL)displayFlag animate:(BOOL)animateFlag
 353 {
 354     LOG("GlassWindow(Java) _setFlipFrame:display:animate: %s", [NSStringFromRect(frameRect) UTF8String]);
 355 
 356     NSScreen * screen = [[NSScreen screens] objectAtIndex: 0];
 357     NSRect screenFrame = screen.frame;
 358     LOG("GlassWindow(Java) screenFrame: %s", [NSStringFromRect(screenFrame) UTF8String]);
 359     
 360     frameRect.origin.y = screenFrame.size.height - frameRect.size.height - frameRect.origin.y;
 361     
 362     if (frameRect.size.width > screenFrame.size.width) {
 363         frameRect.size.width = screenFrame.size.width;
 364     }
 365     
 366     if (frameRect.size.height > screenFrame.size.height) {
 367         frameRect.size.height = screenFrame.size.height;
 368     }
 369     
 370     LOG("GlassWindow(Java) set to frameRect: %s", [NSStringFromRect(frameRect) UTF8String]);
 371 
 372     [self->nsWindow setFrame:frameRect display:displayFlag animate:animateFlag];
 373     
 374     frameRect = [self _flipFrame];
 375     LOG("GlassWindow(Java) _flipFrame: %s", [NSStringFromRect(frameRect) UTF8String]);


 376 }
 377 
 378 - (NSRect)_flipFrame
 379 {
 380     NSScreen * screen = [[NSScreen screens] objectAtIndex: 0];
 381     NSRect screenFrame = screen.frame;
 382     
 383     NSRect frame = [self->nsWindow frame];
 384     LOG("GlassWindow(Java) _flipFrame: screenFrame %s windowFrame %s",
 385         [NSStringFromRect(screenFrame) UTF8String],
 386         [NSStringFromRect(frame) UTF8String]);
 387 
 388     frame.origin.y = screenFrame.size.height - frame.size.height - frame.origin.y;
 389     frame.origin.x = screenFrame.size.width - frame.size.width - frame.origin.x;
 390     
 391     LOG("GlassView3D _flipFrame: result %s", [NSStringFromPoint(frame.origin) UTF8String]);
 392 

 393     return frame;
 394 }
 395 
 396 @end