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
:
185 Free all the lines in HBufferImage.
192 @retval EFI_SUCCESS The operation was successful.
195 HBufferImageFreeLines (
199 HFreeLines (HBufferImage
.ListHead
, HBufferImage
.Lines
);
201 HBufferImage
.Lines
= NULL
;
202 HBufferImage
.CurrentLine
= NULL
;
203 HBufferImage
.NumLines
= 0;
209 Cleanup function for HBufferImage
211 @retval EFI_SUCCESS The operation was successful.
214 HBufferImageCleanup (
221 // free all the lines
223 Status
= HBufferImageFreeLines ();
225 SHELL_FREE_NON_NULL (HBufferImage
.ListHead
);
226 HBufferImage
.ListHead
= NULL
;
228 HFileImageCleanup ();
229 HDiskImageCleanup ();
238 @param[in] Line The lline to print.
239 @param[in] Row The row on screen ( begin from 1 ).
240 @param[in] FRow The FRow.
241 @param[in] Orig The original color.
242 @param[in] New The color to print with.
244 @retval EFI_SUCCESS The operation was successful.
247 HBufferImagePrintLine (
248 IN HEFI_EDITOR_LINE
*Line
,
251 IN HEFI_EDITOR_COLOR_UNION Orig
,
252 IN HEFI_EDITOR_COLOR_UNION New
267 // variable initialization
274 // print the selected area in opposite color
276 if (HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
277 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
278 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
280 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
281 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
283 if (FRow
>= RowStart
&& FRow
<= RowEnd
) {
287 if (FRow
> RowStart
) {
297 if (!HEditorMouseAction
) {
302 ((INT32
)Row
- 2 + HBufferImage
.LowVisibleRow
- 1) * 0x10
307 for (Index
= 0; Index
< 0x08 && Index
< Line
->Size
; Index
++) {
312 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
318 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
320 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
323 Pos
= 10 + (Index
* 3);
324 if (Line
->Buffer
[Index
] < 0x10) {
325 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
330 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
332 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
337 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
338 while (Index
< 0x08) {
339 Pos
= 10 + (Index
* 3);
340 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
344 while (Index
< 0x10 && Index
< Line
->Size
) {
349 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
355 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
357 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
360 Pos
= 10 + (Index
* 3) + 1;
361 if (Line
->Buffer
[Index
] < 0x10) {
362 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
366 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
370 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
371 while (Index
< 0x10) {
372 Pos
= 10 + (Index
* 3) + 1;
373 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
377 // restore the original color
379 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
382 // PRINT the buffer content
384 if (!HEditorMouseAction
) {
385 for (Index
= 0; Index
< 0x10 && Index
< Line
->Size
; Index
++) {
386 Pos
= ASCII_POSITION
+ Index
;
389 // learned from shelle.h -- IsValidChar
391 if (Line
->Buffer
[Index
] >= L
' ') {
392 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", (CHAR16
) Line
->Buffer
[Index
]);
394 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", '.');
398 while (Index
< 0x10) {
399 Pos
= ASCII_POSITION
+ Index
;
400 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
405 // restore the abundant blank in hex edit area to original color
409 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
410 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
411 } else if (ColEnd
== 8) {
412 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
413 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
415 Pos
= 10 + (ColEnd
- 1) * 3 + 3;
416 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
424 Function to decide if a column number is stored in the high bits.
426 @param[in] Column The column to examine.
427 @param[out] FCol The actual column number.
429 @retval TRUE The actual column was in high bits and is now in FCol.
430 @retval FALSE There was not a column number in the high bits.
433 HBufferImageIsAtHighBits (
441 // NOW AFTER THE SUB, Column start from 0
442 // 23 AND 24 ARE BOTH BLANK
453 *FCol
= (Column
/ 3) + 1;
455 if (Column
% 3 == 0) {
459 if ((Column
% 3 == 2)) {
467 Decide if a point is in the already selected area.
469 @param[in] MouseRow The row of the point to test.
470 @param[in] MouseCol The col of the point to test.
472 @retval TRUE The point is in the selected area.
473 @retval FALSE The point is not in the selected area.
476 HBufferImageIsInSelectedArea (
490 // judge mouse position whether is in selected area
495 if (HMainEditor
.SelectStart
== 0 || HMainEditor
.SelectEnd
== 0) {
499 // calculate the select area
501 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
502 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
504 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
505 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
507 FRow
= HBufferImage
.LowVisibleRow
+ MouseRow
- 2;
508 if (FRow
< RowStart
|| FRow
> RowEnd
) {
512 if (FRow
> RowStart
) {
520 MouseColStart
= 10 + (ColStart
- 1) * 3;
525 MouseColEnd
= 10 + (ColEnd
- 1) * 3 + 1;
530 if (MouseCol
< MouseColStart
|| MouseCol
> MouseColEnd
) {
538 Set mouse position according to HBufferImage.MousePosition.
540 @retval EFI_SUCCESS The operation was successful.
543 HBufferImageRestoreMousePosition (
547 HEFI_EDITOR_COLOR_UNION Orig
;
548 HEFI_EDITOR_COLOR_UNION New
;
551 BOOLEAN HasCharacter
;
552 HEFI_EDITOR_LINE
*CurrentLine
;
553 HEFI_EDITOR_LINE
*Line
;
558 if (HMainEditor
.MouseSupported
) {
560 if (HBufferImageMouseNeedRefresh
) {
562 HBufferImageMouseNeedRefresh
= FALSE
;
565 // if mouse position not moved and only mouse action
566 // so do not need to refresh mouse position
569 HBufferImage
.MousePosition
.Row
== HBufferImageBackupVar
.MousePosition
.Row
&&
570 HBufferImage
.MousePosition
.Column
== HBufferImageBackupVar
.MousePosition
.Column
577 // backup the old screen attributes
579 Orig
= HMainEditor
.ColorAttributes
;
580 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
581 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
584 // if in selected area,
585 // so do not need to refresh mouse
587 if (!HBufferImageIsInSelectedArea (
588 HBufferImageBackupVar
.MousePosition
.Row
,
589 HBufferImageBackupVar
.MousePosition
.Column
591 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
593 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
596 // clear the old mouse position
598 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
600 HighBits
= HBufferImageIsAtHighBits (
601 HBufferImageBackupVar
.MousePosition
.Column
,
606 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
607 HasCharacter
= FALSE
;
609 CurrentLine
= HBufferImage
.CurrentLine
;
610 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
612 if (Line
== NULL
|| FColumn
> Line
->Size
) {
613 HasCharacter
= FALSE
;
616 HBufferImage
.CurrentLine
= CurrentLine
;
620 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
621 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
627 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
628 Value
= (UINT8
) (Value
>> 4);
630 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
634 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
635 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
641 if (!HBufferImageIsInSelectedArea (
642 HBufferImage
.MousePosition
.Row
,
643 HBufferImage
.MousePosition
.Column
645 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
647 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
650 // clear the old mouse position
652 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImage
.MousePosition
.Row
- 2;
654 HighBits
= HBufferImageIsAtHighBits (
655 HBufferImage
.MousePosition
.Column
,
660 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
661 HasCharacter
= FALSE
;
663 CurrentLine
= HBufferImage
.CurrentLine
;
664 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
666 if (Line
== NULL
|| FColumn
> Line
->Size
) {
667 HasCharacter
= FALSE
;
670 HBufferImage
.CurrentLine
= CurrentLine
;
674 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
675 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
681 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
682 Value
= (UINT8
) (Value
>> 4);
684 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
688 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
689 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
695 // end of HasCharacter
697 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
700 // end of MouseNeedRefresh
704 // end of MouseSupported
710 Set cursor position according to HBufferImage.DisplayPosition.
712 @retval EFI_SUCCESS The operation was successful.
715 HBufferImageRestorePosition (
720 // set cursor position
722 gST
->ConOut
->SetCursorPosition (
724 HBufferImage
.DisplayPosition
.Column
- 1,
725 HBufferImage
.DisplayPosition
.Row
- 1
732 Refresh function for HBufferImage.
734 @retval EFI_SUCCESS The operation was successful.
735 @retval EFI_LOAD_ERROR A Load error occured.
739 HBufferImageRefresh (
744 HEFI_EDITOR_LINE
*Line
;
746 HEFI_EDITOR_COLOR_UNION Orig
;
747 HEFI_EDITOR_COLOR_UNION New
;
755 Orig
= HMainEditor
.ColorAttributes
;
756 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
757 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
760 // if it's the first time after editor launch, so should refresh
762 if (HEditorFirst
== FALSE
) {
764 // no definite required refresh
765 // and file position displayed on screen has not been changed
767 if (!HBufferImageNeedRefresh
&&
768 !HBufferImageOnlyLineNeedRefresh
&&
769 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
771 HBufferImageRestoreMousePosition ();
772 HBufferImageRestorePosition ();
777 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
780 // only need to refresh current line
782 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
784 HBufferImagePrintLine (
785 HBufferImage
.CurrentLine
,
786 HBufferImage
.DisplayPosition
.Row
,
787 HBufferImage
.BufferPosition
.Row
,
793 // the whole edit area need refresh
795 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
796 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
797 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
798 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
800 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
803 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
806 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
807 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
809 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
814 if (StartRow
> EndRow
) {
820 FStartRow
= StartRow
;
823 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
824 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
828 // not mouse selection actions
830 FStartRow
= HBufferImage
.LowVisibleRow
;
832 EndRow
= (HMainEditor
.ScreenSize
.Row
- 4);
837 if (HBufferImage
.Lines
== NULL
) {
838 HBufferImageRestoreMousePosition ();
839 HBufferImageRestorePosition ();
840 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
844 // get the first line that will be displayed
846 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
848 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
849 return EFI_LOAD_ERROR
;
852 Link
= &(Line
->Link
);
855 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
860 HBufferImagePrintLine (
863 HBufferImage
.LowVisibleRow
+ Row
- 2,
868 Link
= Link
->ForwardLink
;
870 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
872 while (Row
<= EndRow
) {
873 EditorClearLine (Row
, HMainEditor
.ScreenSize
.Column
, HMainEditor
.ScreenSize
.Row
);
877 // while not file end and not screen full
881 HBufferImageRestoreMousePosition ();
882 HBufferImageRestorePosition ();
884 HBufferImageNeedRefresh
= FALSE
;
885 HBufferImageOnlyLineNeedRefresh
= FALSE
;
886 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
892 Read an image into a buffer friom a source.
894 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
895 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
896 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
897 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
898 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
899 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
900 @param[in] BufferType The type of buffer to save. IGNORED.
901 @param[in] Recover TRUE for recovermode, FALSE otherwise.
903 @return EFI_SUCCESS The operation was successful.
908 IN CONST CHAR16
*FileName
,
909 IN CONST CHAR16
*DiskName
,
914 IN EDIT_FILE_TYPE BufferType
,
919 EDIT_FILE_TYPE BufferTypeBackup
;
922 // variable initialization
924 Status
= EFI_SUCCESS
;
925 HBufferImage
.BufferType
= BufferType
;
928 // three types of buffer supported
933 BufferTypeBackup
= HBufferImage
.BufferType
;
935 switch (BufferType
) {
936 case FileTypeFileBuffer
:
937 Status
= HFileImageRead (FileName
, Recover
);
940 case FileTypeDiskBuffer
:
941 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
944 case FileTypeMemBuffer
:
945 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
949 if (EFI_ERROR (Status
)) {
950 HBufferImage
.BufferType
= BufferTypeBackup
;
957 Save the current image.
959 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
960 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
961 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
962 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
963 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
964 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
965 @param[in] BufferType The type of buffer to save. IGNORED.
967 @return EFI_SUCCESS The operation was successful.
977 IN EDIT_FILE_TYPE BufferType
981 EDIT_FILE_TYPE BufferTypeBackup
;
984 // variable initialization
986 Status
= EFI_SUCCESS
;
987 BufferTypeBackup
= HBufferImage
.BufferType
;
989 switch (HBufferImage
.BufferType
) {
993 case FileTypeFileBuffer
:
994 Status
= HFileImageSave (FileName
);
1000 case FileTypeDiskBuffer
:
1001 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1007 case FileTypeMemBuffer
:
1008 Status
= HMemImageSave (MemOffset
, MemSize
);
1012 if (EFI_ERROR (Status
)) {
1013 HBufferImage
.BufferType
= BufferTypeBackup
;
1020 Create a new line and append it to the line list.
1025 @retval NULL create line failed.
1026 @return the line created.
1030 HBufferImageCreateLine (
1034 HEFI_EDITOR_LINE
*Line
;
1037 // allocate for line structure
1039 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1044 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1047 HBufferImage
.NumLines
++;
1050 // insert to line list
1052 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1054 if (HBufferImage
.Lines
== NULL
) {
1055 HBufferImage
.Lines
= CR (
1056 HBufferImage
.ListHead
->ForwardLink
,
1059 EFI_EDITOR_LINE_LIST
1067 Free the current image.
1069 @retval EFI_SUCCESS The operation was successful.
1079 HBufferImageFreeLines ();
1085 change char to int value based on Hex.
1087 @param[in] Char The input char.
1089 @return The character's index value.
1090 @retval -1 The operation failed.
1094 HBufferImageCharToHex (
1099 // change the character to hex
1101 if (Char
>= L
'0' && Char
<= L
'9') {
1102 return (INTN
) (Char
- L
'0');
1105 if (Char
>= L
'a' && Char
<= L
'f') {
1106 return (INTN
) (Char
- L
'a' + 10);
1109 if (Char
>= L
'A' && Char
<= L
'F') {
1110 return (INTN
) (Char
- L
'A' + 10);
1119 @param[in] Char -- input char.
1121 @retval EFI_SUCCESS The operation was successful.
1122 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1126 HBufferImageAddChar (
1130 HEFI_EDITOR_LINE
*Line
;
1131 HEFI_EDITOR_LINE
*NewLine
;
1138 Value
= HBufferImageCharToHex (Char
);
1147 Line
= HBufferImage
.CurrentLine
;
1148 FRow
= HBufferImage
.BufferPosition
.Row
;
1149 FCol
= HBufferImage
.BufferPosition
.Column
;
1150 High
= HBufferImage
.HighBits
;
1153 // only needs to refresh current line
1155 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1158 // not a full line and beyond the last character
1160 if (FCol
> Line
->Size
) {
1162 // cursor always at high 4 bits
1163 // and always put input to the low 4 bits
1165 Line
->Buffer
[Line
->Size
] = (UINT8
) Value
;
1170 Old
= Line
->Buffer
[FCol
- 1];
1173 // always put the input to the low 4 bits
1175 Old
= (UINT8
) (Old
& 0x0f);
1176 Old
= (UINT8
) (Old
<< 4);
1177 Old
= (UINT8
) (Value
+ Old
);
1178 Line
->Buffer
[FCol
- 1] = Old
;
1181 // at the low 4 bits of the last character of a full line
1182 // so if no next line, need to create a new line
1184 if (!High
&& FCol
== 0x10) {
1186 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1187 HBufferImageNeedRefresh
= TRUE
;
1189 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1193 // create a new line
1195 NewLine
= HBufferImageCreateLine ();
1196 if (NewLine
== NULL
) {
1197 return EFI_OUT_OF_RESOURCES
;
1204 // end of == ListHead
1210 // if already at end of this line, scroll it to the start of next line
1212 if (FCol
== 0x10 && !High
) {
1214 // definitely has next line
1221 // if not at end of this line, just move to next column
1239 // move cursor to right
1241 HBufferImageMovePosition (FRow
, FCol
, High
);
1243 if (!HBufferImage
.Modified
) {
1244 HBufferImage
.Modified
= TRUE
;
1251 Delete the previous character.
1253 @retval EFI_SUCCESS The operationw as successful.
1257 HBufferImageDoBackspace (
1261 HEFI_EDITOR_LINE
*Line
;
1268 // variable initialization
1273 // already the first character
1275 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
1279 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1281 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1283 Line
= HBufferImage
.CurrentLine
;
1285 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
1289 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1292 // if is the last line
1293 // then only this line need to be refreshed
1296 HBufferImageNeedRefresh
= FALSE
;
1297 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1299 HBufferImageNeedRefresh
= TRUE
;
1300 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1303 if (!HBufferImage
.Modified
) {
1304 HBufferImage
.Modified
= TRUE
;
1311 ASCII key + Backspace + return.
1313 @param[in] Char The input char.
1315 @retval EFI_SUCCESS The operation was successful.
1316 @retval EFI_LOAD_ERROR A load error occured.
1317 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1321 HBufferImageDoCharInput (
1327 Status
= EFI_SUCCESS
;
1334 Status
= HBufferImageDoBackspace ();
1341 // Tabs, Returns are thought as nothing
1347 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1349 if (Char
> 127 || Char
< 32) {
1350 Status
= StatusBarSetStatusString (L
"Unknown Command");
1352 Status
= HBufferImageAddChar (Char
);
1362 Check user specified FileRow is above current screen.
1364 @param[in] FileRow Row of file position ( start from 1 ).
1366 @retval TRUE It is above the current screen.
1367 @retval FALSE It is not above the current screen.
1371 HAboveCurrentScreen (
1375 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1383 Check user specified FileRow is under current screen.
1385 @param[in] FileRow Row of file position ( start from 1 ).
1387 @retval TRUE It is under the current screen.
1388 @retval FALSE It is not under the current screen.
1392 HUnderCurrentScreen (
1396 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 5) - 1) {
1404 According to cursor's file position, adjust screen display.
1406 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1407 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1408 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1411 HBufferImageMovePosition (
1412 IN UINTN NewFilePosRow
,
1413 IN UINTN NewFilePosCol
,
1421 UINTN NewDisplayCol
;
1424 // CALCULATE gap between current file position and new file position
1426 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1428 Under
= HUnderCurrentScreen (NewFilePosRow
);
1429 Above
= HAboveCurrentScreen (NewFilePosRow
);
1431 HBufferImage
.HighBits
= HighBits
;
1434 // if is below current screen
1438 // display row will be unchanged
1440 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1444 // has enough above line, so display row unchanged
1445 // not has enough above lines, so the first line is
1446 // at the first display line
1448 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1449 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1452 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1455 // in current screen
1457 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1459 Abs
= (UINTN
)ABS(RowGap
);
1460 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1462 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1468 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1471 // always in current screen
1473 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1475 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1476 if (NewFilePosCol
> 0x8) {
1484 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1487 // let CurrentLine point to correct line;
1489 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1494 Scroll cursor to right.
1496 @retval EFI_SUCCESS The operation was successful.
1499 HBufferImageScrollRight (
1503 HEFI_EDITOR_LINE
*Line
;
1508 // scroll right will always move to the high4 bits of the next character
1510 HBufferImageNeedRefresh
= FALSE
;
1511 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1513 Line
= HBufferImage
.CurrentLine
;
1515 FRow
= HBufferImage
.BufferPosition
.Row
;
1516 FCol
= HBufferImage
.BufferPosition
.Column
;
1519 // this line is not full and no next line
1521 if (FCol
> Line
->Size
) {
1525 // if already at end of this line, scroll it to the start of next line
1531 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1540 // if not at end of this line, just move to next column
1546 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1552 Scroll cursor to left.
1554 @retval EFI_SUCCESS The operation was successful.
1557 HBufferImageScrollLeft (
1562 HEFI_EDITOR_LINE
*Line
;
1566 HBufferImageNeedRefresh
= FALSE
;
1567 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1569 Line
= HBufferImage
.CurrentLine
;
1571 FRow
= HBufferImage
.BufferPosition
.Row
;
1572 FCol
= HBufferImage
.BufferPosition
.Column
;
1575 // if already at start of this line, so move to the end of previous line
1579 // has previous line
1581 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1583 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1590 // if not at start of this line, just move to previous column
1595 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1601 Scroll cursor to the next line
1603 @retval EFI_SUCCESS The operation was successful.
1606 HBufferImageScrollDown (
1610 HEFI_EDITOR_LINE
*Line
;
1615 Line
= HBufferImage
.CurrentLine
;
1617 FRow
= HBufferImage
.BufferPosition
.Row
;
1618 FCol
= HBufferImage
.BufferPosition
.Column
;
1619 HighBits
= HBufferImage
.HighBits
;
1624 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1626 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1629 // if the next line is not that long, so move to end of next line
1631 if (FCol
> Line
->Size
) {
1632 FCol
= Line
->Size
+ 1;
1640 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1646 Scroll cursor to previous line
1648 @retval EFI_SUCCESS The operation was successful.
1651 HBufferImageScrollUp (
1655 HEFI_EDITOR_LINE
*Line
;
1659 Line
= HBufferImage
.CurrentLine
;
1661 FRow
= HBufferImage
.BufferPosition
.Row
;
1662 FCol
= HBufferImage
.BufferPosition
.Column
;
1665 // has previous line
1667 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1674 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1680 Scroll cursor to next page
1682 @retval EFI_SUCCESS The operation was successful.
1685 HBufferImagePageDown (
1689 HEFI_EDITOR_LINE
*Line
;
1695 Line
= HBufferImage
.CurrentLine
;
1697 FRow
= HBufferImage
.BufferPosition
.Row
;
1698 FCol
= HBufferImage
.BufferPosition
.Column
;
1699 HighBits
= HBufferImage
.HighBits
;
1704 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 5)) {
1705 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1708 // MOVE CURSOR TO LAST LINE
1710 Gap
= HBufferImage
.NumLines
- FRow
;
1715 Line
= HMoveLine (Gap
);
1718 // if that line, is not that long, so move to the end of that line
1720 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1721 FCol
= Line
->Size
+ 1;
1727 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1733 Scroll cursor to previous page
1735 @retval EFI_SUCCESS The operation was successful.
1738 HBufferImagePageUp (
1742 HEFI_EDITOR_LINE
*Line
;
1748 Line
= HBufferImage
.CurrentLine
;
1750 FRow
= HBufferImage
.BufferPosition
.Row
;
1751 FCol
= HBufferImage
.BufferPosition
.Column
;
1754 // has previous page
1756 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 5)) {
1757 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1760 // the first line of file will displayed on the first line of screen
1771 Line
= HMoveLine (Retreat
);
1775 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1781 Scroll cursor to start of line
1783 @retval EFI_SUCCESS The operation was successful.
1790 HEFI_EDITOR_LINE
*Line
;
1795 Line
= HBufferImage
.CurrentLine
;
1798 // curosr will at the high bit
1800 FRow
= HBufferImage
.BufferPosition
.Row
;
1805 // move cursor position
1807 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1813 Scroll cursor to end of line.
1815 @retval EFI_SUCCESS Teh operation was successful.
1822 HEFI_EDITOR_LINE
*Line
;
1828 // need refresh mouse
1830 HBufferImageMouseNeedRefresh
= TRUE
;
1832 Line
= HBufferImage
.CurrentLine
;
1834 FRow
= HBufferImage
.BufferPosition
.Row
;
1836 if (Line
->Size
== 0x10) {
1840 FCol
= Line
->Size
+ 1;
1844 // move cursor position
1846 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1852 Get the size of the open buffer.
1854 @retval The size in bytes.
1857 HBufferImageGetTotalSize (
1863 HEFI_EDITOR_LINE
*Line
;
1866 // calculate the total size of whole line list's buffer
1868 if (HBufferImage
.Lines
== NULL
) {
1873 HBufferImage
.ListHead
->BackLink
,
1876 EFI_EDITOR_LINE_LIST
1879 // one line at most 0x10
1881 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1887 Delete character from buffer.
1889 @param[in] Pos Position, Pos starting from 0.
1890 @param[in] Count The Count of characters to delete.
1891 @param[out] DeleteBuffer The DeleteBuffer.
1893 @retval EFI_SUCCESS Success
1896 HBufferImageDeleteCharacterFromBuffer (
1899 OUT UINT8
*DeleteBuffer
1908 HEFI_EDITOR_LINE
*Line
;
1921 // get the line that start position is at
1923 StartRow
= Pos
/ 0x10;
1925 Size
= HBufferImageGetTotalSize ();
1928 return EFI_LOAD_ERROR
;
1936 // relocate all the HBufferImage fields
1938 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1939 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1940 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1944 // has character before it,
1945 // so locate according to block's previous character
1951 // has no character before it,
1952 // so locate according to block's next character
1957 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1959 Buffer
= AllocateZeroPool (Size
);
1960 if (Buffer
== NULL
) {
1961 return EFI_OUT_OF_RESOURCES
;
1964 HBufferImageListToBuffer (Buffer
, Size
);
1966 BufferPtr
= (UINT8
*) Buffer
;
1969 // pass deleted buffer out
1971 if (DeleteBuffer
!= NULL
) {
1972 for (Index
= 0; Index
< Count
; Index
++) {
1973 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1977 // delete the part from Pos
1979 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1980 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1985 HBufferImageFreeLines ();
1987 Status
= HBufferImageBufferToList (Buffer
, Size
);
1990 if (EFI_ERROR (Status
)) {
1994 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1995 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
1996 Link
= Link
->ForwardLink
;
1999 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2000 HBufferImage
.CurrentLine
= Line
;
2003 // if current cursor position if inside select area
2004 // then move it to the block's NEXT character
2006 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
2012 NewPos
= OldPos
- Count
;
2016 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2022 Add character to buffer, add before pos.
2024 @param[in] Pos Position, Pos starting from 0.
2025 @param[in] Count Count of characters to add.
2026 @param[in] AddBuffer Add buffer.
2028 @retval EFI_SUCCESS Success.
2031 HBufferImageAddCharacterToBuffer (
2043 HEFI_EDITOR_LINE
*Line
;
2055 // get the line that start position is at
2057 StartRow
= Pos
/ 0x10;
2059 Size
= HBufferImageGetTotalSize ();
2062 // relocate all the HBufferImage fields
2064 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2065 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2066 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2069 // move cursor before Pos
2077 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2079 Buffer
= AllocateZeroPool (Size
+ Count
);
2080 if (Buffer
== NULL
) {
2081 return EFI_OUT_OF_RESOURCES
;
2084 HBufferImageListToBuffer (Buffer
, Size
);
2086 BufferPtr
= (UINT8
*) Buffer
;
2089 // get a place to add
2091 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2092 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2097 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2098 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2103 HBufferImageFreeLines ();
2105 HBufferImageBufferToList (Buffer
, Size
);
2109 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2110 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2111 Link
= Link
->ForwardLink
;
2114 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2115 HBufferImage
.CurrentLine
= Line
;
2117 if (OldPos
>= Pos
) {
2118 NewPos
= OldPos
+ Count
;
2123 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2129 Delete current character from line.
2131 @retval EFI_SUCCESS The operationw as successful.
2135 HBufferImageDoDelete (
2140 HEFI_EDITOR_LINE
*Line
;
2146 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2148 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2150 Line
= HBufferImage
.CurrentLine
;
2153 // if beyond the last character
2155 if (FileColumn
> Line
->Size
) {
2160 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2164 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2167 // if is the last line
2168 // then only this line need to be refreshed
2171 HBufferImageNeedRefresh
= FALSE
;
2172 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2174 HBufferImageNeedRefresh
= TRUE
;
2175 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2178 if (!HBufferImage
.Modified
) {
2179 HBufferImage
.Modified
= TRUE
;
2186 Change the raw buffer to a list of lines for the UI.
2188 @param[in] Buffer The pointer to the buffer to fill.
2189 @param[in] Bytes The size of the buffer in bytes.
2191 @retval EFI_SUCCESS The operation was successful.
2192 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2196 HBufferImageBufferToList (
2204 HEFI_EDITOR_LINE
*Line
;
2209 BufferPtr
= (UINT8
*) Buffer
;
2212 // parse file content line by line
2214 while (TempI
< Bytes
) {
2215 if (Bytes
- TempI
>= 0x10) {
2218 Left
= Bytes
- TempI
;
2222 // allocate a new line
2224 Line
= HBufferImageCreateLine ();
2226 return EFI_OUT_OF_RESOURCES
;
2231 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2232 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2239 // last line is a full line, SO create a new line
2241 if (Left
== 0x10 || Bytes
== 0) {
2242 Line
= HBufferImageCreateLine ();
2244 return EFI_OUT_OF_RESOURCES
;
2252 Change the list of lines from the UI to a raw buffer.
2254 @param[in] Buffer The pointer to the buffer to fill.
2255 @param[in] Bytes The size of the buffer in bytes.
2257 @retval EFI_SUCCESS The operation was successful.
2261 HBufferImageListToBuffer (
2268 HEFI_EDITOR_LINE
*Line
;
2273 // change the line list to a large buffer
2275 if (HBufferImage
.Lines
== NULL
) {
2279 Link
= &HBufferImage
.Lines
->Link
;
2281 BufferPtr
= (UINT8
*) Buffer
;
2284 // deal line by line
2286 while (Link
!= HBufferImage
.ListHead
) {
2288 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2290 //@todo shouldn't this be an error???
2291 if (Count
+ Line
->Size
> Bytes
) {
2295 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2296 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2299 Count
+= Line
->Size
;
2300 BufferPtr
+= Line
->Size
;
2302 Link
= Link
->ForwardLink
;
2309 Move the mouse in the image buffer.
2311 @param[in] TextX The x-coordinate.
2312 @param[in] TextY The y-coordinate.
2316 HBufferImageAdjustMousePosition (
2327 // TextX and TextY is mouse movement data returned by mouse driver
2328 // This function will change it to MousePosition
2331 // get absolute TempX value
2339 // get absolute TempY value
2347 TempX
= HBufferImage
.MousePosition
.Column
;
2348 TempY
= HBufferImage
.MousePosition
.Row
;
2353 if (TempX
>= AbsX
) {
2363 if (TempY
>= AbsY
) {
2370 // check whether new mouse column position is beyond screen
2371 // if not, adjust it
2373 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2374 HBufferImage
.MousePosition
.Column
= TempX
;
2375 } else if (TempX
< 10) {
2376 HBufferImage
.MousePosition
.Column
= 10;
2377 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2378 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2381 // check whether new mouse row position is beyond screen
2382 // if not, adjust it
2384 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 4)) {
2385 HBufferImage
.MousePosition
.Row
= TempY
;
2386 } else if (TempY
< 2) {
2387 HBufferImage
.MousePosition
.Row
= 2;
2388 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 4)) {
2389 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 4);
2395 Dispatch input to different handler
2397 @param[in] Key The input key:
2401 Direction key: up/down/left/right/pgup/pgdn
2405 @retval EFI_SUCCESS The operation was successful.
2406 @retval EFI_LOAD_ERROR A load error occured.
2407 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2410 HBufferImageHandleInput (
2411 IN EFI_INPUT_KEY
*Key
2416 Status
= EFI_SUCCESS
;
2418 switch (Key
->ScanCode
) {
2423 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2430 Status
= HBufferImageScrollUp ();
2437 Status
= HBufferImageScrollDown ();
2444 Status
= HBufferImageScrollRight ();
2451 Status
= HBufferImageScrollLeft ();
2458 Status
= HBufferImagePageUp ();
2464 case SCAN_PAGE_DOWN
:
2465 Status
= HBufferImagePageDown ();
2472 Status
= HBufferImageDoDelete ();
2479 Status
= HBufferImageHome ();
2486 Status
= HBufferImageEnd ();
2490 Status
= StatusBarSetStatusString (L
"Unknown Command");