]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Make the USB mouse behavior in 'edit' consistent with 'hexedit'.
authorQiu Shumin <shumin.qiu@intel.com>
Mon, 14 Mar 2016 03:14:56 +0000 (11:14 +0800)
committerQiu Shumin <shumin.qiu@intel.com>
Thu, 24 Mar 2016 02:17:52 +0000 (10:17 +0800)
1. Make the USB mouse cursor move smoothly in 'edit'.
2. Make the USB mouse can drag and select text in 'edit'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.h
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditor.h
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/TextEditorTypes.h

index acd8512ff3e876e4318c4f50c5ff79092932e577..fb0c76e2e9db75a680ece56706793907530625d7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2016, 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,6 +256,71 @@ 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
@@ -311,6 +376,29 @@ 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
@@ -343,8 +431,15 @@ FileBufferRestoreMousePosition (
       //\r
       // set the new mouse position\r
       //\r
-      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\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
       //\r
       // clear the old mouse position\r
       //\r
@@ -472,18 +567,25 @@ FileBufferCleanup (
 \r
 }\r
 \r
+\r
 /**\r
-  Print a line specified by Line on a row specified by Row of the screen.\r
+  Print Line on Row\r
 \r
-  @param[in] Line               The line to print.\r
-  @param[in] Row                The row on the screen to print onto (begin from 1).\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
 \r
-  @retval EFI_SUCCESS           The printing was successful.\r
+  @retval EFI_SUCCESS The operation was successful.\r
 **/\r
 EFI_STATUS\r
 FileBufferPrintLine (\r
-  IN CONST EFI_EDITOR_LINE  *Line,\r
-  IN CONST UINTN            Row\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
   )\r
 {\r
 \r
@@ -491,7 +593,42 @@ FileBufferPrintLine (
   UINTN   Limit;\r
   CHAR16  *PrintLine;\r
   CHAR16  *PrintLine2;\r
-  UINTN   BufLen; \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
 \r
   //\r
   // print start from correct character\r
@@ -519,15 +656,64 @@ FileBufferPrintLine (
 \r
   ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);\r
 \r
-  ShellPrintEx (\r
-    0,\r
-    (INT32)Row - 1,\r
-    L"%s",\r
-    PrintLine2\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
 \r
   FreePool (PrintLine);\r
   FreePool (PrintLine2);\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -568,6 +754,18 @@ 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                   FStartRow;\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
@@ -579,13 +777,10 @@ FileBufferRefresh (
     //\r
     if (!FileBufferNeedRefresh &&\r
         !FileBufferOnlyLineNeedRefresh &&\r
-        FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
-        FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
+        FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row\r
         ) {\r
-\r
       FileBufferRestoreMousePosition ();\r
       FileBufferRestorePosition ();\r
-\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -596,19 +791,60 @@ FileBufferRefresh (
   // only need to refresh current line\r
   //\r
   if (FileBufferOnlyLineNeedRefresh &&\r
-      FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
-      FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
+      FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row\r
       ) {\r
 \r
     EditorClearLine (FileBuffer.DisplayPosition.Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);\r
     FileBufferPrintLine (\r
       FileBuffer.CurrentLine,\r
-      FileBuffer.DisplayPosition.Row\r
+      FileBuffer.DisplayPosition.Row,\r
+      FileBuffer.FilePosition.Row,\r
+      Orig,\r
+      New\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
+      FStartRow = StartRow;\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
+      FStartRow = FileBuffer.LowVisibleRange.Row;\r
+      StartRow  = 2;\r
+      EndRow    = (MainEditor.ScreenSize.Row - 1);\r
+    }\r
 \r
     //\r
     // no line\r
@@ -638,15 +874,20 @@ FileBufferRefresh (
       //\r
       // print line at row\r
       //\r
-      FileBufferPrintLine (Line, Row);\r
+      FileBufferPrintLine (Line,\r
+        Row,\r
+        FileBuffer.LowVisibleRange.Row + Row - 2,\r
+        Orig,\r
+        New\r
+        );\r
 \r
       Link = Link->ForwardLink;\r
       Row++;\r
-    } while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 1));\r
+    } while (Link != FileBuffer.ListHead && Row <= EndRow);\r
     //\r
     // while not file end and not screen full\r
     //\r
-    while (Row <= (MainEditor.ScreenSize.Row - 1)) {\r
+    while (Row <= EndRow) {\r
       EditorClearLine (Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);\r
       Row++;\r
     }\r
@@ -3369,3 +3610,39 @@ 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
index 9d4a08d7a3128236c87a92cdc3b5b37a89e40c95..627bb8449e01a2daeee0740c81f87f4a1bc27735 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declares filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2016, 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
@@ -260,4 +260,14 @@ FileBufferSetModified (
   VOID\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
 #endif\r
index 4eb7d9eee304dfc2937fcc169a981b5fc34d5c25..6e91719ade39228e5035567942973534e3da27a2 100644 (file)
@@ -40,6 +40,7 @@ extern BOOLEAN                FileBufferMouseNeedRefresh;
 extern EFI_EDITOR_FILE_BUFFER FileBufferBackupVar;\r
 \r
 EFI_EDITOR_GLOBAL_EDITOR      MainEditor;\r
+EFI_EDITOR_GLOBAL_EDITOR      MainEditorBackupVar;\r
 \r
 \r
 /**\r
@@ -1689,7 +1690,8 @@ GetTextY (
 /**\r
   Support mouse movement.  Move the cursor.\r
 \r
-  @param[in] MouseState     The current mouse state.\r
+  @param[in]   MouseState             The current mouse state.\r
+  @param[out]  BeforeLeftButtonDown   TRUE if the left button down. Helps with selections.\r
 \r
   @retval EFI_SUCCESS       The operation was successful.\r
   @retval EFI_NOT_FOUND     There was no mouse support found.\r
@@ -1697,7 +1699,8 @@ GetTextY (
 EFI_STATUS\r
 EFIAPI\r
 MainEditorHandleMouseInput (\r
-  IN EFI_SIMPLE_POINTER_STATE       MouseState\r
+  IN  EFI_SIMPLE_POINTER_STATE        MouseState,\r
+  OUT BOOLEAN                         *BeforeLeftButtonDown\r
   )\r
 {\r
 \r
@@ -1705,10 +1708,8 @@ MainEditorHandleMouseInput (
   INT32           TextY;\r
   UINTN           FRow;\r
   UINTN           FCol;\r
-\r
-  LIST_ENTRY  *Link;\r
+  LIST_ENTRY      *Link;\r
   EFI_EDITOR_LINE *Line;\r
-\r
   UINTN           Index;\r
   BOOLEAN         Action;\r
 \r
@@ -1761,10 +1762,27 @@ MainEditorHandleMouseInput (
     Line = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
 \r
     //\r
+    // dragging\r
     // beyond the line's column length\r
     //\r
-    if (FCol > Line->Size + 1) {\r
-      FCol = Line->Size + 1;\r
+    if (FCol > Line->Size ) {\r
+      if (*BeforeLeftButtonDown) {\r
+\r
+        if (Line->Size == 0) {\r
+          if (FRow > 1) {\r
+            FRow--;\r
+            FCol = SHELL_EDIT_MAX_LINE_SIZE;\r
+          } else {\r
+            FRow  = 1;\r
+            FCol  = 1;\r
+          }\r
+\r
+        } else {\r
+          FCol = Line->Size ;\r
+        }\r
+      } else {\r
+        FCol      = Line->Size + 1;\r
+      }\r
     }\r
 \r
     FileBufferMovePosition (FRow, FCol);\r
@@ -1773,8 +1791,24 @@ MainEditorHandleMouseInput (
 \r
     MainEditor.FileBuffer->MousePosition.Column = MainEditor.FileBuffer->DisplayPosition.Column;\r
 \r
+    *BeforeLeftButtonDown                       = TRUE;\r
+\r
     Action = TRUE;\r
+  } else {\r
+    //\r
+    // else of if LButton\r
+    //\r
+    // release LButton\r
+    //\r
+    if (*BeforeLeftButtonDown) {\r
+      Action = TRUE;\r
+    }\r
+    //\r
+    // mouse up\r
+    //\r
+    *BeforeLeftButtonDown = FALSE;\r
   }\r
+\r
   //\r
   // mouse has action\r
   //\r
@@ -1804,6 +1838,23 @@ MainEditorKeyInput (
   EFI_INPUT_KEY             Key;\r
   EFI_STATUS                Status;\r
   EFI_SIMPLE_POINTER_STATE  MouseState;\r
+  BOOLEAN                   BeforeMouseIsDown;\r
+  BOOLEAN                   MouseIsDown;\r
+  BOOLEAN                   FirstDown;\r
+  BOOLEAN                   MouseDrag;\r
+  UINTN                     FRow;\r
+  UINTN                     FCol;\r
+  UINTN                     SelectStartBackup;\r
+  UINTN                     SelectEndBackup;\r
+\r
+  //\r
+  // variable initialization\r
+  //\r
+  FRow          = 0;\r
+  FCol          = 0;\r
+  MouseIsDown   = FALSE;\r
+  FirstDown     = FALSE;\r
+  MouseDrag     = FALSE;\r
 \r
   do {\r
 \r
@@ -1826,10 +1877,105 @@ MainEditorKeyInput (
                                             &MouseState\r
                                             );\r
       if (!EFI_ERROR (Status)) {\r
+        BeforeMouseIsDown = MouseIsDown;\r
 \r
-        Status = MainEditorHandleMouseInput (MouseState);\r
+        Status            = MainEditorHandleMouseInput (MouseState, &MouseIsDown);\r
 \r
         if (!EFI_ERROR (Status)) {\r
+          if (!BeforeMouseIsDown) {\r
+            //\r
+            // mouse down\r
+            //\r
+            if (MouseIsDown) {\r
+              FRow              = FileBuffer.FilePosition.Row;\r
+              FCol              = FileBuffer.FilePosition.Column;\r
+              SelectStartBackup = MainEditor.SelectStart;\r
+              SelectEndBackup   = MainEditor.SelectEnd;\r
+\r
+              FirstDown         = TRUE;\r
+            }\r
+          } else {\r
+\r
+            SelectStartBackup = MainEditor.SelectStart;\r
+            SelectEndBackup   = MainEditor.SelectEnd;\r
+\r
+            //\r
+            // begin to drag\r
+            //\r
+            if (MouseIsDown) {\r
+              if (FirstDown) {\r
+                if (MouseState.RelativeMovementX || MouseState.RelativeMovementY) {\r
+                  MainEditor.SelectStart = 0;\r
+                  MainEditor.SelectEnd   = 0;\r
+                  MainEditor.SelectStart = (FRow - 1) * SHELL_EDIT_MAX_LINE_SIZE + FCol;\r
+\r
+                  MouseDrag               = TRUE;\r
+                  FirstDown               = FALSE;\r
+                }\r
+              } else {\r
+                if ((\r
+                      (FileBuffer.FilePosition.Row - 1) *\r
+                      SHELL_EDIT_MAX_LINE_SIZE +\r
+                      FileBuffer.FilePosition.Column\r
+                    ) >= MainEditor.SelectStart\r
+                   ) {\r
+                  MainEditor.SelectEnd = (FileBuffer.FilePosition.Row - 1) *\r
+                                          SHELL_EDIT_MAX_LINE_SIZE +\r
+                                          FileBuffer.FilePosition.Column;\r
+                } else {\r
+                  MainEditor.SelectEnd = 0;\r
+                }\r
+              }\r
+              //\r
+              // end of if RelativeX/Y\r
+              //\r
+            } else {\r
+              //\r
+              // mouse is up\r
+              //\r
+              if (MouseDrag) {\r
+                if (FileBufferGetTotalSize () == 0) {\r
+                  MainEditor.SelectStart = 0;\r
+                  MainEditor.SelectEnd   = 0;\r
+                  FirstDown               = FALSE;\r
+                  MouseDrag               = FALSE;\r
+                }\r
+\r
+                if ((\r
+                      (FileBuffer.FilePosition.Row - 1) *\r
+                      SHELL_EDIT_MAX_LINE_SIZE +\r
+                      FileBuffer.FilePosition.Column\r
+                    ) >= MainEditor.SelectStart\r
+                   ) {\r
+                  MainEditor.SelectEnd = (FileBuffer.FilePosition.Row - 1) *\r
+                                          SHELL_EDIT_MAX_LINE_SIZE +\r
+                                          FileBuffer.FilePosition.Column;\r
+                } else {\r
+                  MainEditor.SelectEnd = 0;\r
+                }\r
+\r
+                if (MainEditor.SelectEnd == 0) {\r
+                  MainEditor.SelectStart = 0;\r
+                }\r
+              }\r
+\r
+              FirstDown = FALSE;\r
+              MouseDrag = FALSE;\r
+            }\r
+\r
+            if (SelectStartBackup != MainEditor.SelectStart || SelectEndBackup != MainEditor.SelectEnd) {\r
+              if ((SelectStartBackup - 1) / SHELL_EDIT_MAX_LINE_SIZE != (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE) {\r
+                FileBufferNeedRefresh = TRUE;\r
+              } else {\r
+                if ((SelectEndBackup - 1) / SHELL_EDIT_MAX_LINE_SIZE != (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE) {\r
+                  FileBufferNeedRefresh = TRUE;\r
+                } else {\r
+                  FileBufferOnlyLineNeedRefresh = TRUE;\r
+                }\r
+              }\r
+            }\r
+          }\r
+\r
           EditorMouseAction           = TRUE;\r
           FileBufferMouseNeedRefresh  = TRUE;\r
         } else if (Status == EFI_LOAD_ERROR) {\r
@@ -1930,7 +2076,11 @@ MainEditorBackup (
   VOID\r
   )\r
 {\r
+  MainEditorBackupVar.SelectStart  = MainEditor.SelectStart;\r
+  MainEditorBackupVar.SelectEnd    = MainEditor.SelectEnd;\r
   FileBufferBackup ();\r
   \r
   return EFI_SUCCESS;\r
 }\r
+\r
+\r
index 774f01a29141a7e92abc7b2ca5e7a3909e56fe87..54dc7de9e9616f8878058c389a0379a8df9a6d5a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main include file for Edit shell Debug1 function.\r
 \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2016, 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
@@ -26,6 +26,7 @@
 #include "Misc.h"\r
 \r
 extern EFI_EDITOR_GLOBAL_EDITOR MainEditor;\r
+extern EFI_EDITOR_GLOBAL_EDITOR MainEditorBackupVar;\r
 extern BOOLEAN                  EditorFirst;\r
 extern BOOLEAN                  EditorExit;\r
 \r
index dfd56dd9a6eced196624b41a58853498c5670301..43e3558793f2dc166c86c903c65ab340feb6a077 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declares editor types.\r
 \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2016, 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
@@ -19,8 +19,9 @@
 #include "EditTitleBar.h"\r
 #include "EditMenuBar.h"\r
 \r
-#define MIN_POOL_SIZE         125\r
-#define MAX_STRING_LENGTH     127\r
+#define MIN_POOL_SIZE                 125\r
+#define MAX_STRING_LENGTH             127\r
+#define SHELL_EDIT_MAX_LINE_SIZE      0x50\r
 \r
 typedef struct {\r
   UINTN Row;\r
@@ -97,6 +98,8 @@ typedef struct {
   INT32                       MouseAccumulatorX;\r
   INT32                       MouseAccumulatorY;\r
 \r
+  UINTN                       SelectStart;          // starting from 1\r
+  UINTN                       SelectEnd;            // starting from 1\r
 } EFI_EDITOR_GLOBAL_EDITOR;\r
 \r
 #endif\r