[CRT] crtdefs.h: Wrap localeinfo_struct in ifdef
[reactos.git] / win32ss / user / winsrv / consrv / frontends / input.c
index 17b7ff3..5305e10 100644 (file)
@@ -10,7 +10,6 @@
 /* INCLUDES *******************************************************************/
 
 #include "consrv.h"
-#include "include/conio.h"
 #include "include/term.h"
 #include "coninput.h"
 
@@ -20,7 +19,7 @@
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
-static DWORD FASTCALL
+static DWORD
 ConioGetShiftState(PBYTE KeyState, LPARAM lParam)
 {
     DWORD ssOut = 0;
@@ -35,27 +34,30 @@ ConioGetShiftState(PBYTE KeyState, LPARAM lParam)
         ssOut |= SCROLLLOCK_ON;
 
     if (KeyState[VK_SHIFT] & 0x80)
+    // || (KeyState[VK_LSHIFT] & 0x80) || (KeyState[VK_RSHIFT] & 0x80)
         ssOut |= SHIFT_PRESSED;
 
     if (KeyState[VK_LCONTROL] & 0x80)
         ssOut |= LEFT_CTRL_PRESSED;
     if (KeyState[VK_RCONTROL] & 0x80)
         ssOut |= RIGHT_CTRL_PRESSED;
+    // if (KeyState[VK_CONTROL] & 0x80) { ... }
 
     if (KeyState[VK_LMENU] & 0x80)
         ssOut |= LEFT_ALT_PRESSED;
     if (KeyState[VK_RMENU] & 0x80)
         ssOut |= RIGHT_ALT_PRESSED;
+    // if (KeyState[VK_MENU] & 0x80) { ... }
 
     /* See WM_CHAR MSDN documentation for instance */
-    if (lParam & 0x01000000)
+    if (HIWORD(lParam) & KF_EXTENDED)
         ssOut |= ENHANCED_KEY;
 
     return ssOut;
 }
 
 VOID NTAPI
-ConioProcessKey(PCONSOLE Console, MSG* msg)
+ConioProcessKey(PCONSRV_CONSOLE Console, MSG* msg)
 {
     static BYTE KeyState[256] = { 0 };
     /* MSDN mentions that you should use the last virtual key code received
@@ -66,11 +68,13 @@ ConioProcessKey(PCONSOLE Console, MSG* msg)
     WCHAR UnicodeChar;
     UINT VirtualKeyCode;
     UINT VirtualScanCode;
-    BOOL Down = FALSE;
-    BOOLEAN Fake;          // synthesized, not a real event
-    BOOLEAN NotChar;       // message should not be used to return a character
+    BOOL Down;
+    BOOLEAN Fake;          // Synthesized, not a real event
+    BOOLEAN NotChar;       // Message should not be used to return a character
 
-    if (NULL == Console)
+    INPUT_RECORD er;
+
+    if (Console == NULL)
     {
         DPRINT1("No Active Console!\n");
         return;
@@ -101,17 +105,7 @@ ConioProcessKey(PCONSOLE Console, MSG* msg)
                                2,
                                0,
                                NULL);
-        UnicodeChar = (1 == RetChars ? Chars[0] : 0);
-    }
-
-    if (TermProcessKeyCallback(Console,
-                               msg,
-                               KeyState[VK_MENU],
-                               ShiftState,
-                               VirtualKeyCode,
-                               Down))
-    {
-        return;
+        UnicodeChar = (RetChars == 1 ? Chars[0] : 0);
     }
 
     Fake = UnicodeChar &&
@@ -133,14 +127,65 @@ ConioProcessKey(PCONSOLE Console, MSG* msg)
 
     if (Fake) return;
 
+//
+// FIXME: Scrolling via keyboard shortcuts must be done differently,
+// without touching the internal VirtualY variable.
+//
+#if 0
+    if ( (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0 &&
+         (VirtualKeyCode == VK_UP || VirtualKeyCode == VK_DOWN) )
+    {
+        if (!Down) return;
+
+        /* Scroll up or down */
+        if (VirtualKeyCode == VK_UP)
+        {
+            /* Only scroll up if there is room to scroll up into */
+            if (Console->ActiveBuffer->CursorPosition.Y != Console->ActiveBuffer->ScreenBufferSize.Y - 1)
+            {
+                Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY +
+                                                   Console->ActiveBuffer->ScreenBufferSize.Y - 1) %
+                                                   Console->ActiveBuffer->ScreenBufferSize.Y;
+                Console->ActiveBuffer->CursorPosition.Y++;
+            }
+        }
+        else
+        {
+            /* Only scroll down if there is room to scroll down into */
+            if (Console->ActiveBuffer->CursorPosition.Y != 0)
+            {
+                Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + 1) %
+                                                   Console->ActiveBuffer->ScreenBufferSize.Y;
+                Console->ActiveBuffer->CursorPosition.Y--;
+            }
+        }
+
+        ConioDrawConsole(Console);
+        return;
+    }
+#endif
+
     /* Send the key press to the console driver */
-    ConDrvProcessKey(Console,
-                     Down,
-                     VirtualKeyCode,
-                     VirtualScanCode,
-                     UnicodeChar,
-                     ShiftState,
-                     KeyState[VK_CONTROL]);
+
+    er.EventType                        = KEY_EVENT;
+    er.Event.KeyEvent.bKeyDown          = Down;
+    er.Event.KeyEvent.wRepeatCount      = 1;
+    er.Event.KeyEvent.wVirtualKeyCode   = VirtualKeyCode;
+    er.Event.KeyEvent.wVirtualScanCode  = VirtualScanCode;
+    er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar;
+    er.Event.KeyEvent.dwControlKeyState = ShiftState;
+
+    ConioProcessInputEvent(Console, &er);
+}
+
+DWORD
+ConioEffectiveCursorSize(PCONSRV_CONSOLE Console, DWORD Scale)
+{
+    DWORD Size = (Console->ActiveBuffer->CursorInfo.dwSize * Scale + 99) / 100;
+    /* If line input in progress, perhaps adjust for insert toggle */
+    if (Console->LineBuffer && !Console->LineComplete && (Console->InsertMode ? !Console->LineInsertToggle : Console->LineInsertToggle))
+        return (Size * 2 <= Scale) ? (Size * 2) : (Size / 2);
+    return Size;
 }
 
 /* EOF */