update for HEAD-2003091401
[reactos.git] / subsys / win32k / ntuser / input.c
index edd347d..59a62f1 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ *  ReactOS W32 Subsystem
+ *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /* $Id$
  *
  * COPYRIGHT:        See COPYING in the top level directory
@@ -19,6 +37,7 @@
 #include <include/winsta.h>
 #include <include/msgqueue.h>
 #include <ddk/ntddmou.h>
+#include <include/mouse.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -32,11 +51,9 @@ static HANDLE KeyboardDeviceHandle;
 static KEVENT InputThreadsStart;
 static BOOLEAN InputThreadsRunning = FALSE;
 
-VOID MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount);
-
 /* FUNCTIONS *****************************************************************/
 
-NTSTATUS STDCALL STATIC
+VOID STDCALL_FUNC STATIC
 KeyboardThreadMain(PVOID StartContext)
 {
   UNICODE_STRING KeyboardDeviceName;
@@ -58,8 +75,8 @@ KeyboardThreadMain(PVOID StartContext)
                      FILE_SYNCHRONOUS_IO_ALERT);
   if (!NT_SUCCESS(Status))
     {
-      DbgPrint("W32K: Failed to open keyboard.\n");
-      return(Status);
+      DbgPrint("Win32K: Failed to open keyboard.\n");
+      return; //(Status);
     }
 
   for (;;)
@@ -72,6 +89,7 @@ KeyboardThreadMain(PVOID StartContext)
                                     UserMode,
                                     TRUE,
                                     NULL);
+
       /*
        * Receive and process keyboard input.
        */
@@ -79,6 +97,7 @@ KeyboardThreadMain(PVOID StartContext)
        {
          KEY_EVENT_RECORD KeyEvent;
          LPARAM lParam;
+    BOOLEAN SysKey;
          
          Status = NtReadFile (KeyboardDeviceHandle, 
                               NULL,
@@ -89,33 +108,61 @@ KeyboardThreadMain(PVOID StartContext)
                               sizeof(KEY_EVENT_RECORD),
                               NULL,
                               NULL);
+    DbgPrint( "KeyRaw: %s %04x\n",
+             KeyEvent.bKeyDown ? "down" : "up",
+             KeyEvent.wVirtualScanCode );
+
          if (Status == STATUS_ALERTED && !InputThreadsRunning)
            {
              break;
            }
          if (!NT_SUCCESS(Status))
            {
-             DbgPrint("W32K: Failed to read from keyboard.\n");
-             return(Status);
+             DbgPrint("Win32K: Failed to read from keyboard.\n");
+             return; //(Status);
            }
          
+    SysKey = KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED);
+       DbgPrint( "Key: %s\n", KeyEvent.bKeyDown ? "down" : "up" );
+
          /*
           * Post a keyboard message.
           */
          if (KeyEvent.bKeyDown)
            {
-             /* FIXME: Bit 24 indicates if this is an extended key. */
              lParam = KeyEvent.wRepeatCount | 
-               ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0x40000000;
-             MsqPostKeyboardMessage(WM_KEYDOWN, KeyEvent.wVirtualKeyCode, 
+                     ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0x40000000;
+
+             /* Bit 24 indicates if this is an extended key */
+        if (KeyEvent.dwControlKeyState & ENHANCED_KEY)
+          {
+            lParam |= (1 << 24);
+          }
+
+        if (SysKey)
+          {
+            lParam |= (1 << 29);  /* Context mode. 1 if ALT if pressed while the key is pressed */
+          }
+
+             MsqPostKeyboardMessage(SysKey ? WM_SYSKEYDOWN : WM_KEYDOWN, KeyEvent.wVirtualKeyCode, 
                                     lParam);
            }
          else
            {
-             /* FIXME: Bit 24 indicates if this is an extended key. */
              lParam = KeyEvent.wRepeatCount | 
-               ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0xC0000000;
-             MsqPostKeyboardMessage(WM_KEYUP, KeyEvent.wVirtualKeyCode, 
+                     ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0xC0000000;
+
+             /* Bit 24 indicates if this is an extended key */
+        if (KeyEvent.dwControlKeyState & ENHANCED_KEY)
+          {
+            lParam |= (1 << 24);
+          }
+
+        if (SysKey)
+          {
+            lParam |= (1 << 29);  /* Context mode. 1 if ALT if pressed while the key is pressed */
+          }
+             MsqPostKeyboardMessage(SysKey ? WM_SYSKEYUP : WM_KEYUP, KeyEvent.wVirtualKeyCode, 
                                     lParam);
            }
        }
@@ -139,7 +186,7 @@ NtUserAcquireOrReleaseInputOwnership(BOOLEAN Release)
   return(STATUS_SUCCESS);
 }
 
-NTSTATUS
+NTSTATUS FASTCALL
 InitInputImpl(VOID)
 {
   NTSTATUS Status;
@@ -163,7 +210,7 @@ InitInputImpl(VOID)
                                NULL);
   if (!NT_SUCCESS(Status))
     {
-      DbgPrint("W32K: Failed to create keyboard thread.\n");
+      DbgPrint("Win32K: Failed to create keyboard thread.\n");
     }
 
   /*
@@ -183,7 +230,7 @@ InitInputImpl(VOID)
                      0);
   if (!NT_SUCCESS(Status))
     {
-      DbgPrint("W32K: Failed to open mouse.\n");
+      DbgPrint("Win32K: Failed to open mouse.\n");
       return(Status);
     }
   Status = ObReferenceObjectByHandle(MouseDeviceHandle,
@@ -195,7 +242,7 @@ InitInputImpl(VOID)
    
    if (!NT_SUCCESS(Status))
      {
-       DbgPrint("W32K: Failed to reference mouse file object.\n");
+       DbgPrint("Win32K: Failed to reference mouse file object.\n");
        return(Status);
      }
    KeInitializeEvent(&IoEvent, FALSE, NotificationEvent);
@@ -209,6 +256,10 @@ InitInputImpl(VOID)
                                       TRUE,
                                       &FileObject->Event,
                                       &Iosb);
+
+   //trigger FileObject/Event dereferencing
+   Irp->Tail.Overlay.OriginalFileObject = FileObject;
+
    StackPtr = IoGetNextIrpStackLocation(Irp);
    StackPtr->FileObject = FileObject;
    StackPtr->DeviceObject = FileObject->DeviceObject;
@@ -224,17 +275,29 @@ InitInputImpl(VOID)
      }
    if (!NT_SUCCESS(Status))
      {
-       DbgPrint("W32K: Failed to connect to mouse driver.\n");
+       DbgPrint("Win32K: Failed to connect to mouse driver.\n");
        return(Status);
      }
    
    return(STATUS_SUCCESS);
 }
 
-NTSTATUS
+NTSTATUS FASTCALL
 CleanupInputImp(VOID)
 {
   return(STATUS_SUCCESS);
 }
 
+BOOL
+STDCALL
+NtUserDragDetect(
+  HWND hWnd,
+  LONG x,
+  LONG y)
+{
+  UNIMPLEMENTED
+  return 0;
+}
+
+
 /* EOF */