VAqua.libvaqua.JavaWindowAccess.m Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaqua Show documentation
Show all versions of vaqua Show documentation
An improved native Swing look and feel for macOS
The newest version!
/*
* Copyright (c) 2018-2023 Alan Snyder.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the license agreement. For details see
* accompanying license terms.
*/
// Support for mapping a native window to a Java window.
#include "jnix.h"
#import "JavaWindowAccess.h"
#import "AquaNativeSupport.h"
static jclass jc_CPlatformWindow;
static jfieldID jf_target;
// Map a native window to its Java window, if possible.
jobject getJavaWindow(JNIEnv *env, NSWindow *w)
{
jobject jPlatformWindow = getJavaPlatformWindow(env, w);
if (jPlatformWindow) {
GET_CLASS_RETURN(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow", NULL);
GET_FIELD_RETURN(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;", NULL);
jobject result = (*env)->GetObjectField(env, jPlatformWindow, jf_target);
CHECK_EXCEPTION();
return result;
}
return NULL;
}
// Map a native window to its Java platform window, if possible.
jobject getJavaPlatformWindow(JNIEnv *env, NSWindow *w)
{
NSObject *delegate = [w delegate];
if ([delegate respondsToSelector: @selector(javaPlatformWindow)]) {
long javaVersion = getJavaVersion();
if (javaVersion >= 1700000
|| (javaVersion >= 1500004 && javaVersion < 1600000)
|| (javaVersion >= 1300008 && javaVersion < 1400000)
|| (javaVersion >= 1100012 && javaVersion < 1300000)
) {
return (*env)->NewLocalRef(env, [delegate javaPlatformWindow]);
} else {
/* JNFWeakJObjectWrapper */ NSObject *jPlatformWindowWrapper = [delegate javaPlatformWindow];
if (jPlatformWindowWrapper) {
return [jPlatformWindowWrapper jObjectWithEnv:env];
}
}
}
return NULL;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy