2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Window classes
24 * FILE: subsys/win32k/ntuser/class.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
31 * Copyright 1993 Martin Ayotte
32 * Copyright 1994 Alexandre Julliard
33 * Copyright 1997 Morten Welinder
35 * This library is free software; you can redistribute it and/or
36 * modify it under the terms of the GNU Lesser General Public
37 * License as published by the Free Software Foundation; either
38 * version 2.1 of the License, or (at your option) any later version.
40 * This library is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43 * Lesser General Public License for more details.
45 * You should have received a copy of the GNU Lesser General Public
46 * License along with this library; if not, write to the Free Software
47 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
50 /* INCLUDES ******************************************************************/
57 /* FUNCTIONS *****************************************************************/
60 InitAcceleratorImpl(VOID
)
62 return(STATUS_SUCCESS
);
66 CleanupAcceleratorImpl(VOID
)
68 return(STATUS_SUCCESS
);
72 PACCELERATOR_TABLE FASTCALL
UserGetAccelObject(HACCEL hAccel
)
74 PACCELERATOR_TABLE Accel
;
78 SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE
);
82 Accel
= UserGetObject(gHandleTable
, hAccel
, otAccel
);
85 SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE
);
89 ASSERT(Accel
->head
.cLockObj
>= 0);
97 co_IntTranslateAccelerator(
98 PWINDOW_OBJECT Window
,
108 ASSERT_REFS_CO(Window
);
110 DPRINT("IntTranslateAccelerator(hwnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x)\n",
111 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
118 if (message
== WM_CHAR
)
120 if (!(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
))
122 DPRINT("found accel for WM_CHAR: ('%c')\n", wParam
& 0xff);
128 if ((fVirt
& FVIRTKEY
) > 0)
131 DPRINT("found accel for virt_key %04x (scan %04x)\n",
132 wParam
, 0xff & HIWORD(lParam
));
134 DPRINT("NtUserGetKeyState(VK_SHIFT) = 0x%x\n",
135 UserGetKeyState(VK_SHIFT
));
136 DPRINT("NtUserGetKeyState(VK_CONTROL) = 0x%x\n",
137 UserGetKeyState(VK_CONTROL
));
138 DPRINT("NtUserGetKeyState(VK_MENU) = 0x%x\n",
139 UserGetKeyState(VK_MENU
));
141 if (UserGetKeyState(VK_SHIFT
) & 0x8000)
143 if (UserGetKeyState(VK_CONTROL
) & 0x8000)
145 if (UserGetKeyState(VK_MENU
) & 0x8000)
147 if (mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
149 DPRINT("but incorrect SHIFT/CTRL/ALT-state\n");
153 if (!(lParam
& 0x01000000)) /* no special_key */
155 if ((fVirt
& FALT
) && (lParam
& 0x20000000))
156 { /* ^^ ALT pressed */
157 DPRINT("found accel for Alt-%c\n", wParam
& 0xff);
164 DPRINT("IntTranslateAccelerator(hwnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x) = FALSE\n",
165 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
170 if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
172 else if (IntGetCaptureWindow())
174 else if (!IntIsWindowVisible(Window
)) /* FIXME: WINE IsWindowEnabled == IntIsWindowVisible? */
179 HMENU hMenu
, hSubMenu
, hSysMenu
;
180 UINT uSysStat
= (UINT
)-1, uStat
= (UINT
)-1, nPos
;
182 hMenu
= (UserGetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
) ? 0 : GetMenu(hWnd
);
183 hSysMenu
= get_win_sys_menu(hWnd
);
185 /* find menu item and ask application to initialize it */
186 /* 1. in the system menu */
189 if(MENU_FindItem(&hSubMenu
, &nPos
, MF_BYCOMMAND
))
191 co_IntSendMessage(hWnd
, WM_INITMENU
, (WPARAM
)hSysMenu
, 0L);
192 if(hSubMenu
!= hSysMenu
)
194 nPos
= MENU_FindSubMenu(&hSysMenu
, hSubMenu
);
195 TRACE_(accel
)("hSysMenu = %p, hSubMenu = %p, nPos = %d\n", hSysMenu
, hSubMenu
, nPos
);
196 co_IntSendMessage(hWnd
, WM_INITMENUPOPUP
, (WPARAM
)hSubMenu
, MAKELPARAM(nPos
, TRUE
));
198 uSysStat
= GetMenuState(GetSubMenu(hSysMenu
, 0), cmd
, MF_BYCOMMAND
);
200 else /* 2. in the window's menu */
204 if(MENU_FindItem(&hSubMenu
, &nPos
, MF_BYCOMMAND
))
206 co_IntSendMessage(hWnd
, WM_INITMENU
, (WPARAM
)hMenu
, 0L);
207 if(hSubMenu
!= hMenu
)
209 nPos
= MENU_FindSubMenu(&hMenu
, hSubMenu
);
210 TRACE_(accel
)("hMenu = %p, hSubMenu = %p, nPos = %d\n", hMenu
, hSubMenu
, nPos
);
211 co_IntSendMessage(hWnd
, WM_INITMENUPOPUP
, (WPARAM
)hSubMenu
, MAKELPARAM(nPos
, FALSE
));
213 uStat
= GetMenuState(hMenu
, cmd
, MF_BYCOMMAND
);
217 if (uSysStat
!= (UINT
)-1)
219 if (uSysStat
& (MF_DISABLED
|MF_GRAYED
))
226 if (uStat
!= (UINT
)-1)
232 if (uStat
& (MF_DISABLED
|MF_GRAYED
))
244 DPRINT1("Menu search not implemented\n");
250 if (mesg
== WM_COMMAND
)
252 DPRINT(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd
);
253 co_IntSendMessage(Window
->hSelf
, mesg
, 0x10000 | cmd
, 0L);
255 else if (mesg
== WM_SYSCOMMAND
)
257 DPRINT(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd
);
258 co_IntSendMessage(Window
->hSelf
, mesg
, cmd
, 0x00010000L
);
262 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
263 * #0: unknown (please report!)
264 * #1: for WM_KEYUP,WM_SYSKEYUP
265 * #2: mouse is captured
266 * #3: window is disabled
267 * #4: it's a disabled system menu option
268 * #5: it's a menu option, but window is iconic
269 * #6: it's a menu option, but disabled
271 DPRINT(", but won't send WM_{SYS}COMMAND, reason is #%d\n", mesg
);
274 DPRINT1(" unknown reason - please report!");
278 DPRINT("IntTranslateAccelerator(hWnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x) = TRUE\n",
279 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
285 /* SYSCALLS *****************************************************************/
290 NtUserCopyAcceleratorTable(
295 PACCELERATOR_TABLE Accel
;
300 DPRINT("Enter NtUserCopyAcceleratorTable\n");
303 Accel
= UserGetAccelObject(hAccel
);
305 if ((Entries
&& (EntriesCount
< 1)) || ((hAccel
== NULL
) || (!Accel
)))
310 if (Accel
->Count
< EntriesCount
)
311 EntriesCount
= Accel
->Count
;
319 Entries
[Ret
].fVirt
= Accel
->Table
[Ret
].fVirt
& 0x7f;
320 Entries
[Ret
].key
= Accel
->Table
[Ret
].key
;
321 Entries
[Ret
].cmd
= Accel
->Table
[Ret
].cmd
;
323 if(Ret
+ 1 == EntriesCount
) Done
= TRUE
;
326 if((Accel
->Table
[Ret
].fVirt
& 0x80) != 0) Done
= TRUE
;
334 DPRINT("Leave NtUserCopyAcceleratorTable, ret=%i\n",_ret_
);
341 NtUserCreateAcceleratorTable(
345 PACCELERATOR_TABLE Accel
;
348 DECLARE_RETURN(HACCEL
);
350 DPRINT("Enter NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d)\n",
351 Entries
, EntriesCount
);
352 UserEnterExclusive();
354 if (!Entries
|| EntriesCount
< 1)
356 SetLastNtError(STATUS_INVALID_PARAMETER
);
357 RETURN( (HACCEL
) NULL
);
360 Accel
= UserCreateObject(gHandleTable
, NULL
, (PHANDLE
)&hAccel
, otAccel
, sizeof(ACCELERATOR_TABLE
));
364 SetLastNtError(STATUS_NO_MEMORY
);
365 RETURN( (HACCEL
) NULL
);
368 Accel
->Count
= EntriesCount
;
369 if (Accel
->Count
> 0)
371 Accel
->Table
= ExAllocatePoolWithTag(PagedPool
, EntriesCount
* sizeof(ACCEL
), TAG_ACCEL
);
372 if (Accel
->Table
== NULL
)
374 UserDereferenceObject(Accel
);
375 UserDeleteObject(hAccel
, otAccel
);
376 SetLastNtError(STATUS_NO_MEMORY
);
377 RETURN( (HACCEL
) NULL
);
380 for (Index
= 0; Index
< EntriesCount
; Index
++)
382 Accel
->Table
[Index
].fVirt
= Entries
[Index
].fVirt
&0x7f;
383 if(Accel
->Table
[Index
].fVirt
& FVIRTKEY
)
385 Accel
->Table
[Index
].key
= Entries
[Index
].key
;
389 RtlMultiByteToUnicodeN(&Accel
->Table
[Index
].key
,
392 (PCSTR
)&Entries
[Index
].key
,
396 Accel
->Table
[Index
].cmd
= Entries
[Index
].cmd
;
399 /* Set the end-of-table terminator. */
400 Accel
->Table
[EntriesCount
- 1].fVirt
|= 0x80;
403 /* FIXME: Save HandleTable in a list somewhere so we can clean it up again */
408 DPRINT("Leave NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d) = %x\n",
409 Entries
, EntriesCount
,_ret_
);
418 NtUserDestroyAcceleratorTable(
421 PACCELERATOR_TABLE Accel
;
422 DECLARE_RETURN(BOOLEAN
);
424 /* FIXME: If the handle table is from a call to LoadAcceleratorTable, decrement it's
425 usage count (and return TRUE).
426 FIXME: Destroy only tables created using CreateAcceleratorTable.
429 DPRINT("NtUserDestroyAcceleratorTable(Table %x)\n", hAccel
);
430 UserEnterExclusive();
432 if (!(Accel
= UserGetAccelObject(hAccel
)))
437 if (Accel
->Table
!= NULL
)
439 ExFreePoolWithTag(Accel
->Table
, TAG_ACCEL
);
443 UserDeleteObject(hAccel
, otAccel
);
448 DPRINT("Leave NtUserDestroyAcceleratorTable(Table %x) = %i\n", hAccel
,_ret_
);
456 NtUserTranslateAccelerator(
461 PWINDOW_OBJECT Window
= NULL
;
462 PACCELERATOR_TABLE Accel
= NULL
;
464 USER_REFERENCE_ENTRY AccelRef
, WindowRef
;
467 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p)\n",
468 hWnd
, hAccel
, Message
);
473 SetLastNtError(STATUS_INVALID_PARAMETER
);
477 if ((Message
->message
!= WM_KEYDOWN
) &&
478 (Message
->message
!= WM_SYSKEYDOWN
) &&
479 (Message
->message
!= WM_SYSCHAR
) &&
480 (Message
->message
!= WM_CHAR
))
485 if (!(Accel
= UserGetAccelObject(hAccel
)))
490 UserRefObjectCo(Accel
, &AccelRef
);
492 if (!(Window
= UserGetWindowObject(hWnd
)))
497 UserRefObjectCo(Window
, &WindowRef
);
500 /* FIXME: Associate AcceleratorTable with the current thread */
502 for (i
= 0; i
< Accel
->Count
; i
++)
504 if (co_IntTranslateAccelerator(Window
, Message
->message
, Message
->wParam
, Message
->lParam
,
505 Accel
->Table
[i
].fVirt
, Accel
->Table
[i
].key
,
506 Accel
->Table
[i
].cmd
))
508 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
509 hWnd
, hAccel
, Message
, 1);
512 if (((Accel
->Table
[i
].fVirt
& 0x80) > 0))
521 if (Window
) UserDerefObjectCo(Window
);
522 if (Accel
) UserDerefObjectCo(Accel
);
524 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
525 hWnd
, hAccel
, Message
, 0);