]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
Revert "ShellPkg: Make the USB mouse behavior in 'edit' consistent with 'hexedit'."
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / FileBuffer.c
index 5acd8d49f765fcd4a29fe687967d95b44bdd08d4..acd8512ff3e876e4318c4f50c5ff79092932e577 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2015, 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
@@ -256,71 +256,6 @@ MoveLine (
   return Line;\r
 }\r
 \r
-/**\r
-  Decide if a point is in the already selected area.\r
-\r
-  @param[in] MouseRow     The row of the point to test.\r
-  @param[in] MouseCol     The col of the point to test.\r
-\r
-  @retval TRUE      The point is in the selected area.\r
-  @retval FALSE     The point is not in the selected area.\r
-**/\r
-BOOLEAN\r
-FileBufferIsInSelectedArea (\r
-  IN UINTN MouseRow,\r
-  IN UINTN MouseCol\r
-  )\r
-{\r
-  UINTN FRow;\r
-  UINTN RowStart;\r
-  UINTN RowEnd;\r
-  UINTN ColStart;\r
-  UINTN ColEnd;\r
-  UINTN MouseColStart;\r
-  UINTN MouseColEnd;\r
-\r
-  //\r
-  // judge mouse position whether is in selected area\r
-  //\r
-  //\r
-  // not select\r
-  //\r
-  if (MainEditor.SelectStart == 0 || MainEditor.SelectEnd == 0) {\r
-    return FALSE;\r
-  }\r
-  //\r
-  // calculate the select area\r
-  //\r
-  RowStart  = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-  RowEnd    = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-\r
-  ColStart  = (MainEditor.SelectStart - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-  ColEnd    = (MainEditor.SelectEnd - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-\r
-  FRow      = FileBuffer.LowVisibleRange.Row + MouseRow - 2;\r
-  if (FRow < RowStart || FRow > RowEnd) {\r
-    return FALSE;\r
-  }\r
-\r
-  if (FRow > RowStart) {\r
-    ColStart = 1;\r
-  }\r
-\r
-  if (FRow < RowEnd) {\r
-    ColEnd = SHELL_EDIT_MAX_LINE_SIZE;\r
-  }\r
-\r
-  MouseColStart = ColStart;\r
-\r
-  MouseColEnd = ColEnd;\r
-\r
-  if (MouseCol < MouseColStart || MouseCol > MouseColEnd) {\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
 /**\r
   Function to update the 'screen' to display the mouse position.\r
 \r
@@ -376,29 +311,6 @@ FileBufferRestoreMousePosition (
 \r
       FColumn       = FileBuffer.LowVisibleRange.Column + FileBufferBackupVar.MousePosition.Column - 1;\r
 \r
-      if (FRow <= FileBuffer.NumLines) {\r
-        CurrentLine = FileBuffer.CurrentLine;\r
-        Line        = MoveLine (FRow - FileBuffer.FilePosition.Row);\r
-        FileBuffer.CurrentLine = CurrentLine;\r
-      }\r
-\r
-      //\r
-      // if in selected area,\r
-      // so do not need to refresh mouse\r
-      //\r
-      if (!FileBufferIsInSelectedArea (\r
-            FileBufferBackupVar.MousePosition.Row,\r
-            FileBufferBackupVar.MousePosition.Column\r
-            ) ||\r
-          (Line == NULL || FColumn > Line->Size)\r
-      ) {\r
-        gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
-      } else {\r
-        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
-      }\r
-\r
-      Line = NULL;\r
-\r
       HasCharacter  = TRUE;\r
       if (FRow > FileBuffer.NumLines) {\r
         HasCharacter = FALSE;\r
@@ -431,15 +343,8 @@ FileBufferRestoreMousePosition (
       //\r
       // set the new mouse position\r
       //\r
-      if (!FileBufferIsInSelectedArea (\r
-            FileBuffer.MousePosition.Row,\r
-            FileBuffer.MousePosition.Column\r
-            )\r
-      ) {\r
-        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
-      } else {\r
-        gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
-      }\r
+      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
+\r
       //\r
       // clear the old mouse position\r
       //\r
@@ -567,25 +472,18 @@ FileBufferCleanup (
 \r
 }\r
 \r
-\r
 /**\r
-  Print Line on Row\r
+  Print a line specified by Line on a row specified by Row of the screen.\r
 \r
-  @param[in] Line     The lline to print.\r
-  @param[in] Row      The row on screen ( begin from 1 ).\r
-  @param[in] FRow     The FRow.\r
-  @param[in] Orig     The original color.\r
-  @param[in] New      The color to print with.\r
+  @param[in] Line               The line to print.\r
+  @param[in] Row                The row on the screen to print onto (begin from 1).\r
 \r
-  @retval EFI_SUCCESS The operation was successful.\r
+  @retval EFI_SUCCESS           The printing was successful.\r
 **/\r
 EFI_STATUS\r
 FileBufferPrintLine (\r
-  IN CONST EFI_EDITOR_LINE        *Line,\r
-  IN CONST  UINTN                 Row,\r
-  IN CONST  UINTN                 FRow,\r
-  IN EFI_EDITOR_COLOR_UNION       Orig,\r
-  IN EFI_EDITOR_COLOR_UNION       New\r
+  IN CONST EFI_EDITOR_LINE  *Line,\r
+  IN CONST UINTN            Row\r
   )\r
 {\r
 \r
@@ -593,42 +491,7 @@ FileBufferPrintLine (
   UINTN   Limit;\r
   CHAR16  *PrintLine;\r
   CHAR16  *PrintLine2;\r
-  CHAR16  *TempString;\r
-  UINTN   BufLen;\r
-  BOOLEAN Selected;\r
-  UINTN   RowStart;\r
-  UINTN   RowEnd;\r
-  UINTN   ColStart;\r
-  UINTN   ColEnd;\r
-\r
-  ColStart    = 0;\r
-  ColEnd      = 0;\r
-  Selected    = FALSE;\r
-  TempString  = NULL;\r
-\r
-  //\r
-  // print the selected area in opposite color\r
-  //\r
-  if (MainEditor.SelectStart != 0 && MainEditor.SelectEnd != 0) {\r
-    RowStart  = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-    RowEnd    = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-\r
-    ColStart  = (MainEditor.SelectStart - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-    ColEnd    = (MainEditor.SelectEnd - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-\r
-    if (FRow >= RowStart && FRow <= RowEnd) {\r
-      Selected = TRUE;\r
-    }\r
-\r
-    if (FRow > RowStart) {\r
-      ColStart = 1;\r
-    }\r
-\r
-    if (FRow < RowEnd) {\r
-      ColEnd = Line->Size + 1;\r
-    }\r
-\r
-  }\r
+  UINTN   BufLen; \r
 \r
   //\r
   // print start from correct character\r
@@ -656,64 +519,15 @@ FileBufferPrintLine (
 \r
   ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);\r
 \r
-  if (!Selected) {\r
-    ShellPrintEx (\r
-      0,\r
-      (INT32)Row - 1,\r
-      L"%s",\r
-      PrintLine2\r
-      );\r
-  } else {\r
-    //\r
-    // If the current line is selected.\r
-    //\r
-    if (ColStart != 1) {\r
-      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
-      TempString = AllocateCopyPool ((ColStart - 1) * sizeof(CHAR16), PrintLine2);\r
-      ASSERT (TempString != NULL);\r
-      ShellPrintEx (\r
-        0,\r
-        (INT32)Row - 1,\r
-        L"%s",\r
-        TempString\r
-      );\r
-      FreePool (TempString);\r
-    }\r
-\r
-    gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
-    TempString = AllocateCopyPool (\r
-                  (ColEnd - ColStart + 1)  * sizeof(CHAR16),\r
-                  PrintLine2 + ColStart - 1\r
-                  );\r
-    ASSERT (TempString != NULL);\r
-    ShellPrintEx (\r
-      (INT32)ColStart - 1,\r
-      (INT32)Row - 1,\r
-      L"%s",\r
-      TempString\r
-      );\r
-    FreePool (TempString);\r
-\r
-    if (ColEnd != SHELL_EDIT_MAX_LINE_SIZE) {\r
-      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
-      TempString = AllocateCopyPool (\r
-                    (SHELL_EDIT_MAX_LINE_SIZE - ColEnd + 1)  * sizeof(CHAR16),\r
-                    PrintLine2 + ColEnd - 1\r
-                    );\r
-      ASSERT (TempString != NULL);\r
-      ShellPrintEx (\r
-        (INT32)ColEnd - 1,\r
-        (INT32)Row - 1,\r
-        L"%s",\r
-        TempString\r
-      );\r
-      FreePool (TempString);\r
-    }\r
-  }\r
+  ShellPrintEx (\r
+    0,\r
+    (INT32)Row - 1,\r
+    L"%s",\r
+    PrintLine2\r
+    );\r
 \r
   FreePool (PrintLine);\r
   FreePool (PrintLine2);\r
-  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -754,17 +568,6 @@ FileBufferRefresh (
   LIST_ENTRY  *Link;\r
   EFI_EDITOR_LINE *Line;\r
   UINTN           Row;\r
-  EFI_EDITOR_COLOR_UNION Orig;\r
-  EFI_EDITOR_COLOR_UNION New;\r
-\r
-  UINTN                   StartRow;\r
-  UINTN                   EndRow;\r
-  UINTN                   Tmp;\r
-\r
-  Orig                  = MainEditor.ColorAttributes;\r
-  New.Data              = 0;\r
-  New.Colors.Foreground = Orig.Colors.Background;\r
-  New.Colors.Background = Orig.Colors.Foreground;\r
 \r
   //\r
   // if it's the first time after editor launch, so should refresh\r
@@ -776,10 +579,13 @@ FileBufferRefresh (
     //\r
     if (!FileBufferNeedRefresh &&\r
         !FileBufferOnlyLineNeedRefresh &&\r
-        FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row\r
+        FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
+        FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
         ) {\r
+\r
       FileBufferRestoreMousePosition ();\r
       FileBufferRestorePosition ();\r
+\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -790,57 +596,19 @@ FileBufferRefresh (
   // only need to refresh current line\r
   //\r
   if (FileBufferOnlyLineNeedRefresh &&\r
-      FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row\r
+      FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
+      FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
       ) {\r
 \r
     EditorClearLine (FileBuffer.DisplayPosition.Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);\r
     FileBufferPrintLine (\r
       FileBuffer.CurrentLine,\r
-      FileBuffer.DisplayPosition.Row,\r
-      FileBuffer.FilePosition.Row,\r
-      Orig,\r
-      New\r
+      FileBuffer.DisplayPosition.Row\r
       );\r
   } else {\r
     //\r
     // the whole edit area need refresh\r
     //\r
-    if (EditorMouseAction && MainEditor.SelectStart != 0 && MainEditor.SelectEnd != 0) {\r
-      if (MainEditor.SelectStart != MainEditorBackupVar.SelectStart) {\r
-        if (MainEditor.SelectStart >= MainEditorBackupVar.SelectStart && MainEditorBackupVar.SelectStart != 0) {\r
-          StartRow = (MainEditorBackupVar.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-        } else {\r
-          StartRow = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-        }\r
-      } else {\r
-        StartRow = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-      }\r
-\r
-      if (MainEditor.SelectEnd <= MainEditorBackupVar.SelectEnd) {\r
-        EndRow = (MainEditorBackupVar.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-      } else {\r
-        EndRow = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;\r
-      }\r
-\r
-      //\r
-      // swap\r
-      //\r
-      if (StartRow > EndRow) {\r
-        Tmp       = StartRow;\r
-        StartRow  = EndRow;\r
-        EndRow    = Tmp;\r
-      }\r
-\r
-      StartRow  = 2 + StartRow - FileBuffer.LowVisibleRange.Row;\r
-      EndRow    = 2 + EndRow - FileBuffer.LowVisibleRange.Row;\r
-\r
-    } else {\r
-      //\r
-      // not mouse selection actions\r
-      //\r
-      StartRow  = 2;\r
-      EndRow    = (MainEditor.ScreenSize.Row - 1);\r
-    }\r
 \r
     //\r
     // no line\r
@@ -870,20 +638,15 @@ FileBufferRefresh (
       //\r
       // print line at row\r
       //\r
-      FileBufferPrintLine (Line,\r
-        Row,\r
-        FileBuffer.LowVisibleRange.Row + Row - 2,\r
-        Orig,\r
-        New\r
-        );\r
+      FileBufferPrintLine (Line, Row);\r
 \r
       Link = Link->ForwardLink;\r
       Row++;\r
-    } while (Link != FileBuffer.ListHead && Row <= EndRow);\r
+    } while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 1));\r
     //\r
     // while not file end and not screen full\r
     //\r
-    while (Row <= EndRow) {\r
+    while (Row <= (MainEditor.ScreenSize.Row - 1)) {\r
       EditorClearLine (Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);\r
       Row++;\r
     }\r
@@ -3606,39 +3369,3 @@ FileBufferSetModified (
   FileBuffer.FileModified = TRUE;\r
 }\r
 \r
-\r
-/**\r
-  Get the size of the open buffer.\r
-\r
-  @retval The size in bytes.\r
-**/\r
-UINTN\r
-FileBufferGetTotalSize (\r
-  VOID\r
-  )\r
-{\r
-  UINTN             Size;\r
-\r
-  EFI_EDITOR_LINE   *Line;\r
-\r
-  //\r
-  // calculate the total size of whole line list's buffer\r
-  //\r
-  if (FileBuffer.Lines == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  Line = CR (\r
-          FileBuffer.ListHead->BackLink,\r
-          EFI_EDITOR_LINE,\r
-          Link,\r
-          LINE_LIST_SIGNATURE\r
-          );\r
-  //\r
-  // one line at most 0x50\r
-  //\r
-  Size = SHELL_EDIT_MAX_LINE_SIZE * (FileBuffer.NumLines - 1) + Line->Size;\r
-\r
-  return Size;\r
-}\r
-\r