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 occurred.
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 ();
234 @param[in] Line The lline to print.
235 @param[in] Row The row on screen ( begin from 1 ).
236 @param[in] FRow The FRow.
237 @param[in] Orig The original color.
238 @param[in] New The color to print with.
240 @retval EFI_SUCCESS The operation was successful.
243 HBufferImagePrintLine (
244 IN HEFI_EDITOR_LINE
*Line
,
247 IN HEFI_EDITOR_COLOR_UNION Orig
,
248 IN HEFI_EDITOR_COLOR_UNION New
262 // variable initialization
269 // print the selected area in opposite color
271 if ((HMainEditor
.SelectStart
!= 0) && (HMainEditor
.SelectEnd
!= 0)) {
272 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
273 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
275 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
276 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
278 if ((FRow
>= RowStart
) && (FRow
<= RowEnd
)) {
282 if (FRow
> RowStart
) {
291 if (!HEditorMouseAction
) {
296 ((INT32
)Row
- 2 + HBufferImage
.LowVisibleRow
- 1) * 0x10
300 for (Index
= 0; Index
< 0x08 && Index
< Line
->Size
; Index
++) {
304 if ((Index
+ 1 >= ColStart
) && (Index
+ 1 <= ColEnd
)) {
310 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
312 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
315 Pos
= 10 + (Index
* 3);
316 if (Line
->Buffer
[Index
] < 0x10) {
317 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
322 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
324 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
328 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
329 while (Index
< 0x08) {
330 Pos
= 10 + (Index
* 3);
331 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
335 while (Index
< 0x10 && Index
< Line
->Size
) {
339 if ((Index
+ 1 >= ColStart
) && (Index
+ 1 <= ColEnd
)) {
345 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
347 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
350 Pos
= 10 + (Index
* 3) + 1;
351 if (Line
->Buffer
[Index
] < 0x10) {
352 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
356 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
360 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
361 while (Index
< 0x10) {
362 Pos
= 10 + (Index
* 3) + 1;
363 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
368 // restore the original color
370 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
373 // PRINT the buffer content
375 if (!HEditorMouseAction
) {
376 for (Index
= 0; Index
< 0x10 && Index
< Line
->Size
; Index
++) {
377 Pos
= ASCII_POSITION
+ Index
;
380 // learned from shelle.h -- IsValidChar
382 if (Line
->Buffer
[Index
] >= L
' ') {
383 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", (CHAR16
)Line
->Buffer
[Index
]);
385 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", '.');
389 while (Index
< 0x10) {
390 Pos
= ASCII_POSITION
+ Index
;
391 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
397 // restore the abundant blank in hex edit area to original color
401 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
402 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
403 } else if (ColEnd
== 8) {
404 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
405 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
407 Pos
= 10 + (ColEnd
- 1) * 3 + 3;
408 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
416 Function to decide if a column number is stored in the high bits.
418 @param[in] Column The column to examine.
419 @param[out] FCol The actual column number.
421 @retval TRUE The actual column was in high bits and is now in FCol.
422 @retval FALSE There was not a column number in the high bits.
425 HBufferImageIsAtHighBits (
433 // NOW AFTER THE SUB, Column start from 0
434 // 23 AND 24 ARE BOTH BLANK
445 *FCol
= (Column
/ 3) + 1;
447 if (Column
% 3 == 0) {
451 if ((Column
% 3 == 2)) {
459 Decide if a point is in the already selected area.
461 @param[in] MouseRow The row of the point to test.
462 @param[in] MouseCol The col of the point to test.
464 @retval TRUE The point is in the selected area.
465 @retval FALSE The point is not in the selected area.
468 HBufferImageIsInSelectedArea (
482 // judge mouse position whether is in selected area
487 if ((HMainEditor
.SelectStart
== 0) || (HMainEditor
.SelectEnd
== 0)) {
492 // calculate the select area
494 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
495 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
497 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
498 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
500 FRow
= HBufferImage
.LowVisibleRow
+ MouseRow
- 2;
501 if ((FRow
< RowStart
) || (FRow
> RowEnd
)) {
505 if (FRow
> RowStart
) {
513 MouseColStart
= 10 + (ColStart
- 1) * 3;
518 MouseColEnd
= 10 + (ColEnd
- 1) * 3 + 1;
523 if ((MouseCol
< MouseColStart
) || (MouseCol
> MouseColEnd
)) {
531 Set mouse position according to HBufferImage.MousePosition.
533 @retval EFI_SUCCESS The operation was successful.
536 HBufferImageRestoreMousePosition (
540 HEFI_EDITOR_COLOR_UNION Orig
;
541 HEFI_EDITOR_COLOR_UNION New
;
544 BOOLEAN HasCharacter
;
545 HEFI_EDITOR_LINE
*CurrentLine
;
546 HEFI_EDITOR_LINE
*Line
;
551 if (HMainEditor
.MouseSupported
) {
552 if (HBufferImageMouseNeedRefresh
) {
553 HBufferImageMouseNeedRefresh
= FALSE
;
556 // if mouse position not moved and only mouse action
557 // so do not need to refresh mouse position
560 (HBufferImage
.MousePosition
.Row
== HBufferImageBackupVar
.MousePosition
.Row
) &&
561 (HBufferImage
.MousePosition
.Column
== HBufferImageBackupVar
.MousePosition
.Column
)
570 // backup the old screen attributes
572 Orig
= HMainEditor
.ColorAttributes
;
574 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
575 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
578 // if in selected area,
579 // so do not need to refresh mouse
581 if (!HBufferImageIsInSelectedArea (
582 HBufferImageBackupVar
.MousePosition
.Row
,
583 HBufferImageBackupVar
.MousePosition
.Column
586 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
588 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
592 // clear the old mouse position
594 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
596 HighBits
= HBufferImageIsAtHighBits (
597 HBufferImageBackupVar
.MousePosition
.Column
,
602 if ((FRow
> HBufferImage
.NumLines
) || (FColumn
== 0)) {
603 HasCharacter
= FALSE
;
605 CurrentLine
= HBufferImage
.CurrentLine
;
606 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
608 if ((Line
== NULL
) || (FColumn
> Line
->Size
)) {
609 HasCharacter
= FALSE
;
612 HBufferImage
.CurrentLine
= CurrentLine
;
616 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
617 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
623 Value
= (UINT8
)(Line
->Buffer
[FColumn
- 1] & 0xf0);
624 Value
= (UINT8
)(Value
>> 4);
626 Value
= (UINT8
)(Line
->Buffer
[FColumn
- 1] & 0xf);
630 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
631 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
637 if (!HBufferImageIsInSelectedArea (
638 HBufferImage
.MousePosition
.Row
,
639 HBufferImage
.MousePosition
.Column
642 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
644 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,
694 // end of HasCharacter
696 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
700 // end of MouseNeedRefresh
705 // end of MouseSupported
711 Set cursor position according to HBufferImage.DisplayPosition.
713 @retval EFI_SUCCESS The operation was successful.
716 HBufferImageRestorePosition (
721 // set cursor position
723 gST
->ConOut
->SetCursorPosition (
725 HBufferImage
.DisplayPosition
.Column
- 1,
726 HBufferImage
.DisplayPosition
.Row
- 1
733 Refresh function for HBufferImage.
735 @retval EFI_SUCCESS The operation was successful.
736 @retval EFI_LOAD_ERROR A Load error occurred.
740 HBufferImageRefresh (
745 HEFI_EDITOR_LINE
*Line
;
747 HEFI_EDITOR_COLOR_UNION Orig
;
748 HEFI_EDITOR_COLOR_UNION New
;
755 Orig
= HMainEditor
.ColorAttributes
;
757 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
758 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
761 // if it's the first time after editor launch, so should refresh
763 if (HEditorFirst
== FALSE
) {
765 // no definite required refresh
766 // and file position displayed on screen has not been changed
768 if (!HBufferImageNeedRefresh
&&
769 !HBufferImageOnlyLineNeedRefresh
&&
770 (HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
)
773 HBufferImageRestoreMousePosition ();
774 HBufferImageRestorePosition ();
779 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
782 // only need to refresh current line
784 if (HBufferImageOnlyLineNeedRefresh
&& (HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
)) {
785 HBufferImagePrintLine (
786 HBufferImage
.CurrentLine
,
787 HBufferImage
.DisplayPosition
.Row
,
788 HBufferImage
.BufferPosition
.Row
,
794 // the whole edit area need refresh
796 if (HEditorMouseAction
&& (HMainEditor
.SelectStart
!= 0) && (HMainEditor
.SelectEnd
!= 0)) {
797 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
798 if ((HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
) && (HMainEditorBackupVar
.SelectStart
!= 0)) {
799 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
801 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
804 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
807 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
808 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
810 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
816 if (StartRow
> EndRow
) {
822 FStartRow
= StartRow
;
824 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
825 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
828 // not mouse selection actions
830 FStartRow
= HBufferImage
.LowVisibleRow
;
832 EndRow
= (HMainEditor
.ScreenSize
.Row
- 1);
838 if (HBufferImage
.Lines
== NULL
) {
839 HBufferImageRestoreMousePosition ();
840 HBufferImageRestorePosition ();
841 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
846 // get the first line that will be displayed
848 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
850 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
851 return EFI_LOAD_ERROR
;
854 Link
= &(Line
->Link
);
857 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
862 HBufferImagePrintLine (
865 HBufferImage
.LowVisibleRow
+ Row
- 2,
870 Link
= Link
->ForwardLink
;
872 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
874 while (Row
<= EndRow
) {
875 EditorClearLine (Row
, HMainEditor
.ScreenSize
.Column
, HMainEditor
.ScreenSize
.Row
);
880 // while not file end and not screen full
884 HBufferImageRestoreMousePosition ();
885 HBufferImageRestorePosition ();
887 HBufferImageNeedRefresh
= FALSE
;
888 HBufferImageOnlyLineNeedRefresh
= FALSE
;
889 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
895 Read an image into a buffer friom a source.
897 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
898 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
899 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
900 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
901 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
902 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
903 @param[in] BufferType The type of buffer to save. IGNORED.
904 @param[in] Recover TRUE for recovermode, FALSE otherwise.
906 @return EFI_SUCCESS The operation was successful.
910 IN CONST CHAR16
*FileName
,
911 IN CONST CHAR16
*DiskName
,
916 IN EDIT_FILE_TYPE BufferType
,
921 EDIT_FILE_TYPE BufferTypeBackup
;
924 // variable initialization
926 Status
= EFI_SUCCESS
;
927 HBufferImage
.BufferType
= BufferType
;
930 // three types of buffer supported
935 BufferTypeBackup
= HBufferImage
.BufferType
;
937 switch (BufferType
) {
938 case FileTypeFileBuffer
:
939 Status
= HFileImageRead (FileName
, Recover
);
942 case FileTypeDiskBuffer
:
943 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
946 case FileTypeMemBuffer
:
947 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
951 Status
= EFI_NOT_FOUND
;
955 if (EFI_ERROR (Status
)) {
956 HBufferImage
.BufferType
= BufferTypeBackup
;
963 Save the current image.
965 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
966 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
967 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
968 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
969 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
970 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
971 @param[in] BufferType The type of buffer to save. IGNORED.
973 @return EFI_SUCCESS The operation was successful.
983 IN EDIT_FILE_TYPE BufferType
987 EDIT_FILE_TYPE BufferTypeBackup
;
990 // variable initialization
992 Status
= EFI_SUCCESS
;
993 BufferTypeBackup
= HBufferImage
.BufferType
;
995 switch (HBufferImage
.BufferType
) {
999 case FileTypeFileBuffer
:
1000 Status
= HFileImageSave (FileName
);
1006 case FileTypeDiskBuffer
:
1007 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1013 case FileTypeMemBuffer
:
1014 Status
= HMemImageSave (MemOffset
, MemSize
);
1018 Status
= EFI_NOT_FOUND
;
1022 if (EFI_ERROR (Status
)) {
1023 HBufferImage
.BufferType
= BufferTypeBackup
;
1030 Create a new line and append it to the line list.
1035 @retval NULL create line failed.
1036 @return the line created.
1040 HBufferImageCreateLine (
1044 HEFI_EDITOR_LINE
*Line
;
1047 // allocate for line structure
1049 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1054 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1057 HBufferImage
.NumLines
++;
1060 // insert to line list
1062 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1064 if (HBufferImage
.Lines
== NULL
) {
1065 HBufferImage
.Lines
= CR (
1066 HBufferImage
.ListHead
->ForwardLink
,
1069 EFI_EDITOR_LINE_LIST
1077 Free the current image.
1079 @retval EFI_SUCCESS The operation was successful.
1089 HBufferImageFreeLines ();
1095 change char to int value based on Hex.
1097 @param[in] Char The input char.
1099 @return The character's index value.
1100 @retval -1 The operation failed.
1103 HBufferImageCharToHex (
1108 // change the character to hex
1110 if ((Char
>= L
'0') && (Char
<= L
'9')) {
1111 return (Char
- L
'0');
1114 if ((Char
>= L
'a') && (Char
<= L
'f')) {
1115 return (Char
- L
'a' + 10);
1118 if ((Char
>= L
'A') && (Char
<= L
'F')) {
1119 return (Char
- L
'A' + 10);
1128 @param[in] Char -- input char.
1130 @retval EFI_SUCCESS The operation was successful.
1131 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1134 HBufferImageAddChar (
1138 HEFI_EDITOR_LINE
*Line
;
1139 HEFI_EDITOR_LINE
*NewLine
;
1146 Value
= HBufferImageCharToHex (Char
);
1155 Line
= HBufferImage
.CurrentLine
;
1156 FRow
= HBufferImage
.BufferPosition
.Row
;
1157 FCol
= HBufferImage
.BufferPosition
.Column
;
1158 High
= HBufferImage
.HighBits
;
1161 // only needs to refresh current line
1163 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1166 // not a full line and beyond the last character
1168 if (FCol
> Line
->Size
) {
1170 // cursor always at high 4 bits
1171 // and always put input to the low 4 bits
1173 Line
->Buffer
[Line
->Size
] = (UINT8
)Value
;
1177 Old
= Line
->Buffer
[FCol
- 1];
1180 // always put the input to the low 4 bits
1182 Old
= (UINT8
)(Old
& 0x0f);
1183 Old
= (UINT8
)(Old
<< 4);
1184 Old
= (UINT8
)(Value
+ Old
);
1185 Line
->Buffer
[FCol
- 1] = Old
;
1188 // at the low 4 bits of the last character of a full line
1189 // so if no next line, need to create a new line
1191 if (!High
&& (FCol
== 0x10)) {
1192 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1193 HBufferImageNeedRefresh
= TRUE
;
1195 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1199 // create a new line
1201 NewLine
= HBufferImageCreateLine ();
1202 if (NewLine
== NULL
) {
1203 return EFI_OUT_OF_RESOURCES
;
1212 // end of == ListHead
1219 // if already at end of this line, scroll it to the start of next line
1221 if ((FCol
== 0x10) && !High
) {
1223 // definitely has next line
1230 // if not at end of this line, just move to next column
1249 // move cursor to right
1251 HBufferImageMovePosition (FRow
, FCol
, High
);
1253 if (!HBufferImage
.Modified
) {
1254 HBufferImage
.Modified
= TRUE
;
1261 Delete the previous character.
1263 @retval EFI_SUCCESS The operationw as successful.
1266 HBufferImageDoBackspace (
1270 HEFI_EDITOR_LINE
*Line
;
1277 // variable initialization
1282 // already the first character
1284 if ((HBufferImage
.BufferPosition
.Row
== 1) && (HBufferImage
.BufferPosition
.Column
== 1)) {
1288 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1290 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1292 Line
= HBufferImage
.CurrentLine
;
1294 if ((Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) && (FileColumn
> 1)) {
1298 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1301 // if is the last line
1302 // then only this line need to be refreshed
1305 HBufferImageNeedRefresh
= FALSE
;
1306 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1308 HBufferImageNeedRefresh
= TRUE
;
1309 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1312 if (!HBufferImage
.Modified
) {
1313 HBufferImage
.Modified
= TRUE
;
1320 ASCII key + Backspace + return.
1322 @param[in] Char The input char.
1324 @retval EFI_SUCCESS The operation was successful.
1325 @retval EFI_LOAD_ERROR A load error occurred.
1326 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1329 HBufferImageDoCharInput (
1335 Status
= EFI_SUCCESS
;
1342 Status
= HBufferImageDoBackspace ();
1349 // Tabs, Returns are thought as nothing
1355 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1357 if ((Char
> 127) || (Char
< 32)) {
1358 Status
= StatusBarSetStatusString (L
"Unknown Command");
1360 Status
= HBufferImageAddChar (Char
);
1370 Check user specified FileRow is above current screen.
1372 @param[in] FileRow Row of file position ( start from 1 ).
1374 @retval TRUE It is above the current screen.
1375 @retval FALSE It is not above the current screen.
1379 HAboveCurrentScreen (
1383 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1391 Check user specified FileRow is under current screen.
1393 @param[in] FileRow Row of file position ( start from 1 ).
1395 @retval TRUE It is under the current screen.
1396 @retval FALSE It is not under the current screen.
1400 HUnderCurrentScreen (
1404 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 2) - 1) {
1412 According to cursor's file position, adjust screen display.
1414 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1415 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1416 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1419 HBufferImageMovePosition (
1420 IN UINTN NewFilePosRow
,
1421 IN UINTN NewFilePosCol
,
1429 UINTN NewDisplayCol
;
1432 // CALCULATE gap between current file position and new file position
1434 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1436 Under
= HUnderCurrentScreen (NewFilePosRow
);
1437 Above
= HAboveCurrentScreen (NewFilePosRow
);
1439 HBufferImage
.HighBits
= HighBits
;
1442 // if is below current screen
1446 // display row will be unchanged
1448 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1452 // has enough above line, so display row unchanged
1453 // not has enough above lines, so the first line is
1454 // at the first display line
1456 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1457 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1460 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1463 // in current screen
1465 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1467 Abs
= (UINTN
)ABS (RowGap
);
1468 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1470 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1475 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1478 // always in current screen
1480 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1482 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1483 if (NewFilePosCol
> 0x8) {
1491 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1494 // let CurrentLine point to correct line;
1496 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1500 Scroll cursor to right.
1502 @retval EFI_SUCCESS The operation was successful.
1505 HBufferImageScrollRight (
1509 HEFI_EDITOR_LINE
*Line
;
1514 // scroll right will always move to the high4 bits of the next character
1516 HBufferImageNeedRefresh
= FALSE
;
1517 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1519 Line
= HBufferImage
.CurrentLine
;
1521 FRow
= HBufferImage
.BufferPosition
.Row
;
1522 FCol
= HBufferImage
.BufferPosition
.Column
;
1525 // this line is not full and no next line
1527 if (FCol
> Line
->Size
) {
1532 // if already at end of this line, scroll it to the start of next line
1538 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1546 // if not at end of this line, just move to next column
1551 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1557 Scroll cursor to left.
1559 @retval EFI_SUCCESS The operation was successful.
1562 HBufferImageScrollLeft (
1566 HEFI_EDITOR_LINE
*Line
;
1570 HBufferImageNeedRefresh
= FALSE
;
1571 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1573 Line
= HBufferImage
.CurrentLine
;
1575 FRow
= HBufferImage
.BufferPosition
.Row
;
1576 FCol
= HBufferImage
.BufferPosition
.Column
;
1579 // if already at start of this line, so move to the end of previous line
1583 // has previous line
1585 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1587 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1594 // if not at start of this line, just move to previous column
1599 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1605 Scroll cursor to the next line
1607 @retval EFI_SUCCESS The operation was successful.
1610 HBufferImageScrollDown (
1614 HEFI_EDITOR_LINE
*Line
;
1619 Line
= HBufferImage
.CurrentLine
;
1621 FRow
= HBufferImage
.BufferPosition
.Row
;
1622 FCol
= HBufferImage
.BufferPosition
.Column
;
1623 HighBits
= HBufferImage
.HighBits
;
1628 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1630 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1633 // if the next line is not that long, so move to end of next line
1635 if (FCol
> Line
->Size
) {
1636 FCol
= Line
->Size
+ 1;
1643 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1649 Scroll cursor to previous line
1651 @retval EFI_SUCCESS The operation was successful.
1654 HBufferImageScrollUp (
1658 HEFI_EDITOR_LINE
*Line
;
1662 Line
= HBufferImage
.CurrentLine
;
1664 FRow
= HBufferImage
.BufferPosition
.Row
;
1665 FCol
= HBufferImage
.BufferPosition
.Column
;
1668 // has previous line
1670 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1676 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1682 Scroll cursor to next page
1684 @retval EFI_SUCCESS The operation was successful.
1687 HBufferImagePageDown (
1691 HEFI_EDITOR_LINE
*Line
;
1697 Line
= HBufferImage
.CurrentLine
;
1699 FRow
= HBufferImage
.BufferPosition
.Row
;
1700 FCol
= HBufferImage
.BufferPosition
.Column
;
1701 HighBits
= HBufferImage
.HighBits
;
1706 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 2)) {
1707 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1710 // MOVE CURSOR TO LAST LINE
1712 Gap
= HBufferImage
.NumLines
- FRow
;
1718 Line
= HMoveLine (Gap
);
1721 // if that line, is not that long, so move to the end of that line
1723 if ((Line
!= NULL
) && (FCol
> Line
->Size
)) {
1724 FCol
= Line
->Size
+ 1;
1730 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1736 Scroll cursor to previous page
1738 @retval EFI_SUCCESS The operation was successful.
1741 HBufferImagePageUp (
1750 FRow
= HBufferImage
.BufferPosition
.Row
;
1751 FCol
= HBufferImage
.BufferPosition
.Column
;
1754 // has previous page
1756 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 2)) {
1757 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1760 // the first line of file will displayed on the first line of screen
1770 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1776 Scroll cursor to start of line
1778 @retval EFI_SUCCESS The operation was successful.
1790 // curosr will at the high bit
1792 FRow
= HBufferImage
.BufferPosition
.Row
;
1797 // move cursor position
1799 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1805 Scroll cursor to end of line.
1807 @retval EFI_SUCCESS Teh operation was successful.
1814 HEFI_EDITOR_LINE
*Line
;
1820 // need refresh mouse
1822 HBufferImageMouseNeedRefresh
= TRUE
;
1824 Line
= HBufferImage
.CurrentLine
;
1826 FRow
= HBufferImage
.BufferPosition
.Row
;
1828 if (Line
->Size
== 0x10) {
1832 FCol
= Line
->Size
+ 1;
1837 // move cursor position
1839 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1845 Get the size of the open buffer.
1847 @retval The size in bytes.
1850 HBufferImageGetTotalSize (
1856 HEFI_EDITOR_LINE
*Line
;
1859 // calculate the total size of whole line list's buffer
1861 if (HBufferImage
.Lines
== NULL
) {
1866 HBufferImage
.ListHead
->BackLink
,
1869 EFI_EDITOR_LINE_LIST
1872 // one line at most 0x10
1874 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1880 Delete character from buffer.
1882 @param[in] Pos Position, Pos starting from 0.
1883 @param[in] Count The Count of characters to delete.
1884 @param[out] DeleteBuffer The DeleteBuffer.
1886 @retval EFI_SUCCESS Success
1889 HBufferImageDeleteCharacterFromBuffer (
1892 OUT UINT8
*DeleteBuffer
1901 HEFI_EDITOR_LINE
*Line
;
1912 Size
= HBufferImageGetTotalSize ();
1915 return EFI_LOAD_ERROR
;
1923 // relocate all the HBufferImage fields
1925 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1926 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1927 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1931 // has character before it,
1932 // so locate according to block's previous character
1937 // has no character before it,
1938 // so locate according to block's next character
1943 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1945 Buffer
= AllocateZeroPool (Size
);
1946 if (Buffer
== NULL
) {
1947 return EFI_OUT_OF_RESOURCES
;
1950 HBufferImageListToBuffer (Buffer
, Size
);
1952 BufferPtr
= (UINT8
*)Buffer
;
1955 // pass deleted buffer out
1957 if (DeleteBuffer
!= NULL
) {
1958 for (Index
= 0; Index
< Count
; Index
++) {
1959 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1964 // delete the part from Pos
1966 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1967 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1972 HBufferImageFreeLines ();
1974 Status
= HBufferImageBufferToList (Buffer
, Size
);
1977 if (EFI_ERROR (Status
)) {
1981 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1982 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
1983 Link
= Link
->ForwardLink
;
1986 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1987 HBufferImage
.CurrentLine
= Line
;
1990 // if current cursor position if inside select area
1991 // then move it to the block's NEXT character
1993 if ((OldPos
>= Pos
) && (OldPos
< (Pos
+ Count
))) {
1999 NewPos
= OldPos
- Count
;
2003 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2009 Add character to buffer, add before pos.
2011 @param[in] Pos Position, Pos starting from 0.
2012 @param[in] Count Count of characters to add.
2013 @param[in] AddBuffer Add buffer.
2015 @retval EFI_SUCCESS Success.
2018 HBufferImageAddCharacterToBuffer (
2030 HEFI_EDITOR_LINE
*Line
;
2040 Size
= HBufferImageGetTotalSize ();
2043 // relocate all the HBufferImage fields
2045 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2046 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2047 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2050 // move cursor before Pos
2058 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2060 Buffer
= AllocateZeroPool (Size
+ Count
);
2061 if (Buffer
== NULL
) {
2062 return EFI_OUT_OF_RESOURCES
;
2065 HBufferImageListToBuffer (Buffer
, Size
);
2067 BufferPtr
= (UINT8
*)Buffer
;
2070 // get a place to add
2072 for (Index
= (INTN
)(Size
+ Count
- 1); Index
>= (INTN
)Pos
; Index
--) {
2073 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2079 for (Index
= (INTN
)0; Index
< (INTN
)Count
; Index
++) {
2080 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2085 HBufferImageFreeLines ();
2087 HBufferImageBufferToList (Buffer
, Size
);
2091 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2092 for (Index
= 0; Index
< (INTN
)NewPos
/ 0x10; Index
++) {
2093 Link
= Link
->ForwardLink
;
2096 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2097 HBufferImage
.CurrentLine
= Line
;
2099 if (OldPos
>= Pos
) {
2100 NewPos
= OldPos
+ Count
;
2105 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2111 Delete current character from line.
2113 @retval EFI_SUCCESS The operationw as successful.
2116 HBufferImageDoDelete (
2120 HEFI_EDITOR_LINE
*Line
;
2126 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2128 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2130 Line
= HBufferImage
.CurrentLine
;
2133 // if beyond the last character
2135 if (FileColumn
> Line
->Size
) {
2140 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2144 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2147 // if is the last line
2148 // then only this line need to be refreshed
2151 HBufferImageNeedRefresh
= FALSE
;
2152 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2154 HBufferImageNeedRefresh
= TRUE
;
2155 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2158 if (!HBufferImage
.Modified
) {
2159 HBufferImage
.Modified
= TRUE
;
2166 Change the raw buffer to a list of lines for the UI.
2168 @param[in] Buffer The pointer to the buffer to fill.
2169 @param[in] Bytes The size of the buffer in bytes.
2171 @retval EFI_SUCCESS The operation was successful.
2172 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2175 HBufferImageBufferToList (
2183 HEFI_EDITOR_LINE
*Line
;
2188 BufferPtr
= (UINT8
*)Buffer
;
2191 // parse file content line by line
2193 while (TempI
< Bytes
) {
2194 if (Bytes
- TempI
>= 0x10) {
2197 Left
= Bytes
- TempI
;
2201 // allocate a new line
2203 Line
= HBufferImageCreateLine ();
2205 return EFI_OUT_OF_RESOURCES
;
2210 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2211 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2217 // last line is a full line, SO create a new line
2219 if ((Left
== 0x10) || (Bytes
== 0)) {
2220 Line
= HBufferImageCreateLine ();
2222 return EFI_OUT_OF_RESOURCES
;
2230 Change the list of lines from the UI to a raw buffer.
2232 @param[in] Buffer The pointer to the buffer to fill.
2233 @param[in] Bytes The size of the buffer in bytes.
2235 @retval EFI_SUCCESS The operation was successful.
2238 HBufferImageListToBuffer (
2245 HEFI_EDITOR_LINE
*Line
;
2250 // change the line list to a large buffer
2252 if (HBufferImage
.Lines
== NULL
) {
2256 Link
= &HBufferImage
.Lines
->Link
;
2258 BufferPtr
= (UINT8
*)Buffer
;
2261 // deal line by line
2263 while (Link
!= HBufferImage
.ListHead
) {
2264 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2266 // @todo shouldn't this be an error???
2267 if (Count
+ Line
->Size
> Bytes
) {
2271 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2272 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2275 Count
+= Line
->Size
;
2276 BufferPtr
+= Line
->Size
;
2278 Link
= Link
->ForwardLink
;
2285 Move the mouse in the image buffer.
2287 @param[in] TextX The x-coordinate.
2288 @param[in] TextY The y-coordinate.
2291 HBufferImageAdjustMousePosition (
2302 // TextX and TextY is mouse movement data returned by mouse driver
2303 // This function will change it to MousePosition
2306 // get absolute TempX value
2315 // get absolute TempY value
2323 TempX
= HBufferImage
.MousePosition
.Column
;
2324 TempY
= HBufferImage
.MousePosition
.Row
;
2329 if (TempX
>= AbsX
) {
2339 if (TempY
>= AbsY
) {
2347 // check whether new mouse column position is beyond screen
2348 // if not, adjust it
2350 if ((TempX
>= 10) && (TempX
<= (10 + 0x10 * 3 - 1))) {
2351 HBufferImage
.MousePosition
.Column
= TempX
;
2352 } else if (TempX
< 10) {
2353 HBufferImage
.MousePosition
.Column
= 10;
2354 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2355 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2359 // check whether new mouse row position is beyond screen
2360 // if not, adjust it
2362 if ((TempY
>= 2) && (TempY
<= (HMainEditor
.ScreenSize
.Row
- 1))) {
2363 HBufferImage
.MousePosition
.Row
= TempY
;
2364 } else if (TempY
< 2) {
2365 HBufferImage
.MousePosition
.Row
= 2;
2366 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 1)) {
2367 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 1);
2372 Dispatch input to different handler
2374 @param[in] Key The input key:
2378 Direction key: up/down/left/right/pgup/pgdn
2382 @retval EFI_SUCCESS The operation was successful.
2383 @retval EFI_LOAD_ERROR A load error occurred.
2384 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2387 HBufferImageHandleInput (
2388 IN EFI_INPUT_KEY
*Key
2393 Status
= EFI_SUCCESS
;
2395 switch (Key
->ScanCode
) {
2400 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2407 Status
= HBufferImageScrollUp ();
2414 Status
= HBufferImageScrollDown ();
2421 Status
= HBufferImageScrollRight ();
2428 Status
= HBufferImageScrollLeft ();
2435 Status
= HBufferImagePageUp ();
2441 case SCAN_PAGE_DOWN
:
2442 Status
= HBufferImagePageDown ();
2449 Status
= HBufferImageDoDelete ();
2456 Status
= HBufferImageHome ();
2463 Status
= HBufferImageEnd ();
2467 Status
= StatusBarSetStatusString (L
"Unknown Command");