- Implement ReadConsoleInputW, PeekConsoleInputW, ReadConsoleOutputW, WriteConsoleOut...
authorFilip Navara <filip.navara@gmail.com>
Sun, 22 Aug 2004 20:52:28 +0000 (20:52 +0000)
committerFilip Navara <filip.navara@gmail.com>
Sun, 22 Aug 2004 20:52:28 +0000 (20:52 +0000)
- Fix input peeking in CSRSS to not return fake events.

svn path=/trunk/; revision=10658

reactos/include/csrss/csrss.h
reactos/lib/kernel32/misc/console.c
reactos/subsys/csrss/include/conio.h
reactos/subsys/csrss/win32csr/conio.c
reactos/subsys/csrss/win32csr/dllmain.c

index 392e23b..173f935 100644 (file)
@@ -137,6 +137,7 @@ typedef struct
 typedef struct
 {
    HANDLE ConsoleHandle;
+   BOOL Unicode;
 } CSRSS_READ_INPUT_REQUEST, *PCSRSS_READ_INPUT_REQUEST;
 
 typedef struct
@@ -277,6 +278,7 @@ typedef struct
 typedef struct
 {
   HANDLE ConsoleHandle;
+  BOOL Unicode;
   COORD BufferSize;
   COORD BufferCoord;
   SMALL_RECT WriteRegion;
@@ -389,6 +391,7 @@ typedef struct
 typedef struct
 {
   HANDLE ConsoleHandle;
+  BOOL Unicode;
   DWORD Length;
   INPUT_RECORD* InputRecord;
 } CSRSS_PEEK_CONSOLE_INPUT_REQUEST, *PCSRSS_PEEK_CONSOLE_INPUT_REQUEST;
@@ -401,6 +404,7 @@ typedef struct
 typedef struct
 {
   HANDLE ConsoleHandle;
+  BOOL Unicode;
   COORD BufferSize;
   COORD BufferCoord;
   SMALL_RECT ReadRegion;
@@ -493,15 +497,21 @@ typedef struct
 
 typedef struct
 {
-  HANDLE ConsoleHandle;
+} CSRSS_GET_CONSOLE_WINDOW_REQUEST, *PCSRSS_GET_CONSOLE_WINDOW_REQUEST;
+
+typedef struct
+{
   HWND   WindowHandle;
-} CSRSS_CONSOLE_WINDOW, *PCSRSS_CONSOLE_WINDOW;
+} CSRSS_GET_CONSOLE_WINDOW_REPLY, *PCSRSS_GET_CONSOLE_WINDOW_REPLY;
 
 typedef struct
 {
-  HANDLE ConsoleHandle;
   HICON  WindowIcon;
-} CSRSS_CONSOLE_SET_WINDOW_ICON, *PCSRSS_CONSOLE_SET_WINDOW_ICON;
+} CSRSS_SET_CONSOLE_ICON_REQUEST, *PCSRSS_SET_CONSOLE_ICON_REQUEST;
+
+typedef struct
+{
+} CSRSS_SET_CONSOLE_ICON_REPLY, *PCSRSS_SET_CONSOLE_ICON_REPLY;
 
 typedef struct
 {
@@ -551,6 +561,42 @@ typedef struct
 {
 } CSRSS_REGISTER_LOGON_PROCESS_REPLY, *PCSRSS_REGISTER_LOGON_PROCESS_REPLY;
 
+typedef struct
+{
+} CSRSS_GET_CONSOLE_CP_REQUEST, *PCSRSS_GET_CONSOLE_CP_REQUEST;
+
+typedef struct
+{
+  UINT CodePage;
+} CSRSS_GET_CONSOLE_CP_REPLY, *PCSRSS_GET_CONSOLE_CP_REPLY;
+
+typedef struct
+{
+  UINT CodePage;
+} CSRSS_SET_CONSOLE_CP_REQUEST, *PCSRSS_SET_CONSOLE_CP_REQUEST;
+
+typedef struct
+{
+} CSRSS_SET_CONSOLE_CP_REPLY, *PCSRSS_SET_CONSOLE_CP_REPLY;
+
+typedef struct
+{
+} CSRSS_GET_CONSOLE_OUTPUT_CP_REQUEST, *PCSRSS_GET_CONSOLE_OUTPUT_CP_REQUEST;
+
+typedef struct
+{
+  UINT CodePage;
+} CSRSS_GET_CONSOLE_OUTPUT_CP_REPLY, *PCSRSS_GET_CONSOLE_OUTPUT_CP_REPLY;
+
+typedef struct
+{
+  UINT CodePage;
+} CSRSS_SET_CONSOLE_OUTPUT_CP_REQUEST, *PCSRSS_SET_CONSOLE_OUTPUT_CP_REQUEST;
+
+typedef struct
+{
+} CSRSS_SET_CONSOLE_OUTPUT_CP_REPLY, *PCSRSS_SET_CONSOLE_OUTPUT_CP_REPLY;
+
 #define CSRSS_MAX_WRITE_CONSOLE_REQUEST       \
       (MAX_MESSAGE_DATA - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE_REQUEST))
 
