< prev index next >
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -53,10 +53,15 @@
// which had been the key window just before a new key window
// was set. It would be nil if the new key window isn't an AWT
// window or the app currently has no key window.
static AWTWindow* lastKeyWindow = nil;
+// This variable contains coordinates of a window's top left
+// which was positioned via java.awt.Window.setLocationByPlatform.
+// It would be NSZeroPoint if 'Location by Platform' is not used.
+static NSPoint lastTopLeftPoint;
+
// --------------------------------------------------------------
// NSWindow/NSPanel descendants implementation
#define AWT_NS_WINDOW_IMPLEMENTATION \
- (id) initWithDelegate:(AWTWindow *)delegate \
frameRect:(NSRect)contectRect \
@@ -1082,10 +1087,35 @@
JNF_COCOA_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CPlatformWindow
+ * Method: nativeSetNSWindowLocationByPlatform
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+ JNF_COCOA_ENTER(env);
+
+ NSWindow *nsWindow = OBJC(windowPtr);
+ [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+
+ if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
+ // This is the first usage of lastTopLeftPoint. So invoke cascadeTopLeftFromPoint
+ // twice to avoid positioning the window's top left to zero-point, since it may
+ // cause negative user experience.
+ lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
+ }
+ lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
+ }];
+
+ JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class: sun_lwawt_macosx_CPlatformWindow
* Method: nativeSetNSWindowMinMax
* Signature: (JDDDD)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
< prev index next >