From 9abd2ae8d18c096fe4b62db4408d3777f0a34851 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 19 May 2022 13:24:26 +0200 Subject: [PATCH] win32u: Move NtUserSetInternalWindowPos implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/user32/sysparams.c | 20 ---- dlls/user32/user32.spec | 2 +- dlls/user32/win.h | 2 - dlls/user32/winpos.c | 208 ----------------------------------- dlls/win32u/gdiobj.c | 1 + dlls/win32u/win32u.spec | 2 +- dlls/win32u/win32u_private.h | 1 + dlls/win32u/window.c | 26 +++++ dlls/win32u/wrappers.c | 6 + include/ntuser.h | 1 + 10 files changed, 37 insertions(+), 232 deletions(-) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index c42b6c77b0c..ec83a1822a5 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -739,16 +739,6 @@ POINT point_win_to_thread_dpi( HWND hwnd, POINT pt ) return map_dpi_point( pt, GetDpiForWindow( hwnd ), dpi ); } -/********************************************************************** - * point_thread_to_win_dpi - */ -POINT point_thread_to_win_dpi( HWND hwnd, POINT pt ) -{ - UINT dpi = get_thread_dpi(); - if (!dpi) dpi = get_win_monitor_dpi( hwnd ); - return map_dpi_point( pt, dpi, GetDpiForWindow( hwnd )); -} - /********************************************************************** * map_dpi_rect */ @@ -774,16 +764,6 @@ RECT rect_win_to_thread_dpi( HWND hwnd, RECT rect ) return map_dpi_rect( rect, GetDpiForWindow( hwnd ), dpi ); } -/********************************************************************** - * rect_thread_to_win_dpi - */ -RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect ) -{ - UINT dpi = get_thread_dpi(); - if (!dpi) dpi = get_win_monitor_dpi( hwnd ); - return map_dpi_rect( rect, dpi, GetDpiForWindow( hwnd ) ); -} - /********************************************************************** * SetProcessDpiAwarenessContext (USER32.@) */ diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index dfa5c2516b9..d251b80fb70 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -673,7 +673,7 @@ @ stdcall SetFocus(long) NtUserSetFocus @ stdcall SetForegroundWindow(long) @ stdcall SetGestureConfig(ptr long long ptr long) -@ stdcall SetInternalWindowPos(long long ptr ptr) +@ stdcall SetInternalWindowPos(long long ptr ptr) NtUserSetInternalWindowPos @ stdcall SetKeyboardState(ptr) NtUserSetKeyboardState @ stdcall SetLastErrorEx(long long) @ stdcall SetLayeredWindowAttributes(ptr long long long) NtUserSetLayeredWindowAttributes diff --git a/dlls/user32/win.h b/dlls/user32/win.h index 2155ea51e94..dfa5fdf3283 100644 --- a/dlls/user32/win.h +++ b/dlls/user32/win.h @@ -70,10 +70,8 @@ extern POINT map_dpi_point( POINT pt, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDD extern POINT point_win_to_phys_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; extern POINT point_phys_to_win_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; extern POINT point_win_to_thread_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; -extern POINT point_thread_to_win_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; extern RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN; extern RECT rect_win_to_thread_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN; -extern RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN; static inline void mirror_rect( const RECT *window_rect, RECT *rect ) { diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c index d19ebab3e6e..e4eee036f07 100644 --- a/dlls/user32/winpos.c +++ b/dlls/user32/winpos.c @@ -44,10 +44,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(win); #define ON_BOTTOM_BORDER(hit) \ (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT)) -#define PLACE_MIN 0x0001 -#define PLACE_MAX 0x0002 -#define PLACE_RECT 0x0004 - /*********************************************************************** * SwitchToThisWindow (USER32.@) @@ -220,33 +216,6 @@ BOOL WINAPI BringWindowToTop( HWND hwnd ) } -/******************************************************************* - * get_work_rect - * - * Get the work area that a maximized window can cover, depending on style. - */ -static BOOL get_work_rect( HWND hwnd, RECT *rect ) -{ - HMONITOR monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY ); - MONITORINFO mon_info; - DWORD style; - - if (!monitor) return FALSE; - - mon_info.cbSize = sizeof(mon_info); - GetMonitorInfoW( monitor, &mon_info ); - *rect = mon_info.rcMonitor; - - style = GetWindowLongW( hwnd, GWL_STYLE ); - if (style & WS_MAXIMIZEBOX) - { - if ((style & WS_CAPTION) == WS_CAPTION || !(style & (WS_CHILD | WS_POPUP))) - *rect = mon_info.rcWork; - } - return TRUE; -} - - /*********************************************************************** * GetInternalWindowPos (USER32.@) */ @@ -266,47 +235,6 @@ UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd, } -static RECT get_maximized_work_rect( HWND hwnd ) -{ - RECT work_rect = { 0 }; - - if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_MINIMIZE | WS_MAXIMIZE)) == WS_MAXIMIZE) - { - if (!get_work_rect( hwnd, &work_rect )) - work_rect = get_primary_monitor_rect(); - } - return work_rect; -} - - -/******************************************************************* - * update_maximized_pos - * - * For top level windows covering the work area, we might have to - * "forget" the maximized position. Windows presumably does this - * to avoid situations where the border style changes, which would - * lead the window to be outside the screen, or the window gets - * reloaded on a different screen, and the "saved" position no - * longer applies to it (despite being maximized). - * - * Some applications (e.g. Imperiums: Greek Wars) depend on this. - */ -static void update_maximized_pos( WND *wnd, RECT *work_rect ) -{ - if (wnd->parent && wnd->parent != GetDesktopWindow()) - return; - - if (wnd->dwStyle & WS_MAXIMIZE) - { - if (wnd->window_rect.left <= work_rect->left && wnd->window_rect.top <= work_rect->top && - wnd->window_rect.right >= work_rect->right && wnd->window_rect.bottom >= work_rect->bottom) - wnd->max_pos.x = wnd->max_pos.y = -1; - } - else - wnd->max_pos.x = wnd->max_pos.y = -1; -} - - /*********************************************************************** * GetWindowPlacement (USER32.@) * @@ -318,115 +246,6 @@ BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl ) return NtUserGetWindowPlacement( hwnd, wndpl ); } -/* make sure the specified rect is visible on screen */ -static void make_rect_onscreen( RECT *rect ) -{ - MONITORINFO info; - HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST ); - - info.cbSize = sizeof(info); - if (!monitor || !GetMonitorInfoW( monitor, &info )) return; - /* FIXME: map coordinates from rcWork to rcMonitor */ - if (rect->right <= info.rcWork.left) - { - rect->right += info.rcWork.left - rect->left; - rect->left = info.rcWork.left; - } - else if (rect->left >= info.rcWork.right) - { - rect->left += info.rcWork.right - rect->right; - rect->right = info.rcWork.right; - } - if (rect->bottom <= info.rcWork.top) - { - rect->bottom += info.rcWork.top - rect->top; - rect->top = info.rcWork.top; - } - else if (rect->top >= info.rcWork.bottom) - { - rect->top += info.rcWork.bottom - rect->bottom; - rect->bottom = info.rcWork.bottom; - } -} - -/* make sure the specified point is visible on screen */ -static void make_point_onscreen( POINT *pt ) -{ - RECT rect; - - SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 ); - make_rect_onscreen( &rect ); - pt->x = rect.left; - pt->y = rect.top; -} - - -/*********************************************************************** - * WINPOS_SetPlacement - */ -static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags ) -{ - DWORD style; - RECT work_rect = get_maximized_work_rect( hwnd ); - WND *pWnd = WIN_GetPtr( hwnd ); - WINDOWPLACEMENT wp = *wndpl; - - if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition ); - if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition ); - if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition ); - - TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x adjusted to min %d,%d max %d,%d normal %s\n", - hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y, - wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y, - wine_dbgstr_rect(&wndpl->rcNormalPosition), flags, - wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y, - wine_dbgstr_rect(&wp.rcNormalPosition) ); - - if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE; - - if (flags & PLACE_MIN) pWnd->min_pos = point_thread_to_win_dpi( hwnd, wp.ptMinPosition ); - if (flags & PLACE_MAX) - { - pWnd->max_pos = point_thread_to_win_dpi( hwnd, wp.ptMaxPosition ); - update_maximized_pos( pWnd, &work_rect ); - } - if (flags & PLACE_RECT) pWnd->normal_rect = rect_thread_to_win_dpi( hwnd, wp.rcNormalPosition ); - - style = pWnd->dwStyle; - - WIN_ReleasePtr( pWnd ); - - if( style & WS_MINIMIZE ) - { - if (flags & PLACE_MIN) - { - NtUserSetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0, - SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); - } - } - else if( style & WS_MAXIMIZE ) - { - if (flags & PLACE_MAX) - NtUserSetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0, - SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); - } - else if( flags & PLACE_RECT ) - NtUserSetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top, - wp.rcNormalPosition.right - wp.rcNormalPosition.left, - wp.rcNormalPosition.bottom - wp.rcNormalPosition.top, - SWP_NOZORDER | SWP_NOACTIVATE ); - - NtUserShowWindow( hwnd, wndpl->showCmd ); - - if (IsIconic( hwnd )) - { - /* SDK: ...valid only the next time... */ - if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) - win_set_flags( hwnd, WIN_RESTORE_MAX, 0 ); - } - return TRUE; -} - /*********************************************************************** * AnimateWindow (USER32.@) @@ -453,33 +272,6 @@ BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags) return TRUE; } -/*********************************************************************** - * SetInternalWindowPos (USER32.@) - */ -void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd, - LPRECT rect, LPPOINT pt ) -{ - WINDOWPLACEMENT wndpl; - UINT flags; - - wndpl.length = sizeof(wndpl); - wndpl.showCmd = showCmd; - wndpl.flags = flags = 0; - - if( pt ) - { - flags |= PLACE_MIN; - wndpl.flags |= WPF_SETMINPOSITION; - wndpl.ptMinPosition = *pt; - } - if( rect ) - { - flags |= PLACE_RECT; - wndpl.rcNormalPosition = *rect; - } - WINPOS_SetPlacement( hwnd, &wndpl, flags ); -} - /******************************************************************* * can_activate_window diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c index b9c71674e75..053ca5aa8f1 100644 --- a/dlls/win32u/gdiobj.c +++ b/dlls/win32u/gdiobj.c @@ -1212,6 +1212,7 @@ static struct unix_funcs unix_funcs = NtUserSetCursorIconData, NtUserSetCursorPos, NtUserSetFocus, + NtUserSetInternalWindowPos, NtUserSetLayeredWindowAttributes, NtUserSetMenu, NtUserSetParent, diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index 1652446a503..7ef2a4b2c7e 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -1201,7 +1201,7 @@ @ stub NtUserSetInputServiceState @ stub NtUserSetInteractiveControlFocus @ stub NtUserSetInteractiveCtrlRotationAngle -@ stub NtUserSetInternalWindowPos +@ stdcall NtUserSetInternalWindowPos(long long ptr ptr) @ stdcall -syscall NtUserSetKeyboardState(ptr) @ stdcall NtUserSetLayeredWindowAttributes(ptr long long long) @ stub NtUserSetMagnificationDesktopMagnifierOffsetsDWMUpdated diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index c9da765e6a1..0e1afb80e62 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -282,6 +282,7 @@ struct unix_funcs UNICODE_STRING *res_name, struct cursoricon_desc *desc ); BOOL (WINAPI *pNtUserSetCursorPos)( INT x, INT y ); HWND (WINAPI *pNtUserSetFocus)( HWND hwnd ); + void (WINAPI *pNtUserSetInternalWindowPos)( HWND hwnd, UINT cmd, RECT *rect, POINT *pt ); BOOL (WINAPI *pNtUserSetLayeredWindowAttributes)( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags ); BOOL (WINAPI *pNtUserSetMenu)( HWND hwnd, HMENU menu ); HWND (WINAPI *pNtUserSetParent)( HWND hwnd, HWND parent ); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index e75f47a2fe6..440052d6e0b 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -3678,6 +3678,32 @@ BOOL WINAPI NtUserEndDeferWindowPosEx( HDWP hdwp, BOOL async ) return TRUE; } +/*********************************************************************** + * NtUserSetInternalWindowPos (win32u.@) + */ +void WINAPI NtUserSetInternalWindowPos( HWND hwnd, UINT cmd, RECT *rect, POINT *pt ) +{ + WINDOWPLACEMENT wndpl; + UINT flags; + + wndpl.length = sizeof(wndpl); + wndpl.showCmd = cmd; + wndpl.flags = flags = 0; + + if (pt) + { + flags |= PLACE_MIN; + wndpl.flags |= WPF_SETMINPOSITION; + wndpl.ptMinPosition = *pt; + } + if( rect ) + { + flags |= PLACE_RECT; + wndpl.rcNormalPosition = *rect; + } + set_window_placement( hwnd, &wndpl, flags ); +} + /*********************************************************************** * win_set_flags * diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c index 64f823ccd26..953de0caafc 100644 --- a/dlls/win32u/wrappers.c +++ b/dlls/win32u/wrappers.c @@ -1185,6 +1185,12 @@ HWND WINAPI NtUserSetFocus( HWND hwnd ) return unix_funcs->pNtUserSetFocus( hwnd ); } +void WINAPI NtUserSetInternalWindowPos( HWND hwnd, UINT cmd, RECT *rect, POINT *pt ) +{ + if (!unix_funcs) return; + return unix_funcs->pNtUserSetInternalWindowPos( hwnd, cmd, rect, pt ); +} + BOOL WINAPI NtUserSetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags ) { if (!unix_funcs) return FALSE; diff --git a/include/ntuser.h b/include/ntuser.h index af87d8a5fec..bc60f421f0e 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -625,6 +625,7 @@ BOOL WINAPI NtUserSetCursorIconData( HCURSOR cursor, UNICODE_STRING *module, struct cursoricon_desc *desc ); BOOL WINAPI NtUserSetCursorPos( INT x, INT y ); HWND WINAPI NtUserSetFocus( HWND hwnd ); +void WINAPI NtUserSetInternalWindowPos( HWND hwnd, UINT cmd, RECT *rect, POINT *pt ); BOOL WINAPI NtUserSetKeyboardState( BYTE *state ); BOOL WINAPI NtUserSetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags ); BOOL WINAPI NtUserSetMenu( HWND hwnd, HMENU menu );