aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/WindowsWindow.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/native/WindowsWindow.c')
-rw-r--r--[-rwxr-xr-x]src/newt/native/WindowsWindow.c186
1 files changed, 102 insertions, 84 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 5e3311d3b..cda6a4086 100755..100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -109,15 +109,17 @@
#define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
-static jmethodID sizeChangedID = NULL;
static jmethodID insetsChangedID = NULL;
+static jmethodID sizeChangedID = NULL;
static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
+static jmethodID visibleChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
-static jmethodID enqueueMouseEventID = NULL;
-static jmethodID enqueueKeyEventID = NULL;
-static jmethodID sendPaintEventID = NULL;
+static jmethodID windowRepaintID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
+static jmethodID focusActionID = NULL;
static RECT* UpdateInsets(JNIEnv *env, HWND hwnd, jobject window);
@@ -506,7 +508,7 @@ static int WmChar(JNIEnv *env, jobject window, UINT character, UINT repCnt,
if (character == VK_RETURN) {
character = J_VK_ENTER;
}
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -551,7 +553,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_PRESSED,
modifiers,
(jint) jkey,
@@ -562,7 +564,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
WM_KEYDOWN.
*/
if (jkey == J_VK_DELETE) {
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -586,7 +588,7 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_RELEASED,
modifiers,
(jint) jkey,
@@ -595,23 +597,27 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
return 0;
}
-static void NewtWindows_requestFocus (HWND hwnd, BOOL topLevel, BOOL reparented) {
- DBG_PRINT("*** WindowsWindow: requestFocus.0 window %p\n", (void*)hwnd);
- if (IsWindow(hwnd)) {
- UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
- if(reparented) {
- flags |= SWP_FRAMECHANGED;
- }
- SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags);
- DBG_PRINT("*** WindowsWindow: requestFocus.1\n");
- SetForegroundWindow(hwnd); // Slightly Higher Priority
- DBG_PRINT("*** WindowsWindow: requestFocus.2\n");
- SetFocus(hwnd);// Sets Keyboard Focus To TheWindow
- DBG_PRINT("*** WindowsWindow: requestFocus.3\n");
- if(topLevel) {
- SetActiveWindow(hwnd);
+static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, BOOL reparented) {
+ HWND pHwnd = GetParent(hwnd);
+ HWND current = GetFocus();
+ DBG_PRINT("*** WindowsWindow: requestFocus.0 parent %p, window %p, isCurrent %d\n",
+ (void*) pHwnd, (void*)hwnd, current==hwnd);
+ if(reparented || current!=hwnd) {
+ if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) {
+ UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
+ if(reparented) {
+ flags |= SWP_FRAMECHANGED;
+ }
+ SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags);
+ SetForegroundWindow(hwnd); // Slightly Higher Priority
+ SetFocus(hwnd);// Sets Keyboard Focus To Window
+ if(NULL!=pHwnd) {
+ SetActiveWindow(hwnd);
+ }
+ DBG_PRINT("*** WindowsWindow: requestFocus.X1\n");
+ } else {
+ DBG_PRINT("*** WindowsWindow: requestFocus.X0\n");
}
- DBG_PRINT("*** WindowsWindow: requestFocus.X\n");
}
}
@@ -706,6 +712,7 @@ static void WmSize(JNIEnv *env, HWND wnd, jobject window, UINT type)
static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
+ LRESULT res = 0;
int useDefWindowProc = 0;
JNIEnv *env = NULL;
jobject window = NULL;
@@ -798,8 +805,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_LBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: LBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -808,7 +816,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_LBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -817,8 +825,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: MBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -827,7 +836,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -836,8 +845,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: RBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -846,7 +856,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -855,7 +865,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MOUSEMOVE:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_MOVED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -871,7 +881,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
eventPt.x = x;
eventPt.y = y;
ScreenToClient(wnd, &eventPt);
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_WHEEL_MOVED,
GetModifiers(),
(jint) eventPt.x, (jint) eventPt.y,
@@ -881,17 +891,19 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
}
case WM_SETFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_TRUE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_TRUE);
useDefWindowProc = 1;
break;
case WM_KILLFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_FALSE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE);
useDefWindowProc = 1;
break;
+ case WM_SHOWWINDOW:
+ (*env)->CallVoidMethod(env, window, visibleChangedID, wParam==TRUE?JNI_TRUE:JNI_FALSE);
+ break;
+
case WM_MOVE:
DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d\n", wnd, (int)LOWORD(lParam), (int)HIWORD(lParam));
(*env)->CallVoidMethod(env, window, positionChangedID,
@@ -901,21 +913,24 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_PAINT: {
RECT r;
- if (GetUpdateRect(wnd, &r, FALSE)) {
- if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0) {
- (*env)->CallVoidMethod(env, window, sendPaintEventID,
- 0, r.left, r.top, r.right-r.left, r.bottom-r.top);
+ useDefWindowProc = 0;
+ if (GetUpdateRect(wnd, &r, TRUE /* erase background */)) {
+ /*
+ jint width = r.right-r.left;
+ jint height = r.bottom-r.top;
+ if (width > 0 && height > 0) {
+ (*env)->CallVoidMethod(env, window, windowRepaintID, r.left, r.top, width, height);
}
ValidateRect(wnd, &r);
- useDefWindowProc = 0;
- } else {
- useDefWindowProc = 1;
+ */
}
break;
}
case WM_ERASEBKGND:
// ignore erase background
+ (*env)->CallVoidMethod(env, window, windowRepaintID, 0, 0, -1, -1);
useDefWindowProc = 0;
+ res = 1;
break;
@@ -926,7 +941,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
if (useDefWindowProc)
return DefWindowProc(wnd, message, wParam, lParam);
- return 0;
+ return res;
}
/*
@@ -1052,24 +1067,29 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getHeight
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initIDs0
(JNIEnv *env, jclass clazz)
{
- sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V");
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
- focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(JZ)V");
+ focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V");
+ visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
- enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
- sendPaintEventID = (*env)->GetMethodID(env, clazz, "sendPaintEvent", "(IIIII)V");
- if (sizeChangedID == NULL ||
- insetsChangedID == NULL ||
+ windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z");
+
+ if (insetsChangedID == NULL ||
+ sizeChangedID == NULL ||
positionChangedID == NULL ||
focusChangedID == NULL ||
+ visibleChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
- enqueueMouseEventID == NULL ||
- sendPaintEventID == NULL ||
- enqueueKeyEventID == NULL)
+ windowRepaintID == NULL ||
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL ||
+ focusActionID == NULL)
{
return JNI_FALSE;
}
@@ -1139,13 +1159,6 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi
#endif
UpdateInsets(env, window, obj);
-
- ShowWindow(window, SW_SHOWNORMAL);
- if(NULL!=parentWindow) {
- NewtWindows_requestFocus ( window, FALSE, FALSE ); // request focus on this window, if not already ..
- } /* else {
- // top level already capable of receiving [keyboard] events
- } */
}
#ifdef UNICODE
@@ -1215,13 +1228,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_MonitorF
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setVisible0
(JNIEnv *_env, jclass clazz, jlong window, jboolean visible)
{
- HWND hWnd = (HWND) (intptr_t) window;
- DBG_PRINT("*** WindowsWindow: setVisible window %p, visible: %d\n", hWnd, (int)visible);
+ HWND hwnd = (HWND) (intptr_t) window;
+ DBG_PRINT("*** WindowsWindow: setVisible window %p, visible: %d\n", hwnd, (int)visible);
if (visible) {
- SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
- ShowWindow(hWnd, SW_SHOW);
+ SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
+ ShowWindow(hwnd, SW_SHOW);
} else {
- ShowWindow(hWnd, SW_HIDE);
+ ShowWindow(hwnd, SW_HIDE);
}
}
@@ -1292,14 +1305,14 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setPositi
}
}
-static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
+static void NewtWindows_reparentWindow(JNIEnv *env, jobject obj, HWND hwndP, HWND hwnd, BOOL visible,
+ jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
{
UINT flags;
HWND hWndInsertAfter;
DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
- BOOL isVisible = IsWindowVisible(hwnd);
- DBG_PRINT("*** WindowsWindow: reparentWindow.1 parent %p, window %p, %d/%d %dx%d undeco %d visible %d\n", (void*)hwndP, (void*)hwnd, x, y, width, height, bIsUndecorated, isVisible);
+ DBG_PRINT("*** WindowsWindow: reparentWindow.1 parent %p, window %p, %d/%d %dx%d undeco %d\n", (void*)hwndP, (void*)hwnd, x, y, width, height, bIsUndecorated);
if (!IsWindow(hwnd)) {
DBG_PRINT("*** WindowsWindow: reparentWindow failure: Passed window %p is invalid\n", (void*)hwnd);
return;
@@ -1309,8 +1322,8 @@ static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, ji
return;
}
- if (isVisible) {
- windowStyle |= WS_VISIBLE;
+ if(visible) {
+ windowStyle |= WS_VISIBLE ;
}
// order of call sequence: (MS documentation)
@@ -1337,10 +1350,6 @@ static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, ji
DBG_PRINT("*** WindowsWindow: reparentWindow.4\n");
}
- if(isVisible) {
- NewtWindows_requestFocus ( hwnd, ( NULL == hwndP ) ? TRUE : FALSE, TRUE );
- }
-
DBG_PRINT("*** WindowsWindow: reparentWindow.X\n");
}
@@ -1356,13 +1365,12 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullsc
HWND hwndP = (HWND) (intptr_t) parent;
HWND hwnd = (HWND) (intptr_t) window;
HWND hWndInsertAfter;
- DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
BOOL isVisible = IsWindowVisible(hwnd);
DBG_PRINT("*** WindowsWindow: setFullscreen.1 parent %p, window %p, %d/%d %dx%d undeco %d visible\n",
parent, window, x, y, width, height, bIsUndecorated, isVisible);
- NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
+ NewtWindows_reparentWindow(env, obj, hwndP, hwnd, FALSE, x, y, width, height, bIsUndecorated);
if ( NULL == hwndP ) {
flags = SWP_SHOWWINDOW;
@@ -1371,9 +1379,12 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullsc
flags = SWP_NOACTIVATE | SWP_NOZORDER;
hWndInsertAfter = 0;
}
-
SetWindowPos(hwnd, hWndInsertAfter, x, y, width, height, flags);
+ if(isVisible) {
+ NewtWindows_requestFocus ( env, obj, hwnd, TRUE ); // request focus on this window, if not already ..
+ }
+
DBG_PRINT("*** WindowsWindow: setFullscreen.X\n");
(*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height); // resize necessary ..
}
@@ -1388,8 +1399,14 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentW
{
HWND hwndP = (HWND) (intptr_t) parent;
HWND hwnd = (HWND) (intptr_t) window;
+ BOOL isVisible = IsWindowVisible(hwnd);
+
+ NewtWindows_reparentWindow(env, obj, hwndP, hwnd, FALSE, x, y, width, height, bIsUndecorated);
+
+ if(isVisible) {
+ NewtWindows_requestFocus ( env, obj, hwnd, TRUE ); // request focus on this window, if not already ..
+ }
- NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
}
/*
@@ -1416,8 +1433,9 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setTitle0
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_requestFocus0
- (JNIEnv *env, jclass clazz, jlong parent, jlong window)
+ (JNIEnv *env, jobject obj, jlong window)
{
- NewtWindows_requestFocus ( (HWND) (intptr_t) window, (0 == parent) ? TRUE : FALSE, FALSE ) ;
+ DBG_PRINT("*** WindowsWindow: RequestFocus0\n");
+ NewtWindows_requestFocus ( env, obj, (HWND) (intptr_t) window, FALSE ) ;
}