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
);
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(USER_BODY_TO_HEADER(Accel
)->RefCount
>= 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 if (!(Accel
= UserGetAccelObject(hAccel
)))
310 Ret
= min(EntriesCount
, Accel
->Count
);
311 Status
= MmCopyToCaller(Entries
, Accel
->Table
, Ret
* sizeof(ACCEL
));
312 if (!NT_SUCCESS(Status
))
314 SetLastNtError(Status
);
326 DPRINT("Leave NtUserCopyAcceleratorTable, ret=%i\n",_ret_
);
333 NtUserCreateAcceleratorTable(
337 PACCELERATOR_TABLE Accel
;
340 DECLARE_RETURN(HACCEL
);
342 DPRINT("Enter NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d)\n",
343 Entries
, EntriesCount
);
344 UserEnterExclusive();
346 if (!Entries
|| !EntriesCount
)
348 RETURN( (HACCEL
) 0 );
351 Accel
= UserCreateObject(gHandleTable
, (PHANDLE
)&hAccel
, otAccel
, sizeof(ACCELERATOR_TABLE
));
355 SetLastNtError(STATUS_NO_MEMORY
);
356 RETURN( (HACCEL
) 0 );
359 Accel
->Count
= EntriesCount
;
360 if (Accel
->Count
> 0)
362 Accel
->Table
= ExAllocatePoolWithTag(PagedPool
, EntriesCount
* sizeof(ACCEL
), TAG_ACCEL
);
363 if (Accel
->Table
== NULL
)
365 UserDereferenceObject(Accel
);
366 UserDeleteObject(hAccel
, otAccel
);
367 SetLastNtError(STATUS_NO_MEMORY
);
371 Status
= MmCopyFromCaller(Accel
->Table
, Entries
, EntriesCount
* sizeof(ACCEL
));
372 if (!NT_SUCCESS(Status
))
374 ExFreePool(Accel
->Table
);
375 UserDereferenceObject(Accel
);
376 UserDeleteObject(hAccel
, otAccel
);
377 SetLastNtError(Status
);
382 /* FIXME: Save HandleTable in a list somewhere so we can clean it up again */
387 DPRINT("Leave NtUserCreateAcceleratorTable(Entries %p, EntriesCount %d) = %x\n",
388 Entries
, EntriesCount
,_ret_
);
397 NtUserDestroyAcceleratorTable(
400 PACCELERATOR_TABLE Accel
;
401 DECLARE_RETURN(BOOLEAN
);
403 /* FIXME: If the handle table is from a call to LoadAcceleratorTable, decrement it's
404 usage count (and return TRUE).
405 FIXME: Destroy only tables created using CreateAcceleratorTable.
408 DPRINT("NtUserDestroyAcceleratorTable(Table %x)\n", hAccel
);
409 UserEnterExclusive();
411 if (!(Accel
= UserGetAccelObject(hAccel
)))
416 if (Accel
->Table
!= NULL
)
418 ExFreePool(Accel
->Table
);
422 UserDeleteObject(hAccel
, otAccel
);
427 DPRINT("Leave NtUserDestroyAcceleratorTable(Table %x) = %i\n", hAccel
,_ret_
);
435 NtUserTranslateAccelerator(
440 PWINDOW_OBJECT Window
= NULL
;
441 PACCELERATOR_TABLE Accel
= NULL
;
443 USER_REFERENCE_ENTRY AccelRef
, WindowRef
;
446 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p)\n",
447 hWnd
, hAccel
, Message
);
452 SetLastNtError(STATUS_INVALID_PARAMETER
);
456 if ((Message
->message
!= WM_KEYDOWN
) &&
457 (Message
->message
!= WM_SYSKEYDOWN
) &&
458 (Message
->message
!= WM_SYSCHAR
) &&
459 (Message
->message
!= WM_CHAR
))
464 if (!(Accel
= UserGetAccelObject(hAccel
)))
469 UserRefObjectCo(Accel
, &AccelRef
);
471 if (!(Window
= UserGetWindowObject(hWnd
)))
476 UserRefObjectCo(Window
, &WindowRef
);
479 /* FIXME: Associate AcceleratorTable with the current thread */
481 for (i
= 0; i
< Accel
->Count
; i
++)
483 if (co_IntTranslateAccelerator(Window
, Message
->message
, Message
->wParam
, Message
->lParam
,
484 Accel
->Table
[i
].fVirt
, Accel
->Table
[i
].key
,
485 Accel
->Table
[i
].cmd
))
487 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
488 hWnd
, hAccel
, Message
, 1);
491 if (((Accel
->Table
[i
].fVirt
& 0x80) > 0))
500 if (Window
) UserDerefObjectCo(Window
);
501 if (Accel
) UserDerefObjectCo(Accel
);
503 DPRINT("NtUserTranslateAccelerator(hWnd %x, Table %x, Message %p) = %i end\n",
504 hWnd
, hAccel
, Message
, 0);