@@ -618,6 +664,10 @@ typedef struct
 #define CSRSS_SET_CONSOLE_ICON              (0x2E)
 #define CSRSS_SET_LOGON_NOTIFY_WINDOW       (0x2F)
 #define CSRSS_REGISTER_LOGON_PROCESS        (0x30)
+#define CSRSS_GET_CONSOLE_CP                (0x31)
+#define CSRSS_SET_CONSOLE_CP                (0x32)
+#define CSRSS_GET_CONSOLE_OUTPUT_CP         (0x33)
+#define CSRSS_SET_CONSOLE_OUTPUT_CP         (0x34)
 
 /* Keep in sync with definition below. */
 #define CSRSS_REQUEST_HEADER_SIZE (LPC_MESSAGE_BASE_SIZE + sizeof(ULONG))
@@ -672,13 +722,17 @@ typedef struct
         CSRSS_VERIFY_HANDLE_REQUEST VerifyHandleRequest;
         CSRSS_DUPLICATE_HANDLE_REQUEST DuplicateHandleRequest;
         CSRSS_SETGET_CONSOLE_HW_STATE_REQUEST ConsoleHardwareStateRequest;
-        CSRSS_CONSOLE_WINDOW ConsoleWindowRequest;
+        CSRSS_GET_CONSOLE_WINDOW_REQUEST GetConsoleWindowRequest;
         CSRSS_CREATE_DESKTOP_REQUEST CreateDesktopRequest;
         CSRSS_SHOW_DESKTOP_REQUEST ShowDesktopRequest;
         CSRSS_HIDE_DESKTOP_REQUEST HideDesktopRequest;
-        CSRSS_CONSOLE_SET_WINDOW_ICON ConsoleSetWindowIconRequest;
+        CSRSS_SET_CONSOLE_ICON_REQUEST SetConsoleIconRequest;
         CSRSS_SET_LOGON_NOTIFY_WINDOW_REQUEST SetLogonNotifyWindowRequest;
         CSRSS_REGISTER_LOGON_PROCESS_REQUEST RegisterLogonProcessRequest;
+        CSRSS_GET_CONSOLE_CP_REQUEST GetConsoleCodePage;
+        CSRSS_SET_CONSOLE_CP_REQUEST SetConsoleCodePage;
+        CSRSS_GET_CONSOLE_OUTPUT_CP_REQUEST GetConsoleOutputCodePage;
+        CSRSS_SET_CONSOLE_OUTPUT_CP_REQUEST SetConsoleOutputCodePage;
       } Data;
     };
   };
@@ -721,13 +775,17 @@ typedef struct
         CSRSS_GET_OUTPUT_HANDLE_REPLY GetOutputHandleReply;
         CSRSS_DUPLICATE_HANDLE_REPLY DuplicateHandleReply;
         CSRSS_SETGET_CONSOLE_HW_STATE_REPLY ConsoleHardwareStateReply;
-        CSRSS_CONSOLE_WINDOW ConsoleWindowReply;
+        CSRSS_GET_CONSOLE_WINDOW_REPLY GetConsoleWindowReply;
         CSRSS_CREATE_DESKTOP_REPLY CreateDesktopReply;
         CSRSS_SHOW_DESKTOP_REPLY ShowDesktopReply;
         CSRSS_HIDE_DESKTOP_REPLY HideDesktopReply;
-        CSRSS_CONSOLE_SET_WINDOW_ICON ConsoleSetWindowIconReply;
+        CSRSS_SET_CONSOLE_ICON_REPLY SetConsoleIconReply;
         CSRSS_SET_LOGON_NOTIFY_WINDOW_REPLY SetLogonNotifyWindowReply;
         CSRSS_REGISTER_LOGON_PROCESS_REPLY RegisterLogonProcessReply;
+        CSRSS_GET_CONSOLE_CP_REPLY GetConsoleCodePage;
+        CSRSS_SET_CONSOLE_CP_REPLY SetConsoleCodePage;
+        CSRSS_GET_CONSOLE_OUTPUT_CP_REPLY GetConsoleOutputCodePage;
+        CSRSS_SET_CONSOLE_OUTPUT_CP_REPLY SetConsoleOutputCodePage;
       } Data;
     };
   };
index 3787132..240b00a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: console.c,v 1.76 2004/06/13 20:04:56 navaraf Exp $
+/* $Id: console.c,v 1.77 2004/08/22 20:52:28 navaraf Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -1394,22 +1394,24 @@ FillConsoleOutputCharacterW(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
 
 /*--------------------------------------------------------------
- *     PeekConsoleInputA
+ *     IntPeekConsoleInput
  *
- * @implemented
+ * INTERNAL
  */
 BOOL
 WINAPI
