From 9759ed143a12e61349de156b54d9f7a9b9155714 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 2 Mar 2022 15:06:33 +0100 Subject: [PATCH] win32u: Move accelerators object implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/menu.c | 4 +- dlls/user32/resource.c | 95 ++----------------------------- dlls/user32/user32.spec | 6 +- dlls/win32u/Makefile.in | 1 + dlls/win32u/menu.c | 107 +++++++++++++++++++++++++++++++++++ dlls/win32u/ntgdi_private.h | 1 - dlls/win32u/syscall.c | 3 + dlls/win32u/win32u.spec | 6 +- dlls/win32u/win32u_private.h | 1 + dlls/wow64win/syscall.h | 3 + dlls/wow64win/user.c | 24 ++++++++ include/ntuser.h | 3 + 12 files changed, 154 insertions(+), 100 deletions(-) create mode 100644 dlls/win32u/menu.c diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 3dc0bf36f90..eca1d7af9a6 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -5705,12 +5705,12 @@ INT WINAPI TranslateAcceleratorW( HWND hWnd, HACCEL hAccel, LPMSG msg ) TRACE_(accel)("hAccel %p, hWnd %p, msg->hwnd %p, msg->message %04x, wParam %08lx, lParam %08lx\n", hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam); - if (!(count = CopyAcceleratorTableW( hAccel, NULL, 0 ))) return 0; + if (!(count = NtUserCopyAcceleratorTable( hAccel, NULL, 0 ))) return 0; if (count > ARRAY_SIZE( data )) { if (!(ptr = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*ptr) ))) return 0; } - count = CopyAcceleratorTableW( hAccel, ptr, count ); + count = NtUserCopyAcceleratorTable( hAccel, ptr, count ); for (i = 0; i < count; i++) { if (translate_accelerator( hWnd, msg->message, msg->wParam, msg->lParam, diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c index 7c15e1905a5..1031ee2da65 100644 --- a/dlls/user32/resource.c +++ b/dlls/user32/resource.c @@ -23,11 +23,9 @@ #include "windef.h" #include "winbase.h" -#include "winerror.h" -#include "winternl.h" #include "winnls.h" +#include "ntuser.h" #include "wine/debug.h" -#include "user_private.h" WINE_DEFAULT_DEBUG_CHANNEL(resource); WINE_DECLARE_DEBUG_CHANNEL(accel); @@ -41,14 +39,6 @@ typedef struct WORD pad; } PE_ACCEL; -/* the accelerator user object */ -struct accelerator -{ - struct user_object obj; - unsigned int count; - ACCEL table[1]; -}; - /********************************************************************** * LoadAcceleratorsW (USER32.@) */ @@ -73,7 +63,7 @@ HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance, LPCWSTR name) table[i].key = pe_table[i].key; table[i].cmd = pe_table[i].cmd; } - handle = CreateAcceleratorTableW( table, count ); + handle = NtUserCreateAcceleratorTable( table, count ); HeapFree( GetProcessHeap(), 0, table ); TRACE_(accel)("%p %s returning %p\n", instance, debugstr_w(name), handle ); return handle; @@ -106,7 +96,7 @@ HACCEL WINAPI LoadAcceleratorsA(HINSTANCE instance,LPCSTR lpTableName) INT WINAPI CopyAcceleratorTableA(HACCEL src, LPACCEL dst, INT count) { char ch; - int i, ret = CopyAcceleratorTableW( src, dst, count ); + int i, ret = NtUserCopyAcceleratorTable( src, dst, count ); if (ret && dst) { @@ -120,35 +110,6 @@ INT WINAPI CopyAcceleratorTableA(HACCEL src, LPACCEL dst, INT count) return ret; } -/********************************************************************** - * CopyAcceleratorTableW (USER32.@) - */ -INT WINAPI CopyAcceleratorTableW(HACCEL src, LPACCEL dst, INT count) -{ - struct accelerator *accel; - int i; - - if (!(accel = get_user_handle_ptr( src, NTUSER_OBJ_ACCEL ))) return 0; - if (accel == OBJ_OTHER_PROCESS) - { - FIXME( "other process handle %p?\n", src ); - return 0; - } - if (dst) - { - if (count > accel->count) count = accel->count; - for (i = 0; i < count; i++) - { - dst[i].fVirt = accel->table[i].fVirt & 0x7f; - dst[i].key = accel->table[i].key; - dst[i].cmd = accel->table[i].cmd; - } - } - else count = accel->count; - release_user_handle_ptr( accel ); - return count; -} - /********************************************************************* * CreateAcceleratorTableA (USER32.@) */ @@ -176,60 +137,12 @@ HACCEL WINAPI CreateAcceleratorTableA( ACCEL *accel, INT count ) } else table[i].key = accel[i].key; } - handle = CreateAcceleratorTableW( table, count ); + handle = NtUserCreateAcceleratorTable( table, count ); HeapFree( GetProcessHeap(), 0, table ); TRACE_(accel)("returning %p\n", handle ); return handle; } -/********************************************************************* - * CreateAcceleratorTableW (USER32.@) - */ -HACCEL WINAPI CreateAcceleratorTableW(LPACCEL lpaccel, INT count) -{ - struct accelerator *accel; - HACCEL handle; - - if (count < 1) - { - SetLastError( ERROR_INVALID_PARAMETER ); - return 0; - } - accel = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( struct accelerator, table[count] )); - if (!accel) return 0; - accel->count = count; - memcpy( accel->table, lpaccel, count * sizeof(*lpaccel) ); - - if (!(handle = alloc_user_handle( &accel->obj, NTUSER_OBJ_ACCEL ))) - HeapFree( GetProcessHeap(), 0, accel ); - TRACE_(accel)("returning %p\n", handle ); - return handle; -} - -/****************************************************************************** - * DestroyAcceleratorTable [USER32.@] - * Destroys an accelerator table - * - * PARAMS - * handle [I] Handle to accelerator table - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ -BOOL WINAPI DestroyAcceleratorTable( HACCEL handle ) -{ - struct accelerator *accel; - - if (!(accel = free_user_handle( handle, NTUSER_OBJ_ACCEL ))) return FALSE; - if (accel == OBJ_OTHER_PROCESS) - { - FIXME( "other process handle %p?\n", accel ); - return FALSE; - } - return HeapFree( GetProcessHeap(), 0, accel ); -} - /********************************************************************** * LoadStringW (USER32.@) */ diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index fc2a7b1d50f..c1d4318dc04 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -79,13 +79,13 @@ @ stdcall CloseWindow(long) @ stdcall CloseWindowStation(long) NtUserCloseWindowStation @ stdcall CopyAcceleratorTableA(long ptr long) -@ stdcall CopyAcceleratorTableW(long ptr long) +@ stdcall CopyAcceleratorTableW(long ptr long) NtUserCopyAcceleratorTable @ stdcall CopyIcon(long) @ stdcall CopyImage(long long long long long) @ stdcall CopyRect(ptr ptr) @ stdcall CountClipboardFormats() NtUserCountClipboardFormats @ stdcall CreateAcceleratorTableA(ptr long) -@ stdcall CreateAcceleratorTableW(ptr long) +@ stdcall CreateAcceleratorTableW(ptr long) NtUserCreateAcceleratorTable @ stdcall CreateCaret(long long long long) @ stdcall CreateCursor(long long long long long ptr ptr) @ stdcall CreateDesktopA(str str ptr long long ptr) @@ -155,7 +155,7 @@ @ stdcall DeferWindowPos(long long long long long long long long) @ stdcall DeleteMenu(long long long) @ stdcall DeregisterShellHookWindow (long) -@ stdcall DestroyAcceleratorTable(long) +@ stdcall DestroyAcceleratorTable(long) NtUserDestroyAcceleratorTable @ stdcall DestroyCaret() @ stdcall DestroyCursor(long) @ stdcall DestroyIcon(long) diff --git a/dlls/win32u/Makefile.in b/dlls/win32u/Makefile.in index 208ffa18763..0435c2f86ab 100644 --- a/dlls/win32u/Makefile.in +++ b/dlls/win32u/Makefile.in @@ -32,6 +32,7 @@ C_SRCS = \ input.c \ main.c \ mapping.c \ + menu.c \ message.c \ opentype.c \ painting.c \ diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c new file mode 100644 index 00000000000..abaca12047f --- /dev/null +++ b/dlls/win32u/menu.c @@ -0,0 +1,107 @@ +/* + * Menu functions + * + * Copyright 1993 Robert J. Amstadt + * Copyright 1995, 2009 Alexandre Julliard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include "win32u_private.h" +#include "ntuser_private.h" +#include "wine/debug.h" + +WINE_DECLARE_DEBUG_CHANNEL(accel); + +/* the accelerator user object */ +struct accelerator +{ + struct user_object obj; + unsigned int count; + ACCEL table[1]; +}; + +/********************************************************************** + * NtUserCopyAcceleratorTable (win32u.@) + */ +INT WINAPI NtUserCopyAcceleratorTable( HACCEL src, ACCEL *dst, INT count ) +{ + struct accelerator *accel; + int i; + + if (!(accel = get_user_handle_ptr( src, NTUSER_OBJ_ACCEL ))) return 0; + if (accel == OBJ_OTHER_PROCESS) + { + FIXME_(accel)( "other process handle %p?\n", src ); + return 0; + } + if (dst) + { + if (count > accel->count) count = accel->count; + for (i = 0; i < count; i++) + { + dst[i].fVirt = accel->table[i].fVirt & 0x7f; + dst[i].key = accel->table[i].key; + dst[i].cmd = accel->table[i].cmd; + } + } + else count = accel->count; + release_user_handle_ptr( accel ); + return count; +} + +/********************************************************************* + * NtUserCreateAcceleratorTable (win32u.@) + */ +HACCEL WINAPI NtUserCreateAcceleratorTable( ACCEL *table, INT count ) +{ + struct accelerator *accel; + HACCEL handle; + + if (count < 1) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + accel = malloc( FIELD_OFFSET( struct accelerator, table[count] )); + if (!accel) return 0; + accel->count = count; + memcpy( accel->table, table, count * sizeof(*table) ); + + if (!(handle = alloc_user_handle( &accel->obj, NTUSER_OBJ_ACCEL ))) free( accel ); + TRACE_(accel)("returning %p\n", handle ); + return handle; +} + +/****************************************************************************** + * NtUserDestroyAcceleratorTable (win32u.@) + */ +BOOL WINAPI NtUserDestroyAcceleratorTable( HACCEL handle ) +{ + struct accelerator *accel; + + if (!(accel = free_user_handle( handle, NTUSER_OBJ_ACCEL ))) return FALSE; + if (accel == OBJ_OTHER_PROCESS) + { + FIXME_(accel)( "other process handle %p\n", accel ); + return FALSE; + } + free( accel ); + return TRUE; +} diff --git a/dlls/win32u/ntgdi_private.h b/dlls/win32u/ntgdi_private.h index 2ed6182e151..985ed4fa30f 100644 --- a/dlls/win32u/ntgdi_private.h +++ b/dlls/win32u/ntgdi_private.h @@ -23,7 +23,6 @@ #include #include -#include #include "win32u_private.h" /* extra stock object: default 1x1 bitmap for memory DCs */ diff --git a/dlls/win32u/syscall.c b/dlls/win32u/syscall.c index 8ce4359b760..43fdb8bc8c1 100644 --- a/dlls/win32u/syscall.c +++ b/dlls/win32u/syscall.c @@ -106,8 +106,11 @@ static void * const syscalls[] = NtUserBuildHwndList, NtUserCloseDesktop, NtUserCloseWindowStation, + NtUserCopyAcceleratorTable, + NtUserCreateAcceleratorTable, NtUserCreateDesktopEx, NtUserCreateWindowStation, + NtUserDestroyAcceleratorTable, NtUserFindExistingCursorIcon, NtUserGetClipboardFormatName, NtUserGetClipboardOwner, diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index 0b63c43c6f6..0fc0d906507 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -802,9 +802,9 @@ @ stub NtUserConfirmResizeCommit @ stub NtUserConsoleControl @ stub NtUserConvertMemHandle -@ stub NtUserCopyAcceleratorTable +@ stdcall -syscall NtUserCopyAcceleratorTable(long ptr long) @ stdcall NtUserCountClipboardFormats() -@ stub NtUserCreateAcceleratorTable +@ stdcall -syscall NtUserCreateAcceleratorTable(ptr long) @ stub NtUserCreateActivationGroup @ stub NtUserCreateActivationObject @ stub NtUserCreateCaret @@ -826,7 +826,7 @@ @ stub NtUserDelegateInput @ stub NtUserDeleteMenu @ stub NtUserDeleteWindowGroup -@ stub NtUserDestroyAcceleratorTable +@ stdcall -syscall NtUserDestroyAcceleratorTable(long) @ stub NtUserDestroyActivationGroup @ stub NtUserDestroyActivationObject @ stdcall NtUserDestroyCursor(long long) diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index e6a5105dcf5..b5fc8df022f 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -22,6 +22,7 @@ #define __WINE_WIN32U_PRIVATE #include +#include #include "windef.h" #include "winbase.h" #include "ntgdi.h" diff --git a/dlls/wow64win/syscall.h b/dlls/wow64win/syscall.h index b15904df35d..1bea8daf125 100644 --- a/dlls/wow64win/syscall.h +++ b/dlls/wow64win/syscall.h @@ -93,8 +93,11 @@ SYSCALL_ENTRY( NtUserBuildHwndList ) \ SYSCALL_ENTRY( NtUserCloseDesktop ) \ SYSCALL_ENTRY( NtUserCloseWindowStation ) \ + SYSCALL_ENTRY( NtUserCopyAcceleratorTable ) \ + SYSCALL_ENTRY( NtUserCreateAcceleratorTable ) \ SYSCALL_ENTRY( NtUserCreateDesktopEx ) \ SYSCALL_ENTRY( NtUserCreateWindowStation ) \ + SYSCALL_ENTRY( NtUserDestroyAcceleratorTable ) \ SYSCALL_ENTRY( NtUserFindExistingCursorIcon ) \ SYSCALL_ENTRY( NtUserGetClipboardFormatName ) \ SYSCALL_ENTRY( NtUserGetClipboardOwner ) \ diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 4af39b61418..9e08fe7eda6 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -491,3 +491,27 @@ NTSTATUS WINAPI wow64_NtUserGetGUIThreadInfo( UINT *args ) info32->rcCaret = info.rcCaret; return TRUE; } + +NTSTATUS WINAPI wow64_NtUserCopyAcceleratorTable( UINT *args ) +{ + HACCEL src = get_handle( &args ); + ACCEL *dst = get_ptr( &args ); + INT count = get_ulong( &args ); + + return NtUserCopyAcceleratorTable( src, dst, count ); +} + +NTSTATUS WINAPI wow64_NtUserCreateAcceleratorTable( UINT *args ) +{ + ACCEL *table = get_ptr( &args ); + INT count = get_ulong( &args ); + + return HandleToUlong( NtUserCreateAcceleratorTable( table, count )); +} + +NTSTATUS WINAPI wow64_NtUserDestroyAcceleratorTable( UINT *args ) +{ + HACCEL handle = get_handle( &args ); + + return NtUserDestroyAcceleratorTable( handle ); +} diff --git a/include/ntuser.h b/include/ntuser.h index a899c03e66e..3fe8e84279e 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -215,12 +215,15 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *d BOOL WINAPI NtUserClipCursor( const RECT *rect ); BOOL WINAPI NtUserCloseDesktop( HDESK handle ); BOOL WINAPI NtUserCloseWindowStation( HWINSTA handle ); +INT WINAPI NtUserCopyAcceleratorTable( HACCEL src, ACCEL *dst, INT count ); INT WINAPI NtUserCountClipboardFormats(void); +HACCEL WINAPI NtUserCreateAcceleratorTable( ACCEL *table, INT count ); HDESK WINAPI NtUserCreateDesktopEx( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *device, DEVMODEW *devmode, DWORD flags, ACCESS_MASK access, ULONG heap_size ); HWINSTA WINAPI NtUserCreateWindowStation( OBJECT_ATTRIBUTES *attr, ACCESS_MASK mask, ULONG arg3, ULONG arg4, ULONG arg5, ULONG arg6, ULONG arg7 ); +BOOL WINAPI NtUserDestroyAcceleratorTable( HACCEL handle ); BOOL WINAPI NtUserDestroyCursor( HCURSOR cursor, ULONG arg ); BOOL WINAPI NtUserDrawIconEx( HDC hdc, INT x0, INT y0, HICON icon, INT width, INT height, UINT istep, HBRUSH hbr, UINT flags );