changeset 5578:82c5dba3721a

RT-32531: Scene Width and Height, if not specified, result in no window being shown Reviewed-by: Alexander Zvegintsev <Alexander.Zvegintsev@oracle.com>
author Anthony Petrov <anthony.petrov@oracle.com>
date Wed, 30 Oct 2013 12:15:06 +0400
parents 29bc314ef771
children fbf244020834
files modules/graphics/src/main/native-glass/gtk/GlassWindow.cpp modules/graphics/src/main/native-glass/gtk/glass_window.cpp modules/graphics/src/main/native-glass/gtk/glass_window.h modules/graphics/src/main/native-glass/mac/GlassWindow+Java.h modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m modules/graphics/src/main/native-glass/mac/GlassWindow.h modules/graphics/src/main/native-glass/mac/GlassWindow.m
diffstat 7 files changed, 57 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/gtk/GlassWindow.cpp	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/gtk/GlassWindow.cpp	Wed Oct 30 12:15:06 2013 +0400
@@ -176,7 +176,7 @@
 
 /*
  * Class:     com_sun_glass_ui_gtk_GtkWindow
- * Method:    _setBounds
+ * Method:    setBoundsImpl
  * Signature: (JIIZZIIII)V
  */
 JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkWindow_setBoundsImpl
--- a/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Wed Oct 30 12:15:06 2013 +0400
@@ -627,7 +627,9 @@
             resizable(),
             xshape(),
             frame_extents_initialized(),
-            map_received(false)
+            map_received(false),
+            location_assigned(false),
+            size_assigned(false)
 {
     jwindow = mainEnv->NewGlobalRef(_jwindow);
 
@@ -1032,6 +1034,18 @@
     }
 }
 
+void WindowContextTop::set_visible(bool visible)
+{
+    if (visible) {
+        if (!size_assigned) {
+            set_bounds(0, 0, false, false, 320, 200, -1, -1);
+        }
+        if (!location_assigned) {
+            set_bounds(0, 0, true, true, -1, -1, -1, -1);
+        }
+    }
+    WindowContextBase::set_visible(visible);
+}
 
 void WindowContextTop::set_bounds(int x, int y, bool xSet, bool ySet, int w, int h, int cw, int ch) {
     if (!frame_extents_initialized && frame_type == TITLED) {
@@ -1089,6 +1103,9 @@
         windowChangesMask |= CWY;
     }
 
+    if (xSet || ySet) location_assigned = true;
+    if (w > 0 || h > 0 || cw > 0 || ch > 0) size_assigned = true;
+
     window_configure(&windowChanges, windowChangesMask);
 
 }
--- a/modules/graphics/src/main/native-glass/gtk/glass_window.h	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/gtk/glass_window.h	Wed Oct 30 12:15:06 2013 +0400
@@ -376,6 +376,8 @@
 
     bool frame_extents_initialized;
     bool map_received;
+    bool location_assigned;
+    bool size_assigned;
 public:
     WindowContextTop(jobject, WindowContext*, long, WindowFrameType, WindowType);
     void process_map();
@@ -402,6 +404,7 @@
     void set_modal(bool, WindowContext* parent = NULL);
     void set_gravity(float, float);
     void set_level(int);
+    void set_visible(bool);
 
     void enter_fullscreen();
     void exit_fullscreen();
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.h	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.h	Wed Oct 30 12:15:06 2013 +0400
@@ -43,6 +43,7 @@
 - (void)_setResizable;
 - (NSRect)_constrainFrame:(NSRect)frame;
 - (void)_setVisible;
+- (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;
 - (void)_setWindowFrameWithRect:(NSRect)rect withDisplay:(jboolean)display withAnimate:(jboolean)animate;
 - (void)_restorePreZoomedRect;
 - (NSScreen*)_getScreen;
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow+Java.m	Wed Oct 30 12:15:06 2013 +0400
@@ -291,6 +291,21 @@
 
 }
 
