/* $Id: winaccel.cpp,v 1.12 2003-07-31 15:56:47 sandervl Exp $ */ /* * Win32 accelerator key functions for OS/2 * * Based on Wine: (windows\input.c; loader\resource.c) (20000130) * Copyright 1993 Bob Amstadt * Copyright 1996 Albrecht Kleine * Copyright 1997 David Faure * Copyright 1998 Morten Welinder * Copyright 1998 Ulrich Weigand * Copyright 1993 Robert J. Amstadt * Copyright 1995 Alexandre Julliard * * Project Odin Software License can be found in LICENSE.TXT * */ #include #include #include #include #define DBG_LOCALLOG DBG_winaccel #include "dbglocal.h" /********************************************************************** * LoadAccelerators32W [USER.177] * The image layout seems to look like this (not 100% sure): * 00: BYTE type type of accelerator * 01: BYTE pad (to WORD boundary) * 02: WORD event * 04: WORD IDval * 06: WORD pad (to DWORD boundary) */ HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance,LPCWSTR lpTableName) { HRSRC hRsrc; HACCEL hMem,hRetval=0; DWORD size; if (!(hRsrc = FindResourceW( instance, lpTableName, RT_ACCELERATORW ))) { dprintf(("LoadAcceleratorsW couldn't find accelerator table resource %x %x", instance, lpTableName)); return 0; } else { hMem = LoadResource( instance, hRsrc ); size = SizeofResource( instance, hRsrc ); if(size >= sizeof(PE_ACCEL)) { LPPE_ACCEL accel_table = (LPPE_ACCEL) hMem; LPACCEL accel; int i,nrofaccells = size/sizeof(PE_ACCEL); hRetval = GlobalAlloc(0,sizeof(ACCEL)*nrofaccells); accel = (LPACCEL)GlobalLock(hRetval); for (i=0;ientries) entries=xsize; i=0; while(!done) { /* Spit out some debugging information. */ // TRACE_(accel)("accel %d: type 0x%02x, event '%c', IDval 0x%04x.\n", // i, accel[i].fVirt, accel[i].key, accel[i].cmd); /* Copy data to the destination structure array (if dst == NULL, we're just supposed to count the number of entries). */ if(dst) { dst[i].fVirt = accel[i].fVirt; dst[i].key = accel[i].key; dst[i].cmd = accel[i].cmd; /* Check if we've reached the end of the application supplied accelerator table. */ if(i+1 == entries) { /* Turn off the high order bit, just in case. */ dst[i].fVirt &= 0x7f; done = TRUE; } } /* The highest order bit seems to mark the end of the accelerator resource table, but not always. Use GlobalSize() check too. */ if((accel[i].fVirt & 0x80) != 0) done = TRUE; i++; } return i; } /********************************************************************* * CreateAcceleratorTable (USER32.64) * * By mortene@pvv.org 980321 */ HACCEL WINAPI CreateAcceleratorTableA(LPACCEL lpaccel, INT cEntries) { HACCEL hAccel; LPACCEL accel; int i; /* Do parameter checking just in case someone's trying to be funny. */ if(cEntries < 1) { dprintf(("CreateAcceleratorTableA: Application sent invalid parameters (%p %d).\n", lpaccel, cEntries)); SetLastError(ERROR_INVALID_PARAMETER); return NULL; } dprintf(("FIXME: CreateAcceleratorTableA: should check that the accelerator descriptions are valid return NULL and SetLastError() if not")); /* Allocate memory and copy the table. */ hAccel = GlobalAlloc(0,cEntries*sizeof(ACCEL)); if(!hAccel) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return (HACCEL)NULL; } accel = (LPACCEL)GlobalLock(hAccel); for (i=0;i