ReactOS 0.4.15-dev-7704-gc07eb9f
accel.c File Reference
#include <user32.h>
Include dependency graph for accel.c:

Go to the source code of this file.

Classes

struct  PE_ACCEL
 
struct  _USER_ACCEL_CACHE_ENTRY
 

Typedefs

typedef struct PE_ACCELLPPE_ACCEL
 
typedef struct _USER_ACCEL_CACHE_ENTRY U32_ACCEL_CACHE_ENTRY
 

Functions

U32_ACCEL_CACHE_ENTRY **WINAPI U32AccelCacheFind (HANDLE Object, HGLOBAL Data)
 
void WINAPI U32AccelCacheAdd (HACCEL Object, HGLOBAL Data)
 
HACCEL WINAPI U32LoadAccelerators (HINSTANCE hInstance, HRSRC hTableRes)
 
BOOL WINAPI U32IsValidAccelMessage (UINT uMsg)
 
BOOL WINAPI DestroyAcceleratorTable (HACCEL hAccel)
 
HACCEL WINAPI LoadAcceleratorsW (HINSTANCE hInstance, LPCWSTR lpTableName)
 
HACCEL WINAPI LoadAcceleratorsA (HINSTANCE hInstance, LPCSTR lpTableName)
 
int WINAPI TranslateAcceleratorW (HWND hWnd, HACCEL hAccTable, LPMSG lpMsg)
 
int WINAPI CopyAcceleratorTableA (HACCEL hAccelSrc, LPACCEL lpAccelDst, int cAccelEntries)
 
HACCEL WINAPI CreateAcceleratorTableA (LPACCEL lpaccl, int cEntries)
 
int WINAPI TranslateAcceleratorA (HWND hWnd, HACCEL hAccTable, LPMSG lpMsg)
 

Variables

CRITICAL_SECTION U32AccelCacheLock
 
U32_ACCEL_CACHE_ENTRYU32AccelCache = NULL
 

Typedef Documentation

◆ LPPE_ACCEL

◆ U32_ACCEL_CACHE_ENTRY

Function Documentation

◆ CopyAcceleratorTableA()

int WINAPI CopyAcceleratorTableA ( HACCEL  hAccelSrc,
LPACCEL  lpAccelDst,
int  cAccelEntries 
)

Definition at line 279 of file accel.c.

285{
286 int i;
287
288 cAccelEntries = CopyAcceleratorTableW(hAccelSrc, lpAccelDst, cAccelEntries);
289
290 if (lpAccelDst == NULL) return cAccelEntries;
291
292 for(i = 0; i < cAccelEntries; ++ i)
293 if(!(lpAccelDst[i].fVirt & FVIRTKEY))
294 {
296 (PCHAR)&lpAccelDst[i].key,
297 sizeof(lpAccelDst[i].key),
298 NULL,
299 (PWCHAR)&lpAccelDst[i].key,
300 sizeof(lpAccelDst[i].key)
301 );
302
303 if(!NT_SUCCESS(nErrCode)) lpAccelDst[i].key = 0;
304 }
305
306 return cAccelEntries;
307}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:107
Definition: copy.c:22
WORD key
Definition: winuser.h:2923
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51
int WINAPI CopyAcceleratorTableW(_In_ HACCEL hAccelSrc, _Out_writes_to_opt_(cAccelEntries, return) LPACCEL lpAccelDst, _In_ int cAccelEntries)
#define FVIRTKEY
Definition: winuser.h:24

◆ CreateAcceleratorTableA()

HACCEL WINAPI CreateAcceleratorTableA ( LPACCEL  lpaccl,
int  cEntries 
)

Definition at line 313 of file accel.c.

