aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-06-15 04:22:59 +0000
committerSven Gothel <[email protected]>2009-06-15 04:22:59 +0000
commitd99a2964f2891e7b3b214142ad003b198fe5a688 (patch)
tree5cd9cd5a7595efce29f90c52deba24e715c49899 /src/newt
parentfd94e280f644d5cf5c46f3f1b8eb835ed323ed60 (diff)
NEWT MacOSX fullscreen fix - real fullscreen now, some leakage fixes; MainThread - dealock fix in case invoke already runs on main-thread
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1950 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/newt')
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java171
-rw-r--r--src/newt/classes/com/sun/javafx/newt/util/MainThread.java8
-rw-r--r--src/newt/native/MacWindow.m178
-rw-r--r--src/newt/native/NewtMacWindow.h25
-rw-r--r--src/newt/native/NewtMacWindow.m144
5 files changed, 329 insertions, 197 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
index 73526eb33..86cff2d9f 100755
--- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
@@ -129,7 +129,7 @@ public class MacWindow extends Window {
private static final int NSHelpFunctionKey = 0xF746;
private static final int NSModeSwitchFunctionKey = 0xF747;
- private long nativeWindow;
+ private long surfaceHandle;
// non fullscreen dimensions ..
private int nfs_width, nfs_height, nfs_x, nfs_y;
@@ -161,9 +161,9 @@ public class MacWindow extends Window {
class CloseAction implements Runnable {
public void run() {
if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName());
- if (nativeWindow != 0) {
- close0(nativeWindow);
- nativeWindow = 0;
+ if (windowHandle != 0) {
+ close0(windowHandle);
+ windowHandle = 0;
}
}
}
@@ -171,38 +171,54 @@ public class MacWindow extends Window {
protected void closeNative() {
if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.closeNative "+Thread.currentThread().getName());
- MainThread.invoke(true, this, closeAction);
+ MainThread.invoke(true, this, closeAction); // blocks: modifies resources
}
public long getSurfaceHandle() {
- if (nativeWindow == 0) {
- return 0;
+ if(0==surfaceHandle) {
+ surfaceHandle = contentView(windowHandle);
}
- return contentView(nativeWindow);
+ return surfaceHandle;
+ }
+
+ private void createWindow(boolean recreate) {
+ if(0!=windowHandle && !recreate) {
+ return;
+ }
+ if(0!=windowHandle) {
+ // save the view .. close the window
+ surfaceHandle = changeContentView(windowHandle, 0);
+ close0(windowHandle);
+ windowHandle=0;
+ } else {
+ surfaceHandle = 0;
+ }
+ windowHandle = createWindow0(getX(), getY(), getWidth(), getHeight(), fullscreen,
+ (isUndecorated() ?
+ NSBorderlessWindowMask :
+ NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask),
+ NSBackingStoreBuffered,
+ getScreen().getIndex(), surfaceHandle);
+ if (windowHandle == 0) {
+ throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this);
+ }
+ surfaceHandle = contentView(windowHandle);
+ setTitle0(windowHandle, getTitle());
+ makeKeyAndOrderFront(windowHandle);
+ makeKey(windowHandle);
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
}
class VisibleAction implements Runnable {
public void run() {
if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName());
if (visible) {
- if (nativeWindow == 0) {
- nativeWindow = createWindow(getX(), getY(), getWidth(), getHeight(),
- (isUndecorated() ?
- NSBorderlessWindowMask :
- NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask),
- NSBackingStoreBuffered,
- true);
- }
- if (nativeWindow != 0) {
- setTitle0(nativeWindow, getTitle());
- makeKeyAndOrderFront(nativeWindow);
- sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
- sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
- sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- }
+ createWindow(false);
} else {
- if (nativeWindow != 0) {
- orderOut(nativeWindow);
+ if (windowHandle != 0) {
+ orderOut(windowHandle);
}
}
}
@@ -212,13 +228,13 @@ public class MacWindow extends Window {
public void setVisible(boolean visible) {
this.visible = visible;
if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.setVisible "+visible+" "+Thread.currentThread().getName());
- MainThread.invoke(true, this, visibleAction);
+ MainThread.invoke(true, this, visibleAction); // blocks: modifies resources
}
class TitleAction implements Runnable {
public void run() {
- if (nativeWindow != 0) {
- setTitle0(nativeWindow, title);
+ if (windowHandle != 0) {
+ setTitle0(windowHandle, title);
}
}
}
@@ -226,13 +242,13 @@ public class MacWindow extends Window {
public void setTitle(String title) {
super.setTitle(title);
- MainThread.invoke(true, this, titleAction);
+ MainThread.invoke(false, this, titleAction);
}
class FocusAction implements Runnable {
public void run() {
- if (nativeWindow != 0) {
- makeKey(nativeWindow);
+ if (windowHandle != 0) {
+ makeKey(windowHandle);
}
}
}
@@ -240,13 +256,13 @@ public class MacWindow extends Window {
public void requestFocus() {
super.requestFocus();
- MainThread.invoke(true, this, focusAction);
+ MainThread.invoke(false, this, focusAction);
}
class SizeAction implements Runnable {
public void run() {
- if (nativeWindow != 0) {
- setContentSize(nativeWindow, width, height);
+ if (windowHandle != 0) {
+ setContentSize(windowHandle, width, height);
}
}
}
@@ -259,13 +275,13 @@ public class MacWindow extends Window {
nfs_width=width;
nfs_height=height;
}
- MainThread.invoke(false, this, sizeAction);
+ MainThread.invoke(true, this, sizeAction); // blocks: modifies resources
}
class PositionAction implements Runnable {
public void run() {
- if (nativeWindow != 0) {
- setFrameTopLeftPoint(nativeWindow, x, y);
+ if (windowHandle != 0) {
+ setFrameTopLeftPoint(windowHandle, x, y);
}
}
}
@@ -283,7 +299,7 @@ public class MacWindow extends Window {
class DispatchAction implements Runnable {
public void run() {
- dispatchMessages0(nativeWindow, eventMask);
+ dispatchMessages0(windowHandle, eventMask);
}
}
private DispatchAction dispatchAction = new DispatchAction();
@@ -295,44 +311,40 @@ public class MacWindow extends Window {
}
class FullscreenAction implements Runnable {
- int x, y, w, h;
- public void set(int x, int y, int w, int h) {
- this.x=x; this.y=y; this.w=w; this.h=h;
- }
public void run() {
- if (nativeWindow != 0) {
+ createWindow(true);
+ /*
+ if (windowHandle != 0) {
if(fullscreen) {
- setFrameTopLeftPoint(nativeWindow, x, y);
- setContentSize(nativeWindow, w, h);
+ setFrameTopLeftPoint(windowHandle, x, y);
+ setContentSize(windowHandle, width, height);
} else {
- setContentSize(nativeWindow, w, h);
- setFrameTopLeftPoint(nativeWindow, x, y);
+ setContentSize(windowHandle, width, height);
+ setFrameTopLeftPoint(windowHandle, x, y);
}
- }
+ } */
}
}
private FullscreenAction fullscreenAction = new FullscreenAction();
public boolean setFullscreen(boolean fullscreen) {
if(this.fullscreen!=fullscreen) {
- int x, y, w, h;
this.fullscreen=fullscreen;
if(fullscreen) {
x = 0;
y = 0;
- w = screen.getWidth();
- h = screen.getHeight();
+ width = screen.getWidth();
+ height = screen.getHeight();
} else {
x = nfs_x;
y = nfs_y;
- w = nfs_width;
- h = nfs_height;
+ width = nfs_width;
+ height = nfs_height;
}
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h);
+ System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height);
}
- fullscreenAction.set(x, y, w, h);
- MainThread.invoke(false, this, fullscreenAction);
+ MainThread.invoke(true, this, fullscreenAction); // blocks: modifies resources
}
return fullscreen;
}
@@ -341,36 +353,32 @@ public class MacWindow extends Window {
if (DEBUG_IMPLEMENTATION) {
System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight);
}
- if (width != newWidth || height != newHeight) {
- width = newWidth;
- height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- }
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(" Posted WINDOW_RESIZED event");
- }
- sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
+ width = newWidth;
+ height = newHeight;
+ if(!fullscreen) {
+ nfs_width=width;
+ nfs_height=height;
}
+ if (DEBUG_IMPLEMENTATION) {
+ System.out.println(" Posted WINDOW_RESIZED event");
+ }
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
}
private void positionChanged(int newX, int newY) {
if (DEBUG_IMPLEMENTATION) {
System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY);
}
- if (x != newX || y != newY) {
- x = newX;
- y = newY;
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- }
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(" Posted WINDOW_MOVED event");
- }
- sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
+ x = newX;
+ y = newY;
+ if(!fullscreen) {
+ nfs_x=x;
+ nfs_y=y;
+ }
+ if (DEBUG_IMPLEMENTATION) {
+ System.out.println(" Posted WINDOW_MOVED event");
}
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
private void focusChanged(boolean focusGained) {
@@ -472,10 +480,10 @@ public class MacWindow extends Window {
super.sendKeyEvent(eventType, modifiers, key, keyChar);
}
- private native long createWindow(int x, int y, int w, int h,
- int windowStyle,
+ private native long createWindow0(int x, int y, int w, int h,
+ boolean fullscreen, int windowStyle,
int backingStoreType,
- boolean deferCreation);
+ int screen_idx, long view);
private native void makeKeyAndOrderFront(long window);
private native void makeKey(long window);
private native void orderOut(long window);
@@ -483,6 +491,7 @@ public class MacWindow extends Window {
private native void setTitle0(long window, String title);
protected native void dispatchMessages0(long window, int eventMask);
private native long contentView(long window);
+ private native long changeContentView(long window, long view);
private native void setContentSize(long window, int w, int h);
private native void setFrameTopLeftPoint(long window, int x, int y);
protected static native int getScreenWidth(int scrn_idx);
diff --git a/src/newt/classes/com/sun/javafx/newt/util/MainThread.java b/src/newt/classes/com/sun/javafx/newt/util/MainThread.java
index d3459adf9..4b7dae178 100644
--- a/src/newt/classes/com/sun/javafx/newt/util/MainThread.java
+++ b/src/newt/classes/com/sun/javafx/newt/util/MainThread.java
@@ -92,6 +92,7 @@ public class MainThread {
private static boolean shouldStop;
private static ArrayList tasks;
private static ArrayList tasksBlock;
+ private static Thread mainThread;
static class MainAction extends Thread {
private String mainClassName;
@@ -161,6 +162,7 @@ public class MainThread {
shouldStop = false;
tasks = new ArrayList();
tasksBlock = new ArrayList();
+ mainThread = Thread.currentThread();
mainAction = new MainAction(mainClassName, mainClassArgs);
@@ -186,9 +188,9 @@ public class MainThread {
return;
}
- // if this main thread is not being used,
- // let them run it on their own thread ..
- if(!isRunning()) {
+ // if this main thread is not being used or
+ // if this is already the main thread .. just execute.
+ if( !isRunning() || mainThread == Thread.currentThread() ) {
r.run();
return;
}
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m
index aa1385801..70170e525 100644
--- a/src/newt/native/MacWindow.m
+++ b/src/newt/native/MacWindow.m
@@ -44,25 +44,6 @@
#import <stdio.h>
-// For some reason, rightMouseDown isn't automatically being passed
-// from the NSView to the containing NSWindow
-
-@interface NewtView : NSView
-{
-}
-
-@end
-
-@implementation NewtView
-- (void) rightMouseDown: (NSEvent*) theEvent
-{
- NSResponder* next = [self nextResponder];
- if (next != nil) {
- [next rightMouseDown: theEvent];
- }
-}
-@end
-
NSString* jstringToNSString(JNIEnv* env, jstring jstr)
{
const jchar* jstrChars = (*env)->GetStringChars(env, jstr, NULL);
@@ -81,6 +62,32 @@ void setFrameTopLeftPoint(NSWindow* win, jint x, jint y)
[win setFrameTopLeftPoint: pt];
}
+static NewtView * changeContentView(JNIEnv *env, jobject javaWindowObject, NSWindow *win, NewtView *newView) {
+ NSView* oldNSView = [win contentView];
+ NewtView* oldView = NULL;
+
+ if(NULL!=oldNSView) {
+ if([oldNSView isInFullScreenMode]) {
+ // FIXME: Available >= 10.5 - Makes the taskbar disapear
+ [oldNSView exitFullScreenModeWithOptions: NULL];
+ }
+ if( [oldNSView isMemberOfClass:[NewtView class]] ) {
+ oldView = (NewtView *) oldNSView;
+
+ jobject globJavaWindowObject = [oldView getJavaWindowObject];
+ (*env)->DeleteGlobalRef(env, globJavaWindowObject);
+ [oldView setJavaWindowObject: NULL];
+ }
+ }
+ if(NULL!=newView) {
+ jobject globJavaWindowObject = (*env)->NewGlobalRef(env, javaWindowObject);
+ [newView setJavaWindowObject: globJavaWindowObject];
+ }
+ [win setContentView: newView];
+
+ return oldView;
+}
+
/*
* Class: com_sun_javafx_newt_macosx_MacWindow
* Method: initIDs
@@ -117,41 +124,61 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_initIDs
/*
* Class: com_sun_javafx_newt_macosx_MacWindow
- * Method: createWindow
- * Signature: (IIIIIIZ)J
+ * Method: createWindow0
+ * Signature: (IIIIZIIIJ)J
*/
-JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow
- (JNIEnv *env, jobject jthis, jint x, jint y, jint w, jint h, jint styleMask, jint bufferingType, jboolean deferCreation)
+JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow0
+ (JNIEnv *env, jobject jthis, jint x, jint y, jint w, jint h, jboolean fullscreen, jint styleMask,
+ jint bufferingType, jint screen_idx, jlong jview)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSRect rect = NSMakeRect(x, y, w, h);
- jobject windowObj = (*env)->NewGlobalRef(env, jthis);
+
+ NSArray *screens = [NSScreen screens];
+ if(screen_idx<0) screen_idx=0;
+ if(screen_idx>=[screens count]) screen_idx=0;
+ NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx];
+
+ if (fullscreen) {
+ styleMask = NSBorderlessWindowMask;
+ NSRect rect = [screen frame];
+ w = (jint) (rect.size.width);
+ h = (jint) (rect.size.height);
+ }
// Allocate the window
NSWindow* window = [[[NewtMacWindow alloc] initWithContentRect: rect
styleMask: (NSUInteger) styleMask
backing: (NSBackingStoreType) bufferingType
- defer: YES
- javaWindowObject: windowObj] retain];
-
- // If the window is undecorated, assume we want the possibility of
- // a shaped window, so make it non-opaque and the background color clear
- if ((styleMask & NSTitledWindowMask) == 0) {
- [window setOpaque: NO];
- [window setBackgroundColor: [NSColor clearColor]];
+ screen: screen] retain];
+
+ if (fullscreen) {
+ [window setOpaque: YES];
+ } else {
+ // If the window is undecorated, assume we want the possibility of
+ // a shaped window, so make it non-opaque and the background color clear
+ if ((styleMask & NSTitledWindowMask) == 0) {
+ [window setOpaque: NO];
+ [window setBackgroundColor: [NSColor clearColor]];
+ }
}
// Immediately re-position the window based on an upper-left coordinate system
setFrameTopLeftPoint(window, x, y);
- // Allocate an NSView
- NSView* view = [[NewtView alloc] initWithFrame: rect];
-
// specify we want mouse-moved events
[window setAcceptsMouseMovedEvents:YES];
+ // Use given NewtView or allocate an NewtView if NULL
+ NewtView* view = (0==jview)? [[NewtView alloc] initWithFrame: rect] : (NewtView*) ((intptr_t) jview) ;
+
// Set the content view
- [window setContentView: view];
+ (void) changeContentView(env, jthis, window, view);
+
+ if(fullscreen) {
+ // FIXME: Available >= 10.5 - Makes the taskbar disapear
+ [view enterFullScreenMode: screen withOptions:NULL];
+ }
// Set the next responder to be the window so that we can forward
// right mouse button down events
@@ -245,23 +272,37 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_dispatchMessage
NSEvent* event = NULL;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NewtMacWindow* nwwin = (NewtMacWindow*) ((intptr_t) window);
- [nwwin setJNIEnv: env];
+NS_DURING
+
+ NSWindow* win = (NSWindow *) ((intptr_t) window);
+
+ if(NULL != win) {
+ NewtView* view = (NewtView *) [win contentView];
+ [view setJNIEnv: env];
+
+ do {
+ // FIXME: ignoring event mask for the time being
+ event = [NSApp nextEventMatchingMask: NSAnyEventMask
+ untilDate: [NSDate distantPast]
+ inMode: NSDefaultRunLoopMode
+ dequeue: YES];
+ if (event != NULL) {
+ win = (NSWindow*) [event window];
+ view = (NewtView *) [win contentView];
+ [view setJNIEnv: env];
+
+ [NSApp sendEvent: event];
+ }
+ } while (event != NULL);
+ }
+
+NS_HANDLER
+
+ // just ignore it ..
+
+NS_ENDHANDLER
- do {
- // FIXME: ignoring event mask for the time being
- event = [NSApp nextEventMatchingMask: NSAnyEventMask
- untilDate: [NSDate distantPast]
- inMode: NSDefaultRunLoopMode
- dequeue: YES];
- if (event != NULL) {
- NewtMacWindow* nwwin = (NewtMacWindow*) [event window];
- [nwwin setJNIEnv: env];
- [NSApp sendEvent: event];
- }
- } while (event != NULL);
- // [nwwin setJNIEnv: NULL];
[pool release];
}
@@ -282,6 +323,25 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_contentView
/*
* Class: com_sun_javafx_newt_macosx_MacWindow
+ * Method: changeContentView
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_changeContentView
+ (JNIEnv *env, jobject jthis, jlong window, jlong jview)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSWindow* win = (NewtMacWindow*) ((intptr_t) window);
+ NewtView* newView = (NewtView *) ((intptr_t) jview);
+
+ NewtView* oldView = changeContentView(env, jthis, win, newView);
+
+ [pool release];
+
+ return oldView;
+}
+
+/*
+ * Class: com_sun_javafx_newt_macosx_MacWindow
* Method: setContentSize
* Signature: (JII)V
*/
@@ -315,14 +375,14 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setFrameTopLeft
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_getScreenWidth
- (JNIEnv *env, jclass clazz, jint sidx)
+ (JNIEnv *env, jclass clazz, jint screen_idx)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray *screens = [NSScreen screens];
- if(sidx<0) sidx=0;
- if(sidx>=[screens count]) sidx=0;
- NSScreen *screen = (NSScreen *) [screens objectAtIndex: sidx];
+ if(screen_idx<0) screen_idx=0;
+ if(screen_idx>=[screens count]) screen_idx=0;
+ NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx];
NSRect rect = [screen frame];
[pool release];
@@ -336,14 +396,14 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_getScreenWidth
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_getScreenHeight
- (JNIEnv *env, jclass clazz, jint sidx)
+ (JNIEnv *env, jclass clazz, jint screen_idx)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray *screens = [NSScreen screens];
- if(sidx<0) sidx=0;
- if(sidx>=[screens count]) sidx=0;
- NSScreen *screen = (NSScreen *) [screens objectAtIndex: sidx];
+ if(screen_idx<0) screen_idx=0;
+ if(screen_idx>=[screens count]) screen_idx=0;
+ NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx];
NSRect rect = [screen frame];
[pool release];
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index fc8a1e4f3..09f9ffbd2 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -34,7 +34,7 @@
#import <AppKit/AppKit.h>
#import "jni.h"
-@interface NewtMacWindow : NSWindow
+@interface NewtView : NSView
{
jobject javaWindowObject;
@@ -42,15 +42,28 @@
JNIEnv* env;
}
-+ (BOOL) initNatives: (JNIEnv*) env forClass: (jobject) clazz;
-
-/* Set and cleared during event dispatching cycle */
+/* Set during event dispatching cycle */
- (void) setJNIEnv: (JNIEnv*) env;
+- (JNIEnv*) getJNIEnv;
+
+/* Register or deregister (NULL) the java Window object,
+ ie, if NULL, no events are send */
+- (void) setJavaWindowObject: (jobject) javaWindowObj;
+- (jobject) getJavaWindowObject;
+
+- (void) rightMouseDown: (NSEvent*) theEvent;
+
+@end
+
+@interface NewtMacWindow : NSWindow
+{
+}
+
++ (BOOL) initNatives: (JNIEnv*) env forClass: (jobject) clazz;
- (id) initWithContentRect: (NSRect) contentRect
styleMask: (NSUInteger) windowStyle
backing: (NSBackingStoreType) bufferingType
- defer: (BOOL) deferCreation
- javaWindowObject: (jobject) javaWindowObj;
+ screen:(NSScreen *)screen;
@end
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 94837359d..62c6a6e25 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -36,6 +36,35 @@
#import "KeyEvent.h"
#import "MouseEvent.h"
+@implementation NewtView
+- (void) setJNIEnv: (JNIEnv*) theEnv
+{
+ env = theEnv;
+}
+- (JNIEnv*) getJNIEnv
+{
+ return env;
+}
+
+- (void) setJavaWindowObject: (jobject) javaWindowObj
+{
+ javaWindowObject = javaWindowObj;
+}
+
+- (jobject) getJavaWindowObject
+{
+ return javaWindowObject;
+}
+
+- (void) rightMouseDown: (NSEvent*) theEvent
+{
+ NSResponder* next = [self nextResponder];
+ if (next != nil) {
+ [next rightMouseDown: theEvent];
+ }
+}
+@end
+
static jmethodID sendMouseEventID = NULL;
static jmethodID sendKeyEventID = NULL;
static jmethodID sizeChangedID = NULL;
@@ -61,22 +90,16 @@ static jmethodID windowDestroyedID = NULL;
return NO;
}
-- (void) setJNIEnv: (JNIEnv*) theEnv
-{
- env = theEnv;
-}
-
- (id) initWithContentRect: (NSRect) contentRect
styleMask: (NSUInteger) windowStyle
backing: (NSBackingStoreType) bufferingType
- defer: (BOOL) deferCreation
- javaWindowObject: (jobject) javaWindowObj
+ screen:(NSScreen *)screen
{
id res = [super initWithContentRect: contentRect
styleMask: windowStyle
backing: bufferingType
- defer: deferCreation];
- javaWindowObject = javaWindowObj;
+ defer: YES
+ screen: screen];
// Why is this necessary? Without it we don't get any of the
// delegate methods like resizing and window movement.
[self setDelegate: self];
@@ -110,20 +133,23 @@ static jint mods2JavaMods(NSUInteger mods)
- (void) sendKeyEvent: (NSEvent*) event eventType: (jint) evType
{
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
+ return;
+ }
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
+ return;
+ }
+
int i;
jint keyCode = (jint) [event keyCode];
NSString* chars = [event charactersIgnoringModifiers];
int len = [chars length];
jint javaMods = mods2JavaMods([event modifierFlags]);
- if (env == NULL) {
- return;
- }
-
- if (javaWindowObject == NULL) {
- return;
- }
-
for (i = 0; i < len; i++) {
// Note: the key code in the NSEvent does not map to anything we can use
jchar keyChar = (jchar) [chars characterAtIndex: i];
@@ -145,6 +171,17 @@ static jint mods2JavaMods(NSUInteger mods)
- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType
{
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
+ return;
+ }
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
+ return;
+ }
+
jint javaMods = mods2JavaMods([event modifierFlags]);
NSRect frameRect = [self frame];
NSRect contentRect = [self contentRectForFrameRect: frameRect];
@@ -179,14 +216,6 @@ static jint mods2JavaMods(NSUInteger mods)
break;
}
- if (env == NULL) {
- return;
- }
-
- if (javaWindowObject == NULL) {
- return;
- }
-
(*env)->CallVoidMethod(env, javaWindowObject, sendMouseEventID,
evType, javaMods,
(jint) location.x,
@@ -259,17 +288,20 @@ static jint mods2JavaMods(NSUInteger mods)
- (void)windowDidResize: (NSNotification*) notification
{
- NSRect frameRect = [self frame];
- NSRect contentRect = [self contentRectForFrameRect: frameRect];
-
- if (env == NULL) {
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
}
-
- if (javaWindowObject == NULL) {
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
return;
}
+ NSRect frameRect = [self frame];
+ NSRect contentRect = [self contentRectForFrameRect: frameRect];
+
(*env)->CallVoidMethod(env, javaWindowObject, sizeChangedID,
(jint) contentRect.size.width,
(jint) contentRect.size.height);
@@ -277,20 +309,23 @@ static jint mods2JavaMods(NSUInteger mods)
- (void)windowDidMove: (NSNotification*) notification
{
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
+ return;
+ }
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
+ return;
+ }
+
NSRect rect = [self frame];
NSScreen* menuBarScreen = NULL;
NSScreen* screen = NULL;
NSRect screenRect;
NSPoint pt;
- if (env == NULL) {
- return;
- }
-
- if (javaWindowObject == NULL) {
- return;
- }
-
// FIXME: unclear whether this works correctly in multiple monitor situations
screen = [self screen];
screenRect = [screen visibleFrame];
@@ -302,25 +337,35 @@ static jint mods2JavaMods(NSUInteger mods)
- (void)windowWillClose: (NSNotification*) notification
{
- if (env == NULL) {
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
}
-
- if (javaWindowObject == NULL) {
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
return;
}
(*env)->CallVoidMethod(env, javaWindowObject, windowDestroyNotifyID);
// Will be called by Window.java (*env)->CallVoidMethod(env, javaWindowObject, windowDestroyedID);
+
+ // EOL ..
+ (*env)->DeleteGlobalRef(env, javaWindowObject);
+ [view setJavaWindowObject: NULL];
}
- (void) windowDidBecomeKey: (NSNotification *) notification
{
- if (env == NULL) {
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
}
-
- if (javaWindowObject == NULL) {
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
return;
}
@@ -329,11 +374,14 @@ static jint mods2JavaMods(NSUInteger mods)
- (void) windowDidResignKey: (NSNotification *) notification
{
- if (env == NULL) {
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
}
-
- if (javaWindowObject == NULL) {
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ JNIEnv* env = [view getJNIEnv];
+ if (env==NULL || javaWindowObject == NULL) {
return;
}