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
;
82 Initialization function for HBufferImage
98 // basically initialize the HBufferImage
100 CopyMem (&HBufferImage
, &HBufferImageConst
, sizeof (HBufferImage
));
105 HBufferImage
.ListHead
= AllocateZeroPool (sizeof (LIST_ENTRY
));
106 if (HBufferImage
.ListHead
== NULL
) {
107 return EFI_LOAD_ERROR
;
110 InitializeListHead (HBufferImage
.ListHead
);
112 HBufferImage
.DisplayPosition
.Row
= 2;
113 HBufferImage
.DisplayPosition
.Column
= 10;
114 HBufferImage
.MousePosition
.Row
= 2;
115 HBufferImage
.MousePosition
.Column
= 10;
117 HBufferImage
.FileImage
= &HFileImage
;
118 HBufferImage
.DiskImage
= &HDiskImage
;
119 HBufferImage
.MemImage
= &HMemImage
;
121 HBufferImageNeedRefresh
= FALSE
;
122 HBufferImageOnlyLineNeedRefresh
= FALSE
;
123 HBufferImageMouseNeedRefresh
= FALSE
;
125 HBufferImageBackupVar
.FileImage
= &HFileImageBackupVar
;
126 HBufferImageBackupVar
.DiskImage
= &HDiskImageBackupVar
;
127 HBufferImageBackupVar
.MemImage
= &HMemImageBackupVar
;
129 Status
= HFileImageInit ();
130 if (EFI_ERROR (Status
)) {
131 return EFI_LOAD_ERROR
;
134 Status
= HDiskImageInit ();
135 if (EFI_ERROR (Status
)) {
136 return EFI_LOAD_ERROR
;
139 Status
= HMemImageInit ();
140 if (EFI_ERROR (Status
)) {
141 return EFI_LOAD_ERROR
;
152 Backup function for HBufferImage
153 Only a few fields need to be backup.
154 This is for making the file buffer refresh
167 HBufferImageBackupVar
.MousePosition
= HBufferImage
.MousePosition
;
169 HBufferImageBackupVar
.BufferPosition
= HBufferImage
.BufferPosition
;
171 HBufferImageBackupVar
.Modified
= HBufferImage
.Modified
;
173 HBufferImageBackupVar
.BufferType
= HBufferImage
.BufferType
;
174 HBufferImageBackupVar
.LowVisibleRow
= HBufferImage
.LowVisibleRow
;
175 HBufferImageBackupVar
.HighBits
= HBufferImage
.HighBits
;
178 // three kinds of buffer supported
183 switch (HBufferImage
.BufferType
) {
184 case FileTypeFileBuffer
:
188 case FileTypeDiskBuffer
:
192 case FileTypeMemBuffer
:
201 HBufferImageFreeLines (
205 Free all the lines in HBufferImage
222 HFreeLines (HBufferImage
.ListHead
, HBufferImage
.Lines
);
224 HBufferImage
.Lines
= NULL
;
225 HBufferImage
.CurrentLine
= NULL
;
226 HBufferImage
.NumLines
= 0;
232 HBufferImageCleanup (
236 Cleanup function for HBufferImage
251 // free all the lines
253 Status
= HBufferImageFreeLines ();
255 SHELL_FREE_NON_NULL (HBufferImage
.ListHead
);
256 HBufferImage
.ListHead
= NULL
;
258 HFileImageCleanup ();
259 HDiskImageCleanup ();
267 HBufferImagePrintLine (
268 IN HEFI_EDITOR_LINE
*Line
,
271 IN HEFI_EDITOR_COLOR_UNION Orig
,
272 IN HEFI_EDITOR_COLOR_UNION New
281 Row - Row on screen ( begin from 1 )
303 // variable initialization
310 // print the selected area in opposite color
312 if (HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
313 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
314 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
316 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
317 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
319 if (FRow
>= RowStart
&& FRow
<= RowEnd
) {
323 if (FRow
> RowStart
) {
333 if (HEditorMouseAction
== FALSE
) {
338 ((INT32
)Row
- 2 + HBufferImage
.LowVisibleRow
- 1) * 0x10
343 for (Index
= 0; Index
< 0x08 && Index
< Line
->Size
; Index
++) {
348 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
354 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
356 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
359 Pos
= 10 + (Index
* 3);
360 if (Line
->Buffer
[Index
] < 0x10) {
361 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
366 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
368 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
373 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
374 while (Index
< 0x08) {
375 Pos
= 10 + (Index
* 3);
376 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
380 while (Index
< 0x10 && Index
< Line
->Size
) {
385 if (Index
+ 1 >= ColStart
&& Index
+ 1 <= ColEnd
) {
391 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
393 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
396 Pos
= 10 + (Index
* 3) + 1;
397 if (Line
->Buffer
[Index
] < 0x10) {
398 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"0");
402 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%x ", Line
->Buffer
[Index
]);
406 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
407 while (Index
< 0x10) {
408 Pos
= 10 + (Index
* 3) + 1;
409 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
413 // restore the original color
415 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
418 // PRINT the buffer content
420 if (HEditorMouseAction
== FALSE
) {
421 for (Index
= 0; Index
< 0x10 && Index
< Line
->Size
; Index
++) {
422 Pos
= ASCII_POSITION
+ Index
;
425 // learned from shelle.h -- IsValidChar
427 if (Line
->Buffer
[Index
] >= L
' ') {
428 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", (CHAR16
) Line
->Buffer
[Index
]);
430 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
"%c", '.');
434 while (Index
< 0x10) {
435 Pos
= ASCII_POSITION
+ Index
;
436 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
441 // restore the abundant blank in hex edit area to original color
445 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
446 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
447 } else if (ColEnd
== 8) {
448 Pos
= 10 + (ColEnd
- 1) * 3 + 2;
449 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
451 Pos
= 10 + (ColEnd
- 1) * 3 + 3;
452 ShellPrintEx ((INT32
)Pos
- 1, (INT32
)Row
- 1, L
" ");
460 HBufferImageIsAtHighBits (
468 // NOW AFTER THE SUB, Column start from 0
469 // 23 AND 24 ARE BOTH BLANK
480 *FCol
= (Column
/ 3) + 1;
486 if ((Column
% 3 == 2)) {
494 HBufferImageIsInSelectedArea (
508 // judge mouse position whether is in selected area
513 if (HMainEditor
.SelectStart
== 0 || HMainEditor
.SelectEnd
== 0) {
517 // calculate the select area
519 RowStart
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
520 RowEnd
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
522 ColStart
= (HMainEditor
.SelectStart
- 1) % 0x10 + 1;
523 ColEnd
= (HMainEditor
.SelectEnd
- 1) % 0x10 + 1;
525 FRow
= HBufferImage
.LowVisibleRow
+ MouseRow
- 2;
526 if (FRow
< RowStart
|| FRow
> RowEnd
) {
530 if (FRow
> RowStart
) {
538 MouseColStart
= 10 + (ColStart
- 1) * 3;
543 MouseColEnd
= 10 + (ColEnd
- 1) * 3 + 1;
548 if (MouseCol
< MouseColStart
|| MouseCol
> MouseColEnd
) {
556 HBufferImageRestoreMousePosition (
560 HEFI_EDITOR_COLOR_UNION Orig
;
561 HEFI_EDITOR_COLOR_UNION New
;
564 BOOLEAN HasCharacter
;
565 HEFI_EDITOR_LINE
*CurrentLine
;
566 HEFI_EDITOR_LINE
*Line
;
571 if (HMainEditor
.MouseSupported
) {
573 if (HBufferImageMouseNeedRefresh
) {
575 HBufferImageMouseNeedRefresh
= FALSE
;
578 // if mouse position not moved and only mouse action
579 // so do not need to refresh mouse position
582 HBufferImage
.MousePosition
.Row
== HBufferImageBackupVar
.MousePosition
.Row
&&
583 HBufferImage
.MousePosition
.Column
== HBufferImageBackupVar
.MousePosition
.Column
590 // backup the old screen attributes
592 Orig
= HMainEditor
.ColorAttributes
;
593 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
594 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
597 // if in selected area,
598 // so do not need to refresh mouse
600 if (!HBufferImageIsInSelectedArea (
601 HBufferImageBackupVar
.MousePosition
.Row
,
602 HBufferImageBackupVar
.MousePosition
.Column
604 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
606 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
609 // clear the old mouse position
611 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImageBackupVar
.MousePosition
.Row
- 2;
613 HighBits
= HBufferImageIsAtHighBits (
614 HBufferImageBackupVar
.MousePosition
.Column
,
619 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
620 HasCharacter
= FALSE
;
622 CurrentLine
= HBufferImage
.CurrentLine
;
623 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
625 if (Line
== NULL
|| FColumn
> Line
->Size
) {
626 HasCharacter
= FALSE
;
629 HBufferImage
.CurrentLine
= CurrentLine
;
633 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
634 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
640 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
641 Value
= (UINT8
) (Value
>> 4);
643 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
647 (INT32
)HBufferImageBackupVar
.MousePosition
.Column
- 1,
648 (INT32
)HBufferImageBackupVar
.MousePosition
.Row
- 1,
654 if (!HBufferImageIsInSelectedArea (
655 HBufferImage
.MousePosition
.Row
,
656 HBufferImage
.MousePosition
.Column
658 gST
->ConOut
->SetAttribute (gST
->ConOut
, New
.Data
);
660 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
663 // clear the old mouse position
665 FRow
= HBufferImage
.LowVisibleRow
+ HBufferImage
.MousePosition
.Row
- 2;
667 HighBits
= HBufferImageIsAtHighBits (
668 HBufferImage
.MousePosition
.Column
,
673 if (FRow
> HBufferImage
.NumLines
|| FColumn
== 0) {
674 HasCharacter
= FALSE
;
676 CurrentLine
= HBufferImage
.CurrentLine
;
677 Line
= HMoveLine (FRow
- HBufferImage
.BufferPosition
.Row
);
679 if (Line
== NULL
|| FColumn
> Line
->Size
) {
680 HasCharacter
= FALSE
;
683 HBufferImage
.CurrentLine
= CurrentLine
;
687 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
688 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
694 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf0);
695 Value
= (UINT8
) (Value
>> 4);
697 Value
= (UINT8
) (Line
->Buffer
[FColumn
- 1] & 0xf);
701 (INT32
)HBufferImage
.MousePosition
.Column
- 1,
702 (INT32
)HBufferImage
.MousePosition
.Row
- 1,
708 // end of HasCharacter
710 gST
->ConOut
->SetAttribute (gST
->ConOut
, Orig
.Data
);
713 // end of MouseNeedRefresh
717 // end of MouseSupported
723 HBufferImageRestorePosition (
727 Set cursor position according to HBufferImage.DisplayPosition.
740 // set cursor position
742 gST
->ConOut
->SetCursorPosition (
744 HBufferImage
.DisplayPosition
.Column
- 1,
745 HBufferImage
.DisplayPosition
.Row
- 1
752 Refresh function for HBufferImage.
754 @retval EFI_SUCCESS The operation was successful.
755 @retval EFI_LOAD_ERROR A Load error occured.
759 HBufferImageRefresh (
764 HEFI_EDITOR_LINE
*Line
;
766 HEFI_EDITOR_COLOR_UNION Orig
;
767 HEFI_EDITOR_COLOR_UNION New
;
775 Orig
= HMainEditor
.ColorAttributes
;
776 New
.Colors
.Foreground
= Orig
.Colors
.Background
;
777 New
.Colors
.Background
= Orig
.Colors
.Foreground
;
780 // if it's the first time after editor launch, so should refresh
782 if (HEditorFirst
== FALSE
) {
784 // no definite required refresh
785 // and file position displayed on screen has not been changed
787 if (!HBufferImageNeedRefresh
&&
788 !HBufferImageOnlyLineNeedRefresh
&&
789 HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
791 HBufferImageRestoreMousePosition ();
792 HBufferImageRestorePosition ();
797 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
800 // only need to refresh current line
802 if (HBufferImageOnlyLineNeedRefresh
&& HBufferImageBackupVar
.LowVisibleRow
== HBufferImage
.LowVisibleRow
) {
804 HBufferImagePrintLine (
805 HBufferImage
.CurrentLine
,
806 HBufferImage
.DisplayPosition
.Row
,
807 HBufferImage
.BufferPosition
.Row
,
813 // the whole edit area need refresh
815 if (HEditorMouseAction
&& HMainEditor
.SelectStart
!= 0 && HMainEditor
.SelectEnd
!= 0) {
816 if (HMainEditor
.SelectStart
!= HMainEditorBackupVar
.SelectStart
) {
817 if (HMainEditor
.SelectStart
>= HMainEditorBackupVar
.SelectStart
&& HMainEditorBackupVar
.SelectStart
!= 0) {
818 StartRow
= (HMainEditorBackupVar
.SelectStart
- 1) / 0x10 + 1;
820 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
823 StartRow
= (HMainEditor
.SelectStart
- 1) / 0x10 + 1;
826 if (HMainEditor
.SelectEnd
<= HMainEditorBackupVar
.SelectEnd
) {
827 EndRow
= (HMainEditorBackupVar
.SelectEnd
- 1) / 0x10 + 1;
829 EndRow
= (HMainEditor
.SelectEnd
- 1) / 0x10 + 1;
834 if (StartRow
> EndRow
) {
840 FStartRow
= StartRow
;
843 StartRow
= 2 + StartRow
- HBufferImage
.LowVisibleRow
;
844 EndRow
= 2 + EndRow
- HBufferImage
.LowVisibleRow
;
848 // not mouse selection actions
850 FStartRow
= HBufferImage
.LowVisibleRow
;
852 EndRow
= (HMainEditor
.ScreenSize
.Row
- 4);
857 if (HBufferImage
.Lines
== NULL
) {
858 HBufferImageRestoreMousePosition ();
859 HBufferImageRestorePosition ();
860 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
864 // get the first line that will be displayed
866 Line
= HMoveLine (FStartRow
- HBufferImage
.BufferPosition
.Row
);
868 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
869 return EFI_LOAD_ERROR
;
872 Link
= &(Line
->Link
);
875 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
880 HBufferImagePrintLine (
883 HBufferImage
.LowVisibleRow
+ Row
- 2,
888 Link
= Link
->ForwardLink
;
890 } while (Link
!= HBufferImage
.ListHead
&& Row
<= EndRow
);
892 while (Row
<= EndRow
) {
893 HEditorClearLine (Row
);
897 // while not file end and not screen full
901 HBufferImageRestoreMousePosition ();
902 HBufferImageRestorePosition ();
904 HBufferImageNeedRefresh
= FALSE
;
905 HBufferImageOnlyLineNeedRefresh
= FALSE
;
906 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
912 Read an image into a buffer friom a source.
914 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
915 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
916 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
917 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
918 @param[in] MemoryOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
919 @param[in] MemorySize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
920 @param[in] BufferType The type of buffer to save. IGNORED.
921 @param[in] Recover TRUE for recovermode, FALSE otherwise.
923 @return EFI_SUCCESS The operation was successful.
928 IN CONST CHAR16
*FileName
,
929 IN CONST CHAR16
*DiskName
,
934 IN EDIT_FILE_TYPE BufferType
,
939 EDIT_FILE_TYPE BufferTypeBackup
;
942 // variable initialization
944 Status
= EFI_SUCCESS
;
945 HBufferImage
.BufferType
= BufferType
;
948 // three types of buffer supported
953 BufferTypeBackup
= HBufferImage
.BufferType
;
955 switch (BufferType
) {
956 case FileTypeFileBuffer
:
957 Status
= HFileImageRead (FileName
, Recover
);
960 case FileTypeDiskBuffer
:
961 Status
= HDiskImageRead (DiskName
, DiskOffset
, DiskSize
, Recover
);
964 case FileTypeMemBuffer
:
965 Status
= HMemImageRead (MemOffset
, MemSize
, Recover
);
969 if (EFI_ERROR (Status
)) {
970 HBufferImage
.BufferType
= BufferTypeBackup
;
977 Save the current image.
979 @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
980 @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
981 @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
982 @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
983 @param[in] MemoryOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
984 @param[in] MemorySize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
985 @param[in] BufferType The type of buffer to save. IGNORED.
987 @return EFI_SUCCESS The operation was successful.
997 IN EDIT_FILE_TYPE BufferType
1001 EDIT_FILE_TYPE BufferTypeBackup
;
1004 // variable initialization
1006 Status
= EFI_SUCCESS
;
1007 BufferTypeBackup
= HBufferImage
.BufferType
;
1009 switch (HBufferImage
.BufferType
) {
1013 case FileTypeFileBuffer
:
1014 Status
= HFileImageSave (FileName
);
1020 case FileTypeDiskBuffer
:
1021 Status
= HDiskImageSave (DiskName
, DiskOffset
, DiskSize
);
1027 case FileTypeMemBuffer
:
1028 Status
= HMemImageSave (MemOffset
, MemSize
);
1032 if (EFI_ERROR (Status
)) {
1033 HBufferImage
.BufferType
= BufferTypeBackup
;
1040 Create a new line and append it to the line list.
1045 @retval NULL create line failed.
1046 @return the line created.
1050 HBufferImageCreateLine (
1054 HEFI_EDITOR_LINE
*Line
;
1057 // allocate for line structure
1059 Line
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
1064 Line
->Signature
= EFI_EDITOR_LINE_LIST
;
1067 HBufferImage
.NumLines
++;
1070 // insert to line list
1072 InsertTailList (HBufferImage
.ListHead
, &Line
->Link
);
1074 if (HBufferImage
.Lines
== NULL
) {
1075 HBufferImage
.Lines
= CR (
1076 HBufferImage
.ListHead
->ForwardLink
,
1079 EFI_EDITOR_LINE_LIST
1087 Free the current image.
1089 @retval EFI_SUCCESS The operation was successful.
1099 HBufferImageFreeLines ();
1105 Dispatch input to different handler
1107 @param[in] Key The input key:
1111 Direction key: up/down/left/right/pgup/pgdn
1115 @retval EFI_SUCCESS The operation was successful.
1116 @retval EFI_LOAD_ERROR A load error occured.
1117 @retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
1120 HBufferImageHandleInput (
1121 IN EFI_INPUT_KEY
*Key
1126 Status
= EFI_SUCCESS
;
1128 switch (Key
->ScanCode
) {
1133 Status
= HBufferImageDoCharInput (Key
->UnicodeChar
);
1140 Status
= HBufferImageScrollUp ();
1147 Status
= HBufferImageScrollDown ();
1154 Status
= HBufferImageScrollRight ();
1161 Status
= HBufferImageScrollLeft ();
1168 Status
= HBufferImagePageUp ();
1174 case SCAN_PAGE_DOWN
:
1175 Status
= HBufferImagePageDown ();
1182 Status
= HBufferImageDoDelete ();
1189 Status
= HBufferImageHome ();
1196 Status
= HBufferImageEnd ();
1200 Status
= StatusBarSetStatusString (L
"Unknown Command");
1208 ASCII key + Backspace + return.
1210 @param[in] Char The input char.
1212 @retval EFI_SUCCESS The operation was successful.
1213 @retval EFI_LOAD_ERROR A load error occured.
1214 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1218 HBufferImageDoCharInput (
1224 Status
= EFI_SUCCESS
;
1231 Status
= HBufferImageDoBackspace ();
1238 // Tabs, Returns are thought as nothing
1244 // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
1246 if (Char
> 127 || Char
< 32) {
1247 Status
= StatusBarSetStatusString (L
"Unknown Command");
1249 Status
= HBufferImageAddChar (Char
);
1259 change char to int value based on Hex.
1261 @param[in] Char The input char.
1263 @return The character's index value.
1264 @retval -1 The operation failed.
1268 HBufferImageCharToHex (
1273 // change the character to hex
1275 if (Char
>= L
'0' && Char
<= L
'9') {
1276 return (INTN
) (Char
- L
'0');
1279 if (Char
>= L
'a' && Char
<= L
'f') {
1280 return (INTN
) (Char
- L
'a' + 10);
1283 if (Char
>= L
'A' && Char
<= L
'F') {
1284 return (INTN
) (Char
- L
'A' + 10);
1293 @param[in] Char -- input char.
1295 @retval EFI_SUCCESS The operation was successful.
1296 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1300 HBufferImageAddChar (
1304 HEFI_EDITOR_LINE
*Line
;
1305 HEFI_EDITOR_LINE
*NewLine
;
1312 Value
= HBufferImageCharToHex (Char
);
1321 Line
= HBufferImage
.CurrentLine
;
1322 FRow
= HBufferImage
.BufferPosition
.Row
;
1323 FCol
= HBufferImage
.BufferPosition
.Column
;
1324 High
= HBufferImage
.HighBits
;
1327 // only needs to refresh current line
1329 HBufferImageOnlyLineNeedRefresh
= TRUE
;
1332 // not a full line and beyond the last character
1334 if (FCol
> Line
->Size
) {
1336 // cursor always at high 4 bits
1337 // and always put input to the low 4 bits
1339 Line
->Buffer
[Line
->Size
] = (UINT8
) Value
;
1344 Old
= Line
->Buffer
[FCol
- 1];
1347 // always put the input to the low 4 bits
1349 Old
= (UINT8
) (Old
& 0x0f);
1350 Old
= (UINT8
) (Old
<< 4);
1351 Old
= (UINT8
) (Value
+ Old
);
1352 Line
->Buffer
[FCol
- 1] = Old
;
1355 // at the low 4 bits of the last character of a full line
1356 // so if no next line, need to create a new line
1358 if (!High
&& FCol
== 0x10) {
1360 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1361 HBufferImageNeedRefresh
= TRUE
;
1363 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
1367 // create a new line
1369 NewLine
= HBufferImageCreateLine ();
1370 if (NewLine
== NULL
) {
1371 return EFI_OUT_OF_RESOURCES
;
1378 // end of == ListHead
1384 // if already at end of this line, scroll it to the start of next line
1386 if (FCol
== 0x10 && !High
) {
1388 // definitely has next line
1395 // if not at end of this line, just move to next column
1413 // move cursor to right
1415 HBufferImageMovePosition (FRow
, FCol
, High
);
1417 if (!HBufferImage
.Modified
) {
1418 HBufferImage
.Modified
= TRUE
;
1425 Check user specified FileRow and FileCol is in current screen.
1427 @param[in] FileRow Row of file position ( start from 1 ).
1429 @retval TRUE It's on the current screen.
1430 @retval FALSE It's not on the current screen.
1437 if (FileRow
>= HBufferImage
.LowVisibleRow
&& FileRow
<= HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 5) - 1) {
1445 Check user specified FileRow is above current screen.
1447 @param[in] FileRow Row of file position ( start from 1 ).
1449 @retval TRUE It is above the current screen.
1450 @retval FALSE It is not above the current screen.
1454 HAboveCurrentScreen (
1458 if (FileRow
< HBufferImage
.LowVisibleRow
) {
1466 Check user specified FileRow is under current screen.
1468 @param[in] FileRow Row of file position ( start from 1 ).
1470 @retval TRUE It is under the current screen.
1471 @retval FALSE It is not under the current screen.
1475 HUnderCurrentScreen (
1479 if (FileRow
> HBufferImage
.LowVisibleRow
+ (HMainEditor
.ScreenSize
.Row
- 5) - 1) {
1487 According to cursor's file position, adjust screen display.
1489 @param[in] NewFilePosRow Row of file position ( start from 1 ).
1490 @param[in] NewFilePosCol Column of file position ( start from 1 ).
1491 @param[in] HighBits Cursor will on high4 bits or low4 bits.
1494 HBufferImageMovePosition (
1495 IN UINTN NewFilePosRow
,
1496 IN UINTN NewFilePosCol
,
1505 UINTN NewDisplayCol
;
1508 // CALCULATE gap between current file position and new file position
1510 RowGap
= NewFilePosRow
- HBufferImage
.BufferPosition
.Row
;
1512 Under
= HUnderCurrentScreen (NewFilePosRow
);
1513 Above
= HAboveCurrentScreen (NewFilePosRow
);
1515 HBufferImage
.HighBits
= HighBits
;
1518 // if is below current screen
1522 // display row will be unchanged
1524 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1528 // has enough above line, so display row unchanged
1529 // not has enough above lines, so the first line is
1530 // at the first display line
1532 if (NewFilePosRow
< (HBufferImage
.DisplayPosition
.Row
- 2 + 1)) {
1533 HBufferImage
.DisplayPosition
.Row
= NewFilePosRow
+ 2 - 1;
1536 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1539 // in current screen
1541 HBufferImage
.BufferPosition
.Row
= NewFilePosRow
;
1543 Abs
= (UINTN
)ABS(RowGap
);
1544 HBufferImage
.DisplayPosition
.Row
-= Abs
;
1546 HBufferImage
.DisplayPosition
.Row
+= RowGap
;
1552 HBufferImage
.LowVisibleRow
= HBufferImage
.BufferPosition
.Row
- (HBufferImage
.DisplayPosition
.Row
- 2);
1555 // always in current screen
1557 HBufferImage
.BufferPosition
.Column
= NewFilePosCol
;
1559 NewDisplayCol
= 10 + (NewFilePosCol
- 1) * 3;
1560 if (NewFilePosCol
> 0x8) {
1568 HBufferImage
.DisplayPosition
.Column
= NewDisplayCol
;
1571 // let CurrentLine point to correct line;
1573 HBufferImage
.CurrentLine
= HMoveCurrentLine (RowGap
);
1578 Scroll cursor to right.
1580 @retval EFI_SUCCESS The operation was successful.
1583 HBufferImageScrollRight (
1587 HEFI_EDITOR_LINE
*Line
;
1592 // scroll right will always move to the high4 bits of the next character
1594 HBufferImageNeedRefresh
= FALSE
;
1595 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1597 Line
= HBufferImage
.CurrentLine
;
1599 FRow
= HBufferImage
.BufferPosition
.Row
;
1600 FCol
= HBufferImage
.BufferPosition
.Column
;
1603 // this line is not full and no next line
1605 if (FCol
> Line
->Size
) {
1609 // if already at end of this line, scroll it to the start of next line
1615 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1624 // if not at end of this line, just move to next column
1630 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1636 Scroll cursor to left.
1638 @retval EFI_SUCCESS The operation was successful.
1641 HBufferImageScrollLeft (
1646 HEFI_EDITOR_LINE
*Line
;
1650 HBufferImageNeedRefresh
= FALSE
;
1651 HBufferImageOnlyLineNeedRefresh
= FALSE
;
1653 Line
= HBufferImage
.CurrentLine
;
1655 FRow
= HBufferImage
.BufferPosition
.Row
;
1656 FCol
= HBufferImage
.BufferPosition
.Column
;
1659 // if already at start of this line, so move to the end of previous line
1663 // has previous line
1665 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1667 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1674 // if not at start of this line, just move to previous column
1679 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
1685 Scroll cursor to the next line
1687 @retval EFI_SUCCESS The operation was successful.
1690 HBufferImageScrollDown (
1694 HEFI_EDITOR_LINE
*Line
;
1699 Line
= HBufferImage
.CurrentLine
;
1701 FRow
= HBufferImage
.BufferPosition
.Row
;
1702 FCol
= HBufferImage
.BufferPosition
.Column
;
1703 HighBits
= HBufferImage
.HighBits
;
1708 if (Line
->Link
.ForwardLink
!= HBufferImage
.ListHead
) {
1710 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1713 // if the next line is not that long, so move to end of next line
1715 if (FCol
> Line
->Size
) {
1716 FCol
= Line
->Size
+ 1;
1724 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1730 Scroll cursor to previous line
1732 @retval EFI_SUCCESS The operation was successful.
1735 HBufferImageScrollUp (
1739 HEFI_EDITOR_LINE
*Line
;
1743 Line
= HBufferImage
.CurrentLine
;
1745 FRow
= HBufferImage
.BufferPosition
.Row
;
1746 FCol
= HBufferImage
.BufferPosition
.Column
;
1749 // has previous line
1751 if (Line
->Link
.BackLink
!= HBufferImage
.ListHead
) {
1758 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1764 Scroll cursor to next page
1766 @retval EFI_SUCCESS The operation was successful.
1769 HBufferImagePageDown (
1773 HEFI_EDITOR_LINE
*Line
;
1779 Line
= HBufferImage
.CurrentLine
;
1781 FRow
= HBufferImage
.BufferPosition
.Row
;
1782 FCol
= HBufferImage
.BufferPosition
.Column
;
1783 HighBits
= HBufferImage
.HighBits
;
1788 if (HBufferImage
.NumLines
>= FRow
+ (HMainEditor
.ScreenSize
.Row
- 5)) {
1789 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1792 // MOVE CURSOR TO LAST LINE
1794 Gap
= HBufferImage
.NumLines
- FRow
;
1799 Line
= HMoveLine (Gap
);
1802 // if that line, is not that long, so move to the end of that line
1804 if (Line
!= NULL
&& FCol
> Line
->Size
) {
1805 FCol
= Line
->Size
+ 1;
1811 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1817 Scroll cursor to previous page
1819 @retval EFI_SUCCESS The operation was successful.
1822 HBufferImagePageUp (
1826 HEFI_EDITOR_LINE
*Line
;
1832 Line
= HBufferImage
.CurrentLine
;
1834 FRow
= HBufferImage
.BufferPosition
.Row
;
1835 FCol
= HBufferImage
.BufferPosition
.Column
;
1838 // has previous page
1840 if (FRow
> (HMainEditor
.ScreenSize
.Row
- 5)) {
1841 Gap
= (HMainEditor
.ScreenSize
.Row
- 5);
1844 // the first line of file will displayed on the first line of screen
1855 Line
= HMoveLine (Retreat
);
1859 HBufferImageMovePosition (FRow
, FCol
, HBufferImage
.HighBits
);
1865 Scroll cursor to start of line
1867 @retval EFI_SUCCESS The operation was successful.
1874 HEFI_EDITOR_LINE
*Line
;
1879 Line
= HBufferImage
.CurrentLine
;
1882 // curosr will at the high bit
1884 FRow
= HBufferImage
.BufferPosition
.Row
;
1889 // move cursor position
1891 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1897 Scroll cursor to end of line.
1899 @retval EFI_SUCCESS Teh operation was successful.
1906 HEFI_EDITOR_LINE
*Line
;
1912 // need refresh mouse
1914 HBufferImageMouseNeedRefresh
= TRUE
;
1916 Line
= HBufferImage
.CurrentLine
;
1918 FRow
= HBufferImage
.BufferPosition
.Row
;
1920 if (Line
->Size
== 0x10) {
1924 FCol
= Line
->Size
+ 1;
1928 // move cursor position
1930 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1936 Get the size of the open buffer.
1938 @retval The size in bytes.
1941 HBufferImageGetTotalSize (
1947 HEFI_EDITOR_LINE
*Line
;
1950 // calculate the total size of whole line list's buffer
1952 if (HBufferImage
.Lines
== NULL
) {
1957 HBufferImage
.ListHead
->BackLink
,
1960 EFI_EDITOR_LINE_LIST
1963 // one line at most 0x10
1965 Size
= 0x10 * (HBufferImage
.NumLines
- 1) + Line
->Size
;
1971 Delete character from buffer.
1973 @param[in] Pos Position, Pos starting from 0.
1974 @param[in] Count The Count of characters to delete.
1975 @param[OUT] DeleteBuffer The DeleteBuffer.
1977 @retval EFI_SUCCESS Success
1980 HBufferImageDeleteCharacterFromBuffer (
1983 OUT UINT8
*DeleteBuffer
1992 HEFI_EDITOR_LINE
*Line
;
2005 // get the line that start position is at
2007 StartRow
= Pos
/ 0x10;
2009 Size
= HBufferImageGetTotalSize ();
2012 return EFI_LOAD_ERROR
;
2020 // relocate all the HBufferImage fields
2022 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2023 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2024 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2028 // has character before it,
2029 // so locate according to block's previous character
2035 // has no character before it,
2036 // so locate according to block's next character
2041 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2043 Buffer
= AllocateZeroPool (Size
);
2044 if (Buffer
== NULL
) {
2045 return EFI_OUT_OF_RESOURCES
;
2048 HBufferImageListToBuffer (Buffer
, Size
);
2050 BufferPtr
= (UINT8
*) Buffer
;
2053 // pass deleted buffer out
2055 if (DeleteBuffer
!= NULL
) {
2056 for (Index
= 0; Index
< Count
; Index
++) {
2057 DeleteBuffer
[Index
] = BufferPtr
[Pos
+ Index
];
2061 // delete the part from Pos
2063 for (Index
= Pos
; Index
< Size
- Count
; Index
++) {
2064 BufferPtr
[Index
] = BufferPtr
[Index
+ Count
];
2069 HBufferImageFreeLines ();
2071 Status
= HBufferImageBufferToList (Buffer
, Size
);
2074 if (EFI_ERROR (Status
)) {
2078 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2079 for (Index
= 0; Index
< NewPos
/ 0x10; Index
++) {
2080 Link
= Link
->ForwardLink
;
2083 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2084 HBufferImage
.CurrentLine
= Line
;
2087 // if current cursor position if inside select area
2088 // then move it to the block's NEXT character
2090 if (OldPos
>= Pos
&& OldPos
< (Pos
+ Count
)) {
2096 NewPos
= OldPos
- Count
;
2100 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2106 Add character to buffer, add before pos.
2108 @param[in] Pos Position, Pos starting from 0.
2109 @param[in] Count Count of characters to add.
2110 @param[in] AddBuffer Add buffer.
2112 @retval EFI_SUCCESS Success.
2115 HBufferImageAddCharacterToBuffer (
2127 HEFI_EDITOR_LINE
*Line
;
2139 // get the line that start position is at
2141 StartRow
= Pos
/ 0x10;
2143 Size
= HBufferImageGetTotalSize ();
2146 // relocate all the HBufferImage fields
2148 OldFRow
= HBufferImage
.BufferPosition
.Row
;
2149 OldFCol
= HBufferImage
.BufferPosition
.Column
;
2150 OldPos
= (OldFRow
- 1) * 0x10 + OldFCol
- 1;
2153 // move cursor before Pos
2161 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2163 Buffer
= AllocateZeroPool (Size
+ Count
);
2164 if (Buffer
== NULL
) {
2165 return EFI_OUT_OF_RESOURCES
;
2168 HBufferImageListToBuffer (Buffer
, Size
);
2170 BufferPtr
= (UINT8
*) Buffer
;
2173 // get a place to add
2175 for (Index
= (INTN
) (Size
+ Count
- 1); Index
>= (INTN
) Pos
; Index
--) {
2176 BufferPtr
[Index
] = BufferPtr
[Index
- Count
];
2181 for (Index
= (INTN
) 0; Index
< (INTN
) Count
; Index
++) {
2182 BufferPtr
[Index
+ Pos
] = AddBuffer
[Index
];
2187 HBufferImageFreeLines ();
2189 HBufferImageBufferToList (Buffer
, Size
);
2193 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
2194 for (Index
= 0; Index
< (INTN
) NewPos
/ 0x10; Index
++) {
2195 Link
= Link
->ForwardLink
;
2198 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2199 HBufferImage
.CurrentLine
= Line
;
2201 if (OldPos
>= Pos
) {
2202 NewPos
= OldPos
+ Count
;
2207 HBufferImageMovePosition (NewPos
/ 0x10 + 1, NewPos
% 0x10 + 1, TRUE
);
2213 Delete the previous character.
2215 @retval EFI_SUCCESS The operationw as successful.
2219 HBufferImageDoBackspace (
2223 HEFI_EDITOR_LINE
*Line
;
2230 // variable initialization
2235 // already the first character
2237 if (HBufferImage
.BufferPosition
.Row
== 1 && HBufferImage
.BufferPosition
.Column
== 1) {
2241 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2243 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2245 Line
= HBufferImage
.CurrentLine
;
2247 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
&& FileColumn
> 1) {
2251 HBufferImageDeleteCharacterFromBuffer (FPos
- 1, 1, NULL
);
2254 // if is the last line
2255 // then only this line need to be refreshed
2258 HBufferImageNeedRefresh
= FALSE
;
2259 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2261 HBufferImageNeedRefresh
= TRUE
;
2262 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2265 if (!HBufferImage
.Modified
) {
2266 HBufferImage
.Modified
= TRUE
;
2273 Delete current character from line.
2275 @retval EFI_SUCCESS The operationw as successful.
2279 HBufferImageDoDelete (
2284 HEFI_EDITOR_LINE
*Line
;
2290 FPos
= (HBufferImage
.BufferPosition
.Row
- 1) * 0x10 + HBufferImage
.BufferPosition
.Column
- 1;
2292 FileColumn
= HBufferImage
.BufferPosition
.Column
;
2294 Line
= HBufferImage
.CurrentLine
;
2297 // if beyond the last character
2299 if (FileColumn
> Line
->Size
) {
2304 if (Line
->Link
.ForwardLink
== HBufferImage
.ListHead
) {
2308 HBufferImageDeleteCharacterFromBuffer (FPos
, 1, NULL
);
2311 // if is the last line
2312 // then only this line need to be refreshed
2315 HBufferImageNeedRefresh
= FALSE
;
2316 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2318 HBufferImageNeedRefresh
= TRUE
;
2319 HBufferImageOnlyLineNeedRefresh
= FALSE
;
2322 if (!HBufferImage
.Modified
) {
2323 HBufferImage
.Modified
= TRUE
;
2330 Change the raw buffer to a list of lines for the UI.
2332 @param[in] Buffer The pointer to the buffer to fill.
2333 @param[in] Bytes The size of the buffer in bytes.
2335 @retval EFI_SUCCESS The operation was successful.
2336 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2340 HBufferImageBufferToList (
2348 HEFI_EDITOR_LINE
*Line
;
2353 BufferPtr
= (UINT8
*) Buffer
;
2356 // parse file content line by line
2358 while (TempI
< Bytes
) {
2359 if (Bytes
- TempI
>= 0x10) {
2362 Left
= Bytes
- TempI
;
2366 // allocate a new line
2368 Line
= HBufferImageCreateLine ();
2370 return EFI_OUT_OF_RESOURCES
;
2375 for (TempJ
= 0; TempJ
< Left
; TempJ
++) {
2376 Line
->Buffer
[TempJ
] = BufferPtr
[TempI
];
2383 // last line is a full line, SO create a new line
2385 if (Left
== 0x10 || Bytes
== 0) {
2386 Line
= HBufferImageCreateLine ();
2388 return EFI_OUT_OF_RESOURCES
;
2396 Change the list of lines from the UI to a raw buffer.
2398 @param[in] Buffer The pointer to the buffer to fill.
2399 @param[in] Bytes The size of the buffer in bytes.
2401 @retval EFI_SUCCESS The operation was successful.
2405 HBufferImageListToBuffer (
2412 HEFI_EDITOR_LINE
*Line
;
2417 // change the line list to a large buffer
2419 if (HBufferImage
.Lines
== NULL
) {
2423 Link
= &HBufferImage
.Lines
->Link
;
2425 BufferPtr
= (UINT8
*) Buffer
;
2428 // deal line by line
2430 while (Link
!= HBufferImage
.ListHead
) {
2432 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
2434 //@todo shouldn't this be an error???
2435 if (Count
+ Line
->Size
> Bytes
) {
2439 for (Index
= 0; Index
< Line
->Size
; Index
++) {
2440 BufferPtr
[Index
] = Line
->Buffer
[Index
];
2443 Count
+= Line
->Size
;
2444 BufferPtr
+= Line
->Size
;
2446 Link
= Link
->ForwardLink
;
2453 Move the mouse in the image buffer.
2455 @param[in] TextX The x-coordinate.
2456 @param[in] TextY The y-coordinate.
2460 HBufferImageAdjustMousePosition (
2471 // TextX and TextY is mouse movement data returned by mouse driver
2472 // This function will change it to MousePosition
2475 // get absolute TempX value
2483 // get absolute TempY value
2491 TempX
= HBufferImage
.MousePosition
.Column
;
2492 TempY
= HBufferImage
.MousePosition
.Row
;
2497 if (TempX
>= AbsX
) {
2507 if (TempY
>= AbsY
) {
2514 // check whether new mouse column position is beyond screen
2515 // if not, adjust it
2517 if (TempX
>= 10 && TempX
<= (10 + 0x10 * 3 - 1)) {
2518 HBufferImage
.MousePosition
.Column
= TempX
;
2519 } else if (TempX
< 10) {
2520 HBufferImage
.MousePosition
.Column
= 10;
2521 } else if (TempX
> (10 + 0x10 * 3 - 1)) {
2522 HBufferImage
.MousePosition
.Column
= 10 + 0x10 * 3 - 1;
2525 // check whether new mouse row position is beyond screen
2526 // if not, adjust it
2528 if (TempY
>= 2 && TempY
<= (HMainEditor
.ScreenSize
.Row
- 4)) {
2529 HBufferImage
.MousePosition
.Row
= TempY
;
2530 } else if (TempY
< 2) {
2531 HBufferImage
.MousePosition
.Row
= 2;
2532 } else if (TempY
> (HMainEditor
.ScreenSize
.Row
- 4)) {
2533 HBufferImage
.MousePosition
.Row
= (HMainEditor
.ScreenSize
.Row
- 4);