diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java | 26 | ||||
-rwxr-xr-x | src/newt/native/WindowsWindow.c | 75 |
2 files changed, 93 insertions, 8 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java index 0d9015d66..d3f42d13e 100755 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -102,11 +102,22 @@ public class WindowsWindow extends Window { } } + // @Override public void setSize(int width, int height) { - setSize0(windowHandle, width, height); + if (width != this.width || this.height != height) { + this.width = width; + this.height = height; + setSize0(windowHandle, width, height); + } } + //@Override public void setPosition(int x, int y) { + if (this.x != x || this.y != y) { + this.x = x; + this.y = y; + setPosition(windowHandle, x, y); + } } public boolean setFullscreen(boolean fullscreen) { @@ -122,6 +133,17 @@ public class WindowsWindow extends Window { return true; } + // @Override + public void setTitle(String title) { + if (title == null) { + title = ""; + } + if (!title.equals(getTitle())) { + super.setTitle(title); + setTitle(windowHandle, title); + } + } + protected void dispatchMessages(int eventMask) { DispatchMessages(windowHandle, eventMask); } @@ -163,6 +185,8 @@ public class WindowsWindow extends Window { private static native void DispatchMessages(long windowHandle, int eventMask); private native void setSize0(long windowHandle, int width, int height); private native boolean setFullScreen0(long windowHandle, boolean fullscreen); + private static native void setPosition(long windowHandle, int x, int y); + private static native void setTitle(long windowHandle, String title); private void sizeChanged(int newWidth, int newHeight) { width = newWidth; diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index ca8fb68dc..5fa5cf9ba 100755 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -53,6 +53,7 @@ typedef int intptr_t; #include "EventListener.h" #include "MouseEvent.h" +#include "InputEvent.h" #include "KeyEvent.h" static jmethodID sizeChangedID = NULL; @@ -76,6 +77,26 @@ static jchar* GetNullTerminatedStringChars(JNIEnv* env, jstring str) return strChars; } +static jint ConvertModifiers(WPARAM wParam) { + jint modifiers = 0; + if ((wParam & MK_CONTROL) != 0) { + modifiers |= EVENT_CTRL_MASK; + } + if ((wParam & MK_SHIFT) != 0) { + modifiers |= EVENT_SHIFT_MASK; + } + if ((wParam & MK_CONTROL) != 0) { + modifiers |= EVENT_CTRL_MASK; + } + if ((wParam & MK_CONTROL) != 0) { + modifiers |= EVENT_CTRL_MASK; + } + if (HIBYTE(GetKeyState(VK_MENU)) != 0) { + modifiers |= EVENT_ALT_MASK; + } + return modifiers; +} + static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -143,43 +164,49 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, // 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); + ConvertModifiers(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); + ConvertModifiers(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); + ConvertModifiers(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); + ConvertModifiers(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); + ConvertModifiers(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); + ConvertModifiers(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); + ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 0); + useDefWindowProc = 1; + break; + + case WM_MOVE: + (*env)->CallVoidMethod(env, window, positionChangedID, + (jint)LOWORD(lParam), (jint)HIWORD(lParam)); useDefWindowProc = 1; break; @@ -513,3 +540,37 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setFul return JNI_FALSE; #endif } + +/* + * Class: com_sun_javafx_newt_windows_WindowsWindow + * Method: setPosition + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setPosition + (JNIEnv *env, jclass clazz, jlong window, jint x, jint y) +{ + UINT flags = SWP_NOACTIVATE | SWP_NOZORDER; + HWND hwnd = (HWND)window; + RECT r; + + GetWindowRect(hwnd, &r); + SetWindowPos(hwnd, 0, x, y, (r.right-r.left), (r.bottom-r.top), flags); +} + +/* + * Class: com_sun_javafx_newt_windows_WindowsWindow + * Method: setTitle + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setTitle + (JNIEnv *env, jclass clazz, jlong window, jstring title) +{ + HWND hwnd = (HWND)window; + if (title != NULL) { + jchar *titleString = GetNullTerminatedStringChars(env, title); + if (titleString != NULL) { + SetWindowTextW(hwnd, titleString); + free(titleString); + } + } +} |