-PeekConsoleInputA(
+IntPeekConsoleInput(
        HANDLE                  hConsoleInput,
        PINPUT_RECORD           lpBuffer,
        DWORD                   nLength,
-       LPDWORD                 lpNumberOfEventsRead
+       LPDWORD                 lpNumberOfEventsRead,
+       BOOL                    bUnicode
        )
 {
   PCSRSS_API_REQUEST Request;
@@ -1444,6 +1446,7 @@ PeekConsoleInputA(
   
   Request->Type = CSRSS_PEEK_CONSOLE_INPUT;
   Request->Data.PeekConsoleInputRequest.ConsoleHandle = hConsoleInput;
+  Request->Data.PeekConsoleInputRequest.Unicode = bUnicode;
   Request->Data.PeekConsoleInputRequest.Length = nLength;
   Request->Data.PeekConsoleInputRequest.InputRecord = (INPUT_RECORD*)BufferTargetBase;
   
@@ -1464,14 +1467,32 @@ PeekConsoleInputA(
   RtlFreeHeap(GetProcessHeap(), 0, Request);
   CsrReleaseParameterBuffer(BufferBase);  
   
-       return TRUE;
+  return TRUE;
+}
+
+/*--------------------------------------------------------------
+ *     PeekConsoleInputA
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+PeekConsoleInputA(
+       HANDLE                  hConsoleInput,
+       PINPUT_RECORD           lpBuffer,
+       DWORD                   nLength,
+       LPDWORD                 lpNumberOfEventsRead
+       )
+{
+  return IntPeekConsoleInput(hConsoleInput, lpBuffer, nLength,
+                             lpNumberOfEventsRead, FALSE);
 }
 
 
 /*--------------------------------------------------------------
  *     PeekConsoleInputW
  *
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -1482,21 +1503,22 @@ PeekConsoleInputW(
        LPDWORD                 lpNumberOfEventsRead
        )    
 {
-/* TO DO */
-       return FALSE;
+  return IntPeekConsoleInput(hConsoleInput, lpBuffer, nLength,
+                             lpNumberOfEventsRead, TRUE);
 }
 
 
 /*--------------------------------------------------------------
- *     ReadConsoleInputA
+ *     IntReadConsoleInput
  *
- * @implemented
+ * INTERNAL
  */
 BOOL WINAPI
-ReadConsoleInputA(HANDLE hConsoleInput,
-                 PINPUT_RECORD lpBuffer,
-                 DWORD nLength,
-                 LPDWORD lpNumberOfEventsRead)
+IntReadConsoleInput(HANDLE hConsoleInput,
+                    PINPUT_RECORD lpBuffer,
+                    DWORD nLength,
+                    LPDWORD lpNumberOfEventsRead,
+                    BOOL bUnicode)
 {
   CSRSS_API_REQUEST Request;
   CSRSS_API_REPLY Reply;
@@ -1525,6 +1547,7 @@ ReadConsoleInputA(HANDLE hConsoleInput,
       
       Request.Type = CSRSS_READ_INPUT;
       Request.Data.ReadInputRequest.ConsoleHandle = hConsoleInput;
+      Request.Data.ReadInputRequest.Unicode = bUnicode;
       Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
                                   sizeof(CSRSS_API_REPLY));
       if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
@@ -1534,10 +1557,9 @@ ReadConsoleInputA(HANDLE hConsoleInput,
        }
     }
   
-  NumEventsRead = 0;
+  NumEventsRead = 1;
   *lpBuffer = Reply.Data.ReadInputReply.Input;
   lpBuffer++;
-  NumEventsRead++;
   
   while ((NumEventsRead < nLength) && (Reply.Data.ReadInputReply.MoreEvents))
     {
@@ -1565,10 +1587,26 @@ ReadConsoleInputA(HANDLE hConsoleInput,
 }
 
 
+/*--------------------------------------------------------------
+ *     ReadConsoleInputA
+ *
+ * @implemented
+ */
+BOOL WINAPI
+ReadConsoleInputA(HANDLE hConsoleInput,
+                 PINPUT_RECORD lpBuffer,
+                 DWORD nLength,
+                 LPDWORD lpNumberOfEventsRead)
+{
+  return IntReadConsoleInput(hConsoleInput, lpBuffer, nLength,
+                             lpNumberOfEventsRead, FALSE);
+}
+
+
 /*--------------------------------------------------------------
  *     ReadConsoleInputW
  *
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -1579,8 +1617,8 @@ ReadConsoleInputW(
        LPDWORD                 lpNumberOfEventsRead
        )
 {
-/* TO DO */
-       return FALSE;
+  return IntReadConsoleInput(hConsoleInput, lpBuffer, nLength,
+                             lpNumberOfEventsRead, TRUE);
 }
 
 
@@ -1665,23 +1703,25 @@ WriteConsoleInputW(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
 
 /*--------------------------------------------------------------
- *     ReadConsoleOutputA
+ *     IntReadConsoleOutput
  *
- * @implemented
+ * INTERNAL
  */
 BOOL
 WINAPI
-ReadConsoleOutputA(
-       HANDLE          hConsoleOutput,
-       PCHAR_INFO      lpBuffer,
-       COORD           dwBufferSize,
-       COORD           dwBufferCoord,
-       PSMALL_RECT     lpReadRegion
+IntReadConsoleOutput(
+       HANDLE          hConsoleOutput,
+       PCHAR_INFO      lpBuffer,
+       COORD           dwBufferSize,
+       COORD           dwBufferCoord,
+       PSMALL_RECT     lpReadRegion,
+       BOOL            bUnicode
        )
 {
   PCSRSS_API_REQUEST Request;
@@ -1716,6 +1756,7 @@ ReadConsoleOutputA(
    
   Request->Type = CSRSS_READ_CONSOLE_OUTPUT;
   Request->Data.ReadConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
+  Request->Data.ReadConsoleOutputRequest.Unicode = bUnicode;
   Request->Data.ReadConsoleOutputRequest.BufferSize = dwBufferSize;
   Request->Data.ReadConsoleOutputRequest.BufferCoord = dwBufferCoord;
   Request->Data.ReadConsoleOutputRequest.ReadRegion = *lpReadRegion;
@@ -1742,11 +1783,30 @@ ReadConsoleOutputA(
   return TRUE;
 }
 
+/*--------------------------------------------------------------
+ *     ReadConsoleOutputA
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+ReadConsoleOutputA(
+       HANDLE          hConsoleOutput,
+       PCHAR_INFO      lpBuffer,
+       COORD           dwBufferSize,
+       COORD           dwBufferCoord,
+       PSMALL_RECT     lpReadRegion
+       )
+{
+  return IntReadConsoleOutput(hConsoleOutput, lpBuffer, dwBufferSize,
+                             dwBufferCoord, lpReadRegion, FALSE);
+}
+
 
 /*--------------------------------------------------------------
  *     ReadConsoleOutputW
  *
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -1758,21 +1818,23 @@ ReadConsoleOutputW(
        PSMALL_RECT     lpReadRegion
        )
 {
-/* TO DO */
-       return FALSE;
+  return IntReadConsoleOutput(hConsoleOutput, lpBuffer, dwBufferSize,
+                             dwBufferCoord, lpReadRegion, TRUE);
 }
 
+
 /*--------------------------------------------------------------
- *     WriteConsoleOutputA
+ *     IntWriteConsoleOutput
  *
- * @implemented
+ * INTERNAL
  */
 BOOL WINAPI
-WriteConsoleOutputA(HANDLE              hConsoleOutput,
-                   CONST CHAR_INFO     *lpBuffer,
-                   COORD                dwBufferSize,
-                   COORD                dwBufferCoord,
-                   PSMALL_RECT  lpWriteRegion)
+IntWriteConsoleOutput(HANDLE           hConsoleOutput,
+                      CONST CHAR_INFO *lpBuffer,
+                      COORD            dwBufferSize,
+                      COORD            dwBufferCoord,
+                      PSMALL_RECT      lpWriteRegion,
+                      BOOL             bUnicode)
 {
   PCSRSS_API_REQUEST Request;
   CSRSS_API_REPLY Reply;
@@ -1803,6 +1865,7 @@ WriteConsoleOutputA(HANDLE                 hConsoleOutput,
     }
   Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT;
   Request->Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
+  Request->Data.WriteConsoleOutputRequest.Unicode = bUnicode;
   Request->Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
   Request->Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
   Request->Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
@@ -1826,11 +1889,27 @@ WriteConsoleOutputA(HANDLE               hConsoleOutput,
   return(TRUE);
 }
 
+/*--------------------------------------------------------------
+ *     WriteConsoleOutputA
+ *
+ * @implemented
+ */
+BOOL WINAPI
+WriteConsoleOutputA(HANDLE              hConsoleOutput,
+                   CONST CHAR_INFO     *lpBuffer,
+                   COORD                dwBufferSize,
+                   COORD                dwBufferCoord,
+                   PSMALL_RECT  lpWriteRegion)
+{
+  return IntWriteConsoleOutput(hConsoleOutput, lpBuffer, dwBufferSize,
+                               dwBufferCoord, lpWriteRegion, FALSE);
+}
+
 
 /*--------------------------------------------------------------
  *     WriteConsoleOutputW
  *
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -1842,8 +1921,8 @@ WriteConsoleOutputW(
        PSMALL_RECT      lpWriteRegion
        )
 {
-/* TO DO */
-       return FALSE;
+  return IntWriteConsoleOutput(hConsoleOutput, lpBuffer, dwBufferSize,
+                               dwBufferCoord, lpWriteRegion, TRUE);
 }
 
 
@@ -1931,6 +2010,7 @@ ReadConsoleOutputCharacterW(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
@@ -2443,6 +2523,7 @@ SetConsoleScreenBufferSize(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
@@ -2538,6 +2619,7 @@ ScrollConsoleScreenBufferW(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
@@ -2556,6 +2638,7 @@ SetConsoleWindowInfo(
        )
 {
 /* TO DO */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
@@ -2923,6 +3006,7 @@ ReadConsoleW(
        )
 {
 /* --- TO DO --- */
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
        return FALSE;
 }
 
@@ -2942,6 +3026,7 @@ WriteConsoleW(
        LPVOID           lpReserved
        )
 {
+       DbgPrint("%s unimplemented\n", __FUNCTION__);
 #if 0
   PCSRSS_API_REQUEST Request;
   CSRSS_API_REPLY Reply;
@@ -3026,14 +3111,25 @@ CreateConsoleScreenBuffer(
 /*--------------------------------------------------------------
  *     GetConsoleCP
  *
- * @unimplemented
+ * @implemented
  */
 UINT
 WINAPI
 GetConsoleCP( VOID )
 {
-/* --- TO DO --- */
-       return CP_OEMCP; /* FIXME */
+  CSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY   Reply;
+  NTSTATUS          Status;
+   
+  Request.Type = CSRSS_GET_CONSOLE_CP;
+  Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
+                               sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+  {
+    SetLastErrorByStatus (Status);
+    return 0;
+  }
+  return Reply.Data.GetConsoleCodePage.CodePage;
 }
 
 
@@ -3048,29 +3144,51 @@ SetConsoleCP(
        UINT            wCodePageID
        )
 {
-/* --- TO DO --- */
-       return FALSE;
+  CSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY   Reply;
+  NTSTATUS          Status;
+   
+  Request.Type = CSRSS_SET_CONSOLE_CP;
+  Request.Data.SetConsoleCodePage.CodePage = wCodePageID;
+  Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
+                               sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+  {
+    SetLastErrorByStatus (Status);
+  }
+  return NT_SUCCESS(Status);
 }
 
 
 /*--------------------------------------------------------------
  *     GetConsoleOutputCP
  *
- * @unimplemented
+ * @implemented
  */
 UINT
 WINAPI
 GetConsoleOutputCP( VOID )
 {
-/* --- TO DO --- */
-       return 0; /* FIXME */
+  CSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY   Reply;
+  NTSTATUS          Status;
+   
+  Request.Type = CSRSS_GET_CONSOLE_OUTPUT_CP;
+  Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
+                               sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+  {
+    SetLastErrorByStatus (Status);
+    return 0;
+  }
+  return Reply.Data.GetConsoleOutputCodePage.CodePage;
 }
 
 
 /*--------------------------------------------------------------
  *     SetConsoleOutputCP
  *
- * @unimplemented
+ * @implemented
  */
 BOOL
 WINAPI
@@ -3078,8 +3196,19 @@ SetConsoleOutputCP(
        UINT            wCodePageID
        )
 {
-/* --- TO DO --- */
-       return FALSE;
+  CSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY   Reply;
+  NTSTATUS          Status;
+   
+  Request.Type = CSRSS_SET_CONSOLE_OUTPUT_CP;
+  Request.Data.SetConsoleOutputCodePage.CodePage = wCodePageID;
+  Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
+                               sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+  {
+    SetLastErrorByStatus (Status);
+  }
+  return NT_SUCCESS(Status);
 }
 
 
@@ -3136,12 +3265,6 @@ GetConsoleWindow (VOID)
   CSRSS_API_REPLY   Reply;
   NTSTATUS          Status;
    
-  Request.Data.ConsoleWindowRequest.ConsoleHandle =
-    OpenConsoleW (L"CONOUT$", (GENERIC_READ|GENERIC_WRITE), FALSE, OPEN_EXISTING);
-  if (INVALID_HANDLE_VALUE == Request.Data.ConsoleWindowRequest.ConsoleHandle)
-  {
-    return (HWND) NULL;
-  }
   Request.Type = CSRSS_GET_CONSOLE_WINDOW;
   Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
   if (!NT_SUCCESS(Status ) || !NT_SUCCESS(Status = Reply.Status))
@@ -3149,12 +3272,13 @@ GetConsoleWindow (VOID)
     SetLastErrorByStatus (Status);
     return (HWND) NULL;
   }
-  return Reply.Data.ConsoleWindowReply.WindowHandle;
+  return Reply.Data.GetConsoleWindowReply.WindowHandle;
 }
 
 
 /*--------------------------------------------------------------
- *     GetConsoleWindow
+ *     SetConsoleIcon
+ *
  * @implemented
  */
 BOOL STDCALL SetConsoleIcon(HICON hicon)
@@ -3163,14 +3287,8 @@ BOOL STDCALL SetConsoleIcon(HICON hicon)
   CSRSS_API_REPLY   Reply;
   NTSTATUS          Status;
   
-  Request.Data.ConsoleSetWindowIconRequest.ConsoleHandle =
-    OpenConsoleW (L"CONOUT$", (GENERIC_READ|GENERIC_WRITE), FALSE, OPEN_EXISTING);
-  if (INVALID_HANDLE_VALUE == Request.Data.ConsoleSetWindowIconRequest.ConsoleHandle)
-  {
-    return FALSE;
-  }
   Request.Type = CSRSS_SET_CONSOLE_ICON;
-  Request.Data.ConsoleSetWindowIconRequest.WindowIcon = hicon;
+  Request.Data.SetConsoleIconRequest.WindowIcon = hicon;
   Status = CsrClientCallServer( &Request, &Reply, sizeof( CSRSS_API_REQUEST ), sizeof( CSRSS_API_REPLY ) );
   if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
   {
index 865ad61..0db85ce 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: conio.h,v 1.3 2004/03/14 17:53:27 weiden Exp $
+/* $Id: conio.h,v 1.4 2004/08/22 20:52:28 navaraf Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -84,6 +84,8 @@ typedef struct tagCSRSS_CONSOLE
   HICON hWindowIcon;
   COORD Size;
   PVOID PrivateData;
+  UINT CodePage;
+  UINT OutputCodePage;
   PCSRSS_CONSOLE_VTBL Vtbl;
   LIST_ENTRY ProcessList;
 } CSRSS_CONSOLE;
@@ -132,6 +134,10 @@ CSR_API(CsrWriteConsoleInput);
 CSR_API(CsrHardwareStateProperty);
 CSR_API(CsrGetConsoleWindow);
 CSR_API(CsrSetConsoleIcon);
+CSR_API(CsrGetConsoleCodePage);
+CSR_API(CsrSetConsoleCodePage);
+CSR_API(CsrGetConsoleOutputCodePage);
+CSR_API(CsrSetConsoleOutputCodePage);
 
 #define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
 #define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
index 70df7e1..cc8e8da 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: conio.c,v 1.11 2004/07/04 17:22:33 navaraf Exp $
+/* $Id: conio.c,v 1.12 2004/08/22 20:52:28 navaraf Exp $
  *
  * reactos/subsys/csrss/win32csr/conio.c
  *
@@ -68,7 +68,7 @@ CsrConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData)
 {
   HANDLE Process, Thread;
        
-  DPRINT("CsrConsoleCtrlEvent Parent ProcessId = %x\n",        ClientId.UniqueProcess);
+  DPRINT("CsrConsoleCtrlEvent Parent ProcessId = %x\n",        ProcessData->ProcessId);
 
   if (ProcessData->CtrlDispatcher)
     {
@@ -96,11 +96,11 @@ CsrConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData)
 }
 
 #define GET_CELL_BUFFER(b,o)\
-(b)->Buffer[(o)++];
+(b)->Buffer[(o)++]
 
 #define SET_CELL_BUFFER(b,o,c,a)\
-(b)->Buffer[(o)++]=(c);\
-(b)->Buffer[(o)++]=(a);
+(b)->Buffer[(o)++]=(c),\
+(b)->Buffer[(o)++]=(a)
 
 static VOID FASTCALL
 ClearLineBuffer(PCSRSS_SCREEN_BUFFER Buff)
@@ -111,7 +111,7 @@ ClearLineBuffer(PCSRSS_SCREEN_BUFFER Buff)
   for (Pos = 0; Pos < Buff->MaxX; Pos++)
     {
       /* Fill the cell: Offset is incremented by the macro */
-      SET_CELL_BUFFER(Buff, Offset, ' ', Buff->DefaultAttrib)
+      SET_CELL_BUFFER(Buff, Offset, ' ', Buff->DefaultAttrib);
     }
 }
 
@@ -170,6 +170,9 @@ CsrInitConsole(PCSRSS_CONSOLE Console)
   InitializeListHead(&Console->InputEvents);
   InitializeListHead(&Console->ProcessList);
 
+  Console->CodePage = CP_OEMCP;
+  Console->OutputCodePage = CP_OEMCP;
+
   SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
   SecurityAttributes.lpSecurityDescriptor = NULL;
   SecurityAttributes.bInheritHandle = TRUE;
@@ -832,6 +835,18 @@ ConioFillRegion(PCSRSS_SCREEN_BUFFER ScreenBuffer,
     }
 }
 
+STATIC VOID FASTCALL
+ConioInputEventToAnsi(PCSRSS_CONSOLE Console, PINPUT_RECORD InputEvent)
+{
+  if (InputEvent->EventType == KEY_EVENT)
+    {
+      WideCharToMultiByte(Console->CodePage, 0,
+                          &InputEvent->Event.KeyEvent.uChar.UnicodeChar, 1,
+                          &InputEvent->Event.KeyEvent.uChar.AsciiChar, 1,
+                          NULL, NULL);
+    }
+}
+
 CSR_API(CsrWriteConsole)
 {
   NTSTATUS Status;
@@ -1200,14 +1215,6 @@ ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode)
       UnicodeChar = (1 == RetChars ? Chars[0] : 0);
     }
 
-  if (UnicodeChar)
-    {
-      RtlUnicodeToOemN(&AsciiChar,
-                       1,
-                       &ResultSize,
-                       &UnicodeChar,
-                       sizeof(WCHAR));
-    }
   if (0 == ResultSize)
     {
       AsciiChar = 0;
@@ -1216,7 +1223,7 @@ ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode)
   er.EventType = KEY_EVENT;
   er.Event.KeyEvent.bKeyDown = Down;
   er.Event.KeyEvent.wRepeatCount = RepeatCount;
-  er.Event.KeyEvent.uChar.UnicodeChar = AsciiChar & 0xff;
+  er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar;
   er.Event.KeyEvent.dwControlKeyState = ShiftState;
   er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode;
   er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode;
@@ -1255,7 +1262,7 @@ ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode)
     }
     
   ConInRec->InputEvent = er;
-  ConInRec->Fake = AsciiChar && 
+  ConInRec->Fake = UnicodeChar && 
     (msg->message != WM_CHAR && msg->message != WM_SYSCHAR &&
      msg->message != WM_KEYUP && msg->message != WM_SYSKEYUP);
   ConInRec->NotChar = (msg->message != WM_CHAR && msg->message != WM_SYSCHAR);
@@ -1599,6 +1606,11 @@ CSR_API(CsrReadInputEvent)
       Done = !Input->Fake;
       Reply->Data.ReadInputReply.Input = Input->InputEvent;
 
+      if (Request->Data.ReadInputRequest.Unicode == FALSE)
+        {
+          ConioInputEventToAnsi(Console, &Reply->Data.ReadInputReply.Input);
+        }
+
       if (Input->InputEvent.EventType == KEY_EVENT)
         {
           if (0 != (Console->Mode & ENABLE_LINE_INPUT)
@@ -2228,7 +2240,18 @@ CSR_API(CsrWriteConsoleOutput)
       Offset = (((Y + Buff->ShowY) % Buff->MaxY) * Buff->MaxX + WriteRegion.left) * 2;
       for (X = WriteRegion.left; X <= WriteRegion.right; X++)
         {
-          SET_CELL_BUFFER(Buff, Offset, CurCharInfo->Char.AsciiChar, CurCharInfo->Attributes);
+          if (Request->Data.WriteConsoleOutputRequest.Unicode)
+            {
+              CHAR AsciiChar;
+              WideCharToMultiByte(Console->OutputCodePage, 0,
+                                  &CurCharInfo->Char.UnicodeChar, 1,
+                                  &AsciiChar, 1, NULL, NULL);
+              SET_CELL_BUFFER(Buff, Offset, AsciiChar, CurCharInfo->Attributes);
+            }
+          else
+            {
+              SET_CELL_BUFFER(Buff, Offset, CurCharInfo->Char.AsciiChar, CurCharInfo->Attributes);
+            }
           CurCharInfo++;
         }
     }
@@ -2587,22 +2610,28 @@ CSR_API(CsrPeekConsoleInput)
    
   if (! IsListEmpty(&Console->InputEvents))
     {
-      CurrentItem = &Console->InputEvents;
+      CurrentItem = Console->InputEvents.Flink;
    
-      while (NumItems < Length)
+      while (CurrentItem != &Console->InputEvents && NumItems < Length)
         {
-          ++NumItems;
           Item = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry);
-          *InputRecord++ = Item->InputEvent;
-         
-          if (CurrentItem->Flink == &Console->InputEvents)
+
+          if (Item->Fake)
             {
-              break;
+              CurrentItem = CurrentItem->Flink;
+              continue;
             }
-          else
+          
+          ++NumItems;
+          *InputRecord = Item->InputEvent;
+
+          if (Request->Data.ReadInputRequest.Unicode == FALSE)
             {
-              CurrentItem = CurrentItem->Flink;
+              ConioInputEventToAnsi(Console, InputRecord);
             }
+         
+          InputRecord++;
+          CurrentItem = CurrentItem->Flink;
         }
     }
 
@@ -2629,6 +2658,7 @@ CSR_API(CsrReadConsoleOutput)
   RECT ReadRegion;
   RECT ScreenRect;
   DWORD i, Y, X, Offset;
+  UINT CodePage;
       
   DPRINT("CsrReadConsoleOutput\n");
 
@@ -2650,6 +2680,9 @@ CSR_API(CsrReadConsoleOutput)
   BufferCoord = Request->Data.ReadConsoleOutputRequest.BufferCoord;
   Length = BufferSize.X * BufferSize.Y;
   Size = Length * sizeof(CHAR_INFO);
+
+  /* FIXME: Is this correct? */
+  CodePage = ProcessData->Console->OutputCodePage;
    
   if (((PVOID)CharInfo < ProcessData->CsrSectionViewBase)
       || (((PVOID)CharInfo + Size) > (ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize)))
@@ -2679,7 +2712,16 @@ CSR_API(CsrReadConsoleOutput)
       Offset = (((Y + Buff->ShowY) % Buff->MaxY) * Buff->MaxX + ReadRegion.left) * 2;
       for (X = ReadRegion.left; X < ReadRegion.right; ++X)
         {
-          CurCharInfo->Char.AsciiChar = GET_CELL_BUFFER(Buff, Offset);
+          if (Request->Data.ReadConsoleOutputRequest.Unicode)
+            {
+              MultiByteToWideChar(CodePage, 0,
+                                  &GET_CELL_BUFFER(Buff, Offset), 1,
+                                  &CurCharInfo->Char.UnicodeChar, 1);
+            }
+          else
+            {
+              CurCharInfo->Char.AsciiChar = GET_CELL_BUFFER(Buff, Offset);
+            }
           CurCharInfo->Attributes = GET_CELL_BUFFER(Buff, Offset);
           ++CurCharInfo;
         }
@@ -2842,15 +2884,13 @@ CSR_API(CsrGetConsoleWindow)
   Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
   Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
    
-  Status = ConioLockConsole(ProcessData,
-                            Request->Data.ConsoleWindowRequest.ConsoleHandle,
-                            &Console);
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
   if (! NT_SUCCESS(Status))
     {
       return Reply->Status = Status;
     }
 
-  Reply->Data.ConsoleWindowReply.WindowHandle = Console->hWindow;
+  Reply->Data.GetConsoleWindowReply.WindowHandle = Console->hWindow;
   ConioUnlockConsole(Console);
 
   return Reply->Status = STATUS_SUCCESS;
@@ -2866,21 +2906,107 @@ CSR_API(CsrSetConsoleIcon)
   Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
   Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
    
-  Status = ConioLockConsole(ProcessData,
-                            Request->Data.ConsoleSetWindowIconRequest.ConsoleHandle,
-                            &Console);
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
   if (! NT_SUCCESS(Status))
     {
       return Reply->Status = Status;
     }
 
-  Console->hWindowIcon = Request->Data.ConsoleSetWindowIconRequest.WindowIcon;
+  Console->hWindowIcon = Request->Data.SetConsoleIconRequest.WindowIcon;
   Reply->Status = (ConioChangeIcon(Console) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
-  Reply->Data.ConsoleSetWindowIconReply.WindowIcon = Console->hWindowIcon;
-  
   ConioUnlockConsole(Console);
 
   return Reply->Status;
 }
 
+CSR_API(CsrGetConsoleCodePage)
+{
+  PCSRSS_CONSOLE Console;
+  NTSTATUS Status;
+
+  DPRINT("CsrGetConsoleCodePage\n");
+
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
+  if (! NT_SUCCESS(Status))
+    {
+      return Reply->Status = Status;
+    }
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
+  Reply->Data.GetConsoleCodePage.CodePage = Console->CodePage;
+  ConioUnlockConsole(Console);
+  return Reply->Status = STATUS_SUCCESS;
+}
+
+CSR_API(CsrSetConsoleCodePage)
+{
+  PCSRSS_CONSOLE Console;
+  NTSTATUS Status;
+
+  DPRINT("CsrSetConsoleCodePage\n");
+
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
+  if (! NT_SUCCESS(Status))
+    {
+      return Reply->Status = Status;
+    }
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
+  if (IsValidCodePage(Request->Data.SetConsoleCodePage.CodePage))
+    {
+      Console->CodePage = Request->Data.SetConsoleCodePage.CodePage;
+      ConioUnlockConsole(Console);
+      return Reply->Status = STATUS_SUCCESS;
+    }
+  ConioUnlockConsole(Console);
+  return Reply->Status = STATUS_UNSUCCESSFUL;
+}
+
+CSR_API(CsrGetConsoleOutputCodePage)
+{
+  PCSRSS_CONSOLE Console;
+  NTSTATUS Status;
+
+  DPRINT("CsrGetConsoleOutputCodePage\n");
+
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
+  if (! NT_SUCCESS(Status))
+    {
+      return Reply->Status = Status;
+    }
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
+  Reply->Data.GetConsoleOutputCodePage.CodePage = Console->OutputCodePage;
+  ConioUnlockConsole(Console);
+  return Reply->Status = STATUS_SUCCESS;
+}
+
+CSR_API(CsrSetConsoleOutputCodePage)
+{
+  PCSRSS_CONSOLE Console;
+  NTSTATUS Status;
+
+  DPRINT("CsrSetConsoleOutputCodePage\n");
+
+  Status = ConioConsoleFromProcessData(ProcessData, &Console);
+  if (! NT_SUCCESS(Status))
+    {
+      return Reply->Status = Status;
+    }
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
+  if (IsValidCodePage(Request->Data.SetConsoleOutputCodePage.CodePage))
+    {
+      Console->OutputCodePage = Request->Data.SetConsoleOutputCodePage.CodePage;
+      ConioUnlockConsole(Console);
+      return Reply->Status = STATUS_SUCCESS;
+    }
+  ConioUnlockConsole(Console);
+  return Reply->Status = STATUS_UNSUCCESSFUL;
+}
+
 /* EOF */
index a084b5b..758cbdb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dllmain.c,v 1.6 2004/07/12 20:09:34 gvg Exp $
+/* $Id: dllmain.c,v 1.7 2004/08/22 20:52:28 navaraf Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -60,11 +60,17 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] =
     CSRSS_DEFINE_API(CSRSS_READ_CONSOLE_OUTPUT,          CsrReadConsoleOutput),
     CSRSS_DEFINE_API(CSRSS_WRITE_CONSOLE_INPUT,          CsrWriteConsoleInput),
     CSRSS_DEFINE_API(CSRSS_SETGET_CONSOLE_HW_STATE,      CsrHardwareStateProperty),
+    CSRSS_DEFINE_API(CSRSS_GET_CONSOLE_WINDOW,           CsrGetConsoleWindow),
     CSRSS_DEFINE_API(CSRSS_CREATE_DESKTOP,               CsrCreateDesktop),
     CSRSS_DEFINE_API(CSRSS_SHOW_DESKTOP,                 CsrShowDesktop),
     CSRSS_DEFINE_API(CSRSS_HIDE_DESKTOP,                 CsrHideDesktop),
+    CSRSS_DEFINE_API(CSRSS_SET_CONSOLE_ICON,             CsrSetConsoleIcon),
     CSRSS_DEFINE_API(CSRSS_SET_LOGON_NOTIFY_WINDOW,      CsrSetLogonNotifyWindow),
     CSRSS_DEFINE_API(CSRSS_REGISTER_LOGON_PROCESS,       CsrRegisterLogonProcess),
+    CSRSS_DEFINE_API(CSRSS_GET_CONSOLE_CP,               CsrGetConsoleCodePage),
+    CSRSS_DEFINE_API(CSRSS_SET_CONSOLE_CP,               CsrSetConsoleCodePage),
+    CSRSS_DEFINE_API(CSRSS_GET_CONSOLE_OUTPUT_CP,        CsrGetConsoleOutputCodePage),
+    CSRSS_DEFINE_API(CSRSS_SET_CONSOLE_OUTPUT_CP,        CsrSetConsoleOutputCodePage),
     { 0, 0, 0, NULL }
   };