]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c
ShellPkg/[hex]edit: Fix mouse freeze issue
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / HexEdit / MainHexEditor.c
index 4c346cc24ebbc5ee3ed1164f66c2cb2c3fef0879..1a89d3d72a95525ed30d5ba58ab5919ff5b6a39d 100644 (file)
@@ -4,7 +4,7 @@
      - Instances of the other objects of the editor\r
      - Main Interfaces\r
   \r
-  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -56,6 +56,7 @@ HEFI_EDITOR_GLOBAL_EDITOR       HMainEditorConst = {
     0,\r
     0\r
   },\r
+  NULL,\r
   FALSE,\r
   NULL,\r
   0,\r
@@ -105,22 +106,55 @@ HMainCommandDisplayHelp (
   VOID\r
   )\r
 {\r
-  INT32    CurrentLine;\r
-  CHAR16 * InfoString;\r
-  EFI_INPUT_KEY  Key;\r
-\r
-  CurrentLine = 0;\r
+  INT32           CurrentLine;\r
+  CHAR16          *InfoString;\r
+  EFI_KEY_DATA    KeyData;\r
+  EFI_STATUS      Status;\r
+  UINTN           EventIndex;\r
+  \r
+  //\r
   // print helpInfo      \r
+  //\r
   for (CurrentLine = 0; 0 != HexMainMenuHelpInfo[CurrentLine]; CurrentLine++) {\r
     InfoString = HiiGetString(gShellDebug1HiiHandle, HexMainMenuHelpInfo[CurrentLine]\r
 , NULL);\r
     ShellPrintEx (0,CurrentLine+1,L"%E%s%N",InfoString);        \r
   }\r
-  \r
+\r
+  //\r
   // scan for ctrl+w\r
-  do {\r
-    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-  } while(SCAN_CONTROL_W != Key.UnicodeChar); \r
+  //\r
+  while (TRUE) {\r
+    Status = gBS->WaitForEvent (1, &HMainEditor.TextInputEx->WaitForKeyEx, &EventIndex);\r
+    if (EFI_ERROR (Status) || (EventIndex != 0)) {\r
+      continue;\r
+    }\r
+    Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.TextInputEx, &KeyData);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) ||\r
+        (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID)) {\r
+      //\r
+      // For consoles that don't support/report shift state,\r
+      // CTRL+W is translated to L'W' - L'A' + 1.\r
+      //\r
+      if (KeyData.Key.UnicodeChar == L'W' - L'A' + 1) {\r
+        break;\r
+      }\r
+    } else if (((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&\r
+               ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) &&\r
+               ((KeyData.KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) == 0)) {\r
+      //\r
+      // For consoles that supports/reports shift state,\r
+      // make sure that only CONTROL shift key is pressed.\r
+      //\r
+      if ((KeyData.Key.UnicodeChar == 'w') || (KeyData.Key.UnicodeChar == 'W')) {\r
+        break;\r
+      }\r
+    }\r
+  }\r
 \r
   // update screen with buffer's info\r
   HBufferImageNeedRefresh = TRUE;\r
@@ -1633,11 +1667,24 @@ HMainEditorInit (
         &(HMainEditor.ScreenSize.Row)\r
         );\r
 \r
+  //\r
+  // Find TextInEx in System Table ConsoleInHandle\r
+  // Per UEFI Spec, TextInEx is required for a console capable platform.\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+              gST->ConsoleInHandle,\r
+              &gEfiSimpleTextInputExProtocolGuid,\r
+              (VOID**)&HMainEditor.TextInputEx\r
+              );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Find mouse in System Table ConsoleInHandle\r
   //\r
   Status = gBS->HandleProtocol (\r
-                gST->ConIn,\r
+                gST->ConsoleInHandle,\r
                 &gEfiSimplePointerProtocolGuid,\r
                 (VOID**)&HMainEditor.MouseInterface\r
                 );\r
@@ -1706,7 +1753,7 @@ HMainEditorInit (
     return EFI_LOAD_ERROR;\r
   }\r
 \r
