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
;
757 Orig
= HMainEditor
.ColorAttributes
;
758 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
759 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
762 // if it's the first time after editor launch, so should refresh
764 if (HEditorFirst
== FALSE
) {
766 // no definite required refresh
767 // and file position displayed on screen has not been changed
769 if (!HBufferImageNeedRefresh
&&
770 !HBufferImageOnlyLineNeedRefresh
&&
771 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
773 HBufferImageRestoreMousePosition ();
774 HBufferImageRestorePosition ();
779 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
782 // only need to refresh current line
784 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
786 HBufferImagePrintLine (
787 HBufferImage
.CurrentLine
,
788 HBufferImage
.DisplayPosition
.Row
,
789 HBufferImage
.BufferPosition
.Row
,
795 // the whole edit area need refresh
797 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
798 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
799 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
800 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
802 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
805 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
808 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
809 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
811 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
816 if (StartRow
> EndRow
) {
822 FStartRow
= StartRow
;
824 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
825 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
829 // not mouse selection actions
831 FStartRow
= HBufferImage
.LowVisibleRow
;
833 EndRow
= (HMainEditor
.ScreenSize
.Row
- 1);
838 if (HBufferImage
.Lines
== NULL
) {
839 HBufferImageRestoreMousePosition ();
840 HBufferImageRestorePosition ();
841 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
845 // get the first line that will be displayed
847 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
849 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
850 return EFI_LOAD_ERROR
;
853 Link
= &(Line
->Link
);
856 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
861 HBufferImagePrintLine (
864 HBufferImage
.LowVisibleRow
+ Row
- 2,
869 Link
= Link
->ForwardLink
;
871 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
873 while (Row
<= EndRow
) {
874 EditorClearLine (Row
, HMainEditor
.ScreenSize
.Column
, HMainEditor
.ScreenSize
.Row
);
878 // while not file end and not screen full
882 HBufferImageRestoreMousePosition ();
883 HBufferImageRestorePosition ();
885 HBufferImageNeedRefresh
= FALSE
;
886 HBufferImageOnlyLineNeedRefresh
= FALSE
;
887 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
893 Read an image into a buffer friom a source.
895 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
896 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
897 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
898 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
899 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
900 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
901 @param[in] BufferType The type of buffer to save. IGNORED.
902 @param[in] Recover TRUE for recovermode, FALSE otherwise.
904 @return EFI_SUCCESS The operation was successful.
909 IN CONST CHAR16
*FileName
,
910 IN CONST CHAR16
*DiskName
,
915 IN EDIT_FILE_TYPE BufferType
,
920 EDIT_FILE_TYPE BufferTypeBackup
;
923 // variable initialization
925 Status
= EFI_SUCCESS
;
926 HBufferImage
.BufferType
= BufferType
;
929 // three types of buffer supported
934 BufferTypeBackup
= HBufferImage
.BufferType
;
936 switch (BufferType
) {
937 case FileTypeFileBuffer
:
938 Status
= HFileImageRead (FileName
, Recover
);
941 case FileTypeDiskBuffer
:
942 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
945 case FileTypeMemBuffer
:
946 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
950 Status
= EFI_NOT_FOUND
;
954 if (EFI_ERROR (Status
)) {
955 HBufferImage
.BufferType
= BufferTypeBackup
;
962 Save the current image.
964 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
965 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
966 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
967 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
968 @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
969 @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
970 @param[in] BufferType The type of buffer to save. IGNORED.
972 @return EFI_SUCCESS The operation was successful.
982 IN EDIT_FILE_TYPE BufferType
986 EDIT_FILE_TYPE BufferTypeBackup
;
989 // variable initialization
991 Status
= EFI_SUCCESS
;
992 BufferTypeBackup
= HBufferImage
.BufferType
;
994 switch (HBufferImage
.BufferType
) {
998 case FileTypeFileBuffer
:
999 Status
= HFileImageSave (FileName
);
1005 case FileTypeDiskBuffer
:
1006 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1012 case FileTypeMemBuffer
:
1013 Status
= HMemImageSave (MemOffset
, MemSize
);
1017 Status
= EFI_NOT_FOUND
;
1021 if (EFI_ERROR (Status
)) {
1022 HBufferImage
.BufferType
= BufferTypeBackup
;
1029 Create a new line and append it to the line list.
1034 @retval NULL create line failed.
1035 @return the line created.
1039 HBufferImageCreateLine (
1043 HEFI_EDITOR_LINE
*Line
;
1046 // allocate for line structure
1048 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1053 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1056 HBufferImage
.NumLines
++;
1059 // insert to line list
1061 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1063 if (HBufferImage
.Lines
== NULL
) {
1064 HBufferImage
.Lines
= CR (
1065 HBufferImage
.ListHead
->ForwardLink
,
1068 EFI_EDITOR_LINE_LIST
1076 Free the current image.
1078 @retval EFI_SUCCESS The operation was successful.
1088 HBufferImageFreeLines ();
1094 change char to int value based on Hex.
1096 @param[in] Char The input char.
1098 @return The character's index value.
1099 @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.
1135 HBufferImageAddChar (
1139 HEFI_EDITOR_LINE
*Line
;
1140 HEFI_EDITOR_LINE
*NewLine
;
1147 Value
= HBufferImageCharToHex (Char
);
1156 Line
= HBufferImage
.CurrentLine
;
1157 FRow
= HBufferImage
.BufferPosition
.Row
;
1158 FCol
= HBufferImage
.BufferPosition
.Column
;
1159 High
= HBufferImage
.HighBits
;
1162 // only needs to refresh current line
1164 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1167 // not a full line and beyond the last character
1169 if (FCol
> Line
->Size
) {
1171 // cursor always at high 4 bits
1172 // and always put input to the low 4 bits
1174 Line
->Buffer
[Line
->Size
] = (UINT8
) Value
;
1179 Old
= Line
->Buffer
[FCol
- 1];
1182 // always put the input to the low 4 bits
1184 Old
= (UINT8
) (Old
& 0x0f);
1185 Old
= (UINT8
) (Old
<< 4);
1186 Old
= (UINT8
) (Value
+ Old
);
1187 Line
->Buffer
[FCol
- 1] = Old
;
1190 // at the low 4 bits of the last character of a full line
1191 // so if no next line, need to create a new line
1193 if (!High
&& FCol
== 0x10) {
1195 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1196 HBufferImageNeedRefresh
= TRUE
;
1198 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1202 // create a new line
1204 NewLine
= HBufferImageCreateLine ();
1205 if (NewLine
== NULL
) {
1206 return EFI_OUT_OF_RESOURCES
;
1213 // end of == ListHead
1219 // if already at end of this line, scroll it to the start of next line
1221 if (FCol
== 0x10 && !High
) {
1223 // definitely has next line
1230 // if not at end of this line, just move to next column
1248 // move cursor to right
1250 HBufferImageMovePosition (FRow
, FCol
, High
);
1252 if (!HBufferImage
.Modified
) {
1253 HBufferImage
.Modified
= TRUE
;
1260 Delete the previous character.
1262 @retval EFI_SUCCESS The operationw as successful.
1266 HBufferImageDoBackspace (
1270 HEFI_EDITOR_LINE
*Line
;
1277 // variable initialization
1282 // already the first character
1284 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
1288 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
1290 FileColumn
= HBufferImage
.BufferPosition
.Column
;
1292 Line
= HBufferImage
.CurrentLine
;
1294 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
1298 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
1301 // if is the last line
1302 // then only this line need to be refreshed
1305 HBufferImageNeedRefresh
= FALSE
;
1306 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1308 HBufferImageNeedRefresh
= TRUE
;
1309 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1312 if (!HBufferImage
.Modified
) {
1313 HBufferImage
.Modified
= TRUE
;
1320 ASCII key + Backspace + return.
1322 @param[in] Char The input char.
1324 @retval EFI_SUCCESS The operation was successful.
1325 @retval EFI_LOAD_ERROR A load error occured.
1326 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1330 HBufferImageDoCharInput (
1336 Status
= EFI_SUCCESS
;
1343 Status
= HBufferImageDoBackspace ();
1350 // Tabs, Returns are thought as nothing
1356 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1358 if (Char
> 127 || Char
< 32) {
1359 Status
= StatusBarSetStatusString (L
"Unknown Command");
1361 Status
= HBufferImageAddChar (Char
);
1371 Check user specified FileRow is above current screen.
1373 @param[in] FileRow Row of file position ( start from 1 ).
1375 @retval TRUE It is above the current screen.
1376 @retval FALSE It is not above the current screen.
1380 HAboveCurrentScreen (
1384 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1392 Check user specified FileRow is under current screen.
1394 @param[in] FileRow Row of file position ( start from 1 ).
1396 @retval TRUE It is under the current screen.
1397 @retval FALSE It is not under the current screen.
1401 HUnderCurrentScreen (
1405 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 2) - 1) {
1413 According to cursor's file position, adjust screen display.
1415 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1416 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1417 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1420 HBufferImageMovePosition (
1421 IN UINTN NewFilePosRow
,
1422 IN UINTN NewFilePosCol
,
1430 UINTN NewDisplayCol
;
1433 // CALCULATE gap between current file position and new file position
1435 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1437 Under
= HUnderCurrentScreen (NewFilePosRow
);
1438 Above
= HAboveCurrentScreen (NewFilePosRow
);
1440 HBufferImage
.HighBits
= HighBits
;
1443 // if is below current screen
1447 // display row will be unchanged
1449 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1453 // has enough above line, so display row unchanged
1454 // not has enough above lines, so the first line is
1455 // at the first display line
1457 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1458 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1461 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1464 // in current screen
1466 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1468 Abs
= (UINTN
)ABS(RowGap
);
1469 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1471 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1477 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1480 // always in current screen
1482 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1484 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1485 if (NewFilePosCol
> 0x8) {
1493 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1496 // let CurrentLine point to correct line;
1498 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1503 Scroll cursor to right.
1505 @retval EFI_SUCCESS The operation was successful.
1508 HBufferImageScrollRight (
1512 HEFI_EDITOR_LINE
*Line
;
1517 // scroll right will always move to the high4 bits of the next character
1519 HBufferImageNeedRefresh
= FALSE
;
1520 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1522 Line
= HBufferImage
.CurrentLine
;
1524 FRow
= HBufferImage
.BufferPosition
.Row
;
1525 FCol
= HBufferImage
.BufferPosition
.Column
;
1528 // this line is not full and no next line
1530 if (FCol
> Line
->Size
) {
1534 // if already at end of this line, scroll it to the start of next line
1540 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1549 // if not at end of this line, just move to next column
1555 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1561 Scroll cursor to left.
1563 @retval EFI_SUCCESS The operation was successful.
1566 HBufferImageScrollLeft (
1571 HEFI_EDITOR_LINE
*Line
;
1575 HBufferImageNeedRefresh
= FALSE
;
1576 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1578 Line
= HBufferImage
.CurrentLine
;
1580 FRow
= HBufferImage
.BufferPosition
.Row
;
1581 FCol
= HBufferImage
.BufferPosition
.Column
;
1584 // if already at start of this line, so move to the end of previous line
1588 // has previous line
1590 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1592 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1599 // if not at start of this line, just move to previous column
1604 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1610 Scroll cursor to the next line
1612 @retval EFI_SUCCESS The operation was successful.
1615 HBufferImageScrollDown (
1619 HEFI_EDITOR_LINE
*Line
;
1624 Line
= HBufferImage
.CurrentLine
;
1626 FRow
= HBufferImage
.BufferPosition
.Row
;
1627 FCol
= HBufferImage
.BufferPosition
.Column
;
1628 HighBits
= HBufferImage
.HighBits
;
1633 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1635 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1638 // if the next line is not that long, so move to end of next line
1640 if (FCol
> Line
->Size
) {
1641 FCol
= Line
->Size
+ 1;
1649 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1655 Scroll cursor to previous line
1657 @retval EFI_SUCCESS The operation was successful.
1660 HBufferImageScrollUp (
1664 HEFI_EDITOR_LINE
*Line
;
1668 Line
= HBufferImage
.CurrentLine
;
1670 FRow
= HBufferImage
.BufferPosition
.Row
;
1671 FCol
= HBufferImage
.BufferPosition
.Column
;
1674 // has previous line
1676 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1683 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1689 Scroll cursor to next page
1691 @retval EFI_SUCCESS The operation was successful.
1694 HBufferImagePageDown (
1698 HEFI_EDITOR_LINE
*Line
;
1704 Line
= HBufferImage
.CurrentLine
;
1706 FRow
= HBufferImage
.BufferPosition
.Row
;
1707 FCol
= HBufferImage
.BufferPosition
.Column
;
1708 HighBits
= HBufferImage
.HighBits
;
1713 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 2)) {
1714 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1717 // MOVE CURSOR TO LAST LINE
1719 Gap
= HBufferImage
.NumLines
- FRow
;
1724 Line
= HMoveLine (Gap
);
1727 // if that line, is not that long, so move to the end of that line
1729 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1730 FCol
= Line
->Size
+ 1;
1736 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1742 Scroll cursor to previous page
1744 @retval EFI_SUCCESS The operation was successful.
1747 HBufferImagePageUp (
1756 FRow
= HBufferImage
.BufferPosition
.Row
;
1757 FCol
= HBufferImage
.BufferPosition
.Column
;
1760 // has previous page
1762 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 2)) {
1763 Gap
= (HMainEditor
.ScreenSize
.Row
- 2);
1766 // the first line of file will displayed on the first line of screen
1776 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1782 Scroll cursor to start of line
1784 @retval EFI_SUCCESS The operation was successful.
1796 // curosr will at the high bit
1798 FRow
= HBufferImage
.BufferPosition
.Row
;
1803 // move cursor position
1805 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1811 Scroll cursor to end of line.
1813 @retval EFI_SUCCESS Teh operation was successful.
1820 HEFI_EDITOR_LINE
*Line
;
1826 // need refresh mouse
1828 HBufferImageMouseNeedRefresh
= TRUE
;
1830 Line
= HBufferImage
.CurrentLine
;
1832 FRow
= HBufferImage
.BufferPosition
.Row
;
1834 if (Line
->Size
== 0x10) {
1838 FCol
= Line
->Size
+ 1;
1842 // move cursor position
1844 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1850 Get the size of the open buffer.
1852 @retval The size in bytes.
1855 HBufferImageGetTotalSize (
1861 HEFI_EDITOR_LINE
*Line
;
1864 // calculate the total size of whole line list's buffer
1866 if (HBufferImage
.Lines
== NULL
) {
1871 HBufferImage
.ListHead
->BackLink
,
1874 EFI_EDITOR_LINE_LIST
1877 // one line at most 0x10
1879 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1885 Delete character from buffer.
1887 @param[in] Pos Position, Pos starting from 0.
1888 @param[in] Count The Count of characters to delete.
1889 @param[out] DeleteBuffer The DeleteBuffer.
1891 @retval EFI_SUCCESS Success
1894 HBufferImageDeleteCharacterFromBuffer (
1897 OUT UINT8
*DeleteBuffer
1906 HEFI_EDITOR_LINE
*Line
;
1917 Size
= HBufferImageGetTotalSize ();
1920 return EFI_LOAD_ERROR
;
1928 // relocate all the HBufferImage fields
1930 OldFRow
= HBufferImage
.BufferPosition
.Row
;
1931 OldFCol
= HBufferImage
.BufferPosition
.Column
;
1932 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
1936 // has character before it,
1937 // so locate according to block's previous character
1943 // has no character before it,
1944 // so locate according to block's next character
1949 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
1951 Buffer
= AllocateZeroPool (Size
);
1952 if (Buffer
== NULL
) {
1953 return EFI_OUT_OF_RESOURCES
;
1956 HBufferImageListToBuffer (Buffer
, Size
);
1958 BufferPtr
= (UINT8
*) Buffer
;
1961 // pass deleted buffer out
1963 if (DeleteBuffer
!= NULL
) {
1964 for (Index
= 0; Index
< Count
; Index
++) {
1965 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
1969 // delete the part from Pos
1971 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
1972 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
1977 HBufferImageFreeLines ();
1979 Status
= HBufferImageBufferToList (Buffer
, Size
);
1982 if (EFI_ERROR (Status
)) {
1986 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1987 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
1988 Link
= Link
->ForwardLink
;
1991 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1992 HBufferImage
.CurrentLine
= Line
;
1995 // if current cursor position if inside select area
1996 // then move it to the block's NEXT character
1998 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
2004 NewPos
= OldPos
- Count
;
2008 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2014 Add character to buffer, add before pos.
2016 @param[in] Pos Position, Pos starting from 0.
2017 @param[in] Count Count of characters to add.
2018 @param[in] AddBuffer Add buffer.
2020 @retval EFI_SUCCESS Success.
2023 HBufferImageAddCharacterToBuffer (
2035 HEFI_EDITOR_LINE
*Line
;
2045 Size
= HBufferImageGetTotalSize ();
2048 // relocate all the HBufferImage fields
2050 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2051 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2052 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2055 // move cursor before Pos
2063 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2065 Buffer
= AllocateZeroPool (Size
+ Count
);
2066 if (Buffer
== NULL
) {
2067 return EFI_OUT_OF_RESOURCES
;
2070 HBufferImageListToBuffer (Buffer
, Size
);
2072 BufferPtr
= (UINT8
*) Buffer
;
2075 // get a place to add
2077 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2078 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2083 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2084 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2089 HBufferImageFreeLines ();
2091 HBufferImageBufferToList (Buffer
, Size
);
2095 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2096 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2097 Link
= Link
->ForwardLink
;
2100 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2101 HBufferImage
.CurrentLine
= Line
;
2103 if (OldPos
>= Pos
) {
2104 NewPos
= OldPos
+ Count
;
2109 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2115 Delete current character from line.
2117 @retval EFI_SUCCESS The operationw as successful.
2121 HBufferImageDoDelete (
2126 HEFI_EDITOR_LINE
*Line
;
2132 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2134 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2136 Line
= HBufferImage
.CurrentLine
;
2139 // if beyond the last character
2141 if (FileColumn
> Line
->Size
) {
2146 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2150 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2153 // if is the last line
2154 // then only this line need to be refreshed
2157 HBufferImageNeedRefresh
= FALSE
;
2158 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2160 HBufferImageNeedRefresh
= TRUE
;
2161 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2164 if (!HBufferImage
.Modified
) {
2165 HBufferImage
.Modified
= TRUE
;
2172 Change the raw buffer to a list of lines for the UI.
2174 @param[in] Buffer The pointer to the buffer to fill.
2175 @param[in] Bytes The size of the buffer in bytes.
2177 @retval EFI_SUCCESS The operation was successful.
2178 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2182 HBufferImageBufferToList (
2190 HEFI_EDITOR_LINE
*Line
;
2195 BufferPtr
= (UINT8
*) Buffer
;
2198 // parse file content line by line
2200 while (TempI
< Bytes
) {
2201 if (Bytes
- TempI
>= 0x10) {
2204 Left
= Bytes
- TempI
;
2208 // allocate a new line
2210 Line
= HBufferImageCreateLine ();
2212 return EFI_OUT_OF_RESOURCES
;
2217 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2218 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2225 // last line is a full line, SO create a new line
2227 if (Left
== 0x10 || Bytes
== 0) {
2228 Line
= HBufferImageCreateLine ();
2230 return EFI_OUT_OF_RESOURCES
;
2238 Change the list of lines from the UI to a raw buffer.
2240 @param[in] Buffer The pointer to the buffer to fill.
2241 @param[in] Bytes The size of the buffer in bytes.
2243 @retval EFI_SUCCESS The operation was successful.
2247 HBufferImageListToBuffer (
2254 HEFI_EDITOR_LINE
*Line
;
2259 // change the line list to a large buffer
2261 if (HBufferImage
.Lines
== NULL
) {
2265 Link
= &HBufferImage
.Lines
->Link
;
2267 BufferPtr
= (UINT8
*) Buffer
;
2270 // deal line by line
2272 while (Link
!= HBufferImage
.ListHead
) {
2274 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2276 //@todo shouldn't this be an error???
2277 if (Count
+ Line
->Size
> Bytes
) {
2281 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2282 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2285 Count
+= Line
->Size
;
2286 BufferPtr
+= Line
->Size
;
2288 Link
= Link
->ForwardLink
;
2295 Move the mouse in the image buffer.
2297 @param[in] TextX The x-coordinate.
2298 @param[in] TextY The y-coordinate.
2302 HBufferImageAdjustMousePosition (
2313 // TextX and TextY is mouse movement data returned by mouse driver
2314 // This function will change it to MousePosition
2317 // get absolute TempX value
2325 // get absolute TempY value
2333 TempX
= HBufferImage
.MousePosition
.Column
;
2334 TempY
= HBufferImage
.MousePosition
.Row
;
2339 if (TempX
>= AbsX
) {
2349 if (TempY
>= AbsY
) {
2356 // check whether new mouse column position is beyond screen
2357 // if not, adjust it
2359 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2360 HBufferImage
.MousePosition
.Column
= TempX
;
2361 } else if (TempX
< 10) {
2362 HBufferImage
.MousePosition
.Column
= 10;
2363 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2364 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2367 // check whether new mouse row position is beyond screen
2368 // if not, adjust it
2370 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 1)) {
2371 HBufferImage
.MousePosition
.Row
= TempY
;
2372 } else if (TempY
< 2) {
2373 HBufferImage
.MousePosition
.Row
= 2;
2374 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 1)) {
2375 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 1);
2381 Dispatch input to different handler
2383 @param[in] Key The input key:
2387 Direction key: up/down/left/right/pgup/pgdn
2391 @retval EFI_SUCCESS The operation was successful.
2392 @retval EFI_LOAD_ERROR A load error occured.
2393 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
2396 HBufferImageHandleInput (
2397 IN EFI_INPUT_KEY
*Key
2402 Status
= EFI_SUCCESS
;
2404 switch (Key
->ScanCode
) {
2409 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
2416 Status
= HBufferImageScrollUp ();
2423 Status
= HBufferImageScrollDown ();
2430 Status
= HBufferImageScrollRight ();
2437 Status
= HBufferImageScrollLeft ();
2444 Status
= HBufferImagePageUp ();
2450 case SCAN_PAGE_DOWN
:
2451 Status
= HBufferImagePageDown ();
2458 Status
= HBufferImageDoDelete ();
2465 Status
= HBufferImageHome ();
2472 Status
= HBufferImageEnd ();
2476 Status
= StatusBarSetStatusString (L
"Unknown Command");