Determine number of accelerator table entries in resource from size of

the resource

svn path=/trunk/; revision=7901
This commit is contained in:
Gé van Geldorp 2004-01-28 21:00:23 +00:00
parent cdcb7ec378
commit bccf34a7a1
2 changed files with 18 additions and 27 deletions

View file

@ -1,18 +1,9 @@
/* $Id: accel.h,v 1.1 2003/07/20 03:45:31 hyperion Exp $ /* $Id: accel.h,v 1.2 2004/01/28 21:00:23 gvg Exp $
*/ */
#ifndef __USER32_ACCEL_H_INCLUDED__ #ifndef __USER32_ACCEL_H_INCLUDED__
#define __USER32_ACCEL_H_INCLUDED__ #define __USER32_ACCEL_H_INCLUDED__
/* RT_ACCELERATOR resources are arrays of RES_ACCEL structures */
typedef struct _RES_ACCEL
{
WORD fVirt;
WORD key;
DWORD cmd;
}
RES_ACCEL;
/* ACCELERATOR TABLES CACHE */ /* ACCELERATOR TABLES CACHE */
/* Cache entry */ /* Cache entry */
typedef struct _USER_ACCEL_CACHE_ENTRY typedef struct _USER_ACCEL_CACHE_ENTRY

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: accel.c,v 1.12 2003/12/07 16:54:44 chorns Exp $ /* $Id: accel.c,v 1.13 2004/01/28 21:00:23 gvg Exp $
* *
* PROJECT: ReactOS user32.dll * PROJECT: ReactOS user32.dll
* FILE: lib/user32/windows/input.c * FILE: lib/user32/windows/input.c
@ -32,6 +32,16 @@
#include <user32/accel.h> #include <user32/accel.h>
#include <win32k/ntuser.h> #include <win32k/ntuser.h>
/* this is the 8 byte accel struct used in Win32 resources (internal only) */
typedef struct
{
BYTE fVirt;
BYTE pad0;
WORD key;
WORD cmd;
WORD pad1;
} PE_ACCEL, *LPPE_ACCEL;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* Lock guarding the cache */ /* Lock guarding the cache */
@ -80,8 +90,7 @@ HACCEL WINAPI U32LoadAccelerators(HINSTANCE hInstance, HRSRC hTableRes)
HGLOBAL hAccTableData; HGLOBAL hAccTableData;
HACCEL hAccTable = NULL; HACCEL hAccTable = NULL;
U32_ACCEL_CACHE_ENTRY * pEntry; U32_ACCEL_CACHE_ENTRY * pEntry;
RES_ACCEL * pAccTableResData; PE_ACCEL * pAccTableResData;
RES_ACCEL * p;
SIZE_T i = 0; SIZE_T i = 0;
SIZE_T j = 0; SIZE_T j = 0;
ACCEL * pAccTableData; ACCEL * pAccTableData;
@ -110,20 +119,8 @@ HACCEL WINAPI U32LoadAccelerators(HINSTANCE hInstance, HRSRC hTableRes)
goto l_Leave; goto l_Leave;
} }
/* count the number of entries in the table */ /* determine the number of entries in the table */
p = pAccTableResData = (RES_ACCEL *)hAccTableData; i = SizeofResource(hInstance, hTableRes) / sizeof(PE_ACCEL);
while(1)
{
/* FIXME??? unknown flag 0x60 stops the scan */
if(p->fVirt & 0x60) break;
++ i;
++ p;
/* flag 0x80 marks the last entry of the table */
if(p->fVirt & 0x80) break;
}
/* allocate the buffer for the table to be passed to Win32K */ /* allocate the buffer for the table to be passed to Win32K */
pAccTableData = LocalAlloc(LMEM_FIXED, i * sizeof(ACCEL)); pAccTableData = LocalAlloc(LMEM_FIXED, i * sizeof(ACCEL));
@ -131,6 +128,8 @@ HACCEL WINAPI U32LoadAccelerators(HINSTANCE hInstance, HRSRC hTableRes)
/* failure */ /* failure */
if(pAccTableData == NULL) goto l_Leave; if(pAccTableData == NULL) goto l_Leave;
pAccTableResData = (PE_ACCEL *)hAccTableData;
/* copy the table */ /* copy the table */
for(j = 0; j < i; ++ j) for(j = 0; j < i; ++ j)
{ {
@ -138,6 +137,7 @@ HACCEL WINAPI U32LoadAccelerators(HINSTANCE hInstance, HRSRC hTableRes)
pAccTableData[j].key = pAccTableResData[j].key; pAccTableData[j].key = pAccTableResData[j].key;
pAccTableData[j].cmd = pAccTableResData[j].cmd; pAccTableData[j].cmd = pAccTableResData[j].cmd;
} }
pAccTableData[i - 1].fVirt |= 0x80;
/* create a new accelerator table object */ /* create a new accelerator table object */
hAccTable = NtUserCreateAcceleratorTable(pAccTableData, i); hAccTable = NtUserCreateAcceleratorTable(pAccTableData, i);