-  InputBarInit ();\r
+  InputBarInit (HMainEditor.TextInputEx);\r
 \r
   Status = HBufferImageInit ();\r
   if (EFI_ERROR (Status)) {\r
@@ -2058,9 +2105,10 @@ HMainEditorKeyInput (
   VOID\r
   )\r
 {\r
-  EFI_INPUT_KEY             Key;\r
+  EFI_KEY_DATA              KeyData;\r
   EFI_STATUS                Status;\r
   EFI_SIMPLE_POINTER_STATE  MouseState;\r
+  BOOLEAN                   NoShiftState;\r
   BOOLEAN                   LengthChange;\r
   UINTN                     Size;\r
   UINTN                     OldSize;\r
@@ -2219,77 +2267,90 @@ HMainEditorKeyInput (
       }\r
     }\r
 \r
-    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+    //\r
+    // CheckEvent() returns Success when non-partial key is pressed.\r
+    //\r
+    Status = gBS->CheckEvent (HMainEditor.TextInputEx->WaitForKeyEx);\r
     if (!EFI_ERROR (Status)) {\r
-      //\r
-      // dispatch to different components' key handling function\r
-      // so not everywhere has to set this variable\r
-      //\r
-      HBufferImageMouseNeedRefresh = TRUE;\r
-\r
-      //\r
-      // clear previous status string\r
-      //\r
-      StatusBarSetRefresh();\r
-      if (EFI_SUCCESS == MenuBarDispatchControlHotKey(&Key)) {\r
-        Status = EFI_SUCCESS;\r
-      } else if (Key.ScanCode == SCAN_NULL) {\r
-        Status = HBufferImageHandleInput (&Key);\r
-      } else if (((Key.ScanCode >= SCAN_UP) && (Key.ScanCode <= SCAN_PAGE_DOWN))) {\r
-        Status = HBufferImageHandleInput (&Key);\r
-      } else if (((Key.ScanCode >= SCAN_F1) && Key.ScanCode <= (SCAN_F12))) {\r
-        Status = MenuBarDispatchFunctionKey (&Key);\r
-      } else {\r
-        StatusBarSetStatusString (L"Unknown Command");\r
-\r
-        HBufferImageMouseNeedRefresh = FALSE;\r
-      }\r
+      Status = HMainEditor.TextInputEx->ReadKeyStrokeEx (HMainEditor.TextInputEx, &KeyData);\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // dispatch to different components' key handling function\r
+        // so not everywhere has to set this variable\r
+        //\r
+        HBufferImageMouseNeedRefresh = TRUE;\r
 \r
-      if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
         //\r
-        // not already has some error status\r
+        // clear previous status string\r
+        //\r
+        StatusBarSetRefresh();\r
+        //\r
+        // NoShiftState: TRUE when no shift key is pressed.\r
         //\r
-        if (StrCmp (L"", StatusBarGetString()) == 0) {\r
-          StatusBarSetStatusString (L"Disk Error. Try Again");\r
+        NoShiftState = ((KeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) || (KeyData.KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID);\r
+        //\r
+        // dispatch to different components' key handling function\r
+        //\r
+        if (EFI_SUCCESS == MenuBarDispatchControlHotKey(&KeyData)) {\r
+          Status = EFI_SUCCESS;\r
+        } else if (NoShiftState && KeyData.Key.ScanCode == SCAN_NULL) {\r
+          Status = HBufferImageHandleInput (&KeyData.Key);\r
+        } else if (NoShiftState && ((KeyData.Key.ScanCode >= SCAN_UP) && (KeyData.Key.ScanCode <= SCAN_PAGE_DOWN))) {\r
+          Status = HBufferImageHandleInput (&KeyData.Key);\r
+        } else if (NoShiftState && ((KeyData.Key.ScanCode >= SCAN_F1) && KeyData.Key.ScanCode <= SCAN_F12)) {\r
+          Status = MenuBarDispatchFunctionKey (&KeyData.Key);\r
+        } else {\r
+          StatusBarSetStatusString (L"Unknown Command");\r
+\r
+          HBufferImageMouseNeedRefresh = FALSE;\r
+        }\r
+\r
+        if (Status != EFI_SUCCESS && Status != EFI_OUT_OF_RESOURCES) {\r
+          //\r
+          // not already has some error status\r
+          //\r
+          if (StrCmp (L"", StatusBarGetString()) == 0) {\r
+            StatusBarSetStatusString (L"Disk Error. Try Again");\r
+          }\r
         }\r
       }\r
-    }\r
-    //\r
-    // decide if has to set length warning\r
-    //\r
-    if (HBufferImage.BufferType != HBufferImageBackupVar.BufferType) {\r
-      LengthChange = FALSE;\r
-    } else {\r
       //\r
-      // still the old buffer\r
+      // decide if has to set length warning\r
       //\r
-      if (HBufferImage.BufferType != FileTypeFileBuffer) {\r
-        Size = HBufferImageGetTotalSize ();\r
+      if (HBufferImage.BufferType != HBufferImageBackupVar.BufferType) {\r
+        LengthChange = FALSE;\r
+      } else {\r
+        //\r
+        // still the old buffer\r
+        //\r
+        if (HBufferImage.BufferType != FileTypeFileBuffer) {\r
+          Size = HBufferImageGetTotalSize ();\r
 \r
-        switch (HBufferImage.BufferType) {\r
-        case FileTypeDiskBuffer:\r
-          OldSize = HBufferImage.DiskImage->Size * HBufferImage.DiskImage->BlockSize;\r
-          break;\r
+          switch (HBufferImage.BufferType) {\r
+          case FileTypeDiskBuffer:\r
+            OldSize = HBufferImage.DiskImage->Size * HBufferImage.DiskImage->BlockSize;\r
+            break;\r
 \r
-        case FileTypeMemBuffer:\r
-          OldSize = HBufferImage.MemImage->Size;\r
-          break;\r
+          case FileTypeMemBuffer:\r
+            OldSize = HBufferImage.MemImage->Size;\r
+            break;\r
         \r
-        default:\r
-          OldSize = 0;\r
-          break;\r
-        }\r
+          default:\r
+            OldSize = 0;\r
+            break;\r
+          }\r
 \r
-        if (!LengthChange) {\r
-          if (OldSize != Size) {\r
-            StatusBarSetStatusString (L"Disk/Mem Buffer Length should not be changed");\r
+          if (!LengthChange) {\r
+            if (OldSize != Size) {\r
+              StatusBarSetStatusString (L"Disk/Mem Buffer Length should not be changed");\r
+            }\r
           }\r
-        }\r
 \r
-        if (OldSize != Size) {\r
-          LengthChange = TRUE;\r
-        } else {\r
-          LengthChange = FALSE;\r
+          if (OldSize != Size) {\r
+            LengthChange = TRUE;\r
+          } else {\r
+            LengthChange = FALSE;\r
+          }\r
         }\r
       }\r
     }\r
@@ -2307,7 +2368,6 @@ HMainEditorKeyInput (
   Backup function for MainEditor.\r
 **/\r
 VOID\r
-EFIAPI\r
 HMainEditorBackup (\r
   VOID\r
   )\r