[CONSRV] Use NtClearEvent() and NtClose() instead of the Win32 functions.
[reactos.git] / win32ss / user / winsrv / consrv / condrv / console.c
index 4075e76..e763a81 100644 (file)
@@ -6,24 +6,24 @@
  * PROGRAMMERS:     Gé van Geldorp
  *                  Jeffrey Morlan
  *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
+ *                  Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
  */
 
 /* INCLUDES *******************************************************************/
 
 #include <consrv.h>
-
 #include <coninput.h>
+#include "../../concfg/font.h"
 
 #define NDEBUG
 #include <debug.h>
 
-
 /* GLOBALS ********************************************************************/
 
 static ULONG CurrentConsoleID = 0;
 
 /* Linked list of consoles */
-static LIST_ENTRY ConsoleList;
+static LIST_ENTRY ConDrvConsoleList;
 static RTL_RESOURCE ListLock;
 
 #define ConDrvLockConsoleListExclusive()    \
@@ -37,15 +37,15 @@ static RTL_RESOURCE ListLock;
 
 
 static NTSTATUS
-InsertConsole(IN PCONSOLE Console)
+ConDrvInsertConsole(IN PCONSOLE Console)
 {
     ASSERT(Console);
 
     /* All went right, so add the console to the list */
     ConDrvLockConsoleListExclusive();
 
-    DPRINT1("Insert in the list\n");
-    InsertTailList(&ConsoleList, &Console->ListEntry);
+    DPRINT("Insert in the list\n");
+    InsertTailList(&ConDrvConsoleList, &Console->ListEntry);
 
     // FIXME: Move this code to the caller function!!
     /* Get a new console ID */
@@ -79,19 +79,24 @@ RemoveConsole(IN PCONSOLE Console)
 VOID NTAPI
 ConDrvPause(PCONSOLE Console)
 {
-    if (!Console->UnpauseEvent)
-        Console->UnpauseEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+    /* In case we already have a pause event, just exit... */
+    if (Console->UnpauseEvent) return;
+
+    /* ... otherwise create it */
+    NtCreateEvent(&Console->UnpauseEvent, EVENT_ALL_ACCESS,
+                  NULL, NotificationEvent, FALSE);
 }
 
 VOID NTAPI
 ConDrvUnpause(PCONSOLE Console)
 {
-    if (Console->UnpauseEvent)
-    {
-        SetEvent(Console->UnpauseEvent);
-        CloseHandle(Console->UnpauseEvent);
-        Console->UnpauseEvent = NULL;
-    }
+    /* In case we already freed the event, just exit... */
+    if (!Console->UnpauseEvent) return;
+
+    /* ... otherwise set and free it */
+    NtSetEvent(Console->UnpauseEvent, NULL);
+    NtClose(Console->UnpauseEvent);
+    Console->UnpauseEvent = NULL;
 }
 
 
@@ -147,10 +152,8 @@ ConDrvInitConsoleSupport(VOID)
     DPRINT("CONSRV: ConDrvInitConsoleSupport()\n");
 
     /* Initialize the console list and its lock */
-    InitializeListHead(&ConsoleList);
+    InitializeListHead(&ConDrvConsoleList);
     RtlInitializeResource(&ListLock);
-
-    /* Should call LoadKeyboardLayout */
 }
 
 /* For resetting the terminal - defined in dummyterm.c */
@@ -182,9 +185,11 @@ ConDrvInitConsole(OUT PCONSOLE* NewConsole,
     }
 
     /*
-     * Fix the screen buffer size if needed. The rule is:
-     * ScreenBufferSize >= ConsoleSize
+     * Set and fix the screen buffer size if needed.
+     * The rule is: ScreenBufferSize >= ConsoleSize
      */
+    if (ConsoleInfo->ScreenBufferSize.X == 0) ConsoleInfo->ScreenBufferSize.X = 1;
+    if (ConsoleInfo->ScreenBufferSize.Y == 0) ConsoleInfo->ScreenBufferSize.Y = 1;
     if (ConsoleInfo->ScreenBufferSize.X < ConsoleInfo->ConsoleSize.X)
         ConsoleInfo->ScreenBufferSize.X = ConsoleInfo->ConsoleSize.X;
     if (ConsoleInfo->ScreenBufferSize.Y < ConsoleInfo->ConsoleSize.Y)
