diff options
Diffstat (limited to 'src/newt/native/WindowsWindow.c')
-rw-r--r-- | src/newt/native/WindowsWindow.c | 361 |
1 files changed, 272 insertions, 89 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index a9a5cac10..59e054516 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -181,6 +181,7 @@ static jmethodID maximizedChangedID = NULL; static jmethodID positionChangedID = NULL; static jmethodID focusChangedID = NULL; static jmethodID visibleChangedID = NULL; +static jmethodID sizePosInsetsFocusVisibleChangedID = NULL; static jmethodID windowDestroyNotifyID = NULL; static jmethodID windowRepaintID = NULL; static jmethodID sendMouseEventID = NULL; @@ -206,10 +207,18 @@ static int NewtEDID_avail = 0; typedef struct { JNIEnv* jenv; jobject jinstance; + /* client x-pos */ + int xpos; + /* client y-pos */ + int ypos; /* client size width */ int width; /* client size height */ int height; + /* visible state */ + BOOL visible; + /* focused state */ + BOOL focused; /* Insets left, right, top, bottom */ RECT insets; /** Tristate: -1 HIDE, 0 NOP, 1 SHOW */ @@ -226,6 +235,10 @@ typedef struct { BOOL isMinimized; /** Bool: 0 NOP, 1 maximized */ BOOL isMaximized; + BOOL isOnBottom; + BOOL isOnTop; + /** Bug 1205: Clear Window Background -> security! */ + BOOL isInCreation; int pointerCaptured; int pointerInside; int touchDownCount; @@ -608,21 +621,41 @@ static int WmKeyUp(JNIEnv *env, jobject window, USHORT wkey, WORD repCnt, BYTE s static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, jboolean force) { HWND pHwnd, current; + WindowUserData * wud; BOOL isEnabled = IsWindowEnabled(hwnd); pHwnd = GetParent(hwnd); current = GetFocus(); - DBG_PRINT("*** WindowsWindow: requestFocus.S force %d, parent %p, window %p, isEnabled %d, isCurrent %d\n", - (int)force, (void*)pHwnd, (void*)hwnd, isEnabled, current==hwnd); +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + wud = (WindowUserData *) GetWindowLong(hwnd, GWL_USERDATA); +#else + wud = (WindowUserData *) GetWindowLongPtr(hwnd, GWLP_USERDATA); +#endif + + DBG_PRINT("*** WindowsWindow: requestFocus.S force %d, parent %p, window %p, isEnabled %d, isCurrent %d, isOn[Top %d, Bottom %d]\n", + (int)force, (void*)pHwnd, (void*)hwnd, isEnabled, current==hwnd, + wud->isOnTop, wud->isOnBottom); if( JNI_TRUE==force || current!=hwnd || !isEnabled ) { UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; if(!isEnabled) { EnableWindow(hwnd, TRUE); } - SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags); - SetForegroundWindow(hwnd); // Slightly Higher Priority + BOOL frontWindow; + if( wud->isOnBottom ) { + SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); + frontWindow = FALSE; + } else if( wud->isOnTop ) { + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, flags); + frontWindow = TRUE; + } else { + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags); + frontWindow = TRUE; + } + if( frontWindow ) { + SetForegroundWindow(hwnd); // Slightly Higher Priority + } SetFocus(hwnd);// Sets Keyboard Focus To Window (activates parent window if exist, or this window) - if(NULL!=pHwnd) { + if( frontWindow && NULL!=pHwnd ) { SetActiveWindow(hwnd); } current = GetFocus(); @@ -671,10 +704,11 @@ static void UpdateInsets(JNIEnv *env, WindowUserData *wud, HWND hwnd) { jobject window = wud->jinstance; RECT outside; RECT inside; + int strategy = 0; if (IsIconic(hwnd)) { wud->insets.left = wud->insets.top = wud->insets.right = wud->insets.bottom = -1; - return FALSE; + return; } wud->insets.left = wud->insets.top = wud->insets.right = wud->insets.bottom = 0; @@ -688,6 +722,7 @@ static void UpdateInsets(JNIEnv *env, WindowUserData *wud, HWND hwnd) { wud->insets.bottom = outside.bottom - inside.bottom; wud->insets.left = inside.left - outside.left; wud->insets.right = outside.right - inside.right; + strategy = 1; } else { wud->insets.top = -1; } @@ -713,18 +748,21 @@ static void UpdateInsets(JNIEnv *env, WindowUserData *wud, HWND hwnd) { /* Add in title. */ wud->insets.top += GetSystemMetrics(SM_CYCAPTION); + strategy += 10; } else { /* undo the -1 set above */ wud->insets.left = wud->insets.top = wud->insets.right = wud->insets.bottom = 0; + strategy += 20; } } - DBG_PRINT("*** WindowsWindow: UpdateInsets window %p, [l %d, r %d - t %d, b %d - %dx%d]\n", - (void*)hwnd, (int)wud->insets.left, (int)wud->insets.right, (int)wud->insets.top, (int)wud->insets.bottom, - (int) ( wud->insets.left + wud->insets.right ), (int) (wud->insets.top + wud->insets.bottom)); - - (*env)->CallVoidMethod(env, window, insetsChangedID, JNI_FALSE, - (int)wud->insets.left, (int)wud->insets.right, (int)wud->insets.top, (int)wud->insets.bottom); + DBG_PRINT("*** WindowsWindow: UpdateInsets window %p, s %d, [l %d, r %d - t %d, b %d - %dx%d], at-init %d\n", + (void*)hwnd, strategy, (int)wud->insets.left, (int)wud->insets.right, (int)wud->insets.top, (int)wud->insets.bottom, + (int) ( wud->insets.left + wud->insets.right ), (int) (wud->insets.top + wud->insets.bottom), wud->isInCreation); + if( !wud->isInCreation ) { + (*env)->CallVoidMethod(env, window, insetsChangedID, JNI_FALSE, + (int)wud->insets.left, (int)wud->insets.right, (int)wud->insets.top, (int)wud->insets.bottom); + } } static void WmSize(JNIEnv *env, WindowUserData * wud, HWND wnd, UINT type) @@ -763,14 +801,16 @@ static void WmSize(JNIEnv *env, WindowUserData * wud, HWND wnd, UINT type) wud->width = (int) ( rc.right - rc.left ); wud->height = (int) ( rc.bottom - rc.top ); - DBG_PRINT("*** WindowsWindow: WmSize.X window %p, %dx%d, isMinimized %d, isMaximized %d (changed %d), visible %d\n", - (void*)wnd, wud->width, wud->height, wud->isMinimized, wud->isMaximized, maxChanged, isVisible); + DBG_PRINT("*** WindowsWindow: WmSize.X window %p, %dx%d, isMinimized %d, isMaximized %d (changed %d), visible %d, at-init %d\n", + (void*)wnd, wud->width, wud->height, wud->isMinimized, wud->isMaximized, maxChanged, isVisible, wud->isInCreation); - if( maxChanged ) { - jboolean v = wud->isMaximized ? JNI_TRUE : JNI_FALSE; - (*env)->CallVoidMethod(env, window, maximizedChangedID, v, v); + if( !wud->isInCreation ) { + if( maxChanged ) { + jboolean v = wud->isMaximized ? JNI_TRUE : JNI_FALSE; + (*env)->CallVoidMethod(env, window, maximizedChangedID, v, v); + } + (*env)->CallVoidMethod(env, window, sizeChangedID, JNI_FALSE, wud->width, wud->height, JNI_FALSE); } - (*env)->CallVoidMethod(env, window, sizeChangedID, JNI_FALSE, wud->width, wud->height, JNI_FALSE); } #ifdef TEST_MOUSE_HOOKS @@ -896,6 +936,7 @@ static void sendTouchScreenEvent(JNIEnv *env, jobject window, jNames, jX, jY, jPressure, (jfloat)maxPressure); } +// #define DO_ERASEBKGND 1 static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT res = 0; @@ -959,11 +1000,15 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP // Bug 916 - NEWT Fullscreen Mode on Windows ALT-TAB doesn't allow Application Switching // Remedy for 'some' display drivers, i.e. Intel HD: // Explicitly push fullscreen window to BOTTOM when inactive (ALT-TAB) - UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; - if( inactive ) { - SetWindowPos(wnd, HWND_BOTTOM, 0, 0, 0, 0, flags); + if( inactive || wud->isOnBottom ) { + SetWindowPos(wnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); } else { - SetWindowPos(wnd, HWND_TOP, 0, 0, 0, 0, flags); + UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; + if( wud->isOnTop ) { + SetWindowPos(wnd, HWND_TOPMOST, 0, 0, 0, 0, flags); + } else { + SetWindowPos(wnd, HWND_TOP, 0, 0, 0, 0, flags); + } SetForegroundWindow(wnd); // Slightly Higher Priority } } @@ -971,6 +1016,34 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP } break; + case WM_WINDOWPOSCHANGING: { + WINDOWPOS *p = (WINDOWPOS*)lParam; + BOOL isThis = wnd == p->hwnd; + BOOL isBottom = HWND_BOTTOM == p->hwndInsertAfter; + BOOL isTopMost = HWND_TOPMOST == p->hwndInsertAfter; + BOOL forceBottom = isThis && wud->isOnBottom && !isBottom; + BOOL forceTop = isThis && wud->isOnTop && !isTopMost; + #ifdef VERBOSE_ON + BOOL isNoTopMost = HWND_NOTOPMOST == p->hwndInsertAfter; + BOOL isTop = HWND_TOP == p->hwndInsertAfter; + BOOL isNoZ = 0 != ( SWP_NOZORDER & p->flags ); + DBG_PRINT("*** WindowsWindow: WM_WINDOWPOSCHANGING window %p / %p (= %d), %p[bottom %d, notop %d, top %d, topmost %d, noZ %d, force[Top %d, Bottom %d], %d/%d %dx%d 0x%X\n", + wnd, p->hwnd, isThis, + p->hwndInsertAfter, isBottom, isNoTopMost, isTop, isTopMost, isNoZ, + forceTop, forceBottom, + p->x, p->y, p->cx, p->cy, p->flags); + #endif + if( forceTop ) { + p->hwndInsertAfter = HWND_TOPMOST; + p->flags &= ~SWP_NOZORDER; + } else if( forceBottom ) { + p->hwndInsertAfter = HWND_BOTTOM; + p->flags &= ~SWP_NOZORDER; + } + useDefWindowProc = 1; + } + break; + case WM_SETTINGCHANGE: if (wParam == SPI_SETNONCLIENTMETRICS) { // make sure insets are updated, we don't need to resize the window @@ -986,33 +1059,79 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP break; case WM_SHOWWINDOW: - DBG_PRINT("*** WindowsWindow: WM_SHOWWINDOW window %p: %d\n", wnd, wParam==TRUE); - (*env)->CallVoidMethod(env, window, visibleChangedID, JNI_FALSE, wParam==TRUE?JNI_TRUE:JNI_FALSE); + DBG_PRINT("*** WindowsWindow: WM_SHOWWINDOW window %p: %d, at-init %d\n", wnd, wParam==TRUE, wud->isInCreation); + wud->visible = wParam==TRUE; + if( !wud->isInCreation ) { + (*env)->CallVoidMethod(env, window, visibleChangedID, JNI_FALSE, wParam==TRUE?JNI_TRUE:JNI_FALSE); + } break; case WM_MOVE: - DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d\n", wnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - (*env)->CallVoidMethod(env, window, positionChangedID, JNI_FALSE, (jint)GET_X_LPARAM(lParam), (jint)GET_Y_LPARAM(lParam)); + wud->xpos = (int)GET_X_LPARAM(lParam); + wud->ypos = (int)GET_Y_LPARAM(lParam); + DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d, at-init %d\n", wnd, wud->xpos, wud->ypos, wud->isInCreation); + if( !wud->isInCreation ) { + (*env)->CallVoidMethod(env, window, positionChangedID, JNI_FALSE, (jint)wud->xpos, (jint)wud->ypos); + } useDefWindowProc = 1; break; case WM_PAINT: { - RECT r; - if (GetUpdateRect(wnd, &r, FALSE /* do not erase background */)) { - // clear the whole client area and issue repaint for it, w/o looping through erase background - ValidateRect(wnd, NULL); // clear all! - (*env)->CallVoidMethod(env, window, windowRepaintID, JNI_FALSE, 0, 0, -1, -1); + if( wud->isInCreation ) { + #ifdef DO_ERASEBKGND + if (GetUpdateRect(wnd, NULL, TRUE /* erase background */)) { + DBG_PRINT("*** WindowsWindow: WM_PAINT.0 (dirty)\n"); + // WM_ERASEBKGND sent! + #else + if (GetUpdateRect(wnd, NULL, FALSE /* do not erase background */)) { + DBG_PRINT("*** WindowsWindow: WM_PAINT.0 (dirty)\n"); + ValidateRect(wnd, NULL); // clear all! + #endif + } else { + DBG_PRINT("*** WindowsWindow: WM_PAINT.0 (clean)\n"); + } } else { - // shall not happen ? - ValidateRect(wnd, NULL); // clear all! + if (GetUpdateRect(wnd, NULL, FALSE /* do not erase background */)) { + DBG_PRINT("*** WindowsWindow: WM_PAINT.1 (dirty)\n"); + // Let NEWT render the whole client area by issueing repaint for it, w/o looping through erase background + ValidateRect(wnd, NULL); // clear all! + (*env)->CallVoidMethod(env, window, windowRepaintID, JNI_FALSE, 0, 0, -1, -1); + } else { + DBG_PRINT("*** WindowsWindow: WM_PAINT.1 (clean)\n"); + // shall not happen ? + ValidateRect(wnd, NULL); // clear all! + } + // return 0 == done } - // return 0 == done break; } case WM_ERASEBKGND: - // ignore erase background - (*env)->CallVoidMethod(env, window, windowRepaintID, JNI_FALSE, 0, 0, -1, -1); - res = 1; // return 1 == done, OpenGL, etc .. erases the background, hence we claim to have just done this + if( wud->isInCreation ) { + #ifdef DO_ERASEBKGND + // On Windows the initial window is clean?! + // This fill destroys translucency on Windows 10 + // (which only seem to work on undecorated windows) + PAINTSTRUCT ps; + HDC hdc; + hdc = BeginPaint(wnd, &ps); + DBG_PRINT("*** WindowsWindow: WM_ERASEBKGND.0 (erasure) l/b %d/%d r/t %d/%d\n", + ps.rcPaint.left, ps.rcPaint.bottom, ps.rcPaint.right, ps.rcPaint.top); + // FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW+1)); + // FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_APPWORKSPACE+1)); + // A black color also sets alpha to zero for translucency! + FillRect(hdc, &ps.rcPaint, (HBRUSH)GetStockObject(BLACK_PEN)); + EndPaint(wnd, &ps); + #else + ValidateRect(wnd, NULL); // clear all! + #endif + res = 1; // return 1 == done + } else { + // ignore erase background, but let NEWT render the whole client area + DBG_PRINT("*** WindowsWindow: WM_ERASEBKGND.1 (repaint)\n"); + ValidateRect(wnd, NULL); // clear all! + (*env)->CallVoidMethod(env, window, windowRepaintID, JNI_FALSE, 0, 0, -1, -1); + res = 1; // return 1 == done, OpenGL, etc .. erases the background, hence we claim to have just done this + } break; case WM_SETCURSOR : @@ -1061,8 +1180,11 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP break; case WM_SETFOCUS: - DBG_PRINT("*** WindowsWindow: WM_SETFOCUS window %p, lost %p\n", wnd, (HWND)wParam); - (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE, JNI_TRUE); + DBG_PRINT("*** WindowsWindow: WM_SETFOCUS window %p, lost %p, at-init %d\n", wnd, (HWND)wParam, wud->isInCreation); + wud->focused = TRUE; + if( !wud->isInCreation ) { + (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE, JNI_TRUE); + } useDefWindowProc = 1; break; @@ -1075,7 +1197,10 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP wud->pointerCaptured = 0; ReleaseCapture(); } - (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE, JNI_FALSE); + wud->focused = FALSE; + if( !wud->isInCreation ) { + (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE, JNI_FALSE); + } useDefWindowProc = 1; } else { // quick focus .. we had it already, are enabled .. @@ -2003,6 +2128,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_windows_WindowDriver_initIDs0 positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V"); focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(ZZ)V"); visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V"); + sizePosInsetsFocusVisibleChangedID = (*env)->GetMethodID(env, clazz, "sizePosInsetsFocusVisibleChanged", "(ZIIIIIIIIIIZ)V"); windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(ZIIII)V"); sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(SIIISF)V"); @@ -2016,6 +2142,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_windows_WindowDriver_initIDs0 positionChangedID == NULL || focusChangedID == NULL || visibleChangedID == NULL || + sizePosInsetsFocusVisibleChangedID == NULL || windowDestroyNotifyID == NULL || windowRepaintID == NULL || sendMouseEventID == NULL || @@ -2078,6 +2205,9 @@ static void NewtWindow_setVisiblePosSize(WindowUserData *wud, HWND hwnd, int jfl if(visible) { wflags = SWP_SHOWWINDOW; + if( abottom ) { + wflags |= SWP_NOACTIVATE; + } } else { wflags = SWP_NOACTIVATE | SWP_NOZORDER; } @@ -2085,6 +2215,8 @@ static void NewtWindow_setVisiblePosSize(WindowUserData *wud, HWND hwnd, int jfl wflags |= SWP_NOSIZE; } + wud->isOnTop = atop; + wud->isOnBottom = abottom; if(atop) { SetWindowPos(hwnd, HWND_TOP, x, y, width, height, wflags); SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, wflags); @@ -2095,7 +2227,6 @@ static void NewtWindow_setVisiblePosSize(WindowUserData *wud, HWND hwnd, int jfl SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, width, height, wflags); SetWindowPos(hwnd, HWND_TOP, x, y, width, height, wflags); } - // SetWindowPos(hwnd, atop ? HWND_TOPMOST : HWND_TOP, x, y, width, height, wflags); if( TST_FLAG_CHANGE_MAXIMIZED_ANY(jflags) ) { if( TST_FLAG_IS_MAXIMIZED_VERT(jflags) && TST_FLAG_IS_MAXIMIZED_HORZ(jflags) ) { @@ -2122,16 +2253,15 @@ static void NewtWindow_setVisiblePosSize(WindowUserData *wud, HWND hwnd, int jfl JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindow0 (JNIEnv *env, jobject obj, jlong hInstance, jstring jWndClassName, jstring jWndName, jint winMajor, jint winMinor, - jlong parent, jint jx, jint jy, jint defaultWidth, jint defaultHeight, jint flags) + jlong parent, jint jxpos, jint jypos, jint defaultWidth, jint defaultHeight, jint flags) { HWND parentWindow = (HWND) (intptr_t) parent; const TCHAR* wndClassName = NULL; const TCHAR* wndName = NULL; - DWORD windowStyle = WS_DEFAULT_STYLES | WS_VISIBLE; - int x=(int)jx, y=(int)jy; + DWORD windowStyle = WS_DEFAULT_STYLES; + int xpos=(int)jxpos, ypos=(int)jypos; int width=(int)defaultWidth, height=(int)defaultHeight; - HWND window = NULL; - int _x = x, _y = y; // pos for CreateWindow, might be tweaked + HWND hwnd = NULL; #ifdef UNICODE wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName); @@ -2147,10 +2277,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo return 0; } windowStyle |= WS_CHILD ; - } else if ( TST_FLAG_IS_UNDECORATED(flags) ) { - windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; } else { - if ( TST_FLAG_IS_RESIZABLE(flags) ) { + if ( TST_FLAG_IS_UNDECORATED(flags) ) { + windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + } else if ( TST_FLAG_IS_RESIZABLE(flags) ) { // WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); windowStyle |= WS_OVERLAPPEDWINDOW; } else { @@ -2158,31 +2288,32 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo } if( TST_FLAG_IS_AUTOPOSITION(flags) ) { // user didn't requested specific position, use WM default - _x = CW_USEDEFAULT; - _y = 0; + xpos = CW_USEDEFAULT; + ypos = 0; } } - window = CreateWindow(wndClassName, wndName, windowStyle, - _x, _y, width, height, - parentWindow, NULL, - (HINSTANCE) (intptr_t) hInstance, - NULL); + hwnd = CreateWindow(wndClassName, wndName, windowStyle, + xpos, ypos, width, height, + parentWindow, NULL, (HINSTANCE) (intptr_t) hInstance, NULL); - DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, win %d.%d parent %p, window %p, %d/%d %dx%d, undeco %d, alwaysOnTop %d, autoPosition %d\n", - (int)GetCurrentThreadId(), winMajor, winMinor, parentWindow, window, x, y, width, height, + DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, win %d.%d parent %p, window %p, %d/%d -> %d/%d %dx%d, undeco %d, alwaysOnTop %d, autoPosition %d\n", + (int)GetCurrentThreadId(), winMajor, winMinor, parentWindow, hwnd, jxpos, jypos, xpos, ypos, width, height, TST_FLAG_IS_UNDECORATED(flags), TST_FLAG_IS_ALWAYSONTOP(flags), TST_FLAG_IS_AUTOPOSITION(flags)); - if (NULL == window) { + if (NULL == hwnd) { int lastError = (int) GetLastError(); DBG_PRINT("*** WindowsWindow: CreateWindow failure: 0x%X %d\n", lastError, lastError); - return 0; } else { WindowUserData * wud = (WindowUserData *) malloc(sizeof(WindowUserData)); wud->jinstance = (*env)->NewGlobalRef(env, obj); wud->jenv = env; + wud->xpos = xpos; + wud->ypos = ypos; wud->width = width; wud->height = height; + wud->visible = TRUE; + wud->focused = TRUE; wud->setPointerVisible = 0; wud->setPointerAction = 0; wud->defPointerHandle = LoadCursor( NULL, IDC_ARROW); @@ -2191,6 +2322,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo wud->isChildWindow = NULL!=parentWindow; wud->isMinimized = FALSE; wud->isMaximized = FALSE; + wud->isOnBottom = FALSE; + wud->isOnTop = FALSE; + wud->isInCreation = TRUE; wud->pointerCaptured = 0; wud->pointerInside = 0; wud->touchDownCount = 0; @@ -2209,32 +2343,26 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo DBG_PRINT("*** WindowsWindow: CreateWindow winTouchFuncAvail %d, supportsMTouch %d\n", WinTouch_func_avail, wud->supportsMTouch); #if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) - SetWindowLong(window, GWL_USERDATA, (intptr_t) wud); + SetWindowLong(hwnd, GWL_USERDATA, (intptr_t) wud); #else - SetWindowLongPtr(window, GWLP_USERDATA, (intptr_t) wud); + SetWindowLongPtr(hwnd, GWLP_USERDATA, (intptr_t) wud); #endif - // gather and adjust position and size - { - RECT rc; - - ShowWindow(window, SW_SHOW); - - // send insets before visibility, allowing java code a proper sync point! - UpdateInsets(env, wud, window); - (*env)->CallVoidMethod(env, wud->jinstance, visibleChangedID, JNI_FALSE, JNI_TRUE); + // send insets before visibility, allowing java code a proper sync point! + UpdateInsets(env, wud, hwnd); - if( TST_FLAG_IS_AUTOPOSITION(flags) ) { - GetWindowRect(window, &rc); - x = rc.left + wud->insets.left; // client coords - y = rc.top + wud->insets.top; // client coords - } - DBG_PRINT("*** WindowsWindow: CreateWindow client: %d/%d %dx%d (autoPosition %d)\n", x, y, width, height, TST_FLAG_IS_AUTOPOSITION(flags)); - NewtWindow_setVisiblePosSize(wud, window, flags, TRUE, x, y, width, height); - } - if( wud->supportsMTouch ) { - WinTouch_RegisterTouchWindow(window, 0); + if( TST_FLAG_IS_AUTOPOSITION(flags) ) { + RECT rc; + GetWindowRect(hwnd, &rc); + xpos = rc.left + wud->insets.left; // client coords + ypos = rc.top + wud->insets.top; // client coords + wud->xpos = xpos; + wud->ypos = ypos; } + DBG_PRINT("*** WindowsWindow: CreateWindow client: %d/%d %dx%d -> %d/%d %dx%d (autoPosition %d)\n", + xpos, ypos, width, height, + wud->xpos, wud->ypos, wud->width, wud->height, + TST_FLAG_IS_AUTOPOSITION(flags)); } #ifdef UNICODE @@ -2251,7 +2379,49 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo DBG_PRINT("**** LLMP Hook %p, MP Hook %p\n", hookLLMP, hookMP); #endif - return (jlong) (intptr_t) window; + DBG_PRINT("*** WindowsWindow: CreateWindow done\n"); + return (jlong) (intptr_t) hwnd; +} + +/* + * Class: jogamp_newt_driver_windows_WindowDriver + * Method: InitWindow + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_InitWindow0 + (JNIEnv *env, jobject obj, jlong window, jint flags) +{ + HWND hwnd = (HWND) (intptr_t) window; + WindowUserData * wud; +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + wud = (WindowUserData *) GetWindowLong(hwnd, GWL_USERDATA); +#else + wud = (WindowUserData *) GetWindowLongPtr(hwnd, GWLP_USERDATA); +#endif + + DBG_PRINT("*** WindowsWindow: InitWindow start %d/%d %dx%d, focused %d, visible %d\n", + wud->xpos, wud->ypos, wud->width, wud->height, wud->focused, wud->visible); + + NewtWindow_setVisiblePosSize(wud, hwnd, flags, TRUE, wud->xpos, wud->ypos, wud->width, wud->height); + wud->isInCreation = FALSE; + + DBG_PRINT("*** WindowsWindow: InitWindow pos/size set: %d/%d %dx%d, focused %d, visible %d\n", + wud->xpos, wud->ypos, wud->width, wud->height, wud->focused, wud->visible); + + if( wud->isMaximized ) { + (*env)->CallVoidMethod(env, wud->jinstance, maximizedChangedID, JNI_TRUE, JNI_TRUE); + } + (*env)->CallVoidMethod(env, wud->jinstance, sizePosInsetsFocusVisibleChangedID, JNI_FALSE, + (jint)wud->xpos, (jint)wud->ypos, + (jint)wud->width, (jint)wud->height, + (jint)wud->insets.left, (jint)wud->insets.right, (jint)wud->insets.top, (jint)wud->insets.bottom, + (jint)(wud->focused ? 1 : 0), + (jint)(wud->visible ? 1 : 0), + JNI_FALSE); + DBG_PRINT("*** WindowsWindow: InitWindow JNI callbacks done\n"); + + if( wud->supportsMTouch ) { + WinTouch_RegisterTouchWindow(hwnd, 0); + } } /* @@ -2283,6 +2453,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW DWORD windowStyle = WS_DEFAULT_STYLES; BOOL styleChange = TST_FLAG_CHANGE_DECORATION(flags) || TST_FLAG_CHANGE_FULLSCREEN(flags) || TST_FLAG_CHANGE_PARENTING(flags) || TST_FLAG_CHANGE_RESIZABLE(flags); + BOOL atop = TST_FLAG_IS_ALWAYSONTOP(flags); + BOOL abottom = TST_FLAG_IS_ALWAYSONBOTTOM(flags); WindowUserData * wud; #if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) wud = (WindowUserData *) GetWindowLong(hwnd, GWL_USERDATA); @@ -2290,12 +2462,13 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW wud = (WindowUserData *) GetWindowLongPtr(hwnd, GWLP_USERDATA); #endif - DBG_PRINT( "*** WindowsWindow: reconfigureWindow0 parent %p, window %p, %d/%d %dx%d, parentChange %d, isChild %d, undecoration[change %d, val %d], fullscreen[change %d, val %d], alwaysOnTop[change %d, val %d], visible[change %d, val %d], resizable[change %d, val %d] -> styleChange %d, isChild %d, isMinimized %d, isMaximized %d, isFullscreen %d\n", + DBG_PRINT( "*** WindowsWindow: reconfigureWindow0 parent %p, window %p, %d/%d %dx%d, parentChange %d, isChild %d, undecoration[change %d, val %d], fullscreen[change %d, val %d], alwaysOnTop[change %d, val %d], alwaysOnBottom[change %d, val %d], visible[change %d, val %d], resizable[change %d, val %d] -> styleChange %d, isChild %d, isMinimized %d, isMaximized %d, isFullscreen %d\n", parent, window, x, y, width, height, TST_FLAG_CHANGE_PARENTING(flags), TST_FLAG_IS_CHILD(flags), TST_FLAG_CHANGE_DECORATION(flags), TST_FLAG_IS_UNDECORATED(flags), TST_FLAG_CHANGE_FULLSCREEN(flags), TST_FLAG_IS_FULLSCREEN(flags), TST_FLAG_CHANGE_ALWAYSONTOP(flags), TST_FLAG_IS_ALWAYSONTOP(flags), + TST_FLAG_CHANGE_ALWAYSONBOTTOM(flags), TST_FLAG_IS_ALWAYSONBOTTOM(flags), TST_FLAG_CHANGE_VISIBILITY(flags), TST_FLAG_IS_VISIBLE(flags), TST_FLAG_CHANGE_RESIZABLE(flags), TST_FLAG_CHANGE_RESIZABLE(flags), styleChange, wud->isChildWindow, wud->isMinimized, wud->isMaximized, wud->isFullscreen); @@ -2305,6 +2478,9 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW return; } + wud->isOnTop = atop; + wud->isOnBottom = abottom; + if (NULL!=hwndP && !IsWindow(hwndP)) { DBG_PRINT("*** WindowsWindow: reconfigureWindow0 failure: Passed parent window %p is invalid\n", (void*)hwndP); return; @@ -2329,10 +2505,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW SetParent(hwnd, NULL); } - if( TST_FLAG_CHANGE_FULLSCREEN(flags) && TST_FLAG_IS_FULLSCREEN(flags) ) { // FS on - // TOP: in -> out - wud->isFullscreen = TRUE; - NewtWindows_setFullScreen(JNI_TRUE); + if( TST_FLAG_IS_FULLSCREEN(flags) ) { + if( TST_FLAG_CHANGE_FULLSCREEN(flags) ) { // FS on + wud->isFullscreen = TRUE; + if( !abottom ) { + NewtWindows_setFullScreen(JNI_TRUE); + } + } else if( TST_FLAG_CHANGE_ALWAYSONBOTTOM(flags) ) { // FS BOTTOM toggle + NewtWindows_setFullScreen( abottom ? JNI_FALSE : JNI_TRUE); + } } if ( styleChange ) { @@ -2351,7 +2532,6 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW } if( TST_FLAG_CHANGE_FULLSCREEN(flags) && !TST_FLAG_IS_FULLSCREEN(flags) ) { // FS off - // CHILD: out -> in wud->isFullscreen = FALSE; NewtWindows_setFullScreen(JNI_FALSE); } @@ -2365,9 +2545,12 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowDriver_reconfigureW if( TST_FLAG_CHANGE_VISIBILITY(flags) ) { if( TST_FLAG_IS_VISIBLE(flags) ) { - int cmd = wud->isMinimized ? SW_RESTORE : SW_SHOW; + int cmd = wud->isMinimized ? SW_RESTORE : ( abottom ? SW_SHOWNA : SW_SHOW ); wud->isMinimized = FALSE; ShowWindow(hwnd, cmd); + if( abottom ) { + SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); + } } else if( !TST_FLAG_CHANGE_VISIBILITY_FAST(flags) && !TST_FLAG_IS_CHILD(flags) ) { wud->isMinimized = TRUE; ShowWindow(hwnd, SW_MINIMIZE); |