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 - 2011, 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
);
323 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
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
);
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
);
360 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
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
);
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
);
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
;
583 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
584 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
587 // if in selected area,
588 // so do not need to refresh mouse
590 if (!HBufferImageIsInSelectedArea (
591 HBufferImageBackupVar
.MousePosition
.Row
,
592 HBufferImageBackupVar
.MousePosition
.Column
594 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
596 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
599 // clear the old mouse position
601 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
603 HighBits
= HBufferImageIsAtHighBits (
604 HBufferImageBackupVar
.MousePosition
.Column
,
609 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
610 HasCharacter
= FALSE
;
612 CurrentLine
= HBufferImage
.CurrentLine
;
613 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
615 if (Line
== NULL
|| FColumn
> Line
->Size
) {
616 HasCharacter
= FALSE
;
619 HBufferImage
.CurrentLine
= CurrentLine
;
623 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
624 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
630 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
631 Value
= (UINT8
) (Value
>> 4);
633 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
637 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
638 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
644 if (!HBufferImageIsInSelectedArea (
645 HBufferImage
.MousePosition
.Row
,
646 HBufferImage
.MousePosition
.Column
648 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
650 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
653 // clear the old mouse position
655 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImage
.MousePosition
.Row
- 2;
657 HighBits
= HBufferImageIsAtHighBits (
658 HBufferImage
.MousePosition
.Column
,
663 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
664 HasCharacter
= FALSE
;
666 CurrentLine
= HBufferImage
.CurrentLine
;
667 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
669 if (Line
== NULL
|| FColumn
> Line
->Size
) {
670 HasCharacter
= FALSE
;
673 HBufferImage
.CurrentLine
= CurrentLine
;
677 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
678 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
684 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
685 Value
= (UINT8
) (Value
>> 4);
687 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
691 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
692 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
698 // end of HasCharacter
700 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
703 // end of MouseNeedRefresh
707 // end of MouseSupported
713 Set cursor position according to HBufferImage.DisplayPosition.
715 @retval EFI_SUCCESS The operation was successful.
718 HBufferImageRestorePosition (
723 // set cursor position
725 gST
->ConOut
->SetCursorPosition (
727 HBufferImage
.DisplayPosition
.Column
- 1,
728 HBufferImage
.DisplayPosition
.Row
- 1
735 Refresh function for HBufferImage.
737 @retval EFI_SUCCESS The operation was successful.
738 @retval EFI_LOAD_ERROR A Load error occured.
742 HBufferImageRefresh (
747 HEFI_EDITOR_LINE
*Line
;
749 HEFI_EDITOR_COLOR_UNION Orig
;
750 HEFI_EDITOR_COLOR_UNION New
;
758 Orig
= HMainEditor
.ColorAttributes
;
759 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
760 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
763 // if it's the first time after editor launch, so should refresh
765 if (HEditorFirst
== FALSE
) {
767 // no definite required refresh
768 // and file position displayed on screen has not been changed
770 if (!HBufferImageNeedRefresh
&&
771 !HBufferImageOnlyLineNeedRefresh
&&
772 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
774 HBufferImageRestoreMousePosition ();
775 HBufferImageRestorePosition ();
780 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
783 // only need to refresh current line
785 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
787 HBufferImagePrintLine (
788 HBufferImage
.CurrentLine
,
789 HBufferImage
.DisplayPosition
.Row
,
790 HBufferImage
.BufferPosition
.Row
,
796 // the whole edit area need refresh
798 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
799 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
800 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
801 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
803 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
806 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
809 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
810 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
812 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
817 if (StartRow
> EndRow
) {
823 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
- 4);
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.
911 IN CONST CHAR16
*FileName
,
912 IN CONST CHAR16
*DiskName
,
917 IN EDIT_FILE_TYPE BufferType
,
922 EDIT_FILE_TYPE BufferTypeBackup
;
925 // variable initialization
927 Status
= EFI_SUCCESS
;
928 HBufferImage
.BufferType
= BufferType
;
931 // three types of buffer supported
936 BufferTypeBackup
= HBufferImage
.BufferType
;
938 switch (BufferType
) {
939 case FileTypeFileBuffer
:
940 Status
= HFileImageRead (FileName
, Recover
);
943 case FileTypeDiskBuffer
:
944 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
947 case FileTypeMemBuffer
:
948 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
952 Status
= EFI_NOT_FOUND
;
956 if (EFI_ERROR (Status
)) {
957 HBufferImage
.BufferType
= BufferTypeBackup
;
964 Save the current image.
966 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
967 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
968 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
969 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
970 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
971 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
972 @param[in] BufferType The type of buffer to save. IGNORED.
974 @return EFI_SUCCESS The operation was successful.
984 IN EDIT_FILE_TYPE BufferType
988 EDIT_FILE_TYPE BufferTypeBackup
;
991 // variable initialization
993 Status
= EFI_SUCCESS
;
994 BufferTypeBackup
= HBufferImage
.BufferType
;
996 switch (HBufferImage
.BufferType
) {
1000 case FileTypeFileBuffer
:
1001 Status
= HFileImageSave (FileName
);
1007 case FileTypeDiskBuffer
:
1008 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1014 case FileTypeMemBuffer
:
1015 Status
= HMemImageSave (MemOffset
, MemSize
);
1019 Status
= EFI_NOT_FOUND
;
1023 if (EFI_ERROR (Status
)) {
1024 HBufferImage
.BufferType
= BufferTypeBackup
;
1031 Create a new line and append it to the line list.
1036 @retval NULL create line failed.
1037 @return the line created.
1041 HBufferImageCreateLine (
1045 HEFI_EDITOR_LINE
*Line
;
1048 // allocate for line structure
1050 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1055 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1058 HBufferImage
.NumLines
++;
1061 // insert to line list
1063 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1065 if (HBufferImage
.Lines
== NULL
) {
1066 HBufferImage
.Lines
= CR (
1067 HBufferImage
.ListHead
->ForwardLink
,
1070 EFI_EDITOR_LINE_LIST
1078 Free the current image.
1080 @retval EFI_SUCCESS The operation was successful.
1090 HBufferImageFreeLines ();
1096 change char to int value based on Hex.
1098 @param[in] Char The input char.
1100 @return The character's index value.
1101 @retval -1 The operation failed.
1105 HBufferImageCharToHex (
1110 // change the character to hex
1112 if (Char
>= L
'0' && Char
<= L
'9') {
1113 return (INTN
) (Char
- L
'0');
1116 if (Char
>= L
'a' && Char
<= L
'f') {
1117 return (INTN
) (Char
- L
'a' + 10);
1120 if (Char
>= L
'A' && Char
<= L
'F') {
1121 return (INTN
) (Char
- L
'A' + 10);
1130 @param[in] Char -- input char.
1132 @retval EFI_SUCCESS The operation was successful.
1133 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1137 HBufferImageAddChar (
1141 HEFI_EDITOR_LINE
*Line
;
1142 HEFI_EDITOR_LINE
*NewLine
;
1149 Value
= HBufferImageCharToHex (Char
);
1158 Line
= HBufferImage
.CurrentLine
;
1159 FRow
= HBufferImage
.BufferPosition
.Row
;
1160 FCol
= HBufferImage
.BufferPosition
.Column
;
1161 High
= HBufferImage
.HighBits
;
1164 // only needs to refresh current line
1166 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1169 // not a full line and beyond the last character
1171 if (FCol
> Line
->Size
) {
1173 // cursor always at high 4 bits
1174 // and always put input to the low 4 bits
1176 Line
->Buffer
[Line
->Size
] = (UINT8
) Value
;
1181 Old
= Line
->Buffer
[FCol
- 1];
1184 // always put the input to the low 4 bits
1186 Old
= (UINT8
) (Old
& 0x0f);
1187 Old
= (UINT8
) (Old
<< 4);
1188 Old
= (UINT8
) (Value
+ Old
);
1189 Line
->Buffer
[FCol
- 1] = Old
;
1192 // at the low 4 bits of the last character of a full line
1193 // so if no next line, need to create a new line
1195 if (!High
&& FCol
== 0x10) {
1197 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1198 HBufferImageNeedRefresh
= TRUE
;
1200 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1204 // create a new line
1206 NewLine
= HBufferImageCreateLine ();
1207 if (NewLine
== NULL
) {
1208 return EFI_OUT_OF_RESOURCES
;
1215 // end of == ListHead
1221 // if already at end of this line, scroll it to the start of next line
1223 if (FCol
== 0x10 && !High
) {
1225 // definitely has next line
1232 // if not at end of this line, just move to next column
1250 // move cursor to right
1252 HBufferImageMovePosition (FRow
, FCol
, High
);
1254 if (!HBufferImage
.Modified
) {
1255 HBufferImage
.Modified
= TRUE
;
1262 Delete the previous character.
1264 @retval EFI_SUCCESS The operationw as successful.
1268 HBufferImageDoBackspace (
1272 HEFI_EDITOR_LINE
*Line
;
1279 // variable initialization
1284 // already the first character
1286 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
1290 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1292 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1294 Line
= HBufferImage
.CurrentLine
;
1296 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
1300 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1303 // if is the last line
1304 // then only this line need to be refreshed
1307 HBufferImageNeedRefresh
= FALSE
;
1308 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1310 HBufferImageNeedRefresh
= TRUE
;
1311 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1314 if (!HBufferImage
.Modified
) {
1315 HBufferImage
.Modified
= TRUE
;
1322 ASCII key + Backspace + return.
1324 @param[in] Char The input char.
1326 @retval EFI_SUCCESS The operation was successful.
1327 @retval EFI_LOAD_ERROR A load error occured.
1328 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1332 HBufferImageDoCharInput (
1338 Status
= EFI_SUCCESS
;
1345 Status
= HBufferImageDoBackspace ();
1352 // Tabs, Returns are thought as nothing
1358 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1360 if (Char
> 127 || Char
< 32) {
1361 Status
= StatusBarSetStatusString (L
"Unknown Command");
1363 Status
= HBufferImageAddChar (Char
);
1373 Check user specified FileRow is above current screen.
1375 @param[in] FileRow Row of file position ( start from 1 ).
1377 @retval TRUE It is above the current screen.
1378 @retval FALSE It is not above the current screen.
1382 HAboveCurrentScreen (
1386 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1394 Check user specified FileRow is under current screen.
1396 @param[in] FileRow Row of file position ( start from 1 ).
1398 @retval TRUE It is under the current screen.
1399 @retval FALSE It is not under the current screen.
1403 HUnderCurrentScreen (
1407 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 5) - 1) {
1415 According to cursor's file position, adjust screen display.
1417 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1418 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1419 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1422 HBufferImageMovePosition (
1423 IN UINTN NewFilePosRow
,
1424 IN UINTN NewFilePosCol
,
1432 UINTN NewDisplayCol
;
1435 // CALCULATE gap between current file position and new file position
1437 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1439 Under
= HUnderCurrentScreen (NewFilePosRow
);
1440 Above
= HAboveCurrentScreen (NewFilePosRow
);
1442 HBufferImage
.HighBits
= HighBits
;
1445 // if is below current screen
1449 // display row will be unchanged
1451 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1455 // has enough above line, so display row unchanged
1456 // not has enough above lines, so the first line is
1457 // at the first display line
1459 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1460 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1463 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1466 // in current screen
1468 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1470 Abs
= (UINTN
)ABS(RowGap
);
1471 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1473 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1479 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1482 // always in current screen
1484 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1486 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1487 if (NewFilePosCol
> 0x8) {
1495 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1498 // let CurrentLine point to correct line;
1500 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1505 Scroll cursor to right.
1507 @retval EFI_SUCCESS The operation was successful.
1510 HBufferImageScrollRight (
1514 HEFI_EDITOR_LINE
*Line
;
1519 // scroll right will always move to the high4 bits of the next character
1521 HBufferImageNeedRefresh
= FALSE
;
1522 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1524 Line
= HBufferImage
.CurrentLine
;
1526 FRow
= HBufferImage
.BufferPosition
.Row
;
1527 FCol
= HBufferImage
.BufferPosition
.Column
;
1530 // this line is not full and no next line
1532 if (FCol
> Line
->Size
) {
1536 // if already at end of this line, scroll it to the start of next line
1542 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1551 // if not at end of this line, just move to next column
1557 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1563 Scroll cursor to left.
1565 @retval EFI_SUCCESS The operation was successful.
1568 HBufferImageScrollLeft (
1573 HEFI_EDITOR_LINE
*Line
;
1577 HBufferImageNeedRefresh
= FALSE
;
1578 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1580 Line
= HBufferImage
.CurrentLine
;
1582 FRow
= HBufferImage
.BufferPosition
.Row
;
1583 FCol
= HBufferImage
.BufferPosition
.Column
;
1586 // if already at start of this line, so move to the end of previous line
1590 // has previous line
1592 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1594 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1601 // if not at start of this line, just move to previous column
1606 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1612 Scroll cursor to the next line
1614 @retval EFI_SUCCESS The operation was successful.
1617 HBufferImageScrollDown (
1621 HEFI_EDITOR_LINE
*Line
;
1626 Line
= HBufferImage
.CurrentLine
;
1628 FRow
= HBufferImage
.BufferPosition
.Row
;
1629 FCol
= HBufferImage
.BufferPosition
.Column
;
1630 HighBits
= HBufferImage
.HighBits
;
1635 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1637 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1640 // if the next line is not that long, so move to end of next line
1642 if (FCol
> Line
->Size
) {
1643 FCol
= Line
->Size
+ 1;
1651 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1657 Scroll cursor to previous line
1659 @retval EFI_SUCCESS The operation was successful.
1662 HBufferImageScrollUp (
1666 HEFI_EDITOR_LINE
*Line
;
1670 Line
= HBufferImage
.CurrentLine
;
1672 FRow
= HBufferImage
.BufferPosition
.Row
;
1673 FCol
= HBufferImage
.BufferPosition
.Column
;
1676 // has previous line
1678 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1685 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1691 Scroll cursor to next page
1693 @retval EFI_SUCCESS The operation was successful.
1696 HBufferImagePageDown (
1700 HEFI_EDITOR_LINE
*Line
;
1706 Line
= HBufferImage
.CurrentLine
;
1708 FRow
= HBufferImage
.BufferPosition
.Row
;
1709 FCol
= HBufferImage
.BufferPosition
.Column
;
1710 HighBits
= HBufferImage
.HighBits
;
1715 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 5)) {
1716 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1719 // MOVE CURSOR TO LAST LINE
1721 Gap
= HBufferImage
.NumLines
- FRow
;
1726 Line
= HMoveLine (Gap
);
1729 // if that line, is not that long, so move to the end of that line
1731 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1732 FCol
= Line
->Size
+ 1;
1738 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1744 Scroll cursor to previous page
1746 @retval EFI_SUCCESS The operation was successful.
1749 HBufferImagePageUp (
1753 HEFI_EDITOR_LINE
*Line
;
1759 Line
= HBufferImage
.CurrentLine
;
1761 FRow
= HBufferImage
.BufferPosition
.Row
;
1762 FCol
= HBufferImage
.BufferPosition
.Column
;
1765 // has previous page
1767 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 5)) {
1768 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1771 // the first line of file will displayed on the first line of screen
1782 Line
= HMoveLine (Retreat
);
1786 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1792 Scroll cursor to start of line
1794 @retval EFI_SUCCESS The operation was successful.
1801 HEFI_EDITOR_LINE
*Line
;
1806 Line
= HBufferImage
.CurrentLine
;
1809 // curosr will at the high bit
1811 FRow
= HBufferImage
.BufferPosition
.Row
;
1816 // move cursor position
1818 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1824 Scroll cursor to end of line.
1826 @retval EFI_SUCCESS Teh operation was successful.
1833 HEFI_EDITOR_LINE
*Line
;
1839 // need refresh mouse
1841 HBufferImageMouseNeedRefresh
= TRUE
;
1843 Line
= HBufferImage
.CurrentLine
;
1845 FRow
= HBufferImage
.BufferPosition
.Row
;
1847 if (Line
->Size
== 0x10) {
1851 FCol
= Line
->Size
+ 1;
1855 // move cursor position
1857 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1863 Get the size of the open buffer.
1865 @retval The size in bytes.
1868 HBufferImageGetTotalSize (
1874 HEFI_EDITOR_LINE
*Line
;
1877 // calculate the total size of whole line list's buffer
1879 if (HBufferImage
.Lines
== NULL
) {
1884 HBufferImage
.ListHead
->BackLink
,
1887 EFI_EDITOR_LINE_LIST
1890 // one line at most 0x10
1892 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1898 Delete character from buffer.
1900 @param[in] Pos Position, Pos starting from 0.
1901 @param[in] Count The Count of characters to delete.
1902 @param[out] DeleteBuffer The DeleteBuffer.
1904 @retval EFI_SUCCESS Success
1907 HBufferImageDeleteCharacterFromBuffer (
1910 OUT UINT8
*DeleteBuffer
1919 HEFI_EDITOR_LINE
*Line
;
1932 // get the line that start position is at
1934 StartRow
= Pos
/ 0x10;
1936 Size
= HBufferImageGetTotalSize ();
1939 return EFI_LOAD_ERROR
;
1947 // relocate all the HBufferImage fields
1949 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1950 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1951 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1955 // has character before it,
1956 // so locate according to block's previous character
1962 // has no character before it,
1963 // so locate according to block's next character
1968 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1970 Buffer
= AllocateZeroPool (Size
);
1971 if (Buffer
== NULL
) {
1972 return EFI_OUT_OF_RESOURCES
;
1975 HBufferImageListToBuffer (Buffer
, Size
);
1977 BufferPtr
= (UINT8
*) Buffer
;
1980 // pass deleted buffer out
1982 if (DeleteBuffer
!= NULL
) {
1983 for (Index
= 0; Index
< Count
; Index
++) {
1984 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1988 // delete the part from Pos
1990 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1991 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1996 HBufferImageFreeLines ();
1998 Status
= HBufferImageBufferToList (Buffer
, Size
);
2001 if (EFI_ERROR (Status
)) {
2005 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2006 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
2007 Link
= Link
->ForwardLink
;
2010 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2011 HBufferImage
.CurrentLine
= Line
;
2014 // if current cursor position if inside select area
2015 // then move it to the block's NEXT character
2017 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
2023 NewPos
= OldPos
- Count
;
2027 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2033 Add character to buffer, add before pos.
2035 @param[in] Pos Position, Pos starting from 0.
2036 @param[in] Count Count of characters to add.
2037 @param[in] AddBuffer Add buffer.
2039 @retval EFI_SUCCESS Success.
2042 HBufferImageAddCharacterToBuffer (
2054 HEFI_EDITOR_LINE
*Line
;
2066 // get the line that start position is at
2068 StartRow
= Pos
/ 0x10;
2070 Size
= HBufferImageGetTotalSize ();
2073 // relocate all the HBufferImage fields
2075 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2076 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2077 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2080 // move cursor before Pos
2088 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2090 Buffer
= AllocateZeroPool (Size
+ Count
);
2091 if (Buffer
== NULL
) {
2092 return EFI_OUT_OF_RESOURCES
;
2095 HBufferImageListToBuffer (Buffer
, Size
);
2097 BufferPtr
= (UINT8
*) Buffer
;
2100 // get a place to add
2102 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2103 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2108 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2109 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2114 HBufferImageFreeLines ();
2116 HBufferImageBufferToList (Buffer
, Size
);
2120 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2121 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2122 Link
= Link
->ForwardLink
;
2125 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2126 HBufferImage
.CurrentLine
= Line
;
2128 if (OldPos
>= Pos
) {
2129 NewPos
= OldPos
+ Count
;
2134 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2140 Delete current character from line.
2142 @retval EFI_SUCCESS The operationw as successful.
2146 HBufferImageDoDelete (
2151 HEFI_EDITOR_LINE
*Line
;
2157 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2159 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2161 Line
= HBufferImage
.CurrentLine
;
2164 // if beyond the last character
2166 if (FileColumn
> Line
->Size
) {
2171 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2175 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2178 // if is the last line
2179 // then only this line need to be refreshed
2182 HBufferImageNeedRefresh
= FALSE
;
2183 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2185 HBufferImageNeedRefresh
= TRUE
;
2186 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2189 if (!HBufferImage
.Modified
) {
2190 HBufferImage
.Modified
= TRUE
;
2197 Change the raw buffer to a list of lines for the UI.
2199 @param[in] Buffer The pointer to the buffer to fill.
2200 @param[in] Bytes The size of the buffer in bytes.
2202 @retval EFI_SUCCESS The operation was successful.
2203 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2207 HBufferImageBufferToList (
2215 HEFI_EDITOR_LINE
*Line
;
2220 BufferPtr
= (UINT8
*) Buffer
;
2223 // parse file content line by line
2225 while (TempI
< Bytes
) {
2226 if (Bytes
- TempI
>= 0x10) {
2229 Left
= Bytes
- TempI
;
2233 // allocate a new line
2235 Line
= HBufferImageCreateLine ();
2237 return EFI_OUT_OF_RESOURCES
;
2242 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2243 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2250 // last line is a full line, SO create a new line
2252 if (Left
== 0x10 || Bytes
== 0) {
2253 Line
= HBufferImageCreateLine ();
2255 return EFI_OUT_OF_RESOURCES
;
2263 Change the list of lines from the UI to a raw buffer.
2265 @param[in] Buffer The pointer to the buffer to fill.
2266 @param[in] Bytes The size of the buffer in bytes.
2268 @retval EFI_SUCCESS The operation was successful.
2272 HBufferImageListToBuffer (
2279 HEFI_EDITOR_LINE
*Line
;
2284 // change the line list to a large buffer
2286 if (HBufferImage
.Lines
== NULL
) {
2290 Link
= &HBufferImage
.Lines
->Link
;
2292 BufferPtr
= (UINT8
*) Buffer
;
2295 // deal line by line
2297 while (Link
!= HBufferImage
.ListHead
) {
2299 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2301 //@todo shouldn't this be an error???
2302 if (Count
+ Line
->Size
> Bytes
) {
2306 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2307 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2310 Count
+= Line
->Size
;
2311 BufferPtr
+= Line
->Size
;
2313 Link
= Link
->ForwardLink
;
2320 Move the mouse in the image buffer.
2322 @param[in] TextX The x-coordinate.
2323 @param[in] TextY The y-coordinate.
2327 HBufferImageAdjustMousePosition (
2338 // TextX and TextY is mouse movement data returned by mouse driver
2339 // This function will change it to MousePosition
2342 // get absolute TempX value
2350 // get absolute TempY value
2358 TempX
= HBufferImage
.MousePosition
.Column
;
2359 TempY
= HBufferImage
.MousePosition
.Row
;
2364 if (TempX
>= AbsX
) {
2374 if (TempY
>= AbsY
) {
2381 // check whether new mouse column position is beyond screen
2382 // if not, adjust it
2384 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2385 HBufferImage
.MousePosition
.Column
= TempX
;
2386 } else if (TempX
< 10) {
2387 HBufferImage
.MousePosition
.Column
= 10;
2388 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2389 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2392 // check whether new mouse row position is beyond screen
2393 // if not, adjust it
2395 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 4)) {
2396 HBufferImage
.MousePosition
.Row
= TempY
;
2397 } else if (TempY
< 2) {
2398 HBufferImage
.MousePosition
.Row
= 2;
2399 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 4)) {
2400 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 4);
2406 Dispatch input to different handler
2408 @param[in] Key The input key:
2412 Direction key: up/down/left/right/pgup/pgdn
2416 @retval EFI_SUCCESS The operation was successful.
2417 @retval EFI_LOAD_ERROR A load error occured.
2418 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2421 HBufferImageHandleInput (
2422 IN EFI_INPUT_KEY
*Key
2427 Status
= EFI_SUCCESS
;
2429 switch (Key
->ScanCode
) {
2434 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2441 Status
= HBufferImageScrollUp ();
2448 Status
= HBufferImageScrollDown ();
2455 Status
= HBufferImageScrollRight ();
2462 Status
= HBufferImageScrollLeft ();
2469 Status
= HBufferImagePageUp ();
2475 case SCAN_PAGE_DOWN
:
2476 Status
= HBufferImagePageDown ();
2483 Status
= HBufferImageDoDelete ();
2490 Status
= HBufferImageHome ();
2497 Status
= HBufferImageEnd ();
2501 Status
= StatusBarSetStatusString (L
"Unknown Command");