@@ -214,18 +219,23 @@ ConDrvInitConsole(OUT PCONSOLE* NewConsole,
     }
 
     /* Set-up the code page */
-    Console->InputCodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
+    if (IsValidCodePage(ConsoleInfo->CodePage))
+        Console->InputCodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
+
+    Console->IsCJK = IsCJKCodePage(Console->OutputCodePage);
 
     /* Initialize a new text-mode screen buffer with default settings */
     ScreenBufferInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
+    ScreenBufferInfo.ViewSize         = ConsoleInfo->ConsoleSize;
     ScreenBufferInfo.ScreenAttrib     = ConsoleInfo->ScreenAttrib;
     ScreenBufferInfo.PopupAttrib      = ConsoleInfo->PopupAttrib;
-    ScreenBufferInfo.IsCursorVisible  = TRUE;
     ScreenBufferInfo.CursorSize       = ConsoleInfo->CursorSize;
+    ScreenBufferInfo.IsCursorVisible  = TRUE;
 
     InitializeListHead(&Console->BufferList);
     Status = ConDrvCreateScreenBuffer(&NewBuffer,
                                       Console,
+                                      NULL,
                                       CONSOLE_TEXTMODE_BUFFER,
                                       &ScreenBufferInfo);
     if (!NT_SUCCESS(Status))
@@ -243,7 +253,7 @@ ConDrvInitConsole(OUT PCONSOLE* NewConsole,
     DPRINT("Console initialized\n");
 
     /* All went right, so add the console to the list */
-    Status = InsertConsole(Console);
+    Status = ConDrvInsertConsole(Console);
     if (!NT_SUCCESS(Status))
     {
         /* Fail */
@@ -261,8 +271,8 @@ ConDrvInitConsole(OUT PCONSOLE* NewConsole,
 }
 
 NTSTATUS NTAPI
-ConDrvRegisterTerminal(IN PCONSOLE Console,
-                       IN PTERMINAL Terminal)
+ConDrvAttachTerminal(IN PCONSOLE Console,
+                     IN PTERMINAL Terminal)
 {
     NTSTATUS Status;
 
@@ -288,21 +298,18 @@ ConDrvRegisterTerminal(IN PCONSOLE Console,
         /* We failed, detach the terminal from the console */
         Terminal->Console = NULL; // For the caller
         ResetTerminal(Console);
-
         return Status;
     }
 
     /* Copy buffer contents to screen */
     // Terminal.Draw();
-    // ConioDrawConsole(Console);
-    DPRINT("Console drawn\n");
 
     DPRINT("Terminal initialization done\n");
     return STATUS_SUCCESS;
 }
 
 NTSTATUS NTAPI
-ConDrvDeregisterTerminal(IN PCONSOLE Console)
+ConDrvDetachTerminal(IN PCONSOLE Console)
 {
     if (Console == NULL) return STATUS_INVALID_PARAMETER;
 
@@ -362,11 +369,9 @@ ConDrvDeleteConsole(IN PCONSOLE Console)
     LeaveCriticalSection(&Console->Lock);
     ConDrvUnlockConsoleList();
 
-    /* FIXME: Send a terminate message to all the processes owning this console */
-
     /* Deregister the terminal */
     DPRINT("Deregister terminal\n");
-    ConDrvDeregisterTerminal(Console);
+    ConDrvDetachTerminal(Console);
     DPRINT("Terminal deregistered\n");
 
     /***
@@ -404,7 +409,7 @@ ConDrvDeleteConsole(IN PCONSOLE Console)
     /* Deinitialize the input buffer */
     ConDrvDeinitInputBuffer(Console);
 
-    if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
+    if (Console->UnpauseEvent) NtClose(Console->UnpauseEvent);
 
     DPRINT("ConDrvDeleteConsole - Unlocking\n");
     LeaveCriticalSection(&Console->Lock);
@@ -531,9 +536,14 @@ ConDrvSetConsoleCP(IN PCONSOLE Console,
         return STATUS_INVALID_PARAMETER;
 
     if (OutputCP)
+    {
         Console->OutputCodePage = CodePage;
+        Console->IsCJK = IsCJKCodePage(CodePage);
+    }
     else
+    {
         Console->InputCodePage = CodePage;
+    }
 
     return STATUS_SUCCESS;
 }