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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50 /* INCLUDES ******************************************************************/
57 /* FUNCTIONS *****************************************************************/
60 InitAcceleratorImpl(VOID
)
62 return(STATUS_SUCCESS
);
66 CleanupAcceleratorImpl(VOID
)
68 return(STATUS_SUCCESS
);
73 PACCELERATOR_TABLE FASTCALL
UserGetAccelObject(HACCEL hAccel
)
75 PACCELERATOR_TABLE Accel
= UserGetObject(&gHandleTable
, hAccel
, otAccel
);
79 ASSERT(USER_BODY_TO_HEADER(Accel
)->RefCount
>= 0);
83 SetLastWin32Error(ERROR_INVALID_ACCEL_HANDLE
);
94 NtUserCopyAcceleratorTable(
99 PWINSTATION_OBJECT WindowStation
;
100 PACCELERATOR_TABLE Accel
;
105 DPRINT("Enter NtUserCopyAcceleratorTable\n");
108 Status
= IntValidateWindowStationHandle(UserGetProcessWindowStation(),
113 if (!NT_SUCCESS(Status
))
115 SetLastNtError(STATUS_ACCESS_DENIED
);
119 if (!(Accel
= UserGetAccelObject(hAccel
)))
121 ObDereferenceObject(WindowStation
);
127 Ret
= min(EntriesCount
, Accel
->Count
);
128 Status
= MmCopyToCaller(Entries
, Accel
->Table
, Ret
* sizeof(ACCEL
));
129 if (!NT_SUCCESS(Status
))
131 ObDereferenceObject(WindowStation
);
132 SetLastNtError(Status
);
141 ObDereferenceObject(WindowStation
);
146 DPRINT("Leave NtUserCopyAcceleratorTable, ret=%i\n",_ret_
);
153 NtUserCreateAcceleratorTable(
157 PWINSTATION_OBJECT WindowStation
;
158 PACCELERATOR_TABLE Accel
;
161 DECLARE_RETURN(HACCEL
);
163 DPRINT("Enter NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d)\n",
164 Entries
, EntriesCount
);
165 UserEnterExclusive();
167 Status
= IntValidateWindowStationHandle(UserGetProcessWindowStation(),
172 if (!NT_SUCCESS(Status
))
174 SetLastNtError(STATUS_ACCESS_DENIED
);
178 Accel
= ObmCreateObject(&gHandleTable
, (PHANDLE
)&hAccel
, otAccel
, sizeof(ACCELERATOR_TABLE
));
182 ObDereferenceObject(WindowStation
);
183 SetLastNtError(STATUS_NO_MEMORY
);
184 RETURN( (HACCEL
) 0 );
187 Accel
->Count
= EntriesCount
;
188 if (Accel
->Count
> 0)
190 Accel
->Table
= ExAllocatePoolWithTag(PagedPool
, EntriesCount
* sizeof(ACCEL
), TAG_ACCEL
);
191 if (Accel
->Table
== NULL
)
193 ObmDeleteObject(hAccel
, otAccel
);
194 ObDereferenceObject(WindowStation
);
195 SetLastNtError(Status
);
199 Status
= MmCopyFromCaller(Accel
->Table
, Entries
, EntriesCount
* sizeof(ACCEL
));
200 if (!NT_SUCCESS(Status
))
202 ExFreePool(Accel
->Table
);
203 ObmDeleteObject(hAccel
, otAccel
);
204 ObDereferenceObject(WindowStation
);
205 SetLastNtError(Status
);
210 ObDereferenceObject(WindowStation
);
212 /* FIXME: Save HandleTable in a list somewhere so we can clean it up again */
217 DPRINT("Leave NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d) = %x\n",
218 Entries
, EntriesCount
,_ret_
);
227 NtUserDestroyAcceleratorTable(
230 PWINSTATION_OBJECT WindowStation
;
231 PACCELERATOR_TABLE Accel
;
233 DECLARE_RETURN(BOOLEAN
);
235 /* FIXME: If the handle table is from a call to LoadAcceleratorTable, decrement it's
236 usage count (and return TRUE).
237 FIXME: Destroy only tables created using CreateAcceleratorTable.
240 DPRINT("NtUserDestroyAcceleratorTable(Table %x)\n", hAccel
);
241 UserEnterExclusive();
243 Status
= IntValidateWindowStationHandle(UserGetProcessWindowStation(),
248 if (!NT_SUCCESS(Status
))
250 SetLastNtError(STATUS_ACCESS_DENIED
);
255 if (!(Accel
= UserGetAccelObject(hAccel
)))
257 ObDereferenceObject(WindowStation
);
261 ObmDeleteObject(hAccel
, otAccel
);
263 if (Accel
->Table
!= NULL
)
265 ExFreePool(Accel
->Table
);
268 ObDereferenceObject(WindowStation
);
273 DPRINT("Leave NtUserDestroyAcceleratorTable(Table %x) = %i\n", hAccel
,_ret_
);
280 co_IntTranslateAccelerator(
281 PWINDOW_OBJECT Window
,
291 ASSERT_REFS_CO(Window
);
293 DPRINT("IntTranslateAccelerator(hwnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x)\n",
294 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
302 if (message
== WM_CHAR
)
304 if (!(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
))
306 DPRINT("found accel for WM_CHAR: ('%c')\n", wParam
& 0xff);
312 if ((fVirt
& FVIRTKEY
) > 0)
315 DPRINT("found accel for virt_key %04x (scan %04x)\n",
316 wParam
, 0xff & HIWORD(lParam
));
318 DPRINT("NtUserGetKeyState(VK_SHIFT) = 0x%x\n",
319 UserGetKeyState(VK_SHIFT
));
320 DPRINT("NtUserGetKeyState(VK_CONTROL) = 0x%x\n",
321 UserGetKeyState(VK_CONTROL
));
322 DPRINT("NtUserGetKeyState(VK_MENU) = 0x%x\n",
323 UserGetKeyState(VK_MENU
));
325 if (UserGetKeyState(VK_SHIFT
) & 0x8000)
327 if (UserGetKeyState(VK_CONTROL
) & 0x8000)
329 if (UserGetKeyState(VK_MENU
) & 0x8000)
331 if (mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
333 DPRINT("but incorrect SHIFT/CTRL/ALT-state\n");
337 if (!(lParam
& 0x01000000)) /* no special_key */
339 if ((fVirt
& FALT
) && (lParam
& 0x20000000))
340 { /* ^^ ALT pressed */
341 DPRINT("found accel for Alt-%c\n", wParam
& 0xff);
348 DPRINT("IntTranslateAccelerator(hwnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x) = FALSE\n",
349 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
354 if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
356 else if (IntGetCaptureWindow())
358 else if (!IntIsWindowVisible(Window
->hSelf
)) /* FIXME: WINE IsWindowEnabled == IntIsWindowVisible? */
363 HMENU hMenu
, hSubMenu
, hSysMenu
;
364 UINT uSysStat
= (UINT
)-1, uStat
= (UINT
)-1, nPos
;
366 hMenu
= (UserGetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
) ? 0 : GetMenu(hWnd
);
367 hSysMenu
= get_win_sys_menu(hWnd
);
369 /* find menu item and ask application to initialize it */
370 /* 1. in the system menu */
373 if(MENU_FindItem(&hSubMenu
, &nPos
, MF_BYCOMMAND
))
375 co_IntSendMessage(hWnd
, WM_INITMENU
, (WPARAM
)hSysMenu
, 0L);
376 if(hSubMenu
!= hSysMenu
)
378 nPos
= MENU_FindSubMenu(&hSysMenu
, hSubMenu
);
379 TRACE_(accel
)("hSysMenu = %p, hSubMenu = %p, nPos = %d\n", hSysMenu
, hSubMenu
, nPos
);
380 co_IntSendMessage(hWnd
, WM_INITMENUPOPUP
, (WPARAM
)hSubMenu
, MAKELPARAM(nPos
, TRUE
));
382 uSysStat
= GetMenuState(GetSubMenu(hSysMenu
, 0), cmd
, MF_BYCOMMAND
);
384 else /* 2. in the window's menu */
388 if(MENU_FindItem(&hSubMenu
, &nPos
, MF_BYCOMMAND
))
390 co_IntSendMessage(hWnd
, WM_INITMENU
, (WPARAM
)hMenu
, 0L);
391 if(hSubMenu
!= hMenu
)
393 nPos
= MENU_FindSubMenu(&hMenu
, hSubMenu
);
394 TRACE_(accel
)("hMenu = %p, hSubMenu = %p, nPos = %d\n", hMenu
, hSubMenu
, nPos
);
395 co_IntSendMessage(hWnd
, WM_INITMENUPOPUP
, (WPARAM
)hSubMenu
, MAKELPARAM(nPos
, FALSE
));
397 uStat
= GetMenuState(hMenu
, cmd
, MF_BYCOMMAND
);
401 if (uSysStat
!= (UINT
)-1)
403 if (uSysStat
& (MF_DISABLED
|MF_GRAYED
))
410 if (uStat
!= (UINT
)-1)
416 if (uStat
& (MF_DISABLED
|MF_GRAYED
))
428 DPRINT1("menu search not implemented");
434 if (mesg
== WM_COMMAND
)
436 DPRINT(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd
);
437 co_IntSendMessage(Window
->hSelf
, mesg
, 0x10000 | cmd
, 0L);
439 else if (mesg
== WM_SYSCOMMAND
)
441 DPRINT(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd
);
442 co_IntSendMessage(Window
->hSelf
, mesg
, cmd
, 0x00010000L
);
446 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
447 * #0: unknown (please report!)
448 * #1: for WM_KEYUP,WM_SYSKEYUP
449 * #2: mouse is captured
450 * #3: window is disabled
451 * #4: it's a disabled system menu option
452 * #5: it's a menu option, but window is iconic
453 * #6: it's a menu option, but disabled
455 DPRINT(", but won't send WM_{SYS}COMMAND, reason is #%d\n", mesg
);
458 DPRINT1(" unknown reason - please report!");
462 DPRINT("IntTranslateAccelerator(hWnd %x, message %x, wParam %x, lParam %x, fVirt %d, key %x, cmd %x) = TRUE\n",
463 Window
->hSelf
, message
, wParam
, lParam
, fVirt
, key
, cmd
);
470 NtUserTranslateAccelerator(
475 PWINSTATION_OBJECT WindowStation
= NULL
;
476 PWINDOW_OBJECT Window
= NULL
;
477 PACCELERATOR_TABLE Accel
= NULL
;
482 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p)\n",
483 hWnd
, hAccel
, Message
);
488 SetLastNtError(STATUS_INVALID_PARAMETER
);
492 if ((Message
->message
!= WM_KEYDOWN
) &&
493 (Message
->message
!= WM_SYSKEYDOWN
) &&
494 (Message
->message
!= WM_SYSCHAR
) &&
495 (Message
->message
!= WM_CHAR
))
500 Status
= IntValidateWindowStationHandle(UserGetProcessWindowStation(),
505 if (!NT_SUCCESS(Status
))
507 SetLastNtError(STATUS_ACCESS_DENIED
);
511 if (!(Accel
= UserGetAccelObject(hAccel
)))
516 UserRefObjectCo(Accel
);
518 if (!(Window
= UserGetWindowObject(hWnd
)))
523 UserRefObjectCo(Window
);
526 /* FIXME: Associate AcceleratorTable with the current thread */
528 for (i
= 0; i
< Accel
->Count
; i
++)
530 if (co_IntTranslateAccelerator(Window
, Message
->message
, Message
->wParam
, Message
->lParam
,
531 Accel
->Table
[i
].fVirt
, Accel
->Table
[i
].key
,
532 Accel
->Table
[i
].cmd
))
534 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
535 hWnd
, hAccel
, Message
, 1);
538 if (((Accel
->Table
[i
].fVirt
& 0x80) > 0))
549 UserDerefObjectCo(Window
);
551 UserDerefObjectCo(Accel
);
554 ObDereferenceObject(WindowStation
);
556 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
557 hWnd
, hAccel
, Message
, 0);