314{
315 int i;
316
317 if (!cEntries || !lpaccl) return (HACCEL)0;
318
319 for(i = 0; i < cEntries; ++ i)
320 if(!lpaccl[i].fVirt)
321 {
323 (
324 (PWCHAR)&lpaccl[i].key,
325 sizeof(lpaccl[i].key),
326 NULL,
327 (PCHAR)&lpaccl[i].key,
328 sizeof(lpaccl[i].key)
329 );
330
331 if(!NT_SUCCESS(nErrCode)) lpaccl[i].key = -1;
332 }
333
334 return CreateAcceleratorTableW(lpaccl, cEntries);
335}
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:62
_In_ UINT _In_ UINT cEntries
Definition: wingdi.h:3621
HACCEL WINAPI CreateAcceleratorTableW(_In_reads_(cAccel) LPACCEL paccel, _In_ int cAccel)

◆ DestroyAcceleratorTable()

BOOL WINAPI DestroyAcceleratorTable ( HACCEL  hAccel)

Definition at line 191 of file accel.c.

192{
193 U32_ACCEL_CACHE_ENTRY ** ppEntry;
194 ULONG_PTR nUsage = 0;
195
196 if (!hAccel)
197 return FALSE;
198
200
201 /* see if this accelerator table has been cached */
202 ppEntry = U32AccelCacheFind(hAccel, NULL);
203
204 /* accelerator table cached */
205 if(*ppEntry)
206 {
207 U32_ACCEL_CACHE_ENTRY * pEntry = *ppEntry;
208
209 /* decrement the reference count */
210 nUsage = pEntry->Usage = pEntry->Usage - 1;
211
212 /* reference count now zero: destroy the cache entry */
213 if(nUsage == 0)
214 {
215 /* unlink the cache entry */
216 *ppEntry = pEntry->Next;
217
218 /* free the cache entry */
220 }
221 }
222
224
225 if(nUsage > 0) return FALSE;
226
227 /* destroy the object */
229}
U32_ACCEL_CACHE_ENTRY **WINAPI U32AccelCacheFind(HANDLE Object, HGLOBAL Data)
Definition: accel.c:60
CRITICAL_SECTION U32AccelCacheLock
Definition: accel.c:54
#define FALSE
Definition: types.h:117
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
BOOLEAN NTAPI NtUserDestroyAcceleratorTable(HACCEL Table)
Definition: accelerator.c:340
HACCEL hAccel
Definition: main.c:47
Definition: accel.c:43
uint32_t ULONG_PTR
Definition: typedefs.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

◆ LoadAcceleratorsA()

HACCEL WINAPI LoadAcceleratorsA ( HINSTANCE  hInstance,
LPCSTR  lpTableName 
)

Definition at line 250 of file accel.c.

251{
252 HRSRC Accel;
253
254 Accel = FindResourceExA(hInstance, (LPCSTR) RT_ACCELERATOR, lpTableName, 0);
255 if (NULL == Accel)
256 {
257 return NULL;
258 }
259
260 return U32LoadAccelerators(hInstance, Accel);
261}
HACCEL WINAPI U32LoadAccelerators(HINSTANCE hInstance, HRSRC hTableRes)
Definition: accel.c:94
HINSTANCE hInstance
Definition: charmap.c:19
HRSRC WINAPI FindResourceExA(HMODULE hModule, LPCSTR type, LPCSTR name, WORD lang)
Definition: res.c:143
#define RT_ACCELERATOR
Definition: winuser.h:607
const char * LPCSTR
Definition: xmlstorage.h:183

◆ LoadAcceleratorsW()

HACCEL WINAPI LoadAcceleratorsW ( HINSTANCE  hInstance,
LPCWSTR  lpTableName 
)

Definition at line 237 of file accel.c.

238{
240 (
241 hInstance,
243 );
244}
HRSRC WINAPI FindResourceExW(HMODULE hModule, LPCWSTR type, LPCWSTR name, WORD lang)
Definition: res.c:164
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

◆ TranslateAcceleratorA()

