Commit d5fd2776 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move NtUserSetFocus implementation from user32.

parent 33277292
......@@ -278,7 +278,7 @@ LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
/* fall through */
case WM_LBUTTONDOWN:
SetCapture( hWnd );
SetFocus( hWnd );
NtUserSetFocus( hWnd );
set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
break;
......
......@@ -1792,7 +1792,7 @@ LRESULT ComboWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
return (LRESULT)lphc->hFont;
case WM_SETFOCUS:
if( lphc->wState & CBF_EDIT ) {
SetFocus( lphc->hWndEdit );
NtUserSetFocus( lphc->hWndEdit );
/* The first time focus is received, select all the text */
if( !(lphc->wState & CBF_BEENFOCUSED) ) {
SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, -1);
......@@ -1901,8 +1901,8 @@ LRESULT ComboWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
SendMessageA(hwndTarget, message, wParam, lParam);
}
case WM_LBUTTONDOWN:
if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
if (!(lphc->wState & CBF_FOCUSED)) NtUserSetFocus( lphc->self );
if (lphc->wState & CBF_FOCUSED) COMBO_LButtonDown( lphc, lParam );
return TRUE;
case WM_LBUTTONUP:
COMBO_LButtonUp( lphc );
......
......@@ -61,7 +61,7 @@ static void DEFDLG_SetFocus( HWND hwndCtrl )
{
if (SendMessageW( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
SendMessageW( hwndCtrl, EM_SETSEL, 0, -1 );
SetFocus( hwndCtrl );
NtUserSetFocus( hwndCtrl );
}
......@@ -102,7 +102,7 @@ static void DEFDLG_RestoreFocus( HWND hwnd, BOOL justActivate )
if (!IsWindow( infoPtr->hwndFocus )) return;
}
if (justActivate)
SetFocus( infoPtr->hwndFocus );
NtUserSetFocus( infoPtr->hwndFocus );
else
DEFDLG_SetFocus( infoPtr->hwndFocus );
infoPtr->hwndFocus = NULL;
......
......@@ -417,7 +417,7 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa
/* The default action in Windows is to set the keyboard focus to
* the window, if it's being activated and not minimized */
if (LOWORD(wParam) != WA_INACTIVE) {
if (!IsIconic(hwnd)) SetFocus(hwnd);
if (!IsIconic(hwnd)) NtUserSetFocus( hwnd );
}
break;
......
......@@ -687,12 +687,12 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
{
if (SendMessageW( focus, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
SendMessageW( focus, EM_SETSEL, 0, MAXLONG );
SetFocus( focus );
NtUserSetFocus( focus );
}
else
{
if (!(template.style & WS_CHILD))
SetFocus( hwnd );
NtUserSetFocus( hwnd );
}
}
}
......@@ -926,7 +926,7 @@ BOOL WINAPI EndDialog( HWND hwnd, INT_PTR retval )
/* Windows sets the focus to the dialog itself in EndDialog */
if (IsChild(hwnd, GetFocus()))
SetFocus( hwnd );
NtUserSetFocus( hwnd );
/* Don't have to send a ShowWindow(SW_HIDE), just do
SetWindowPos with SWP_HIDEWINDOW as done in Windows */
......@@ -1226,7 +1226,7 @@ BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
SendMessageW (hwndNext, EM_SETSEL, 0, length);
}
}
SetFocus (hwndNext);
NtUserSetFocus( hwndNext );
DIALOG_FixChildrenOnChangeFocus (hwndDlg, hwndNext);
}
else
......@@ -1246,7 +1246,7 @@ BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
HWND hwndNext = GetNextDlgGroupItem( hwndDlg, msg->hwnd, fPrevious );
if (hwndNext && SendMessageW( hwndNext, WM_GETDLGCODE, msg->wParam, (LPARAM)msg ) == (DLGC_BUTTON | DLGC_RADIOBUTTON))
{
SetFocus( hwndNext );
NtUserSetFocus( hwndNext );
if ((GetWindowLongW( hwndNext, GWL_STYLE ) & BS_TYPEMASK) == BS_AUTORADIOBUTTON &&
SendMessageW( hwndNext, BM_GETCHECK, 0, 0 ) != BST_CHECKED)
SendMessageW( hwndNext, BM_CLICK, 1, 0 );
......
......@@ -3329,7 +3329,7 @@ static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
}
if (!(es->flags & EF_FOCUSED))
SetFocus(es->hwndSelf);
NtUserSetFocus(es->hwndSelf);
cmd = TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
x, y, 0, es->hwndSelf, NULL);
......@@ -3619,7 +3619,7 @@ static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
SetTimer(es->hwndSelf, 0, 100, NULL);
if (!(es->flags & EF_FOCUSED))
SetFocus(es->hwndSelf);
NtUserSetFocus(es->hwndSelf);
return 0;
}
......
......@@ -235,66 +235,6 @@ BOOL FOCUS_MouseActivate( HWND hwnd )
}
/*****************************************************************
* SetFocus (USER32.@)
*/
HWND WINAPI SetFocus( HWND hwnd )
{
HWND hwndTop = hwnd;
HWND previous = GetFocus();
TRACE( "%p prev %p\n", hwnd, previous );
if (hwnd)
{
/* Check if we can set the focus to this window */
hwnd = WIN_GetFullHandle( hwnd );
if (!IsWindow( hwnd ))
{
SetLastError( ERROR_INVALID_WINDOW_HANDLE );
return 0;
}
if (hwnd == previous) return previous; /* nothing to do */
for (;;)
{
HWND parent;
LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
if (!(style & WS_CHILD)) break;
parent = NtUserGetAncestor( hwndTop, GA_PARENT );
if (!parent || parent == GetDesktopWindow())
{
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return 0;
break;
}
if (parent == get_hwnd_message_parent()) return 0;
hwndTop = parent;
}
/* call hooks */
if (HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)hwnd, (LPARAM)previous, TRUE )) return 0;
/* activate hwndTop if needed. */
if (hwndTop != GetActiveWindow())
{
if (!set_active_window( hwndTop, NULL, FALSE, FALSE )) return 0;
if (!IsWindow( hwnd )) return 0; /* Abort if window destroyed */
/* Do not change focus if the window is no longer active */
if (hwndTop != GetActiveWindow()) return 0;
}
}
else /* NULL hwnd passed in */
{
if (!previous) return 0; /* nothing to do */
if (HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)previous, TRUE )) return 0;
}
/* change focus and send messages */
return set_focus_window( hwnd );
}
/*******************************************************************
* SetForegroundWindow (USER32.@)
*/
......
......@@ -2131,8 +2131,8 @@ static LRESULT LISTBOX_HandleLButtonDown( LB_DESCR *descr, DWORD keys, INT x, IN
if (!descr->in_focus)
{
if( !descr->lphc ) SetFocus( descr->self );
else SetFocus( (descr->lphc->hWndEdit) ? descr->lphc->hWndEdit : descr->lphc->self );
if( !descr->lphc ) NtUserSetFocus( descr->self );
else NtUserSetFocus( (descr->lphc->hWndEdit) ? descr->lphc->hWndEdit : descr->lphc->self );
}
if (index == -1) return 0;
......
......@@ -629,7 +629,7 @@ static LONG MDI_ChildActivate( HWND client, HWND child )
* SetFocus won't work. It appears that Windows sends WM_SETFOCUS
* manually in this case.
*/
if (SetFocus(client) == client)
if (NtUserSetFocus(client) == client)
SendMessageW( client, WM_SETFOCUS, (WPARAM)client, 0 );
}
......@@ -1172,7 +1172,7 @@ LRESULT MDIClientWndProc_common( HWND hwnd, UINT message, WPARAM wParam, LPARAM
case WM_SETFOCUS:
if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
SetFocus( ci->hwndActiveChild );
NtUserSetFocus( ci->hwndActiveChild );
return 0;
case WM_NCACTIVATE:
......@@ -1344,7 +1344,7 @@ LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
return 1; /* success. FIXME: check text length */
case WM_SETFOCUS:
SetFocus(hwndMDIClient);
NtUserSetFocus( hwndMDIClient );
break;
case WM_SIZE:
......
......@@ -300,7 +300,7 @@ static void MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb)
hItem = GetDlgItem(hwnd, buttonOrder[i]);
if (GetWindowLongW(hItem, GWL_STYLE) & WS_VISIBLE) {
if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
SetFocus(hItem);
NtUserSetFocus(hItem);
SendMessageW( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
}
SetWindowPos(hItem, 0, bpos, tiheight, bw, bh,
......
......@@ -852,7 +852,7 @@ void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt )
lastMousePos = lastClickPos;
trackThumbPos = thumbPos;
prevPt = pt;
if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) SetFocus( hwnd );
if (nBar == SB_CTL && (GetWindowLongW(hwnd, GWL_STYLE) & WS_TABSTOP)) NtUserSetFocus( hwnd );
SetCapture( hwnd );
break;
......
......@@ -669,7 +669,7 @@
@ stdcall SetDlgItemTextA(long long str)
@ stdcall SetDlgItemTextW(long long wstr)
@ stdcall SetDoubleClickTime(long)
@ stdcall SetFocus(long)
@ stdcall SetFocus(long) NtUserSetFocus
@ stdcall SetForegroundWindow(long)
@ stdcall SetGestureConfig(ptr long long ptr long)
@ stdcall SetInternalWindowPos(long long ptr ptr)
......
......@@ -2054,7 +2054,7 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
if (!retvalue)
{
if (hwnd == GetFocus())
SetFocus( 0 ); /* A disabled window can't have the focus */
NtUserSetFocus( 0 ); /* A disabled window can't have the focus */
SendMessageW( hwnd, WM_ENABLE, FALSE, 0 );
}
......
......@@ -864,9 +864,9 @@ UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
if (GetFocus() == hwnd)
{
if (GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD)
SetFocus(NtUserGetAncestor(hwnd, GA_PARENT));
NtUserSetFocus( NtUserGetAncestor( hwnd, GA_PARENT ));
else
SetFocus(0);
NtUserSetFocus( 0 );
}
old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
......@@ -1058,7 +1058,7 @@ static BOOL show_window( HWND hwnd, INT cmd )
{
HWND parent = NtUserGetAncestor(hwnd, GA_PARENT);
if (parent == GetDesktopWindow()) parent = 0;
SetFocus(parent);
NtUserSetFocus( parent );
}
goto done;
}
......@@ -1091,7 +1091,7 @@ static BOOL show_window( HWND hwnd, INT cmd )
/* if previous state was minimized Windows sets focus to the window */
if (style & WS_MINIMIZE)
{
SetFocus( hwnd );
NtUserSetFocus( hwnd );
/* Send a WM_ACTIVATE message for a top level window, even if the window is already active */
if (NtUserGetAncestor( hwnd, GA_ROOT ) == hwnd && !(swp & SWP_NOACTIVATE))
SendMessageW( hwnd, WM_ACTIVATE, WA_ACTIVE, 0 );
......
......@@ -1189,6 +1189,7 @@ static struct unix_funcs unix_funcs =
NtUserSetCursor,
NtUserSetCursorIconData,
NtUserSetCursorPos,
NtUserSetFocus,
NtUserSetLayeredWindowAttributes,
NtUserSetSysColors,
NtUserSetWindowPos,
......
......@@ -1270,3 +1270,62 @@ HWND WINAPI NtUserSetActiveWindow( HWND hwnd )
if (!set_active_window( hwnd, &prev, FALSE, TRUE )) return 0;
return prev;
}
/*****************************************************************
* NtUserSetFocus (win32u.@)
*/
HWND WINAPI NtUserSetFocus( HWND hwnd )
{
HWND hwndTop = hwnd;
HWND previous = get_focus();
TRACE( "%p prev %p\n", hwnd, previous );
if (hwnd)
{
/* Check if we can set the focus to this window */
hwnd = get_full_window_handle( hwnd );
if (!is_window( hwnd ))
{
SetLastError( ERROR_INVALID_WINDOW_HANDLE );
return 0;
}
if (hwnd == previous) return previous; /* nothing to do */
for (;;)
{
HWND parent;
LONG style = get_window_long( hwndTop, GWL_STYLE );
if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
if (!(style & WS_CHILD)) break;
parent = NtUserGetAncestor( hwndTop, GA_PARENT );
if (!parent || parent == get_desktop_window())
{
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return 0;
break;
}
if (parent == get_hwnd_message_parent()) return 0;
hwndTop = parent;
}
/* call hooks */
if (call_hooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)hwnd, (LPARAM)previous, TRUE )) return 0;
/* activate hwndTop if needed. */
if (hwndTop != get_active_window())
{
if (!set_active_window( hwndTop, NULL, FALSE, FALSE )) return 0;
if (!is_window( hwnd )) return 0; /* Abort if window destroyed */
/* Do not change focus if the window is no longer active */
if (hwndTop != get_active_window()) return 0;
}
}
else /* NULL hwnd passed in */
{
if (!previous) return 0; /* nothing to do */
if (call_hooks( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)previous, TRUE )) return 0;
}
/* change focus and send messages */
return set_focus_window( hwnd );
}
......@@ -1190,7 +1190,7 @@
@ stub NtUserSetDisplayMapping
@ stub NtUserSetFallbackForeground
@ stub NtUserSetFeatureReportResponse
@ stub NtUserSetFocus
@ stdcall NtUserSetFocus(long)
@ stub NtUserSetForegroundWindowForApplication
@ stub NtUserSetFullscreenMagnifierOffsetsDWMUpdated
@ stub NtUserSetGestureConfig
......
......@@ -235,6 +235,7 @@ struct unix_funcs
BOOL (WINAPI *pNtUserSetCursorIconData)( HCURSOR cursor, UNICODE_STRING *module,
UNICODE_STRING *res_name, struct cursoricon_desc *desc );
BOOL (WINAPI *pNtUserSetCursorPos)( INT x, INT y );
HWND (WINAPI *pNtUserSetFocus)( HWND hwnd );
BOOL (WINAPI *pNtUserSetLayeredWindowAttributes)( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags );
BOOL (WINAPI *pNtUserSetSysColors)( INT count, const INT *colors, const COLORREF *values );
BOOL (WINAPI *pNtUserSetWindowPos)( HWND hwnd, HWND after, INT x, INT y, INT cx, INT cy, UINT flags );
......@@ -317,6 +318,7 @@ extern void user_check_not_lock(void) DECLSPEC_HIDDEN;
struct tagWND;
extern HWND get_desktop_window(void) DECLSPEC_HIDDEN;
extern HWND get_full_window_handle( HWND hwnd ) DECLSPEC_HIDDEN;
extern HWND get_hwnd_message_parent(void) DECLSPEC_HIDDEN;
extern BOOL get_window_placement( HWND hwnd, WINDOWPLACEMENT *placement ) DECLSPEC_HIDDEN;
extern DWORD get_window_thread( HWND hwnd, DWORD *process ) DECLSPEC_HIDDEN;
extern HWND is_current_thread_window( HWND hwnd ) DECLSPEC_HIDDEN;
......
......@@ -159,7 +159,7 @@ WND *next_thread_window_ptr( HWND *hwnd )
*
* Return the parent for HWND_MESSAGE windows.
*/
static HWND get_hwnd_message_parent(void)
HWND get_hwnd_message_parent(void)
{
struct user_thread_info *thread_info = get_user_thread_info();
......
......@@ -946,6 +946,12 @@ BOOL WINAPI NtUserSetCursorPos( INT x, INT y )
return unix_funcs->pNtUserSetCursorPos( x, y );
}
HWND WINAPI NtUserSetFocus( HWND hwnd )
{
if (!unix_funcs) return FALSE;
return unix_funcs->pNtUserSetFocus( hwnd );
}
BOOL WINAPI NtUserSetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
{
if (!unix_funcs) return FALSE;
......
......@@ -367,6 +367,7 @@ HCURSOR WINAPI NtUserSetCursor( HCURSOR cursor );
BOOL WINAPI NtUserSetCursorIconData( HCURSOR cursor, UNICODE_STRING *module, UNICODE_STRING *res_name,
struct cursoricon_desc *desc );
BOOL WINAPI NtUserSetCursorPos( INT x, INT y );
HWND WINAPI NtUserSetFocus( HWND hwnd );
BOOL WINAPI NtUserSetKeyboardState( BYTE *state );
BOOL WINAPI NtUserSetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags );
BOOL WINAPI NtUserSetProcessDpiAwarenessContext( ULONG awareness, ULONG unknown );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment