2000-08-04 06:21:02 +02:00
|
|
|
/*
|
|
|
|
* USER resource functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
2009-10-15 17:35:06 +02:00
|
|
|
* Copyright 1995, 2009 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-12 10:25:09 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2008-03-03 20:06:54 +01:00
|
|
|
#include "winternl.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "winnls.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2009-10-15 17:35:06 +02:00
|
|
|
#include "user_private.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(resource);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(accel);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2000-10-13 01:18:55 +02:00
|
|
|
/* this is the 8 byte accel struct used in Win32 resources (internal only) */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-11-21 16:41:38 +01:00
|
|
|
WORD fVirt;
|
2000-10-13 01:18:55 +02:00
|
|
|
WORD key;
|
|
|
|
WORD cmd;
|
2004-11-21 16:41:38 +01:00
|
|
|
WORD pad;
|
2009-10-15 17:35:06 +02:00
|
|
|
} PE_ACCEL;
|
|
|
|
|
|
|
|
/* the accelerator user object */
|
|
|
|
struct accelerator
|
|
|
|
{
|
|
|
|
struct user_object obj;
|
|
|
|
unsigned int count;
|
|
|
|
PE_ACCEL table[1];
|
|
|
|
};
|
2000-10-13 01:18:55 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadAcceleratorsW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance, LPCWSTR name)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
struct accelerator *accel;
|
|
|
|
const PE_ACCEL *table;
|
|
|
|
HRSRC rsrc;
|
|
|
|
HACCEL handle;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
if (!(rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR ))) return 0;
|
|
|
|
table = LoadResource( instance, rsrc );
|
|
|
|
count = SizeofResource( instance, rsrc ) / sizeof(*table);
|
|
|
|
if (!count) return 0;
|
|
|
|
accel = HeapAlloc( GetProcessHeap(), 0, 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, USER_ACCEL )))
|
|
|
|
HeapFree( GetProcessHeap(), 0, accel );
|
|
|
|
TRACE_(accel)("%p %s returning %p\n", instance, debugstr_w(name), handle );
|
|
|
|
return handle;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadAcceleratorsA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
HACCEL WINAPI LoadAcceleratorsA(HINSTANCE instance,LPCSTR lpTableName)
|
|
|
|
{
|
2002-01-01 01:24:30 +01:00
|
|
|
INT len;
|
|
|
|
LPWSTR uni;
|
|
|
|
HACCEL result = 0;
|
|
|
|
|
2010-02-03 21:04:27 +01:00
|
|
|
if (IS_INTRESOURCE(lpTableName)) return LoadAcceleratorsW( instance, (LPCWSTR)lpTableName );
|
2002-01-01 01:24:30 +01:00
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, NULL, 0 );
|
|
|
|
if ((uni = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, uni, len );
|
|
|
|
result = LoadAcceleratorsW(instance,uni);
|
|
|
|
HeapFree( GetProcessHeap(), 0, uni);
|
|
|
|
}
|
|
|
|
return result;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CopyAcceleratorTableA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
INT WINAPI CopyAcceleratorTableA(HACCEL src, LPACCEL dst, INT count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
char ch;
|
|
|
|
int i, ret = CopyAcceleratorTableW( src, dst, count );
|
|
|
|
|
|
|
|
if (ret && dst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < ret; i++)
|
|
|
|
{
|
|
|
|
if (dst[i].fVirt & FVIRTKEY) continue;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, &dst[i].key, 1, &ch, 1, NULL, NULL );
|
|
|
|
dst[i].key = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CopyAcceleratorTableW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
INT WINAPI CopyAcceleratorTableW(HACCEL src, LPACCEL dst, INT count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
struct accelerator *accel;
|
|
|
|
int i;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2009-10-15 17:35:06 +02:00
|
|
|
if (!(accel = get_user_handle_ptr( src, USER_ACCEL ))) return 0;
|
|
|
|
if (accel == OBJ_OTHER_PROCESS)
|
|
|
|
{
|
|
|
|
FIXME( "other process handle %p?\n", src );
|
|
|
|
return 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2009-10-15 17:35:06 +02:00
|
|
|
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;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CreateAcceleratorTableA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
HACCEL WINAPI CreateAcceleratorTableA(LPACCEL lpaccel, INT count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
struct accelerator *accel;
|
|
|
|
HACCEL handle;
|
|
|
|
int i;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2009-10-15 17:35:06 +02:00
|
|
|
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;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
accel->table[i].fVirt = lpaccel[i].fVirt;
|
|
|
|
accel->table[i].cmd = lpaccel[i].cmd;
|
|
|
|
if (!(lpaccel[i].fVirt & FVIRTKEY))
|
|
|
|
{
|
|
|
|
char ch = lpaccel[i].key;
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, &ch, 1, &accel->table[i].key, 1 );
|
|
|
|
}
|
|
|
|
else accel->table[i].key = lpaccel[i].key;
|
|
|
|
}
|
|
|
|
if (!(handle = alloc_user_handle( &accel->obj, USER_ACCEL )))
|
|
|
|
HeapFree( GetProcessHeap(), 0, accel );
|
|
|
|
TRACE_(accel)("returning %p\n", handle );
|
|
|
|
return handle;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CreateAcceleratorTableW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
HACCEL WINAPI CreateAcceleratorTableW(LPACCEL lpaccel, INT count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
struct accelerator *accel;
|
|
|
|
HACCEL handle;
|
|
|
|
int i;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2009-10-15 17:35:06 +02:00
|
|
|
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;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
accel->table[i].fVirt = lpaccel[i].fVirt;
|
|
|
|
accel->table[i].key = lpaccel[i].key;
|
|
|
|
accel->table[i].cmd = lpaccel[i].cmd;
|
|
|
|
}
|
|
|
|
if (!(handle = alloc_user_handle( &accel->obj, USER_ACCEL )))
|
|
|
|
HeapFree( GetProcessHeap(), 0, accel );
|
|
|
|
TRACE_(accel)("returning %p\n", handle );
|
|
|
|
return handle;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* DestroyAcceleratorTable [USER32.@]
|
2000-08-04 06:21:02 +02:00
|
|
|
* Destroys an accelerator table
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* handle [I] Handle to accelerator table
|
|
|
|
*
|
2005-11-09 11:33:40 +01:00
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DestroyAcceleratorTable( HACCEL handle )
|
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
struct accelerator *accel;
|
|
|
|
|
|
|
|
if (!(accel = free_user_handle( handle, USER_ACCEL ))) return FALSE;
|
|
|
|
if (accel == OBJ_OTHER_PROCESS)
|
|
|
|
{
|
|
|
|
FIXME( "other process handle %p?\n", accel );
|
2004-07-12 22:42:30 +02:00
|
|
|
return FALSE;
|
2009-10-15 17:35:06 +02:00
|
|
|
}
|
|
|
|
return HeapFree( GetProcessHeap(), 0, accel );
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadStringW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2019-02-12 10:25:09 +01:00
|
|
|
INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id,
|
2000-08-04 06:21:02 +02:00
|
|
|
LPWSTR buffer, INT buflen )
|
|
|
|
{
|
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
WCHAR *p;
|
|
|
|
int string_num;
|
|
|
|
int i;
|
|
|
|
|
2005-09-12 16:12:46 +02:00
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2008-03-05 21:28:54 +01:00
|
|
|
if(buffer == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2006-09-21 20:47:20 +02:00
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
2003-09-10 05:56:47 +02:00
|
|
|
(LPWSTR)RT_STRING );
|
2000-08-04 06:21:02 +02:00
|
|
|
if (!hrsrc) return 0;
|
|
|
|
hmem = LoadResource( instance, hrsrc );
|
|
|
|
if (!hmem) return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
p = LockResource(hmem);
|
|
|
|
string_num = resource_id & 0x000f;
|
|
|
|
for (i = 0; i < string_num; i++)
|
|
|
|
p += *p + 1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
TRACE("strlen = %d\n", (int)*p );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-03-05 21:28:54 +01:00
|
|
|
/*if buflen == 0, then return a read-only pointer to the resource itself in buffer
|
|
|
|
it is assumed that buffer is actually a (LPWSTR *) */
|
|
|
|
if(buflen == 0)
|
|
|
|
{
|
|
|
|
*((LPWSTR *)buffer) = p + 1;
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
i = min(buflen - 1, *p);
|
|
|
|
if (i > 0) {
|
|
|
|
memcpy(buffer, p + 1, i * sizeof (WCHAR));
|
2008-11-03 22:35:31 +01:00
|
|
|
buffer[i] = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
} else {
|
|
|
|
if (buflen > 1) {
|
2008-11-03 22:35:31 +01:00
|
|
|
buffer[0] = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s loaded !\n", debugstr_w(buffer));
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadStringA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2019-02-12 10:25:09 +01:00
|
|
|
INT WINAPI DECLSPEC_HOTPATCH LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2008-03-03 20:06:54 +01:00
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
DWORD retval = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2005-09-12 16:12:46 +02:00
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2008-03-03 20:06:54 +01:00
|
|
|
if (!buflen) return -1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-03-03 20:06:54 +01:00
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
|
|
|
(LPWSTR)RT_STRING )) &&
|
|
|
|
(hmem = LoadResource( instance, hrsrc )))
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2008-03-03 20:06:54 +01:00
|
|
|
const WCHAR *p = LockResource(hmem);
|
|
|
|
unsigned int id = resource_id & 0x000f;
|
|
|
|
|
|
|
|
while (id--) p += *p + 1;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2019-12-03 08:53:44 +01:00
|
|
|
RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, p + 1, *p * sizeof(WCHAR) );
|
2008-03-03 20:06:54 +01:00
|
|
|
}
|
|
|
|
buffer[retval] = 0;
|
|
|
|
TRACE("returning %s\n", debugstr_a(buffer));
|
2000-08-04 06:21:02 +02:00
|
|
|
return retval;
|
|
|
|
}
|
2004-04-07 21:41:21 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetGuiResources (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetGuiResources( HANDLE hProcess, DWORD uiFlags )
|
|
|
|
{
|
2008-09-28 20:47:07 +02:00
|
|
|
static BOOL warn = TRUE;
|
|
|
|
|
|
|
|
if (warn) {
|
|
|
|
FIXME("(%p,%x): stub\n",hProcess,uiFlags);
|
|
|
|
warn = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-07 21:41:21 +02:00
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return 0;
|
|
|
|
}
|