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 - 2014, Intel Corporation. All rights reserved. <BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HexEditor.h"
18 extern EFI_HANDLE HImageHandleBackup
;
20 extern HEFI_EDITOR_FILE_IMAGE HFileImage
;
21 extern HEFI_EDITOR_DISK_IMAGE HDiskImage
;
22 extern HEFI_EDITOR_MEM_IMAGE HMemImage
;
24 extern HEFI_EDITOR_FILE_IMAGE HFileImageBackupVar
;
25 extern HEFI_EDITOR_DISK_IMAGE HDiskImageBackupVar
;
26 extern HEFI_EDITOR_MEM_IMAGE HMemImageBackupVar
;
28 extern BOOLEAN HEditorMouseAction
;
30 extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
31 extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
33 HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
34 HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
37 // for basic initialization of HBufferImage
39 HEFI_EDITOR_BUFFER_IMAGE HBufferImageConst
= {
66 // the whole edit area needs to be refreshed
68 BOOLEAN HBufferImageNeedRefresh
;
71 // only the current line in edit area needs to be refresh
73 BOOLEAN HBufferImageOnlyLineNeedRefresh
;
75 BOOLEAN HBufferImageMouseNeedRefresh
;
78 Initialization function for HBufferImage
80 @retval EFI_SUCCESS The operation was successful.
81 @retval EFI_LOAD_ERROR A load error occured.
91 // basically initialize the HBufferImage
93 CopyMem (&HBufferImage
, &HBufferImageConst
, sizeof (HBufferImage
));
98 HBufferImage
.ListHead
= AllocateZeroPool (sizeof (LIST_ENTRY
));
99 if (HBufferImage
.ListHead
== NULL
) {
100 return EFI_LOAD_ERROR
;
103 InitializeListHead (HBufferImage
.ListHead
);
105 HBufferImage
.DisplayPosition
.Row
= 2;
106 HBufferImage
.DisplayPosition
.Column
= 10;
107 HBufferImage
.MousePosition
.Row
= 2;
108 HBufferImage
.MousePosition
.Column
= 10;
110 HBufferImage
.FileImage
= &HFileImage
;
111 HBufferImage
.DiskImage
= &HDiskImage
;
112 HBufferImage
.MemImage
= &HMemImage
;
114 HBufferImageNeedRefresh
= FALSE
;
115 HBufferImageOnlyLineNeedRefresh
= FALSE
;
116 HBufferImageMouseNeedRefresh
= FALSE
;
118 HBufferImageBackupVar
.FileImage
= &HFileImageBackupVar
;
119 HBufferImageBackupVar
.DiskImage
= &HDiskImageBackupVar
;
120 HBufferImageBackupVar
.MemImage
= &HMemImageBackupVar
;
122 Status
= HFileImageInit ();
123 if (EFI_ERROR (Status
)) {
124 return EFI_LOAD_ERROR
;
127 Status
= HDiskImageInit ();
128 if (EFI_ERROR (Status
)) {
129 return EFI_LOAD_ERROR
;
132 Status
= HMemImageInit ();
133 if (EFI_ERROR (Status
)) {
134 return EFI_LOAD_ERROR
;
141 Backup function for HBufferImage. Only a few fields need to be backup.
142 This is for making the file buffer refresh as few as possible.
144 @retval EFI_SUCCESS The operation was successful.
151 HBufferImageBackupVar
.MousePosition
= HBufferImage
.MousePosition
;
153 HBufferImageBackupVar
.BufferPosition
= HBufferImage
.BufferPosition
;
155 HBufferImageBackupVar
.Modified
= HBufferImage
.Modified
;
157 HBufferImageBackupVar
.BufferType
= HBufferImage
.BufferType
;
158 HBufferImageBackupVar
.LowVisibleRow
= HBufferImage
.LowVisibleRow
;
159 HBufferImageBackupVar
.HighBits
= HBufferImage
.HighBits
;
162 // three kinds of buffer supported
167 switch (HBufferImage
.BufferType
) {
168 case FileTypeFileBuffer
:
172 case FileTypeDiskBuffer
:
176 case FileTypeMemBuffer
:
188 Free all the lines in HBufferImage.
195 @retval EFI_SUCCESS The operation was successful.
198 HBufferImageFreeLines (
202 HFreeLines (HBufferImage
.ListHead
, HBufferImage
.Lines
);
204 HBufferImage
.Lines
= NULL
;
205 HBufferImage
.CurrentLine
= NULL
;
206 HBufferImage
.NumLines
= 0;
212 Cleanup function for HBufferImage
214 @retval EFI_SUCCESS The operation was successful.
217 HBufferImageCleanup (
224 // free all the lines
226 Status
= HBufferImageFreeLines ();
228 SHELL_FREE_NON_NULL (HBufferImage
.ListHead
);
229 HBufferImage
.ListHead
= NULL
;
231 HFileImageCleanup ();
232 HDiskImageCleanup ();
241 @param[in] Line The lline to print.
242 @param[in] Row The row on screen ( begin from 1 ).
243 @param[in] FRow The FRow.
244 @param[in] Orig The original color.
245 @param[in] New The color to print with.
247 @retval EFI_SUCCESS The operation was successful.
250 HBufferImagePrintLine (
251 IN HEFI_EDITOR_LINE
*Line
,
254 IN HEFI_EDITOR_COLOR_UNION Orig
,
255 IN HEFI_EDITOR_COLOR_UNION New
270 // variable initialization
277 // print the selected area in opposite color
279 if (HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
280 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
281 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
283 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
284 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
286 if (FRow
>= RowStart
&& FRow
<= RowEnd
) {
290 if (FRow
> RowStart
) {
300 if (!HEditorMouseAction
) {
305 ((INT32
)Row
- 2 + HBufferImage
.LowVisibleRow
- 1) * 0x10
310 for (Index
= 0; Index
< 0x08 && Index
< Line
->Size
; Index
++) {
315 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
321 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
323 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
326 Pos
= 10 + (Index
* 3);
327 if (Line
->Buffer
[Index
] < 0x10) {
328 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
333 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
335 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
340 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
341 while (Index
< 0x08) {
342 Pos
= 10 + (Index
* 3);
343 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
347 while (Index
< 0x10 && Index
< Line
->Size
) {
352 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
358 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
360 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
363 Pos
= 10 + (Index
* 3) + 1;
364 if (Line
->Buffer
[Index
] < 0x10) {
365 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
369 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
373 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
374 while (Index
< 0x10) {
375 Pos
= 10 + (Index
* 3) + 1;
376 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
380 // restore the original color
382 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
& 0x7F);
385 // PRINT the buffer content
387 if (!HEditorMouseAction
) {
388 for (Index
= 0; Index
< 0x10 && Index
< Line
->Size
; Index
++) {
389 Pos
= ASCII_POSITION
+ Index
;
392 // learned from shelle.h -- IsValidChar
394 if (Line
->Buffer
[Index
] >= L
' ') {
395 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", (CHAR16
) Line
->Buffer
[Index
]);
397 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", '.');
401 while (Index
< 0x10) {
402 Pos
= ASCII_POSITION
+ Index
;
403 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
408 // restore the abundant blank in hex edit area to original color
412 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
413 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
414 } else if (ColEnd
== 8) {
415 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
416 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
418 Pos
= 10 + (ColEnd
- 1) * 3 + 3;
419 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
427 Function to decide if a column number is stored in the high bits.
429 @param[in] Column The column to examine.
430 @param[out] FCol The actual column number.
432 @retval TRUE The actual column was in high bits and is now in FCol.
433 @retval FALSE There was not a column number in the high bits.
436 HBufferImageIsAtHighBits (
444 // NOW AFTER THE SUB, Column start from 0
445 // 23 AND 24 ARE BOTH BLANK
456 *FCol
= (Column
/ 3) + 1;
458 if (Column
% 3 == 0) {
462 if ((Column
% 3 == 2)) {
470 Decide if a point is in the already selected area.
472 @param[in] MouseRow The row of the point to test.
473 @param[in] MouseCol The col of the point to test.
475 @retval TRUE The point is in the selected area.
476 @retval FALSE The point is not in the selected area.
479 HBufferImageIsInSelectedArea (
493 // judge mouse position whether is in selected area
498 if (HMainEditor
.SelectStart
== 0 || HMainEditor
.SelectEnd
== 0) {
502 // calculate the select area
504 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
505 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
507 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
508 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
510 FRow
= HBufferImage
.LowVisibleRow
+ MouseRow
- 2;
511 if (FRow
< RowStart
|| FRow
> RowEnd
) {
515 if (FRow
> RowStart
) {
523 MouseColStart
= 10 + (ColStart
- 1) * 3;
528 MouseColEnd
= 10 + (ColEnd
- 1) * 3 + 1;
533 if (MouseCol
< MouseColStart
|| MouseCol
> MouseColEnd
) {
541 Set mouse position according to HBufferImage.MousePosition.
543 @retval EFI_SUCCESS The operation was successful.
546 HBufferImageRestoreMousePosition (
550 HEFI_EDITOR_COLOR_UNION Orig
;
551 HEFI_EDITOR_COLOR_UNION New
;
554 BOOLEAN HasCharacter
;
555 HEFI_EDITOR_LINE
*CurrentLine
;
556 HEFI_EDITOR_LINE
*Line
;
561 if (HMainEditor
.MouseSupported
) {
563 if (HBufferImageMouseNeedRefresh
) {
565 HBufferImageMouseNeedRefresh
= FALSE
;
568 // if mouse position not moved and only mouse action
569 // so do not need to refresh mouse position
572 HBufferImage
.MousePosition
.Row
== HBufferImageBackupVar
.MousePosition
.Row
&&
573 HBufferImage
.MousePosition
.Column
== HBufferImageBackupVar
.MousePosition
.Column
580 // backup the old screen attributes
582 Orig
= HMainEditor
.ColorAttributes
;
584 New
.Colors
.Foreground
= Orig
.Colors
.Background
& 0xF;
585 New
.Colors
.Background
= Orig
.Colors
.Foreground
& 0x7;
588 // if in selected area,
589 // so do not need to refresh mouse
591 if (!HBufferImageIsInSelectedArea (
592 HBufferImageBackupVar
.MousePosition
.Row
,
593 HBufferImageBackupVar
.MousePosition
.Column
595 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
597 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
600 // clear the old mouse position
602 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
604 HighBits
= HBufferImageIsAtHighBits (
605 HBufferImageBackupVar
.MousePosition
.Column
,
610 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
611 HasCharacter
= FALSE
;
613 CurrentLine
= HBufferImage
.CurrentLine
;
614 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
616 if (Line
== NULL
|| FColumn
> Line
->Size
) {
617 HasCharacter
= FALSE
;
620 HBufferImage
.CurrentLine
= CurrentLine
;
624 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
625 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
631 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
632 Value
= (UINT8
) (Value
>> 4);
634 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
638 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
639 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
645 if (!HBufferImageIsInSelectedArea (
646 HBufferImage
.MousePosition
.Row
,
647 HBufferImage
.MousePosition
.Column
649 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
& 0x7F);
651 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
654 // clear the old mouse position
656 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImage
.MousePosition
.Row
- 2;
658 HighBits
= HBufferImageIsAtHighBits (
659 HBufferImage
.MousePosition
.Column
,
664 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
665 HasCharacter
= FALSE
;
667 CurrentLine
= HBufferImage
.CurrentLine
;
668 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
670 if (Line
== NULL
|| FColumn
> Line
->Size
) {
671 HasCharacter
= FALSE
;
674 HBufferImage
.CurrentLine
= CurrentLine
;
678 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
679 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
685 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
686 Value
= (UINT8
) (Value
>> 4);
688 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
692 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
693 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
699 // end of HasCharacter
701 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
704 // end of MouseNeedRefresh
708 // end of MouseSupported
714 Set cursor position according to HBufferImage.DisplayPosition.
716 @retval EFI_SUCCESS The operation was successful.
719 HBufferImageRestorePosition (
724 // set cursor position
726 gST
->ConOut
->SetCursorPosition (
728 HBufferImage
.DisplayPosition
.Column
- 1,
729 HBufferImage
.DisplayPosition
.Row
- 1
736 Refresh function for HBufferImage.
738 @retval EFI_SUCCESS The operation was successful.
739 @retval EFI_LOAD_ERROR A Load error occured.
743 HBufferImageRefresh (
748 HEFI_EDITOR_LINE
*Line
;
750 HEFI_EDITOR_COLOR_UNION Orig
;
751 HEFI_EDITOR_COLOR_UNION New
;
758 Orig
= HMainEditor
.ColorAttributes
;
760 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
761 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
764 // if it's the first time after editor launch, so should refresh
766 if (HEditorFirst
== FALSE
) {
768 // no definite required refresh
769 // and file position displayed on screen has not been changed
771 if (!HBufferImageNeedRefresh
&&
772 !HBufferImageOnlyLineNeedRefresh
&&
773 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
775 HBufferImageRestoreMousePosition ();
776 HBufferImageRestorePosition ();
781 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
784 // only need to refresh current line
786 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
788 HBufferImagePrintLine (
789 HBufferImage
.CurrentLine
,
790 HBufferImage
.DisplayPosition
.Row
,
791 HBufferImage
.BufferPosition
.Row
,
797 // the whole edit area need refresh
799 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
800 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
801 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
802 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
804 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
807 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
810 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
811 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
813 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
818 if (StartRow
> EndRow
) {
824 FStartRow
= StartRow
;
826 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
827 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
831 // not mouse selection actions
833 FStartRow
= HBufferImage
.LowVisibleRow
;
835 EndRow
= (HMainEditor
.ScreenSize
.Row
- 1);
840 if (HBufferImage
.Lines
== NULL
) {
841 HBufferImageRestoreMousePosition ();
842 HBufferImageRestorePosition ();
843 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
847 // get the first line that will be displayed
849 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
851 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
852 return EFI_LOAD_ERROR
;
855 Link
= &(Line
->Link
);
858 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
863 HBufferImagePrintLine (
866 HBufferImage
.LowVisibleRow
+ Row
- 2,
871 Link
= Link
->ForwardLink
;
873 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
875 while (Row
<= EndRow
) {
876 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 (INTN
) (Char
- L
'0');
1114 if (Char
>= L
'a' && Char
<= L
'f') {
1115 return (INTN
) (Char
- L
'a' + 10);
1118 if (Char
>= L
'A' && Char
<= L
'F') {
1119 return (INTN
) (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
;
1178 Old
= Line
->Buffer
[FCol
- 1];
1181 // always put the input to the low 4 bits
1183 Old
= (UINT8
) (Old
& 0x0f);
1184 Old
= (UINT8
) (Old
<< 4);
1185 Old
= (UINT8
) (Value
+ Old
);
1186 Line
->Buffer
[FCol
- 1] = Old
;
1189 // at the low 4 bits of the last character of a full line
1190 // so if no next line, need to create a new line
1192 if (!High
&& FCol
== 0x10) {
1194 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1195 HBufferImageNeedRefresh
= TRUE
;
1197 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1201 // create a new line
1203 NewLine
= HBufferImageCreateLine ();
1204 if (NewLine
== NULL
) {
1205 return EFI_OUT_OF_RESOURCES
;
1212 // end of == ListHead
1218 // if already at end of this line, scroll it to the start of next line
1220 if (FCol
== 0x10 && !High
) {
1222 // definitely has next line
1229 // if not at end of this line, just move to next column
1247 // move cursor to right
1249 HBufferImageMovePosition (FRow
, FCol
, High
);
1251 if (!HBufferImage
.Modified
) {
1252 HBufferImage
.Modified
= TRUE
;
1259 Delete the previous character.
1261 @retval EFI_SUCCESS The operationw as successful.
1264 HBufferImageDoBackspace (
1268 HEFI_EDITOR_LINE
*Line
;
1275 // variable initialization
1280 // already the first character
1282 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
1286 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1288 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1290 Line
= HBufferImage
.CurrentLine
;
1292 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
1296 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1299 // if is the last line
1300 // then only this line need to be refreshed
1303 HBufferImageNeedRefresh
= FALSE
;
1304 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1306 HBufferImageNeedRefresh
= TRUE
;
1307 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1310 if (!HBufferImage
.Modified
) {
1311 HBufferImage
.Modified
= TRUE
;
1318 ASCII key + Backspace + return.
1320 @param[in] Char The input char.
1322 @retval EFI_SUCCESS The operation was successful.
1323 @retval EFI_LOAD_ERROR A load error occured.
1324 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1327 HBufferImageDoCharInput (
1333 Status
= EFI_SUCCESS
;
1340 Status
= HBufferImageDoBackspace ();
1347 // Tabs, Returns are thought as nothing
1353 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1355 if (Char
> 127 || Char
< 32) {
1356 Status
= StatusBarSetStatusString (L
"Unknown Command");
1358 Status
= HBufferImageAddChar (Char
);
1368 Check user specified FileRow is above current screen.
1370 @param[in] FileRow Row of file position ( start from 1 ).
1372 @retval TRUE It is above the current screen.
1373 @retval FALSE It is not above the current screen.
1377 HAboveCurrentScreen (
1381 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1389 Check user specified FileRow is under current screen.
1391 @param[in] FileRow Row of file position ( start from 1 ).
1393 @retval TRUE It is under the current screen.
1394 @retval FALSE It is not under the current screen.
1398 HUnderCurrentScreen (
1402 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 2) - 1) {
1410 According to cursor's file position, adjust screen display.
1412 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1413 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1414 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1417 HBufferImageMovePosition (
1418 IN UINTN NewFilePosRow
,
1419 IN UINTN NewFilePosCol
,
1427 UINTN NewDisplayCol
;
1430 // CALCULATE gap between current file position and new file position
1432 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1434 Under
= HUnderCurrentScreen (NewFilePosRow
);
1435 Above
= HAboveCurrentScreen (NewFilePosRow
);
1437 HBufferImage
.HighBits
= HighBits
;
1440 // if is below current screen
1444 // display row will be unchanged
1446 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1450 // has enough above line, so display row unchanged
1451 // not has enough above lines, so the first line is
1452 // at the first display line
1454 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1455 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1458 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1461 // in current screen
1463 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1465 Abs
= (UINTN
)ABS(RowGap
);
1466 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1468 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1474 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1477 // always in current screen
1479 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1481 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1482 if (NewFilePosCol
> 0x8) {
1490 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1493 // let CurrentLine point to correct line;
1495 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
) {
1531 // if already at end of this line, scroll it to the start of next line
1537 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1546 // if not at end of this line, just move to next column
1552 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1558 Scroll cursor to left.
1560 @retval EFI_SUCCESS The operation was successful.
1563 HBufferImageScrollLeft (
1568 HEFI_EDITOR_LINE
*Line
;
1572 HBufferImageNeedRefresh
= FALSE
;
1573 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1575 Line
= HBufferImage
.CurrentLine
;
1577 FRow
= HBufferImage
.BufferPosition
.Row
;
1578 FCol
= HBufferImage
.BufferPosition
.Column
;
1581 // if already at start of this line, so move to the end of previous line
1585 // has previous line
1587 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1589 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1596 // if not at start of this line, just move to previous column
1601 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1607 Scroll cursor to the next line
1609 @retval EFI_SUCCESS The operation was successful.
1612 HBufferImageScrollDown (
1616 HEFI_EDITOR_LINE
*Line
;
1621 Line
= HBufferImage
.CurrentLine
;
1623 FRow
= HBufferImage
.BufferPosition
.Row
;
1624 FCol
= HBufferImage
.BufferPosition
.Column
;
1625 HighBits
= HBufferImage
.HighBits
;
1630 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1632 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1635 // if the next line is not that long, so move to end of next line
1637 if (FCol
> Line
->Size
) {
1638 FCol
= Line
->Size
+ 1;
1646 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1652 Scroll cursor to previous line
1654 @retval EFI_SUCCESS The operation was successful.
1657 HBufferImageScrollUp (
1661 HEFI_EDITOR_LINE
*Line
;
1665 Line
= HBufferImage
.CurrentLine
;
1667 FRow
= HBufferImage
.BufferPosition
.Row
;
1668 FCol
= HBufferImage
.BufferPosition
.Column
;
1671 // has previous line
1673 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1680 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1686 Scroll cursor to next page
1688 @retval EFI_SUCCESS The operation was successful.
1691 HBufferImagePageDown (
1695 HEFI_EDITOR_LINE
*Line
;
1701 Line
= HBufferImage
.CurrentLine
;
1703 FRow
= HBufferImage
.BufferPosition
.Row
;
1704 FCol
= HBufferImage
.BufferPosition
.Column
;
1705 HighBits
= HBufferImage
.HighBits
;
1710 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 2)) {
1711 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1714 // MOVE CURSOR TO LAST LINE
1716 Gap
= HBufferImage
.NumLines
- FRow
;
1721 Line
= HMoveLine (Gap
);
1724 // if that line, is not that long, so move to the end of that line
1726 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1727 FCol
= Line
->Size
+ 1;
1733 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1739 Scroll cursor to previous page
1741 @retval EFI_SUCCESS The operation was successful.
1744 HBufferImagePageUp (
1753 FRow
= HBufferImage
.BufferPosition
.Row
;
1754 FCol
= HBufferImage
.BufferPosition
.Column
;
1757 // has previous page
1759 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 2)) {
1760 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1763 // the first line of file will displayed on the first line of screen
1773 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1779 Scroll cursor to start of line
1781 @retval EFI_SUCCESS The operation was successful.
1793 // curosr will at the high bit
1795 FRow
= HBufferImage
.BufferPosition
.Row
;
1800 // move cursor position
1802 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1808 Scroll cursor to end of line.
1810 @retval EFI_SUCCESS Teh operation was successful.
1817 HEFI_EDITOR_LINE
*Line
;
1823 // need refresh mouse
1825 HBufferImageMouseNeedRefresh
= TRUE
;
1827 Line
= HBufferImage
.CurrentLine
;
1829 FRow
= HBufferImage
.BufferPosition
.Row
;
1831 if (Line
->Size
== 0x10) {
1835 FCol
= Line
->Size
+ 1;
1839 // move cursor position
1841 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1847 Get the size of the open buffer.
1849 @retval The size in bytes.
1852 HBufferImageGetTotalSize (
1858 HEFI_EDITOR_LINE
*Line
;
1861 // calculate the total size of whole line list's buffer
1863 if (HBufferImage
.Lines
== NULL
) {
1868 HBufferImage
.ListHead
->BackLink
,
1871 EFI_EDITOR_LINE_LIST
1874 // one line at most 0x10
1876 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1882 Delete character from buffer.
1884 @param[in] Pos Position, Pos starting from 0.
1885 @param[in] Count The Count of characters to delete.
1886 @param[out] DeleteBuffer The DeleteBuffer.
1888 @retval EFI_SUCCESS Success
1891 HBufferImageDeleteCharacterFromBuffer (
1894 OUT UINT8
*DeleteBuffer
1903 HEFI_EDITOR_LINE
*Line
;
1914 Size
= HBufferImageGetTotalSize ();
1917 return EFI_LOAD_ERROR
;
1925 // relocate all the HBufferImage fields
1927 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1928 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1929 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1933 // has character before it,
1934 // so locate according to block's previous character
1940 // has no character before it,
1941 // so locate according to block's next character
1946 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1948 Buffer
= AllocateZeroPool (Size
);
1949 if (Buffer
== NULL
) {
1950 return EFI_OUT_OF_RESOURCES
;
1953 HBufferImageListToBuffer (Buffer
, Size
);
1955 BufferPtr
= (UINT8
*) Buffer
;
1958 // pass deleted buffer out
1960 if (DeleteBuffer
!= NULL
) {
1961 for (Index
= 0; Index
< Count
; Index
++) {
1962 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1966 // delete the part from Pos
1968 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1969 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1974 HBufferImageFreeLines ();
1976 Status
= HBufferImageBufferToList (Buffer
, Size
);
1979 if (EFI_ERROR (Status
)) {
1983 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1984 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
1985 Link
= Link
->ForwardLink
;
1988 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1989 HBufferImage
.CurrentLine
= Line
;
1992 // if current cursor position if inside select area
1993 // then move it to the block's NEXT character
1995 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
2001 NewPos
= OldPos
- Count
;
2005 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2011 Add character to buffer, add before pos.
2013 @param[in] Pos Position, Pos starting from 0.
2014 @param[in] Count Count of characters to add.
2015 @param[in] AddBuffer Add buffer.
2017 @retval EFI_SUCCESS Success.
2020 HBufferImageAddCharacterToBuffer (
2032 HEFI_EDITOR_LINE
*Line
;
2042 Size
= HBufferImageGetTotalSize ();
2045 // relocate all the HBufferImage fields
2047 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2048 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2049 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2052 // move cursor before Pos
2060 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2062 Buffer
= AllocateZeroPool (Size
+ Count
);
2063 if (Buffer
== NULL
) {
2064 return EFI_OUT_OF_RESOURCES
;
2067 HBufferImageListToBuffer (Buffer
, Size
);
2069 BufferPtr
= (UINT8
*) Buffer
;
2072 // get a place to add
2074 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2075 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2080 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2081 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2086 HBufferImageFreeLines ();
2088 HBufferImageBufferToList (Buffer
, Size
);
2092 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2093 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2094 Link
= Link
->ForwardLink
;
2097 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2098 HBufferImage
.CurrentLine
= Line
;
2100 if (OldPos
>= Pos
) {
2101 NewPos
= OldPos
+ Count
;
2106 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2112 Delete current character from line.
2114 @retval EFI_SUCCESS The operationw as successful.
2117 HBufferImageDoDelete (
2122 HEFI_EDITOR_LINE
*Line
;
2128 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2130 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2132 Line
= HBufferImage
.CurrentLine
;
2135 // if beyond the last character
2137 if (FileColumn
> Line
->Size
) {
2142 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2146 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2149 // if is the last line
2150 // then only this line need to be refreshed
2153 HBufferImageNeedRefresh
= FALSE
;
2154 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2156 HBufferImageNeedRefresh
= TRUE
;
2157 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2160 if (!HBufferImage
.Modified
) {
2161 HBufferImage
.Modified
= TRUE
;
2168 Change the raw buffer to a list of lines for the UI.
2170 @param[in] Buffer The pointer to the buffer to fill.
2171 @param[in] Bytes The size of the buffer in bytes.
2173 @retval EFI_SUCCESS The operation was successful.
2174 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2177 HBufferImageBufferToList (
2185 HEFI_EDITOR_LINE
*Line
;
2190 BufferPtr
= (UINT8
*) Buffer
;
2193 // parse file content line by line
2195 while (TempI
< Bytes
) {
2196 if (Bytes
- TempI
>= 0x10) {
2199 Left
= Bytes
- TempI
;
2203 // allocate a new line
2205 Line
= HBufferImageCreateLine ();
2207 return EFI_OUT_OF_RESOURCES
;
2212 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2213 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2220 // last line is a full line, SO create a new line
2222 if (Left
== 0x10 || Bytes
== 0) {
2223 Line
= HBufferImageCreateLine ();
2225 return EFI_OUT_OF_RESOURCES
;
2233 Change the list of lines from the UI to a raw buffer.
2235 @param[in] Buffer The pointer to the buffer to fill.
2236 @param[in] Bytes The size of the buffer in bytes.
2238 @retval EFI_SUCCESS The operation was successful.
2241 HBufferImageListToBuffer (
2248 HEFI_EDITOR_LINE
*Line
;
2253 // change the line list to a large buffer
2255 if (HBufferImage
.Lines
== NULL
) {
2259 Link
= &HBufferImage
.Lines
->Link
;
2261 BufferPtr
= (UINT8
*) Buffer
;
2264 // deal line by line
2266 while (Link
!= HBufferImage
.ListHead
) {
2268 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2270 //@todo shouldn't this be an error???
2271 if (Count
+ Line
->Size
> Bytes
) {
2275 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2276 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2279 Count
+= Line
->Size
;
2280 BufferPtr
+= Line
->Size
;
2282 Link
= Link
->ForwardLink
;
2289 Move the mouse in the image buffer.
2291 @param[in] TextX The x-coordinate.
2292 @param[in] TextY The y-coordinate.
2295 HBufferImageAdjustMousePosition (
2306 // TextX and TextY is mouse movement data returned by mouse driver
2307 // This function will change it to MousePosition
2310 // get absolute TempX value
2318 // get absolute TempY value
2326 TempX
= HBufferImage
.MousePosition
.Column
;
2327 TempY
= HBufferImage
.MousePosition
.Row
;
2332 if (TempX
>= AbsX
) {
2342 if (TempY
>= AbsY
) {
2349 // check whether new mouse column position is beyond screen
2350 // if not, adjust it
2352 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2353 HBufferImage
.MousePosition
.Column
= TempX
;
2354 } else if (TempX
< 10) {
2355 HBufferImage
.MousePosition
.Column
= 10;
2356 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2357 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2360 // check whether new mouse row position is beyond screen
2361 // if not, adjust it
2363 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 1)) {
2364 HBufferImage
.MousePosition
.Row
= TempY
;
2365 } else if (TempY
< 2) {
2366 HBufferImage
.MousePosition
.Row
= 2;
2367 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 1)) {
2368 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 1);
2374 Dispatch input to different handler
2376 @param[in] Key The input key:
2380 Direction key: up/down/left/right/pgup/pgdn
2384 @retval EFI_SUCCESS The operation was successful.
2385 @retval EFI_LOAD_ERROR A load error occured.
2386 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2389 HBufferImageHandleInput (
2390 IN EFI_INPUT_KEY
*Key
2395 Status
= EFI_SUCCESS
;
2397 switch (Key
->ScanCode
) {
2402 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2409 Status
= HBufferImageScrollUp ();
2416 Status
= HBufferImageScrollDown ();
2423 Status
= HBufferImageScrollRight ();
2430 Status
= HBufferImageScrollLeft ();
2437 Status
= HBufferImagePageUp ();
2443 case SCAN_PAGE_DOWN
:
2444 Status
= HBufferImagePageDown ();
2451 Status
= HBufferImageDoDelete ();
2458 Status
= HBufferImageHome ();
2465 Status
= HBufferImageEnd ();
2469 Status
= StatusBarSetStatusString (L
"Unknown Command");