diff options
author | Kenneth Russel <[email protected]> | 2008-06-01 10:45:45 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-06-01 10:45:45 +0000 |
commit | 6ccca575ac92310b2ff2f8a495e84d754b021086 (patch) | |
tree | 8f58fbf71aea6f30155fbb95099c6a5dbd111b17 | |
parent | c71c40fbbd2655097cd8fc50fd64c9e8a6740fa0 (diff) |
Ported Newt event handling to Windows. Minor bug fixes to Windows
platform related to recent code refactoring. Unicode correctness in
Windows native code. Cosmetic fixes.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1657 232f8b59-042b-4e1e-8c03-345bb8c30851
-rw-r--r-- | make/build.xml | 11 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Display.java | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Screen.java | 2 | ||||
-rwxr-xr-x | src/native/jogl/WindowsWindow.c | 151 |
4 files changed, 130 insertions, 36 deletions
diff --git a/make/build.xml b/make/build.xml index 01f08750e..464e24a11 100644 --- a/make/build.xml +++ b/make/build.xml @@ -54,9 +54,9 @@ jogl.es2 jogl.noAWT jogl.noX11WindowsMacOsX - jogl.noX11 - jogl.noWindows - jogl.noMacOsX + jogl.noX11 + jogl.noWindows + jogl.noMacOsX --> <project name="JOGL" basedir="." default="all"> @@ -375,13 +375,12 @@ <target name="declare.common.2"> <!-- Java files to exclude based on platform (relative to "src.java") --> <!-- NOTE: the OpenGL ES exclusions are due to references to unsupported APIs --> - <property name="java.excludes.win32.gles" value="com/sun/opengl/impl/windows/*.java" /> - <property name="java.excludes.win32" value="${java.excludes.gles}, ${java.excludes.win32.gles}, ${java.excludes.impl.x11}, ${java.excludes.impl.win}, ${java.excludes.impl.macosx}, ${java.excludes.awt}" /> + <!-- FIXME: this needs refactoring at this point --> + <property name="java.excludes.win32" value="${java.excludes.gles}, ${java.excludes.impl.x11}, ${java.excludes.impl.win}, ${java.excludes.impl.macosx}, ${java.excludes.awt}" /> <property name="java.excludes.x11" value="${java.excludes.gles}, ${java.excludes.impl.x11}, ${java.excludes.impl.win}, ${java.excludes.impl.macosx}, ${java.excludes.awt}" /> <property name="java.excludes.macosx" value="${java.excludes.gles}, ${java.excludes.impl.x11}, ${java.excludes.impl.win}, ${java.excludes.impl.macosx}, ${java.excludes.awt}" /> </target> - <echo message="java.excludes.win32.gles: ${java.excludes.win32.gles}" /> <echo message="java.excludes.win32: ${java.excludes.win32}" /> <echo message="java.excludes.x11: ${java.excludes.x11}" /> <echo message="java.excludes.macosx: ${java.excludes.macosx}" /> diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java index 5ec2c381a..220a612a4 100755 --- a/src/classes/com/sun/javafx/newt/Display.java +++ b/src/classes/com/sun/javafx/newt/Display.java @@ -41,7 +41,7 @@ public abstract class Display { if (NewtFactory.KD.equals(type)) { displayClass = Class.forName("com.sun.javafx.newt.kd.KDDisplay"); } else if (NewtFactory.WINDOWS.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.displays.WindowsDisplay"); + displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); } else if (NewtFactory.X11.equals(type)) { displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); } else if (NewtFactory.MACOSX.equals(type)) { diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java index 9252b30d4..77414d00e 100755 --- a/src/classes/com/sun/javafx/newt/Screen.java +++ b/src/classes/com/sun/javafx/newt/Screen.java @@ -41,7 +41,7 @@ public abstract class Screen { if (NewtFactory.KD.equals(type)) { screenClass = Class.forName("com.sun.javafx.newt.kd.KDScreen"); } else if (NewtFactory.WINDOWS.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.screens.WindowsScreen"); + screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); } else if (NewtFactory.X11.equals(type)) { screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); } else if (NewtFactory.MACOSX.equals(type)) { diff --git a/src/native/jogl/WindowsWindow.c b/src/native/jogl/WindowsWindow.c index c33c68d3c..bf4dcb819 100755 --- a/src/native/jogl/WindowsWindow.c +++ b/src/native/jogl/WindowsWindow.c @@ -32,6 +32,7 @@ */ #include <windows.h> +#include <tchar.h> #include <stdlib.h> #ifdef UNDER_CE #include "aygshell.h" @@ -79,6 +80,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, RECT rc; int useDefWindowProc = 0; jobject window = NULL; + BOOL isKeyDown = FALSE; #ifdef UNDER_CE window = (jobject) GetWindowLong(wnd, GWL_USERDATA); @@ -100,15 +102,34 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, (*env)->CallVoidMethod(env, window, windowDestroyedID); break; + // Windows does the translation between key codes and key chars by + // producing synthetic WM_CHAR messages in response to WM_KEYDOWN + // messages. The Java level contains the state machine to assemble + // these multiple events into a single event. + case WM_CHAR: + // NOTE that the (1 << 31) bit is meaningless regardless of + // what the docs for WM_CHAR say; we never receive a WM_CHAR + // message in response to translating a WM_KEYUP message + (*env)->CallVoidMethod(env, window, sendKeyEventID, + (jint) EVENT_KEY_PRESSED, + // FIXME: need to interpret the key events in order to compute the modifiers + (jint) 0, + (jint) -1, + (jchar) wParam); + useDefWindowProc = 1; + break; + case WM_KEYDOWN: - (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED, - (jint) 0, (jint) 0x28, (jchar) 0); + // FIXME: need to interpret the key events in order to compute the modifiers + (*env)->CallVoidMethod(env, window, sendKeyEventID, (jint) EVENT_KEY_PRESSED, + (jint) 0, (jint) wParam, (jchar) -1); useDefWindowProc = 1; break; case WM_KEYUP: - (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED, - (jint) 0, (jint) 0x26, (jchar) 0); + // FIXME: need to interpret the key events in order to compute the modifiers + (*env)->CallVoidMethod(env, window, sendKeyEventID, (jint) EVENT_KEY_RELEASED, + (jint) 0, (jint) wParam, (jchar) -1); useDefWindowProc = 1; break; @@ -117,11 +138,50 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, (*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom); break; - /* FIXME: - case WM_MOUSE_LALA: - (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) eventType, (jint) mod, - (jint) x, (jint) y, (jint) button); - */ + // FIXME: define constants for the mouse buttons and modifiers + case WM_LBUTTONDOWN: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 1); + useDefWindowProc = 1; + break; + + case WM_LBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 1); + useDefWindowProc = 1; + break; + + case WM_MBUTTONDOWN: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 2); + useDefWindowProc = 1; + break; + + case WM_MBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 2); + useDefWindowProc = 1; + break; + + case WM_RBUTTONDOWN: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 3); + useDefWindowProc = 1; + break; + + case WM_RBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 3); + useDefWindowProc = 1; + break; + + case WM_MOUSEMOVE: + (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_MOVED, + (jint) wParam, (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 0); + useDefWindowProc = 1; + break; + + // FIXME: generate EVENT_MOUSE_ENTERED, EVENT_MOUSE_EXITED default: useDefWindowProc = 1; } @@ -178,10 +238,12 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_LoadLibra JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterWindowClass (JNIEnv *env, jclass clazz, jstring appName, jlong hInstance) { - WNDCLASSW* wc; + WNDCLASS* wc; +#ifndef UNICODE const char* _appName = NULL; +#endif - wc = calloc(1, sizeof(WNDCLASSW)); + wc = calloc(1, sizeof(WNDCLASS)); /* register class */ wc->style = CS_HREDRAW | CS_VREDRAW; wc->lpfnWndProc = (WNDPROC)wndProc; @@ -191,11 +253,17 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterW its HINSTANCE -- see MSDN docs for DllMain */ wc->hInstance = (HINSTANCE) hInstance; wc->hIcon = NULL; - wc->hCursor = 0; + wc->hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); wc->hbrBackground = GetStockObject(BLACK_BRUSH); wc->lpszMenuName = NULL; +#ifdef UNICODE wc->lpszClassName = GetNullTerminatedStringChars(env, appName); - if (!RegisterClassW(wc)) { +#else + _appName = (*env)->GetStringUTFChars(env, appName, NULL); + wc->lpszClassName = strdup(_appName); + (*env)->ReleaseStringUTFChars(env, appName, _appName); +#endif + if (!RegisterClass(wc)) { free(wc); return 0; } @@ -205,39 +273,50 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterW /* * Class: com_sun_javafx_newt_windows_WindowsWindow * Method: CreateWindow - * Signature: (Ljava/lang/String;JJIIII)J + * Signature: (Ljava/lang/String;JIIIII)J */ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWindow - (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jlong visualID, + (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jint visualID, jint jx, jint jy, jint defaultWidth, jint defaultHeight) { - jchar* wndClassName = GetNullTerminatedStringChars(env, windowClassName); + const TCHAR* wndClassName = NULL; DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; - int x=(int)x, y=(int)y; + int x=(int)jx, y=(int)jy; int width=(int)defaultWidth, height=(int)defaultHeight; HWND window = NULL; -/** FIXME: why ? use setFullscreen() .. - * +#ifdef UNICODE + wndClassName = GetNullTerminatedStringChars(env, windowClassName); +#else + wndClassName = (*env)->GetStringUTFChars(env, windowClassName, NULL); +#endif + + // FIXME: until we have valid values coming down from the + // application code, use some default values #ifdef UNDER_CE + // Prefer to not have any surprises in the initial window sizing or placement width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); x = y = 0; #else - windowStyle |= WS_OVERLAPPEDWINDOW; x = CW_USEDEFAULT; y = 0; - width = defaultWidth; - height = defaultHeight; + windowStyle |= WS_OVERLAPPEDWINDOW; #endif - */ + (void) visualID; // FIXME: use the visualID .. - window = CreateWindowW(wndClassName, wndClassName, windowStyle, - x, y, width, height, - NULL, NULL, - (HINSTANCE) hInstance, - NULL); + window = CreateWindow(wndClassName, wndClassName, windowStyle, + x, y, width, height, + NULL, NULL, + (HINSTANCE) hInstance, + NULL); +#ifdef UNICODE + free((void*) wndClassName); +#else + (*env)->ReleaseStringUTFChars(env, windowClassName, wndClassName); +#endif + if (window != NULL) { #ifdef UNDER_CE SetWindowLong(window, GWL_USERDATA, (intptr_t) (*env)->NewGlobalRef(env, obj)); @@ -251,6 +330,22 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin /* * Class: com_sun_javafx_newt_windows_WindowsWindow + * Method: setVisible0 + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setVisible0 + (JNIEnv *_env, jclass clazz, jlong window, jboolean visible) +{ + HWND hWnd = (HWND) (intptr_t) window; + if (visible) { + ShowWindow(hWnd, SW_SHOW); + } else { + ShowWindow(hWnd, SW_HIDE); + } +} + +/* + * Class: com_sun_javafx_newt_windows_WindowsWindow * Method: DispatchMessages * Signature: (J)V */ |