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 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
= {
69 Move cursor to specified lines.
71 @retval EFI_SUCCESS The operation was successful.
74 HMainCommandGoToOffset (
85 // variable initialization
95 Status
= InputBarSetPrompt (L
"Go To Offset: ");
96 if (EFI_ERROR (Status
)) {
100 Status
= InputBarSetStringSize (8);
101 if (EFI_ERROR (Status
)) {
106 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
111 if (Status
== EFI_NOT_READY
) {
116 // THE input string length should > 0
118 if (StrLen (InputBarGetString()) > 0) {
119 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
120 if (EFI_ERROR (Status
)) {
121 StatusBarSetStatusString (L
"Invalid Offset");
129 Size
= HBufferImageGetTotalSize ();
130 if (Offset
>= Size
) {
131 StatusBarSetStatusString (L
"Invalid Offset");
135 FRow
= (UINTN
)DivU64x32(Offset
, 0x10) + 1;
136 FCol
= (UINTN
)ModU64x32(Offset
, 0x10) + 1;
138 HBufferImageMovePosition (FRow
, FCol
, TRUE
);
140 HBufferImageNeedRefresh
= TRUE
;
141 HBufferImageOnlyLineNeedRefresh
= FALSE
;
142 HBufferImageMouseNeedRefresh
= TRUE
;
148 Save current opened buffer.
149 If is file buffer, you can save to current file name or
150 save to another file name.
152 @retval EFI_SUCCESS The operation was successful.
153 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
154 @retval EFI_LOAD_ERROR A load error occured.
157 HMainCommandSaveBuffer (
167 SHELL_FILE_HANDLE ShellFileHandle
;
169 if (HMainEditor
.BufferImage
->BufferType
!= FileTypeFileBuffer
) {
170 if (!HMainEditor
.BufferImage
->Modified
) {
174 Status
= InputBarSetPrompt (L
"Dangerous to save disk/mem buffer. Save (Yes/No/Cancel) ? ");
175 if (EFI_ERROR (Status
)) {
179 // the answer is just one character
181 Status
= InputBarSetStringSize (1);
182 if (EFI_ERROR (Status
)) {
186 // loop for user's answer
187 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
190 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
195 if (Status
== EFI_NOT_READY
) {
199 switch (InputBarGetString()[0]) {
203 // want to save this buffer first
205 Status
= HBufferImageSave (
207 HMainEditor
.BufferImage
->DiskImage
->Name
,
208 HMainEditor
.BufferImage
->DiskImage
->Offset
,
209 HMainEditor
.BufferImage
->DiskImage
->Size
,
210 HMainEditor
.BufferImage
->MemImage
->Offset
,
211 HMainEditor
.BufferImage
->MemImage
->Size
,
212 HMainEditor
.BufferImage
->BufferType
215 if (EFI_ERROR (Status
)) {
216 StatusBarSetStatusString (L
"BufferSave: Problems Writing");
225 // the file won't be saved
243 // ENDOF != FILEBUFFER
245 // This command will save currently opened file to disk.
246 // You can choose save to another file name or just save to
247 // current file name.
248 // Below is the scenario of Save File command: (
249 // Suppose the old file name is A )
250 // 1. An Input Bar will be prompted: "File To Save: [ old file name]"
251 // IF user press ESC, Save File command ends .
252 // IF user press Enter, input file name will be A.
253 // IF user inputs a new file name B, input file name will be B.
255 // 2. IF input file name is A, go to do Step 3.
256 // IF input file name is B, go to do Step 4.
258 // 3. IF A is read only, Status Bar will show "Access Denied"
259 // and Save File commands ends.
260 // IF A is not read only, save file buffer to disk
261 // and remove Modified flag in Title Bar , then Save File command ends.
263 // 4. IF B does not exist, create this file and save file buffer to it.
265 // IF B exits, do Step 5.
267 // 5. An Input Bar will be prompted:
268 // "File Exists. Overwrite ( Yes/No/Cancel ) ?"
269 // IF user press 'y' or 'Y', do Step 6.
270 // IF user press 'n' or 'N', Save File commands ends.
271 // IF user press 'c' or 'C' or ESC, Save File commands ends.
273 // 6. IF B is a read-only file, Status Bar will show "Access Denied"
274 // and Save File commands ends.
275 // IF B can be read and write, save file buffer to B.
277 // 7. Update File Name field in Title Bar to B
278 // and remove the Modified flag in Title Bar.
280 Str
= CatSPrint(NULL
,
281 L
"File to Save: [%s]",
282 HMainEditor
.BufferImage
->FileImage
->FileName
285 return EFI_OUT_OF_RESOURCES
;
288 if (StrLen (Str
) >= 50) {
290 // replace the long file name with "..."
299 Status
= InputBarSetPrompt (Str
);
300 if (EFI_ERROR (Status
)) {
304 Status
= InputBarSetStringSize (100);
305 if (EFI_ERROR (Status
)) {
311 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
314 // if user pressed ESC
316 if (Status
== EFI_NOT_READY
) {
317 SHELL_FREE_NON_NULL (Str
);
321 SHELL_FREE_NON_NULL (Str
);
324 // if just enter pressed, so think save to current file name
326 if (StrLen (InputBarGetString()) == 0) {
327 FileName
= CatSPrint(NULL
,
329 HMainEditor
.BufferImage
->FileImage
->FileName
332 FileName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
335 if (FileName
== NULL
) {
336 return EFI_OUT_OF_RESOURCES
;
339 if (!IsValidFileName (FileName
)) {
340 StatusBarSetStatusString (L
"Invalid File Name");
341 SHELL_FREE_NON_NULL (FileName
);
348 // save to the old file
350 if (StringNoCaseCompare (
352 &HMainEditor
.BufferImage
->FileImage
->FileName
359 // if the file is read only, so can not write back to it.
361 if (HMainEditor
.BufferImage
->FileImage
->ReadOnly
) {
362 StatusBarSetStatusString (L
"Access Denied");
363 SHELL_FREE_NON_NULL (FileName
);
367 Status
= ShellOpenFileByName (FileName
, &ShellFileHandle
, EFI_FILE_MODE_READ
, 0);
369 if (!EFI_ERROR (Status
)) {
371 Info
= ShellGetFileInfo(ShellFileHandle
);
373 ShellCloseFile(&ShellFileHandle
);
375 // check if read only
377 if (Info
->Attribute
& EFI_FILE_READ_ONLY
) {
378 StatusBarSetStatusString (L
"Access Denied");
379 SHELL_FREE_NON_NULL (FileName
);
383 SHELL_FREE_NON_NULL(Info
);
385 // ask user whether to overwrite this file
387 Status
= InputBarSetPrompt (L
"File exists. Overwrite (Yes/No/Cancel) ? ");
388 if (EFI_ERROR (Status
)) {
389 SHELL_FREE_NON_NULL (FileName
);
393 Status
= InputBarSetStringSize (1);
394 if (EFI_ERROR (Status
)) {
395 SHELL_FREE_NON_NULL (FileName
);
401 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
403 if (Status
== EFI_NOT_READY
) {
404 SHELL_FREE_NON_NULL (FileName
);
408 switch (InputBarGetString()[0]) {
415 SHELL_FREE_NON_NULL (FileName
);
419 SHELL_FREE_NON_NULL (FileName
);
423 } // if opened existing file
427 // save file back to disk
429 Status
= HBufferImageSave (
431 HMainEditor
.BufferImage
->DiskImage
->Name
,
432 HMainEditor
.BufferImage
->DiskImage
->Offset
,
433 HMainEditor
.BufferImage
->DiskImage
->Size
,
434 HMainEditor
.BufferImage
->MemImage
->Offset
,
435 HMainEditor
.BufferImage
->MemImage
->Size
,
438 SHELL_FREE_NON_NULL (FileName
);
440 if (EFI_ERROR (Status
)) {
441 return EFI_LOAD_ERROR
;
448 Load a disk buffer editor.
450 @retval EFI_SUCCESS The operation was successful.
451 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
452 @retval EFI_LOAD_ERROR A load error occured.
455 HMainCommandSelectStart (
461 Start
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
466 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
467 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
468 StatusBarSetStatusString (L
"Invalid Block Start");
469 return EFI_LOAD_ERROR
;
473 if (HMainEditor
.SelectEnd
!= 0 && Start
> HMainEditor
.SelectEnd
) {
474 StatusBarSetStatusString (L
"Invalid Block Start");
475 return EFI_LOAD_ERROR
;
478 HMainEditor
.SelectStart
= Start
;
480 HBufferImageNeedRefresh
= TRUE
;
486 Load a disk buffer editor.
488 @retval EFI_SUCCESS The operation was successful.
489 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
490 @retval EFI_LOAD_ERROR A load error occured.
493 HMainCommandSelectEnd (
499 End
= (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) * 0x10 + HMainEditor
.BufferImage
->BufferPosition
.Column
;
504 if (HMainEditor
.BufferImage
->CurrentLine
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
505 if (HMainEditor
.BufferImage
->BufferPosition
.Column
> HMainEditor
.BufferImage
->CurrentLine
->Size
) {
506 StatusBarSetStatusString (L
"Invalid Block End");
507 return EFI_LOAD_ERROR
;
511 if (HMainEditor
.SelectStart
!= 0 && End
< HMainEditor
.SelectStart
) {
512 StatusBarSetStatusString (L
"Invalid Block End");
516 HMainEditor
.SelectEnd
= End
;
518 HBufferImageNeedRefresh
= TRUE
;
524 Cut current line to clipboard.
526 @retval EFI_SUCCESS The operation was successful.
527 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
528 @retval EFI_LOAD_ERROR A load error occured.
536 HEFI_EDITOR_LINE
*Line
;
542 // not select, so not allowed to cut
544 if (HMainEditor
.SelectStart
== 0) {
545 StatusBarSetStatusString (L
"No Block is Selected");
549 // not select, so not allowed to cut
551 if (HMainEditor
.SelectEnd
== 0) {
552 StatusBarSetStatusString (L
"No Block is Selected");
556 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
557 for (Index
= 0; Index
< (HMainEditor
.SelectEnd
- 1) / 0x10; Index
++) {
558 Link
= Link
->ForwardLink
;
561 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
563 Count
= HMainEditor
.SelectEnd
- HMainEditor
.SelectStart
+ 1;
564 Buffer
= AllocateZeroPool (Count
);
565 if (Buffer
== NULL
) {
566 return EFI_OUT_OF_RESOURCES
;
569 // cut the selected area
571 HBufferImageDeleteCharacterFromBuffer (
572 HMainEditor
.SelectStart
- 1,
580 HClipBoardSet (Buffer
, Count
);
582 HBufferImageNeedRefresh
= TRUE
;
583 HBufferImageOnlyLineNeedRefresh
= FALSE
;
585 if (!HMainEditor
.BufferImage
->Modified
) {
586 HMainEditor
.BufferImage
->Modified
= TRUE
;
590 // now no select area
592 HMainEditor
.SelectStart
= 0;
593 HMainEditor
.SelectEnd
= 0;
599 Paste line to file buffer.
601 @retval EFI_SUCCESS The operation was successful.
602 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
603 @retval EFI_LOAD_ERROR A load error occured.
611 BOOLEAN OnlyLineRefresh
;
612 HEFI_EDITOR_LINE
*Line
;
617 Count
= HClipBoardGet (&Buffer
);
618 if (Count
== 0 || Buffer
== NULL
) {
619 StatusBarSetStatusString (L
"Nothing to Paste");
623 Line
= HMainEditor
.BufferImage
->CurrentLine
;
625 OnlyLineRefresh
= FALSE
;
626 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
&& Line
->Size
+ Count
< 0x10) {
628 // is at last line, and after paste will not exceed
629 // so only this line need to be refreshed
631 // if after add, the line is 0x10, then will append a new line
632 // so the whole page will need be refreshed
634 OnlyLineRefresh
= TRUE
;
638 FPos
= 0x10 * (HMainEditor
.BufferImage
->BufferPosition
.Row
- 1) + HMainEditor
.BufferImage
->BufferPosition
.Column
- 1;
640 HBufferImageAddCharacterToBuffer (FPos
, Count
, Buffer
);
642 if (OnlyLineRefresh
) {
643 HBufferImageNeedRefresh
= FALSE
;
644 HBufferImageOnlyLineNeedRefresh
= TRUE
;
646 HBufferImageNeedRefresh
= TRUE
;
647 HBufferImageOnlyLineNeedRefresh
= FALSE
;
650 if (!HMainEditor
.BufferImage
->Modified
) {
651 HMainEditor
.BufferImage
->Modified
= TRUE
;
661 @retval EFI_SUCCESS The operation was successful.
662 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
663 @retval EFI_LOAD_ERROR A load error occured.
673 // Below is the scenario of Exit command:
674 // 1. IF currently opened file is not modified, exit the editor and
675 // Exit command ends.
676 // IF currently opened file is modified, do Step 2
678 // 2. An Input Bar will be prompted:
679 // "File modified. Save ( Yes/No/Cancel )?"
680 // IF user press 'y' or 'Y', currently opened file will be saved and
682 // IF user press 'n' or 'N', currently opened file will not be saved
684 // IF user press 'c' or 'C' or ESC, Exit command ends.
687 // if file has been modified, so will prompt user
688 // whether to save the changes
690 if (HMainEditor
.BufferImage
->Modified
) {
692 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
693 if (EFI_ERROR (Status
)) {
697 Status
= InputBarSetStringSize (1);
698 if (EFI_ERROR (Status
)) {
703 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
708 if (Status
== EFI_NOT_READY
) {
712 switch (InputBarGetString()[0]) {
716 // write file back to disk
718 Status
= HBufferImageSave (
719 HMainEditor
.BufferImage
->FileImage
->FileName
,
720 HMainEditor
.BufferImage
->DiskImage
->Name
,
721 HMainEditor
.BufferImage
->DiskImage
->Offset
,
722 HMainEditor
.BufferImage
->DiskImage
->Size
,
723 HMainEditor
.BufferImage
->MemImage
->Offset
,
724 HMainEditor
.BufferImage
->MemImage
->Size
,
725 HMainEditor
.BufferImage
->BufferType
727 if (!EFI_ERROR (Status
)) {
752 Load a file from disk to editor.
754 @retval EFI_SUCCESS The operation was successful.
755 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
756 @retval EFI_LOAD_ERROR A load error occured.
759 HMainCommandOpenFile (
765 EDIT_FILE_TYPE BufferType
;
767 BufferType
= HMainEditor
.BufferImage
->BufferType
;
770 // This command will open a file from current working directory.
771 // Read-only file can also be opened. But it can not be modified.
772 // Below is the scenario of Open File command:
773 // 1. IF currently opened file has not been modified, directly go to step .
774 // IF currently opened file has been modified, an Input Bar will be
776 // "File Modified. Save ( Yes/No/Cancel) ?"
777 // IF user press 'y' or 'Y', currently opened file will be saved.
778 // IF user press 'n' or 'N', currently opened file will
780 // IF user press 'c' or 'C' or ESC, Open File command ends and
781 // currently opened file is still opened.
783 // 2. An Input Bar will be prompted as : "File Name to Open: "
784 // IF user press ESC, Open File command ends and
785 // currently opened file is still opened.
786 // Any other inputs with a Return will cause
787 // currently opened file close.
789 // 3. IF user input file name is an existing file ,
790 // this file will be read and opened.
791 // IF user input file name is a new file, this file will be created
792 // and opened. This file's type ( UNICODE or ASCII ) is the same with
796 // if current file is modified, so you need to choose whether to
799 if (HMainEditor
.BufferImage
->Modified
) {
801 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
802 if (EFI_ERROR (Status
)) {
806 // the answer is just one character
808 Status
= InputBarSetStringSize (1);
809 if (EFI_ERROR (Status
)) {
813 // loop for user's answer
814 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
818 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
823 if (Status
== EFI_NOT_READY
) {
827 switch (InputBarGetString()[0]) {
831 // want to save this buffer first
833 Status
= HBufferImageSave (
834 HMainEditor
.BufferImage
->FileImage
->FileName
,
835 HMainEditor
.BufferImage
->DiskImage
->Name
,
836 HMainEditor
.BufferImage
->DiskImage
->Offset
,
837 HMainEditor
.BufferImage
->DiskImage
->Size
,
838 HMainEditor
.BufferImage
->MemImage
->Offset
,
839 HMainEditor
.BufferImage
->MemImage
->Size
,
840 HMainEditor
.BufferImage
->BufferType
842 if (EFI_ERROR (Status
)) {
846 MainTitleBarRefresh (
847 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
848 HMainEditor
.BufferImage
->BufferType
,
849 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
851 HMainEditor
.ScreenSize
.Column
,
852 HMainEditor
.ScreenSize
.Row
,
853 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
854 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
862 // the file won't be saved
874 // TO get the open file name
876 Status
= InputBarSetPrompt (L
"File Name to Open: ");
877 if (EFI_ERROR (Status
)) {
879 HMainEditor
.BufferImage
->FileImage
->FileName
,
880 HMainEditor
.BufferImage
->DiskImage
->Name
,
881 HMainEditor
.BufferImage
->DiskImage
->Offset
,
882 HMainEditor
.BufferImage
->DiskImage
->Size
,
883 HMainEditor
.BufferImage
->MemImage
->Offset
,
884 HMainEditor
.BufferImage
->MemImage
->Size
,
891 Status
= InputBarSetStringSize (100);
892 if (EFI_ERROR (Status
)) {
893 Status
= HBufferImageRead (
894 HMainEditor
.BufferImage
->FileImage
->FileName
,
895 HMainEditor
.BufferImage
->DiskImage
->Name
,
896 HMainEditor
.BufferImage
->DiskImage
->Offset
,
897 HMainEditor
.BufferImage
->DiskImage
->Size
,
898 HMainEditor
.BufferImage
->MemImage
->Offset
,
899 HMainEditor
.BufferImage
->MemImage
->Size
,
907 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
912 if (Status
== EFI_NOT_READY
) {
913 Status
= HBufferImageRead (
914 HMainEditor
.BufferImage
->FileImage
->FileName
,
915 HMainEditor
.BufferImage
->DiskImage
->Name
,
916 HMainEditor
.BufferImage
->DiskImage
->Offset
,
917 HMainEditor
.BufferImage
->DiskImage
->Size
,
918 HMainEditor
.BufferImage
->MemImage
->Offset
,
919 HMainEditor
.BufferImage
->MemImage
->Size
,
927 // THE input string length should > 0
929 if (StrLen (InputBarGetString()) > 0) {
931 // CHECK if filename's valid
933 if (!IsValidFileName (InputBarGetString())) {
935 HMainEditor
.BufferImage
->FileImage
->FileName
,
936 HMainEditor
.BufferImage
->DiskImage
->Name
,
937 HMainEditor
.BufferImage
->DiskImage
->Offset
,
938 HMainEditor
.BufferImage
->DiskImage
->Size
,
939 HMainEditor
.BufferImage
->MemImage
->Offset
,
940 HMainEditor
.BufferImage
->MemImage
->Size
,
945 StatusBarSetStatusString (L
"Invalid File Name");
955 Status
= HBufferImageRead (
957 HMainEditor
.BufferImage
->DiskImage
->Name
,
958 HMainEditor
.BufferImage
->DiskImage
->Offset
,
959 HMainEditor
.BufferImage
->DiskImage
->Size
,
960 HMainEditor
.BufferImage
->MemImage
->Offset
,
961 HMainEditor
.BufferImage
->MemImage
->Size
,
966 if (EFI_ERROR (Status
)) {
968 HMainEditor
.BufferImage
->FileImage
->FileName
,
969 HMainEditor
.BufferImage
->DiskImage
->Name
,
970 HMainEditor
.BufferImage
->DiskImage
->Offset
,
971 HMainEditor
.BufferImage
->DiskImage
->Size
,
972 HMainEditor
.BufferImage
->MemImage
->Offset
,
973 HMainEditor
.BufferImage
->MemImage
->Size
,
978 return EFI_LOAD_ERROR
;
985 Load a disk buffer editor.
987 @retval EFI_SUCCESS The operation was successful.
988 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
989 @retval EFI_LOAD_ERROR A load error occured.
990 @retval EFI_NOT_FOUND The disk was not found.
993 HMainCommandOpenDisk (
1003 EDIT_FILE_TYPE BufferType
;
1006 // variable initialization
1010 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1013 // if current file is modified, so you need to choose
1014 // whether to save it first.
1016 if (HMainEditor
.BufferImage
->Modified
) {
1018 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1019 if (EFI_ERROR (Status
)) {
1023 // the answer is just one character
1025 Status
= InputBarSetStringSize (1);
1026 if (EFI_ERROR (Status
)) {
1030 // loop for user's answer
1031 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1035 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1040 if (Status
== EFI_NOT_READY
) {
1044 switch (InputBarGetString()[0]) {
1048 // want to save this buffer first
1050 Status
= HBufferImageSave (
1051 HMainEditor
.BufferImage
->FileImage
->FileName
,
1052 HMainEditor
.BufferImage
->DiskImage
->Name
,
1053 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1054 HMainEditor
.BufferImage
->DiskImage
->Size
,
1055 HMainEditor
.BufferImage
->MemImage
->Offset
,
1056 HMainEditor
.BufferImage
->MemImage
->Size
,
1059 if (EFI_ERROR (Status
)) {
1063 MainTitleBarRefresh (
1064 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1065 HMainEditor
.BufferImage
->BufferType
,
1066 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1068 HMainEditor
.ScreenSize
.Column
,
1069 HMainEditor
.ScreenSize
.Row
,
1070 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1071 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1079 // the file won't be saved
1091 // get disk block device name
1093 Status
= InputBarSetPrompt (L
"Block Device to Open: ");
1094 if (EFI_ERROR (Status
)) {
1098 Status
= InputBarSetStringSize (100);
1099 if (EFI_ERROR (Status
)) {
1104 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1109 if (Status
== EFI_NOT_READY
) {
1114 // THE input string length should > 0
1116 if (StrLen (InputBarGetString()) > 0) {
1121 DeviceName
= CatSPrint(NULL
, L
"%s", InputBarGetString());
1122 if (DeviceName
== NULL
) {
1123 return EFI_OUT_OF_RESOURCES
;
1126 // get starting offset
1128 Status
= InputBarSetPrompt (L
"First Block No.: ");
1129 if (EFI_ERROR (Status
)) {
1133 Status
= InputBarSetStringSize (16);
1134 if (EFI_ERROR (Status
)) {
1139 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1144 if (Status
== EFI_NOT_READY
) {
1149 // THE input string length should > 0
1151 if (StrLen (InputBarGetString()) > 0) {
1152 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1153 if (EFI_ERROR (Status
)) {
1161 // get Number of Blocks:
1163 Status
= InputBarSetPrompt (L
"Number of Blocks: ");
1164 if (EFI_ERROR (Status
)) {
1168 Status
= InputBarSetStringSize (8);
1169 if (EFI_ERROR (Status
)) {
1174 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1179 if (Status
== EFI_NOT_READY
) {
1184 // THE input string length should > 0
1186 if (StrLen (InputBarGetString()) > 0) {
1187 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1188 if (EFI_ERROR (Status
)) {
1200 Status
= HBufferImageRead (
1211 if (EFI_ERROR (Status
)) {
1214 HMainEditor
.BufferImage
->FileImage
->FileName
,
1215 HMainEditor
.BufferImage
->DiskImage
->Name
,
1216 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1217 HMainEditor
.BufferImage
->DiskImage
->Size
,
1218 HMainEditor
.BufferImage
->MemImage
->Offset
,
1219 HMainEditor
.BufferImage
->MemImage
->Size
,
1223 return EFI_NOT_FOUND
;
1230 Load memory content to editor
1232 @retval EFI_SUCCESS The operation was successful.
1233 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1234 @retval EFI_LOAD_ERROR A load error occured.
1235 @retval EFI_NOT_FOUND The disk was not found.
1238 HMainCommandOpenMemory (
1246 EDIT_FILE_TYPE BufferType
;
1249 // variable initialization
1253 BufferType
= HMainEditor
.BufferImage
->BufferType
;
1256 // if current buffer is modified, so you need to choose
1257 // whether to save it first.
1259 if (HMainEditor
.BufferImage
->Modified
) {
1261 Status
= InputBarSetPrompt (L
"Buffer modified. Save (Yes/No/Cancel) ? ");
1262 if (EFI_ERROR (Status
)) {
1266 // the answer is just one character
1268 Status
= InputBarSetStringSize (1);
1269 if (EFI_ERROR (Status
)) {
1273 // loop for user's answer
1274 // valid answer is just 'y' 'Y', 'n' 'N', 'c' 'C'
1278 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1283 if (Status
== EFI_NOT_READY
) {
1287 switch (InputBarGetString()[0]) {
1291 // want to save this buffer first
1293 Status
= HBufferImageSave (
1294 HMainEditor
.BufferImage
->FileImage
->FileName
,
1295 HMainEditor
.BufferImage
->DiskImage
->Name
,
1296 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1297 HMainEditor
.BufferImage
->DiskImage
->Size
,
1298 HMainEditor
.BufferImage
->MemImage
->Offset
,
1299 HMainEditor
.BufferImage
->MemImage
->Size
,
1302 if (EFI_ERROR (Status
)) {
1306 MainTitleBarRefresh (
1307 HMainEditor
.BufferImage
->BufferType
== FileTypeFileBuffer
?HMainEditor
.BufferImage
->FileImage
->FileName
:HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Name
:NULL
,
1308 HMainEditor
.BufferImage
->BufferType
,
1309 HMainEditor
.BufferImage
->FileImage
->ReadOnly
,
1311 HMainEditor
.ScreenSize
.Column
,
1312 HMainEditor
.ScreenSize
.Row
,
1313 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Offset
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Offset
:0,
1314 HMainEditor
.BufferImage
->BufferType
== FileTypeDiskBuffer
?HMainEditor
.BufferImage
->DiskImage
->Size
:HMainEditor
.BufferImage
->BufferType
== FileTypeMemBuffer
?HMainEditor
.BufferImage
->MemImage
->Size
:0
1322 // the file won't be saved
1334 // get starting offset
1336 Status
= InputBarSetPrompt (L
"Starting Offset: ");
1337 if (EFI_ERROR (Status
)) {
1341 Status
= InputBarSetStringSize (8);
1342 if (EFI_ERROR (Status
)) {
1347 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1352 if (Status
== EFI_NOT_READY
) {
1357 // THE input string length should > 0
1359 if (StrLen (InputBarGetString()) > 0) {
1360 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Offset
, TRUE
, FALSE
);
1361 if (EFI_ERROR (Status
)) {
1369 // get Number of Blocks:
1371 Status
= InputBarSetPrompt (L
"Buffer Size: ");
1372 if (EFI_ERROR (Status
)) {
1376 Status
= InputBarSetStringSize (8);
1377 if (EFI_ERROR (Status
)) {
1382 Status
= InputBarRefresh (HMainEditor
.ScreenSize
.Row
, HMainEditor
.ScreenSize
.Column
);
1387 if (Status
== EFI_NOT_READY
) {
1392 // THE input string length should > 0
1394 if (StrLen (InputBarGetString()) > 0) {
1395 Status
= ShellConvertStringToUint64 (InputBarGetString(), &Size
, TRUE
, FALSE
);
1396 if (EFI_ERROR (Status
)) {
1408 if ((Offset
+ Size
- 1)> 0xffffffff) {
1409 StatusBarSetStatusString (L
"Invalid parameter");
1410 return EFI_LOAD_ERROR
;
1413 Status
= HBufferImageRead (
1424 if (EFI_ERROR (Status
)) {
1425 StatusBarSetStatusString (L
"Read Device Error!");
1427 HMainEditor
.BufferImage
->FileImage
->FileName
,
1428 HMainEditor
.BufferImage
->DiskImage
->Name
,
1429 HMainEditor
.BufferImage
->DiskImage
->Offset
,
1430 HMainEditor
.BufferImage
->DiskImage
->Size
,
1431 HMainEditor
.BufferImage
->MemImage
->Offset
,
1432 HMainEditor
.BufferImage
->MemImage
->Size
,
1436 return EFI_NOT_FOUND
;
1442 CONST EDITOR_MENU_ITEM HexEditorMenuItems
[] = {
1444 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_GO_TO_OFFSET
),
1445 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F1
),
1446 HMainCommandGoToOffset
1449 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SAVE_BUFFER
),
1450 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F2
),
1451 HMainCommandSaveBuffer
1454 STRING_TOKEN(STR_EDIT_LIBMENUBAR_EXIT
),
1455 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F3
),
1460 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_START
),
1461 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F4
),
1462 HMainCommandSelectStart
1465 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_SELECT_END
),
1466 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F5
),
1467 HMainCommandSelectEnd
1470 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_CUT
),
1471 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F6
),
1475 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_PASTE
),
1476 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F7
),
1481 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_FILE
),
1482 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F8
),
1483 HMainCommandOpenFile
1486 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_DISK
),
1487 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F9
),
1488 HMainCommandOpenDisk
1491 STRING_TOKEN(STR_HEXEDIT_LIBMENUBAR_OPEN_MEMORY
),
1492 STRING_TOKEN(STR_EDIT_LIBMENUBAR_F10
),
1493 HMainCommandOpenMemory
1504 Init function for MainEditor
1506 @retval EFI_SUCCESS The operation was successful.
1507 @retval EFI_LOAD_ERROR A load error occured.
1515 EFI_HANDLE
*HandleBuffer
;
1520 // basic initialization
1522 CopyMem (&HMainEditor
, &HMainEditorConst
, sizeof (HMainEditor
));
1525 // set screen attributes
1527 HMainEditor
.ColorAttributes
.Colors
.Foreground
= gST
->ConOut
->Mode
->Attribute
& 0x000000ff;
1529 HMainEditor
.ColorAttributes
.Colors
.Background
= (UINT8
) (gST
->ConOut
->Mode
->Attribute
>> 4);
1531 HOriginalColors
= HMainEditor
.ColorAttributes
.Colors
;
1533 HOriginalMode
= gST
->ConOut
->Mode
->Mode
;
1536 // query screen size
1538 gST
->ConOut
->QueryMode (
1540 gST
->ConOut
->Mode
->Mode
,
1541 &(HMainEditor
.ScreenSize
.Column
),
1542 &(HMainEditor
.ScreenSize
.Row
)
1546 // Find mouse in System Table ConsoleInHandle
1548 Status
= gBS
->HandleProtocol (
1550 &gEfiSimplePointerProtocolGuid
,
1551 (VOID
**)&HMainEditor
.MouseInterface
1553 if (EFI_ERROR (Status
)) {
1555 // If there is no Simple Pointer Protocol on System Table
1557 HandleBuffer
= NULL
;
1558 HMainEditor
.MouseInterface
= NULL
;
1559 Status
= gBS
->LocateHandleBuffer (
1561 &gEfiSimplePointerProtocolGuid
,
1566 if (!EFI_ERROR (Status
) && HandleCount
> 0) {
1568 // Try to find the first available mouse device
1570 for (Index
= 0; Index
< HandleCount
; Index
++) {
1571 Status
= gBS
->HandleProtocol (
1572 HandleBuffer
[Index
],
1573 &gEfiSimplePointerProtocolGuid
,
1574 (VOID
**)&HMainEditor
.MouseInterface
1576 if (!EFI_ERROR (Status
)) {
1581 if (HandleBuffer
!= NULL
) {
1582 FreePool (HandleBuffer
);
1586 if (!EFI_ERROR (Status
) && HMainEditor
.MouseInterface
!= NULL
) {
1587 HMainEditor
.MouseAccumulatorX
= 0;
1588 HMainEditor
.MouseAccumulatorY
= 0;
1589 HMainEditor
.MouseSupported
= TRUE
;
1593 // below will call the five components' init function
1595 Status
= MainTitleBarInit (NULL
);
1596 if (EFI_ERROR (Status
)) {
1597 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE
), gShellDebug1HiiHandle
);
1598 return EFI_LOAD_ERROR
;
1601 Status
= MenuBarInit (HexEditorMenuItems
);
1602 if (EFI_ERROR (Status
)) {
1603 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_MAINMENU
), gShellDebug1HiiHandle
);
1604 return EFI_LOAD_ERROR
;
1607 Status
= StatusBarInit ();
1608 if (EFI_ERROR (Status
)) {
1609 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_STATUS
), gShellDebug1HiiHandle
);
1610 return EFI_LOAD_ERROR
;
1615 Status
= HBufferImageInit ();
1616 if (EFI_ERROR (Status
)) {
1617 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_BUFFERIMAGE
), gShellDebug1HiiHandle
);
1618 return EFI_LOAD_ERROR
;
1621 Status
= HClipBoardInit ();
1622 if (EFI_ERROR (Status
)) {
1623 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_CLIPBOARD
), gShellDebug1HiiHandle
);
1624 return EFI_LOAD_ERROR
;
1627 // clear whole screen and enable cursor
1629 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1630 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1633 // initialize EditorFirst and EditorExit
1635 HEditorFirst
= TRUE
;
1636 HEditorExit
= FALSE
;
1637 HEditorMouseAction
= FALSE
;
1643 Cleanup function for MainEditor.
1645 @retval EFI_SUCCESS The operation was successful.
1646 @retval EFI_LOAD_ERROR A load error occured.
1649 HMainEditorCleanup (
1656 // call the five components' cleanup function
1658 MainTitleBarCleanup ();
1662 StatusBarCleanup ();
1666 Status
= HBufferImageCleanup ();
1667 if (EFI_ERROR (Status
)) {
1668 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_BUFFERIMAGE_CLEAN
), gShellDebug1HiiHandle
);
1671 Status
= HClipBoardCleanup ();
1672 if (EFI_ERROR (Status
)) {
1673 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_CLIPBOARD_CLEAN
), gShellDebug1HiiHandle
);
1678 if (HOriginalMode
!= gST
->ConOut
->Mode
->Mode
) {
1679 gST
->ConOut
->SetMode (gST
->ConOut
, HOriginalMode
);
1682 gST
->ConOut
->SetAttribute (
1684 EFI_TEXT_ATTR (HOriginalColors
.Foreground
, HOriginalColors
.Background
)
1686 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1692 Refresh function for MainEditor.
1694 @retval EFI_SUCCESS The operation was successful.
1697 HMainEditorRefresh (
1707 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1708 HMainEditor
.BufferImage
->FileImage
->FileName
!= NULL
&&
1709 HBufferImageBackupVar
.FileImage
!= NULL
&&
1710 HBufferImageBackupVar
.FileImage
->FileName
!= NULL
&&
1711 StrCmp (HMainEditor
.BufferImage
->FileImage
->FileName
, HBufferImageBackupVar
.FileImage
->FileName
) != 0 ) {
1714 if ( HMainEditor
.BufferImage
->FileImage
!= NULL
&&
1715 HBufferImageBackupVar
.FileImage
!= NULL
&&
1716 HMainEditor
.BufferImage
->FileImage
->ReadOnly
!= HBufferImageBackupVar
.FileImage
->ReadOnly
) {
1721 // to aVOID screen flicker
1722 // the stall value is from experience
1727 // call the components refresh function
1731 || HMainEditor
.BufferImage
->BufferType
!= HBufferImageBackupVar
.BufferType
1732 || HBufferImageBackupVar
.Modified
!= HMainEditor
.BufferImage
->Modified
1735 MainTitleBarRefresh (
1736 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
,
1737 HMainEditor
.BufferImage
->BufferType
,
1738 (BOOLEAN
)(HMainEditor
.BufferImage
->FileImage
!=NULL
?HMainEditor
.BufferImage
->FileImage
->ReadOnly
:FALSE
),
1739 HMainEditor
.BufferImage
->Modified
,
1740 HMainEditor
.ScreenSize
.Column
,
1741 HMainEditor
.ScreenSize
.Row
,
1742 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,
1743 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
1745 HBufferImageRefresh ();
1748 || HBufferImageBackupVar
.DisplayPosition
.Row
!= HMainEditor
.BufferImage
->DisplayPosition
.Row
1749 || HBufferImageBackupVar
.DisplayPosition
.Column
!= HMainEditor
.BufferImage
->DisplayPosition
.Column
1750 || StatusBarGetRefresh()) {
1754 HMainEditor
.ScreenSize
.Row
,
1755 HMainEditor
.ScreenSize
.Column
,
1760 HBufferImageRefresh ();
1765 HMainEditor
.ScreenSize
.Row
,
1766 HMainEditor
.ScreenSize
.Column
);
1767 HBufferImageRefresh ();
1771 // EditorFirst is now set to FALSE
1773 HEditorFirst
= FALSE
;
1779 Handle the mouse input.
1781 @param[in] MouseState The current mouse state.
1782 @param[out] BeforeLeftButtonDown helps with selections.
1784 @retval EFI_SUCCESS The operation was successful.
1785 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1786 @retval EFI_LOAD_ERROR A load error occured.
1787 @retval EFI_NOT_FOUND The disk was not found.
1790 HMainEditorHandleMouseInput (
1791 IN EFI_SIMPLE_POINTER_STATE MouseState
,
1792 OUT BOOLEAN
*BeforeLeftButtonDown
1802 HEFI_EDITOR_LINE
*Line
;
1809 // have mouse movement
1811 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
1815 TextX
= HGetTextX (MouseState
.RelativeMovementX
);
1816 TextY
= HGetTextY (MouseState
.RelativeMovementY
);
1818 HBufferImageAdjustMousePosition (TextX
, TextY
);
1824 if (MouseState
.LeftButton
) {
1825 HighBits
= HBufferImageIsAtHighBits (
1826 HMainEditor
.BufferImage
->MousePosition
.Column
,
1831 // not at an movable place
1835 // now just move mouse pointer to legal position
1838 // move mouse position to legal position
1840 HMainEditor
.BufferImage
->MousePosition
.Column
-= 10;
1841 if (HMainEditor
.BufferImage
->MousePosition
.Column
> 24) {
1842 HMainEditor
.BufferImage
->MousePosition
.Column
--;
1843 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1845 if (HMainEditor
.BufferImage
->MousePosition
.Column
< 24) {
1846 FCol
= HMainEditor
.BufferImage
->MousePosition
.Column
/ 3 + 1 + 1;
1859 FRow
= HMainEditor
.BufferImage
->BufferPosition
.Row
+
1860 HMainEditor
.BufferImage
->MousePosition
.Row
-
1861 HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1863 if (HMainEditor
.BufferImage
->NumLines
< FRow
) {
1868 // now just move mouse pointer to legal position
1870 FRow
= HMainEditor
.BufferImage
->NumLines
;
1874 Link
= HMainEditor
.BufferImage
->ListHead
->ForwardLink
;
1875 for (Index
= 0; Index
< FRow
- 1; Index
++) {
1876 Link
= Link
->ForwardLink
;
1879 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
1885 // now just move mouse pointer to legal position
1887 if (FCol
> Line
->Size
) {
1888 if (*BeforeLeftButtonDown
) {
1891 if (Line
->Size
== 0) {
1904 FCol
= Line
->Size
+ 1;
1909 HBufferImageMovePosition (FRow
, FCol
, HighBits
);
1911 HMainEditor
.BufferImage
->MousePosition
.Row
= HMainEditor
.BufferImage
->DisplayPosition
.Row
;
1913 HMainEditor
.BufferImage
->MousePosition
.Column
= HMainEditor
.BufferImage
->DisplayPosition
.Column
;
1915 *BeforeLeftButtonDown
= TRUE
;
1920 // else of if LButton
1924 if (*BeforeLeftButtonDown
) {
1930 *BeforeLeftButtonDown
= FALSE
;
1937 return EFI_NOT_FOUND
;
1941 Handle user key input. will route it to other components handle function.
1943 @retval EFI_SUCCESS The operation was successful.
1944 @retval EFI_OUT_OF_RESOURCES A memory allocation occured.
1945 @retval EFI_LOAD_ERROR A load error occured.
1948 HMainEditorKeyInput (
1954 EFI_SIMPLE_POINTER_STATE MouseState
;
1955 BOOLEAN LengthChange
;
1958 BOOLEAN BeforeMouseIsDown
;
1959 BOOLEAN MouseIsDown
;
1964 UINTN SelectStartBackup
;
1965 UINTN SelectEndBackup
;
1968 // variable initialization
1973 LengthChange
= FALSE
;
1975 MouseIsDown
= FALSE
;
1981 Status
= EFI_SUCCESS
;
1983 HEditorMouseAction
= FALSE
;
1986 // backup some key elements, so that can aVOID some refresh work
1988 HMainEditorBackup ();
1991 // wait for user key input
1994 // change priority of checking mouse/keyboard activity dynamically
1995 // so prevent starvation of keyboard.
1996 // if last time, mouse moves then this time check keyboard
1998 if (HMainEditor
.MouseSupported
) {
1999 Status
= HMainEditor
.MouseInterface
->GetState (
2000 HMainEditor
.MouseInterface
,
2003 if (!EFI_ERROR (Status
)) {
2005 BeforeMouseIsDown
= MouseIsDown
;
2007 Status
= HMainEditorHandleMouseInput (MouseState
, &MouseIsDown
);
2009 if (!EFI_ERROR (Status
)) {
2010 if (!BeforeMouseIsDown
) {
2015 FRow
= HBufferImage
.BufferPosition
.Row
;
2016 FCol
= HBufferImage
.BufferPosition
.Column
;
2017 SelectStartBackup
= HMainEditor
.SelectStart
;
2018 SelectEndBackup
= HMainEditor
.SelectEnd
;
2024 SelectStartBackup
= HMainEditor
.SelectStart
;
2025 SelectEndBackup
= HMainEditor
.SelectEnd
;
2032 if (MouseState
.RelativeMovementX
|| MouseState
.RelativeMovementY
) {
2033 HMainEditor
.SelectStart
= 0;
2034 HMainEditor
.SelectEnd
= 0;
2035 HMainEditor
.SelectStart
= (FRow
- 1) * 0x10 + FCol
;
2042 (HBufferImage
.BufferPosition
.Row
- 1) *
2044 HBufferImage
.BufferPosition
.Column
2045 ) >= HMainEditor
.SelectStart
2047 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2049 HBufferImage
.BufferPosition
.Column
;
2051 HMainEditor
.SelectEnd
= 0;
2055 // end of if RelativeX/Y
2062 if (HBufferImageGetTotalSize () == 0) {
2063 HMainEditor
.SelectStart
= 0;
2064 HMainEditor
.SelectEnd
= 0;
2070 (HBufferImage
.BufferPosition
.Row
- 1) *
2072 HBufferImage
.BufferPosition
.Column
2073 ) >= HMainEditor
.SelectStart
2075 HMainEditor
.SelectEnd
= (HBufferImage
.BufferPosition
.Row
- 1) *
2077 HBufferImage
.BufferPosition
.Column
;
2079 HMainEditor
.SelectEnd
= 0;
2082 if (HMainEditor
.SelectEnd
== 0) {
2083 HMainEditor
.SelectStart
= 0;
2091 if (SelectStartBackup
!= HMainEditor
.SelectStart
|| SelectEndBackup
!= HMainEditor
.SelectEnd
) {
2092 if ((SelectStartBackup
- 1) / 0x10 != (HMainEditor
.SelectStart
- 1) / 0x10) {
2093 HBufferImageNeedRefresh
= TRUE
;
2095 if ((SelectEndBackup
- 1) / 0x10 != (HMainEditor
.SelectEnd
- 1) / 0x10) {
2096 HBufferImageNeedRefresh
= TRUE
;
2098 HBufferImageOnlyLineNeedRefresh
= TRUE
;
2104 HEditorMouseAction
= TRUE
;
2105 HBufferImageMouseNeedRefresh
= TRUE
;
2107 } else if (Status
== EFI_LOAD_ERROR
) {
2108 StatusBarSetStatusString (L
"Invalid Mouse Movement ");
2113 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2114 if (!EFI_ERROR (Status
)) {
2116 // dispatch to different components' key handling function
2117 // so not everywhere has to set this variable
2119 HBufferImageMouseNeedRefresh
= TRUE
;
2122 // clear previous status string
2124 StatusBarSetRefresh();
2126 if (Key
.ScanCode
== SCAN_NULL
) {
2127 Status
= HBufferImageHandleInput (&Key
);
2128 } else if (((Key
.ScanCode
>= SCAN_UP
) && (Key
.ScanCode
<= SCAN_PAGE_DOWN
))) {
2129 Status
= HBufferImageHandleInput (&Key
);
2130 } else if (((Key
.ScanCode
>= SCAN_F1
) && Key
.ScanCode
<= (SCAN_F12
))) {
2131 Status
= MenuBarDispatchFunctionKey (&Key
);
2133 StatusBarSetStatusString (L
"Unknown Command");
2135 HBufferImageMouseNeedRefresh
= FALSE
;
2138 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_OUT_OF_RESOURCES
) {
2140 // not already has some error status
2142 if (StrCmp (L
"", StatusBarGetString()) == 0) {
2143 StatusBarSetStatusString (L
"Disk Error. Try Again");
2148 // decide if has to set length warning
2150 if (HBufferImage
.BufferType
!= HBufferImageBackupVar
.BufferType
) {
2151 LengthChange
= FALSE
;
2154 // still the old buffer
2156 if (HBufferImage
.BufferType
!= FileTypeFileBuffer
) {
2157 Size
= HBufferImageGetTotalSize ();
2159 switch (HBufferImage
.BufferType
) {
2160 case FileTypeDiskBuffer
:
2161 OldSize
= HBufferImage
.DiskImage
->Size
* HBufferImage
.DiskImage
->BlockSize
;
2164 case FileTypeMemBuffer
:
2165 OldSize
= HBufferImage
.MemImage
->Size
;
2173 if (!LengthChange
) {
2174 if (OldSize
!= Size
) {
2175 StatusBarSetStatusString (L
"Disk/Mem Buffer Length should not be changed");
2179 if (OldSize
!= Size
) {
2180 LengthChange
= TRUE
;
2182 LengthChange
= FALSE
;
2187 // after handling, refresh editor
2189 HMainEditorRefresh ();
2191 } while (Status
!= EFI_OUT_OF_RESOURCES
&& !HEditorExit
);
2197 Backup function for MainEditor.
2205 HMainEditorBackupVar
.SelectStart
= HMainEditor
.SelectStart
;
2206 HMainEditorBackupVar
.SelectEnd
= HMainEditor
.SelectEnd
;
2207 HBufferImageBackup ();