+- (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
+{
+    NSPoint origin = [self _flipFrame].origin;
+    NSSize size = [self->nsWindow frame].size;
+    NSSize sizeForClient = [NSWindow frameRectForContentRect:NSMakeRect(0.0, 0.0, cw > 0 ? cw : 0.0, ch > 0 ? ch : 0.0) styleMask:[self->nsWindow styleMask]].size;
+
+    jint newX = xSet == JNI_TRUE ? x : (jint)origin.x;
+    jint newY = ySet == JNI_TRUE ? y : (jint)origin.y;
+
+    jint newW = (w > 0) ? w : (cw > 0) ? (jint)sizeForClient.width : (jint)size.width;
+    jint newH = (h > 0) ? h : (ch > 0) ? (jint)sizeForClient.height : (jint)size.height;
+
+    [self _setWindowFrameWithRect:NSMakeRect(newX, newY, newW, newH) withDisplay:JNI_TRUE withAnimate:JNI_FALSE];
+}
+
 - (void)_restorePreZoomedRect
 {
     [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];
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow.h	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow.h	Wed Oct 30 12:15:06 2013 +0400
@@ -62,7 +62,13 @@
     GlassAccessibleBaseProvider *accFocusElement ; // Focussed element
     BOOL                isAccessibleInitComplete ;
         
-    BOOL                 isClosed;   
+    BOOL                isClosed;   
+
+    // We track whether an explicit size/location have been assigned to the window
+    // in order to differentiate between an explicitly assigned zero bounds, and the
+    // deafult bounds (which are also zeros - see a comment in _createWindowCommon().)
+    BOOL                isSizeAssigned;
+    BOOL                isLocationAssigned;
 }
 
 - (void)setFullscreenWindow:(NSWindow *)fsWindow;
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Wed Oct 30 08:41:07 2013 +0100
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Wed Oct 30 12:15:06 2013 +0400
@@ -545,6 +545,9 @@
         
         window->fullscreenWindow = nil;
         window->isAccessibleInitComplete = NO;
+
+        window->isSizeAssigned = NO;
+        window->isLocationAssigned = NO;
     }
     [pool drain];
     
@@ -1092,16 +1095,9 @@
     GLASS_POOL_ENTER;
     {
         GlassWindow *window = getGlassWindow(env, jPtr);
-        NSPoint origin = [window _flipFrame].origin;
-        NSSize size = [window->nsWindow frame].size;
-        NSSize sizeForClient = [NSWindow frameRectForContentRect:NSMakeRect(0.0, 0.0, cw > 0 ? cw : 0.0, ch > 0 ? ch : 0.0) styleMask:[window->nsWindow styleMask]].size;
-        
-        jint newX = xSet == JNI_TRUE ? x : (jint)origin.x;
-        jint newY = ySet == JNI_TRUE ? y : (jint)origin.y;
-        jint newW = (w > 0) ? w : (cw > 0) ? (jint)sizeForClient.width : (jint)size.width;
-        jint newH = (h > 0) ? h : (ch > 0) ? (jint)sizeForClient.height : (jint)size.height;
-        
-        [window _setWindowFrameWithRect:NSMakeRect(newX, newY, newW, newH) withDisplay:JNI_TRUE withAnimate:JNI_FALSE];
+        if (xSet || ySet) window->isLocationAssigned = YES;
+        if (w > 0 || h > 0 || cw > 0 || ch > 0) window->isSizeAssigned = YES;
+        [window _setBounds:x y:y xSet:xSet ySet:ySet w:w h:h cw:cw ch:ch];
     }
     GLASS_POOL_EXIT;
     GLASS_CHECK_EXCEPTION(env);
@@ -1195,6 +1191,12 @@
         GlassWindow *window = getGlassWindow(env, jPtr);
         if (jVisible == JNI_TRUE)
         {
+            if (!window->isLocationAssigned) {
+                [window _setBounds:0 y:0 xSet:JNI_TRUE ySet:JNI_TRUE w:-1 h:-1 cw:-1 ch:-1];
+            }
+            if (!window->isSizeAssigned) {
+                [window _setBounds:0 y:0 xSet:JNI_FALSE ySet:JNI_FALSE w:320 h:200 cw:-1 ch:-1];
+            }
             [window _setVisible];
         }
         else