2 Defines the Main Editor data type -
4 - Instances of the other objects of the editor
7 Copyright (c) 2005 - 2012, 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 BOOLEAN HBufferImageMouseNeedRefresh
;
41 extern BOOLEAN HBufferImageNeedRefresh
;
42 extern BOOLEAN HBufferImageOnlyLineNeedRefresh
;
44 HEFI_EDITOR_GLOBAL_EDITOR HMainEditor
;
45 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorBackupVar
;
48 // basic initialization for MainEditor
50 HEFI_EDITOR_GLOBAL_EDITOR HMainEditorConst
= {
68 Help info that will be displayed.
70 EFI_STRING_ID HexMainMenuHelpInfo
[] = {
71 STRING_TOKEN(STR_HEXEDIT_HELP_TITLE
),
72 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
73 STRING_TOKEN(STR_HEXEDIT_HELP_LIST_TITLE
),
74 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
75 STRING_TOKEN(STR_HEXEDIT_HELP_GO_TO_OFFSET
),
76 STRING_TOKEN(STR_HEXEDIT_HELP_SAVE_BUFFER
),
77 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT
),
78 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_START
),
79 STRING_TOKEN(STR_HEXEDIT_HELP_SELECT_END
),
80 STRING_TOKEN(STR_HEXEDIT_HELP_CUT
),
81 STRING_TOKEN(STR_HEXEDIT_HELP_PASTE
),
82 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_FILE
),
83 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_DISK
),
84 STRING_TOKEN(STR_HEXEDIT_HELP_OPEN_MEMORY
),
85 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
86 STRING_TOKEN(STR_HEXEDIT_HELP_EXIT_HELP
),
87 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
88 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
89 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
90 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
91 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
92 STRING_TOKEN(STR_HEXEDIT_HELP_BLANK
),
93 STRING_TOKEN(STR_HEXEDIT_HELP_DIV
),
101 @retval EFI_SUCCESS The operation was successful.
104 HMainCommandDisplayHelp (
114 for (CurrentLine
= 0; 0 != HexMainMenuHelpInfo
[CurrentLine
]; CurrentLine
++) {
115 InfoString
= HiiGetString(gShellDebug1HiiHandle
, HexMainMenuHelpInfo
[CurrentLine
]
117 ShellPrintEx (0,CurrentLine
+1,L
"%E%s%N",InfoString
);
122 gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
123 } while(SCAN_CONTROL_W
!= Key
.UnicodeChar
);
125 // update screen with buffer's info
126 HBufferImageNeedRefresh
= TRUE
;
127 HBufferImageOnlyLineNeedRefresh
= FALSE
;
128 HBufferImageRefresh ();
134 Move cursor to specified lines.
136 @retval EFI_SUCCESS The operation was successful.
139 HMainCommandGoToOffset (
150 // variable initialization
160 Status
= InputBarSetPrompt (L
"Go To Offset: ");
161 if (EFI_ERROR (Status
)) {
165 Status
= InputBarSetStringSize (8);
166 if (EFI_ERROR (Status
)) {
171 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
176 if (Status
== EFI_NOT_READY
) {
181 // THE input string length should > 0
183 if (StrLen (InputBarGetString()) > 0) {
184 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
185 if (EFI_ERROR (Status
)) {
186 StatusBarSetStatusString (L
"Invalid Offset");
194 Size
= HBufferImageGetTotalSize ();
195 if (Offset
>= Size
) {
196 StatusBarSetStatusString (L
"Invalid Offset");
200 FRow
= (UINTN
)DivU64x32(Offset
, 0x10) + 1;
201 FCol
= (UINTN
)ModU64x32(Offset
, 0x10) + 1;
203 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
205 HBufferImageNeedRefresh
= TRUE
;
206 HBufferImageOnlyLineNeedRefresh
= FALSE
;
207 HBufferImageMouseNeedRefresh
= TRUE
;
213 Save current opened buffer.
214 If is file buffer, you can save to current file name or
215 save to another file name.
217 @retval EFI_SUCCESS The operation was successful.
218 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
219 @retval EFI_LOAD_ERROR A load error occured.
222 HMainCommandSaveBuffer (
232 SHELL_FILE_HANDLE ShellFileHandle
;
234 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
235 if (!HMainEditor
.BufferImage
->Modified
) {
239 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
240 if (EFI_ERROR (Status
)) {
244 // the answer is just one character
246 Status
= InputBarSetStringSize (1);
247 if (EFI_ERROR (Status
)) {
251 // loop for user's answer
252 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
255 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
260 if (Status
== EFI_NOT_READY
) {
264 switch (InputBarGetString()[0]) {
268 // want to save this buffer first
270 Status
= HBufferImageSave (
272 HMainEditor
.BufferImage
->DiskImage
->Name
,
273 HMainEditor
.BufferImage
->DiskImage
->Offset
,
274 HMainEditor
.BufferImage
->DiskImage
->Size
,
275 HMainEditor
.BufferImage
->MemImage
->Offset
,
276 HMainEditor
.BufferImage
->MemImage
->Size
,
277 HMainEditor
.BufferImage
->BufferType
280 if (EFI_ERROR (Status
)) {
281 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
290 // the file won't be saved
308 // ENDOF != FILEBUFFER
310 // This command will save currently opened file to disk.
311 // You can choose save to another file name or just save to
312 // current file name.
313 // Below is the scenario of Save File command: (
314 // Suppose the old file name is A )
315 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
316 // IF user press ESC, Save File command ends .
317 // IF user press Enter, input file name will be A.
318 // IF user inputs a new file name B, input file name will be B.
320 // 2. IF input file name is A, go to do Step 3.
321 // IF input file name is B, go to do Step 4.
323 // 3. IF A is read only, Status Bar will show "Access Denied"
324 // and Save File commands ends.
325 // IF A is not read only, save file buffer to disk
326 // and remove Modified flag in Title Bar , then Save File command ends.
328 // 4. IF B does not exist, create this file and save file buffer to it.
330 // IF B exits, do Step 5.
332 // 5. An Input Bar will be prompted:
333 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
334 // IF user press 'y' or 'Y', do Step 6.
335 // IF user press 'n' or 'N', Save File commands ends.
336 // IF user press 'c' or 'C' or ESC, Save File commands ends.
338 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
339 // and Save File commands ends.
340 // IF B can be read and write, save file buffer to B.
342 // 7. Update File Name field in Title Bar to B
343 // and remove the Modified flag in Title Bar.
345 Str
= CatSPrint(NULL
,
346 L
"File to Save: [%s]",
347 HMainEditor
.BufferImage
->FileImage
->FileName
350 return EFI_OUT_OF_RESOURCES
;
353 if (StrLen (Str
) >= 50) {
355 // replace the long file name with "..."
364 Status
= InputBarSetPrompt (Str
);
365 if (EFI_ERROR (Status
)) {
369 Status
= InputBarSetStringSize (100);
370 if (EFI_ERROR (Status
)) {
376 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
379 // if user pressed ESC
381 if (Status
== EFI_NOT_READY
) {
382 SHELL_FREE_NON_NULL (Str
);
386 SHELL_FREE_NON_NULL (Str
);
389 // if just enter pressed, so think save to current file name
391 if (StrLen (InputBarGetString()) == 0) {
392 FileName
= CatSPrint(NULL
,
394 HMainEditor
.BufferImage
->FileImage
->FileName
397 FileName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
400 if (FileName
== NULL
) {
401 return EFI_OUT_OF_RESOURCES
;
404 if (!IsValidFileName (FileName
)) {
405 StatusBarSetStatusString (L
"Invalid File Name");
406 SHELL_FREE_NON_NULL (FileName
);
413 // save to the old file
415 if (StringNoCaseCompare (
417 &HMainEditor
.BufferImage
->FileImage
->FileName
424 // if the file is read only, so can not write back to it.
426 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
) {
427 StatusBarSetStatusString (L
"Access Denied");
428 SHELL_FREE_NON_NULL (FileName
);
432 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
434 if (!EFI_ERROR (Status
)) {
436 Info
= ShellGetFileInfo(ShellFileHandle
);
438 ShellCloseFile(&ShellFileHandle
);
440 // check if read only
442 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
443 StatusBarSetStatusString (L
"Access Denied");
444 SHELL_FREE_NON_NULL (FileName
);
448 SHELL_FREE_NON_NULL(Info
);
450 // ask user whether to overwrite this file
452 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
453 if (EFI_ERROR (Status
)) {
454 SHELL_FREE_NON_NULL (FileName
);
458 Status
= InputBarSetStringSize (1);
459 if (EFI_ERROR (Status
)) {
460 SHELL_FREE_NON_NULL (FileName
);
466 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
468 if (Status
== EFI_NOT_READY
) {
469 SHELL_FREE_NON_NULL (FileName
);
473 switch (InputBarGetString()[0]) {
480 SHELL_FREE_NON_NULL (FileName
);
484 SHELL_FREE_NON_NULL (FileName
);
488 } // if opened existing file
492 // save file back to disk
494 Status
= HBufferImageSave (
496 HMainEditor
.BufferImage
->DiskImage
->Name
,
497 HMainEditor
.BufferImage
->DiskImage
->Offset
,
498 HMainEditor
.BufferImage
->DiskImage
->Size
,
499 HMainEditor
.BufferImage
->MemImage
->Offset
,
500 HMainEditor
.BufferImage
->MemImage
->Size
,
503 SHELL_FREE_NON_NULL (FileName
);
505 if (EFI_ERROR (Status
)) {
506 return EFI_LOAD_ERROR
;
513 Load a disk buffer editor.
515 @retval EFI_SUCCESS The operation was successful.
516 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
517 @retval EFI_LOAD_ERROR A load error occured.
520 HMainCommandSelectStart (
526 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
531 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
532 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
533 StatusBarSetStatusString (L
"Invalid Block Start");
534 return EFI_LOAD_ERROR
;
538 if (HMainEditor
.SelectEnd
!= 0 && Start
> HMainEditor
.SelectEnd
) {
539 StatusBarSetStatusString (L
"Invalid Block Start");
540 return EFI_LOAD_ERROR
;
543 HMainEditor
.SelectStart
= Start
;
545 HBufferImageNeedRefresh
= TRUE
;
551 Load a disk buffer editor.
553 @retval EFI_SUCCESS The operation was successful.
554 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
555 @retval EFI_LOAD_ERROR A load error occured.
558 HMainCommandSelectEnd (
564 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
569 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
570 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
571 StatusBarSetStatusString (L
"Invalid Block End");
572 return EFI_LOAD_ERROR
;
576 if (HMainEditor
.SelectStart
!= 0 && End
< HMainEditor
.SelectStart
) {
577 StatusBarSetStatusString (L
"Invalid Block End");
581 HMainEditor
.SelectEnd
= End
;
583 HBufferImageNeedRefresh
= TRUE
;
589 Cut current line to clipboard.
591 @retval EFI_SUCCESS The operation was successful.
592 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
593 @retval EFI_LOAD_ERROR A load error occured.
601 HEFI_EDITOR_LINE
*Line
;
607 // not select, so not allowed to cut
609 if (HMainEditor
.SelectStart
== 0) {
610 StatusBarSetStatusString (L
"No Block is Selected");
614 // not select, so not allowed to cut
616 if (HMainEditor
.SelectEnd
== 0) {
617 StatusBarSetStatusString (L
"No Block is Selected");
621 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
622 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
623 Link
= Link
->ForwardLink
;
626 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
628 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
629 Buffer
= AllocateZeroPool (Count
);
630 if (Buffer
== NULL
) {
631 return EFI_OUT_OF_RESOURCES
;
634 // cut the selected area
636 HBufferImageDeleteCharacterFromBuffer (
637 HMainEditor
.SelectStart
- 1,
645 HClipBoardSet (Buffer
, Count
);
647 HBufferImageNeedRefresh
= TRUE
;
648 HBufferImageOnlyLineNeedRefresh
= FALSE
;
650 if (!HMainEditor
.BufferImage
->Modified
) {
651 HMainEditor
.BufferImage
->Modified
= TRUE
;
655 // now no select area
657 HMainEditor
.SelectStart
= 0;
658 HMainEditor
.SelectEnd
= 0;
664 Paste line to file buffer.
666 @retval EFI_SUCCESS The operation was successful.
667 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
668 @retval EFI_LOAD_ERROR A load error occured.
676 BOOLEAN OnlyLineRefresh
;
677 HEFI_EDITOR_LINE
*Line
;
682 Count
= HClipBoardGet (&Buffer
);
683 if (Count
== 0 || Buffer
== NULL
) {
684 StatusBarSetStatusString (L
"Nothing to Paste");
688 Line
= HMainEditor
.BufferImage
->CurrentLine
;
690 OnlyLineRefresh
= FALSE
;
691 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
&& Line
->Size
+ Count
< 0x10) {
693 // is at last line, and after paste will not exceed
694 // so only this line need to be refreshed
696 // if after add, the line is 0x10, then will append a new line
697 // so the whole page will need be refreshed
699 OnlyLineRefresh
= TRUE
;
703 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
705 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
707 if (OnlyLineRefresh
) {
708 HBufferImageNeedRefresh
= FALSE
;
709 HBufferImageOnlyLineNeedRefresh
= TRUE
;
711 HBufferImageNeedRefresh
= TRUE
;
712 HBufferImageOnlyLineNeedRefresh
= FALSE
;
715 if (!HMainEditor
.BufferImage
->Modified
) {
716 HMainEditor
.BufferImage
->Modified
= TRUE
;
726 @retval EFI_SUCCESS The operation was successful.
727 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
728 @retval EFI_LOAD_ERROR A load error occured.
738 // Below is the scenario of Exit command:
739 // 1. IF currently opened file is not modified, exit the editor and
740 // Exit command ends.
741 // IF currently opened file is modified, do Step 2
743 // 2. An Input Bar will be prompted:
744 // "File modified. Save ( Yes/No/Cancel )?"
745 // IF user press 'y' or 'Y', currently opened file will be saved and
747 // IF user press 'n' or 'N', currently opened file will not be saved
749 // IF user press 'c' or 'C' or ESC, Exit command ends.
752 // if file has been modified, so will prompt user
753 // whether to save the changes
755 if (HMainEditor
.BufferImage
->Modified
) {
757 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
758 if (EFI_ERROR (Status
)) {
762 Status
= InputBarSetStringSize (1);
763 if (EFI_ERROR (Status
)) {
768 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
773 if (Status
== EFI_NOT_READY
) {
777 switch (InputBarGetString()[0]) {
781 // write file back to disk
783 Status
= HBufferImageSave (
784 HMainEditor
.BufferImage
->FileImage
->FileName
,
785 HMainEditor
.BufferImage
->DiskImage
->Name
,
786 HMainEditor
.BufferImage
->DiskImage
->Offset
,
787 HMainEditor
.BufferImage
->DiskImage
->Size
,
788 HMainEditor
.BufferImage
->MemImage
->Offset
,
789 HMainEditor
.BufferImage
->MemImage
->Size
,
790 HMainEditor
.BufferImage
->BufferType
792 if (!EFI_ERROR (Status
)) {
817 Load a file from disk to editor.
819 @retval EFI_SUCCESS The operation was successful.
820 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
821 @retval EFI_LOAD_ERROR A load error occured.
824 HMainCommandOpenFile (
830 EDIT_FILE_TYPE BufferType
;
832 BufferType
= HMainEditor
.BufferImage
->BufferType
;
835 // This command will open a file from current working directory.
836 // Read-only file can also be opened. But it can not be modified.
837 // Below is the scenario of Open File command:
838 // 1. IF currently opened file has not been modified, directly go to step .
839 // IF currently opened file has been modified, an Input Bar will be
841 // "File Modified. Save ( Yes/No/Cancel) ?"
842 // IF user press 'y' or 'Y', currently opened file will be saved.
843 // IF user press 'n' or 'N', currently opened file will
845 // IF user press 'c' or 'C' or ESC, Open File command ends and
846 // currently opened file is still opened.
848 // 2. An Input Bar will be prompted as : "File Name to Open: "
849 // IF user press ESC, Open File command ends and
850 // currently opened file is still opened.
851 // Any other inputs with a Return will cause
852 // currently opened file close.
854 // 3. IF user input file name is an existing file ,
855 // this file will be read and opened.
856 // IF user input file name is a new file, this file will be created
857 // and opened. This file's type ( UNICODE or ASCII ) is the same with
861 // if current file is modified, so you need to choose whether to
864 if (HMainEditor
.BufferImage
->Modified
) {
866 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
867 if (EFI_ERROR (Status
)) {
871 // the answer is just one character
873 Status
= InputBarSetStringSize (1);
874 if (EFI_ERROR (Status
)) {
878 // loop for user's answer
879 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
883 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
888 if (Status
== EFI_NOT_READY
) {
892 switch (InputBarGetString()[0]) {
896 // want to save this buffer first
898 Status
= HBufferImageSave (
899 HMainEditor
.BufferImage
->FileImage
->FileName
,
900 HMainEditor
.BufferImage
->DiskImage
->Name
,
901 HMainEditor
.BufferImage
->DiskImage
->Offset
,
902 HMainEditor
.BufferImage
->DiskImage
->Size
,
903 HMainEditor
.BufferImage
->MemImage
->Offset
,
904 HMainEditor
.BufferImage
->MemImage
->Size
,
905 HMainEditor
.BufferImage
->BufferType
907 if (EFI_ERROR (Status
)) {
911 MainTitleBarRefresh (
912 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
913 HMainEditor
.BufferImage
->BufferType
,
914 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
916 HMainEditor
.ScreenSize
.Column
,
917 HMainEditor
.ScreenSize
.Row
,
918 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
919 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
927 // the file won't be saved
939 // TO get the open file name
941 Status
= InputBarSetPrompt (L
"File Name to Open: ");
942 if (EFI_ERROR (Status
)) {
944 HMainEditor
.BufferImage
->FileImage
->FileName
,
945 HMainEditor
.BufferImage
->DiskImage
->Name
,
946 HMainEditor
.BufferImage
->DiskImage
->Offset
,
947 HMainEditor
.BufferImage
->DiskImage
->Size
,
948 HMainEditor
.BufferImage
->MemImage
->Offset
,
949 HMainEditor
.BufferImage
->MemImage
->Size
,
956 Status
= InputBarSetStringSize (100);
957 if (EFI_ERROR (Status
)) {
958 Status
= HBufferImageRead (
959 HMainEditor
.BufferImage
->FileImage
->FileName
,
960 HMainEditor
.BufferImage
->DiskImage
->Name
,
961 HMainEditor
.BufferImage
->DiskImage
->Offset
,
962 HMainEditor
.BufferImage
->DiskImage
->Size
,
963 HMainEditor
.BufferImage
->MemImage
->Offset
,
964 HMainEditor
.BufferImage
->MemImage
->Size
,
972 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
977 if (Status
== EFI_NOT_READY
) {
978 Status
= HBufferImageRead (
979 HMainEditor
.BufferImage
->FileImage
->FileName
,
980 HMainEditor
.BufferImage
->DiskImage
->Name
,
981 HMainEditor
.BufferImage
->DiskImage
->Offset
,
982 HMainEditor
.BufferImage
->DiskImage
->Size
,
983 HMainEditor
.BufferImage
->MemImage
->Offset
,
984 HMainEditor
.BufferImage
->MemImage
->Size
,
992 // THE input string length should > 0
994 if (StrLen (InputBarGetString()) > 0) {
996 // CHECK if filename's valid
998 if (!IsValidFileName (InputBarGetString())) {
1000 HMainEditor
.BufferImage
->FileImage
->FileName
,
1001 HMainEditor
.BufferImage
->DiskImage
->Name
,
1002 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1003 HMainEditor
.BufferImage
->DiskImage
->Size
,
1004 HMainEditor
.BufferImage
->MemImage
->Offset
,
1005 HMainEditor
.BufferImage
->MemImage
->Size
,
1010 StatusBarSetStatusString (L
"Invalid File Name");
1020 Status
= HBufferImageRead (
1021 InputBarGetString(),
1022 HMainEditor
.BufferImage
->DiskImage
->Name
,
1023 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1024 HMainEditor
.BufferImage
->DiskImage
->Size
,
1025 HMainEditor
.BufferImage
->MemImage
->Offset
,
1026 HMainEditor
.BufferImage
->MemImage
->Size
,
1031 if (EFI_ERROR (Status
)) {
1033 HMainEditor
.BufferImage
->FileImage
->FileName
,
1034 HMainEditor
.BufferImage
->DiskImage
->Name
,
1035 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1036 HMainEditor
.BufferImage
->DiskImage
->Size
,
1037 HMainEditor
.BufferImage
->MemImage
->Offset
,
1038 HMainEditor
.BufferImage
->MemImage
->Size
,
1043 return EFI_LOAD_ERROR
;
1050 Load a disk buffer editor.
1052 @retval EFI_SUCCESS The operation was successful.
1053 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1054 @retval EFI_LOAD_ERROR A load error occured.
1055 @retval EFI_NOT_FOUND The disk was not found.
1058 HMainCommandOpenDisk (
1068 EDIT_FILE_TYPE BufferType
;
1071 // variable initialization
1075 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1078 // if current file is modified, so you need to choose
1079 // whether to save it first.
1081 if (HMainEditor
.BufferImage
->Modified
) {
1083 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1084 if (EFI_ERROR (Status
)) {
1088 // the answer is just one character
1090 Status
= InputBarSetStringSize (1);
1091 if (EFI_ERROR (Status
)) {
1095 // loop for user's answer
1096 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1100 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1105 if (Status
== EFI_NOT_READY
) {
1109 switch (InputBarGetString()[0]) {
1113 // want to save this buffer first
1115 Status
= HBufferImageSave (
1116 HMainEditor
.BufferImage
->FileImage
->FileName
,
1117 HMainEditor
.BufferImage
->DiskImage
->Name
,
1118 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1119 HMainEditor
.BufferImage
->DiskImage
->Size
,
1120 HMainEditor
.BufferImage
->MemImage
->Offset
,
1121 HMainEditor
.BufferImage
->MemImage
->Size
,
1124 if (EFI_ERROR (Status
)) {
1128 MainTitleBarRefresh (
1129 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1130 HMainEditor
.BufferImage
->BufferType
,
1131 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1133 HMainEditor
.ScreenSize
.Column
,
1134 HMainEditor
.ScreenSize
.Row
,
1135 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1136 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1144 // the file won't be saved
1156 // get disk block device name
1158 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1159 if (EFI_ERROR (Status
)) {
1163 Status
= InputBarSetStringSize (100);
1164 if (EFI_ERROR (Status
)) {
1169 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1174 if (Status
== EFI_NOT_READY
) {
1179 // THE input string length should > 0
1181 if (StrLen (InputBarGetString()) > 0) {
1186 DeviceName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
1187 if (DeviceName
== NULL
) {
1188 return EFI_OUT_OF_RESOURCES
;
1191 // get starting offset
1193 Status
= InputBarSetPrompt (L
"First Block No.: ");
1194 if (EFI_ERROR (Status
)) {
1198 Status
= InputBarSetStringSize (16);
1199 if (EFI_ERROR (Status
)) {
1204 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1209 if (Status
== EFI_NOT_READY
) {
1214 // THE input string length should > 0
1216 if (StrLen (InputBarGetString()) > 0) {
1217 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1218 if (EFI_ERROR (Status
)) {
1226 // get Number of Blocks:
1228 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1229 if (EFI_ERROR (Status
)) {
1233 Status
= InputBarSetStringSize (8);
1234 if (EFI_ERROR (Status
)) {
1239 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1244 if (Status
== EFI_NOT_READY
) {
1249 // THE input string length should > 0
1251 if (StrLen (InputBarGetString()) > 0) {
1252 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1253 if (EFI_ERROR (Status
)) {
1265 Status
= HBufferImageRead (
1276 if (EFI_ERROR (Status
)) {
1279 HMainEditor
.BufferImage
->FileImage
->FileName
,
1280 HMainEditor
.BufferImage
->DiskImage
->Name
,
1281 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1282 HMainEditor
.BufferImage
->DiskImage
->Size
,
1283 HMainEditor
.BufferImage
->MemImage
->Offset
,
1284 HMainEditor
.BufferImage
->MemImage
->Size
,
1288 return EFI_NOT_FOUND
;
1295 Load memory content to editor
1297 @retval EFI_SUCCESS The operation was successful.
1298 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1299 @retval EFI_LOAD_ERROR A load error occured.
1300 @retval EFI_NOT_FOUND The disk was not found.
1303 HMainCommandOpenMemory (
1311 EDIT_FILE_TYPE BufferType
;
1314 // variable initialization
1318 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1321 // if current buffer is modified, so you need to choose
1322 // whether to save it first.
1324 if (HMainEditor
.BufferImage
->Modified
) {
1326 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1327 if (EFI_ERROR (Status
)) {
1331 // the answer is just one character
1333 Status
= InputBarSetStringSize (1);
1334 if (EFI_ERROR (Status
)) {
1338 // loop for user's answer
1339 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1343 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1348 if (Status
== EFI_NOT_READY
) {
1352 switch (InputBarGetString()[0]) {
1356 // want to save this buffer first
1358 Status
= HBufferImageSave (
1359 HMainEditor
.BufferImage
->FileImage
->FileName
,
1360 HMainEditor
.BufferImage
->DiskImage
->Name
,
1361 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1362 HMainEditor
.BufferImage
->DiskImage
->Size
,
1363 HMainEditor
.BufferImage
->MemImage
->Offset
,
1364 HMainEditor
.BufferImage
->MemImage
->Size
,
1367 if (EFI_ERROR (Status
)) {
1371 MainTitleBarRefresh (
1372 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1373 HMainEditor
.BufferImage
->BufferType
,
1374 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1376 HMainEditor
.ScreenSize
.Column
,
1377 HMainEditor
.ScreenSize
.Row
,
1378 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1379 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1387 // the file won't be saved
1399 // get starting offset
1401 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1402 if (EFI_ERROR (Status
)) {
1406 Status
= InputBarSetStringSize (8);
1407 if (EFI_ERROR (Status
)) {
1412 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1417 if (Status
== EFI_NOT_READY
) {
1422 // THE input string length should > 0
1424 if (StrLen (InputBarGetString()) > 0) {
1425 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1426 if (EFI_ERROR (Status
)) {
1434 // get Number of Blocks:
1436 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1437 if (EFI_ERROR (Status
)) {
1441 Status
= InputBarSetStringSize (8);
1442 if (EFI_ERROR (Status
)) {
1447 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1452 if (Status
== EFI_NOT_READY
) {
1457 // THE input string length should > 0
1459 if (StrLen (InputBarGetString()) > 0) {
1460 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1461 if (EFI_ERROR (Status
)) {
1473 if ((Offset
+ Size
- 1)> 0xffffffff) {
1474 StatusBarSetStatusString (L
"Invalid parameter");
1475 return EFI_LOAD_ERROR
;
1478 Status
= HBufferImageRead (
1489 if (EFI_ERROR (Status
)) {
1490 StatusBarSetStatusString (L
"Read Device Error!");
1492 HMainEditor
.BufferImage
->FileImage
->FileName
,
1493 HMainEditor
.BufferImage
->DiskImage
->Name
,
1494 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1495 HMainEditor
.BufferImage
->DiskImage
->Size
,
1496 HMainEditor
.BufferImage
->MemImage
->Offset
,
1497 HMainEditor
.BufferImage
->MemImage
->Size
,
1501 return EFI_NOT_FOUND
;
1507 MENU_ITEM_FUNCTION HexMainControlBasedMenuFunctions
[] = {
1509 NULL
, /* Ctrl - A */
1510 NULL
, /* Ctrl - B */
1511 NULL
, /* Ctrl - C */
1512 HMainCommandSelectEnd
, /* Ctrl - D */
1513 HMainCommandDisplayHelp
, /* Ctrl - E */
1514 NULL
, /* Ctrl - F */
1515 HMainCommandGoToOffset
, /* Ctrl - G */
1516 NULL
, /* Ctrl - H */
1517 HMainCommandOpenDisk
, /* Ctrl - I */
1518 NULL
, /* Ctrl - J */
1519 NULL
, /* Ctrl - K */
1520 NULL
, /* Ctrl - L */
1521 HMainCommandOpenMemory
, /* Ctrl - M */
1522 NULL
, /* Ctrl - N */
1523 HMainCommandOpenFile
, /* Ctrl - O */
1524 NULL
, /* Ctrl - P */
1525 HMainCommandExit
, /* Ctrl - Q */
1526 NULL
, /* Ctrl - R */
1527 HMainCommandSaveBuffer
, /* Ctrl - S */
1528 HMainCommandSelectStart
, /* Ctrl - T */
1529 NULL
, /* Ctrl - U */
1530 HMainCommandPaste
, /* Ctrl - V */
1531 NULL
, /* Ctrl - W */
1532 HMainCommandCut
, /* Ctrl - X */
1533 NULL
, /* Ctrl - Y */
1534 NULL
, /* Ctrl - Z */
1537 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1539 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1540 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F1
),
1541 HMainCommandGoToOffset
1544 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1545 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F2
),
1546 HMainCommandSaveBuffer
1549 STRING_TOKEN(STR_EDIT_LIBMENUBAR_EXIT
),
1550 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F3
),
1555 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1556 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F4
),
1557 HMainCommandSelectStart
1560 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1561 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F5
),
1562 HMainCommandSelectEnd
1565 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_CUT
),
1566 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F6
),
1570 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_PASTE
),
1571 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F7
),
1576 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1577 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F8
),
1578 HMainCommandOpenFile
1581 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1582 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9
),
1583 HMainCommandOpenDisk
1586 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1587 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F10
),
1588 HMainCommandOpenMemory
1599 Init function for MainEditor
1601 @retval EFI_SUCCESS The operation was successful.
1602 @retval EFI_LOAD_ERROR A load error occured.
1610 EFI_HANDLE
*HandleBuffer
;
1615 // basic initialization
1617 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1620 // set screen attributes
1622 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1624 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
) (gST
->ConOut
->Mode
->Attribute
>> 4);
1626 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1628 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1631 // query screen size
1633 gST
->ConOut
->QueryMode (
1635 gST
->ConOut
->Mode
->Mode
,
1636 &(HMainEditor
.ScreenSize
.Column
),
1637 &(HMainEditor
.ScreenSize
.Row
)
1641 // Find mouse in System Table ConsoleInHandle
1643 Status
= gBS
->HandleProtocol (
1645 &gEfiSimplePointerProtocolGuid
,
1646 (VOID
**)&HMainEditor
.MouseInterface
1648 if (EFI_ERROR (Status
)) {
1650 // If there is no Simple Pointer Protocol on System Table
1652 HandleBuffer
= NULL
;
1653 HMainEditor
.MouseInterface
= NULL
;
1654 Status
= gBS
->LocateHandleBuffer (
1656 &gEfiSimplePointerProtocolGuid
,
1661 if (!EFI_ERROR (Status
) && HandleCount
> 0) {
1663 // Try to find the first available mouse device
1665 for (Index
= 0; Index
< HandleCount
; Index
++) {
1666 Status
= gBS
->HandleProtocol (
1667 HandleBuffer
[Index
],
1668 &gEfiSimplePointerProtocolGuid
,
1669 (VOID
**)&HMainEditor
.MouseInterface
1671 if (!EFI_ERROR (Status
)) {
1676 if (HandleBuffer
!= NULL
) {
1677 FreePool (HandleBuffer
);
1681 if (!EFI_ERROR (Status
) && HMainEditor
.MouseInterface
!= NULL
) {
1682 HMainEditor
.MouseAccumulatorX
= 0;
1683 HMainEditor
.MouseAccumulatorY
= 0;
1684 HMainEditor
.MouseSupported
= TRUE
;
1688 // below will call the five components' init function
1690 Status
= MainTitleBarInit (NULL
);
1691 if (EFI_ERROR (Status
)) {
1692 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1693 return EFI_LOAD_ERROR
;
1696 Status
= ControlHotKeyInit (HexMainControlBasedMenuFunctions
);
1697 if (EFI_ERROR (Status
)) {
1698 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1699 return EFI_LOAD_ERROR
;
1701 Status
= MenuBarInit (HexEditorMenuItems
);
1702 if (EFI_ERROR (Status
)) {
1703 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1704 return EFI_LOAD_ERROR
;
1707 Status
= StatusBarInit ();
1708 if (EFI_ERROR (Status
)) {
1709 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1710 return EFI_LOAD_ERROR
;
1715 Status
= HBufferImageInit ();
1716 if (EFI_ERROR (Status
)) {
1717 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1718 return EFI_LOAD_ERROR
;
1721 Status
= HClipBoardInit ();
1722 if (EFI_ERROR (Status
)) {
1723 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1724 return EFI_LOAD_ERROR
;
1727 // clear whole screen and enable cursor
1729 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1730 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1733 // initialize EditorFirst and EditorExit
1735 HEditorFirst
= TRUE
;
1736 HEditorExit
= FALSE
;
1737 HEditorMouseAction
= FALSE
;
1743 Cleanup function for MainEditor.
1745 @retval EFI_SUCCESS The operation was successful.
1746 @retval EFI_LOAD_ERROR A load error occured.
1749 HMainEditorCleanup (
1756 // call the five components' cleanup function
1758 MainTitleBarCleanup ();
1762 StatusBarCleanup ();
1766 Status
= HBufferImageCleanup ();
1767 if (EFI_ERROR (Status
)) {
1768 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1771 Status
= HClipBoardCleanup ();
1772 if (EFI_ERROR (Status
)) {
1773 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1778 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1779 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1782 gST
->ConOut
->SetAttribute (
1784 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1786 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1792 Refresh function for MainEditor.
1794 @retval EFI_SUCCESS The operation was successful.
1797 HMainEditorRefresh (
1807 if (HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
) {
1808 if (HMainEditor
.BufferImage
->DiskImage
!= NULL
&&
1809 HBufferImageBackupVar
.DiskImage
!= NULL
&&
1810 (HMainEditor
.BufferImage
->DiskImage
->Offset
!= HBufferImageBackupVar
.DiskImage
->Offset
||
1811 HMainEditor
.BufferImage
->DiskImage
->Size
!= HBufferImageBackupVar
.DiskImage
->Size
) ){
1814 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
) {
1815 if (HMainEditor
.BufferImage
->MemImage
!= NULL
&&
1816 HBufferImageBackupVar
.MemImage
!= NULL
&&
1817 (HMainEditor
.BufferImage
->MemImage
->Offset
!= HBufferImageBackupVar
.MemImage
->Offset
||
1818 HMainEditor
.BufferImage
->MemImage
->Size
!= HBufferImageBackupVar
.MemImage
->Size
) ){
1821 } else if (HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
) {
1822 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1823 HMainEditor
.BufferImage
->FileImage
->FileName
!= NULL
&&
1824 HBufferImageBackupVar
.FileImage
!= NULL
&&
1825 HBufferImageBackupVar
.FileImage
->FileName
!= NULL
&&
1826 StrCmp (HMainEditor
.BufferImage
->FileImage
->FileName
, HBufferImageBackupVar
.FileImage
->FileName
) != 0 ) {
1830 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1831 HBufferImageBackupVar
.FileImage
!= NULL
&&
1832 HMainEditor
.BufferImage
->FileImage
->ReadOnly
!= HBufferImageBackupVar
.FileImage
->ReadOnly
) {
1837 // to aVOID screen flicker
1838 // the stall value is from experience
1843 // call the components refresh function
1847 || HMainEditor
.BufferImage
->BufferType
!= HBufferImageBackupVar
.BufferType
1848 || HBufferImageBackupVar
.Modified
!= HMainEditor
.BufferImage
->Modified
1851 MainTitleBarRefresh (
1852 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
&&HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1853 HMainEditor
.BufferImage
->BufferType
,
1854 (BOOLEAN
)(HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->ReadOnly
:FALSE
),
1855 HMainEditor
.BufferImage
->Modified
,
1856 HMainEditor
.ScreenSize
.Column
,
1857 HMainEditor
.ScreenSize
.Row
,
1858 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
&&HMainEditor
.BufferImage
->MemImage
!=NULL
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1859 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
&&HMainEditor
.BufferImage
->DiskImage
!=NULL
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
&&HMainEditor
.BufferImage
->MemImage
!=NULL
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1861 HBufferImageRefresh ();
1864 || HBufferImageBackupVar
.DisplayPosition
.Row
!= HMainEditor
.BufferImage
->DisplayPosition
.Row
1865 || HBufferImageBackupVar
.DisplayPosition
.Column
!= HMainEditor
.BufferImage
->DisplayPosition
.Column
1866 || StatusBarGetRefresh()) {
1870 HMainEditor
.ScreenSize
.Row
,
1871 HMainEditor
.ScreenSize
.Column
,
1876 HBufferImageRefresh ();
1880 HBufferImageRefresh ();
1884 // EditorFirst is now set to FALSE
1886 HEditorFirst
= FALSE
;
1892 Handle the mouse input.
1894 @param[in] MouseState The current mouse state.
1895 @param[out] BeforeLeftButtonDown helps with selections.
1897 @retval EFI_SUCCESS The operation was successful.
1898 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1899 @retval EFI_LOAD_ERROR A load error occured.
1900 @retval EFI_NOT_FOUND The disk was not found.
1903 HMainEditorHandleMouseInput (
1904 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1905 OUT BOOLEAN
*BeforeLeftButtonDown
1915 HEFI_EDITOR_LINE
*Line
;
1922 // have mouse movement
1924 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1928 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1929 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1931 HBufferImageAdjustMousePosition (TextX
, TextY
);
1937 if (MouseState
.LeftButton
) {
1938 HighBits
= HBufferImageIsAtHighBits (
1939 HMainEditor
.BufferImage
->MousePosition
.Column
,
1944 // not at an movable place
1948 // now just move mouse pointer to legal position
1951 // move mouse position to legal position
1953 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
1954 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
1955 HMainEditor
.BufferImage
->MousePosition
.Column
--;
1956 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1958 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
1959 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1972 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
1973 HMainEditor
.BufferImage
->MousePosition
.Row
-
1974 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1976 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
1981 // now just move mouse pointer to legal position
1983 FRow
= HMainEditor
.BufferImage
->NumLines
;
1987 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1988 for (Index
= 0; Index
< FRow
- 1; Index
++) {
1989 Link
= Link
->ForwardLink
;
1992 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1998 // now just move mouse pointer to legal position
2000 if (FCol
> Line
->Size
) {
2001 if (*BeforeLeftButtonDown
) {
2004 if (Line
->Size
== 0) {
2017 FCol
= Line
->Size
+ 1;
2022 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
2024 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
2026 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
2028 *BeforeLeftButtonDown
= TRUE
;
2033 // else of if LButton
2037 if (*BeforeLeftButtonDown
) {
2043 *BeforeLeftButtonDown
= FALSE
;
2050 return EFI_NOT_FOUND
;
2054 Handle user key input. will route it to other components handle function.
2056 @retval EFI_SUCCESS The operation was successful.
2057 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
2058 @retval EFI_LOAD_ERROR A load error occured.
2061 HMainEditorKeyInput (
2067 EFI_SIMPLE_POINTER_STATE MouseState
;
2068 BOOLEAN LengthChange
;
2071 BOOLEAN BeforeMouseIsDown
;
2072 BOOLEAN MouseIsDown
;
2077 UINTN SelectStartBackup
;
2078 UINTN SelectEndBackup
;
2081 // variable initialization
2086 LengthChange
= FALSE
;
2088 MouseIsDown
= FALSE
;
2094 Status
= EFI_SUCCESS
;
2096 HEditorMouseAction
= FALSE
;
2099 // backup some key elements, so that can aVOID some refresh work
2101 HMainEditorBackup ();
2104 // wait for user key input
2107 // change priority of checking mouse/keyboard activity dynamically
2108 // so prevent starvation of keyboard.
2109 // if last time, mouse moves then this time check keyboard
2111 if (HMainEditor
.MouseSupported
) {
2112 Status
= HMainEditor
.MouseInterface
->GetState (
2113 HMainEditor
.MouseInterface
,
2116 if (!EFI_ERROR (Status
)) {
2118 BeforeMouseIsDown
= MouseIsDown
;
2120 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2122 if (!EFI_ERROR (Status
)) {
2123 if (!BeforeMouseIsDown
) {
2128 FRow
= HBufferImage
.BufferPosition
.Row
;
2129 FCol
= HBufferImage
.BufferPosition
.Column
;
2130 SelectStartBackup
= HMainEditor
.SelectStart
;
2131 SelectEndBackup
= HMainEditor
.SelectEnd
;
2137 SelectStartBackup
= HMainEditor
.SelectStart
;
2138 SelectEndBackup
= HMainEditor
.SelectEnd
;
2145 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2146 HMainEditor
.SelectStart
= 0;
2147 HMainEditor
.SelectEnd
= 0;
2148 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2155 (HBufferImage
.BufferPosition
.Row
- 1) *
2157 HBufferImage
.BufferPosition
.Column
2158 ) >= HMainEditor
.SelectStart
2160 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2162 HBufferImage
.BufferPosition
.Column
;
2164 HMainEditor
.SelectEnd
= 0;
2168 // end of if RelativeX/Y
2175 if (HBufferImageGetTotalSize () == 0) {
2176 HMainEditor
.SelectStart
= 0;
2177 HMainEditor
.SelectEnd
= 0;
2183 (HBufferImage
.BufferPosition
.Row
- 1) *
2185 HBufferImage
.BufferPosition
.Column
2186 ) >= HMainEditor
.SelectStart
2188 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2190 HBufferImage
.BufferPosition
.Column
;
2192 HMainEditor
.SelectEnd
= 0;
2195 if (HMainEditor
.SelectEnd
== 0) {
2196 HMainEditor
.SelectStart
= 0;
2204 if (SelectStartBackup
!= HMainEditor
.SelectStart
|| SelectEndBackup
!= HMainEditor
.SelectEnd
) {
2205 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2206 HBufferImageNeedRefresh
= TRUE
;
2208 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2209 HBufferImageNeedRefresh
= TRUE
;
2211 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2217 HEditorMouseAction
= TRUE
;
2218 HBufferImageMouseNeedRefresh
= TRUE
;
2220 } else if (Status
== EFI_LOAD_ERROR
) {
2221 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2226 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2227 if (!EFI_ERROR (Status
)) {
2229 // dispatch to different components' key handling function
2230 // so not everywhere has to set this variable
2232 HBufferImageMouseNeedRefresh
= TRUE
;
2235 // clear previous status string
2237 StatusBarSetRefresh();
2238 if (EFI_SUCCESS
== MenuBarDispatchControlHotKey(&Key
)) {
2239 Status
= EFI_SUCCESS
;
2240 } else if (Key
.ScanCode
== SCAN_NULL
) {
2241 Status
= HBufferImageHandleInput (&Key
);
2242 } else if (((Key
.ScanCode
>= SCAN_UP
) && (Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2243 Status
= HBufferImageHandleInput (&Key
);
2244 } else if (((Key
.ScanCode
>= SCAN_F1
) && Key
.ScanCode
<= (SCAN_F12
))) {
2245 Status
= MenuBarDispatchFunctionKey (&Key
);
2247 StatusBarSetStatusString (L
"Unknown Command");
2249 HBufferImageMouseNeedRefresh
= FALSE
;
2252 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_OUT_OF_RESOURCES
) {
2254 // not already has some error status
2256 if (StrCmp (L
"", StatusBarGetString()) == 0) {
2257 StatusBarSetStatusString (L
"Disk Error. Try Again");
2262 // decide if has to set length warning
2264 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2265 LengthChange
= FALSE
;
2268 // still the old buffer
2270 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2271 Size
= HBufferImageGetTotalSize ();
2273 switch (HBufferImage
.BufferType
) {
2274 case FileTypeDiskBuffer
:
2275 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2278 case FileTypeMemBuffer
:
2279 OldSize
= HBufferImage
.MemImage
->Size
;
2287 if (!LengthChange
) {
2288 if (OldSize
!= Size
) {
2289 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2293 if (OldSize
!= Size
) {
2294 LengthChange
= TRUE
;
2296 LengthChange
= FALSE
;
2301 // after handling, refresh editor
2303 HMainEditorRefresh ();
2305 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2311 Backup function for MainEditor.
2319 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2320 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2321 HBufferImageBackup ();