2 Defines the Main Editor data type -
4 - Instances of the other objects of the editor
7 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "HexEditor.h"
19 #include "EditStatusBar.h"
20 #include "EditInputBar.h"
22 HEFI_EDITOR_COLOR_ATTRIBUTES HOriginalColors
;
26 // the first time editor launch
31 // it's time editor should exit
35 BOOLEAN HEditorMouseAction
;
37 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImage
;
38 extern HEFI_EDITOR_BUFFER_IMAGE HBufferImageBackupVar
;
40 extern HEFI_EDITOR_CLIPBOARD HClipBoard
;
42 extern BOOLEAN HBufferImageMouseNeedRefresh
;
43 extern BOOLEAN HBufferImageNeedRefresh
;
44 extern BOOLEAN HBufferImageOnlyLineNeedRefresh
;
46 HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
47 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
50 // basic initialization for MainEditor
52 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst
= {
72 HMainCommandGoToOffset (
79 move cursor to specified lines
98 // variable initialization
108 Status
= InputBarSetPrompt (L
"Go To Offset: ");
109 if (EFI_ERROR (Status
)) {
113 Status
= InputBarSetStringSize (8);
114 if (EFI_ERROR (Status
)) {
119 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
124 if (Status
== EFI_NOT_READY
) {
129 // THE input string length should > 0
131 if (StrLen (InputBarGetString()) > 0) {
132 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
133 if (EFI_ERROR (Status
)) {
134 StatusBarSetStatusString (L
"Invalid Offset");
142 Size
= HBufferImageGetTotalSize ();
143 if (Offset
>= Size
) {
144 StatusBarSetStatusString (L
"Invalid Offset");
148 FRow
= (UINTN
)DivU64x32(Offset
, 0x10) + 1;
149 FCol
= (UINTN
)ModU64x32(Offset
, 0x10) + 1;
151 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
153 HBufferImageNeedRefresh
= TRUE
;
154 HBufferImageOnlyLineNeedRefresh
= FALSE
;
155 HBufferImageMouseNeedRefresh
= TRUE
;
161 HMainCommandSaveBuffer (
168 save current opened buffer .
169 if is file buffer, you can save to current file name or
170 save to another file name
190 SHELL_FILE_HANDLE ShellFileHandle
;
192 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
193 if (HMainEditor
.BufferImage
->Modified
== FALSE
) {
197 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
198 if (EFI_ERROR (Status
)) {
202 // the answer is just one character
204 Status
= InputBarSetStringSize (1);
205 if (EFI_ERROR (Status
)) {
209 // loop for user's answer
210 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
213 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
218 if (Status
== EFI_NOT_READY
) {
222 switch (InputBarGetString()[0]) {
226 // want to save this buffer first
228 Status
= HBufferImageSave (
230 HMainEditor
.BufferImage
->DiskImage
->Name
,
231 HMainEditor
.BufferImage
->DiskImage
->Offset
,
232 HMainEditor
.BufferImage
->DiskImage
->Size
,
233 HMainEditor
.BufferImage
->MemImage
->Offset
,
234 HMainEditor
.BufferImage
->MemImage
->Size
,
235 HMainEditor
.BufferImage
->BufferType
238 if (EFI_ERROR (Status
)) {
239 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
248 // the file won't be saved
266 // ENDOF != FILEBUFFER
268 // This command will save currently opened file to disk.
269 // You can choose save to another file name or just save to
270 // current file name.
271 // Below is the scenario of Save File command: (
272 // Suppose the old file name is A )
273 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
274 // IF user press ESC, Save File command ends .
275 // IF user press Enter, input file name will be A.
276 // IF user inputs a new file name B, input file name will be B.
278 // 2. IF input file name is A, go to do Step 3.
279 // IF input file name is B, go to do Step 4.
281 // 3. IF A is read only, Status Bar will show "Access Denied"
282 // and Save File commands ends.
283 // IF A is not read only, save file buffer to disk
284 // and remove Modified flag in Title Bar , then Save File command ends.
286 // 4. IF B does not exist, create this file and save file buffer to it.
288 // IF B exits, do Step 5.
290 // 5. An Input Bar will be prompted:
291 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
292 // IF user press 'y' or 'Y', do Step 6.
293 // IF user press 'n' or 'N', Save File commands ends.
294 // IF user press 'c' or 'C' or ESC, Save File commands ends.
296 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
297 // and Save File commands ends.
298 // IF B can be read and write, save file buffer to B.
300 // 7. Update File Name field in Title Bar to B
301 // and remove the Modified flag in Title Bar.
303 Str
= CatSPrint(NULL
,
304 L
"File to Save: [%s]",
305 HMainEditor
.BufferImage
->FileImage
->FileName
308 return EFI_OUT_OF_RESOURCES
;
311 if (StrLen (Str
) >= 50) {
313 // replace the long file name with "..."
322 Status
= InputBarSetPrompt (Str
);
323 if (EFI_ERROR (Status
)) {
327 Status
= InputBarSetStringSize (100);
328 if (EFI_ERROR (Status
)) {
334 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
337 // if user pressed ESC
339 if (Status
== EFI_NOT_READY
) {
340 SHELL_FREE_NON_NULL (Str
);
344 SHELL_FREE_NON_NULL (Str
);
347 // if just enter pressed, so think save to current file name
349 if (StrLen (InputBarGetString()) == 0) {
350 FileName
= CatSPrint(NULL
,
352 HMainEditor
.BufferImage
->FileImage
->FileName
355 FileName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
358 if (FileName
== NULL
) {
359 return EFI_OUT_OF_RESOURCES
;
362 if (!IsValidFileName (FileName
)) {
363 StatusBarSetStatusString (L
"Invalid File Name");
364 SHELL_FREE_NON_NULL (FileName
);
371 // save to the old file
373 if (StringNoCaseCompare (
375 &HMainEditor
.BufferImage
->FileImage
->FileName
382 // if the file is read only, so can not write back to it.
384 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
== TRUE
) {
385 StatusBarSetStatusString (L
"Access Denied");
386 SHELL_FREE_NON_NULL (FileName
);
390 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
392 if (!EFI_ERROR (Status
)) {
394 Info
= ShellGetFileInfo(ShellFileHandle
);
396 ShellCloseFile(&ShellFileHandle
);
398 // check if read only
400 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
401 StatusBarSetStatusString (L
"Access Denied");
402 SHELL_FREE_NON_NULL (FileName
);
406 SHELL_FREE_NON_NULL(Info
);
408 // ask user whether to overwrite this file
410 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
411 if (EFI_ERROR (Status
)) {
412 SHELL_FREE_NON_NULL (FileName
);
416 Status
= InputBarSetStringSize (1);
417 if (EFI_ERROR (Status
)) {
418 SHELL_FREE_NON_NULL (FileName
);
424 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
426 if (Status
== EFI_NOT_READY
) {
427 SHELL_FREE_NON_NULL (FileName
);
431 switch (InputBarGetString()[0]) {
438 SHELL_FREE_NON_NULL (FileName
);
442 SHELL_FREE_NON_NULL (FileName
);
446 } // if opened existing file
450 // save file back to disk
452 Status
= HBufferImageSave (
454 HMainEditor
.BufferImage
->DiskImage
->Name
,
455 HMainEditor
.BufferImage
->DiskImage
->Offset
,
456 HMainEditor
.BufferImage
->DiskImage
->Size
,
457 HMainEditor
.BufferImage
->MemImage
->Offset
,
458 HMainEditor
.BufferImage
->MemImage
->Size
,
461 SHELL_FREE_NON_NULL (FileName
);
463 if (EFI_ERROR (Status
)) {
464 return EFI_LOAD_ERROR
;
471 HMainCommandSelectStart (
478 Load a disk buffer editor
494 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
499 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
500 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
501 StatusBarSetStatusString (L
"Invalid Block Start");
502 return EFI_LOAD_ERROR
;
506 if (HMainEditor
.SelectEnd
!= 0 && Start
> HMainEditor
.SelectEnd
) {
507 StatusBarSetStatusString (L
"Invalid Block Start");
508 return EFI_LOAD_ERROR
;
511 HMainEditor
.SelectStart
= Start
;
513 HBufferImageNeedRefresh
= TRUE
;
519 HMainCommandSelectEnd (
526 Load a disk buffer editor
542 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
547 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
548 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
549 StatusBarSetStatusString (L
"Invalid Block End");
550 return EFI_LOAD_ERROR
;
554 if (HMainEditor
.SelectStart
!= 0 && End
< HMainEditor
.SelectStart
) {
555 StatusBarSetStatusString (L
"Invalid Block End");
559 HMainEditor
.SelectEnd
= End
;
561 HBufferImageNeedRefresh
= TRUE
;
574 cut current line to clipboard
589 HEFI_EDITOR_LINE
*Line
;
595 // not select, so not allowed to cut
597 if (HMainEditor
.SelectStart
== 0) {
598 StatusBarSetStatusString (L
"No Block is Selected");
602 // not select, so not allowed to cut
604 if (HMainEditor
.SelectEnd
== 0) {
605 StatusBarSetStatusString (L
"No Block is Selected");
609 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
610 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
611 Link
= Link
->ForwardLink
;
614 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
616 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
617 Buffer
= AllocateZeroPool (Count
);
618 if (Buffer
== NULL
) {
619 return EFI_OUT_OF_RESOURCES
;
622 // cut the selected area
624 HBufferImageDeleteCharacterFromBuffer (
625 HMainEditor
.SelectStart
- 1,
633 HClipBoardSet (Buffer
, Count
);
635 HBufferImageNeedRefresh
= TRUE
;
636 HBufferImageOnlyLineNeedRefresh
= FALSE
;
638 if (!HMainEditor
.BufferImage
->Modified
) {
639 HMainEditor
.BufferImage
->Modified
= TRUE
;
643 // now no select area
645 HMainEditor
.SelectStart
= 0;
646 HMainEditor
.SelectEnd
= 0;
659 paste line to file buffer
675 BOOLEAN OnlyLineRefresh
;
676 HEFI_EDITOR_LINE
*Line
;
681 Count
= HClipBoardGet (&Buffer
);
682 if (Count
== 0 || Buffer
== NULL
) {
683 StatusBarSetStatusString (L
"Nothing to Paste");
687 Line
= HMainEditor
.BufferImage
->CurrentLine
;
689 OnlyLineRefresh
= FALSE
;
690 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
&& Line
->Size
+ Count
< 0x10) {
692 // is at last line, and after paste will not exceed
693 // so only this line need to be refreshed
695 // if after add, the line is 0x10, then will append a new line
696 // so the whole page will need be refreshed
698 OnlyLineRefresh
= TRUE
;
702 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
704 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
706 if (OnlyLineRefresh
) {
707 HBufferImageNeedRefresh
= FALSE
;
708 HBufferImageOnlyLineNeedRefresh
= TRUE
;
710 HBufferImageNeedRefresh
= TRUE
;
711 HBufferImageOnlyLineNeedRefresh
= FALSE
;
714 if (!HMainEditor
.BufferImage
->Modified
) {
715 HMainEditor
.BufferImage
->Modified
= TRUE
;
747 // Below is the scenario of Exit command:
748 // 1. IF currently opened file is not modified, exit the editor and
749 // Exit command ends.
750 // IF currently opened file is modified, do Step 2
752 // 2. An Input Bar will be prompted:
753 // "File modified. Save ( Yes/No/Cancel )?"
754 // IF user press 'y' or 'Y', currently opened file will be saved and
756 // IF user press 'n' or 'N', currently opened file will not be saved
758 // IF user press 'c' or 'C' or ESC, Exit command ends.
761 // if file has been modified, so will prompt user
762 // whether to save the changes
764 if (HMainEditor
.BufferImage
->Modified
) {
766 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
767 if (EFI_ERROR (Status
)) {
771 Status
= InputBarSetStringSize (1);
772 if (EFI_ERROR (Status
)) {
777 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
782 if (Status
== EFI_NOT_READY
) {
786 switch (InputBarGetString()[0]) {
790 // write file back to disk
792 Status
= HBufferImageSave (
793 HMainEditor
.BufferImage
->FileImage
->FileName
,
794 HMainEditor
.BufferImage
->DiskImage
->Name
,
795 HMainEditor
.BufferImage
->DiskImage
->Offset
,
796 HMainEditor
.BufferImage
->DiskImage
->Size
,
797 HMainEditor
.BufferImage
->MemImage
->Offset
,
798 HMainEditor
.BufferImage
->MemImage
->Size
,
799 HMainEditor
.BufferImage
->BufferType
801 if (!EFI_ERROR (Status
)) {
826 HMainCommandOpenFile (
833 Load a file from disk to editor
849 EDIT_FILE_TYPE BufferType
;
851 BufferType
= HMainEditor
.BufferImage
->BufferType
;
854 // This command will open a file from current working directory.
855 // Read-only file can also be opened. But it can not be modified.
856 // Below is the scenario of Open File command:
857 // 1. IF currently opened file has not been modified, directly go to step .
858 // IF currently opened file has been modified, an Input Bar will be
860 // "File Modified. Save ( Yes/No/Cancel) ?"
861 // IF user press 'y' or 'Y', currently opened file will be saved.
862 // IF user press 'n' or 'N', currently opened file will
864 // IF user press 'c' or 'C' or ESC, Open File command ends and
865 // currently opened file is still opened.
867 // 2. An Input Bar will be prompted as : "File Name to Open: "
868 // IF user press ESC, Open File command ends and
869 // currently opened file is still opened.
870 // Any other inputs with a Return will cause
871 // currently opened file close.
873 // 3. IF user input file name is an existing file ,
874 // this file will be read and opened.
875 // IF user input file name is a new file, this file will be created
876 // and opened. This file's type ( UNICODE or ASCII ) is the same with
880 // if current file is modified, so you need to choose whether to
883 if (HMainEditor
.BufferImage
->Modified
) {
885 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
886 if (EFI_ERROR (Status
)) {
890 // the answer is just one character
892 Status
= InputBarSetStringSize (1);
893 if (EFI_ERROR (Status
)) {
897 // loop for user's answer
898 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
902 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
907 if (Status
== EFI_NOT_READY
) {
911 switch (InputBarGetString()[0]) {
915 // want to save this buffer first
917 Status
= HBufferImageSave (
918 HMainEditor
.BufferImage
->FileImage
->FileName
,
919 HMainEditor
.BufferImage
->DiskImage
->Name
,
920 HMainEditor
.BufferImage
->DiskImage
->Offset
,
921 HMainEditor
.BufferImage
->DiskImage
->Size
,
922 HMainEditor
.BufferImage
->MemImage
->Offset
,
923 HMainEditor
.BufferImage
->MemImage
->Size
,
924 HMainEditor
.BufferImage
->BufferType
926 if (EFI_ERROR (Status
)) {
930 MainTitleBarRefresh (
931 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
932 HMainEditor
.BufferImage
->BufferType
,
933 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
935 HMainEditor
.ScreenSize
.Column
,
936 HMainEditor
.ScreenSize
.Row
944 // the file won't be saved
956 // TO get the open file name
958 Status
= InputBarSetPrompt (L
"File Name to Open: ");
959 if (EFI_ERROR (Status
)) {
961 HMainEditor
.BufferImage
->FileImage
->FileName
,
962 HMainEditor
.BufferImage
->DiskImage
->Name
,
963 HMainEditor
.BufferImage
->DiskImage
->Offset
,
964 HMainEditor
.BufferImage
->DiskImage
->Size
,
965 HMainEditor
.BufferImage
->MemImage
->Offset
,
966 HMainEditor
.BufferImage
->MemImage
->Size
,
973 Status
= InputBarSetStringSize (100);
974 if (EFI_ERROR (Status
)) {
975 Status
= HBufferImageRead (
976 HMainEditor
.BufferImage
->FileImage
->FileName
,
977 HMainEditor
.BufferImage
->DiskImage
->Name
,
978 HMainEditor
.BufferImage
->DiskImage
->Offset
,
979 HMainEditor
.BufferImage
->DiskImage
->Size
,
980 HMainEditor
.BufferImage
->MemImage
->Offset
,
981 HMainEditor
.BufferImage
->MemImage
->Size
,
989 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
994 if (Status
== EFI_NOT_READY
) {
995 Status
= HBufferImageRead (
996 HMainEditor
.BufferImage
->FileImage
->FileName
,
997 HMainEditor
.BufferImage
->DiskImage
->Name
,
998 HMainEditor
.BufferImage
->DiskImage
->Offset
,
999 HMainEditor
.BufferImage
->DiskImage
->Size
,
1000 HMainEditor
.BufferImage
->MemImage
->Offset
,
1001 HMainEditor
.BufferImage
->MemImage
->Size
,
1009 // THE input string length should > 0
1011 if (StrLen (InputBarGetString()) > 0) {
1013 // CHECK if filename's valid
1015 if (!IsValidFileName (InputBarGetString())) {
1017 HMainEditor
.BufferImage
->FileImage
->FileName
,
1018 HMainEditor
.BufferImage
->DiskImage
->Name
,
1019 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1020 HMainEditor
.BufferImage
->DiskImage
->Size
,
1021 HMainEditor
.BufferImage
->MemImage
->Offset
,
1022 HMainEditor
.BufferImage
->MemImage
->Size
,
1027 StatusBarSetStatusString (L
"Invalid File Name");
1037 Status
= HBufferImageRead (
1038 InputBarGetString(),
1039 HMainEditor
.BufferImage
->DiskImage
->Name
,
1040 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1041 HMainEditor
.BufferImage
->DiskImage
->Size
,
1042 HMainEditor
.BufferImage
->MemImage
->Offset
,
1043 HMainEditor
.BufferImage
->MemImage
->Size
,
1048 if (EFI_ERROR (Status
)) {
1050 HMainEditor
.BufferImage
->FileImage
->FileName
,
1051 HMainEditor
.BufferImage
->DiskImage
->Name
,
1052 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1053 HMainEditor
.BufferImage
->DiskImage
->Size
,
1054 HMainEditor
.BufferImage
->MemImage
->Offset
,
1055 HMainEditor
.BufferImage
->MemImage
->Size
,
1060 return EFI_LOAD_ERROR
;
1067 HMainCommandOpenDisk (
1072 Routine Description:
1074 Load a disk buffer editor
1084 EFI_OUT_OF_RESOURCES
1095 EDIT_FILE_TYPE BufferType
;
1098 // variable initialization
1102 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1105 // if current file is modified, so you need to choose
1106 // whether to save it first.
1108 if (HMainEditor
.BufferImage
->Modified
) {
1110 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1111 if (EFI_ERROR (Status
)) {
1115 // the answer is just one character
1117 Status
= InputBarSetStringSize (1);
1118 if (EFI_ERROR (Status
)) {
1122 // loop for user's answer
1123 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1127 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1132 if (Status
== EFI_NOT_READY
) {
1136 switch (InputBarGetString()[0]) {
1140 // want to save this buffer first
1142 Status
= HBufferImageSave (
1143 HMainEditor
.BufferImage
->FileImage
->FileName
,
1144 HMainEditor
.BufferImage
->DiskImage
->Name
,
1145 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1146 HMainEditor
.BufferImage
->DiskImage
->Size
,
1147 HMainEditor
.BufferImage
->MemImage
->Offset
,
1148 HMainEditor
.BufferImage
->MemImage
->Size
,
1151 if (EFI_ERROR (Status
)) {
1155 MainTitleBarRefresh (
1156 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1157 HMainEditor
.BufferImage
->BufferType
,
1158 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1160 HMainEditor
.ScreenSize
.Column
,
1161 HMainEditor
.ScreenSize
.Row
1169 // the file won't be saved
1181 // get disk block device name
1183 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1184 if (EFI_ERROR (Status
)) {
1188 Status
= InputBarSetStringSize (100);
1189 if (EFI_ERROR (Status
)) {
1194 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1199 if (Status
== EFI_NOT_READY
) {
1204 // THE input string length should > 0
1206 if (StrLen (InputBarGetString()) > 0) {
1211 DeviceName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
1212 if (DeviceName
== NULL
) {
1213 return EFI_OUT_OF_RESOURCES
;
1216 // get starting offset
1218 Status
= InputBarSetPrompt (L
"First Block No.: ");
1219 if (EFI_ERROR (Status
)) {
1223 Status
= InputBarSetStringSize (16);
1224 if (EFI_ERROR (Status
)) {
1229 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1234 if (Status
== EFI_NOT_READY
) {
1239 // THE input string length should > 0
1241 if (StrLen (InputBarGetString()) > 0) {
1242 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1243 if (EFI_ERROR (Status
)) {
1251 // get Number of Blocks:
1253 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1254 if (EFI_ERROR (Status
)) {
1258 Status
= InputBarSetStringSize (8);
1259 if (EFI_ERROR (Status
)) {
1264 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1269 if (Status
== EFI_NOT_READY
) {
1274 // THE input string length should > 0
1276 if (StrLen (InputBarGetString()) > 0) {
1277 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1278 if (EFI_ERROR (Status
)) {
1290 Status
= HBufferImageRead (
1301 if (EFI_ERROR (Status
)) {
1304 HMainEditor
.BufferImage
->FileImage
->FileName
,
1305 HMainEditor
.BufferImage
->DiskImage
->Name
,
1306 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1307 HMainEditor
.BufferImage
->DiskImage
->Size
,
1308 HMainEditor
.BufferImage
->MemImage
->Offset
,
1309 HMainEditor
.BufferImage
->MemImage
->Size
,
1313 return EFI_NOT_FOUND
;
1320 HMainCommandOpenMemory (
1325 Routine Description:
1327 Load memory content to editor
1337 EFI_OUT_OF_RESOURCES
1346 EDIT_FILE_TYPE BufferType
;
1349 // variable initialization
1353 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1356 // if current buffer is modified, so you need to choose
1357 // whether to save it first.
1359 if (HMainEditor
.BufferImage
->Modified
) {
1361 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1362 if (EFI_ERROR (Status
)) {
1366 // the answer is just one character
1368 Status
= InputBarSetStringSize (1);
1369 if (EFI_ERROR (Status
)) {
1373 // loop for user's answer
1374 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1378 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1383 if (Status
== EFI_NOT_READY
) {
1387 switch (InputBarGetString()[0]) {
1391 // want to save this buffer first
1393 Status
= HBufferImageSave (
1394 HMainEditor
.BufferImage
->FileImage
->FileName
,
1395 HMainEditor
.BufferImage
->DiskImage
->Name
,
1396 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1397 HMainEditor
.BufferImage
->DiskImage
->Size
,
1398 HMainEditor
.BufferImage
->MemImage
->Offset
,
1399 HMainEditor
.BufferImage
->MemImage
->Size
,
1402 if (EFI_ERROR (Status
)) {
1406 MainTitleBarRefresh (
1407 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1408 HMainEditor
.BufferImage
->BufferType
,
1409 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1411 HMainEditor
.ScreenSize
.Column
,
1412 HMainEditor
.ScreenSize
.Row
1420 // the file won't be saved
1432 // get starting offset
1434 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1435 if (EFI_ERROR (Status
)) {
1439 Status
= InputBarSetStringSize (8);
1440 if (EFI_ERROR (Status
)) {
1445 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1450 if (Status
== EFI_NOT_READY
) {
1455 // THE input string length should > 0
1457 if (StrLen (InputBarGetString()) > 0) {
1458 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1459 if (EFI_ERROR (Status
)) {
1467 // get Number of Blocks:
1469 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1470 if (EFI_ERROR (Status
)) {
1474 Status
= InputBarSetStringSize (8);
1475 if (EFI_ERROR (Status
)) {
1480 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1485 if (Status
== EFI_NOT_READY
) {
1490 // THE input string length should > 0
1492 if (StrLen (InputBarGetString()) > 0) {
1493 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1494 if (EFI_ERROR (Status
)) {
1506 if ((Offset
+ Size
- 1)> 0xffffffff) {
1507 StatusBarSetStatusString (L
"Invalid parameter");
1508 return EFI_LOAD_ERROR
;
1511 Status
= HBufferImageRead (
1522 if (EFI_ERROR (Status
)) {
1523 StatusBarSetStatusString (L
"Read Device Error!");
1525 HMainEditor
.BufferImage
->FileImage
->FileName
,
1526 HMainEditor
.BufferImage
->DiskImage
->Name
,
1527 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1528 HMainEditor
.BufferImage
->DiskImage
->Size
,
1529 HMainEditor
.BufferImage
->MemImage
->Offset
,
1530 HMainEditor
.BufferImage
->MemImage
->Size
,
1534 return EFI_NOT_FOUND
;
1540 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1542 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1543 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F1
),
1544 HMainCommandGoToOffset
1547 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1548 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F2
),
1549 HMainCommandSaveBuffer
1552 STRING_TOKEN(STR_EDIT_LIBMENUBAR_EXIT
),
1553 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F3
),
1558 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1559 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F4
),
1560 HMainCommandSelectStart
1563 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1564 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F5
),
1565 HMainCommandSelectEnd
1568 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_CUT
),
1569 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F6
),
1573 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_PASTE
),
1574 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F7
),
1579 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1580 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F8
),
1581 HMainCommandOpenFile
1584 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1585 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9
),
1586 HMainCommandOpenDisk
1589 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1590 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F10
),
1591 HMainCommandOpenMemory
1608 Routine Description:
1610 Init function for MainEditor
1624 EFI_HANDLE
*HandleBuffer
;
1629 // basic initialization
1631 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1634 // set screen attributes
1636 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1638 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
) (gST
->ConOut
->Mode
->Attribute
>> 4);
1640 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1642 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1645 // query screen size
1647 gST
->ConOut
->QueryMode (
1649 gST
->ConOut
->Mode
->Mode
,
1650 &(HMainEditor
.ScreenSize
.Column
),
1651 &(HMainEditor
.ScreenSize
.Row
)
1655 // Find mouse in System Table ConsoleInHandle
1657 Status
= gBS
->HandleProtocol (
1659 &gEfiSimplePointerProtocolGuid
,
1660 (VOID
**)&HMainEditor
.MouseInterface
1662 if (EFI_ERROR (Status
)) {
1664 // If there is no Simple Pointer Protocol on System Table
1666 HandleBuffer
= NULL
;
1667 HMainEditor
.MouseInterface
= NULL
;
1668 Status
= gBS
->LocateHandleBuffer (
1670 &gEfiSimplePointerProtocolGuid
,
1675 if (!EFI_ERROR (Status
) && HandleCount
> 0) {
1677 // Try to find the first available mouse device
1679 for (Index
= 0; Index
< HandleCount
; Index
++) {
1680 Status
= gBS
->HandleProtocol (
1681 HandleBuffer
[Index
],
1682 &gEfiSimplePointerProtocolGuid
,
1683 (VOID
**)&HMainEditor
.MouseInterface
1685 if (!EFI_ERROR (Status
)) {
1690 if (HandleBuffer
!= NULL
) {
1691 FreePool (HandleBuffer
);
1695 if (!EFI_ERROR (Status
) && HMainEditor
.MouseInterface
!= NULL
) {
1696 HMainEditor
.MouseAccumulatorX
= 0;
1697 HMainEditor
.MouseAccumulatorY
= 0;
1698 HMainEditor
.MouseSupported
= TRUE
;
1702 // below will call the five components' init function
1704 Status
= MainTitleBarInit (NULL
);
1705 if (EFI_ERROR (Status
)) {
1706 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1707 return EFI_LOAD_ERROR
;
1710 Status
= MenuBarInit (HexEditorMenuItems
);
1711 if (EFI_ERROR (Status
)) {
1712 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1713 return EFI_LOAD_ERROR
;
1716 Status
= StatusBarInit ();
1717 if (EFI_ERROR (Status
)) {
1718 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1719 return EFI_LOAD_ERROR
;
1724 Status
= HBufferImageInit ();
1725 if (EFI_ERROR (Status
)) {
1726 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1727 return EFI_LOAD_ERROR
;
1730 Status
= HClipBoardInit ();
1731 if (EFI_ERROR (Status
)) {
1732 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1733 return EFI_LOAD_ERROR
;
1736 // clear whole screen and enable cursor
1738 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1739 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1742 // initialize EditorFirst and EditorExit
1744 HEditorFirst
= TRUE
;
1745 HEditorExit
= FALSE
;
1746 HEditorMouseAction
= FALSE
;
1752 HMainEditorCleanup (
1757 Routine Description:
1759 cleanup function for MainEditor
1775 // call the five components' cleanup function
1777 MainTitleBarCleanup ();
1781 StatusBarCleanup ();
1785 Status
= HBufferImageCleanup ();
1786 if (EFI_ERROR (Status
)) {
1787 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1790 Status
= HClipBoardCleanup ();
1791 if (EFI_ERROR (Status
)) {
1792 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1797 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1798 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1801 gST
->ConOut
->SetAttribute (
1803 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1805 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1811 HMainEditorRefresh (
1816 Routine Description:
1818 Refresh function for MainEditor
1831 // to aVOID screen flicker
1832 // the stall value is from experience
1837 // call the four components refresh function
1839 MainTitleBarRefresh (
1840 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1841 HMainEditor
.BufferImage
->BufferType
,
1842 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1843 HMainEditor
.BufferImage
->Modified
,
1844 HMainEditor
.ScreenSize
.Column
,
1845 HMainEditor
.ScreenSize
.Row
1847 HBufferImageRefresh ();
1850 HMainEditor
.ScreenSize
.Row
,
1851 HMainEditor
.ScreenSize
.Column
,
1857 HMainEditor
.ScreenSize
.Row
,
1858 HMainEditor
.ScreenSize
.Column
);
1861 // EditorFirst is now set to FALSE
1863 HEditorFirst
= FALSE
;
1870 HMainEditorHandleMouseInput (
1871 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1872 OUT BOOLEAN
*BeforeLeftButtonDown
1882 HEFI_EDITOR_LINE
*Line
;
1889 // have mouse movement
1891 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1895 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1896 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1898 HBufferImageAdjustMousePosition (TextX
, TextY
);
1904 if (MouseState
.LeftButton
) {
1905 HighBits
= HBufferImageIsAtHighBits (
1906 HMainEditor
.BufferImage
->MousePosition
.Column
,
1911 // not at an movable place
1915 // now just move mouse pointer to legal position
1918 // move mouse position to legal position
1920 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
1921 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
1922 HMainEditor
.BufferImage
->MousePosition
.Column
--;
1923 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1925 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
1926 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1939 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
1940 HMainEditor
.BufferImage
->MousePosition
.Row
-
1941 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1943 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
1948 // now just move mouse pointer to legal position
1950 FRow
= HMainEditor
.BufferImage
->NumLines
;
1954 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1955 for (Index
= 0; Index
< FRow
- 1; Index
++) {
1956 Link
= Link
->ForwardLink
;
1959 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1965 // now just move mouse pointer to legal position
1967 if (FCol
> Line
->Size
) {
1968 if (*BeforeLeftButtonDown
) {
1971 if (Line
->Size
== 0) {
1984 FCol
= Line
->Size
+ 1;
1989 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1991 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1993 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
1995 *BeforeLeftButtonDown
= TRUE
;
2000 // else of if LButton
2004 if (*BeforeLeftButtonDown
== TRUE
) {
2010 *BeforeLeftButtonDown
= FALSE
;
2017 return EFI_NOT_FOUND
;
2021 HMainEditorKeyInput (
2026 Routine Description:
2028 Handle user key input. will route it to other components handle function
2038 EFI_OUT_OF_RESOURCES
2044 EFI_SIMPLE_POINTER_STATE MouseState
;
2045 BOOLEAN LengthChange
;
2048 BOOLEAN BeforeMouseIsDown
;
2049 BOOLEAN MouseIsDown
;
2054 UINTN SelectStartBackup
;
2055 UINTN SelectEndBackup
;
2058 // variable initialization
2063 LengthChange
= FALSE
;
2065 MouseIsDown
= FALSE
;
2071 Status
= EFI_SUCCESS
;
2073 HEditorMouseAction
= FALSE
;
2076 // backup some key elements, so that can aVOID some refresh work
2078 HMainEditorBackup ();
2081 // wait for user key input
2084 // change priority of checking mouse/keyboard activity dynamically
2085 // so prevent starvation of keyboard.
2086 // if last time, mouse moves then this time check keyboard
2088 if (HMainEditor
.MouseSupported
) {
2089 Status
= HMainEditor
.MouseInterface
->GetState (
2090 HMainEditor
.MouseInterface
,
2093 if (!EFI_ERROR (Status
)) {
2095 BeforeMouseIsDown
= MouseIsDown
;
2097 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2099 if (!EFI_ERROR (Status
)) {
2100 if (BeforeMouseIsDown
== FALSE
) {
2104 if (MouseIsDown
== TRUE
) {
2105 FRow
= HBufferImage
.BufferPosition
.Row
;
2106 FCol
= HBufferImage
.BufferPosition
.Column
;
2107 SelectStartBackup
= HMainEditor
.SelectStart
;
2108 SelectEndBackup
= HMainEditor
.SelectEnd
;
2114 SelectStartBackup
= HMainEditor
.SelectStart
;
2115 SelectEndBackup
= HMainEditor
.SelectEnd
;
2120 if (MouseIsDown
== TRUE
) {
2121 if (FirstDown
== TRUE
) {
2122 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2123 HMainEditor
.SelectStart
= 0;
2124 HMainEditor
.SelectEnd
= 0;
2125 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2132 (HBufferImage
.BufferPosition
.Row
- 1) *
2134 HBufferImage
.BufferPosition
.Column
2135 ) >= HMainEditor
.SelectStart
2137 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2139 HBufferImage
.BufferPosition
.Column
;
2141 HMainEditor
.SelectEnd
= 0;
2145 // end of if RelativeX/Y
2152 if (HBufferImageGetTotalSize () == 0) {
2153 HMainEditor
.SelectStart
= 0;
2154 HMainEditor
.SelectEnd
= 0;
2160 (HBufferImage
.BufferPosition
.Row
- 1) *
2162 HBufferImage
.BufferPosition
.Column
2163 ) >= HMainEditor
.SelectStart
2165 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2167 HBufferImage
.BufferPosition
.Column
;
2169 HMainEditor
.SelectEnd
= 0;
2172 if (HMainEditor
.SelectEnd
== 0) {
2173 HMainEditor
.SelectStart
= 0;
2181 if (SelectStartBackup
!= HMainEditor
.SelectStart
|| SelectEndBackup
!= HMainEditor
.SelectEnd
) {
2182 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2183 HBufferImageNeedRefresh
= TRUE
;
2185 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2186 HBufferImageNeedRefresh
= TRUE
;
2188 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2194 HEditorMouseAction
= TRUE
;
2195 HBufferImageMouseNeedRefresh
= TRUE
;
2197 } else if (Status
== EFI_LOAD_ERROR
) {
2198 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2203 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2204 if (!EFI_ERROR (Status
)) {
2206 // dispatch to different components' key handling function
2207 // so not everywhere has to set this variable
2209 HBufferImageMouseNeedRefresh
= TRUE
;
2212 // clear previous status string
2214 StatusBarSetRefresh();
2216 if (Key
.ScanCode
== SCAN_NULL
) {
2217 Status
= HBufferImageHandleInput (&Key
);
2218 } else if (((Key
.ScanCode
>= SCAN_UP
) && (Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2219 Status
= HBufferImageHandleInput (&Key
);
2220 } else if (((Key
.ScanCode
>= SCAN_F1
) && Key
.ScanCode
<= (SCAN_F12
))) {
2221 Status
= MenuBarDispatchFunctionKey (&Key
);
2223 StatusBarSetStatusString (L
"Unknown Command");
2225 HBufferImageMouseNeedRefresh
= FALSE
;
2228 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_OUT_OF_RESOURCES
) {
2230 // not already has some error status
2232 if (StrCmp (L
"", StatusBarGetString()) == 0) {
2233 StatusBarSetStatusString (L
"Disk Error. Try Again");
2238 // decide if has to set length warning
2240 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2241 LengthChange
= FALSE
;
2244 // still the old buffer
2246 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2247 Size
= HBufferImageGetTotalSize ();
2249 switch (HBufferImage
.BufferType
) {
2250 case FileTypeDiskBuffer
:
2251 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2254 case FileTypeMemBuffer
:
2255 OldSize
= HBufferImage
.MemImage
->Size
;
2259 if (LengthChange
== FALSE
) {
2260 if (OldSize
!= Size
) {
2261 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2265 if (OldSize
!= Size
) {
2266 LengthChange
= TRUE
;
2268 LengthChange
= FALSE
;
2273 // after handling, refresh editor
2275 HMainEditorRefresh ();
2277 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2283 Backup function for MainEditor.
2291 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2292 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2293 HBufferImageBackup ();