2 Defines HBufferImage - the view of the file that is visible at any point,
3 as well as the event handlers for editing the file
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "HexEditor.h"
12 extern EFI_HANDLE HImageHandleBackup
;
14 extern HEFI_EDITOR_FILE_IMAGE HFileImage
;
15 extern HEFI_EDITOR_DISK_IMAGE HDiskImage
;
16 extern HEFI_EDITOR_MEM_IMAGE HMemImage
;
18 extern HEFI_EDITOR_FILE_IMAGE HFileImageBackupVar
;
19 extern HEFI_EDITOR_DISK_IMAGE HDiskImageBackupVar
;
20 extern HEFI_EDITOR_MEM_IMAGE HMemImageBackupVar
;
22 extern BOOLEAN HEditorMouseAction
;
24 extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
25 extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
27 HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
28 HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
31 // for basic initialization of HBufferImage
33 HEFI_EDITOR_BUFFER_IMAGE HBufferImageConst
= {
60 // the whole edit area needs to be refreshed
62 BOOLEAN HBufferImageNeedRefresh
;
65 // only the current line in edit area needs to be refresh
67 BOOLEAN HBufferImageOnlyLineNeedRefresh
;
69 BOOLEAN HBufferImageMouseNeedRefresh
;
72 Initialization function for HBufferImage
74 @retval EFI_SUCCESS The operation was successful.
75 @retval EFI_LOAD_ERROR A load error occured.
85 // basically initialize the HBufferImage
87 CopyMem (&HBufferImage
, &HBufferImageConst
, sizeof (HBufferImage
));
92 HBufferImage
.ListHead
= AllocateZeroPool (sizeof (LIST_ENTRY
));
93 if (HBufferImage
.ListHead
== NULL
) {
94 return EFI_LOAD_ERROR
;
97 InitializeListHead (HBufferImage
.ListHead
);
99 HBufferImage
.DisplayPosition
.Row
= 2;
100 HBufferImage
.DisplayPosition
.Column
= 10;
101 HBufferImage
.MousePosition
.Row
= 2;
102 HBufferImage
.MousePosition
.Column
= 10;
104 HBufferImage
.FileImage
= &HFileImage
;
105 HBufferImage
.DiskImage
= &HDiskImage
;
106 HBufferImage
.MemImage
= &HMemImage
;
108 HBufferImageNeedRefresh
= FALSE
;
109 HBufferImageOnlyLineNeedRefresh
= FALSE
;
110 HBufferImageMouseNeedRefresh
= FALSE
;
112 HBufferImageBackupVar
.FileImage
= &HFileImageBackupVar
;
113 HBufferImageBackupVar
.DiskImage
= &HDiskImageBackupVar
;
114 HBufferImageBackupVar
.MemImage
= &HMemImageBackupVar
;
116 Status
= HFileImageInit ();
117 if (EFI_ERROR (Status
)) {
118 return EFI_LOAD_ERROR
;
121 Status
= HDiskImageInit ();
122 if (EFI_ERROR (Status
)) {
123 return EFI_LOAD_ERROR
;
126 Status
= HMemImageInit ();
127 if (EFI_ERROR (Status
)) {
128 return EFI_LOAD_ERROR
;
135 Backup function for HBufferImage. Only a few fields need to be backup.
136 This is for making the file buffer refresh as few as possible.
138 @retval EFI_SUCCESS The operation was successful.
145 HBufferImageBackupVar
.MousePosition
= HBufferImage
.MousePosition
;
147 HBufferImageBackupVar
.BufferPosition
= HBufferImage
.BufferPosition
;
149 HBufferImageBackupVar
.Modified
= HBufferImage
.Modified
;
151 HBufferImageBackupVar
.BufferType
= HBufferImage
.BufferType
;
152 HBufferImageBackupVar
.LowVisibleRow
= HBufferImage
.LowVisibleRow
;
153 HBufferImageBackupVar
.HighBits
= HBufferImage
.HighBits
;
156 // three kinds of buffer supported
161 switch (HBufferImage
.BufferType
) {
162 case FileTypeFileBuffer
:
166 case FileTypeDiskBuffer
:
170 case FileTypeMemBuffer
:
182 Free all the lines in HBufferImage.
189 @retval EFI_SUCCESS The operation was successful.
192 HBufferImageFreeLines (
196 HFreeLines (HBufferImage
.ListHead
, HBufferImage
.Lines
);
198 HBufferImage
.Lines
= NULL
;
199 HBufferImage
.CurrentLine
= NULL
;
200 HBufferImage
.NumLines
= 0;
206 Cleanup function for HBufferImage
208 @retval EFI_SUCCESS The operation was successful.
211 HBufferImageCleanup (
218 // free all the lines
220 Status
= HBufferImageFreeLines ();
222 SHELL_FREE_NON_NULL (HBufferImage
.ListHead
);
223 HBufferImage
.ListHead
= NULL
;
225 HFileImageCleanup ();
226 HDiskImageCleanup ();
235 @param[in] Line The lline to print.
236 @param[in] Row The row on screen ( begin from 1 ).
237 @param[in] FRow The FRow.
238 @param[in] Orig The original color.
239 @param[in] New The color to print with.
241 @retval EFI_SUCCESS The operation was successful.
244 HBufferImagePrintLine (
245 IN HEFI_EDITOR_LINE
*Line
,
248 IN HEFI_EDITOR_COLOR_UNION Orig
,
249 IN HEFI_EDITOR_COLOR_UNION New
264 // variable initialization
271 // print the selected area in opposite color
273 if (HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
274 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
275 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
277 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
278 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
280 if (FRow
>= RowStart
&& FRow
<= RowEnd
) {
284 if (FRow
> RowStart
) {
294 if (!HEditorMouseAction
) {
299 ((INT32
)Row
- 2 + HBufferImage
.LowVisibleRow
- 1) * 0x10
304 for (Index
= 0; Index
< 0x08 && Index
< Line
->Size
; Index
++) {
309 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
315 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
317 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
320 Pos
= 10 + (Index
* 3);
321 if (Line
->Buffer
[Index
] < 0x10) {
322 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
327 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
329 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
334 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
335 while (Index
< 0x08) {
336 Pos
= 10 + (Index
* 3);
337 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
341 while (Index
< 0x10 && Index
< Line
->Size
) {
346 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
352 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
354 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
357 Pos
= 10 + (Index
* 3) + 1;
358 if (Line
->Buffer
[Index
] < 0x10) {
359 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
363 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
367 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
368 while (Index
< 0x10) {
369 Pos
= 10 + (Index
* 3) + 1;
370 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
374 // restore the original color
376 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
379 // PRINT the buffer content
381 if (!HEditorMouseAction
) {
382 for (Index
= 0; Index
< 0x10 && Index
< Line
->Size
; Index
++) {
383 Pos
= ASCII_POSITION
+ Index
;
386 // learned from shelle.h -- IsValidChar
388 if (Line
->Buffer
[Index
] >= L
' ') {
389 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", (CHAR16
) Line
->Buffer
[Index
]);
391 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", '.');
395 while (Index
< 0x10) {
396 Pos
= ASCII_POSITION
+ Index
;
397 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
402 // restore the abundant blank in hex edit area to original color
406 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
407 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
408 } else if (ColEnd
== 8) {
409 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
410 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
412 Pos
= 10 + (ColEnd
- 1) * 3 + 3;
413 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
421 Function to decide if a column number is stored in the high bits.
423 @param[in] Column The column to examine.
424 @param[out] FCol The actual column number.
426 @retval TRUE The actual column was in high bits and is now in FCol.
427 @retval FALSE There was not a column number in the high bits.
430 HBufferImageIsAtHighBits (
438 // NOW AFTER THE SUB, Column start from 0
439 // 23 AND 24 ARE BOTH BLANK
450 *FCol
= (Column
/ 3) + 1;
452 if (Column
% 3 == 0) {
456 if ((Column
% 3 == 2)) {
464 Decide if a point is in the already selected area.
466 @param[in] MouseRow The row of the point to test.
467 @param[in] MouseCol The col of the point to test.
469 @retval TRUE The point is in the selected area.
470 @retval FALSE The point is not in the selected area.
473 HBufferImageIsInSelectedArea (
487 // judge mouse position whether is in selected area
492 if (HMainEditor
.SelectStart
== 0 || HMainEditor
.SelectEnd
== 0) {
496 // calculate the select area
498 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
499 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
501 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
502 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
504 FRow
= HBufferImage
.LowVisibleRow
+ MouseRow
- 2;
505 if (FRow
< RowStart
|| FRow
> RowEnd
) {
509 if (FRow
> RowStart
) {
517 MouseColStart
= 10 + (ColStart
- 1) * 3;
522 MouseColEnd
= 10 + (ColEnd
- 1) * 3 + 1;
527 if (MouseCol
< MouseColStart
|| MouseCol
> MouseColEnd
) {
535 Set mouse position according to HBufferImage.MousePosition.
537 @retval EFI_SUCCESS The operation was successful.
540 HBufferImageRestoreMousePosition (
544 HEFI_EDITOR_COLOR_UNION Orig
;
545 HEFI_EDITOR_COLOR_UNION New
;
548 BOOLEAN HasCharacter
;
549 HEFI_EDITOR_LINE
*CurrentLine
;
550 HEFI_EDITOR_LINE
*Line
;
555 if (HMainEditor
.MouseSupported
) {
557 if (HBufferImageMouseNeedRefresh
) {
559 HBufferImageMouseNeedRefresh
= FALSE
;
562 // if mouse position not moved and only mouse action
563 // so do not need to refresh mouse position
566 HBufferImage
.MousePosition
.Row
== HBufferImageBackupVar
.MousePosition
.Row
&&
567 HBufferImage
.MousePosition
.Column
== HBufferImageBackupVar
.MousePosition
.Column
574 // backup the old screen attributes
576 Orig
= HMainEditor
.ColorAttributes
;
578 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
579 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
582 // if in selected area,
583 // so do not need to refresh mouse
585 if (!HBufferImageIsInSelectedArea (
586 HBufferImageBackupVar
.MousePosition
.Row
,
587 HBufferImageBackupVar
.MousePosition
.Column
589 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
591 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
594 // clear the old mouse position
596 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
598 HighBits
= HBufferImageIsAtHighBits (
599 HBufferImageBackupVar
.MousePosition
.Column
,
604 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
605 HasCharacter
= FALSE
;
607 CurrentLine
= HBufferImage
.CurrentLine
;
608 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
610 if (Line
== NULL
|| FColumn
> Line
->Size
) {
611 HasCharacter
= FALSE
;
614 HBufferImage
.CurrentLine
= CurrentLine
;
618 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
619 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
625 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
626 Value
= (UINT8
) (Value
>> 4);
628 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
632 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
633 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
639 if (!HBufferImageIsInSelectedArea (
640 HBufferImage
.MousePosition
.Row
,
641 HBufferImage
.MousePosition
.Column
643 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
645 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
648 // clear the old mouse position
650 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImage
.MousePosition
.Row
- 2;
652 HighBits
= HBufferImageIsAtHighBits (
653 HBufferImage
.MousePosition
.Column
,
658 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
659 HasCharacter
= FALSE
;
661 CurrentLine
= HBufferImage
.CurrentLine
;
662 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
664 if (Line
== NULL
|| FColumn
> Line
->Size
) {
665 HasCharacter
= FALSE
;
668 HBufferImage
.CurrentLine
= CurrentLine
;
672 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
673 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
679 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
680 Value
= (UINT8
) (Value
>> 4);
682 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
686 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
687 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
693 // end of HasCharacter
695 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
698 // end of MouseNeedRefresh
702 // end of MouseSupported
708 Set cursor position according to HBufferImage.DisplayPosition.
710 @retval EFI_SUCCESS The operation was successful.
713 HBufferImageRestorePosition (
718 // set cursor position
720 gST
->ConOut
->SetCursorPosition (
722 HBufferImage
.DisplayPosition
.Column
- 1,
723 HBufferImage
.DisplayPosition
.Row
- 1
730 Refresh function for HBufferImage.
732 @retval EFI_SUCCESS The operation was successful.
733 @retval EFI_LOAD_ERROR A Load error occured.
737 HBufferImageRefresh (
742 HEFI_EDITOR_LINE
*Line
;
744 HEFI_EDITOR_COLOR_UNION Orig
;
745 HEFI_EDITOR_COLOR_UNION New
;
752 Orig
= HMainEditor
.ColorAttributes
;
754 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
755 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
758 // if it's the first time after editor launch, so should refresh
760 if (HEditorFirst
== FALSE
) {
762 // no definite required refresh
763 // and file position displayed on screen has not been changed
765 if (!HBufferImageNeedRefresh
&&
766 !HBufferImageOnlyLineNeedRefresh
&&
767 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
769 HBufferImageRestoreMousePosition ();
770 HBufferImageRestorePosition ();
775 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
778 // only need to refresh current line
780 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
782 HBufferImagePrintLine (
783 HBufferImage
.CurrentLine
,
784 HBufferImage
.DisplayPosition
.Row
,
785 HBufferImage
.BufferPosition
.Row
,
791 // the whole edit area need refresh
793 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
794 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
795 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
796 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
798 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
801 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
804 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
805 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
807 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
812 if (StartRow
> EndRow
) {
818 FStartRow
= StartRow
;
820 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
821 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
825 // not mouse selection actions
827 FStartRow
= HBufferImage
.LowVisibleRow
;
829 EndRow
= (HMainEditor
.ScreenSize
.Row
- 1);
834 if (HBufferImage
.Lines
== NULL
) {
835 HBufferImageRestoreMousePosition ();
836 HBufferImageRestorePosition ();
837 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
841 // get the first line that will be displayed
843 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
845 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
846 return EFI_LOAD_ERROR
;
849 Link
= &(Line
->Link
);
852 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
857 HBufferImagePrintLine (
860 HBufferImage
.LowVisibleRow
+ Row
- 2,
865 Link
= Link
->ForwardLink
;
867 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
869 while (Row
<= EndRow
) {
870 EditorClearLine (Row
, HMainEditor
.ScreenSize
.Column
, HMainEditor
.ScreenSize
.Row
);
874 // while not file end and not screen full
878 HBufferImageRestoreMousePosition ();
879 HBufferImageRestorePosition ();
881 HBufferImageNeedRefresh
= FALSE
;
882 HBufferImageOnlyLineNeedRefresh
= FALSE
;
883 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
889 Read an image into a buffer friom a source.
891 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
892 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
893 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
894 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
895 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
896 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
897 @param[in] BufferType The type of buffer to save. IGNORED.
898 @param[in] Recover TRUE for recovermode, FALSE otherwise.
900 @return EFI_SUCCESS The operation was successful.
904 IN CONST CHAR16
*FileName
,
905 IN CONST CHAR16
*DiskName
,
910 IN EDIT_FILE_TYPE BufferType
,
915 EDIT_FILE_TYPE BufferTypeBackup
;
918 // variable initialization
920 Status
= EFI_SUCCESS
;
921 HBufferImage
.BufferType
= BufferType
;
924 // three types of buffer supported
929 BufferTypeBackup
= HBufferImage
.BufferType
;
931 switch (BufferType
) {
932 case FileTypeFileBuffer
:
933 Status
= HFileImageRead (FileName
, Recover
);
936 case FileTypeDiskBuffer
:
937 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
940 case FileTypeMemBuffer
:
941 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
945 Status
= EFI_NOT_FOUND
;
949 if (EFI_ERROR (Status
)) {
950 HBufferImage
.BufferType
= BufferTypeBackup
;
957 Save the current image.
959 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
960 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
961 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
962 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
963 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
964 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
965 @param[in] BufferType The type of buffer to save. IGNORED.
967 @return EFI_SUCCESS The operation was successful.
977 IN EDIT_FILE_TYPE BufferType
981 EDIT_FILE_TYPE BufferTypeBackup
;
984 // variable initialization
986 Status
= EFI_SUCCESS
;
987 BufferTypeBackup
= HBufferImage
.BufferType
;
989 switch (HBufferImage
.BufferType
) {
993 case FileTypeFileBuffer
:
994 Status
= HFileImageSave (FileName
);
1000 case FileTypeDiskBuffer
:
1001 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1007 case FileTypeMemBuffer
:
1008 Status
= HMemImageSave (MemOffset
, MemSize
);
1012 Status
= EFI_NOT_FOUND
;
1016 if (EFI_ERROR (Status
)) {
1017 HBufferImage
.BufferType
= BufferTypeBackup
;
1024 Create a new line and append it to the line list.
1029 @retval NULL create line failed.
1030 @return the line created.
1034 HBufferImageCreateLine (
1038 HEFI_EDITOR_LINE
*Line
;
1041 // allocate for line structure
1043 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1048 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1051 HBufferImage
.NumLines
++;
1054 // insert to line list
1056 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1058 if (HBufferImage
.Lines
== NULL
) {
1059 HBufferImage
.Lines
= CR (
1060 HBufferImage
.ListHead
->ForwardLink
,
1063 EFI_EDITOR_LINE_LIST
1071 Free the current image.
1073 @retval EFI_SUCCESS The operation was successful.
1083 HBufferImageFreeLines ();
1089 change char to int value based on Hex.
1091 @param[in] Char The input char.
1093 @return The character's index value.
1094 @retval -1 The operation failed.
1097 HBufferImageCharToHex (
1102 // change the character to hex
1104 if (Char
>= L
'0' && Char
<= L
'9') {
1105 return (Char
- L
'0');
1108 if (Char
>= L
'a' && Char
<= L
'f') {
1109 return (Char
- L
'a' + 10);
1112 if (Char
>= L
'A' && Char
<= L
'F') {
1113 return (Char
- L
'A' + 10);
1122 @param[in] Char -- input char.
1124 @retval EFI_SUCCESS The operation was successful.
1125 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1128 HBufferImageAddChar (
1132 HEFI_EDITOR_LINE
*Line
;
1133 HEFI_EDITOR_LINE
*NewLine
;
1140 Value
= HBufferImageCharToHex (Char
);
1149 Line
= HBufferImage
.CurrentLine
;
1150 FRow
= HBufferImage
.BufferPosition
.Row
;
1151 FCol
= HBufferImage
.BufferPosition
.Column
;
1152 High
= HBufferImage
.HighBits
;
1155 // only needs to refresh current line
1157 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1160 // not a full line and beyond the last character
1162 if (FCol
> Line
->Size
) {
1164 // cursor always at high 4 bits
1165 // and always put input to the low 4 bits
1167 Line
->Buffer
[Line
->Size
] = (UINT8
) Value
;
1172 Old
= Line
->Buffer
[FCol
- 1];
1175 // always put the input to the low 4 bits
1177 Old
= (UINT8
) (Old
& 0x0f);
1178 Old
= (UINT8
) (Old
<< 4);
1179 Old
= (UINT8
) (Value
+ Old
);
1180 Line
->Buffer
[FCol
- 1] = Old
;
1183 // at the low 4 bits of the last character of a full line
1184 // so if no next line, need to create a new line
1186 if (!High
&& FCol
== 0x10) {
1188 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1189 HBufferImageNeedRefresh
= TRUE
;
1191 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1195 // create a new line
1197 NewLine
= HBufferImageCreateLine ();
1198 if (NewLine
== NULL
) {
1199 return EFI_OUT_OF_RESOURCES
;
1206 // end of == ListHead
1212 // if already at end of this line, scroll it to the start of next line
1214 if (FCol
== 0x10 && !High
) {
1216 // definitely has next line
1223 // if not at end of this line, just move to next column
1241 // move cursor to right
1243 HBufferImageMovePosition (FRow
, FCol
, High
);
1245 if (!HBufferImage
.Modified
) {
1246 HBufferImage
.Modified
= TRUE
;
1253 Delete the previous character.
1255 @retval EFI_SUCCESS The operationw as successful.
1258 HBufferImageDoBackspace (
1262 HEFI_EDITOR_LINE
*Line
;
1269 // variable initialization
1274 // already the first character
1276 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
1280 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1282 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1284 Line
= HBufferImage
.CurrentLine
;
1286 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
1290 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1293 // if is the last line
1294 // then only this line need to be refreshed
1297 HBufferImageNeedRefresh
= FALSE
;
1298 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1300 HBufferImageNeedRefresh
= TRUE
;
1301 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1304 if (!HBufferImage
.Modified
) {
1305 HBufferImage
.Modified
= TRUE
;
1312 ASCII key + Backspace + return.
1314 @param[in] Char The input char.
1316 @retval EFI_SUCCESS The operation was successful.
1317 @retval EFI_LOAD_ERROR A load error occured.
1318 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1321 HBufferImageDoCharInput (
1327 Status
= EFI_SUCCESS
;
1334 Status
= HBufferImageDoBackspace ();
1341 // Tabs, Returns are thought as nothing
1347 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1349 if (Char
> 127 || Char
< 32) {
1350 Status
= StatusBarSetStatusString (L
"Unknown Command");
1352 Status
= HBufferImageAddChar (Char
);
1362 Check user specified FileRow is above current screen.
1364 @param[in] FileRow Row of file position ( start from 1 ).
1366 @retval TRUE It is above the current screen.
1367 @retval FALSE It is not above the current screen.
1371 HAboveCurrentScreen (
1375 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1383 Check user specified FileRow is under current screen.
1385 @param[in] FileRow Row of file position ( start from 1 ).
1387 @retval TRUE It is under the current screen.
1388 @retval FALSE It is not under the current screen.
1392 HUnderCurrentScreen (
1396 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 2) - 1) {
1404 According to cursor's file position, adjust screen display.
1406 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1407 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1408 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1411 HBufferImageMovePosition (
1412 IN UINTN NewFilePosRow
,
1413 IN UINTN NewFilePosCol
,
1421 UINTN NewDisplayCol
;
1424 // CALCULATE gap between current file position and new file position
1426 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1428 Under
= HUnderCurrentScreen (NewFilePosRow
);
1429 Above
= HAboveCurrentScreen (NewFilePosRow
);
1431 HBufferImage
.HighBits
= HighBits
;
1434 // if is below current screen
1438 // display row will be unchanged
1440 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1444 // has enough above line, so display row unchanged
1445 // not has enough above lines, so the first line is
1446 // at the first display line
1448 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1449 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1452 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1455 // in current screen
1457 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1459 Abs
= (UINTN
)ABS(RowGap
);
1460 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1462 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1468 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1471 // always in current screen
1473 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1475 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1476 if (NewFilePosCol
> 0x8) {
1484 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1487 // let CurrentLine point to correct line;
1489 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1494 Scroll cursor to right.
1496 @retval EFI_SUCCESS The operation was successful.
1499 HBufferImageScrollRight (
1503 HEFI_EDITOR_LINE
*Line
;
1508 // scroll right will always move to the high4 bits of the next character
1510 HBufferImageNeedRefresh
= FALSE
;
1511 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1513 Line
= HBufferImage
.CurrentLine
;
1515 FRow
= HBufferImage
.BufferPosition
.Row
;
1516 FCol
= HBufferImage
.BufferPosition
.Column
;
1519 // this line is not full and no next line
1521 if (FCol
> Line
->Size
) {
1525 // if already at end of this line, scroll it to the start of next line
1531 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1540 // if not at end of this line, just move to next column
1546 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1552 Scroll cursor to left.
1554 @retval EFI_SUCCESS The operation was successful.
1557 HBufferImageScrollLeft (
1562 HEFI_EDITOR_LINE
*Line
;
1566 HBufferImageNeedRefresh
= FALSE
;
1567 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1569 Line
= HBufferImage
.CurrentLine
;
1571 FRow
= HBufferImage
.BufferPosition
.Row
;
1572 FCol
= HBufferImage
.BufferPosition
.Column
;
1575 // if already at start of this line, so move to the end of previous line
1579 // has previous line
1581 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1583 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1590 // if not at start of this line, just move to previous column
1595 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1601 Scroll cursor to the next line
1603 @retval EFI_SUCCESS The operation was successful.
1606 HBufferImageScrollDown (
1610 HEFI_EDITOR_LINE
*Line
;
1615 Line
= HBufferImage
.CurrentLine
;
1617 FRow
= HBufferImage
.BufferPosition
.Row
;
1618 FCol
= HBufferImage
.BufferPosition
.Column
;
1619 HighBits
= HBufferImage
.HighBits
;
1624 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1626 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1629 // if the next line is not that long, so move to end of next line
1631 if (FCol
> Line
->Size
) {
1632 FCol
= Line
->Size
+ 1;
1640 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1646 Scroll cursor to previous line
1648 @retval EFI_SUCCESS The operation was successful.
1651 HBufferImageScrollUp (
1655 HEFI_EDITOR_LINE
*Line
;
1659 Line
= HBufferImage
.CurrentLine
;
1661 FRow
= HBufferImage
.BufferPosition
.Row
;
1662 FCol
= HBufferImage
.BufferPosition
.Column
;
1665 // has previous line
1667 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1674 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1680 Scroll cursor to next page
1682 @retval EFI_SUCCESS The operation was successful.
1685 HBufferImagePageDown (
1689 HEFI_EDITOR_LINE
*Line
;
1695 Line
= HBufferImage
.CurrentLine
;
1697 FRow
= HBufferImage
.BufferPosition
.Row
;
1698 FCol
= HBufferImage
.BufferPosition
.Column
;
1699 HighBits
= HBufferImage
.HighBits
;
1704 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 2)) {
1705 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1708 // MOVE CURSOR TO LAST LINE
1710 Gap
= HBufferImage
.NumLines
- FRow
;
1715 Line
= HMoveLine (Gap
);
1718 // if that line, is not that long, so move to the end of that line
1720 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1721 FCol
= Line
->Size
+ 1;
1727 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1733 Scroll cursor to previous page
1735 @retval EFI_SUCCESS The operation was successful.
1738 HBufferImagePageUp (
1747 FRow
= HBufferImage
.BufferPosition
.Row
;
1748 FCol
= HBufferImage
.BufferPosition
.Column
;
1751 // has previous page
1753 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 2)) {
1754 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1757 // the first line of file will displayed on the first line of screen
1767 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1773 Scroll cursor to start of line
1775 @retval EFI_SUCCESS The operation was successful.
1787 // curosr will at the high bit
1789 FRow
= HBufferImage
.BufferPosition
.Row
;
1794 // move cursor position
1796 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1802 Scroll cursor to end of line.
1804 @retval EFI_SUCCESS Teh operation was successful.
1811 HEFI_EDITOR_LINE
*Line
;
1817 // need refresh mouse
1819 HBufferImageMouseNeedRefresh
= TRUE
;
1821 Line
= HBufferImage
.CurrentLine
;
1823 FRow
= HBufferImage
.BufferPosition
.Row
;
1825 if (Line
->Size
== 0x10) {
1829 FCol
= Line
->Size
+ 1;
1833 // move cursor position
1835 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1841 Get the size of the open buffer.
1843 @retval The size in bytes.
1846 HBufferImageGetTotalSize (
1852 HEFI_EDITOR_LINE
*Line
;
1855 // calculate the total size of whole line list's buffer
1857 if (HBufferImage
.Lines
== NULL
) {
1862 HBufferImage
.ListHead
->BackLink
,
1865 EFI_EDITOR_LINE_LIST
1868 // one line at most 0x10
1870 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1876 Delete character from buffer.
1878 @param[in] Pos Position, Pos starting from 0.
1879 @param[in] Count The Count of characters to delete.
1880 @param[out] DeleteBuffer The DeleteBuffer.
1882 @retval EFI_SUCCESS Success
1885 HBufferImageDeleteCharacterFromBuffer (
1888 OUT UINT8
*DeleteBuffer
1897 HEFI_EDITOR_LINE
*Line
;
1908 Size
= HBufferImageGetTotalSize ();
1911 return EFI_LOAD_ERROR
;
1919 // relocate all the HBufferImage fields
1921 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1922 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1923 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1927 // has character before it,
1928 // so locate according to block's previous character
1934 // has no character before it,
1935 // so locate according to block's next character
1940 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1942 Buffer
= AllocateZeroPool (Size
);
1943 if (Buffer
== NULL
) {
1944 return EFI_OUT_OF_RESOURCES
;
1947 HBufferImageListToBuffer (Buffer
, Size
);
1949 BufferPtr
= (UINT8
*) Buffer
;
1952 // pass deleted buffer out
1954 if (DeleteBuffer
!= NULL
) {
1955 for (Index
= 0; Index
< Count
; Index
++) {
1956 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1960 // delete the part from Pos
1962 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1963 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1968 HBufferImageFreeLines ();
1970 Status
= HBufferImageBufferToList (Buffer
, Size
);
1973 if (EFI_ERROR (Status
)) {
1977 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1978 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
1979 Link
= Link
->ForwardLink
;
1982 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1983 HBufferImage
.CurrentLine
= Line
;
1986 // if current cursor position if inside select area
1987 // then move it to the block's NEXT character
1989 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
1995 NewPos
= OldPos
- Count
;
1999 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2005 Add character to buffer, add before pos.
2007 @param[in] Pos Position, Pos starting from 0.
2008 @param[in] Count Count of characters to add.
2009 @param[in] AddBuffer Add buffer.
2011 @retval EFI_SUCCESS Success.
2014 HBufferImageAddCharacterToBuffer (
2026 HEFI_EDITOR_LINE
*Line
;
2036 Size
= HBufferImageGetTotalSize ();
2039 // relocate all the HBufferImage fields
2041 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2042 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2043 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2046 // move cursor before Pos
2054 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2056 Buffer
= AllocateZeroPool (Size
+ Count
);
2057 if (Buffer
== NULL
) {
2058 return EFI_OUT_OF_RESOURCES
;
2061 HBufferImageListToBuffer (Buffer
, Size
);
2063 BufferPtr
= (UINT8
*) Buffer
;
2066 // get a place to add
2068 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2069 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2074 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2075 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2080 HBufferImageFreeLines ();
2082 HBufferImageBufferToList (Buffer
, Size
);
2086 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2087 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2088 Link
= Link
->ForwardLink
;
2091 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2092 HBufferImage
.CurrentLine
= Line
;
2094 if (OldPos
>= Pos
) {
2095 NewPos
= OldPos
+ Count
;
2100 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2106 Delete current character from line.
2108 @retval EFI_SUCCESS The operationw as successful.
2111 HBufferImageDoDelete (
2116 HEFI_EDITOR_LINE
*Line
;
2122 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2124 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2126 Line
= HBufferImage
.CurrentLine
;
2129 // if beyond the last character
2131 if (FileColumn
> Line
->Size
) {
2136 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2140 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2143 // if is the last line
2144 // then only this line need to be refreshed
2147 HBufferImageNeedRefresh
= FALSE
;
2148 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2150 HBufferImageNeedRefresh
= TRUE
;
2151 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2154 if (!HBufferImage
.Modified
) {
2155 HBufferImage
.Modified
= TRUE
;
2162 Change the raw buffer to a list of lines for the UI.
2164 @param[in] Buffer The pointer to the buffer to fill.
2165 @param[in] Bytes The size of the buffer in bytes.
2167 @retval EFI_SUCCESS The operation was successful.
2168 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2171 HBufferImageBufferToList (
2179 HEFI_EDITOR_LINE
*Line
;
2184 BufferPtr
= (UINT8
*) Buffer
;
2187 // parse file content line by line
2189 while (TempI
< Bytes
) {
2190 if (Bytes
- TempI
>= 0x10) {
2193 Left
= Bytes
- TempI
;
2197 // allocate a new line
2199 Line
= HBufferImageCreateLine ();
2201 return EFI_OUT_OF_RESOURCES
;
2206 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2207 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2214 // last line is a full line, SO create a new line
2216 if (Left
== 0x10 || Bytes
== 0) {
2217 Line
= HBufferImageCreateLine ();
2219 return EFI_OUT_OF_RESOURCES
;
2227 Change the list of lines from the UI to a raw buffer.
2229 @param[in] Buffer The pointer to the buffer to fill.
2230 @param[in] Bytes The size of the buffer in bytes.
2232 @retval EFI_SUCCESS The operation was successful.
2235 HBufferImageListToBuffer (
2242 HEFI_EDITOR_LINE
*Line
;
2247 // change the line list to a large buffer
2249 if (HBufferImage
.Lines
== NULL
) {
2253 Link
= &HBufferImage
.Lines
->Link
;
2255 BufferPtr
= (UINT8
*) Buffer
;
2258 // deal line by line
2260 while (Link
!= HBufferImage
.ListHead
) {
2262 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2264 //@todo shouldn't this be an error???
2265 if (Count
+ Line
->Size
> Bytes
) {
2269 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2270 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2273 Count
+= Line
->Size
;
2274 BufferPtr
+= Line
->Size
;
2276 Link
= Link
->ForwardLink
;
2283 Move the mouse in the image buffer.
2285 @param[in] TextX The x-coordinate.
2286 @param[in] TextY The y-coordinate.
2289 HBufferImageAdjustMousePosition (
2300 // TextX and TextY is mouse movement data returned by mouse driver
2301 // This function will change it to MousePosition
2304 // get absolute TempX value
2312 // get absolute TempY value
2320 TempX
= HBufferImage
.MousePosition
.Column
;
2321 TempY
= HBufferImage
.MousePosition
.Row
;
2326 if (TempX
>= AbsX
) {
2336 if (TempY
>= AbsY
) {
2343 // check whether new mouse column position is beyond screen
2344 // if not, adjust it
2346 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2347 HBufferImage
.MousePosition
.Column
= TempX
;
2348 } else if (TempX
< 10) {
2349 HBufferImage
.MousePosition
.Column
= 10;
2350 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2351 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2354 // check whether new mouse row position is beyond screen
2355 // if not, adjust it
2357 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 1)) {
2358 HBufferImage
.MousePosition
.Row
= TempY
;
2359 } else if (TempY
< 2) {
2360 HBufferImage
.MousePosition
.Row
= 2;
2361 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 1)) {
2362 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 1);
2368 Dispatch input to different handler
2370 @param[in] Key The input key:
2374 Direction key: up/down/left/right/pgup/pgdn
2378 @retval EFI_SUCCESS The operation was successful.
2379 @retval EFI_LOAD_ERROR A load error occured.
2380 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2383 HBufferImageHandleInput (
2384 IN EFI_INPUT_KEY
*Key
2389 Status
= EFI_SUCCESS
;
2391 switch (Key
->ScanCode
) {
2396 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2403 Status
= HBufferImageScrollUp ();
2410 Status
= HBufferImageScrollDown ();
2417 Status
= HBufferImageScrollRight ();
2424 Status
= HBufferImageScrollLeft ();
2431 Status
= HBufferImagePageUp ();
2437 case SCAN_PAGE_DOWN
:
2438 Status
= HBufferImagePageDown ();
2445 Status
= HBufferImageDoDelete ();
2452 Status
= HBufferImageHome ();
2459 Status
= HBufferImageEnd ();
2463 Status
= StatusBarSetStatusString (L
"Unknown Command");