int WINAPI TranslateAcceleratorA ( HWND  hWnd,
HACCEL  hAccTable,
LPMSG  lpMsg 
)

Definition at line 341 of file accel.c.

342{
343 switch (lpMsg->message)
344 {
345 case WM_KEYDOWN:
346 case WM_SYSKEYDOWN:
347 return TranslateAcceleratorW( hWnd, hAccTable, lpMsg );
348
349 case WM_CHAR:
350 case WM_SYSCHAR:
351 {
352 MSG msgW = *lpMsg;
353 char ch = LOWORD(lpMsg->wParam);
354 WCHAR wch;
355 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
356 msgW.wParam = MAKEWPARAM(wch, HIWORD(lpMsg->wParam));
357 return TranslateAcceleratorW( hWnd, hAccTable, &msgW );
358 }
359
360 default:
361 return 0;
362 }
363}
int WINAPI TranslateAcceleratorW(HWND hWnd, HACCEL hAccTable, LPMSG lpMsg)
Definition: accel.c:268
HWND hWnd
Definition: settings.c:17
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
#define LOWORD(l)
Definition: pedump.c:82
UINT message
Definition: winuser.h:3114
WPARAM wParam
Definition: winuser.h:3115
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define HIWORD(l)
Definition: typedefs.h:247
#define MAKEWPARAM(l, h)
Definition: winuser.h:4008
#define WM_SYSCHAR
Definition: winuser.h:1720
#define WM_CHAR
Definition: winuser.h:1716
#define WM_KEYDOWN
Definition: winuser.h:1714
#define WM_SYSKEYDOWN
Definition: winuser.h:1718
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ TranslateAcceleratorW()

int WINAPI TranslateAcceleratorW ( HWND  hWnd,
HACCEL  hAccTable,
LPMSG  lpMsg 
)

Definition at line 268 of file accel.c.

269{
270 if(!U32IsValidAccelMessage(lpMsg->message)) return 0;
271
272 return NtUserTranslateAccelerator(hWnd, hAccTable, lpMsg);
273}
BOOL WINAPI U32IsValidAccelMessage(UINT uMsg)
Definition: accel.c:166
int NTAPI NtUserTranslateAccelerator(HWND Window, HACCEL Table, LPMSG Message)
Definition: accelerator.c:367

Referenced by TranslateAcceleratorA().

◆ U32AccelCacheAdd()

void WINAPI U32AccelCacheAdd ( HACCEL  Object,
HGLOBAL  Data 
)

Definition at line 75 of file accel.c.

76{
79
80 /* failed to allocate an entry - not critical */
81 if(pEntry == NULL) return;
82
83 /* initialize the entry */
84 pEntry->Usage = 1;
85 pEntry->Object = Object;
86 pEntry->Data = Data;
87
88 /* insert the entry into the cache */
89 pEntry->Next = U32AccelCache;
91}
U32_ACCEL_CACHE_ENTRY * U32AccelCache
Definition: accel.c:57
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define LMEM_FIXED
Definition: winbase.h:368

Referenced by U32LoadAccelerators().

◆ U32AccelCacheFind()

U32_ACCEL_CACHE_ENTRY **WINAPI U32AccelCacheFind ( HANDLE  Object,
HGLOBAL  Data 
)

Definition at line 60 of file accel.c.

61{
62 /*
63 to avoid using a double-link list and still allow elements to be removed,
64 return a pointer to the list link that points to the desired entry
65 */
67
68 for(; *ppEntry; ppEntry = &((*ppEntry)->Next))
69 if((*ppEntry)->Object == Object || (*ppEntry)->Data == Data) break;
70
71 return ppEntry;
72}

Referenced by DestroyAcceleratorTable(), and U32LoadAccelerators().

◆ U32IsValidAccelMessage()

BOOL WINAPI U32IsValidAccelMessage ( UINT  uMsg)

Definition at line 166 of file accel.c.

