/** @file
Defines HBufferImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HexEditor.h"
extern EFI_HANDLE HImageHandleBackup;
extern HEFI_EDITOR_FILE_IMAGE HFileImage;
extern HEFI_EDITOR_DISK_IMAGE HDiskImage;
extern HEFI_EDITOR_MEM_IMAGE HMemImage;
extern BOOLEAN HEditorMouseAction;
extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor;
//
// for basic initialization of HBufferImage
//
NULL,
NULL,
0,
NULL,
{
0,
0
},
{
0,
0
},
{
0,
0
},
0,
TRUE,
NULL,
NULL,
};
//
// the whole edit area needs to be refreshed
//
//
// only the current line in edit area needs to be refresh
//
/**
Initialization function for HBufferImage
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
**/
)
{
//
// basically initialize the HBufferImage
//
//
// INIT listhead
//
return EFI_LOAD_ERROR;
}
Status = HFileImageInit ();
return EFI_LOAD_ERROR;
}
Status = HDiskImageInit ();
return EFI_LOAD_ERROR;
}
Status = HMemImageInit ();
return EFI_LOAD_ERROR;
}
return EFI_SUCCESS;
}
/**
Backup function for HBufferImage. Only a few fields need to be backup.
This is for making the file buffer refresh as few as possible.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// three kinds of buffer supported
// file buffer
// disk buffer
// memory buffer
//
switch (HBufferImage.BufferType) {
case FileTypeFileBuffer:
HFileImageBackup ();
break;
case FileTypeDiskBuffer:
HDiskImageBackup ();
break;
case FileTypeMemBuffer:
HMemImageBackup ();
break;
default:
break;
}
return EFI_SUCCESS;
}
/**
Free all the lines in HBufferImage.
Fields affected:
Lines
CurrentLine
NumLines
ListHead
@retval EFI_SUCCESS The operation was successful.
**/
)
{
HBufferImage.NumLines = 0;
return EFI_SUCCESS;
}
/**
Cleanup function for HBufferImage
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// free all the lines
//
Status = HBufferImageFreeLines ();
return Status;
}
/**
Print Line on Row
@param[in] Line The lline to print.
@param[in] Row The row on screen ( begin from 1 ).
@param[in] FRow The FRow.
@param[in] Orig The original color.
@param[in] New The color to print with.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// variable initialization
//
ColStart = 0;
ColEnd = 0;
//
// print the selected area in opposite color
//
}
ColStart = 1;
}
ColEnd = 0x10;
}
}
if (!HEditorMouseAction) {
0,
L"%8X ",
);
}
BeNewColor = FALSE;
if (Selected) {
BeNewColor = TRUE;
}
}
if (BeNewColor) {
} else {
}
Pos++;
}
if (Index < 0x07) {
} else {
}
}
while (Index < 0x08) {
Index++;
}
BeNewColor = FALSE;
if (Selected) {
BeNewColor = TRUE;
}
}
if (BeNewColor) {
} else {
}
Pos++;
}
Index++;
}
while (Index < 0x10) {
Index++;
}
//
// restore the original color
//
//
// PRINT the buffer content
//
if (!HEditorMouseAction) {
//
// learned from shelle.h -- IsValidChar
//
} else {
}
}
while (Index < 0x10) {
Index++;
}
}
//
// restore the abundant blank in hex edit area to original color
//
if (Selected) {
if (ColEnd <= 7) {
} else if (ColEnd == 8) {
} else {
}
}
return EFI_SUCCESS;
}
/**
Function to decide if a column number is stored in the high bits.
@param[in] Column The column to examine.
@param[out] FCol The actual column number.
@retval TRUE The actual column was in high bits and is now in FCol.
@retval FALSE There was not a column number in the high bits.
**/
)
{
Column -= 10;
//
// NOW AFTER THE SUB, Column start from 0
// 23 AND 24 ARE BOTH BLANK
//
if (Column == 24) {
*FCol = 0;
return FALSE;
}
if (Column > 24) {
Column--;
}
if (Column % 3 == 0) {
return TRUE;
}
*FCol = 0;
}
return FALSE;
}
/**
Decide if a point is in the already selected area.
@param[in] MouseRow The row of the point to test.
@param[in] MouseCol The col of the point to test.
@retval TRUE The point is in the selected area.
@retval FALSE The point is not in the selected area.
**/
)
{
//
// judge mouse position whether is in selected area
//
//
// not select
//
return FALSE;
}
//
// calculate the select area
//
return FALSE;
}
ColStart = 1;
}
ColEnd = 0x10;
}
if (ColStart > 8) {
}
if (ColEnd > 8) {
MouseColEnd++;
}
return FALSE;
}
return TRUE;
}
/**
Set mouse position according to HBufferImage.MousePosition.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
if (HMainEditor.MouseSupported) {
if (HBufferImageMouseNeedRefresh) {
//
// if mouse position not moved and only mouse action
// so do not need to refresh mouse position
//
if ((
) &&
) {
return EFI_SUCCESS;
}
//
// backup the old screen attributes
//
//
// if in selected area,
// so do not need to refresh mouse
//
if (!HBufferImageIsInSelectedArea (
)) {
} else {
}
//
// clear the old mouse position
//
);
HasCharacter = TRUE;
} else {
}
}
L" "
);
if (HasCharacter) {
if (HighBits) {
} else {
}
L"%x",
);
}
if (!HBufferImageIsInSelectedArea (
)) {
} else {
}
//
// clear the old mouse position
//
);
HasCharacter = TRUE;
} else {
}
}
L" "
);
if (HasCharacter) {
if (HighBits) {
} else {
}
L"%x",
);
}
//
// end of HasCharacter
//
}
//
// end of MouseNeedRefresh
//
}
//
// end of MouseSupported
//
return EFI_SUCCESS;
}
/**
Set cursor position according to HBufferImage.DisplayPosition.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// set cursor position
//
);
return EFI_SUCCESS;
}
/**
Refresh function for HBufferImage.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A Load error occured.
**/
)
{
//
// if it's the first time after editor launch, so should refresh
//
if (HEditorFirst == FALSE) {
//
// no definite required refresh
// and file position displayed on screen has not been changed
//
if (!HBufferImageNeedRefresh &&
) {
return EFI_SUCCESS;
}
}
//
// only need to refresh current line
//
if (HBufferImageOnlyLineNeedRefresh && HBufferImageBackupVar.LowVisibleRow == HBufferImage.LowVisibleRow) {
Orig,
);
} else {
//
// the whole edit area need refresh
//
if (HMainEditor.SelectStart >= HMainEditorBackupVar.SelectStart && HMainEditorBackupVar.SelectStart != 0) {
} else {
}
} else {
}
} else {
}
//
// swap
//
}
} else {
//
// not mouse selection actions
//
StartRow = 2;
}
//
// no line
//
return EFI_SUCCESS;
}
//
// get the first line that will be displayed
//
return EFI_LOAD_ERROR;
}
do {
//
// print line at row
//
Line,
Row,
Orig,
);
Row++;
Row++;
}
//
// while not file end and not screen full
//
}
return EFI_SUCCESS;
}
/**
Read an image into a buffer friom a source.
@param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
@param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] BufferType The type of buffer to save. IGNORED.
@param[in] Recover TRUE for recovermode, FALSE otherwise.
@return EFI_SUCCESS The operation was successful.
**/
)
{
//
// variable initialization
//
//
// three types of buffer supported
// file buffer
// disk buffer
// memory buffer
//
switch (BufferType) {
case FileTypeFileBuffer:
break;
case FileTypeDiskBuffer:
break;
case FileTypeMemBuffer:
break;
default:
break;
}
}
return Status;
}
/**
Save the current image.
@param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
@param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] BufferType The type of buffer to save. IGNORED.
@return EFI_SUCCESS The operation was successful.
**/
)
{
//
// variable initialization
//
switch (HBufferImage.BufferType) {
//
// file buffer
//
case FileTypeFileBuffer:
break;
//
// disk buffer
//
case FileTypeDiskBuffer:
break;
//
// memory buffer
//
case FileTypeMemBuffer:
break;
default:
break;
}
}
return Status;
}
/**
Create a new line and append it to the line list.
Fields affected:
NumLines
Lines
@retval NULL create line failed.
@return the line created.
**/
)
{
//
// allocate for line structure
//
return NULL;
}
//
// insert to line list
//
Link,
);
}
return Line;
}
/**
Free the current image.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// free all lines
//
return EFI_SUCCESS;
}
/**
change char to int value based on Hex.
@param[in] Char The input char.
@return The character's index value.
@retval -1 The operation failed.
**/
)
{
//
// change the character to hex
//
}
}
}
return -1;
}
/**
Add character.
@param[in] Char -- input char.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
)
{
//
// invalid input
//
if (Value == -1) {
return EFI_SUCCESS;
}
//
// only needs to refresh current line
//
//
// not a full line and beyond the last character
//
//
// cursor always at high 4 bits
// and always put input to the low 4 bits
//
} else {
//
// always put the input to the low 4 bits
//
//
// at the low 4 bits of the last character of a full line
// so if no next line, need to create a new line
//
//
// last line
//
// create a new line
//
return EFI_OUT_OF_RESOURCES;
}
//
// end of NULL
//
}
//
// end of == ListHead
//
}
//
// end of == 0x10
//
// if already at end of this line, scroll it to the start of next line
//
//
// definitely has next line
//
FRow++;
FCol = 1;
} else {
//
// if not at end of this line, just move to next column
//
if (!High) {
FCol++;
}
if (High) {
} else {
}
}
//
// end of ==FALSE
//
}
//
// move cursor to right
//
if (!HBufferImage.Modified) {
}
return EFI_SUCCESS;
}
/**
Delete the previous character.
@retval EFI_SUCCESS The operationw as successful.
**/
)
{
//
// variable initialization
//
//
// already the first character
//
return EFI_SUCCESS;
}
}
//
// if is the last line
// then only this line need to be refreshed
//
if (LastLine) {
} else {
}
if (!HBufferImage.Modified) {
}
return EFI_SUCCESS;
}
/**
ASCII key + Backspace + return.
@param[in] Char The input char.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
)
{
switch (Char) {
case 0:
break;
case 0x08:
break;
case 0x09:
case 0x0a:
case 0x0d:
//
// Tabs, Returns are thought as nothing
//
break;
default:
//
// DEAL WITH ASCII CHAR, filter out thing like ctrl+f
//
} else {
}
break;
}
return Status;
}
/**
Check user specified FileRow is above current screen.
@param[in] FileRow Row of file position ( start from 1 ).
@retval TRUE It is above the current screen.
@retval FALSE It is not above the current screen.
**/
)
{
return TRUE;
}
return FALSE;
}
/**
Check user specified FileRow is under current screen.
@param[in] FileRow Row of file position ( start from 1 ).
@retval TRUE It is under the current screen.
@retval FALSE It is not under the current screen.
**/
)
{
return TRUE;
}
return FALSE;
}
/**
According to cursor's file position, adjust screen display.
@param[in] NewFilePosRow Row of file position ( start from 1 ).
@param[in] NewFilePosCol Column of file position ( start from 1 ).
@param[in] HighBits Cursor will on high4 bits or low4 bits.
**/
)
{
//
// CALCULATE gap between current file position and new file position
//
//
// if is below current screen
//
if (Under) {
//
// display row will be unchanged
//
} else {
if (Above) {
//
// has enough above line, so display row unchanged
// not has enough above lines, so the first line is
// at the first display line
//
}
} else {
//
// in current screen
//
if (RowGap <= 0) {
} else {
}
}
}
HBufferImage.LowVisibleRow = HBufferImage.BufferPosition.Row - (HBufferImage.DisplayPosition.Row - 2);
//
// always in current screen
//
if (NewFilePosCol > 0x8) {
}
if (!HighBits) {
}
//
// let CurrentLine point to correct line;
//
}
/**
Scroll cursor to right.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// scroll right will always move to the high4 bits of the next character
//
//
// this line is not full and no next line
//
return EFI_SUCCESS;
}
//
// if already at end of this line, scroll it to the start of next line
//
if (FCol == 0x10) {
//
// has next line
//
FRow++;
FCol = 1;
} else {
return EFI_SUCCESS;
}
} else {
//
// if not at end of this line, just move to next column
//
FCol++;
}
return EFI_SUCCESS;
}
/**
Scroll cursor to left.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// if already at start of this line, so move to the end of previous line
//
if (FCol <= 1) {
//
// has previous line
//
FRow--;
} else {
return EFI_SUCCESS;
}
} else {
//
// if not at start of this line, just move to previous column
//
FCol--;
}
return EFI_SUCCESS;
}
/**
Scroll cursor to the next line
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// has next line
//
FRow++;
//
// if the next line is not that long, so move to end of next line
//
}
} else {
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
/**
Scroll cursor to previous line
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// has previous line
//
FRow--;
} else {
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
/**
Scroll cursor to next page
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// has next page
//
} else {
//
// MOVE CURSOR TO LAST LINE
//
}
//
// get correct line
//
//
// if that line, is not that long, so move to the end of that line
//
}
return EFI_SUCCESS;
}
/**
Scroll cursor to previous page
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// has previous page
//
} else {
//
// the first line of file will displayed on the first line of screen
//
}
//
// get correct line
//
return EFI_SUCCESS;
}
/**
Scroll cursor to start of line
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// curosr will at the high bit
//
FCol = 1;
//
// move cursor position
//
return EFI_SUCCESS;
}
/**
Scroll cursor to end of line.
@retval EFI_SUCCESS Teh operation was successful.
**/
)
{
//
// need refresh mouse
//
} else {
}
//
// move cursor position
//
return EFI_SUCCESS;
}
/**
Get the size of the open buffer.
@retval The size in bytes.
**/
)
{
//
// calculate the total size of whole line list's buffer
//
return 0;
}
Link,
);
//
// one line at most 0x10
//
return Size;
}
/**
Delete character from buffer.
@param[in] Pos Position, Pos starting from 0.
@param[in] Count The Count of characters to delete.
@param[out] DeleteBuffer The DeleteBuffer.
@retval EFI_SUCCESS Success
**/
)
{
//
// get the line that start position is at
//
Size = HBufferImageGetTotalSize ();
return EFI_LOAD_ERROR;
}
if (Size == 0) {
return EFI_SUCCESS;
}
//
// relocate all the HBufferImage fields
//
if (Pos > 0) {
//
// has character before it,
// so locate according to block's previous character
//
} else {
//
// has no character before it,
// so locate according to block's next character
//
NewPos = 0;
}
return EFI_OUT_OF_RESOURCES;
}
//
// pass deleted buffer out
//
if (DeleteBuffer != NULL) {
}
}
//
// delete the part from Pos
//
}
return Status;
}
}
//
// if current cursor position if inside select area
// then move it to the block's NEXT character
//
} else {
} else {
}
}
return EFI_SUCCESS;
}
/**
Add character to buffer, add before pos.
@param[in] Pos Position, Pos starting from 0.
@param[in] Count Count of characters to add.
@param[in] AddBuffer Add buffer.
@retval EFI_SUCCESS Success.
**/
)
{
//
// get the line that start position is at
//
Size = HBufferImageGetTotalSize ();
//
// relocate all the HBufferImage fields
//
//
// move cursor before Pos
//
if (Pos > 0) {
} else {
NewPos = 0;
}
return EFI_OUT_OF_RESOURCES;
}
//
// get a place to add
//
}
//
// add the buffer
//
}
}
} else {
}
return EFI_SUCCESS;
}
/**
Delete current character from line.
@retval EFI_SUCCESS The operationw as successful.
**/
)
{
//
// if beyond the last character
//
return EFI_SUCCESS;
}
}
//
// if is the last line
// then only this line need to be refreshed
//
if (LastLine) {
} else {
}
if (!HBufferImage.Modified) {
}
return EFI_SUCCESS;
}
/**
Change the raw buffer to a list of lines for the UI.
@param[in] Buffer The pointer to the buffer to fill.
@param[in] Bytes The size of the buffer in bytes.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
)
{
TempI = 0;
Left = 0;
//
// parse file content line by line
//
Left = 0x10;
} else {
}
//
// allocate a new line
//
Line = HBufferImageCreateLine ();
return EFI_OUT_OF_RESOURCES;
}
TempI++;
}
}
//
// last line is a full line, SO create a new line
//
Line = HBufferImageCreateLine ();
return EFI_OUT_OF_RESOURCES;
}
}
return EFI_SUCCESS;
}
/**
Change the list of lines from the UI to a raw buffer.
@param[in] Buffer The pointer to the buffer to fill.
@param[in] Bytes The size of the buffer in bytes.
@retval EFI_SUCCESS The operation was successful.
**/
)
{
//
// change the line list to a large buffer
//
return EFI_SUCCESS;
}
Count = 0;
//
// deal line by line
//
//@todo shouldn't this be an error???
return EFI_SUCCESS;
}
}
}
return EFI_SUCCESS;
}
/**
Move the mouse in the image buffer.
@param[in] TextX The x-coordinate.
@param[in] TextY The y-coordinate.
**/
)
{
//
// TextX and TextY is mouse movement data returned by mouse driver
// This function will change it to MousePosition
//
//
// get absolute TempX value
//
if (TextX >= 0) {
} else {
}
//
// get absolute TempY value
//
if (TextY >= 0) {
} else {
}
if (TextX >= 0) {
} else {
} else {
TempX = 0;
}
}
if (TextY >= 0) {
} else {
} else {
TempY = 0;
}
}
//
// check whether new mouse column position is beyond screen
// if not, adjust it
//
} else if (TempX < 10) {
}
//
// check whether new mouse row position is beyond screen
// if not, adjust it
//
} else if (TempY < 2) {
}
}
/**
Dispatch input to different handler
@param[in] Key The input key:
the keys can be:
ASCII KEY
INS
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
@retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
**/
)
{
//
// ordinary key
//
case SCAN_NULL:
break;
//
// up arrow
//
case SCAN_UP:
Status = HBufferImageScrollUp ();
break;
//
// down arrow
//
case SCAN_DOWN:
Status = HBufferImageScrollDown ();
break;
//
// right arrow
//
case SCAN_RIGHT:
break;
//
// left arrow
//
case SCAN_LEFT:
Status = HBufferImageScrollLeft ();
break;
//
// page up
//
case SCAN_PAGE_UP:
Status = HBufferImagePageUp ();
break;
//
// page down
//
case SCAN_PAGE_DOWN:
Status = HBufferImagePageDown ();
break;
//
// delete
//
case SCAN_DELETE:
Status = HBufferImageDoDelete ();
break;
//
// home
//
case SCAN_HOME:
Status = HBufferImageHome ();
break;
//
// end
//
case SCAN_END:
Status = HBufferImageEnd ();
break;
default:
break;
}
return Status;
}