diff --git a/reactos/win32ss/user/user32/windows/dialog.c b/reactos/win32ss/user/user32/windows/dialog.c index d65e14d251c..0c879c69c75 100644 --- a/reactos/win32ss/user/user32/windows/dialog.c +++ b/reactos/win32ss/user/user32/windows/dialog.c @@ -46,7 +46,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32); #define GET_WORD(ptr) (*(WORD *)(ptr)) #define GET_DWORD(ptr) (*(DWORD *)(ptr)) #define DLG_ISANSI 2 -void WINAPI WinPosActivateOtherWindow(HWND hwnd); /* INTERNAL STRUCTS **********************************************************/ @@ -1062,7 +1061,21 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, return hwnd; } if (modal && ownerEnabled) DIALOG_EnableOwner(owner); - if( IsWindow(hwnd) ) DestroyWindow( hwnd ); + IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND, hwnd, OBJID_WINDOW, CHILDID_SELF, 0); + if( IsWindow(hwnd) ) + { + DestroyWindow( hwnd ); + //// ReactOS + if (owner) + { ERR("DIALOG_CreateIndirect 1\n"); + if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD) && // Rule #1. + !NtUserQueryWindow(owner, QUERY_WINDOW_FOREGROUND) ) + { ERR("DIALOG_CreateIndirect SFW\n"); + SetForegroundWindow(owner); + } + } + //// + } return 0; } @@ -2001,7 +2014,7 @@ DlgDirSelectExW( /* - * @implemented + * @implemented Modified for ReactOS. */ BOOL WINAPI @@ -2012,6 +2025,7 @@ EndDialog( BOOL wasEnabled = TRUE; DIALOGINFO * dlgInfo; HWND owner; + BOOL wasActive; TRACE("%p %ld\n", hwnd, retval ); @@ -2020,6 +2034,7 @@ EndDialog( ERR("got invalid window handle (%p); buggy app !?\n", hwnd); return FALSE; } + wasActive = (hwnd == GetActiveWindow()); dlgInfo->idResult = retval; dlgInfo->flags |= DF_END; wasEnabled = (dlgInfo->flags & DF_OWNERENABLED); @@ -2030,7 +2045,7 @@ EndDialog( /* Windows sets the focus to the dialog itself in EndDialog */ - if (IsChild(hwnd, GetFocus())) + if (wasActive && IsChild(hwnd, GetFocus())) SetFocus( hwnd ); /* Don't have to send a ShowWindow(SW_HIDE), just do @@ -2039,15 +2054,16 @@ EndDialog( SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW); - if (hwnd == GetActiveWindow()) + if (wasActive && owner) { /* If this dialog was given an owner then set the focus to that owner even when the owner is disabled (normally when a window closes any disabled windows cannot receive the focus). */ - if (owner) - SetForegroundWindow( owner ); - else - WinPosActivateOtherWindow( hwnd ); + SetActiveWindow(owner); + } + else if (hwnd == GetActiveWindow()) // Check it again! + { + NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS); } /* unblock dialog loop */ @@ -2593,13 +2609,15 @@ IsDialogMessageW( //// ReactOS case WM_SYSKEYDOWN: /* If the ALT key is being pressed display the keyboard cues */ - if (HIWORD(lpMsg->lParam) & KF_ALTDOWN) + if ( HIWORD(lpMsg->lParam) & KF_ALTDOWN && + !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) ) SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0); break; case WM_SYSCOMMAND: /* If the ALT key is being pressed display the keyboard cues */ - if (lpMsg->wParam == SC_KEYMENU) + if ( lpMsg->wParam == SC_KEYMENU && + !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) ) { SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0); } diff --git a/reactos/win32ss/user/user32/windows/winpos.c b/reactos/win32ss/user/user32/windows/winpos.c index 1ea3d01f2e1..8917ea4718f 100644 --- a/reactos/win32ss/user/user32/windows/winpos.c +++ b/reactos/win32ss/user/user32/windows/winpos.c @@ -25,57 +25,6 @@ void mirror_rect( const RECT *window_rect, RECT *rect ) /* FUNCTIONS *****************************************************************/ -/******************************************************************* - * can_activate_window - * - * Check if we can activate the specified window. - */ -static BOOL can_activate_window( HWND hwnd ) -{ - LONG style; - - if (!hwnd) return FALSE; - style = GetWindowLongPtrW( hwnd, GWL_STYLE ); - if (!(style & WS_VISIBLE)) return FALSE; - if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE; - return !(style & WS_DISABLED); -} - - -/******************************************************************* - * WINPOS_ActivateOtherWindow - * - * Activates window other than pWnd. - */ -void -WINAPI -WinPosActivateOtherWindow(HWND hwnd) -{ - HWND hwndTo, fg; - - if ((GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER ))) - { - hwndTo = GetAncestor( hwndTo, GA_ROOT ); - if (can_activate_window( hwndTo )) goto done; - } - - hwndTo = hwnd; - for (;;) - { - if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break; - if (can_activate_window( hwndTo )) break; - } - - done: - fg = GetForegroundWindow(); - TRACE("win = %p fg = %p\n", hwndTo, fg); - if (!fg || (hwnd == fg)) - { - if (SetForegroundWindow( hwndTo )) return; - } - if (!SetActiveWindow( hwndTo )) SetActiveWindow(0); -} - #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1) UINT WINAPI