167{
168 switch(uMsg)
169 {
170 case WM_KEYDOWN:
171 case WM_KEYUP:
172 case WM_CHAR:
173 case WM_SYSCHAR:
174 case WM_SYSKEYDOWN:
175 case WM_SYSKEYUP:
176 return TRUE;
177
178 default:
179 return FALSE;
180 }
181}
#define TRUE
Definition: types.h:120
#define WM_KEYUP
Definition: winuser.h:1715
#define WM_SYSKEYUP
Definition: winuser.h:1719

Referenced by TranslateAcceleratorW().

◆ U32LoadAccelerators()

HACCEL WINAPI U32LoadAccelerators ( HINSTANCE  hInstance,
HRSRC  hTableRes 
)

Definition at line 94 of file accel.c.

95{
96 HGLOBAL hAccTableData;
97 HACCEL hAccTable = NULL;
99 PE_ACCEL * pAccTableResData;
100 SIZE_T i = 0;
101 SIZE_T j = 0;
102 ACCEL * pAccTableData;
103
104 /* load the accelerator table */
105 hAccTableData = LoadResource(hInstance, hTableRes);
106
107 /* failure */
108 if(hAccTableData == NULL) return NULL;
109
111
112 /* see if this accelerator table has already been loaded */
113 pEntry = *U32AccelCacheFind(NULL, hAccTableData);
114
115 /* accelerator table already loaded */
116 if(pEntry)
117 {
118 /* increment the reference count */
119 ++ pEntry->Usage;
120
121 /* return the existing object */
122 hAccTable = pEntry->Object;
123
124 /* success */
125 goto l_Leave;
126 }
127
128 /* determine the number of entries in the table */
129 i = SizeofResource(hInstance, hTableRes) / sizeof(PE_ACCEL);
130
131 /* allocate the buffer for the table to be passed to Win32K */
132 pAccTableData = LocalAlloc(LMEM_FIXED, i * sizeof(ACCEL));
133
134 /* failure */
135 if(pAccTableData == NULL) goto l_Leave;
136
137 pAccTableResData = (PE_ACCEL *)hAccTableData;
138
139 /* copy the table */
140 for(j = 0; j < i; ++ j)
141 {
142 pAccTableData[j].fVirt = pAccTableResData[j].fVirt;
143 pAccTableData[j].key = pAccTableResData[j].key;
144 pAccTableData[j].cmd = pAccTableResData[j].cmd;
145 }
146 pAccTableData[i - 1].fVirt |= 0x80;
147
148 /* create a new accelerator table object */
149 hAccTable = NtUserCreateAcceleratorTable(pAccTableData, i);
150
151 /* free the buffer */
152 LocalFree(pAccTableData);
153
154 /* failure */
155 if(hAccTable == NULL) goto l_Leave;
156
157 /* success - cache the object */
158 U32AccelCacheAdd(hAccTable, pAccTableResData);
159
160l_Leave:
162 return hAccTable;
163}
void WINAPI U32AccelCacheAdd(HACCEL Object, HGLOBAL Data)
Definition: accel.c:75
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
HACCEL NTAPI NtUserCreateAcceleratorTable(LPACCEL Entries, ULONG EntriesCount)
Definition: accelerator.c:225
Definition: accel.c:33
WORD cmd
Definition: accel.c:37
BYTE fVirt
Definition: accel.c:34
WORD key
Definition: accel.c:36
WORD cmd
Definition: winuser.h:2924
BYTE fVirt
Definition: winuser.h:2922
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by LoadAcceleratorsA(), and LoadAcceleratorsW().

Variable Documentation

◆ U32AccelCache

U32_ACCEL_CACHE_ENTRY* U32AccelCache = NULL

Definition at line 57 of file accel.c.

Referenced by U32AccelCacheAdd(), and U32AccelCacheFind().

◆ U32AccelCacheLock

CRITICAL_SECTION U32AccelCacheLock