[KERNEL32][CONSRV]
[reactos.git] / reactos / win32ss / user / winsrv / consrv / conoutput.c
index af3325a..e8c55c7 100644 (file)
@@ -12,7 +12,7 @@
 #include "consrv.h"
 #include "console.h"
 #include "include/conio.h"
-#include "include/conio2.h"
+#include "include/term.h"
 #include "conoutput.h"
 #include "handle.h"
 
@@ -52,25 +52,44 @@ CSR_API(SrvInvalidateBitMapRect)
 
 NTSTATUS NTAPI
 ConDrvSetConsolePalette(IN PCONSOLE Console,
-                        IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        // IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        IN PCONSOLE_SCREEN_BUFFER Buffer,
                         IN HPALETTE PaletteHandle,
-                        IN UINT Usage);
+                        IN UINT PaletteUsage);
 CSR_API(SrvSetConsolePalette)
 {
     NTSTATUS Status;
     PCONSOLE_SETPALETTE SetPaletteRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetPaletteRequest;
-    // PCONSOLE_SCREEN_BUFFER Buffer;
-    PGRAPHICS_SCREEN_BUFFER Buffer;
+    // PGRAPHICS_SCREEN_BUFFER Buffer;
+    PCONSOLE_SCREEN_BUFFER Buffer;
 
     DPRINT("SrvSetConsolePalette\n");
 
     // NOTE: Tests show that this function is used only for graphics screen buffers
-    // and otherwise it returns false + sets last error to invalid handle.
+    // and otherwise it returns FALSE + sets last error to invalid handle.
+    // I think it's ridiculous, because if you are in text mode, simulating
+    // a change of VGA palette via DAC registers (done by a call to SetConsolePalette)
+    // cannot be done... So I allow it in ReactOS !
+    /*
     Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                      SetPaletteRequest->OutputHandle,
                                      &Buffer, GENERIC_WRITE, TRUE);
+    */
+    Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
+                                   SetPaletteRequest->OutputHandle,
+                                   &Buffer, GENERIC_WRITE, TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
+    /*
+     * Make the palette handle public, so that it can be
+     * used by other threads calling GDI functions on it.
+     * Indeed, the palette handle comes from a console app
+     * calling ourselves, running in CSRSS.
+     */
+    NtUserConsoleControl(ConsoleMakePalettePublic,
+                         &SetPaletteRequest->PaletteHandle,
+                         sizeof(SetPaletteRequest->PaletteHandle));
+
     Status = ConDrvSetConsolePalette(Buffer->Header.Console,
                                      Buffer,
                                      SetPaletteRequest->PaletteHandle,
@@ -304,10 +323,11 @@ CSR_API(SrvSetConsoleActiveScreenBuffer)
 static NTSTATUS
 DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                IN PCSR_THREAD ClientThread,
-               IN BOOL CreateWaitBlock OPTIONAL);
+               IN BOOLEAN CreateWaitBlock OPTIONAL);
 
 // Wait function CSR_WAIT_FUNCTION
 static BOOLEAN
+NTAPI
 WriteConsoleThread(IN PLIST_ENTRY WaitList,
                    IN PCSR_THREAD WaitThread,
                    IN PCSR_API_MESSAGE WaitApiMessage,
@@ -331,9 +351,7 @@ WriteConsoleThread(IN PLIST_ENTRY WaitList,
         goto Quit;
     }
 
-    Status = DoWriteConsole(WaitApiMessage,
-                            WaitThread,
-                            FALSE);
+    Status = DoWriteConsole(WaitApiMessage, WaitThread, FALSE);
 
 Quit:
     if (Status != STATUS_PENDING)
@@ -354,7 +372,7 @@ ConDrvWriteConsole(IN PCONSOLE Console,
 static NTSTATUS
 DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                IN PCSR_THREAD ClientThread,
-               IN BOOL CreateWaitBlock OPTIONAL)
+               IN BOOLEAN CreateWaitBlock OPTIONAL)
 {
     NTSTATUS Status;
     PCONSOLE_WRITECONSOLE WriteConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleRequest;
@@ -380,7 +398,6 @@ DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                                WriteConsoleThread,
                                ClientThread,
                                ApiMessage,
-                               NULL,
                                NULL))
             {
                 /* Fail */
@@ -498,9 +515,7 @@ CSR_API(SrvWriteConsole)
         return STATUS_INVALID_PARAMETER;
     }
 
-    Status = DoWriteConsole(ApiMessage,
-                            CsrGetClientThread(),
-                            TRUE);
+    Status = DoWriteConsole(ApiMessage, CsrGetClientThread(), TRUE);
 
     if (Status == STATUS_PENDING) *ReplyCode = CsrReplyPending;